Skip to content

Commit e307595

Browse files
marioalexis84chennes
authored andcommitted
Fem: Update CalculiX writer of the constraint rigid body
1 parent 35db988 commit e307595

File tree

2 files changed

+50
-56
lines changed

2 files changed

+50
-56
lines changed

src/Mod/Fem/femsolver/calculix/write_constraint_rigidbody.py

+8-26
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,25 @@ def get_after_write_constraint():
5555

5656

5757
def write_meshdata_constraint(f, femobj, rb_obj, ccxwriter):
58+
5859
f.write("*NSET,NSET=" + rb_obj.Name + "\n")
5960
for n in femobj["Nodes"]:
6061
f.write("{},\n".format(n))
6162

6263

6364
def write_constraint(f, femobj, rb_obj, ccxwriter):
6465

65-
# floats read from ccx should use {:.13G}, see comment in writer module
66-
is_ref_bc_defined = any((rb_obj.xDisplacement,
67-
rb_obj.yDisplacement,
68-
rb_obj.zDisplacement,
69-
rb_obj.xForce,
70-
rb_obj.yForce,
71-
rb_obj.zForce))
72-
73-
is_rot_bc_defined = any((rb_obj.xRotation,
74-
rb_obj.yRotation,
75-
rb_obj.zRotation,
76-
rb_obj.xMoment,
77-
rb_obj.yMoment,
78-
rb_obj.zMoment))
79-
80-
# FIXME: This needs to be implemented
81-
ref_node_idx = 10000000
82-
rot_node_idx = 20000000
66+
rb_obj_idx = ccxwriter.analysis.Group.index(rb_obj)
67+
node_count = ccxwriter.mesh_object.FemMesh.NodeCount
68+
# factor 2 is to prevent conflict with other rigid body constraint
69+
ref_node_idx = node_count + 2*rb_obj_idx + 1
70+
rot_node_idx = node_count + 2*rb_obj_idx + 2
8371

8472
f.write("*NODE\n")
85-
f.write("{},{},{},{}\n".format(ref_node_idx, rb_obj.xRefNode, rb_obj.yRefNode, rb_obj.zRefNode))
86-
f.write("{},{},{},{}\n".format(rot_node_idx, rb_obj.xRefNode, rb_obj.yRefNode, rb_obj.zRefNode))
73+
f.write("{},{},{},{}\n".format(ref_node_idx, *rb_obj.ReferenceNode))
74+
f.write("{},{},{},{}\n".format(rot_node_idx, *rb_obj.ReferenceNode))
8775

8876
kw_line = "*RIGID BODY, NSET={}, REF NODE={}, ROT NODE={}".format(rb_obj.Name, ref_node_idx, rot_node_idx)
8977

90-
if is_ref_bc_defined:
91-
kw_line = kw_line + ",REF NODE={}".format(ref_node_idx)
92-
93-
if is_rot_bc_defined:
94-
kw_line = kw_line + ",ROT NODE={}".format(rot_node_idx)
95-
9678
f.write(kw_line + "\n")
9779

src/Mod/Fem/femsolver/calculix/write_constraint_rigidbody_step.py

+42-30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
__url__ = "https://www.freecadweb.org"
2727

2828

29+
import FreeCAD
30+
31+
2932
def get_analysis_types():
3033
return "all" # write for all analysis types
3134

@@ -56,33 +59,42 @@ def get_after_write_constraint():
5659

5760
def write_constraint(f, femobj, rb_obj, ccxwriter):
5861

59-
# floats read from ccx should use {:.13G}, see comment in writer module
60-
is_ref_bc_defined = any((rb_obj.xDisplacement,
61-
rb_obj.yDisplacement,
62-
rb_obj.zDisplacement,
63-
rb_obj.xForce,
64-
rb_obj.yForce,
65-
rb_obj.zForce))
66-
67-
is_rot_bc_defined = any((rb_obj.xRotation,
68-
rb_obj.yRotation,
69-
rb_obj.zRotation,
70-
rb_obj.xMoment,
71-
rb_obj.yMoment,
72-
rb_obj.zMoment))
73-
74-
# FIXME: This needs to be implemented
75-
ref_node_idx = 10000000
76-
rot_node_idx = 20000000
77-
78-
79-
# TODO: Displacement definitions need fixing
80-
f.write("*CLOAD\n")
81-
f.write("{},1,{}\n".format(ref_node_idx, rb_obj.xForce))
82-
f.write("{},2,{}\n".format(ref_node_idx, rb_obj.yForce))
83-
f.write("{},3,{}\n".format(ref_node_idx, rb_obj.zForce))
84-
85-
f.write("*CLOAD\n")
86-
f.write("{},1,{}\n".format(rot_node_idx, rb_obj.xMoment))
87-
f.write("{},2,{}\n".format(rot_node_idx, rb_obj.yMoment))
88-
f.write("{},3,{}\n".format(rot_node_idx, rb_obj.zMoment))
62+
rb_obj_idx = ccxwriter.analysis.Group.index(rb_obj)
63+
node_count = ccxwriter.mesh_object.FemMesh.NodeCount
64+
# factor 2 is to prevent conflict with other rigid body constraint
65+
ref_node_idx = node_count + 2*rb_obj_idx + 1
66+
rot_node_idx = node_count + 2*rb_obj_idx + 2
67+
68+
def write_mode(mode, node, dof, constraint, load):
69+
if mode == "Constraint":
70+
f.write("*BOUNDARY\n")
71+
f.write("{},{},{},{:.13G}\n".format(node, dof, dof, constraint))
72+
elif mode == "Load":
73+
f.write("*CLOAD\n")
74+
f.write("{},{},{:.13G}\n".format(node, dof, load))
75+
76+
mode = [rb_obj.TranslationalModeX, rb_obj.TranslationalModeY, rb_obj.TranslationalModeZ]
77+
constraint = rb_obj.Displacement
78+
load = [rb_obj.ForceX, rb_obj.ForceY, rb_obj.ForceZ]
79+
80+
for i in range(3):
81+
write_mode(mode[i], ref_node_idx, i + 1, constraint[i], load[i].getValueAs("N").Value)
82+
83+
84+
mode = [rb_obj.RotationalModeX, rb_obj.RotationalModeY, rb_obj.RotationalModeZ]
85+
load = [rb_obj.MomentX,rb_obj.MomentY, rb_obj.MomentZ]
86+
87+
# write rotation components according to rotational mode
88+
rot = rb_obj.Rotation
89+
proj_axis = [rot.Axis[i] if mode[i] == "Constraint" else 0 for i in range(3)]
90+
# proj_axis could be null
91+
try:
92+
constraint = FreeCAD.Vector(proj_axis).normalize() * rot.Angle
93+
except:
94+
constraint = FreeCAD.Vector(0, 0, 0)
95+
96+
for i in range(3):
97+
write_mode(mode[i], rot_node_idx, i + 1, constraint[i], load[i].getValueAs("N*mm").Value)
98+
99+
100+
f.write("\n")

0 commit comments

Comments
 (0)