KeithSloan / GDML

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

Solved? : How to make a new material #73

Open lichuanlong opened 2 years ago

lichuanlong commented 2 years ago

we have G4_BORON_CARBIDE and G4_POLYETHYLENE in freecad gdml. how to make a new material with 0.05 G4_BORON_CARBIDE + 0.95 G4_POLYETHYLENE ?

KeithSloan commented 2 years ago

Currently there is no facility to define new materials via the GUI.

You can create an XML file and import it

The file should have an extension of xml and should look like

<xml>
  <materials>
      <material formula="New_Material" name="New_Material" >
            <D unit="g/cm3" value="1.127" />
             <fraction n="0.05" ref="G4_BORON_CARBIDE"/>
              <fraction n="0.95" ref="G4_POLYETHYLENE"/>
       </material>
  </materials>
</xml>

For New_Material choose an appropriate name.

You need to give a value for the density, not sure how one goes about working this out. I am guessing 0.05 density of G4_BORON_CARBIDE + 0.95 density of G4_POLYETHYLENE

Save as NewMaterial.xml then import

It should then appear as a NewMaterial in the main Materials Group and the definition exported for any export GDML file. If you save the FreeCAD file it should also be saved with the file.

Geant4. Materials are defined in Geant4Materials.xml which you should find in the Resources directory. i.e. ../..Mod/GDML/freecad/gdml/Resources. These get loaded into the Group Geant4 within Group Materials. They are NOT exported as Geant4 should already know about them.

If it is a material that Geant4 knows about and missing from Geant4Materials.xml, if you let me know the name and density I will add it to Geant4Materials.xml

KeithSloan commented 2 years ago

If the material is already defined in another existing GDML file, then you should be able to

MITgnome commented 1 year ago

Does the import of materials still work in the current release. I tried the instructions above and the new materials did not appear under the model. The log just showed:

08:27:58 Insert filename : /Users/rickfoster/Desktop/dataBaseMaterialMIT.xml docname : Unnamed 08:27:58 process XML : /Users/rickfoster/Desktop/dataBaseMaterialMIT.xml 08:27:58 Parse : /Users/rickfoster/Desktop/dataBaseMaterialMIT.xml 08:27:58 running with lxml.etree 08:27:58 Process Materials DocSet 08:27:58 define xml None 08:27:58 Process - Opticals: matrix_spreadsheet 08:27:58 define xml None

The following is the XML file I imported (xml postfix changed to txt just to upload into comment):

dataBaseMaterialMIT.txt

KeithSloan commented 1 year ago

Apologies if the instructions are not clear.

The file needs to have an extension of xml and must include

<xml>

at the start of the file and

</xml>

at the end.

dataBaseMaterialMIT.xml.txt

I updated the wiki - let me know if it is still not clear.

MITgnome commented 1 year ago

Yes, silly mistake on my part. I cleaned up the file a bit and used the G4 elements already defined by you. Things seemed to work. One thing that would be useful is if I could add the materials to a new folder as opposed to having them all at the top level of the Materials folder, is that possible?

image
KeithSloan commented 1 year ago

"One thing that would be useful is if I could add the materials to a new folder as opposed to having them all at the top level of the Materials folder, is that possible?"

So you would like the new Materials added to a new group under Materials based on the say the imported file name e.g dataBaseMaterialMIT.

That is certainly doable and a good idea if importing several sets. Will also require updates to various material selection facilities/code.

I fly back from Seattle in the US to the UK on Monday and will look into when I get back.

Thanks for the suggestion.

MITgnome commented 1 year ago

It seems if I import the new materials using a xml file, those new materials do not seem to be available to GDML solids that have already been placed in the workspace. They do seem to be available for GDML solids that I place after I imported the XML Materilas file. Is this what you would expect?

KeithSloan commented 1 year ago

Yes. When a GDML solid is created the Material Property is made up of an enumeration list of the known materials at the time. You could try a recompute of the object but I suspect that would not help without a change of the current coding. Worth trying using the Set Material Icon / Command i.e. select object and then the icon but as the object is already created with the enumeration list of known materials at the time, this may just give an error when trying to set a new value.

I would have to look into the possibility of changing a enumerated property of an object without recreating it, sorry about that.

