KeithSloan / GDML

FreeCAD GDML Workbench - AddonManager Installable
Other
49 stars 16 forks source link

FreeCAD Spreadsheet support. #54

Open KeithSloan opened 2 years ago

KeithSloan commented 2 years ago

The branch "spreadsheet" is some initial code for spreadsheet support.

Currently should read GDML Variables into spreadsheet.

ToDo

luzpaz commented 1 year ago

Related to #49

ParticleTruthSeeker commented 1 month ago

Hi, Is pyg4ometry something that you are still looking into including into the project? Could be quite nice though I am not sure how it compares as it seems the gdml workbench also looks for a way to convert extrusions to gdml primitives. Cheers!

KeithSloan commented 1 month ago

@ParticleTruthSeeker - There is support for using FreeCAD's spreadsheets and works for Export

It is a while ago that we looked at this but updating importGDML was making import very slow, which is not fast. GDML Solids are implemented PartFeaturePython and these are not fast to import.

Developer. RealThunder created a fork of FreeCAD and looked at this issue and his version of FreeCAD was much much faster at importing. I think his fork has now diverged a bit and I don't think his enhancements in this area have been incorporated into FreeCAD ( His version being primarily for experiment )

My limited understanding of pyg4ometry is that one could great a geometry in the FreeCAD GDML workbench, export as gdml and then use in pyg4ometry and then use according to http://www.pp.rhul.ac.uk/bdsim/pyg4ometry/loading.html

Similarly one could export a pyg4ometry created geometry with http://www.pp.rhul.ac.uk/bdsim/pyg4ometry/exporting.html and import into the GDML workbench.

Since 2021 when the comment about export pyg4ometry, the GDML workbench has changed a lot adding

  1. Arrays
  1. Extrusion of Sketches
  2. Rotation of Sketches
  3. Optical Support

So would no longer be a case of just scanning the FreeCAD file and exporting a pyg4ometry statement for each GDMLObject.

Not insurmountable but a lot of effort, do you have a use case / example in mind?

Are you involved with Royal Holloway, University of London at all?

ParticleTruthSeeker commented 1 month ago

Hi Keith, thank you for taking the time to reply. Unfortunately I do not work with Royal Holloway though they also do some work that I quite like and find useful. I work on a number of projects with varying degrees of geometrical complexity, which drives my interest in these projects in case they can improve my workflow. I also think it would be interesting if I could use the same geometry that is used to generate a mesh for a FEA simulation and directly import it into GEANT4 or other codes. Perhaps this isn't the most efficient workflow though I find it potentially useful. Concerning PyG4ometry I thought it might be useful as an alternate way of creating a gdml output from step file ultimately it seems through tesselation and as such might be worth adding to the workbench as a seperate method, though I see this has been done by your work also through gmsh. Is there a benchmark or comparison of the two systems in existence? I for instance am trying to convert a FreeCAD assembly I created of a proportional counter and I am looking into how this might be best done.

KeithSloan commented 1 month ago

You can always create Geometry with Python and the GDML workbench and that could be via the FreeCAD macro or a straight program.

I may not be correct but believe Ami - Hashemi, Seyyed Amirreza sabetlab.mgh.harvard has some experience in this area.

To me creating an API is a step up from a set of functions.

If you look at the file GDMLObjects.py you will see all the functions for creating the GDML Objects for all the Geant4 solids.

At the tail of the file there are lots of functions of the form makeBox, makeCone, make{solid} they have only minimum testing and ideally need reviewing by somebody with experience of creating API's before we promoted.

My experience in the IT industry was that API's would be reviewed by a steering committee.

I will comment of Meshing and FEM in a later post if that is okay.

KeithSloan commented 3 weeks ago

"I also think it would be interesting if I could use the same geometry that is used to generate a mesh for a FEA simulation and directly import it into GEANT4 or other codes."

Easier to go from a geometry created in the workbench to

For the LUXE conceptual design - The model had already been programmed in Geant4 so they

  • Exported the geometry to GDML

  • imported the geometry into the Workbench

  • Exported as a STEP file, for combination with CAD design of existing building.

See reference - 245 http://doi.org/10.1140/epjs/s11734-021-00249-z

GDMLObjects and Parts('Volumes | Assemblies' in GDML terms) can be Meshed.

I too initially thought that would be interesting but I am reliably informed that as Geant4 is all about particle's passing THROUGH objects, this would not be generally required.

ParticleTruthSeeker commented 3 weeks ago

