Importing gmsh mesh file with several subdomains

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Importing gmsh mesh file with several subdomains

ADSW1243
This post was updated on .
Hi there,

I'm interested in making use of the FEA Toolbox. Specifically I'm looking at (initially) solving the vector Poisson equation for the 3D magnetic vector potential across a domain, in the presence of a 3D current source.

Currently from older work I have produced a non-coherent .STEP file defining my geometry. This is then imported to .gmsh. The coherence; command, plus physical groups for each subdomain are used to produce a coherent mesh with a list of domain IDs to identify which elements belong to which subdomain.

The geometry of the entire system can be seen in the figure below, where the internal structure is a current carrying coil with rectangular cross section which is wholly enclosed by a box to form a black-box simulation.
 Geometry

Currently importing grid via a .msh (or .msh2 file if you prefer) works, but the internal subdomain is lost - i.e I get an empty box which prevents me from making progress:
Mesh Import

Alternatively, importing the .STEP gives two sub-domains but I cannot progress to gridding without somehow merging the geometries:
Step Import 

I saw in the documentation that multiple sub-domains are supported in 3D, I'm just unclear on the process to properly import such a geometry. This is key because the internal subdomain contains all source points and I'm mostly interested in the magnetic fields in the space around the 3D coil.

Edit: I have attached an example .STEP and .msh2 file in case recreating this is required to find a solution:
New_Toy_Coil.step
New_Toy_Coil.msh2


Beyond this, I also wondered whether this toolbox can consider the anisotropic form of the vector magnetostatics equation - i.e the del x (1/mu(r)) curl x A = J which would be significantly more interesting to study.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

Precise Simulation
Administrator
This post was updated on .
ADSW1243 wrote
...
I saw in the documentation that multiple sub-domains are supported in 3D, I'm just unclear on the process to properly import such a geometry. This is key because the internal subdomain contains all source points and I'm mostly interested in the magnetic fields in the space around the 3D coil.
I'm not quite sure how you created the mesh but with the command:

    gmsh -merge New_Toy_Coil.step -3 -format msh2

or Gmsh ".geo" file:

    Merge "New_Toy_Coil.step";
    Mesh 3;
    Mesh.MshFileVersion = 2;
    Save "New_Toy_Coil.msh";

I get a mesh that imports the two subdomains fine (please make sure you are using the latest version of FEATool, currently 1.12.1). Sometimes the "-save_all / Mesh.SaveAll = 1;" Gmsh option is also required, but it seems to work fine without it here.

That said, for this fairly straightforward geometry it is recommended to use the built-in CAD tools in the FEATool GUI. It should be sufficient to create two blocks, and subtract a third block from the inner one to create the coil.

ADSW1243 wrote
Beyond this, I also wondered whether this toolbox can consider the anisotropic form of the vector magnetostatics equation - i.e the del x (1/mu(r)) curl x A = J which would be significantly more interesting to study.

Although anisotropic coefficients are currently not pre-defined you can define a custom PDE equation to support this, or modify the existing ones as for example has been done in the orthotropic heat transfer example.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
Thanks for the prompt response: I have the latest version. I'm trailling the gmsh method to I can get to grips trailing it before modelling on more complex systems.

I think I'm mostly struggling with the geometry and import steps but will try running through the documentation and the examples provided for further modelling and get back to you if theres any other problems.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
In reply to this post by Precise Simulation
Hello again,

I'm still having trouble importing the geometry for this simple model. I'm completely certain its an error on my part, but having followed through the examples to the best of my ability I'm not managing to get very far.

I have attached 3 example files which I'm hoping you're able to run. The first two demonstrate my attempts to import the .STEP file, whilst the last shows how importing the mesh produced in GMSH just gives me a solid box.

The aim is to form the intersection as in the example Shinkage Fitting with multiple sub-domains, whilst leaving the coil geometry as a separate subdomain where the currents exist.

 
In my case currently I'm told I need to use a completed geometry to make a mesh if I follow this exactly (Attempt1), whilst using the intersection tool on my two sub-domains (Attempt2) allows me to form a grid, but the result only has a single sub domain which is inadequate for modelling the equations and sources (to the best of my understanding).

Again, I'm fairly certain these are technical problems on my part, so any further advice and guidance is greatly appreciated.


Attempt1.fes
Attempt2.fes
Import_GMSH_Grid.fes
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

Precise Simulation
Administrator
ADSW1243 wrote
I'm still having trouble importing the geometry for this simple model. I'm completely certain its an error on my part, but having followed through the examples to the best of my ability I'm not managing to get very far.
CAD geometry import currently does not support multiple subdomains.

If you used the suggestions above to generate your Gmsh grid you would get a .msh file such as the following:

New_Toy_Coil.msh

which when imported should give you two separate subdomains.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
For the STEP file discussed (consisting of a solid block with the coil placed inside, without any intersection/hole for the coils position), the commands suggested in GMSH produces a mesh with two analytically separated regions (which just so happen to overlap physically). This would be consistent with modelling the box as one complete physical system, and the coil as another complete physical system. The two are not inter-related or connected.

