Advices to couple CAD tools with MCNP and Geant4
Here's a tutorial for CAD to MCNP/Geant4 coupling.
It summarizes weeks of exhaustive attempts with
Marc Krauth
and
Christophe Ruescas.
Off-the-shelf solutions do not exist but a few tools are doing great.
After a brief warning and a description of the benchmark data, the most relevant results are presented for each software:
first for MCNP (section 3), then for Geant4 (section 4).
Some advices are given at the end.
In the following, the notation MCsc is used as a short for Monte Carlo simulation code.
I'll then speak of CAD2MCsc softs/tools for softwares enabling to convert CAD files to MCsc input files.
1. Warning
All CAD2MCsc softwares import STEP files (.st[e]p).
So first make sure your CAD soft exports .step files.
I made the mistake at the beginning, using Google Sketch'Up (GSU) which is a nice free CAD soft everybody can install on its own machine.
Unfortunately, it does not export in .step and I lost several tens of hours trying
bunches of softwares
(CATIA,
AutoCAD,
TurboCAD,
gCAD3D,
Acrobat3D,
CrossCAD,
DataCAD,
Moritz,
MCNP Vised,
MCAM, ...)
to create a .step file of my model from all the available GSU export formats
(.wrl, .x3d, .3ds, .igs, .stl, .ics, .dae, .mtl, .obj, .fbx, .sat, .brep, ...), in vain!
CAD format conversion is really a nightmare! Avoid it as much as you can!
According to me, the smartest thing to do is to work with Catia since it is the IN2P3 official CAD soft (and of course includes .step exportation).
You can install it on your own machine at lab and you'll always find someone from the mechanics team to help you
(
Marc Krauth,
Christophe Ruescas,
Thierry Goeltzenlichter,
Valeria Zeter, ...).
Only snag, Catia's not free.
2. Benchmark
Loads of pieces have been created by Marc Krauth, in order I can test the limits of the CAD2MCsc tools I found googling around and browsing literature.
A particular attention has been paid to the way pieces were created (boolean operations or not, ...).
This does not seem to have any impact at the MCsc level.
So don't bother too much.
The response of each CAD2MCsc tool is described in the following sections.
But we can already mention a few results:
- Not surprisingly, using basic geometric volumes will go fine:
- Any combination of such basic geometric volumes will also go fine:
- And you can safely create all kinds of stuff using basic geometric volumes:
- For fancy-shaped volumes such as those below, the result may not be guaranteed...
3. CAD tools for MCNP
All CAD tools for MCNP are for Windows users only.
Depending on the licence type, some might be installed on xxx. Contact xxx.
3.1. Moritz :-((
Lots of mails have been (indirectly) exchanged with the developer that is keen to answer. (Thanks to Amokrane Allaoua, amokrane.allaoua@irsn.fr)
But the import functions provided (for STEP or VRML files) are just fancy features and tests with basic geometric volumes fail miserably.
Furthermore, no development is scheduled in a near future. So forget about it.
It nevertheless remains a very nice (but not free) visualization tool (see e.g. here).
3.2. Vised (MCNP VISual EDitor) :-(
Since the 22XS release, some CAD possibilities are offered, especially SAT files (.sat) can be imported.
Nevertheless I don't recommend its use for two reasons:
- All the tests we made with Christophe Ruescas, although juggling with 7 import options, were not convincing.
- AutoCAD is no more used at lab (almost nobody will be able to help you).
Yet, as for Moritz, it remains a very nice visualization tool (see below) and it's free for MCNPX beta-users (ask xxx).
3.3. MCAM :-)))
3.3.1. Introduction
This tool originates from the fusion community (see here)
and is by far the best you could find!
It is freely available. Just send a mail to the FDS team (fds@ipp.ac.cn).
MCAM is really designed to convert CAD files to MCsc input files.
It can import
STEP (.st[e]p),
SAT (.sat) or
IGES (.ig[e]s) files
and contains lots of smart functions such as:
scaling a whole volume, checking and fixing gaps and overlaps,
decomposing a complex cell into basic ones, glueing cells together, ...
Further nice options are available.
Materials and names can be directly assigned to each cell directly in MCAM (a same material can be assigned to several cells in one go).
You can also create via Tools/Write MCNP a complete MCNP file by specifying a Material file (watch out the density line position!
See e.g. my own file),
a SDEF file and a Tally file. They will be parsed (material density) then appended properly.
But that's not all folks! MCAM's more powerful than that!
Indeed, you can also
- display any MCNP file in MCAM
- create a .sat file from a MCNP file
- build an entire geometry directly in MCAM and save it as a .sat file.
This may not be a good idea though, considering the abovementioned issues: CAD conversion, support at lab, ...
plus it does not offer all the possibilities a true CAD soft does.
3.3.2. Using the decompose function?
From the manual, once you've imported your .step file (File/New, File/Import), all you have to do to create the MCNP file is to click:
- Preprocess/Heal (removing possible geometry errors)
- Preprocess/Scale and enter 0.1 as a scaling factor
- Preprocess/Decompose (cell splitting for a best MCNP export)
- Preprocess/Check (checking interference between entities)
- Preprocess/Reconstruct (removing gaps and overlaps)
- Tools/Write MCNP
As shown in the picture below, this approach is far from satisfying.
You'll end up with bunches of odd shaped cells you will have to name and give a material.
I rather recommend to skip the steps 3, 4 and 5 and directly write the MCNP file.
In all the cases I encounter, it went fine...
... all but one
So don't bother!
Alternatively you could also
- use the Glue function between step 5 and 6 to make one whole cell
- construct your cell in a smarter way instead of letting MCAM decide for you
3.3.3. How good's MCAM?
As abovementioned, no probs with basic volumes.
For fancy-shaped ones, it depends.
It can go fine:
or not:
(I reported this weird bug to the FDS team. I'll let you know.)
In the latter cases, no choice, you will have to simplify the original geometry.
3.3.4. Warning
As illustrated below, do not blindly trust the MCAM output.
Check the result by plotting it in all the viewers you have:
- MCAM ("Tools/Read MCNP" + section option)
- Moritz (3D window + cutter bodies option)
- Vised (3D window ("3D View/Dynamic 3D Display" and/or "3D View/3D Ray Traced Image/Normal 3D Plot") + slice scanning option)
- MCNP built-in 2D geometry plotter (mcnp ip i=myFile.mcn)
But watch out!
Some viewers (namely Moritz and Vised) are a bit fuzzy (faulty 3D rendering, unrecognition of some MCNP official shapes, ...)
and may not properly display your geometry in 3D whereas there is absolutely no problem.
In case basic display function fails, try the "3D View/3D Ray Traced Image/Normal 3D Plot" of MCNP-Vised
and play with the different options (lower the resolution to find a nice point of view first).
You can use the usual zoom button.
If you're still not convinced, you may
- create your own ray tracing soft.
Fill your piece with lead and, in vacuum, throw it a "pie" of low energy alpha particles (e.g. 1 MeV, to avoid inelastic scattering).
Image its shadow using mesh tallies. Repeat the operation on each axis of interest.
- try to use the radiography tally... (no idea if it works)
3.3.5. Notes
- Worldification
Strangely, the world is not created during the process.
So, here's a Perl script I wrote to create one automatically and which is compliant with the MCAM "Read MCNP" function,
which requires cells and surfaces to be in increasing order!
In the case you use the MCAM "Read MCNP" function, just delete the 2 first cubes you encounter (left click on the cell, then right click / Delete Entity).
- Here's also a basic training .step file consisting of 4 parallelepipeds attached to each other to form a "square doughnut".
4. CAD tools for Geant4
4.1. GDML
Geant4 can only import GDML files.
This requires a specific installation of Geant4 (please see here).
For the time being, only two softwares are able to convert .step files to .gdml files: Fastrad and Esabase2 (see below).
Both are for Windows users only.
4.1.1. Tests' automation
Below's a basic Geant4 program I wrote to convert any .gdml file to any Geant4 visualization driver file (See my G4 tutorial here).
Of course the corresponding drivers should be installed and Geant4 compiled accordingly (see here).
The following outputs are provided: VRML{1,2}, heprep[.zip], Dawn and OpenGL. It's up to you to add more.
>> gdml2G4viz.tgz / doxydoc
Watch out! If you use Fastrad (see below), you cannot directly import the .gdml file generated.
You will have to remove and add some stuff.
The script gdmlify.pl,
also included in the above archive, will do that for you.
The z_gdml/ directory contains a .stp file, the GDML output from Fastrad and the resulting file in .wrl (VRML) as an example.
Everything is (should be) explained in the
readme file.
Whinge if it's not!
4.1.2. Root GDML binding
Note a GDML binding is included in Root. This can be useful to check your geometry.
To do so, just type the following lines in the Root prompt
----------------------------------------------------------------------------
TGeoManager::Import("myFile.gdml") ; gGeoManager->GetTopVolume()->Draw("ogl") ; ----------------------------------------------------------------------------
Be aware though it rarely works at first time.
You may have to hack your .gdml file commenting some lines and/or changing the "gdml.xsd" location.
4.2. Fastrad
4.2.1. Introduction
Fastrad can be downloaded as a free trial after registration.
For Linux users, Fastrad is installed on xxx (the Windows apps server).
Connect using: rdesktop xxx -g 1270x920 -k fr (change your screen resolution and keyboard language accordingly).
Once installed, all you have to do is to
- Load your .step file via Translation/Step/Import.
For curved-shaped volumes, use the highest discretisation for a best renderer and export. - Create the .gdml file Translation/Gdml/Export.
Save it as a one piece file by answering "no" to the question: "Do you want to save to isolate the tesselated geometries in the GDML project?"
In the trial version, you can also
- assign materials to any cells
- build your geometry from scratch (without any CAD import).
4.2.2. Tests performed
The following figures resume the tests performed with the above benchmark pieces.
On average, the result is very satisfying.
- Standard shapes
- Fancy volumes going fine
- Fancy volumes going bad
I've contacted Fastrad for these last cases.
- the "chipped cone" glitch occurs even with the last releases (the STEP conversion and the tesselation are performed through OpenCascade libs).
The advice I had was to reconstruct the piece from scratch directly in Fastrad. - the crash experience (that with the mouse bed) should not happen in the last version of Fastrad...
4.2.3. Notes
- In the past, the software limited GDML export to 1000 elements. It'd seem it now limits it to 20! See here.
- Fastrad v3 exports to GDML 2.7. The last releases of Geant4 (since 18/12/2008) use GDML 3.0.0.
This should not be a problem (backward compatibility should be assured). - My contact at Fastrad is jean-charles.thomas@trad.fr.
4.3. Esabase2
4.3.1. 1st challenge: Getting the soft
To get the soft, register on the website and be (very) patient...
Do not hesitate to contact the developer (Karl Dietrich Bunte, K.Bunte@etamax.de) if it lasts too long.
You will receive a contract (paper) you will have to sign and send back.
Some days later, you'll get an email with your ID (login/psw), giving you access to the download area.
4.3.2. 2nd challenge: Doing something...
Once you have it, good luck!
I didn't have much time to try it but I didn't manage to do anything (even displaying the provided .step files).
I was a bit discouraged by the fact that:
- the word "gdml" does not appear anywhere, neither in the different manuals nor in the help index!
- Esabase2 seems to be choosy about the .step version: "[Only] STEP files conforming to AP214 and partially AP203 can be read".
If you can go further (I'm sure you can), please let me know.
5. Epilogue
5.1. Advices for people starting from scratch
- Use basic geometric forms. Avoid complex shapes and flourishing (round corners, fancy holes, ...).
If necessary, compute the corresponding plain geometry instead. It will speed up your simulation. - Create one CAD cell (CATPart) per simulation cell of interest, keeping in mind you can only assign one material per cell.
If your one-material CAD cell can be built from several basic geometric shapes, don't bother, just create one big CAD cell.
If not (fancy shapes needed), create several CAD cells keeping in mind the way you will create them should not impact your MCsc cell.
5.2. How I would work today...
If you're planning to design something with the mechanics team,
ask them to create a toy model in parallel
to the true model that will be used for machining,
making sure this toy model roughly respects the abovementioned advices.
Superimposing 2 geometries in one file and hide one or the other is possible in Catia.
The STEP conversion will only care about the visible one.
Good luck!
5.3. Feel free to contribute!
This work is far from finished.
Further tests would be necessary to enrich this page.
Almost all the tests made so far are stored
on xxx
(ask xxx).
A useful improvement would be material importation from Catia.
I didn't have time to work on it but that would really be time-saving...
5.4. Acknowledgements
Thanks again to Marc Krauth and Christophe Ruescas for their invaluable help.