KeithSloan commented 1 year ago

Okay the doc says "App::PropertyEnumeration An enumeration property. The allowed items are defined by setting the property to a list. After that, it can contain items of the given list. The list of allowed items can be changed by setting the property to a list again."

I need to look into a code change. I assume this is more urgent than keep all the MIT materials together as per the Geant4 ones.

KeithSloan commented 1 year ago

Okay I just tested, No code change required with set material icon,

I start GDML workbench create a GDML object Then I import a material XML file like your MIT one. Select the object who's material I wish to change. Click on Set Material Icon You should find the new imported Materials under the "Normal" category.

I am open to a better term than Normal for the Non Geant4 groups

Image 30-08-2023 at 22 47

KeithSloan commented 1 year ago

Point of information - Lots of good things are starting to happen in the FreeCAD world and things are slowly moving in the same direction as open source projects such as KiCad, Blender

1) The FreeCAD Project Association was formed see https://fpa.freecad.org 2) There was a meeting in Brussels with funding for developers to attend and recently in Vancouver 3) Brad Collete has been a prime mover in setting up Ondsel see https://ondsel.com/about and obtain funding for developments which will be incorporated into FreeCAD ( address a lot of the topological naming problem etc)

FreeCAD material facilities came from work bench developments FEM and Arch, there us an effort to look at creating a better materials facility see discussion at https://forum.freecad.org/viewtopic.php?t=78242&start=70 and my latest post to that thread.

I have provided some input on what is required for the GDML workbench but it is likely that the new facilities might not be enough.

An orginal GDML workbench was created a long time ago 2008 by Emmanuel Delage: CAD-GDML technical manager (LPC Clermont, IN2P3/CNRS)

And when I started a precursor to the current GDML workbench there was a vague dream that FreeCAD could one day get the same sort of sponsorship from CERN that KiCad has.

If that had happened then I think there would have been more incentive for the matrials requirements to be fully addressed.

Do you have any advice on how one might get say CERN, MIT or other prestigious organisation to at least endorse the FreeCAD FPA.

MITgnome commented 12 months ago

Speaking as an end-user of Geant4, as opposed to a developer, I can say that Freecad with GDML has been progressing in the right direction over the last couple of years. Construction and maintenance of the geometry models has always been difficult for us. Most of the solutions for geometry generation/editing seem to have had a rather start/stop flavor to them. There seems to be effort by the Fastrad folks to provide an integrated solution, but it is not an open source solution that more casual users, such as myself, are looking for.

One way you might get some increased visibility for FreeCad/GDML is to show it off at the upcoming Space Users Workshop in December. The Geant4 collaboration folks that conduct the workshop have been around for a long time and I suspect have the type of influence you are looking for.

https://indico.esa.int/event/477/

You are correct that being able to import materials lists into a geometry model that has already been created is more important than sorting those materials into folders. You can imagine wanting to be able to add or modify materials, import them into the model and update the parts with either a new material or a parametric change to an existing material.

I will try the set material icon approach you described and let you know how it worked.

Thanks Rick

MITgnome commented 12 months ago

Quick Question using the Set Material Icon. Is the Material set at the Part Object (such as Si3N4_coating) or say the GDML Object (such as GDMLBox_Box002) image

KeithSloan commented 12 months ago

The GDML material property is in the GDML Objects, where you see a Material Property ( i.e. A Capital M) on a Part is a FreeCAD material and these are ignore as far as use of the workbench. I might be wrong but it was introduced after the GDML workbench was started. They are used for FEM and Arch workbenches.

This I agree can be confusing. Unfortunately the FreeCAD materials facility is not flexible enough for us to use.

MITgnome commented 12 months ago

OK, so then that didn't seem to work. I selected the GDMLBox_Box002 object. Used the Set Material icon and selected NORMAL:MIT_SILICON_NITRIDE, expecting it to update the previous placeholder material G4_SILICON_DIOXIDE. The console had the message Set Material MIT_SILICON_NITRIDE, but it does not seem to actually update the material, but leaves it as G4_SILICON_DIOXIDE. image

KeithSloan commented 12 months ago

Might be a bug in terms of the property window not being updated, could you try selecting a different object and then going back to GDMLBox_Box002.

Seems to be working for me.

