Skip to content

Commit ce8e3a2

Browse files
committed
Improves COMSOL mesh import.
1 parent 0d323e7 commit ce8e3a2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

FEMAddOns/ImportMesh/Kernel/ImportMesh.m

+17-8
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ This is because low level helper functions (e.g. getNodes) are doing same things
219219

220220
(* Spatial dimensions of the problem. *)
221221
sDim=Last@Dimensions[nodes];
222+
223+
If[ !(sDim === 3 || sDim === 2 || sDim === 1), Return[ $Failed, Module]];
222224

223225
point=Cases[allElements,PointElement[__],2];
224226
line=Cases[allElements,LineElement[__],2];
225227
surface=Cases[allElements,TriangleElement[__]|QuadElement[__],2];
226228
solid=Cases[allElements,TetrahedronElement[__]|HexahedronElement[__],2];
227-
229+
228230
(* If number of dimensions is 3 but no solid elements are specified,
229231
then we use ToBoundaryMesh to create ElementMesh. And similarly for 2 dimensions. *)
230232
If[
@@ -559,8 +561,8 @@ extract element topology (e.g. HexahedronElement) and its order from element typ
559561

560562
getNodes[list_]:=Module[
561563
{noNodes,start,listOfStrings},
562-
noNodes=getNumber[list," # number of mesh points"];
563-
start=getPosition[list,"# Mesh point coordinates"];
564+
noNodes=getNumber[list," # number of mesh points"|" # number of mesh vertices"];
565+
start=getPosition[list,"# Mesh point coordinates"|"# Mesh vertex coordinates"];
564566
listOfStrings=Join@@MapThread[
565567
Take[list,{#1+1,#1+#2}]&,
566568
{start,noNodes}
@@ -595,10 +597,17 @@ extract element topology (e.g. HexahedronElement) and its order from element typ
595597
getElements[list_,type_,length_,startElement_,startDomain_]:=With[
596598
{head=type/.switchType},
597599
{
598-
head[
599-
(* +1 because node counting starts from 0 *)
600-
(modification[type,#]&/@takeLines[list,startElement,length])+1,
601-
Flatten@takeLines[list,startDomain,length]
600+
If[ startDomain === 0,
601+
head[
602+
(* +1 because node counting starts from 0 *)
603+
(modification[type,#]&/@takeLines[list,startElement,length])+1
604+
]
605+
,
606+
head[
607+
(* +1 because node counting starts from 0 *)
608+
(modification[type,#]&/@takeLines[list,startElement,length])+1,
609+
Flatten@takeLines[list,startDomain,length]
610+
]
602611
]
603612
}
604613
];
@@ -632,11 +641,11 @@ extract element topology (e.g. HexahedronElement) and its order from element typ
632641
(* I think both "Domains" and "Geometric entity indices" can be considered as markers. *)
633642
startMarkers=getPosition[list,"# Domains"|"# Geometric entity indices"];
634643
If[ret==="MeshMarkers", Return[startMarkers]];
644+
If[startMarkers === {}, startMarkers = ConstantArray[0, {Length[types]}]];
635645

636646
nodes=getNodes[list];
637647
If[ret==="MeshNodes", Return[nodes]];
638648

639-
640649
allElements=MapThread[
641650
getElements[list,#1,#2,#3,#4]&,
642651
{types,lengths,startElements,startMarkers}

0 commit comments

Comments
 (0)