New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags...

20
Third Gmsh Workshop - Lanzarote March 29-31, 2017 New CAD features, Gmsh 3.0 and API C. Geuzaine University of Liège, Belgium 1

Transcript of New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags...

Page 1: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

NewCADfeatures,Gmsh3.0andAPIC.Geuzaine

UniversityofLiège,Belgium

1

Page 2: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 2

First,ali<lebitofhistory

• Gmshwasstartedin1996,asatoyprojectbyJFandmyself• Firstpublicreleasein1998• OpenSource(GNUGPL)in2003• Gmsh2.0in2006• IJNMEpaperandswitchtoCMakein2009• Pythonwrappersin2011• Curvilinearmeshing:2012–• Quad-Hexmeshing:2012–• Homology:2013–• Parallelmeshing:2015–• NewCADinterfaceandswitchtoGit/Gitlab:2017

Page 3: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 3

First,ali<lebitofhistory

• Today,Gmshrepresentsabout400klinesofC++code

• sdllsame2coredevelopers;about100with>=1commit

• about1,000peopleonmailinglists

• about10,000downloadspermonth(75%Windows)

• about400citadonsperyear–theGmshpaperiscitedabout2,200dmes

• Gmshprobablyoneofthemostpopularopensourcefiniteelementmeshgeneratorintheworld?

Page 4: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 4

FirstworkshopheldinBraives,September15-16,2011

hkps://gitlab.onelab.info/gmsh/gmsh/wikis/FirstGmshWorkshop

First,ali<lebitofhistory

Page 5: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 5

SecondworkshopheldinMoressée,May23-24,2013

hkps://gitlab.onelab.info/gmsh/gmsh/wikis/SecondGmshWorkshop

First,ali<lebitofhistory

Page 6: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 6

First,ali<lebitofhistory

Page 7: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• ThewholeinternalCADinterfacehasbeenrewritenoverthelast2months

• GEO_Internalsinterfacesallthelegacyfeaturesofthebuilt-inGmshCADengine

• OCC_Internalsinterfacestop-levelOpenCASCADEfeatures,includingbooleanoperadons

• AllCADoperadonsarehandledinternallyintheseclasses;theonlyfuncdonthatinteractswithGModelissynchronize(GModel *)

• The.geofileparserhasbeenrewrikentoonlyusetheGEO_Internal/OCC_InternalAPI

• ThisAPIdoesnotexposeanystructuresorclasses:onlyint,double,string,pairandvector

7

NewCADfeatures

Page 8: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 8

