本文整理汇总了Python中Fem类的典型用法代码示例。如果您正苦于以下问题:Python Fem类的具体用法?Python Fem怎么用?Python Fem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export
def export(
objectslist,
filename
):
"called when freecad exports an object to vtk"
if len(objectslist) > 1: # the case of no selected obj is caught by FreeCAD already
FreeCAD.Console.PrintError(
"This exporter can only export one object at once\n"
)
return
obj = objectslist[0]
if obj.isDerivedFrom("Fem::FemPostPipeline"):
FreeCAD.Console.PrintError(
'Export of a VTK post object to vtk is not yet implemented !\n'
)
return
elif obj.isDerivedFrom("Fem::FemMeshObject"):
FreeCAD.Console.PrintError(
'Use export to FEM mesh formats to export a FEM mesh object to vtk!\n'
)
return
elif obj.isDerivedFrom("Fem::FemResultObject"):
Fem.writeResult(filename, obj)
else:
FreeCAD.Console.PrintError(
'Selected object is not supported by export to VTK.\n'
)
return
示例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: 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()
示例4: export
def export(objectslist, filename):
"called when freecad exports a fem result object"
if len(objectslist) != 1:
FreeCAD.Console.PrintError("This exporter can only export one object at once\n")
return
obj = objectslist[0]
if not obj.isDerivedFrom("Fem::FemResultObject"):
FreeCAD.Console.PrintError("object selcted is not FemResultObject.\n")
return
Fem.writeResult(filename, obj)
示例5: test_tetra10_vkt
def test_tetra10_vkt(self):
# tetra10 element: reading from and writing to unv mesh file format
filetyp = 'vtk'
outfile = self.base_outfile + filetyp
testfile = self.base_testfile + filetyp
# fcc_print(outfile)
# fcc_print(testfile)
if "BUILD_FEM_VTK" in FreeCAD.__cmake__:
self.femmesh.write(outfile) # write the mesh
femmesh_outfile = Fem.read(outfile) # read the mesh from written mesh
femmesh_testfile = Fem.read(testfile) # read the mesh from test mesh
# reading the test mesh
self.assertEqual(
femmesh_testfile.Nodes,
self.expected_nodes['nodes'],
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
[femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])],
self.expected_elem['volumes'],
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
# reading the written mesh
self.assertEqual(
femmesh_outfile.Nodes,
self.expected_nodes['nodes'],
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
[femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])],
self.expected_elem['volumes'],
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
# both
self.assertEqual(
femmesh_outfile.Nodes,
femmesh_testfile.Nodes,
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
femmesh_outfile.Volumes,
femmesh_testfile.Volumes,
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
else:
fcc_print('FEM_VTK post processing is disabled.')
示例6: read_and_set_new_mesh
def read_and_set_new_mesh(self):
if not self.error:
fem_mesh = Fem.read(self.temp_file_mesh)
self.mesh_obj.FemMesh = fem_mesh
print(' The Part should have a pretty new FEM mesh!')
else:
print('No mesh was created.')
del self.temp_file_geometry
del self.temp_file_mesh
示例7: importVtkFemMesh
def importVtkFemMesh(
filename,
meshname
):
meshobj = FreeCAD.ActiveDocument.addObject("Fem::FemMeshObject", meshname)
meshobj.FemMesh = Fem.read(filename)
meshobj.touch()
FreeCAD.ActiveDocument.recompute()
return meshobj
示例8: test_tetra10_inp
def test_tetra10_inp(self):
# tetra10 element: reading from and writing to inp mesh file format
filetyp = 'inp'
outfile = self.base_outfile + filetyp
testfile = self.base_testfile + filetyp
# fcc_print(outfile)
# fcc_print(testfile)
self.femmesh.writeABAQUS(outfile, 1, False) # write the mesh
femmesh_outfile = Fem.read(outfile) # read the mesh from written mesh
femmesh_testfile = Fem.read(testfile) # read the mesh from test mesh
# reading the test mesh
# fcc_print([femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])])
self.assertEqual(
femmesh_testfile.Nodes,
self.expected_nodes['nodes'],
"Test reading " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
[femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])],
self.expected_elem['volumes'],
"Test reading " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
# reading the written mesh
self.assertEqual(
femmesh_outfile.Nodes,
self.expected_nodes['nodes'],
"Test reading " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
[femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])],
self.expected_elem['volumes'],
"Test reading " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
# both
self.assertEqual(
femmesh_outfile.Nodes,
femmesh_testfile.Nodes,
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Nodes are different.\n"
)
self.assertEqual(
[femmesh_outfile.Volumes[0], femmesh_outfile.getElementNodes(femmesh_outfile.Volumes[0])],
[femmesh_testfile.Volumes[0], femmesh_testfile.getElementNodes(femmesh_outfile.Volumes[0])],
"Test writing " + self.elem + " mesh to " + filetyp + " file failed. Volumes are different.\n"
)
示例9: 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
示例10: 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
示例11: gmshmesh
def gmshmesh(compound, NG2D, name=""):
'''
export, mesh compound at gmsh, reimport as .unv
(3d to be implemented)
'''
if name =="": name="m_"+compound.Label
#
ImportGui.export([FreeCAD.activeDocument().getObject(compound.Name)], "/tmp/tmpNO2c.step")
#
command="/usr/bin/gmsh /tmp/tmpNO2c.step -2 -format unv -o /tmp/"+name+".unv -algo "+str(NG2D.gmshalgoname)+" -clmax " +str(NG2D.NGParamSetMaxSize)+" -clmin "+str(NG2D.NGParamSetMinSize)+" -string Geometry.OCCSewFaces=1;"
#command="/usr/bin/gmsh /tmp/tmpNO2c.step -2 -format unv -o /tmp/Compound019_Mesh.unv -algo auto -string Geometry.OCCSewFaces=1;"
#command="g"
#
#print command
output = subprocess.check_output([command, '-1'], shell=True, stderr=subprocess.STDOUT,)
FreeCAD.Console.PrintMessage(output)
#
Fem.insert("/tmp/"+name+".unv", FreeCAD.ActiveDocument.Name)
#Fem.insert("/tmp/Compound019_Mesh.unv", FreeCAD.ActiveDocument.Name)
femmesh=FreeCAD.ActiveDocument.Objects[len(FreeCAD.ActiveDocument.Objects)-1]
FreeCADGui.ActiveDocument.getObject(femmesh.Name).DisplayMode = "Wireframe"
return femmesh
示例12: test_unv_save_load
def test_unv_save_load(self):
tetra10 = Fem.FemMesh()
tetra10.addNode(6, 12, 18, 1)
tetra10.addNode(0, 0, 18, 2)
tetra10.addNode(12, 0, 18, 3)
tetra10.addNode(6, 6, 0, 4)
tetra10.addNode(3, 6, 18, 5)
tetra10.addNode(6, 0, 18, 6)
tetra10.addNode(9, 6, 18, 7)
tetra10.addNode(6, 9, 9, 8)
tetra10.addNode(3, 3, 9, 9)
tetra10.addNode(9, 3, 9, 10)
tetra10.addVolume([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
tetra10.write(static_save_unv_file)
newmesh = Fem.read(static_save_unv_file)
expected = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
self.assertEqual(newmesh.getElementNodes(1), expected, "Nodes order of quadratic volume element is unexpected")
示例13: start_calculation
def start_calculation(self):
self.button_add_to_table.setEnabled(False)
self.button_select_file.setEnabled(False)
self.button_select_output.setEnabled(False)
self.button_start_calculation.setEnabled(False)
os.chdir("/")
##Get values from the GUI
if ( os.path.exists(str(self.dirname)) ):
os.chdir("c:/")
shutil.rmtree(str(self.dirname))
os.mkdir(str(self.dirname))
batch = open(str(self.dirname + "/" + "lcmt_CALCULIX_Calculation_batch.bat"),'wb')
#Tell calculixs solver spooles how many cpus to use
#batch.write("export CCX_NPROC=" + str(self.params.GetInt("NumberCPUs")) + "\n")
#If we have a tcsh
#batch.write("setenv CCX_NPROC 4\n")
#Now do the calculation stuff for each row in the table
for job in range (0,self.JobTable.rowCount()):
#Extract the data from the table
current_file_name = self.JobTable.item(job,0).text()
z_offset_from = self.JobTable.item(job,2).data(QtCore.Qt.DisplayRole).toInt()[0]
z_offset_to = self.JobTable.item(job,3).data(QtCore.Qt.DisplayRole).toInt()[0]
z_offset_intervall = self.JobTable.item(job,4).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_from = self.JobTable.item(job,5).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_to = self.JobTable.item(job,6).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_intervall = self.JobTable.item(job,7).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_from = self.JobTable.item(job,8).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_to = self.JobTable.item(job,9).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_intervall = self.JobTable.item(job,10).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_from = self.JobTable.item(job,11).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_to = self.JobTable.item(job,12).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_intervall = self.JobTable.item(job,13).data(QtCore.Qt.DisplayRole).toInt()[0]
young_modulus = self.JobTable.item(job,14).data(QtCore.Qt.DisplayRole).toDouble()[0]
poisson_ratio = self.JobTable.item(job,15).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc1 = self.JobTable.item(job,16).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc2 = self.JobTable.item(job,17).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc3 = self.JobTable.item(job,18).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc4 = self.JobTable.item(job,19).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc5 = self.JobTable.item(job,20).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc6 = self.JobTable.item(job,21).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc1 = self.JobTable.item(job,22).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc2 = self.JobTable.item(job,23).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc3 = self.JobTable.item(job,24).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc4 = self.JobTable.item(job,25).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc5 = self.JobTable.item(job,26).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc6 = self.JobTable.item(job,27).data(QtCore.Qt.DisplayRole).toDouble()[0]
plate_thickness = self.JobTable.item(job,28).data(QtCore.Qt.DisplayRole).toDouble()[0]
filename_without_suffix = self.JobTable.item(job,0).text().split("/").takeLast().split(".")[0]
meshobject = Fem.read(str(current_file_name))
#Perform PCA
Fem.SMESH_PCA(meshobject)
#Do min routine
Fem.minBoundingBox(meshobject)
#Now get the Node Numbers for the Boundary Conditions
node_numbers = []
node_numbers = Fem.getBoundary_Conditions(meshobject)
#Now we have set up the initial geometry for the calculations. Lets generate an ABAQUS input file now for each z-level with exactly the same
#boundary conditions
#1. Lets translate the geometry to the initial desired z-level
#2. Generate a Folder for the current calculation z-level and output the ABAQUS Geometry and the boundary_conditions
#Lets first generate a subfolder with the current filename
os.mkdir(str(self.dirname + "/" + filename_without_suffix))
i = z_offset_from
while i <= z_offset_to:
j = x_rot_from
while j <= x_rot_to:
k = y_rot_from
while k <= y_rot_to:
l = z_rot_from
while l <= z_rot_to:
rotation_around_x = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(1,0,0),j)
rotation_around_y = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,1,0),k)
rotation_around_z = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,0,1),l)
translate = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,i),FreeCAD.Base.Vector(0,0,0),0.0)
translation = rotation_around_x.multiply(rotation_around_y).multiply(rotation_around_z).multiply(translate)
#Now lets check if the part is still in the billet due to the rotation. If not, we directly skip to the next rotation value
if(Fem.checkBB(meshobject,translation,plate_thickness)):
print "Too heavy rotations"
l= l + z_rot_intervall
continue
print "it seems that nothing changed"
#Use the placedment as optional argument for the write() method
#translated_mesh.setTransform(translation)
Case_Dir = str(self.dirname) + "/" + filename_without_suffix + "/" + filename_without_suffix +\
"_"+"x_rot"+ str(int(j))+ \
"_"+"y_rot"+ str(int(k))+ \
"_"+"z_rot"+ str(int(l))+ \
"_"+"z_l"+ str(int(i))
if ( os.path.exists(str(Case_Dir)) ):
os.chdir(str(self.dirname))
shutil.rmtree(str(Case_Dir))
os.mkdir(str(Case_Dir))
#.........这里部分代码省略.........
示例14: start_calculation
def start_calculation(self):
self.button_add_to_table.setEnabled(False)
self.button_select_file.setEnabled(False)
self.button_select_output.setEnabled(False)
self.button_start_calculation.setEnabled(False)
os.chdir(homepath)
##Get values from the GUI
if ( os.path.exists(str(self.dirname)) ):
os.chdir(homepath)
shutil.rmtree(str(self.dirname))
os.mkdir(str(self.dirname))
batch = open(str(self.dirname + "/" + "lcmt_CALCULIX_Calculation_batch.bat"),'wb')
batch.write("#!/bin/bash\n")
batch.write("export CCX_NPROC=4\n")
#Tell calculixs solver spooles how many cpus to use
#batch.write("export CCX_NPROC=" + str(self.params.GetInt("NumberCPUs")) + "\n")
#If we have a tcsh
#batch.write("setenv CCX_NPROC 4\n")
#Now do the calculation stuff for each row in the table
for job in range (0,self.JobTable.rowCount()):
#Extract the data from the table
current_file_name = self.JobTable.item(job,0).text()
z_offset_from = self.JobTable.item(job,2).data(QtCore.Qt.DisplayRole).toInt()[0]
z_offset_to = self.JobTable.item(job,3).data(QtCore.Qt.DisplayRole).toInt()[0]
z_offset_intervall = self.JobTable.item(job,4).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_from = self.JobTable.item(job,5).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_to = self.JobTable.item(job,6).data(QtCore.Qt.DisplayRole).toInt()[0]
x_rot_intervall = self.JobTable.item(job,7).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_from = self.JobTable.item(job,8).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_to = self.JobTable.item(job,9).data(QtCore.Qt.DisplayRole).toInt()[0]
y_rot_intervall = self.JobTable.item(job,10).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_from = self.JobTable.item(job,11).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_to = self.JobTable.item(job,12).data(QtCore.Qt.DisplayRole).toInt()[0]
z_rot_intervall = self.JobTable.item(job,13).data(QtCore.Qt.DisplayRole).toInt()[0]
young_modulus = self.JobTable.item(job,14).data(QtCore.Qt.DisplayRole).toDouble()[0]
poisson_ratio = self.JobTable.item(job,15).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc1 = self.JobTable.item(job,16).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc2 = self.JobTable.item(job,17).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc3 = self.JobTable.item(job,18).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc4 = self.JobTable.item(job,19).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc5 = self.JobTable.item(job,20).data(QtCore.Qt.DisplayRole).toDouble()[0]
lc6 = self.JobTable.item(job,21).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc1 = self.JobTable.item(job,22).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc2 = self.JobTable.item(job,23).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc3 = self.JobTable.item(job,24).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc4 = self.JobTable.item(job,25).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc5 = self.JobTable.item(job,26).data(QtCore.Qt.DisplayRole).toDouble()[0]
ltc6 = self.JobTable.item(job,27).data(QtCore.Qt.DisplayRole).toDouble()[0]
plate_thickness = self.JobTable.item(job,28).data(QtCore.Qt.DisplayRole).toDouble()[0]
filename_without_suffix = self.JobTable.item(job,0).text().split("/").takeLast().split(".")[0]
print current_file_name
meshobject = Fem.read(str(current_file_name))
#Perform PCA
Fem.SMESH_PCA(meshobject)
#Do min routine
Fem.minBoundingBox(meshobject)
#Now get the Node Numbers for the Boundary Conditions
node_numbers = []
node_numbers = Fem.getBoundary_Conditions(meshobject)
#Now we have set up the initial geometry for the calculations. Lets generate an ABAQUS input file now for each z-level with exactly the same
#boundary conditions
#1. Lets translate the geometry to the initial desired z-level
#2. Generate a Folder for the current calculation z-level and output the ABAQUS Geometry and the boundary_conditions
#Lets first generate a subfolder with the current filename
os.mkdir(str(self.dirname + "/" + filename_without_suffix))
i = z_offset_from
while i <= z_offset_to:
j = x_rot_from
while j <= x_rot_to:
k = y_rot_from
while k <= y_rot_to:
l = z_rot_from
while l <= z_rot_to:
rotation_around_x = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(1,0,0),j)
rotation_around_y = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,1,0),k)
rotation_around_z = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,0),FreeCAD.Base.Vector(0,0,1),l)
translate = FreeCAD.Base.Placement(FreeCAD.Base.Vector(0,0,i),FreeCAD.Base.Vector(0,0,0),0.0)
translation = rotation_around_x.multiply(rotation_around_y).multiply(rotation_around_z).multiply(translate)
#Now lets check if the part is still in the billet due to the rotation. If not, we directly skip to the next rotation value
if(Fem.checkBB(meshobject,translation,plate_thickness)):
print "Too heavy rotations"
print str(plate_thickness)
l= l + z_rot_intervall
continue
print "it seems that nothing changed"
print str(plate_thickness)
#Use the placedment as optional argument for the write() method
#translated_mesh.setTransform(translation)
Case_Dir = str(self.dirname) + "/" + filename_without_suffix + "/" + filename_without_suffix +\
"_"+"x_rot"+ str(int(j))+ \
"_"+"y_rot"+ str(int(k))+ \
"_"+"z_rot"+ str(int(l))+ \
"_"+"z_l"+ str(int(i))
#.........这里部分代码省略.........
示例15: cleanmeshdoubles
def cleanmeshdoubles(femmesh):
'''
find doubles nodes, double edges as they occur after gmsh (2d) unv import -by "checking for double interboundary edges"
eleminate edges, nodes and rereference
'''
#m=femmesh.FemMesh
nodeP=femmesh.FemMesh.Nodes
refnodes=[-1]*len(femmesh.FemMesh.Nodes)
res=[]
#res=[(-1,-1),(-1,-1),-1,-1]
resvec=[]
edgeE=femmesh.FemMesh.Edges
for a1 in edgeE:
if res!=[] and len(set([a1]) & set([i[3] for i in res]))!=0:
print "double"
continue
a=femmesh.FemMesh.getElementNodes(a1)
a2=femmesh.FemMesh.getNodeById(a[0])
a3=femmesh.FemMesh.getNodeById(a[1])
for a4 in set(femmesh.FemMesh.Edges)-set([a1]):
a5=femmesh.FemMesh.getElementNodes(a4)
a6=femmesh.FemMesh.getNodeById(a5[0])
a7=femmesh.FemMesh.getNodeById(a5[1])
if [a2,a3]==[a6,a7] or [a3,a2]==[a6,a7]:
if a2==a6:
doublenode1=a[0]
doublenode2=a5[0]
doublenode3=a[1]
doublenode4=a5[1]
else:
doublenode1=a[1]
doublenode2=a5[0]
doublenode3=a[0]
doublenode4=a5[1]
print "first edge endpoints vectors:" + str(a2) + " " + str(a3)+"double nodes " + str(a) + " " + str(a5) +"first +double edge: " + str(a1) + " " + str(a4) +"\ndoublenodespair1by2: " + str(doublenode1) +" "+ str(doublenode2) +"\ndoublenodespair3by4: " + str(doublenode3) +" "+ str(doublenode4)
res.append([a,a5,a1,a4])
resvec.append([[a2,a3]])
#eleminate double edges
edgeE=set(edgeE)-set([a4])
#eleminate (hopefully) all double nodes and reference them
if doublenode2 in nodeP:
del nodeP[doublenode2]
refnodes[doublenode2]=doublenode1
if doublenode4 in nodeP:
del nodeP[doublenode4]
refnodes[doublenode4]=doublenode3
#del nodeP[doublenode4]
break
#!1find and substitute double nodes in face element nodes
facesE=[femmesh.FemMesh.getElementNodes(fac) for fac in list(edgeE.union(femmesh.FemMesh.Faces))]
first_n_plain=[resi1 for resi in res for resi1 in resi[0]]
double_n_plain=[resi1 for resi in res for resi1 in resi[1]]
elenodes=[]
for fac in range(len(facesE)):
#print "h3"
elen=list(set(facesE[fac]) & set(double_n_plain))
#print "h4"
if len(elen)>0:
#print "h4"
factem=facesE[fac]
#print "h4.2"
for i2 in range(len(elen)):
#print "h5"
lfac=list(facesE[fac])
#print "h6 " +str(i2) + " " +str(elen)
lfac[lfac.index(elen[i2])]=first_n_plain[double_n_plain.index(elen[i2])]
#print "h7"
facesE[fac]=tuple(lfac)
print str(elen) +"mface i with 2 double node:" + str(fac) +"to be substituted by:" + str(first_n_plain[double_n_plain.index(elen[0])]) +" to " +str(facesE[fac])+" from " +str(factem)
#elenodes.append(elen) #fac[fac.index(elen)]=first_n_plain[double_n_plain.index(elen)]
# if len(elen)==1:print str(elen)+"mface with 1 double node:" + str(fac)
#!rebuild mesh
import FreeCAD, Fem
m = Fem.FemMesh()
for n in nodeP.keys():
#print str(n1) + " :" + str(n)
n1=nodeP[n]
#print str(n1) + " :" + str(n)
m.addNode(n1.x, n1.y, n1.z, n)
elemN=list(edgeE.union(femmesh.FemMesh.Faces))
for i in range(len(facesE)):
#print str(facesE[i]) + "" + str(elemN[i])
#loose id's here
if len(facesE[i])==3:
m.addFace(facesE[i][0],facesE[i][1],facesE[i][2])
if len(facesE[i])==2:
a=m.addEdge(facesE[i][0],facesE[i][1])
Fem.show(m)
femmesh2=femmesh1.Document.Objects[len(femmesh1.Document.Objects)-1]
return femmesh2