本文整理汇总了Python中ObjectsFem类的典型用法代码示例。如果您正苦于以下问题:Python ObjectsFem类的具体用法?Python ObjectsFem怎么用?Python ObjectsFem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectsFem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_z88_disp
def import_z88_disp(filename, analysis=None, result_name_prefix=None):
'''insert a FreeCAD FEM mechanical result object in the ActiveDocument
'''
import importToolsFem
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
m = read_z88_disp(filename)
if(len(m['Nodes']) > 0):
if analysis is None:
analysis_name = os.path.splitext(os.path.basename(filename))[0]
analysis_object = ObjectsFem.makeAnalysis('Analysis')
analysis_object.Label = analysis_name
else:
analysis_object = analysis # see if statement few lines later, if not analysis -> no FemMesh object is created !
for result_set in m['Results']:
results_name = result_name_prefix + 'results'
results = ObjectsFem.makeResultMechanical(results_name)
for m in analysis_object.Member: # TODO analysis could have multiple mesh objects in the future
if m.isDerivedFrom("Fem::FemMeshObject"):
results.Mesh = m
break
results = importToolsFem.fill_femresult_mechanical(results, result_set, 0)
analysis_object.Member = analysis_object.Member + [results]
if(FreeCAD.GuiUp):
import FemGui
FemGui.setActiveAnalysis(analysis_object)
示例2: importVTK
def importVTK(filename, analysis=None, result_name_prefix=None):
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
if analysis is None:
analysis_name = os.path.splitext(os.path.basename(filename))[0]
analysis_object = ObjectsFem.makeAnalysis('Analysis')
analysis_object.Label = analysis_name
else:
analysis_object = analysis
# if properties can be added in FemVTKTools importCfdResult(), this file can be used for CFD workbench
results_name = result_name_prefix + 'results'
result_obj = ObjectsFem.makeResultMechanical(results_name)
# result_obj = FreeCAD.ActiveDocument.addObject('Fem::FemResultObject', results_name)
Fem.readResult(filename, result_obj.Name) # readResult always creates a new femmesh named ResultMesh
# workaround for the DisplacementLengths (They should have been calculated by Fem.readResult)
if not result_obj.DisplacementLengths:
import importToolsFem
result_obj.DisplacementLengths = importToolsFem.calculate_disp_abs(result_obj.DisplacementVectors)
analysis_object.Member = analysis_object.Member + [result_obj]
# FIXME move the ResultMesh in the analysis
''' seams not used at the moment
示例3: import_z88_disp
def import_z88_disp(
filename,
analysis=None,
result_name_prefix=None
):
'''insert a FreeCAD FEM mechanical result object in the ActiveDocument
pure usage:
import feminout.importZ88O2Results as importZ88O2Results
disp_file = '/pathtofile/z88o2.txt'
importZ88O2Results.import_z88_disp(disp_file)
the z888i1.txt FEMMesh file needs to be in the same directory as z88o2.txt
# ahh, make a new document first ;-)
'''
from . import importZ88Mesh
from . import importToolsFem
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
disp_read = read_z88_disp(filename)
result_mesh_object = None
if len(disp_read['Nodes']) > 0:
if analysis:
analysis_object = analysis
# read result mesh
if filename.endswith('z88o2.txt'):
mesh_file = filename.replace('o2', 'i1')
mesh_data = importZ88Mesh.read_z88_mesh(mesh_file)
femmesh = importToolsFem.make_femmesh(mesh_data)
result_mesh_object = ObjectsFem.makeMeshResult(
FreeCAD.ActiveDocument,
'Result_mesh'
)
result_mesh_object.FemMesh = femmesh
else:
FreeCAD.Console.PrintError('Z88 mesh file z88i1.txt not found!')
# create result obj
for result_set in disp_read['Results']:
results_name = result_name_prefix + 'results'
res_obj = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
res_obj.Mesh = result_mesh_object
res_obj = importToolsFem.fill_femresult_mechanical(res_obj, result_set)
if analysis:
analysis_object.addObject(res_obj)
if FreeCAD.GuiUp:
if analysis:
import FemGui
FemGui.setActiveAnalysis(analysis_object)
FreeCAD.ActiveDocument.recompute()
else:
FreeCAD.Console.PrintError(
'Problem on Z88 result file import. No nodes found in Z88 result file.\n'
)
return res_obj
示例4: importFrd
def importFrd(filename, analysis=None, result_name_prefix=None):
import importToolsFem
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
m = readResult(filename)
mesh_object = None
if(len(m['Nodes']) > 0):
if analysis is None:
analysis_name = os.path.splitext(os.path.basename(filename))[0]
analysis_object = ObjectsFem.makeAnalysis('Analysis')
analysis_object.Label = analysis_name
else:
analysis_object = analysis # see if statement few lines later, if not analysis -> no FemMesh object is created !
if 'Nodes' in m:
positions = []
for k, v in m['Nodes'].items():
positions.append(v)
p_x_max, p_y_max, p_z_max = map(max, zip(*positions))
p_x_min, p_y_min, p_z_min = map(min, zip(*positions))
x_span = abs(p_x_max - p_x_min)
y_span = abs(p_y_max - p_y_min)
z_span = abs(p_z_max - p_z_min)
span = max(x_span, y_span, z_span)
if (not analysis):
mesh = importToolsFem.make_femmesh(m)
if len(m['Nodes']) > 0:
mesh_object = FreeCAD.ActiveDocument.addObject('Fem::FemMeshObject', 'ResultMesh')
mesh_object.FemMesh = mesh
analysis_object.Member = analysis_object.Member + [mesh_object]
number_of_increments = len(m['Results'])
for result_set in m['Results']:
eigenmode_number = result_set['number']
step_time = result_set['time']
step_time = round(step_time, 2)
if eigenmode_number > 0:
results_name = result_name_prefix + 'mode_' + str(eigenmode_number) + '_results'
elif number_of_increments > 1:
results_name = result_name_prefix + 'time_' + str(step_time) + '_results'
else:
results_name = result_name_prefix + 'results'
results = ObjectsFem.makeResultMechanical(results_name)
for m in analysis_object.Member: # TODO analysis could have multiple mesh objects in the future
if m.isDerivedFrom("Fem::FemMeshObject"):
results.Mesh = m
break
results = importToolsFem.fill_femresult_mechanical(results, result_set, span)
analysis_object.Member = analysis_object.Member + [results]
if(FreeCAD.GuiUp):
import FemGui
FemGui.setActiveAnalysis(analysis_object)
示例5: importFrd
def importFrd(filename, analysis=None, result_name_prefix=None):
from . import importToolsFem
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
m = readResult(filename)
result_mesh_object = None
if len(m['Nodes']) > 0:
if analysis:
analysis_object = analysis
mesh = importToolsFem.make_femmesh(m)
result_mesh_object = ObjectsFem.makeMeshResult(FreeCAD.ActiveDocument, 'Result_mesh')
result_mesh_object.FemMesh = mesh
positions = []
for k, v in m['Nodes'].items():
positions.append(v)
p_x_max, p_y_max, p_z_max = map(max, zip(*positions))
p_x_min, p_y_min, p_z_min = map(min, zip(*positions))
x_span = abs(p_x_max - p_x_min)
y_span = abs(p_y_max - p_y_min)
z_span = abs(p_z_max - p_z_min)
span = max(x_span, y_span, z_span)
number_of_increments = len(m['Results'])
for result_set in m['Results']:
if 'number' in result_set:
eigenmode_number = result_set['number']
else:
eigenmode_number = 0
step_time = result_set['time']
step_time = round(step_time, 2)
if eigenmode_number > 0:
results_name = result_name_prefix + 'mode_' + str(eigenmode_number) + '_results'
elif number_of_increments > 1:
results_name = result_name_prefix + 'time_' + str(step_time) + '_results'
else:
results_name = result_name_prefix + 'results'
results = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
results.Mesh = result_mesh_object
results = importToolsFem.fill_femresult_mechanical(results, result_set, span)
if analysis:
analysis_object.addObject(results)
if FreeCAD.GuiUp:
if analysis:
import FemGui
FemGui.setActiveAnalysis(analysis_object)
FreeCAD.ActiveDocument.recompute()
else:
FreeCAD.Console.PrintError('Problem on frd file import. No nodes found in frd file.\n')
示例6: importVtkFCResult
def importVtkFCResult(filename, resultname, analysis=None, result_name_prefix=None):
# only fields from vtk are imported if they exactly named as the FreeCAD result properties
# See _getFreeCADMechResultProperties() in FemVTKTools.cpp for the supported names
import ObjectsFem
from . import importToolsFem
if result_name_prefix is None:
result_name_prefix = ''
if analysis:
analysis_object = analysis
results_name = result_name_prefix + 'results'
result_obj = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
Fem.readResult(filename, result_obj.Name) # readResult always creates a new femmesh named ResultMesh
# workaround for the DisplacementLengths (They should have been calculated by Fem.readResult)
if not result_obj.DisplacementLengths:
result_obj.DisplacementLengths = importToolsFem.calculate_disp_abs(result_obj.DisplacementVectors)
FreeCAD.Console.PrintMessage('Recalculated DisplacementLengths.\n')
''' seems unused at the moment
filenamebase = '.'.join(filename.split('.')[:-1]) # pattern: filebase_timestamp.vtk
ts = filenamebase.split('_')[-1]
try:
time_step = float(ts)
except:
time_step = 0.0
'''
if analysis:
analysis_object.addObject(result_obj)
result_obj.touch()
FreeCAD.ActiveDocument.recompute()
示例7: setup_cantileverfaceload
def setup_cantileverfaceload(doc=None, solver='ccxtools'):
# setup CalculiX cantilever, apply 9 MN on surface of front end face
doc = setup_cantileverbase(doc, solver)
# force_constraint
force_constraint = doc.Analysis.addObject(ObjectsFem.makeConstraintForce(doc, name="ConstraintForce"))[0]
force_constraint.References = [(doc.Box, "Face2")]
force_constraint.Force = 9000000.0
force_constraint.Direction = (doc.Box, ["Edge5"])
force_constraint.Reversed = True
doc.recompute()
return doc
示例8: setup_cantilevernodeload
def setup_cantilevernodeload(doc=None, solver='ccxtools'):
# setup CalculiX cantilever, apply 9 MN on the 4 nodes of the front end face
doc = setup_cantileverbase(doc, solver)
# force_constraint
force_constraint = doc.Analysis.addObject(ObjectsFem.makeConstraintForce(doc, name="ConstraintForce"))[0]
force_constraint.References = [(doc.Box, "Vertex5"), (doc.Box, "Vertex6"), (doc.Box, "Vertex7"), (doc.Box, "Vertex8")] # should be possible in one tuple too
force_constraint.Force = 9000000.0
force_constraint.Direction = (doc.Box, ["Edge5"])
force_constraint.Reversed = True
doc.recompute()
return doc
示例9: setup_cantileverprescribeddisplacement
def setup_cantileverprescribeddisplacement(doc=None, solver='ccxtools'):
# setup CalculiX cantilever, apply a prescribed displacement of 250 mm in -z on the front end face
doc = setup_cantileverbase(doc, solver)
# displacement_constraint
displacement_constraint = doc.Analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc, name="ConstraintDisplacmentPrescribed"))[0]
displacement_constraint.References = [(doc.Box, "Face2")]
displacement_constraint.zFix = False
displacement_constraint.zFree = False
displacement_constraint.zDisplacement = -250.0
doc.recompute()
return doc
示例10: test_adding_refshaps
def test_adding_refshaps(self):
doc = self.active_doc
slab = doc.addObject("Part::Plane", "Face")
slab.Length = 500.00
slab.Width = 500.00
cf = ObjectsFem.makeConstraintFixed(doc)
ref_eles = []
# FreeCAD list property seam not to support append, thus we need some workaround, which is on many elements even much faster
for i, face in enumerate(slab.Shape.Edges):
ref_eles.append("Edge%d" % (i + 1))
cf.References = [(slab, ref_eles)]
doc.recompute()
expected_reflist = [(slab, ('Edge1', 'Edge2', 'Edge3', 'Edge4'))]
assert_err_message = 'Adding reference shapes did not result in expected list ' + str(cf.References) + ' != ' + str(expected_reflist)
self.assertEqual(cf.References, expected_reflist, assert_err_message)
示例11: importVTK
def importVTK(filename, analysis=None, result_name_prefix=None):
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
if analysis:
analysis_object = analysis
# if properties can be added in FemVTKTools importCfdResult(), this file can be used for CFD workbench
results_name = result_name_prefix + 'results'
result_obj = ObjectsFem.makeResultMechanical(results_name)
Fem.readResult(filename, result_obj.Name) # readResult always creates a new femmesh named ResultMesh
# workaround for the DisplacementLengths (They should have been calculated by Fem.readResult)
if not result_obj.DisplacementLengths:
import importToolsFem
result_obj.DisplacementLengths = importToolsFem.calculate_disp_abs(result_obj.DisplacementVectors)
if analysis:
analysis_object.Member = analysis_object.Member + [result_obj]
''' seams not used at the moment
示例12: importVtkFCResult
def importVtkFCResult(
filename,
resultname,
analysis=None,
result_name_prefix=None
):
# only fields from vtk are imported if they exactly named as the FreeCAD result properties
# See _getFreeCADMechResultProperties() in FemVTKTools.cpp for the supported names
import ObjectsFem
if result_name_prefix is None:
result_name_prefix = ''
if analysis:
analysis_object = analysis
results_name = result_name_prefix + 'results'
result_obj = ObjectsFem.makeResultMechanical(FreeCAD.ActiveDocument, results_name)
# readResult always creates a new femmesh named ResultMesh
Fem.readResult(filename, result_obj.Name)
# add missing DisplacementLengths (They should have been added by Fem.readResult)
if not result_obj.DisplacementLengths:
import femresult.resulttools as restools
result_obj = restools.add_disp_apps(result_obj) # DisplacementLengths
''' seems unused at the moment
filenamebase = '.'.join(filename.split('.')[:-1]) # pattern: filebase_timestamp.vtk
ts = filenamebase.split('_')[-1]
try:
time_step = float(ts)
except:
time_step = 0.0
'''
if analysis:
analysis_object.addObject(result_obj)
result_obj.touch()
FreeCAD.ActiveDocument.recompute()
return result_obj
示例13: test_4_thermomech_analysis
def test_4_thermomech_analysis(self):
fcc_print('--------------- Start of FEM tests ---------------')
box = self.active_doc.addObject("Part::Box", "Box")
box.Height = 25.4
box.Width = 25.4
box.Length = 203.2
fcc_print('Checking FEM new analysis...')
analysis = ObjectsFem.makeAnalysis(self.active_doc, 'Analysis')
self.assertTrue(analysis, "FemTest of new analysis failed")
fcc_print('Checking FEM new solver...')
solver_object = ObjectsFem.makeSolverCalculixCcxTools(self.active_doc, 'CalculiX')
solver_object.AnalysisType = 'thermomech'
solver_object.GeometricalNonlinearity = 'linear'
solver_object.ThermoMechSteadyState = True
solver_object.MatrixSolverType = 'default'
solver_object.IterationsThermoMechMaximum = 2000
solver_object.IterationsControlParameterTimeUse = True
self.assertTrue(solver_object, "FemTest of new solver failed")
analysis.addObject(solver_object)
fcc_print('Checking FEM new material...')
material_object = ObjectsFem.makeMaterialSolid(self.active_doc, 'MechanicalMaterial')
mat = material_object.Material
mat['Name'] = "Steel-Generic"
mat['YoungsModulus'] = "200000 MPa"
mat['PoissonRatio'] = "0.30"
mat['Density'] = "7900 kg/m^3"
mat['ThermalConductivity'] = "43.27 W/m/K" # SvdW: Change to Ansys model values
mat['ThermalExpansionCoefficient'] = "12 um/m/K"
mat['SpecificHeat'] = "500 J/kg/K" # SvdW: Change to Ansys model values
material_object.Material = mat
self.assertTrue(material_object, "FemTest of new material failed")
analysis.addObject(material_object)
fcc_print('Checking FEM new fixed constraint...')
fixed_constraint = self.active_doc.addObject("Fem::ConstraintFixed", "FemConstraintFixed")
fixed_constraint.References = [(box, "Face1")]
self.assertTrue(fixed_constraint, "FemTest of new fixed constraint failed")
analysis.addObject(fixed_constraint)
fcc_print('Checking FEM new initial temperature constraint...')
initialtemperature_constraint = self.active_doc.addObject("Fem::ConstraintInitialTemperature", "FemConstraintInitialTemperature")
initialtemperature_constraint.initialTemperature = 300.0
self.assertTrue(initialtemperature_constraint, "FemTest of new initial temperature constraint failed")
analysis.addObject(initialtemperature_constraint)
fcc_print('Checking FEM new temperature constraint...')
temperature_constraint = self.active_doc.addObject("Fem::ConstraintTemperature", "FemConstraintTemperature")
temperature_constraint.References = [(box, "Face1")]
temperature_constraint.Temperature = 310.93
self.assertTrue(temperature_constraint, "FemTest of new temperature constraint failed")
analysis.addObject(temperature_constraint)
fcc_print('Checking FEM new heatflux constraint...')
heatflux_constraint = self.active_doc.addObject("Fem::ConstraintHeatflux", "FemConstraintHeatflux")
heatflux_constraint.References = [(box, "Face3"), (box, "Face4"), (box, "Face5"), (box, "Face6")]
heatflux_constraint.AmbientTemp = 255.3722
heatflux_constraint.FilmCoef = 5.678
self.assertTrue(heatflux_constraint, "FemTest of new heatflux constraint failed")
analysis.addObject(heatflux_constraint)
fcc_print('Checking FEM new mesh...')
from .testfiles.ccx.spine_mesh import create_nodes_spine
from .testfiles.ccx.spine_mesh import create_elements_spine
mesh = Fem.FemMesh()
ret = create_nodes_spine(mesh)
self.assertTrue(ret, "Import of mesh nodes failed")
ret = create_elements_spine(mesh)
self.assertTrue(ret, "Import of mesh volumes failed")
mesh_object = self.active_doc.addObject('Fem::FemMeshObject', self.mesh_name)
mesh_object.FemMesh = mesh
self.assertTrue(mesh, "FemTest of new mesh failed")
analysis.addObject(mesh_object)
self.active_doc.recompute()
thermomech_analysis_dir = self.temp_dir + 'FEM_ccx_thermomech/'
fea = ccxtools.FemToolsCcx(analysis, test_mode=True)
fcc_print('Setting up working directory {}'.format(thermomech_analysis_dir))
fea.setup_working_dir(thermomech_analysis_dir)
self.assertTrue(True if fea.working_dir == thermomech_analysis_dir else False,
"Setting working directory {} failed".format(thermomech_analysis_dir))
fcc_print('Checking FEM inp file prerequisites for thermo-mechanical analysis...')
error = fea.check_prerequisites()
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
fcc_print('Checking FEM inp file write...')
fcc_print('Writing {}/{}.inp for thermomech analysis'.format(thermomech_analysis_dir, self.mesh_name))
error = fea.write_inp_file()
self.assertFalse(error, "Writing failed")
thermomech_base_name = 'spine_thermomech'
thermomech_analysis_inp_file = self.test_file_dir + thermomech_base_name + '.inp'
fcc_print('Comparing {} to {}/{}.inp'.format(thermomech_analysis_inp_file, thermomech_analysis_dir, self.mesh_name))
ret = testtools.compare_inp_files(thermomech_analysis_inp_file, thermomech_analysis_dir + self.mesh_name + '.inp')
self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret))
#.........这里部分代码省略.........
示例14: test_2_static_multiple_material
def test_2_static_multiple_material(self):
fcc_print('--------------- Start of FEM ccxtools multiple material test ---------------')
# create a CompSolid of two Boxes extract the CompSolid (we are able to remesh if needed)
boxlow = self.active_doc.addObject("Part::Box", "BoxLower")
boxupp = self.active_doc.addObject("Part::Box", "BoxUpper")
boxupp.Placement.Base = (0, 0, 10)
# for BooleanFragments Occt >=6.9 is needed
'''
import BOPTools.SplitFeatures
bf = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
bf.Objects = [boxlow, boxupp]
bf.Mode = "CompSolid"
self.active_doc.recompute()
bf.Proxy.execute(bf)
bf.purgeTouched()
for obj in bf.ViewObject.Proxy.claimChildren():
obj.ViewObject.hide()
self.active_doc.recompute()
import CompoundTools.CompoundFilter
cf = CompoundTools.CompoundFilter.makeCompoundFilter(name='MultiMatCompSolid')
cf.Base = bf
cf.FilterType = 'window-volume'
cf.Proxy.execute(cf)
cf.purgeTouched()
cf.Base.ViewObject.hide()
'''
self.active_doc.recompute()
if FreeCAD.GuiUp:
import FreeCADGui
FreeCADGui.ActiveDocument.activeView().viewAxonometric()
FreeCADGui.SendMsgToActiveView("ViewFit")
analysis = ObjectsFem.makeAnalysis(self.active_doc, 'Analysis')
solver_object = ObjectsFem.makeSolverCalculixCcxTools(self.active_doc, 'CalculiXccxTools')
solver_object.AnalysisType = 'static'
solver_object.GeometricalNonlinearity = 'linear'
solver_object.ThermoMechSteadyState = False
solver_object.MatrixSolverType = 'default'
solver_object.IterationsControlParameterTimeUse = False
analysis.addObject(solver_object)
material_object_low = ObjectsFem.makeMaterialSolid(self.active_doc, 'MechanicalMaterialLow')
mat = material_object_low.Material
mat['Name'] = "Aluminium-Generic"
mat['YoungsModulus'] = "70000 MPa"
mat['PoissonRatio'] = "0.35"
mat['Density'] = "2700 kg/m^3"
material_object_low.Material = mat
material_object_low.References = [(boxlow, 'Solid1')]
analysis.addObject(material_object_low)
material_object_upp = ObjectsFem.makeMaterialSolid(self.active_doc, 'MechanicalMaterialUpp')
mat = material_object_upp.Material
mat['Name'] = "Steel-Generic"
mat['YoungsModulus'] = "200000 MPa"
mat['PoissonRatio'] = "0.30"
mat['Density'] = "7980 kg/m^3"
material_object_upp.Material = mat
material_object_upp.References = [(boxupp, 'Solid1')]
analysis.addObject(material_object_upp)
fixed_constraint = self.active_doc.addObject("Fem::ConstraintFixed", "ConstraintFixed")
# fixed_constraint.References = [(cf, "Face3")]
fixed_constraint.References = [(boxlow, "Face5")]
analysis.addObject(fixed_constraint)
pressure_constraint = self.active_doc.addObject("Fem::ConstraintPressure", "ConstraintPressure")
# pressure_constraint.References = [(cf, "Face9")]
pressure_constraint.References = [(boxupp, "Face6")]
pressure_constraint.Pressure = 1000.0
pressure_constraint.Reversed = False
analysis.addObject(pressure_constraint)
mesh = Fem.FemMesh()
import femtest.testfiles.ccx.multimat_mesh as multimatmesh
multimatmesh.create_nodes(mesh)
multimatmesh.create_elements(mesh)
mesh_object = self.active_doc.addObject('Fem::FemMeshObject', self.mesh_name)
mesh_object.FemMesh = mesh
analysis.addObject(mesh_object)
self.active_doc.recompute()
static_multiplemat_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_multimat/')
fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True)
fea.setup_working_dir(static_multiplemat_dir)
fcc_print('Checking FEM inp file prerequisites for ccxtools multimat analysis...')
error = fea.check_prerequisites()
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
fcc_print('Checking FEM inp file write...')
fcc_print('Writing {}/{}.inp for static multiple material'.format(static_multiplemat_dir, self.mesh_name))
error = fea.write_inp_file()
self.assertFalse(error, "Writing failed")
static_base_name = 'multimat'
static_analysis_inp_file = self.test_file_dir + static_base_name + '.inp'
fcc_print('Comparing {} to {}/{}.inp'.format(static_analysis_inp_file, static_multiplemat_dir, self.mesh_name))
ret = testtools.compare_inp_files(static_analysis_inp_file, static_multiplemat_dir + self.mesh_name + '.inp')
#.........这里部分代码省略.........
示例15: test_3_freq_analysis
def test_3_freq_analysis(self):
fcc_print('--------------- Start of FEM tests ---------------')
self.active_doc.addObject("Part::Box", "Box")
fcc_print('Checking FEM new analysis...')
analysis = ObjectsFem.makeAnalysis(self.active_doc, 'Analysis')
self.assertTrue(analysis, "FemTest of new analysis failed")
fcc_print('Checking FEM new solver...')
solver_object = ObjectsFem.makeSolverCalculixCcxTools(self.active_doc, 'CalculiX')
solver_object.AnalysisType = 'frequency'
solver_object.GeometricalNonlinearity = 'linear'
solver_object.ThermoMechSteadyState = False
solver_object.MatrixSolverType = 'default'
solver_object.IterationsControlParameterTimeUse = False
solver_object.EigenmodesCount = 10
solver_object.EigenmodeHighLimit = 1000000.0
solver_object.EigenmodeLowLimit = 0.01
self.assertTrue(solver_object, "FemTest of new solver failed")
analysis.addObject(solver_object)
fcc_print('Checking FEM new material...')
material_object = ObjectsFem.makeMaterialSolid(self.active_doc, 'MechanicalMaterial')
mat = material_object.Material
mat['Name'] = "Steel-Generic"
mat['YoungsModulus'] = "200000 MPa"
mat['PoissonRatio'] = "0.30"
mat['Density'] = "7900 kg/m^3"
material_object.Material = mat
self.assertTrue(material_object, "FemTest of new material failed")
analysis.addObject(material_object)
fcc_print('Checking FEM new mesh...')
from .testfiles.ccx.cube_mesh import create_nodes_cube
from .testfiles.ccx.cube_mesh import create_elements_cube
mesh = Fem.FemMesh()
ret = create_nodes_cube(mesh)
self.assertTrue(ret, "Import of mesh nodes failed")
ret = create_elements_cube(mesh)
self.assertTrue(ret, "Import of mesh volumes failed")
mesh_object = self.active_doc.addObject('Fem::FemMeshObject', self.mesh_name)
mesh_object.FemMesh = mesh
self.assertTrue(mesh, "FemTest of new mesh failed")
analysis.addObject(mesh_object)
self.active_doc.recompute()
frequency_analysis_dir = testtools.get_unit_test_tmp_dir(self.temp_dir, 'FEM_ccx_frequency')
fea = ccxtools.FemToolsCcx(analysis, solver_object, test_mode=True)
fea.update_objects()
fcc_print('Setting up working directory {}'.format(frequency_analysis_dir))
fea.setup_working_dir(frequency_analysis_dir)
self.assertTrue(True if fea.working_dir == frequency_analysis_dir else False,
"Setting working directory {} failed".format(frequency_analysis_dir))
fcc_print('Checking FEM inp file prerequisites for frequency analysis...')
error = fea.check_prerequisites()
self.assertFalse(error, "ccxtools check_prerequisites returned error message: {}".format(error))
frequency_base_name = 'cube_frequency'
inpfile_given = join(self.test_file_dir, (frequency_base_name + '.inp'))
inpfile_totest = join(frequency_analysis_dir, (self.mesh_name + '.inp'))
fcc_print('Checking FEM inp file write...')
fcc_print('Writing {} for frequency analysis'.format(inpfile_totest))
error = fea.write_inp_file()
self.assertFalse(error, "Writing failed")
fcc_print('Comparing {} to {}'.format(inpfile_given, inpfile_totest))
ret = testtools.compare_inp_files(inpfile_given, inpfile_totest)
self.assertFalse(ret, "ccxtools write_inp_file test failed.\n{}".format(ret))
fcc_print('Setting up working directory to {} in order to read simulated calculations'.format(self.test_file_dir))
fea.setup_working_dir(self.test_file_dir)
self.assertTrue(True if fea.working_dir == self.test_file_dir else False,
"Setting working directory {} failed".format(self.test_file_dir))
fcc_print('Setting base name to read test {}.frd file...'.format(frequency_base_name))
fea.set_base_name(frequency_base_name)
self.assertTrue(True if fea.base_name == frequency_base_name else False,
"Setting base name to {} failed".format(frequency_base_name))
fcc_print('Setting inp file name to read test {}.frd file...'.format('cube_frequency'))
fea.set_inp_file_name()
self.assertTrue(True if fea.inp_file_name == inpfile_given else False,
"Setting inp file name to {} failed".format(inpfile_given))
fcc_print('Checking FEM frd file read from frequency analysis...')
fea.load_results()
self.assertTrue(fea.results_present, "Cannot read results from {}.frd frd file".format(fea.base_name))
fcc_print('Reading stats from result object for frequency analysis...')
frequency_expected_values = join(self.test_file_dir, "cube_frequency_expected_values")
ret = testtools.compare_stats(fea, frequency_expected_values, 'CalculiX_frequency_mode_1_results')
self.assertFalse(ret, "Invalid results read from .frd file")
frequency_save_fc_file = frequency_analysis_dir + frequency_base_name + '.FCStd'
fcc_print('Save FreeCAD file for frequency analysis to {}...'.format(frequency_save_fc_file))
self.active_doc.saveAs(frequency_save_fc_file)
fcc_print('--------------- End of FEM tests frequency analysis ---------------')