I am building codes for an adaptive local mesh refinement scheme in finite element method.
The 4-by-ne element and 2-by-nd node are used to store node connectivities of elements and coordinates of nodes, respectively. ne and nd are unknown and will increase in running.
In each computation iteration step, ne and nd are decided until the refined domain is determined.
The mesh is refined and updated by a user-defined function, [element, node] = RefineMesh(element, node, ...), element and node are then updated within:
element = [element, newElem];
Note that preallocation is used for newElem and newNode.
Some other variables are also variable-size, such as energy field values on integration points, these are recreated by preallocation in each iteration:
energy = zeros(4, size(element,2));
I also use parfor to assemble global stiffness matrix over elements. The key procedures of single element stiffness matrix are tranformed to MEX files using codegen. The sparse matrix is recreated in each iteration. GPU computing is also used to solve Ku=F iteratively.
My questions are:
- Why the performance is lower and slower during long-time running athough I follow some approapriate suggestions in Techniques to Improve Performance (such as preallocation and vectorization). To be specific, the assembly time is getting longer.
- Finally, this may lead to out-of-memory error. However, when I exit and restart MATLAB, the computation can continue from where it was last aborted. Note that clear all and delete(gcp('nocreate')) do not work for addressing the out-of-memory error, only exiting and restarting effective. This is very strange.