Macro Mesh Data
Moderator: bernd
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Re: Macro Mesh Data
Looks good to me Harry
BTW: If you would need Solids as Elements too the code needs to be different. getElement does not work with Solid as Element.
BTW: If you would need Solids as Elements too the code needs to be different. getElement does not work with Solid as Element.
Re: Macro Mesh Data
Yes I do need that and am completely stuck . Not so much with getElement (which becomes meshtools.get_element (right?), but more with how I get to the mesh elements that belong to a material object, like this:
Any help would be appreciated.
Code: Select all
fiw = meshtools.FemInputWriter('''the constructor takes 22 parameters, among which matlin_obj. How do I feed this, or am I on the wrong track?''')
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('App::MaterialObjectPython'):
for part, solids in obj.References:
for solid in solids:
ref_shape = fiw.get_element(part, solid)
elementIDs = fiw.get_material_elements() # this doesn't work of course, but what then ??
for ID in elementIDs:
el_keys.append(ID)
el_mat_values.append([ obj.Material["YoungsModulus"],obj.Material["PoissonRatio"]])
material_by_element = dict(zip(el_keys, el_mat_values))
Re: Macro Mesh Data
you are right with get_element ... for the other I need a computer which is not allowed to sit at because of familly ski hollidays ...
Re: Macro Mesh Data
ENJOY !!
I am getting closer, but still not there:
Code: Select all
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('App::MaterialObjectPython'):
fiw = writerbase.FemInputWriter(analysis, solvDummy, doc.FEMMeshGmsh, obj,
None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None)
fiw.get_material_elements()
for part, solids in obj.References:
for solid in solids:
ref_shape = fiw.get_element(part, solid)
elementIDs = fem_object['FEMElements']
for ID in elementIDs:
el_keys.append(ID)
el_mat_values.append([ obj.Material["YoungsModulus"],obj.Material["PoissonRatio"]])
material_by_element = dict(zip(el_keys, el_mat_values))
Code: Select all
Traceback (most recent call last):
File "/home/harry/.FreeCAD/Macro/test1.FCMacro", line 258, in <module> fiw.get_material_elements()
File "/home/harry/FC_Master/build/Mod/Fem/femsolver/writerbase.py", line 264, in get_material_elements
control = FemMeshTools.get_femelement_sets(self.femmesh, self.femelement_table, self.material_objects, self.femnodes_ele_table)
File "/home/harry/FC_Master/build/Mod/Fem/femmesh/meshtools.py", line 365, in get_femelement_sets
for fem_object_i, fem_object in enumerate(fem_objects):
<type 'exceptions.TypeError'>: 'FeaturePython' object is not iterable
FemInputWriter expects a "matlin_obj" object, but I don't know how that relates to my "App::MaterialObjectPython"
Re: Macro Mesh Data
Hmmmm after having spent some time in the labyrint I am starting to believe I need a ccxtools object. The constructor automatically adds all material objects under an active analysis to the ccxtools.materials_linear attribute. This is most likely the “iterable” matlin_obj FemInputWriter is looking for ?! Well I guess I just need to try
Re: Macro Mesh Data
That worked. One step closer, but next problem:
as I say in the code box: how do I get access to "fem_object['FEMElements']" that contains the Volumes that are associated with ft.materials_linear
and that gets filled here: https://github.com/FreeCAD/FreeCAD/blob ... #L360-L393 and is called from FemInputWriter.get_material_elements here: https://github.com/FreeCAD/FreeCAD/blob ... #L241-L274
Code: Select all
import femsolver.writerbase as writerbase
import femtools.ccxtools as tools
...
...
...
ft = tools.FemToolsCcx()
fiw = writerbase.FemInputWriter(analysis, solvDummy, doc.FEMMeshGmsh, ft.materials_linear,
None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None)
for obj in FreeCAD.ActiveDocument.Objects:
if obj.isDerivedFrom('App::MaterialObjectPython'):
for part, solids in obj.References:
for solid in solids:
elementIDs = fiw.fem_object['FEMElements'] # wrong
'''
this is not right - how do I get access to "fem_object['FEMElements']" that contains the Volumes that are associated with ft.materials_linear
and gets filled in meshtools.get_femelement_sets(femmesh, femelement_table, fem_objects, femnodes_ele_table=None),
called from FemInputWriter.get_material_elements ??
'''
for ID in elementIDs:
el_keys.append(ID)
el_mat_values.append([ obj.Material["YoungsModulus"],obj.Material["PoissonRatio"]])
material_by_element = dict(zip(el_keys, el_mat_values))
and that gets filled here: https://github.com/FreeCAD/FreeCAD/blob ... #L360-L393 and is called from FemInputWriter.get_material_elements here: https://github.com/FreeCAD/FreeCAD/blob ... #L241-L274
Re: Macro Mesh Data
Aha, I need a FemInputWriterCcx Object and get the info from the ccx_elsets attribute Thic Class inherits from FemInputWriter, so I may not even need to create a FemInputWriter object in the first place, just a FemInputWriterCcx object
... and who said the age of discovery ended with Livingstone?
and
... and who said the age of discovery ended with Livingstone?
Code: Select all
# solid
def get_ccx_elsets_single_mat_solid(self):
mat_obj = self.material_objects[0]['Object']
elset_data = self.ccx_evolumes
names = [{'long': mat_obj.Name, 'short': 'M0'}, {'long': 'Solid', 'short': 'Solid'}]
ccx_elset = {}
ccx_elset['ccx_elset'] = elset_data
ccx_elset['ccx_elset_name'] = get_ccx_elset_name_standard(names)
ccx_elset['mat_obj_name'] = mat_obj.Name
ccx_elset['ccx_mat_name'] = mat_obj.Material['Name']
self.ccx_elsets.append(ccx_elset)
def get_ccx_elsets_multiple_mat_solid(self):
for mat_data in self.material_objects:
mat_obj = mat_data['Object']
elset_data = mat_data['FEMElements']
names = [{'long': mat_obj.Name, 'short': mat_data['ShortName']}, {'long': 'Solid', 'short': 'Solid'}]
ccx_elset = {}
ccx_elset['ccx_elset'] = elset_data
ccx_elset['ccx_elset_name'] = get_ccx_elset_name_standard(names)
ccx_elset['mat_obj_name'] = mat_obj.Name
ccx_elset['ccx_mat_name'] = mat_obj.Material['Name']
self.ccx_elsets.append(ccx_elset)
Code: Select all
for femobj in self.material_objects: # femobj --> dict, FreeCAD document object is femobj['Object']
mat_obj = femobj['Object']
mat_info_name = mat_obj.Material['Name']
mat_name = mat_obj.Name
mat_label = mat_obj.Label
# get material properties of solid material, Currently in SI units: M/kg/s/Kelvin
if mat_obj.Category == 'Solid':
YM = FreeCAD.Units.Quantity(mat_obj.Material['YoungsModulus'])
YM_in_MPa = float(YM.getValueAs('MPa'))
PR = float(mat_obj.Material['PoissonRatio'])
f.write('*ELASTIC\n')
f.write('{0:.0f}, {1:.3f}\n'.format(YM_in_MPa, PR))
Re: Macro Mesh Data
I can not even access the code because in my mobil the do not scroll ...
check https://www.freecadweb.org/wiki/FEM_Tut ... ep_by_step and have a look at these methods in ccxtools. BTW you can try them on the FEM 3D cantilever example.
check https://www.freecadweb.org/wiki/FEM_Tut ... ep_by_step and have a look at these methods in ccxtools. BTW you can try them on the FEM 3D cantilever example.
Re: Macro Mesh Data
As always, once you have figured out how to do it, it is simple :
elmat is the list of elements with material parameters I was after.
I still need to test with multiple material objects.
Code: Select all
import femsolver as solver
import femtools.ccxtools as tools
ft = tools.FemToolsCcx()
fiwc = solver.calculix.writer.FemInputWriterCcx(analysis, solvDummy, doc.FEMMeshGmsh, ft.materials_linear,
None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None)
fiwc.get_material_elements()
elmat = []
for object in fiwc.material_objects:
E = object['Object'].Material['YoungsModulus']
Nu = object['Object'].Material['PoissonRatio']
for el in object['FEMElements']:
elmat.append([el, E, Nu])
print (elmat)
I still need to test with multiple material objects.