Skip to content

Commit b44e376

Browse files
committed
Fem: usar DFLUX en electrostatic
1 parent cd053c8 commit b44e376

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

src/Mod/Fem/femmesh/meshsetsgetter.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def get_mesh_sets(self):
150150
self.get_constraints_force_nodeloads()
151151
self.get_constraints_pressure_faces()
152152
self.get_constraints_heatflux_faces()
153+
self.get_constraints_electrostatic_faces()
153154

154155
setstime = round((time.process_time() - time_start), 3)
155156
FreeCAD.Console.PrintMessage(f"Getting mesh data time: {setstime} seconds.\n")
@@ -258,8 +259,11 @@ def get_constraints_electrostatic_nodes(self):
258259
# get nodes
259260
for femobj in self.member.cons_electrostatic:
260261
# femobj --> dict, FreeCAD document object is femobj["Object"]
261-
print_obj_info(femobj["Object"])
262-
femobj["Nodes"] = meshtools.get_femnodes_by_femobj_with_references(self.femmesh, femobj)
262+
if femobj["Object"].BoundaryCondition == "Dirichlet":
263+
print_obj_info(femobj["Object"])
264+
femobj["Nodes"] = meshtools.get_femnodes_by_femobj_with_references(
265+
self.femmesh, femobj
266+
)
263267

264268
def get_constraints_force_nodeloads(self):
265269
if not self.member.cons_force:
@@ -365,6 +369,34 @@ def get_constraints_pressure_faces(self):
365369
femobj["PressureFaces"] = [(some_string, pressure_faces)]
366370
FreeCAD.Console.PrintLog("{}\n".format(femobj["PressureFaces"]))
367371

372+
def get_constraints_electrostatic_faces(self):
373+
if not self.member.cons_electrostatic:
374+
return
375+
if not self.femnodes_mesh:
376+
self.femnodes_mesh = self.femmesh.Nodes
377+
if not self.femelement_table:
378+
self.femelement_table = meshtools.get_femelement_table(self.femmesh)
379+
if not self.femnodes_ele_table:
380+
self.femnodes_ele_table = meshtools.get_femnodes_ele_table(
381+
self.femnodes_mesh, self.femelement_table
382+
)
383+
384+
for femobj in self.member.cons_electrostatic:
385+
# femobj --> dict, FreeCAD document object is femobj["Object"]
386+
if femobj["Object"].BoundaryCondition == "Neumann":
387+
print_obj_info(femobj["Object"])
388+
389+
pressure_faces = meshtools.get_pressure_obj_faces(
390+
self.femmesh, self.femelement_table, self.femnodes_ele_table, femobj
391+
)
392+
# the data model is for compatibility reason with deprecated version
393+
# get_pressure_obj_faces_depreciated returns the face ids in a tuple per ref_shape
394+
# some_string was the reference_shape_element_string in deprecated method
395+
# [(some_string, [ele_id, ele_face_id], [ele_id, ele_face_id], ...])]
396+
some_string = "{}: face electric flux".format(femobj["Object"].Name)
397+
femobj["ElectricFluxFaces"] = [(some_string, pressure_faces)]
398+
FreeCAD.Console.PrintLog("{}\n".format(femobj["ElectricFluxFaces"]))
399+
368400
def get_constraints_contact_faces(self):
369401
if not self.member.cons_contact:
370402
return

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

+33-12
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ def get_constraint_title():
4141

4242

4343
def write_meshdata_constraint(f, femobj, pot_obj, ccxwriter):
44-
f.write(f"*NSET,NSET={pot_obj.Name}\n")
45-
for n in femobj["Nodes"]:
46-
f.write(f"{n},\n")
44+
45+
if femobj["Object"].BoundaryCondition == "Dirichlet":
46+
f.write(f"*NSET,NSET={pot_obj.Name}\n")
47+
for n in femobj["Nodes"]:
48+
f.write(f"{n},\n")
4749

4850

4951
def get_before_write_meshdata_constraint():
@@ -66,18 +68,37 @@ def write_constraint(f, femobj, pot_obj, ccxwriter):
6668

6769
# floats read from ccx should use {:.13G}, see comment in writer module
6870