[code] OS: macOS 12.4 Word size of FreeCAD: 64-bit Version: 0.21.0.33675 (Git) Build type: Release Branch: (HEAD detached at 0.21.0) Hash: 41b058e2087de60dc8fef3d3e68c7d0129e13abf Python 3.10.12, Qt 5.15.8, Coin 4.0.0, Vtk 9.2.5, OCC 7.6.3 Locale: C/Default (C) Installed mods:

Image 31-08-2023 at 21 06

MITgnome commented 12 months ago

That did not work either, it stayed as G4_SILICON_DIOXIDE. I also ran recompute on the whole project.

MITgnome commented 12 months ago

I just looked at the exported gdml file and it still shows G4_SILICON_DIOXIDE image

KeithSloan commented 12 months ago

Seems to be working for me.

[code] OS: macOS 12.4 Word size of FreeCAD: 64-bit Version: 0.21.0.33675 (Git) Build type: Release Branch: (HEAD detached at 0.21.0) Hash: 41b058e2087de60dc8fef3d3e68c7d0129e13abf Python 3.10.12, Qt 5.15.8, Coin 4.0.0, Vtk 9.2.5, OCC 7.6.3 Locale: C/Default (C) Installed mods:

ImportNURBS 1.1.0 ImportExport_3DM 0.1.0 DynamicData 2.46.0 Pyramids-and-Polyhedrons occi-freecad-plugin 0.1.0 GDML 2.0.0 Design456 0.0.1 Alternate_OpenSCAD 1.0.0 toSketch 1.0.1 Curves 0.6.13 [/code]

Can you provide your about FreeCAD info.

MITgnome commented 12 months ago

[code] OS: macOS 12.6.8 Word size of FreeCAD: 64-bit Version: 0.21.0.33675 (Git) Build type: Release Branch: (HEAD detached at 0.21.0) Hash: 41b058e2087de60dc8fef3d3e68c7d0129e13abf Python 3.10.12, Qt 5.15.8, Coin 4.0.0, Vtk 9.2.5, OCC 7.6.3 Locale: C/Default (C) Installed mods:

KeithSloan commented 12 months ago

"I just looked at the exported gdml file and it still shows G4_SILICON_DIOXIDE image"

If the Material does not show a change in FreeCAD it will not change on export.

Did you click on the "Set Material Box" after selecting SILICON_NITRIDE?

MITgnome commented 12 months ago

Yes, I hit the Set Material button and seemed to get a positive confirmation in the Report View image

MITgnome commented 12 months ago

I went thru the process again, selecting the object, clicking Set Material Icon, etc and here is the full log in the report window. Not sure what the QCompleter message is all about. image

KeithSloan commented 12 months ago

Okay, the only difference I can see is I am OS: macOS 12.4 and you are on OS: macOS 12.6.8.

I will upgrade and see if I can recreate the problem.

The message is coming from Qt and we seem to have the same version of that.

MITgnome commented 12 months ago

I just ran it on MacOS Ventura 13.5 and had the same result.

KeithSloan commented 12 months ago

I upgraded my Mac and am now seeing the "Setting QCompleter on non-editable QCombox is not allowed" message and seeing the same problem. I think the update has exposed a bug in that an option should be set to allow a QCombox to be changed.

MITgnome commented 12 months ago

Bummer when upgrades break things that worked before.

MITgnome commented 12 months ago

My MacOS 12.6.8 is already my old workstation. I have a mountain of older machines piled in the lab, but that approach is too scary to contemplate.

MITgnome commented 12 months ago

I guess for now, I will just do geometry modifications in Freecad and if I have to tweak the materials I can hand edit the exported gdml file.

KeithSloan commented 12 months ago

Okay have fixed the "Setting QCompleter on non-editable QComBox is not allowed" message, just had to change the order on some QCombobox options

To fix the none update with added material definitions just had to set the combobox to the latest list before setting the value.

Don't understand how it was working before prior Mac update.

Thanks for your patience and testing, please try the latest version.

MITgnome commented 12 months ago

That seems to have done the trick. I tested changing a few materials and then exported out to a gdml file successfully. Thank you!

KeithSloan commented 12 months ago

Well, thank you for - reporting the problem and assisting with problem determination.