lyc102 / ifem

iFEM is a MATLAB software package containing robust, efficient, and easy-following codes for the main building blocks of adaptive finite element methods on unstructured simplicial grids in both two and three dimensions.
https://lyc102.github.io/ifem/
GNU General Public License v3.0
185 stars 73 forks source link

Output argument "isBdNode" (and possibly others) not assigned a value in the execution with "gradmatrix" function. #10

Closed litaihe closed 8 months ago

litaihe commented 10 months ago

when I run the example\fem\Maxwell\Maxwell3ND0femrate.m, the fellowing error will appear

Output argument "isBdNode" (and possibly others) not assigned a value in
the execution with "gradmatrix" function.

Error in mgMaxwell (line 79)
[grad,isBdNode] = gradmatrix(edge,isBdEdge);

Error in Maxwell (line 393)
    [u,info] = mgMaxwell(bigAD,f,AP,node,elemold,edge,HB,option);

Error in femMaxwell3 (line 60)
                [u,edge,eqn,info] = Maxwell(node,elem,bdFlag,pde,option);

Error in Maxwell3ND0femrate (line 39)
femMaxwell3(mesh,pde,option);

this error will be resolved when I make the following changes to the file solver/gradmatrix.m

@@ -28,5 +28,6 @@ if any(isBdEdge) % no grad on boundary edges
    idx = ~(isBdEdge(i) | isBdNode(j)); 
else
    idx = 1:length(i);
    isBdNode = false(N,1);
end
grad = sparse(i(idx),j(idx),s(idx),NE,N);

is the modification reasonable? thank you.

scaomath commented 10 months ago

Your fix is technically correct, since the Neumann type BC counts the ND0 bases' coeffs on boundary edges as DoF (not fixed values), there is no BdNode (fixed valued nodes) and all the nodes on the boundary should go into the transfer matrix.

However, a better coding practice is to set isBdNode outside the if-else conditionals in front of the lines 24

https://github.com/lyc102/ifem/blob/29f31c812001ca8d93dad08e67208ca60e8716d4/solver/gradmatrix.m#L24-L31

Please submit a PR to fix this following my suggestion, is possible, please include your university/advisor and what project you are currently working on using ifem.

scaomath commented 8 months ago

Fixed in #12