Hi Keith, Thank you for your replies. I will definitely check out the reference you posted. I would be happy to try whatever methodology and see what works best. I do think however that there are interesting applications that require solving field equations for instance the propagation of charged particles generated by geant4 in electric fields.

KeithSloan commented 3 weeks ago

"I do think however that there are interesting applications that require solving field equations for instance the propagation of charged particles generated by geant4 in electric fields"

Would that still not be a case of creating a Geometry for Geant4?

I am not an expert in Geant4 like Munther, so maybe there are applications.

There is no reason why you cannot create a geometry with the workbench export as GDML for Geant4, also to take all. or any of the Parts | GDMLObjects and create a Mesh to use that in any FEM analysis, Note: Selection of a Part and use of "create Mesh from Shape" will mesh all the GDMLObjects within the Part. Meshes can be exported as STL for importing into any analysis program

ParticleTruthSeeker commented 3 weeks ago

Indeed. I am still learning the workbench. I like the minimum gdml min_tesselate feature. Though from your and Munthers presentation here, https://indico.esa.int/event/477/contributions/9162/attachments/5828/9721/GDML_Workbench_Pasadena_without_animation.pdf I read slide 31 as the workbench being able to decomposed parts to gdml primitives is this the case? this is my gmsh tesselated export. Looks like quite a few facets. To be fair im not sure i used the min tesselation option on this export. Though if its possible to export it as gdml primites that would be even better. image

KeithSloan commented 3 weeks ago

Not sure why you are Tessellating, primitives will always perform better. Geometry looks like it could be created with Tubes or maybe Tubes and Cones.

If you are referring to Gmsh Min Tessellate then this uses Gmsh CAD option to tessellate, this mostly affects rectangular object i.e. tries to create one Quad facet, rather than two triangular ones. For the objects in the image with curved surfaces the degree of Tessellation would be down to Surface Deviation and Angular Deviation values used.

Slide 31 of the presentation is a comparison of Extruded Sketches which are implemented as Booleans versus Tessellations of the same Extruded Sketches.

Having some Booleans slows things down as does Tessellation, as we have implemented extruded sketches using booleans this was an test exercise that showed using booleans on extruded sketches was 8.4 times better.

Looking at your image it looks like it would be easy to create with a revolved sketch.

So my suggestion would be

  1. If you want best performance when running Geant4- create with primitives
  2. If you want to create more quickly than primitives use a revolved sketch
  3. Otherwise Tessellate.
KeithSloan commented 3 weeks ago

If you do recreate as a revolved sketch and can share, it would make a great example of the use of an extruded sketch that we could use in our documented.

KeithSloan commented 3 weeks ago

If you follow the workflow of create the GDML geometry in the workbench first, then I can see that being able to do FEM anaylsis would make sense for the physical structure.

As mentioned before all GDMLObject has a FreeCAD Shape and can be meshed and could be used in the FEM workbench

ParticleTruthSeeker commented 3 weeks ago

Hi Keith, Sure I will give this a go as soon as I can and get back to you. One of the advantages of making the part in FreeCAD was to have it as an assembly using the Assembly3 workbenck in order for me to be able to tag the sub parts in the exported stl with different material properties for GEANT4. Would one be able to do this if its a solid revolution? I suppose I could also create multiple sketches in the GDML workbench at different offsets to reproduce this functionality.

KeithSloan commented 3 weeks ago

We have not really looked into Assembly workbenches as there are quite a number of them, Two, Three, Four and now a new standard one but less function.

How hard would it be to create a simple example and send it to me - email in Repro - README ? With the intent if there are issues we can look into them.

I can see that a geometry created with an Assembly workbench would be a good use case.

Does it have to be Assembly3? or would the new Assembly workbench be sufficient?

ParticleTruthSeeker commented 3 weeks ago

Hi, I am not sure. I will look into this and update you on progress :D

I think what is important is to assign different material properties to different volumes rather than any of the assembly workbenches.

I am getting the following error on exporting the sketch and extrude. Any tips?

return self._rotation ^^^^^^^^^^^^^^ <class 'AttributeError'>: 'ExtrusionExporter' object has no attribute '_rotation'

KeithSloan commented 2 weeks ago

( We really should move to another issue, long way from Spreadsheet support )

Sorry only just seen this. Please could you send the FC file ( email in Repro README) or add extra "txt" and upload.

Are you setting the Rotation in the Extrude or in the Part that it is in?

Export should deal with either.

What Plane is the sketch in?

There should be an update with a new export shortly, this may or may not fix things, so if you could supply your problem file that would be good to fix in the new update.