NewCADfeaturesclass GEO_Internals{ public: // add shapes bool addVertex(int num, double x, double y, double z, double lc); bool addLine(int num, int startTag, int endTag); bool addCircleArc(int num, int startTag, int centerTag, int EndTag, double nx=0., double ny=0., double nz=0.); bool addBSpline(int num, const std::vector<int> &vertexTags); bool addLineLoop(int num, const std::vector<int> &edgeTags); bool addPlaneSurface(int num, const std::vector<int> &wireTags); ... // extrude and revolve bool extrude(const std::vector<std::pair<int, int> > &inDimTags, double dx, double dy, double dz, std::vector<std::pair<int, int> > &outDimTags); ... // apply transformations bool translate(const std::vector<std::pair<int, int> > &dimTags, double dx, double dy, double dz); ... // remove bool remove(const std::vector<std::pair<int, int> > &dimTags, bool recursive=false); ... // synchronize internal CAD data with the given GModel void synchronize(GModel *model); ...}

Page 9: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 9

NewCADfeaturesclass OCC_Internals{ public: // add shapes bool addVertex(int tag, double x, double y, double z, double meshSize=MAX_LC); bool addLine(int tag, int startTag, int endTag); ... bool addSphere(int tag, double xc, double yc, double zc, double radius, double angle1, double angle2, double angle3); bool addThruSections(int tag, const std::vector<int> &wireTags, std::vector<std::pair<int, int> > &outDimTags, bool makeSolid, bool makeRuled); ... // extrude and revolve bool extrude(const std::vector<std::pair<int, int> > &inDimTags, double dx, double dy, double dz, std::vector<std::pair<int, int> > &outDimTags); ... // apply boolean operator bool applyBooleanOperator(int tag, BooleanOperator op, const std::vector<std::pair<int, int> > &objectDimTags, const std::vector<std::pair<int, int> > &toolDimTags, std::vector<std::pair<int, int> > &outDimTags, bool removeObject, bool removeTool); ... // synchronize internal CAD data with the given GModel void synchronize(GModel *model);}

Page 10: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• Somemeshingconstraintsarestoredin{GEO,OCC}_Internals(theymustcanbecopiedaround),butmosthavebeenmoveddirectlytoGModel

• GEO_Internalsisalwaysallocated;OCC_Internalsisonlycreatedon-demand(evenifGmshiscompiledwithOCCsupport)

• In.geofiles

• SwitchbetweeninternalCADmodelers:SetFactory("name")

• Currently:"Built-in"or"OpenCASCADE"

• Forceasynchronizadon:SyncModel

• Bydefault:"Built-in"

• 99.99%backwardcompadblewithexisdng.geofiles10

NewCADfeatures

• Knownincompadbilides:embeddedenddesarenowcreatedonlyinGModel

Page 11: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• Allexisdng.geocommandsareconserved• Newormodified.geocommands:• Shapes(withexplicitnumbering):Circle, Ellipse, Wire,

Surface, Sphere, Block, Torus, Rectangle, Disk, Cylinder, Cone, Wedge, ThickSolid, ThruSections, Ruled ThruSections

• Operadons(implicitnumbering):ThruSections, Ruled ThruSections, Fillet, Extrude

• Booleanoperadons(explicitorimplicitnumbering):BooleanUnion, BooleanIntersection, BooleanDifference, BooleanFragments

• Other:ShapeFromFile, Recursive Delete, In Surface, In Volume

11

NewCADfeatures

Page 12: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 12

NewCADfeatures

hkp://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/boolean/boolean.geo

Page 13: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 13

NewCADfeatures

SetFactory("OpenCASCADE");

// from http://en.wikipedia.org/wiki/Constructive_solid_geometry

R = DefineNumber[ 1.4 , Min 0.1, Max 2, Step 0.01, Name "Parameters/Block dimension" ];Rs = DefineNumber[ R*.7 , Min 0.1, Max 2, Step 0.01, Name "Parameters/Cylinder radius" ];Rt = DefineNumber[ R*1.25, Min 0.1, Max 2, Step 0.01, Name "Parameters/Sphere radius" ];

Block(1) = {-R,-R,-R, R,R,R};

Sphere(2) = {0,0,0,Rt};

BooleanIntersection(3) = { Volume{1}; Delete; }{ Volume{2}; Delete; };

Cylinder(4) = {-2*R,0,0, 2*R,0,0, Rs};Cylinder(5) = {0,-2*R,0, 0,2*R,0, Rs};Cylinder(6) = {0,0,-2*R, 0,0,2*R, Rs};

BooleanUnion(7) = { Volume{4}; Delete; }{ Volume{5,6}; Delete; };BooleanDifference(8) = { Volume{3}; Delete; }{ Volume{7}; Delete; };

SetOpenCASCADEinternalCADmodeler

Explicittags Deleteobjectandtool

Page 14: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 14

NewCADfeatures

hkp://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/boolean/import.geo

Page 15: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 15

NewCADfeatures

SetFactory("OpenCASCADE");

DefineConstant[ z = {16, Name "Parameters/z position of block"} sph = {0, Choices{0,1}, Name "Parameters/Add sphere?"}];

a() = ShapeFromFile("component8.step");b() = 2;Block(b(0)) = {0,156,z, 10,170,z+10};

If(sph) b() += 3; Sphere(b(1)) = {0,150,0, 20};EndIf

r() = BooleanFragments{ Volume{a()}; Delete; }{ Volume{b()}; Delete; };Save "merged.brep";

Physical Volume("Combined volume", 1) = {r()};Physical Surface("Combined boundary", 2) = CombinedBoundary{ Volume{r()}; }

Import(highestdim)shapesfromSTEPorBREP

Implicittags

BooleanFragmentsintersectseverything

Page 16: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• Moreexamplesonhkp://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/boolean

• OpenCASCADEfeaturesrequireOCCT>=6.9

• Recommended:OCCT7.1

• Muld-threaded2DmeshgeneradonOK(configureGmshwith-DENABLE_OPENMP=1)

• Muld-threadedbooleanoperadons(testwithGeometry.OCCParallel=1;)

• Fuzzybooleanoperadons(Geometry.ToleranceBoolean)

• Let’susetheGit+Debugsessionthisarernoontogeteveryoneup-to-date

16

NewCADfeatures

Page 17: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• Otherrecentfeaturesin.geofiles:

• structures(contributedbyPatrick);sdllexperimental,butexamplesavalailableon

hkp://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/struct• Uniqueoperator

• RuledSurface->Surface

• Otherrecentchangespushedinthemasterbranch

• Faster3Dtetrahedralmeshopdmizadonenabledbydefault

17

NewCADfeatures

Page 18: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• IwouldliketoreleaseGmsh3.0withthesenewfeaturesrightarertheworkshop

• Intensivedebugsessionthisarernoon!

• …andintroducdontoGitbyJonrightarerthistalk

• IwouldwaitforGmsh3.1(or4.0)tobreakthings:

• newreparametrizadoncodefromPierre-Alexandre(cf.histalktomorrow)…andremovaloftheoldone

• newinidal3Dmesher(collaboradonwithHangSi):sdllsomesmallbugs:pleasetestwithMesh.Algorithm3D=2;

• new3Drefinementcode:sdllsomebugs…butmuchfaster:pleasetestwithMesh.OldRefinement=0;

18

Gmsh3.0

Page 19: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017

• IwouldliketoexportaC-typeAPIforthenewCADinterface,themeshingalgorithms(andcombinethiswithHXT)andthepost-pro• shouldbepurelyfuncdonal(weshoulddecideonanaming

convendon)• shouldonlyusestandardtypes(int,double,vector,pair,map)—

nopointers,noclasses,nostructs• shouldbedocumentedandcouldbewrappedinwhatever

(Python,Java,Julia,…)• dynamiclibrariesexposingthisAPIshouldbemadeavailable

• ThecurrentPython/JavawrappersshouldbereservedforGmshdevelopers,andclearlymarkedassuch;theyshouldnotbedistributedbydefault(e.g.inDebian)

19

API

Page 20: New CAD features, Gmsh 3.0 and API - ONELAB · Set OpenCASCADE internal CAD modeler Explicit tags Delete object and tool. Third Gmsh Workshop - Lanzarote March 29-31, 2017 14 New

ThirdGmshWorkshop-LanzaroteMarch29-31,2017 20

Thankyou!