Skip to content

Commit 06e084d

Browse files
committed
Fem: udpdate current density
1 parent 70062d0 commit 06e084d

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/Mod/Fem/femsolver/elmer/equations/magnetodynamic2D_writer.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from FreeCAD import Console
3232
from FreeCAD import Units
3333

34+
from femtools import femutils
3435
from .. import sifio
3536
from .. import writer as general_writer
3637

@@ -135,15 +136,13 @@ def handleMagnetodynamic2DMaterial(self, bodies):
135136
)
136137

137138
def _outputMagnetodynamic2DBodyForce(self, obj, name, equation):
138-
if hasattr(obj, "NormalCurrentDensity_re"):
139-
# output only if current density is enabled and needed
140-
if obj.Mode == "Normal":
141-
currentDensity = float(obj.NormalCurrentDensity_re.getValueAs("A/m^2"))
142-
self.write.bodyForce(name, "Current Density", round(currentDensity, 6))
143-
# imaginaries are only needed for harmonic equation
144-
if equation.IsHarmonic:
145-
currentDensity = float(obj.NormalCurrentDensity_im.getValueAs("A/m^2"))
146-
self.write.bodyForce(name, "Current Density Im", round(currentDensity, 6))
139+
if femutils.is_derived_from(obj, "Fem::ConstraintCurrentDensity") and obj.Mode == "Normal":
140+
currentDensity = obj.NormalCurrentDensity_re.getValueAs("A/m^2").Value
141+
self.write.bodyForce(name, "Current Density", round(currentDensity, 6))
142+
# imaginaries are only needed for harmonic equation
143+
if equation.IsHarmonic:
144+
currentDensity = obj.NormalCurrentDensity_im.getValueAs("A/m^2").Value
145+
self.write.bodyForce(name, "Current Density Im", round(currentDensity, 6))
147146

148147
if hasattr(obj, "Magnetization_re_1"):
149148
# output only if magnetization is enabled and needed

src/Mod/Fem/femsolver/elmer/equations/magnetodynamic_writer.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,26 @@ def handleMagnetodynamicMaterial(self, bodies):
162162
)
163163

164164
def _outputMagnetodynamicBodyForce(self, obj, name, equation):
165-
if hasattr(obj, "CurrentDensity_re_1"):
165+
if femutils.is_derived_from(obj, "Fem::ConstraintCurrentDensity") and obj.Mode == "Custom":
166166
# output only if current density is enabled and needed
167-
if not obj.CurrentDensity_re_1_Disabled:
167+
if obj.EnableCurrentDensity_re_1:
168168
currentDensity = float(obj.CurrentDensity_re_1.getValueAs("A/m^2"))
169169
self.write.bodyForce(name, "Current Density 1", round(currentDensity, 6))
170-
if not obj.CurrentDensity_re_2_Disabled:
170+
if obj.EnableCurrentDensity_re_2:
171171
currentDensity = float(obj.CurrentDensity_re_2.getValueAs("A/m^2"))
172172
self.write.bodyForce(name, "Current Density 2", round(currentDensity, 6))
173-
if not obj.CurrentDensity_re_3_Disabled:
173+
if obj.EnableCurrentDensity_re_3:
174174
currentDensity = float(obj.CurrentDensity_re_3.getValueAs("A/m^2"))
175175
self.write.bodyForce(name, "Current Density 3", round(currentDensity, 6))
176176
# imaginaries are only needed for harmonic equation
177177
if equation.IsHarmonic:
178-
if not obj.CurrentDensity_im_1_Disabled:
178+
if obj.EnableCurrentDensity_im_1:
179179
currentDensity = float(obj.CurrentDensity_im_1.getValueAs("A/m^2"))
180180
self.write.bodyForce(name, "Current Density Im 1", round(currentDensity, 6))
181-
if not obj.CurrentDensity_im_2_Disabled:
181+
if obj.EnableCurrentDensity_im_2:
182182
currentDensity = float(obj.CurrentDensity_im_2.getValueAs("A/m^2"))
183183
self.write.bodyForce(name, "Current Density Im 2", round(currentDensity, 6))
184-
if not obj.CurrentDensity_im_3_Disabled:
184+
if obj.EnableCurrentDensity_im_3:
185185
currentDensity = float(obj.CurrentDensity_im_3.getValueAs("A/m^2"))
186186
self.write.bodyForce(name, "Current Density Im 3", round(currentDensity, 6))
187187

src/Mod/Fem/femsolver/elmer/equations/staticcurrent_writer.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ def handleStaticCurrentBndConditions(self):
9696
# output the FreeCAD label as comment
9797
if obj.Label:
9898
self.write.boundary(name, "! FreeCAD Name", obj.Label)
99-
self.write.boundary(name, "Current Density BC", True)
100-
self.write.boundary(
101-
name, "Current Density", obj.NormalCurrentDensity.getValueAs("A/m^2").Value
102-
)
99+
if obj.Mode == "Normal":
100+
self.write.boundary(name, "Current Density BC", True)
101+
self.write.boundary(
102+
name,
103+
"Current Density",
104+
obj.NormalCurrentDensity_re.getValueAs("A/m^2").Value,
105+
)
103106

104107
self.write.handled(obj)
105108

src/Mod/Fem/femviewprovider/view_constraint_currentdensity.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class VPConstraintCurrentDensity(view_base_femconstraint.VPBaseFemConstraint):
3838
def __init__(self, vobj):
3939
super().__init__(vobj)
4040
mat = vobj.ShapeAppearance[0]
41-
mat.DiffuseColor = (0.0, 0.6, 0.0, 0.0)
41+
mat.DiffuseColor = (0.71, 0.40, 0.11, 0.0)
4242
vobj.ShapeAppearance = mat
4343

4444
def setEdit(self, vobj, mode=0):
@@ -49,3 +49,10 @@ def setEdit(self, vobj, mode=0):
4949
def attach(self, vobj):
5050
super().attach(vobj)
5151
vobj.loadSymbol(self.resource_symbol_dir + "ConstraintCurrentDensity.iv")
52+
53+
def updateData(self, obj, prop):
54+
if prop == "Mode":
55+
if obj.Mode == "Normal":
56+
obj.ViewObject.RotateSymbol = True
57+
elif obj.Mode == "Custom":
58+
obj.ViewObject.RotateSymbol = False

0 commit comments

Comments
 (0)