Typically I would use Coherence; after the merge .STEP file to produce a mesh consisting of a single domain. The GMSH physical groups option is then used to relate elements to sub-domains. Following this method produces the type of mesh I would usually work on for FEM modelling.

I have removed this command and indeed I see that the resulting .msh file can be correctly imported to the FEA Tool with two sub-domains. But before I can progress with this there are some concerns to address:

From the mesh generation standpoint, I am now generating two disconnected domains which happen to overlap at some points in space. I'm unsure how then the FEATool would model a coherent system on this disconnected mesh.
Further on this line, the GMSH optimisation procedures no-longer function on the geometry provided, I simply end up with a uniform mesh in each geometric entity because they're no longer connected. Even in the simplest case I would expect some sort of mesh graduation due to the relative size of the universe domain to the source domain.

In short - using your commands I'm telling GMSH that my .STEP consists of two domains. It then meshes the two domains separately and outputs those to the FEATool. This interprets the two domains as sub-domains correctly, but as far as I can tell the mesh it has imported for each region are not connected to each-other, and therefore any resulting analysis will also be disconnected.

If the Tool is interpreting the geometry first, and then forming a new mesh which is appropriate, that is fine but some additional details on what it is actually doing here and how I can control the optimisation would be important before I can decide to press ahead. Careful control of element sizes and shapes can be extremely important in accurate FEM analysis as I'm sure you're aware.

Assuming these concerns can be addressed, I'm looking forward to becoming a helpful member of the FEATool community and hope to have some useful contributions in the future.

Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

Precise Simulation
Administrator
This post was updated on .
Thank you for clarifying, now I understand the issue. I will make an update later in the week to allow processing of multiple CAD objects and other fixes. In the meantime here below follows a rather convoluted workaround:

1) Follow the link at the bottom and register for the FEATool with the COVID-19 license if you have not done so already (Registering will allow you to export geometry objects and use functions on the Matlab command line).

2) Restart FEATool.

3a) Import your geometry and process/decompose it so that no geometry object overlap (meaning make copies smaller objects and subtract them from the bigger ones). Then export the decomposed geometry as an OpenCascade *BREP* format CAD file (for example named "decomposed_geometry.brep").

3b) Alternatively, instead switch to the Matlab command line and run the following equivalent commands (using the geom_analyze function to automate this):

    geom = impexp_cad( 'my_path_to/New_Toy_Coil.step', 'import' );
    geom = geom_analyze( geom );
    impexp_cad( 'decomposed_geometry.brep', 'export', geom );

  decomposed_geometry.brep

4) Create a gmsh .geo file with the following structure and run it in Gmsh (Meshing multiple connected subdomains in Gmsh for import in FEATool will only work if the domains are *non*-overlapping and in the Brep format):

    SetFactory("OpenCASCADE");
    Merge "decomposed_geometry.brep";

    Mesh.CharacteristicLengthExtendFromBoundary = 1;
    Mesh.CharacteristicLengthFromPoints = 1;
    Mesh.CharacteristicLengthFromCurvature = 1;
    Mesh.CharacteristicLengthMin = 0;
    Mesh.CharacteristicLengthMax = 16;
    Mesh.MshFileVersion = 2;
    Mesh.SaveAll = 1;

    Mesh 3;
    Save "my_new_mesh.msh";

  my_new_mesh.msh

5) Switch to Geometry mode and (re-)import your STEP or BREP geometry, and delete all but the *largest* geometry object.

6) Import the newly created mesh. No mesh will appear due to a bug.

7) Switch back to geometry mode and then import the mesh again, and your mesh should appear with coupled subdomains and shared internal boundaries.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
Thanks for the work-around and again rapid response I'm really appreciative. The COVID-19 license is particularly helpful because I'm a student and all my experimental work is now on hold!

I would be interested in following a code-based approach rather than a GUI setup to embed field simulations in some other codes I have already written. Are there any tutorials/suggested workflows in the documentation which are code orientated? I have searched but didn't manage to find anything to guide me through the setup - A look through one of the tutorial .m scripts the setup is quite complex so I would be unsure where to start really. Thanks again.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

Precise Simulation
Administrator
ADSW1243 wrote
I would be interested in following a code-based approach rather than a GUI setup to embed field simulations in some other codes I have already written. Are there any tutorials/suggested workflows in the documentation which are code orientated? I have searched but didn't manage to find anything to guide me through the setup - A look through one of the tutorial .m scripts the setup is quite complex so I would be unsure where to start really.
Aside from the documentation, and m-file script examples, as every GUI action corresponds 1-to-1 to a FEATool Matlab function a good way of learning the script modeling syntax is simply to make a model in the GUI and save/export it as an m-file (using the "Save As MATLAB Script..." option in the "File" menu). Also note that if you wonder what a function does, or the input syntax you can either look in corresponding reference guide entry, for example gridgen, or simply type "help gridgen" at the Matlab command line prompt.
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
I'm trying to follow your workaround, still for the simple system discussed in the initial post. I have produced the .brep file as specified, but the associated GMSH files give an error "Unable to open file". I tried re-importing the created BREP into the FEATool which works fine so I'm a little confused. I have tried the standard: restarting matlab, recreating BREP, restarting GMSH, new script etc but GMSH doesn't seem to like the file.