69-
NumberOfNodes = len(femobj["Nodes"])
7071
if pot_obj.BoundaryCondition == "Dirichlet":
7172
f.write("*BOUNDARY\n")
7273
f.write("{},11,11,{:.13G}\n".format(pot_obj.Name, pot_obj.Potential.getValueAs("mV").Value))
7374
f.write("\n")
7475
elif pot_obj.BoundaryCondition == "Neumann":
75-
f.write("*CFLUX\n")
76-
# CFLUX has to be specified in mW
77-
f.write(
78-
"{},11,{:.13G}\n".format(
79-
pot_obj.Name,
80-
pot_obj.SurfaceChargeDensity.getValueAs("A*s/mm^2").Value / NumberOfNodes,
81-
)
82-
)
76+
charge_density = pot_obj.SurfaceChargeDensity.getValueAs("A*s/mm^2").Value
77+
78+
f.write("*DFLUX\n")
79+
for ref_shape in femobj["ElectricFluxFaces"]:
80+
# the loop is needed for compatibility reason
81+
# in deprecated method get_pressure_obj_faces_depreciated
82+
# the face ids where per ref_shape
83+
f.write("** " + ref_shape[0] + "\n")
84+
for face, fno in ref_shape[1]:
85+
if fno > 0: # solid mesh face
86+
f.write(f"{face},S{fno},{charge_density}\n")
87+
# # on shell mesh face: fno == 0
88+
# # normal of element face == face normal
89+
# elif fno == 0:
90+
# f.write(f"{face},S,{press_rev}\n")
91+
# # on shell mesh face: fno == -1
92+
# # normal of element face opposite direction face normal
93+
# elif fno == -1:
94+
# f.write(f"{face},P,{-1 * press_rev}\n")
95+
96+
# f.write("*CFLUX\n")
97+
# # CFLUX has to be specified in mW
98+
# f.write(
99+
# "{},11,{:.13G}\n".format(
100+
# pot_obj.Name,
101+
# pot_obj.SurfaceChargeDensity.getValueAs("A*s/mm^2").Value,
102+
# )
103+
# )
83104
f.write("\n")

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def is_density_needed():
9393
KV_in_mm2s = KV.getValueAs("mm^2/s").Value
9494
DV_in_tmms = KV_in_mm2s * density_in_tonne_per_mm3
9595
if ccxwriter.analysis_type == "electrostatic":
96-
TC = FreeCAD.Units.Quantity(mat_obj.Material["ThermalConductivity"])
97-
TC_in_WmK = TC.getValueAs("W/m/K").Value
98-
96+
rel_perm = FreeCAD.Units.Quantity(mat_obj.Material["RelativePermittivity"]).Value
97+
vacuum_perm = FreeCAD.Units.Quantity("8.85419e-12 F/m").getValueAs("C/(mV*mm)").Value
98+
abs_perm = vacuum_perm * rel_perm
9999
# write material properties
100100
f.write(f"** FreeCAD material name: {mat_info_name}\n")
101101
f.write(f"** {mat_label}\n")
@@ -119,7 +119,7 @@ def is_density_needed():
119119
f.write(f"{SH_in_JkgK:.13G},{DV_in_tmms:.13G}\n")
120120
if ccxwriter.analysis_type == "electrostatic":
121121
f.write("*CONDUCTIVITY\n")
122-
f.write(f"{TC_in_WmK:.13G}\n")
122+
f.write(f"{abs_perm:.13G}\n")
123123

124124
# nonlinear material properties
125125
if ccxwriter.solver_obj.MaterialNonlinearity == "nonlinear":

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def write_step_equation(f, ccxwriter):
7979
elif ccxwriter.analysis_type == "buckling":
8080
analysis_type = "*BUCKLE"
8181
elif ccxwriter.analysis_type == "electrostatic":
82-
analysis_type = "*HEAT TRANSFER, STEADY STATE, MATRIXSTORAGE"
82+
analysis_type = "*HEAT TRANSFER, STEADY STATE"
8383
# analysis line --> solver type
8484
# https://forum.freecad.org/viewtopic.php?f=18&t=43178
8585
if ccxwriter.solver_obj.MatrixSolverType == "default":

0 commit comments

Comments
 (0)