Macro Mesh Data

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro Mesh Data

Post by bernd »

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.
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

Yes I do need that :D and am completely stuck :shock: . 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:

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))
Any help would be appreciated.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro Mesh Data

Post by bernd »

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 ... :mrgreen:
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

bernd wrote: Fri Jan 25, 2019 7:59 am 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 ... :mrgreen:
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))
get_material_elements() echos back 63 elements (which is correct), but crashes when trying to iterate over the material object:

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
clearly I am passing the wrong material object ("App::MaterialObjectPython" from the Analysis branch).

FemInputWriter expects a "matlin_obj" object, but I don't know how that relates to my "App::MaterialObjectPython"
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

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 :D
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

That worked. One step closer, but next problem:

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))
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
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

Aha, I need a FemInputWriterCcx Object and get the info from the ccx_elsets attribute :D 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? :shock:

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)
and

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))
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro Mesh Data

Post by bernd »

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.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro Mesh Data

Post by bernd »

HarryvL wrote: Fri Jan 25, 2019 12:39 pm
bernd wrote: Fri Jan 25, 2019 7:59 am 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 ... :mrgreen:
ENJOY !!!
thanks https://forum.freecadweb.org/viewtopic. ... 43#p282443
User avatar
HarryvL
Veteran
Posts: 1285
Joined: Sat Jan 06, 2018 7:38 pm
Location: Netherlands

Re: Macro Mesh Data

Post by HarryvL »

As always, once you have figured out how to do it, it is simple :roll: :

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)
elmat is the list of elements with material parameters I was after.

I still need to test with multiple material objects.
Post Reply