Skip to content

Commit 0f0bd52

Browse files
committed
Fem: Update CalculiX writer of the constraint rigid body
1 parent 18d8987 commit 0f0bd52

File tree

2 files changed

+48
-56
lines changed

2 files changed

+48
-56
lines changed

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

+7-26
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,24 @@ 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+
ref_node_idx = node_count + rb_obj_idx + 1
69+
rot_node_idx = node_count + rb_obj_idx + 2
8370

8471
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))
72+
f.write("{},{},{},{}\n".format(ref_node_idx, *rb_obj.ReferenceNode))
73+
f.write("{},{},{},{}\n".format(rot_node_idx, *rb_obj.ReferenceNode))
8774

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

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-
9677
f.write(kw_line + "\n")
9778

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

+41-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,41 @@ 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+
ref_node_idx = node_count + rb_obj_idx + 1
65+
rot_node_idx = node_count + rb_obj_idx + 2
66+
67+
def write_mode(mode, node, dof, constraint, load):
68+
if mode == "Constraint":
69+
f.write("*BOUNDARY\n")
70+
f.write("{},{},{},{:.13G}\n".format(node, dof, dof, constraint))
71+
elif mode == "Load":
72+
f.write("*CLOAD\n")
73+
f.write("{},{},{:.13G}\n".format(node, dof, load))
74+
75+
mode = [rb_obj.TranslationalModeX, rb_obj.TranslationalModeY, rb_obj.TranslationalModeZ]
76+
constraint = rb_obj.Displacement
77+
load = [rb_obj.ForceX, rb_obj.ForceY, rb_obj.ForceZ]
78+
79+
for i in range(3):
80+
write_mode(mode[i], ref_node_idx, i + 1, constraint[i], load[i].getValueAs("N").Value)
81+
82+
83+
mode = [rb_obj.RotationalModeX, rb_obj.RotationalModeY, rb_obj.RotationalModeZ]
84+
load = [rb_obj.MomentX,rb_obj.MomentY, rb_obj.MomentZ]
85+
86+
# write rotation components according to rotational mode
87+
rot = rb_obj.Rotation
88+
proj_axis = [rot.Axis[i] if mode[i] == "Constraint" else 0 for i in range(3)]
89+
# proj_axis could be null
90+
try:
91+
constraint = FreeCAD.Vector(proj_axis).normalize() * rot.Angle
92+
except:
93+
constraint = FreeCAD.Vector(0, 0, 0)
94+
95+
for i in range(3):
96+
write_mode(mode[i], rot_node_idx, i + 1, constraint[i], load[i].getValueAs("N*mm").Value)
97+
98+
99+
f.write("\n")

0 commit comments

Comments
 (0)