jordimanyer / upa Goto Github PK
View Code? Open in Web Editor NEWFEM library for Plasma Physics and Confinement Fusion.
FEM library for Plasma Physics and Confinement Fusion.
Given a set of coordinates (x,y,z), we would like to obtain the index of the element where this point belongs.
As a first approach, my idea would be the following: We could add to the mesh an element-element connectivity map (which has not been implemented yet but is quite standard to have). Once this is done, a Dijkstra algorithm could be used to navigate between elements until finding the one containing the target coordinates. As a distance function, one could use the distance between the target coordinates and the baricenter of the elements (since all elements are convex, this would be an OK measure).
A feature can be added to GMRES to check the error of the approximation at each substep and stop the algorithm when needed to. This feature could also allow to run GMRES without restart.
This is not urgent, but could be a good (and easy) enhancement to the algorithm.
Decide on which kind of solver to use (Direct, iterative) for a first approach.
The solver will be sequential and a first approach.
In the implementation of 1D Laplace, in file src/Tests/v0_Laplace1D
, there is an allocation error in the mesh when the number of elements per side in an even number.
Lines 18 to 21 of the file are as follows:
int dim = 1;
ElemType type = ElemType::Line;
auto* mesh = new StructuredMesh();
mesh->produceCartesian(dim,11,type);
In the last line, if 11
is the number of elements per side the created cartesian mesh will have (the mesh is the line [0,1], divided into as many elements as the number states.
If 11
is changed to any other odd number (13, 19, 21, ....) the code will run as intended. However, if the number of elements is changed to an even number (10, 12, 8, ...) the code will give a malloc
error when allocating the arrays in the mesh.
For 12
, the output is as follows
Selected rows:
0 1 1 1 1 1 1 1 1 1 1 1 0
Complete matrix:
24 -12 0 0 0 0 0 0 0 0 0
-12 24 -12 0 0 0 0 0 0 0 0
0 -12 24 -12 0 0 0 0 0 0 0
0 0 -12 24 -12 0 0 0 0 0 0
0 0 0 -12 24 -12 0 0 0 0 0
0 0 0 0 -12 24 -12 0 0 0 0
0 0 0 0 0 -12 24 -12 0 0 0
0 0 0 0 0 0 -12 24 -12 0 0
0 0 0 0 0 0 0 -12 24 -12 0
0 0 0 0 0 0 0 0 -12 24 -12
0 0 0 0 0 0 0 0 0 -12 24
Complete Vector:
0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333 0.0833333
malloc(): corrupted top size
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
I do not know why this happens. Why is it doing this?
We need to add a distributed mesh structure.
Interaction with Pre & Post processing
For hard systems, preconditioning is needed. As a start, we should implement a preconditioned version of CG, which works for symmetric positive-definite matrices.
There are two main types of boundary conditions: Dirichlet and Newmann.
Newmann Boundary Conditions (NBCs) impose values on the normal derivatives of the solution (the fluxes) at the boundary. For instance, Newmann boundary conditions equal to zero on a boundary impose that there is no flux of solution through that boundary. NBCs are easy to impose since they are part of the Weak Form and therefore are taken care of while integrating the system.
On the other hand, Dirichlet BCs (DBCs) impose values directly on the DOFs themselves. For instance, DBCs equal to zero on the boundary impose that the solution is zero on that boundary.
Theoretically, DBCs are very easy to impose. On practice, some implementation issues arise.
There are different ways of imposing DBCs on a FEM system, each one woith its own drawbacks:
All in all, I think the first method is the one to go (it is the one used in the 1D Laplace example) but for 2D , 3D meshes it is not as trivial. As advertised, a re-labeling and resizing of the matrix is needed (which is easier said than done using our own matrix classes). The implementation should be thought through to make it as optimal as possible.
For now, c++ solvers have been implemented using arrays as matrices.
However, we will be using a lot of matrices in the future. Is it worth to implement some sort of matrix class? Or to use a 3rd party albegra library? I really have no idea on the advantages/disadvantages of these options, but we should probably consider it before having too much code.
We need to implement a basis function library, similar on how the Reference element class is implemented.
Basis functions for different types of elements are needed for two things: First, you need to evaluate them at the gauss points when integrating the weak form (system matrix assembly). Second, you might need them after solving the system, to do postprocessing stuff.
This second usage is increased if we want to have Nedelec Edge Elements (as Dani suggests). The reason is that Lagrangian basis functions (the standard ones) are interpolative at the nodes, so the solution of the problem can already be used without postprocessing. However Nedelec DOFs are non-interpolative and therefore the solution needs to be interpolated at the nodes as a post-process. This requires evaluating the basis functions.
So this is a feature we MUST have if we ever want to use Nedelec elements. It is also a more elegant way of doing things and a nice quality-of-life feauture even for Lagrangian elements.
We can do one of the two things:
I lean towards the second option. We could also use this opportunity to revise how the reference elemnt class is implemented and enhance it we feel it is necessary.
Once this has been done, we will be able to start implementing Nedelec elements.
We will eventually run into non-symmetric matrices. It would be good to have a solver for this cases.
The most common are GMRES (Krylov method similar to CG but for non-symmetric problems) and AMG.
Both can be complicated to implement in an efficient way:
For GMRES, the main problem is the least squares problem that needs to be solved at each loop iteration. For this reason, most people build and dynamically update a QR factorization when finding the orthogonal basis for the Krylov space. This can be done efficiently using Householder transformations.
For AMG, the problem is how to create an efficient sparse interpolator (i.e the transformation between the different fine and coarse levels). Rugge-Steuben is the all-purpose standard interpolator, but it can be tricky to implement in a sparse way. For simple geometries, and taking advantage of the mesh structure, simpler interpolatros can be obtained. After this, the actual solver is very easy to implement and test.
All in all, here are my initial thoughts:
So in conclusion I would start working towards GMRES as a priority and then try to go towards. Both could be nice to have, but neither are a real priority, since I doubt we find non-symmetric matrices in quite a while.
Develop first version of 1D Finite Element Method libraries to implement the Laplace equation.
The LIL entries in each row are ordered from high to low. We should reverse that order.
Before any physics can be implemented, we need some Documentation on how the numerical tools work. This will allow for other people to be able to cooperate with ease.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.