Frequency analysis


To get the eigenfrequency values in GUI we have to write .dat file reader first. It’s not hard, but it takes time (I can help if someone is willing to code it)

Hi PrzemoF,
I tried to write a small function/definiton to read in the eigenfrequency values stored in the .dat file.
Maybe it is usefull but do not expect to much I am no computer scientist.

BR Howil

# -*- coding: utf-8 -*-

import numpy as np

def dat_ef_reader(foldername, filename, freecad_fem_mesh_fn, skh=7, nr_ef=10):
    #==============================================================================
    # Data readin
    #==============================================================================
    f = open(foldername+filename) # opening the input file
    
    # skipping the header
    for n in np.arange(skh):
        text2 = f.readline()
    
    # output list
    ef_data = []
    
    # reading the eigenfrequencies
    for n in np.arange(nr_ef):
        ef_data.append(np.fromstring(f.readline(), dtype=float, sep=' '))
    
    f.close() # closing the input file

    return ef_data



#==============================================================================
# Setting default parameter
#==============================================================================

# foldername of .dat file has to be adopted for windows !!!!!!!
foldername = '/tmp/'

# filename of Freecad FEM mesh name
freecad_fem_mesh_fn = 'Pad_Mesh'

filename = freecad_fem_mesh_fn+'.dat'

# setting skip_header and skip_footer
skh = 7
# number of eigenfrequencies to readin
nr_ef = 10



ef_data = dat_ef_reader(foldername, filename, freecad_fem_mesh_fn, skh, nr_ef)

#==============================================================================
# Testing the found data
#==============================================================================
ef_counter = 3
print(" Eigenfrequency nr "+str(ef_counter)+" : "+str(ef_data[ef_counter][3])+" Hz (CYCLES/TIME)")

Hi Howil,
Thanks for the code! I’m sure we could make it work, but we’ll need something that can be easily extended to parse different parts of the .dat file.
I started using ccxFrdReader as the base [1]. It’s not fully usable yet, but it can produce this:

import ccxDatReader
ccxDatReader.import_dat('/tmp/aaaaa/Beam_Mesh.dat')
Results [{'eigenmode': 1, 'frequency': 162.7162}, {'eigenmode': 2, 'frequency': 808.0947}, {'eigenmode': 3, 'frequency': 1025.64}, {'eigenmode': 4, 'frequency': 2898.789}, {'eigenmode': 5, 'frequency': 3501.777}, {'eigenmode': 6, 'frequency': 4899.052}, {'eigenmode': 7, 'frequency': 5758.346}, {'eigenmode': 8, 'frequency': 9689.247}, {'eigenmode': 9, 'frequency': 10587.33}, {'eigenmode': 10, 'frequency': 12578.87}]

I’m going to add 2 new fields to result objects called ‘Mode’ and ‘Frequency’ and store the values extracted for the .dat file there.

[1] https://github.com/PrzemoF/FreeCAD/tree/dat_reader

If you would like to have the CalculiX file named the way you would like to have it you could make a new DocumentObject with your favorite name and copy the FEMMesh to the new Document object by python.

old_label = "Face_Mesh"  # the name displayed in FreeCAD Tree View
new_name = "My_Fancy_FEM_Mesh"

newobj = App.ActiveDocument.addObject("Fem::FemMeshObject",new_name)
newobj.FemMesh = App.ActiveDocument.getObjectsByLabel(old_label)[0].FemMesh

Test:

App.ActiveDocument.getObject("My_Fancy_FEM_Mesh").FemMesh

Or even easier, select your FEMMesh which has not the Name you would like to have and copy the following code in python console:

new_name = "My_Fancy_FEM_Mesh"
newobj = App.ActiveDocument.addObject("Fem::FemMeshObject",new_name)
newobj.FemMesh = Gui.Selection.getSelection()[0].FemMesh

Started to improve the dat file reader since I will need it for shellthickness and beamsection node displacements. https://github.com/berndhahnebach/FreeCAD_bhb/blob/bad7454db4e83bf573a1e4421e0645c8b24a9d52/src/Mod/Fem/ccxDatReader.py

import ccxDatReader
ccxDatReader.import_dat(‘/home/hugo/Desktop/CalculiX–Results/Mesh.dat’)