See the GitHub Wiki:
for tutorials and more.
Also see the new Discussion Forum:
for more information.
The following utilities are included:
- 3-D mesh generator for iso-surfaces.
- Closest point searching on meshes, including surface triangulations in 3-D.
NOTE: fixed error with MATLAB's triangulation class.
- Now includes H(curl) elements! Nedelec's 1st kind finite element is implemented.
Shawn Walker (2021). FELICITY (https://www.mathworks.com/matlabcentral/fileexchange/31141-felicity), MATLAB Central File Exchange. Retrieved .
Walker, Shawn W. “FELICITY: A Matlab/C\Mathplus\Mathplus Toolbox for Developing Finite Element Methods and Simulation Modeling.” SIAM Journal on Scientific Computing, vol. 40, no. 2, Society for Industrial & Applied Mathematics (SIAM), Jan. 2018, pp. C234–C257, doi:10.1137/17m1128745.
Thank you for your response. I can correctly run and modify your test examples to apply to new problems. I'm just curious about how to use the MATLAB scripts directly.
All of the demos (and unit tests) have a main "test" file that runs everything. If you check the Wiki, there are also tutorials. The only thing you need to do is make sure you have a C++ compiler that Matlab can find, and configure mex with "mex -setup". There are many resources on the internet for configuring Matlab's mex stuff.
Hello Prof. Shawn.
I'm interested in the FEM tool you wrote, but I don't know much about the mex files.
Is there any example that can be run directly without compiling into mex files?
I have not used the matlab PDE toolbox, so I cannot say. Perhaps something wasn't set properly. You probably want to check things on a square first. Also, check that the boundary conditions (in the actual solution) are correct.
I have solved the three hole Poisson equation problem using radial basis functions (RBFs) and I get a solution very close to the Felicity solution. However, interestingly, when I solve the same problem with the Matlab pde toolbox there appears to be a significant difference. Not sure which solution is correct, if any.
Thanks Graham. If you have any questions, post them at the forum.
Thanks for all your effort in creating such a great toolbox.
The issue seems to be with the new version of Matlab (2017b) keeping F as the input variable in the output string, which is then parsed later on as a variable and causes an error. When I type ffoo into Matlab it outputs the (F) explicitly like this.
ffoo(F) = foo(pi*geomSigma_X3)
which is picked up by symvar later
ans =[ F, geomSigma_X3]
It only seems to affect the 1D matrix assemble test, I can run everything I need just fine. I'm not well versed in the symbolic toolbox but probably just clearing the argument variables would solve it. Just a heads up for future releases or anyone else trying this on Matlab 2017b. Code looks great by the way, thanks a lot for putting this together.
Try changing this line: ffoo = subs(foo, 'F', C1 * gf.X(3) );
to: ffoo = subs(foo, F, C1 * gf.X(3) );
I suspect this is an error with the newest version of Matlab. The old thing works with Version R2016b.
I'm trying to run the test_FELICITY.m file, everything seems to be compiling just fine but I get the error
var_name := "F" is not recognized!
The given var_name does *not* match the following VALID Test, Trial,
Coef, or GeoFunc functions:
Test Function: v
GeoFunc Function: geomSigma
Make sure you include a *valid* Test, Trial, Coef,
and/or GeoFunc function when defining this Integral!
It comes from the last line in the MatAssem_interval code below
Body_Force_Matrix = Linear(Scalar_P2);
syms F foo(F);
ffoo = subs(foo, 'F', C1 * gf.X(3) );
Body_Force_Matrix = Body_Force_Matrix + Integral(Sigma,v.val * ffoo);
any idea what might be causing this?
Sorry I forgot you were doing the curl-curl problem. Ok, I will keep this in mind.
I contacted the AGMG team. They told be that the algorithm has been designed for discrete scalar elliptic PDEs (Poisson like problems), and works poorly for curl-curl problems. Therefore, it would probably not help for what I am doing.
I think a better option would be a GPU implementation of an iterative solver.
I'm not doing anything special; just CPU. You should definitely check out AGMG.
A few seconds? Are you using a GPU or some other kind of parallel computing ?
15 minutes is kind of slow. AGMG will solve it in a few seconds with that many unknowns.
I set the tolerance to 1e-8. Calculation time is less than 15min for a linear system of 1,000,000 unknowns.
Thanks for the info. I assume you used a reasonable tolerance?
Sorry for my late response. I did not notice your post.
Here is the solver that I am using now with lagrange_deg1_dim3 elements.
L = ichol(MAT);
X= minres(MAT, RHS, Tol, Maxit, L, L');
I do not have the AGMG solver, so I cannot compare with it. Since it is an iterative solver, you do have a for loop inside. However, I think the heaviest part of the calculus is the matrix multiplication at each iteration, and the matrix multiplication is already optimized in MATLAB. Im am not sure if compiling the complete solver in a MEX file would speed up that much (though it would be interested to check).
Something you could probably do to speed up the calculations, although I have not tried it yet, is to perform the calculations on a GPU. Since MATLAB’s matrix multiplication function supports sparse arrays on GPU, you could theoretically do the sparse matrix multiplications on a GPU. This should be way faster than on a CPU.
The generation of MEX files used for matrix assembly crashes when there is a space character in the file path.
I could fix the problem with the following modifications.
eval(['cd ' Main_Dir]);
eval("cd '" + Main_Dir + "'");
eval(['cd ' current_path]) ;
eval("cd '" + current_path + "'");
[status, result] = system([COPY_STR, ' ', File1, ' ', File2]);
[status, result] = system([COPY_STR, ' "', File1, '" "', File2, '"']);
I suggest you consider these modifications in the next release.
But how does this compare to AGMG? My experience with the iterative solvers in MATLAB is they are still FOR loop based, so can be slower than a C code equivalent. Is this true?
I managed to solve sparse linear systems with 4 million variables. The problem was to calculate a 3D vector field on a 110x110x110 MeshTetrahedron with Lagrange elements of degree 1.
I did not use a pre-conditioner. Beyond 5 million variables, I run into memory problems: even with a sparse structure, the stiffness matrix is just too big to fit in memory (16GBytes).
From my understanding of the iterative methods, you do not need to load the complete mass matrix in memory to calculate the solution. Therefore, I am trying to modify the iterative solver to store the mass matrix on the hard drive, and load the matrix one small chunk at a time in the limits of what the RAM can handle.
Thanks for the note. I have not compared the MATLAB iterative solvers with AGMG. How big a system did you solve? Did you need an pre-conditioner?
Great toolbox. The matrix assembly and solution interpolation using mex files are very fast.
For systems too big to be solved using "backslash", you can use one of the iterative solvers of MATLAB. I use the biconjugate gradients stabilized method "bicgstab" to solve 3D magnetostatics problems.
Did you compare the performances of the MATLAB iterative solvers with the AGMG solver?
There is now a tutorial on solving Laplace-Beltrami on a piecewise quadratic surface, with piecewise quadratic elements:
You can simplify this to your case of piecewise quadratics for Laplace in 1-D.
I want to implement some adaptive mesh for solving my PDE with the toolbox, so I'm wondering is there one example using the adaptive mesh?
There is a tutorial here on solving the Stokes eqn in 2-D. That involves a piecewise quadratic finite element space:
You can also find more info here:
On managing DoFs for higher order finite element spaces.
Thank you very much for this great toolbox.
Can you please send me modified two m files (MatAssem_Laplace_1D.m and test_Laplace_1D.m) to solve the same problem but using piecewise quadratic space.
Thank you very much
Thanks for the comment.
As for citing, you can cite the GitHub or Wiki site. There is no official paper for it yet. If you use the TIGER mesher, there is a paper for that
Tried out FELICITY - installed and tests all passed! One small note - on the tutorial (https://github.com/walkersw/felicity-finite-element-toolbox/wiki/Mesh_Generation_with_TIGER_1), when generating a 3D volumetric mesh for the sphere, the line "LS.Param.sign=1" is missing from the tutorial.
Also, how do we cite FELICITY if we use it?
I'm not sure what is wrong. Make sure you verify that your version of MATLAB supports the compiler. If it is a recent version R2010 or later, then you should be fine. But double check the version/compiler compatibility on the MATLAB web site.
Also, did you try this link:
They walk you through the full install.
If that doesn't work, you should email the MATLAB helpdesk.
Now I installed the following version of Microsoft Windows SDK 7.1
x64 ISO File Name: GRMSDKX_EN_DVD.iso
First I installed Microsoft Visual C++ 2010 Express as you proposed, but still it cannot find the C++ compiler in matlab when I write mex -setup
Let me add another comment. You have to install TWO things (separately) to make MATLAB see MS Visual C++. They are:
1. Microsoft Visual C++ 2010 Express
2. Microsoft Windows SDK 7.1
Both are free and must be installed in that order (sorry I forgot about this).
The following link should be useful for those who want to use MS Visual C++ (Windows):
Here is the link I found:
Visual C++ 2010 Express:
It says that it supports 64bit versions, and Windows 7. You may have to register as a user, but that isn't a big deal. Once you have it installed, MATLAB should see it by typing "mex -setup".
Which version of Visual C++ edition did you install? In fact I have a 64bit version of matlab R2010a on a Windows 7 computer. Could you send a link where I can download a 64 bit version of Visual C++ express for free?
YES, you do need a 64-bit compiler. When I tested this on Windows 7, I installed Visual C++ express edition (64-bit), and it worked.
I have a 64-bit version of matlab installede and tried to install Visual C++ 2010 Express from the following link:http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express.
When I wrote m -setup in the command window it could not find the compiler. Do you know if I need a 64bit compiler?
Inspired by: Example MATLAB class wrapper for a C++ class
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!