Fem: Improve self weight constraint - fixes #11652
This commit is contained in:
committed by
Chris Hennes
parent
30b907ec5d
commit
9da842d884
@@ -124,7 +124,7 @@ def setup(doc=None, solvertype="ccxtools"):
|
||||
|
||||
# constraint selfweight
|
||||
con_selfweight = ObjectsFem.makeConstraintSelfWeight(doc, "ConstraintSelfWeight")
|
||||
con_selfweight.Gravity_z = -1.00
|
||||
con_selfweight.GravityDirection = (0, 0, -1)
|
||||
analysis.addObject(con_selfweight)
|
||||
|
||||
# mesh
|
||||
|
||||
@@ -29,7 +29,9 @@ __url__ = "https://www.freecad.org"
|
||||
# \ingroup FEM
|
||||
# \brief constraint self weight object
|
||||
|
||||
import FreeCAD
|
||||
from . import base_fempythonobject
|
||||
from femtools import constants
|
||||
|
||||
|
||||
class ConstraintSelfWeight(base_fempythonobject.BaseFemPythonObject):
|
||||
@@ -42,33 +44,52 @@ class ConstraintSelfWeight(base_fempythonobject.BaseFemPythonObject):
|
||||
def __init__(self, obj):
|
||||
super(ConstraintSelfWeight, self).__init__(obj)
|
||||
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat",
|
||||
"Gravity_x",
|
||||
"Gravity",
|
||||
"Gravity direction: set the x-component of the normalized gravity vector"
|
||||
)
|
||||
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat",
|
||||
"Gravity_y",
|
||||
"Gravity",
|
||||
"Gravity direction: set the y-component of the normalized gravity vector"
|
||||
)
|
||||
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat",
|
||||
"Gravity_z",
|
||||
"Gravity",
|
||||
"Gravity direction: set the z-component of the normalized gravity vector"
|
||||
)
|
||||
|
||||
obj.Gravity_x = 0.0
|
||||
obj.Gravity_y = 0.0
|
||||
obj.Gravity_z = -1.0
|
||||
self.addProperty(obj)
|
||||
|
||||
# https://wiki.freecad.org/Scripted_objects#Property_Type
|
||||
# https://forum.freecad.org/viewtopic.php?f=18&t=13460&start=20#p109709
|
||||
# https://forum.freecad.org/viewtopic.php?t=25524
|
||||
# obj.setEditorMode("References", 1) # read only in PropertyEditor, but writeable by Python
|
||||
obj.setEditorMode("References", 2) # do not show in Editor
|
||||
|
||||
def addProperty(self, obj):
|
||||
obj.addProperty("App::PropertyAcceleration",
|
||||
"GravityAcceleration",
|
||||
"Gravity",
|
||||
"Gravity acceleration")
|
||||
obj.GravityAcceleration = constants.gravity()
|
||||
|
||||
obj.addProperty("App::PropertyVector",
|
||||
"GravityDirection",
|
||||
"Gravity",
|
||||
"Normalized gravity direction")
|
||||
obj.GravityDirection = FreeCAD.Vector(0, 0, -1)
|
||||
|
||||
obj.setPropertyStatus("NormalDirection", "Hidden")
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
# migrate old App::PropertyFloat "Gravity_*" if exists
|
||||
try:
|
||||
grav_x = obj.getPropertyByName("Gravity_x")
|
||||
grav_y = obj.getPropertyByName("Gravity_y")
|
||||
grav_z = obj.getPropertyByName("Gravity_z")
|
||||
grav = FreeCAD.Vector(grav_x, grav_y, grav_z)
|
||||
|
||||
self.addProperty(obj)
|
||||
obj.GravityAcceleration = constants.gravity()
|
||||
obj.GravityAcceleration *= grav.Length
|
||||
obj.GravityDirection = grav.normalize()
|
||||
|
||||
obj.removeProperty("Gravity_x")
|
||||
obj.removeProperty("Gravity_y")
|
||||
obj.removeProperty("Gravity_z")
|
||||
|
||||
return
|
||||
|
||||
except:
|
||||
return
|
||||
|
||||
def execute(self, obj):
|
||||
obj.GravityDirection.normalize()
|
||||
|
||||
return False
|
||||
|
||||
@@ -52,10 +52,10 @@ def write_constraint(f, femobj, selwei_obj, ccxwriter):
|
||||
"{},GRAV,{:.13G},{:.13G},{:.13G},{:.13G}\n"
|
||||
.format(
|
||||
ccxwriter.ccx_eall,
|
||||
ccxwriter.gravity, # actual magnitude of gravity vector
|
||||
selwei_obj.Gravity_x, # coordinate x of normalized gravity vector
|
||||
selwei_obj.Gravity_y, # y
|
||||
selwei_obj.Gravity_z # z
|
||||
selwei_obj.GravityAcceleration.getValueAs("mm/s^2").Value, # actual magnitude of gravity vector
|
||||
selwei_obj.GravityDirection.x, # coordinate x of normalized gravity vector
|
||||
selwei_obj.GravityDirection.y, # y
|
||||
selwei_obj.GravityDirection.z # z
|
||||
)
|
||||
)
|
||||
f.write("\n")
|
||||
|
||||
@@ -148,7 +148,7 @@ class DeformationWriter:
|
||||
obj = self.write.getSingleMember("Fem::ConstraintSelfWeight")
|
||||
if obj is not None:
|
||||
for name in bodies:
|
||||
gravity = self.write.convert(self.write.constsdef["Gravity"], "L/T^2")
|
||||
gravity = self.write.convert(obj.GravityAcceleration.toStr(), "L/T^2")
|
||||
if self.write.getBodyMaterial(name) is None:
|
||||
raise general_writer.WriteError(
|
||||
"The body {} is not referenced in any material.\n\n".format(name)
|
||||
@@ -164,9 +164,9 @@ class DeformationWriter:
|
||||
dimension = "M/L^2"
|
||||
density = self.write.convert(densityQuantity, dimension)
|
||||
|
||||
force1 = gravity * obj.Gravity_x * density
|
||||
force2 = gravity * obj.Gravity_y * density
|
||||
force3 = gravity * obj.Gravity_z * density
|
||||
force1 = gravity * obj.GravityDirection.x * density
|
||||
force2 = gravity * obj.GravityDirection.y * density
|
||||
force3 = gravity * obj.GravityDirection.z * density
|
||||
self.write.bodyForce(name, "Stress Bodyforce 1", force1)
|
||||
self.write.bodyForce(name, "Stress Bodyforce 2", force2)
|
||||
self.write.bodyForce(name, "Stress Bodyforce 3", force3)
|
||||
|
||||
@@ -364,7 +364,7 @@ class ElasticityWriter:
|
||||
obj = self.write.getSingleMember("Fem::ConstraintSelfWeight")
|
||||
if obj is not None:
|
||||
for name in bodies:
|
||||
gravity = self.write.convert(self.write.constsdef["Gravity"], "L/T^2")
|
||||
gravity = self.write.convert(obj.GravityAcceleration.toStr(), "L/T^2")
|
||||
if self.write.getBodyMaterial(name) is None:
|
||||
raise general_writer.WriteError(
|
||||
"The body {} is not referenced in any material.\n\n".format(name)
|
||||
@@ -380,9 +380,9 @@ class ElasticityWriter:
|
||||
dimension = "M/L^2"
|
||||
density = self.write.convert(densityQuantity, dimension)
|
||||
|
||||
force1 = gravity * obj.Gravity_x * density
|
||||
force2 = gravity * obj.Gravity_y * density
|
||||
force3 = gravity * obj.Gravity_z * density
|
||||
force1 = gravity * obj.GravityDirection.x * density
|
||||
force2 = gravity * obj.GravityDirection.y * density
|
||||
force3 = gravity * obj.GravityDirection.z * density
|
||||
self.write.bodyForce(name, "Stress Bodyforce 1", force1)
|
||||
self.write.bodyForce(name, "Stress Bodyforce 2", force2)
|
||||
self.write.bodyForce(name, "Stress Bodyforce 3", force3)
|
||||
|
||||
@@ -2170,7 +2170,7 @@ ConstraintFixed,3
|
||||
** Self weight Constraint
|
||||
** ConstraintSelfWeight
|
||||
*DLOAD
|
||||
Eall,GRAV,9806,0,0,-1
|
||||
Eall,GRAV,9806.65,0,0,-1
|
||||
|
||||
|
||||
***********************************************************
|
||||
|
||||
Reference in New Issue
Block a user