I have attached the BREP here though I'm not sure how helpful that is given it works inside the toolbox file.





Decomposed_Toy_Coil.brep
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
In reply to this post by Precise Simulation
Interestingly it works if I use the merge option in the GUI so probably a script error I can fix. Thanks for all the help so far!
kth
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

kth
Hi,

I am also trying to mesh subdomain as in your discussion, i have followed the steps to create the .brep file in (3) .

I also created the gmsh.geo file with the instructions as specified, but i cannot  run it in Gmsh. (how can we run this file from GUI? i get the invalid gmsh file format error when tryung to import it)

I see that ADSW1243 used a merge option in the GUI to run the Gmesh and obtain the results.

Can you please specify how because i got lost in the GUI and cannot make it work?
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
Ah that's me not being very clear. In the GMSH app (which I have installed and typically use separately to FEM modelling), go to File, Merge and then you can follow the advised steps.

I found you have to be extremely careful in creating the .BREP exactly as specified, making slight changes to any of the steps will result it it not working.
kth
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

kth
Hi there,

Thanks for  GMSH app, it work fine with the .geo and  my_new_mesh.msh is now created with merge (i can see all the domains/subdomains meshed with gmsh). I imported as specified to step (5) successfully after leaving only the outer geometry/ largest object and deleting the rest. Improrting the .msh will appear no mesh as it is specified in step (6).


However, at the last step yet again only the outer domain of the largest geometry is shown with a grid.  I made sure that the inner object is copied/subtracted from the largest one.

I attach the files if you have any ideas on this.?

decomposed_geometry.brep
gmsh_.geo
my_new_mesh.msh

Also, if the inner part is deleted, then we can set the boundaries conditions of the inner geometry as a heat flux for example, but can we specify its material properties from the Equation tab, since this subdomain is deleted?
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
So for my problem at least, the geometry I re- import is my original .STEP file with the two sub-domains then I will delete the inner one. The .BREP file has a hole where the object was so importing this instead resulting in the behaviour you have suggested.

I'm attempting to setup my equations on the design currently, but I'm using physics which isn't predefined so currently stuck on syntax, I will update you if I learn anything about the boundary conditions thought.
kth
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

kth
Ok, found my error -i guess, i should import in step (5) the objects without being copied/ subtracted. So, when the largest object is only left in step (5) there is no hole due to the smallest (subtracted) geometry.  Importing the mesh from gmsh will automatically create this subdomain. (i,e the copied/ subtracted domains are important for the gmsh but not for re-importing in step(5).)

When saved as a script obviously it is calling the .step file, without being possible to modify the dimension parameters. This is important for my study since i want to loop the geometry and optimize,  by coupling to another matlab script, the outer dimensions. FEATool is perfect since i have not to call any other software and makes it faster and easier to handle. But is there a way to perform the meshing in subdomains as explained above, without calling a step file or gmsh, but only with using the geometry tab from FEATool gui/script?
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
Potentially is possible, it's probably worth making a new post for a new problem!
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

Precise Simulation
Administrator
There is now an updated version which should allow for importing and working with multiple CAD geometries, as well as improved Gmsh import (so that the workaround above not is necessary anymore):

https://github.com/precise-simulation/featool-multiphysics/releases/tag/1.12.2
kth
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

kth
Hi, thanks for the update and sharp replies. New questions that just arrived with 1.12.2 ;

Skipping the workaround with gmsh, i created two simple case in order to address my error:

First case (un-joined_overlapping_external) two geometries that overlap each other, and without merging them (copy/subtract). They are perfectly decomposed into subdomains during meshing, also Equation gives option to define objects individually, also Boundary can be set without any interior boundaries.
This is exactly what i try to do with a second case (un-joined_overlapping_internal), where the one geometry is completely overlapping the other, as discussed above with the New_Toy_Coil.step. I dont understand how, but i mess it up and the same error keep coming: Only the outer domain is meshed, (in the Equation are available to define but Boundary of the inner geometry have become interior which is not allowing eventually to have a heat flux from the inner domain. (such as a circuit that produced heat losses based on a load profile/ heat-source and the outer domain represents the convection air (free and forced convection) - It is similar to the heat exchanger tutorial example (https://www.featool.com/doc/multiphysics_00_heat_exchanger1) but for 3D.

How can we have the same behavior of case 1, for a complete interior geometry as in case 2?

un-joined_overlapping_external.fea
un-joined_overlapping_internal.fea
Reply | Threaded
Open this post in threaded view
|

Re: 3D Magnetostatics in the presence of a current source.

ADSW1243
In reply to this post by Precise Simulation
Does the new update alter the process I need to follow here? I'm unsure if the new update still requires the workaround or if I need to follow a different method now?
12