CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Gmsh] Patches in GmshToFoam (https://www.cfd-online.com/Forums/openfoam-meshing/106777-patches-gmshtofoam.html)

hannes September 7, 2012 15:07

Patches in GmshToFoam
 
1 Attachment(s)
Hello,

Recently, I have noticed that the "physical surfaces" in gmsh are not properly preserved when the msh file is converted into an OpenFOAM-mesh. All boundary patches end up in the same "default"-patch.

I was using OpenFOAM-1.6-ext and gmsh 2.6.2.
I have also noticed, that this issue is fixed in OF-2.1.x.

I have backported the changes. For those, that are bothered by this issue, here is a patch.

kanuk October 11, 2012 12:42

Thanks very much for the patch - just what I was looking for!

Hisham February 15, 2013 14:57

Thanks Hannes!

fportela March 7, 2013 09:25

missing elements
 
3 Attachment(s)
Hello everyone!

I ran into the issue of missing surfaces when converting from Gmsh to OpenFOAM.

When I use gmshToFoam I get this warning first:

Code:

--> FOAM Warning :
    From function polyMesh::polyMesh(... construct from shapes...)
    in file meshes/polyMesh/polyMeshFromShapeMesh.C at line 619
    Found 3108 undefined faces in mesh; adding to default patch.

And then for each patch it reads I get warnings like:

Code:

--> FOAM Warning :
    From function gmshToFoam
    in file gmshToFoam.C at line 968
    Could not match gmsh face 3(26 346 347) to any of the interior or exterior faces that share the same 0th point

The output mesh will be missing some elements on the surfaces (see attached figures). Figure in_out_gmsh.png displays three (physical) surfaces in Gmsh which I call "inlet", "outlet" and "bottom", Figure in_out_bot_para.png displays this same surfaces after conversion with gmshToFoam. The converter seems to store all the missing faces in a single patch called defaultFaces which you can see in figure defaultFaces.png.

I noticed that the only the faces in the structured part of the mesh are missing.

I tried applying the patch but the problem didn't go away... Any ideas/suggestions on how to go about this?

Hisham March 7, 2013 09:36

Hello fportela

The "defaultFaces" empty patch is the patch that includes all Gmsh surfaces that are not assigned to a physical surface. You need to make sure that all surfaces in Gmsh are assigned to physical surfaces unless you need the surface to be an empty patch.

It is useful if you mention which OpenFOAM and which Gmsh are you using. If you have further problems, it is a good idea to attach your .geo file

Hisham

fportela March 7, 2013 09:52

Hi Hisham,

Thanks for the quick reply!

Yes I noticed that defaultFaces contains all the missing information. If you look at the figure in_out_bot_gmsh I attached in the previous post, each surface is defined as a physical surface and that is how I select them for display. Analogously, after conversion, I pick the same surfaces (now using paraView) for display, but now some elements are missing on those surfaces (it's like some surface elements don't belong to the surface itself).

I am using Gmsh version 2.6.2 and I have OpenFOAM 2.1.1

Hisham March 7, 2013 10:05

I only had problems with internal surfaces in OpenFOAM-2.1 gmshToFoam and it was only assigning the wrong name (It is fixed on the wiki page). So if you sure that you have assigned all surfaces and volumes in Gmsh to physical entities then maybe you can attach or post the ".geo" file!

fportela March 7, 2013 12:04

Hey Hisham,

I have attached the .geo I'm using for the mesh.

I noticed that the issue is probably related with the regions where I do the structured mesh, though I don't understand what exactly is going on...

EDIT: I just noticed that for some reason I can't really upload the .geo so I posted it below:

Code:

h = 0.002;

cl_MR = h/5;
cl_buffer_bottom = 10*h;
cl_buffer_upper = 20*h;

n_inlet = 4;
n_outlet = n_inlet;

n_upstream_sides = 16;
n_downstream_sides = n_upstream_sides;

bufferu_to_MR = 2.5*h;
bufferd_to_MR = 2.5*h+7.5*h*Cos(24*Pi/180);

height = 30*h;
width = 30*h;
inlet_to_VG = 150*h;
length = 300*h;

// Vortex generator points

p_aft_bottom = newp;
Point(p_aft_bottom) = {7.5*h*Cos(24*Pi/180),0,0,cl_MR};
p_aft_upper = newp;
Point(p_aft_upper) = {7.5*h*Cos(24*Pi/180),0,h,cl_MR};
p_nose_front = newp;
Point(p_nose_front) = {0,-7.5*h*Sin(24*Pi/180),0,cl_MR};
p_nose_back = newp;
Point(p_nose_back) = {0,7.5*h*Sin(24*Pi/180),0,cl_MR};

// Domain points

p_inlet_bottom_back = newp;
Point(p_inlet_bottom_back) = {-inlet_to_VG,width/2,0};
p_inlet_bottom_front = newp;
Point(p_inlet_bottom_front) = {-inlet_to_VG,-width/2,0};
p_inlet_upper_back = newp;
Point(p_inlet_upper_back) = {-inlet_to_VG,width/2,height};
p_inlet_upper_front = newp;
Point(p_inlet_upper_front) = {-inlet_to_VG,-width/2,height};
p_outlet_bottom_back = newp;
Point(p_outlet_bottom_back) = {length-inlet_to_VG,width/2,0};
p_outlet_bottom_front = newp;
Point(p_outlet_bottom_front) = {length-inlet_to_VG,-width/2,0};
p_outlet_upper_back = newp;
Point(p_outlet_upper_back) = {length-inlet_to_VG,width/2,height};
p_outlet_upper_front = newp;
Point(p_outlet_upper_front) = {length-inlet_to_VG,-width/2,height};

// Upstream mesh buffer points

p_buffu_bottom_back = newp;
Point(p_buffu_bottom_back ) = {-bufferu_to_MR,width/2,0,cl_buffer_upper};
p_buffu_bottom_front = newp;
Point(p_buffu_bottom_front) = {-bufferu_to_MR,-width/2,0,cl_buffer_upper};
p_buffu_upper_back = newp;
Point(p_buffu_upper_back) = {-bufferu_to_MR,width/2,height,cl_buffer_upper};
p_buffu_upper_front = newp;
Point(p_buffu_upper_front) = {-bufferu_to_MR,-width/2,height,cl_buffer_upper};

// Downstream mesh buffer points

p_buffd_bottom_back = newp;
Point(p_buffd_bottom_back ) = {bufferd_to_MR,width/2,0,cl_buffer_bottom};
p_buffd_bottom_front = newp;
Point(p_buffd_bottom_front) = {bufferd_to_MR,-width/2,0,cl_buffer_bottom};
p_buffd_upper_back = newp;
Point(p_buffd_upper_back) = {bufferd_to_MR,width/2,height,cl_buffer_bottom};
p_buffd_upper_front = newp;
Point(p_buffd_upper_front) = {bufferd_to_MR,-width/2,height,cl_buffer_bottom};

// Inlet lines

l_in_bottom = newl+100;
Line(l_in_bottom) = {p_inlet_bottom_back,p_inlet_bottom_front};
l_in_upper = newl+100;
Line(l_in_upper) = {p_inlet_upper_back,p_inlet_upper_front};
l_in_front = newl+100;
Line(l_in_front) = {p_inlet_bottom_front,p_inlet_upper_front};
l_in_back = newl+100;
Line(l_in_back) = {p_inlet_bottom_back,p_inlet_upper_back};

// Outlet lines

l_out_bottom = newl+100;
Line(l_out_bottom) = {p_outlet_bottom_back,p_outlet_bottom_front};
l_out_upper = newl+100;
Line(l_out_upper) = {p_outlet_upper_back,p_outlet_upper_front};
l_out_front = newl+100;
Line(l_out_front) = {p_outlet_bottom_front,p_outlet_upper_front};
l_out_back = newl+100;
Line(l_out_back) = {p_outlet_bottom_back,p_outlet_upper_back};


// Downstream mesh buffer outlet lines

l_buffd_bottom = newl+100;
Line(l_buffd_bottom) = {p_buffd_bottom_back,p_buffd_bottom_front};
l_buffd_upper = newl+100;
Line(l_buffd_upper) = {p_buffd_upper_back,p_buffd_upper_front};
l_buffd_front = newl+100;
Line(l_buffd_front) = {p_buffd_bottom_front,p_buffd_upper_front};
l_buffd_back = newl+100;
Line(l_buffd_back) = {p_buffd_bottom_back,p_buffd_upper_back};

// Upstream mesh buffer inlet lines

l_buffu_bottom = newl+100;
Line(l_buffu_bottom) = {p_buffu_bottom_back,p_buffu_bottom_front};
l_buffu_upper = newl+100;
Line(l_buffu_upper) = {p_buffu_upper_back,p_buffu_upper_front};
l_buffu_front = newl+100;
Line(l_buffu_front) = {p_buffu_bottom_front,p_buffu_upper_front};
l_buffu_back = newl+100;
Line(l_buffu_back) = {p_buffu_bottom_back,p_buffu_upper_back};

// Upstream sides lines

l_ups_bottom_front = newl+100;
Line(l_ups_bottom_front) = {p_buffu_bottom_front,p_inlet_bottom_front};
l_ups_upper_front = newl+100;
Line(l_ups_upper_front) = {p_buffu_upper_front,p_inlet_upper_front};
l_ups_bottom_back = newl+100;
Line(l_ups_bottom_back) = {p_buffu_bottom_back,p_inlet_bottom_back};
l_ups_upper_back = newl+100;
Line(l_ups_upper_back) = {p_buffu_upper_back,p_inlet_upper_back};

// Downstream sides lines

l_downs_bottom_front = newl+100;
Line(l_downs_bottom_front) = {p_buffd_bottom_front,p_outlet_bottom_front};
l_downs_upper_front = newl+100;
Line(l_downs_upper_front) = {p_buffd_upper_front,p_outlet_upper_front};
l_downs_bottom_back = newl+100;
Line(l_downs_bottom_back) = {p_buffd_bottom_back,p_outlet_bottom_back};
l_downs_upper_back = newl+100;
Line(l_downs_upper_back) = {p_buffd_upper_back,p_outlet_upper_back};

// Micro ramp lines

l_MR_nose = newl+100;
Line(l_MR_nose) = {p_nose_front,p_nose_back};
l_MR_vertical = newl+100;
Line(l_MR_vertical) = {p_aft_bottom,p_aft_upper};
l_MR_front_bottom = newl+100;
Line(l_MR_front_bottom) = {p_nose_front,p_aft_bottom};
l_MR_back_bottom = newl+100;
Line(l_MR_back_bottom) = {p_nose_back,p_aft_bottom};
l_MR_front_upper = newl+100;
Line(l_MR_front_upper) = {p_nose_front,p_aft_upper};
l_MR_back_upper = newl+100;
Line(l_MR_back_upper) = {p_nose_back,p_aft_upper};

// Connection between buffers lines

l_buffers_front_bottom = newl+100;
Line(l_buffers_front_bottom) = {p_buffu_bottom_front,p_buffd_bottom_front};
l_buffers_front_upper = newl+100;
Line(l_buffers_front_upper) = {p_buffu_upper_front,p_buffd_upper_front};
l_buffers_back_bottom = newl+100;
Line(l_buffers_back_bottom) = {p_buffu_bottom_back,p_buffd_bottom_back};
l_buffers_back_upper = newl+100;
Line(l_buffers_back_upper) = {p_buffu_upper_back,p_buffd_upper_back};

// Inlet surface

ll_inlet = newll;
Line Loop(ll_inlet) = {l_in_bottom,-l_in_upper,l_in_front,-l_in_back};
s_inlet = news;
Plane Surface(s_inlet) = {ll_inlet};

// Outlet surface

ll_outlet = newll;
Line Loop(ll_outlet) = {-l_out_bottom,l_out_upper,-l_out_front,l_out_back};
s_outlet = news;
Plane Surface(s_outlet) = {ll_outlet};

// Upstream surfaces;

ll_ups_front = newll;
Line Loop(ll_ups_front) = {-l_ups_bottom_front,-l_in_front,l_ups_upper_front,l_buffu_front};
s_ups_front = news;
Plane Surface(s_ups_front) = {ll_ups_front};

ll_ups_back = newll;
Line Loop(ll_ups_back) = {l_ups_bottom_back,l_in_back,-l_ups_upper_back,-l_buffu_back};
s_ups_back = news;
Plane Surface(s_ups_back) = {ll_ups_back};

ll_ups_bottom = newll;
Line Loop(ll_ups_bottom) = {l_ups_bottom_front,-l_ups_bottom_back,-l_in_bottom,l_buffu_bottom};
s_ups_bottom = news;
Plane Surface(s_ups_bottom) = {ll_ups_bottom};

ll_ups_upper = newll;
Line Loop(ll_ups_upper) = {l_ups_upper_front,-l_ups_upper_back,-l_in_upper,l_buffu_upper};
s_ups_upper = news;
Plane Surface(s_ups_upper) = {ll_ups_upper};

// Downstream surfaces;

ll_downs_front = newll;
Line Loop(ll_downs_front) = {l_downs_bottom_front,l_out_front,-l_downs_upper_front,-l_buffd_front};
s_downs_front = news;
Plane Surface(s_downs_front) = {ll_downs_front};

ll_downs_back = newll;
Line Loop(ll_downs_back) = {-l_downs_bottom_back,-l_out_back,l_downs_upper_back,l_buffd_back};
s_downs_back = news;
Plane Surface(s_downs_back) = {ll_downs_back};

ll_downs_bottom = newll;
Line Loop(ll_downs_bottom) = {-l_downs_bottom_front,l_downs_bottom_back,l_out_bottom,-l_buffd_bottom};
s_downs_bottom = news;
Plane Surface(s_downs_bottom) = {ll_downs_bottom};

ll_downs_upper = newll;
Line Loop(ll_downs_upper) = {l_downs_upper_front,-l_downs_upper_back,-l_out_upper,l_buffd_upper};
s_downs_upper = news;
Plane Surface(s_downs_upper) = {ll_downs_upper};

// Upstream mesh buffer inlet surface

ll_buffu = newll;
Line Loop(ll_buffu) = {l_buffu_bottom,-l_buffu_upper,l_buffu_front,-l_buffu_back};
s_buffu = news;
Plane Surface(s_buffu) = {ll_buffu};

// Downstream mesh buffer outlet surface

ll_buffd = newll;
Line Loop(ll_buffd) = {l_buffd_bottom,-l_buffd_upper,l_buffd_front,-l_buffd_back};
s_buffd = news;
Plane Surface(s_buffd) = {ll_buffd};

// Connection between buffers surfaces

ll_connbuffs_upper = newll;
Line Loop(ll_connbuffs_upper) = {l_buffers_front_upper,-l_buffd_upper,-l_buffers_back_upper,l_buffu_upper};
s_connbuffs_upper = news;
Plane Surface(s_connbuffs_upper) = {ll_connbuffs_upper};

ll_MR_hole = newll;
Line Loop(ll_MR_hole) = {l_MR_nose,l_MR_back_bottom,-l_MR_front_bottom};
ll_connbuffs_bottom = newll;
Line Loop(ll_connbuffs_bottom) = {-l_buffers_front_bottom,l_buffd_bottom,l_buffers_back_bottom,-l_buffu_bottom};
s_connbuffs_bottom = news;
Plane Surface(s_connbuffs_bottom) = {ll_connbuffs_bottom,ll_MR_hole};

ll_connbuffs_front = newll;
Line Loop(ll_connbuffs_front) = {l_buffers_front_bottom,l_buffd_front,-l_buffers_front_upper,-l_buffu_front};
s_connbuffs_front = news;
Plane Surface(s_connbuffs_front) = {ll_connbuffs_front};

ll_connbuffs_back = newll;
Line Loop(ll_connbuffs_back) = {-l_buffers_back_bottom,-l_buffd_back,l_buffers_back_upper,l_buffu_back};
s_connbuffs_back = news;
Plane Surface(s_connbuffs_back) = {ll_connbuffs_back};

// Micro ramp surfaces

ll_MR_upper = newll;
Line Loop(ll_MR_upper) = {l_MR_nose,l_MR_back_upper,-l_MR_front_upper};
s_MR_upper = news;
Plane Surface(s_MR_upper) = {ll_MR_upper};

ll_MR_front = newll;
Line Loop(ll_MR_front) = {-l_MR_vertical,-l_MR_front_bottom,l_MR_front_upper};
s_MR_front = news;
Plane Surface(s_MR_front) = {ll_MR_front};

ll_MR_back = newll;
Line Loop(ll_MR_back) = {l_MR_vertical,l_MR_back_bottom,-l_MR_back_upper};
s_MR_back = news;
Plane Surface(s_MR_back) = {ll_MR_back};

// Upstream volume

sl_ups = newsl;
Surface Loop(sl_ups) = {s_buffu,s_ups_front,s_ups_back,s_ups_bottom,s_ups_upper,-s_inlet};
v_ups = newv;
Volume(v_ups) = {sl_ups};

// Downstream volume

sl_downs = newsl;
Surface Loop(sl_downs) = {s_buffd,s_downs_front,s_downs_back,s_downs_bottom,s_downs_upper,s_outlet};
v_downs = newv;
Volume(v_downs) = {sl_downs};

// Near MR volume

sl_between_buffers = newsl;
Surface Loop(sl_between_buffers) = {s_connbuffs_upper,s_connbuffs_bottom,s_connbuffs_front,s_connbuffs_back,s_buffu,s_buffd,s_MR_upper,s_MR_front,s_MR_back};
v_between_buffers = newv;
Volume(v_between_buffers) = {sl_between_buffers};

// Mesh upstream

Transfinite Line {-l_ups_bottom_front,l_ups_upper_front,l_ups_bottom_back,-l_ups_upper_back} = n_upstream_sides ;
Transfinite Line {l_buffu_bottom,l_buffu_upper,l_buffu_front,-l_buffu_back,l_in_bottom,l_in_upper,-l_in_front,l_in_back} = n_inlet;
Transfinite Surface {s_buffu,s_ups_front,s_ups_back,s_ups_bottom,s_ups_upper,s_inlet} = {} Alternate;
Transfinite Volume {v_ups};

// Mesh downstream

Transfinite Line {l_downs_bottom_front,-l_downs_upper_front,-l_downs_bottom_back,l_downs_upper_back} = n_downstream_sides ;
Transfinite Line {l_buffd_bottom,l_buffd_upper,-l_buffd_front,l_buffd_back,l_out_bottom,l_out_upper,l_out_front,-l_out_back} = n_outlet;
Transfinite Surface {s_buffd,s_downs_front,s_downs_back,s_downs_bottom,s_downs_upper,s_outlet} = {} Alternate;
Transfinite Volume {v_downs};

// Periodic sides

Periodic Surface s_ups_front {-l_ups_bottom_front,-l_in_front,l_ups_upper_front,l_buffu_front} = s_ups_back {l_ups_bottom_back,l_in_back,-l_ups_upper_back,-l_buffu_back};

Periodic Surface s_downs_front {l_downs_bottom_front,l_out_front,-l_downs_upper_front,-l_buffd_front} = s_downs_back {-l_downs_bottom_back,-l_out_back,l_downs_upper_back,l_buffd_back};

Periodic Surface s_connbuffs_front {l_buffers_front_bottom,l_buffd_front,l_buffers_front_upper,l_buffu_front} = s_connbuffs_back {l_buffers_back_bottom,l_buffd_back,l_buffers_back_upper,l_buffu_back};


//Periodic Surface s_inlet {l_in_bottom,l_in_upper,l_in_front,l_in_back} = s_outlet {l_out_bottom,l_out_upper,l_out_back,l_out_front};

Mesh.Optimize=1;
Mesh.OptimizeNetgen=1;

Physical Volume("volume") = {v_between_buffers,v_downs,v_ups};
Physical Surface("microramp") = {s_MR_upper,s_MR_back,s_MR_front};
Physical Surface("inlet") = {s_inlet};
Physical Surface("outlet") = {s_outlet};
Physical Surface("top") = {s_connbuffs_upper,s_downs_upper,s_ups_upper};
Physical Surface("front") = {s_connbuffs_front,s_downs_front,s_ups_front};
Physical Surface("back") = {s_connbuffs_back,s_downs_back,s_ups_back};
Physical Surface("bottom") = {s_connbuffs_bottom,s_downs_bottom,s_ups_bottom};


fportela March 8, 2013 05:14

I have noticed that this issue depends on how the transfinite surface is done. It seems like for some surfaces using the Right alignment results in the surface not being properly stored while for others this happens with the Left alignment; using the Alternate alignment (as I was trying) therefore results in parts of the surfaces disappearing during the conversion...

So, any idea on how to solve this?

I managed to get a successful conversion by making the surfaces transfinite as below:

Code:

// Mesh upstream

Transfinite Line {-l_ups_bottom_front,l_ups_upper_front,l_ups_bottom_back,-l_ups_upper_back} = n_upstream_sides ;
Transfinite Line {l_buffu_bottom,l_buffu_upper,l_buffu_front,-l_buffu_back,l_in_bottom,l_in_upper,-l_in_front,l_in_back} = n_inlet;
Transfinite Surface {s_buffu} = {} Left;
Transfinite Surface {s_ups_front} = {} Left;
Transfinite Surface {s_ups_back} = {} Left;
Transfinite Surface {s_ups_bottom} = {} Right;
Transfinite Surface {s_ups_upper} = {} Right;
Transfinite Surface {s_inlet} = {} Left;
Transfinite Volume {v_ups};

// Mesh downstream

Transfinite Line {l_downs_bottom_front,-l_downs_upper_front,-l_downs_bottom_back,l_downs_upper_back} = n_downstream_sides ;
Transfinite Line {l_buffd_bottom,l_buffd_upper,-l_buffd_front,l_buffd_back,l_out_bottom,l_out_upper,l_out_front,-l_out_back} = n_outlet;
Transfinite Surface {s_buffd} = {} Left;
Transfinite Surface {s_downs_front} = {} Left;
Transfinite Surface {s_downs_back} = {} Left;
Transfinite Surface {s_downs_bottom} = {} Right;
Transfinite Surface {s_downs_upper} = {} Right;
Transfinite Surface {s_outlet} = {} Left;
Transfinite Volume {v_downs};


Hisham March 8, 2013 06:02

Hi

I think you are totally right. What happens is that some command you apply on the surfaces actually creates new surfaces out of them. You can check that in the ".msh" file as you have geometrical surfaces with tags like 3436 for your triangle elements with type (2). And because the physical surfaces are assigned to much fewer number they are assigned to default. So maybe try without the alternate command!

just:

Code:

Transfinite Surface {s_buffu,s_ups_front,s_ups_back,s_ups_bottom,s_ups_upper,s_inlet};

Another thing you have very strange elements near the microramp patch (very high aspect ratio) they are not a problem now but I think they will give some hard time with conversion.

Hisham

Hisham March 8, 2013 06:09

I see you have solved that already :D

fportela March 8, 2013 08:01

It's not really a solution since the cells don't look as I wanted them to, but I guess this will have to work for now :)

Thanks for the help!


All times are GMT -4. The time now is 20:22.