From 037147bf493a151c9dca0704a81e7f1a760e5dfc Mon Sep 17 00:00:00 2001 From: marioalexis Date: Mon, 20 Jan 2025 00:33:19 -0300 Subject: [PATCH] Fem: Electrostaticc --- .../Resources/ui/ElectrostaticPotential.ui | 250 +++++++++--------- .../constraint_electrostaticpotential.py | 37 ++- .../elmer/equations/magnetodynamic_writer.py | 77 +++--- .../task_constraint_electrostaticpotential.py | 92 ++----- 4 files changed, 204 insertions(+), 252 deletions(-) diff --git a/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui b/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui index de85084c5dd4..7a1eae83d500 100644 --- a/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui +++ b/src/Mod/Fem/Gui/Resources/ui/ElectrostaticPotential.ui @@ -19,7 +19,7 @@ - + @@ -41,40 +41,124 @@ false - + - - - - - Potential: - - - - - - - false - - - Electric potential - - - true - - - V - - - 1.000000000000000 - - - 1.000000000000000 - - - - + + + Potential: + + + + + + false + + + Electric potential + + + true + + + V + + + 1.000000000000000 + + + 1.000000000000000 + + + + + + + true + + + Whether the boundary condition defines a farfield potential + + + Electric Infinity + + + + + + + Whether the boundary condition defines a constant potential + + + Potential Constant + + + + + + + Capacitance Body: + + + Enabled by 'Calculate Capacity Matrix' in Electrostatic equation + + + + + + + Counter of the body (or face) with a capacitance + + + false + + + 1 + + + 1 + + + + + + + + + + Neumann + + + + + + Surface Charge Density: + + + + + + + Surface charge density + + + C/m^2 + + + + + + + + + + + + Electromagnetic + + + + @@ -90,6 +174,9 @@ + + Electromagnetic Potential + true @@ -98,7 +185,7 @@ with a harmonic/oscillating driving force - false + true false @@ -147,10 +234,10 @@ with a harmonic/oscillating driving force - false + true - Potential as specified above + Real part of scalar potential true @@ -432,98 +519,11 @@ Note: has no effect if a solid was selected - - - - true - - - Whether the boundary condition defines a farfield potential - - - Farfield / Electric infinity - - - - - - - Whether the boundary condition defines a constant potential - - - Potential Constant - - - - - - - Whether the boundary condition is for the electric force - - - Calculate Electric Force - - - - - - - - - Capacitance Body: - - - Enabled by 'Calculate Capacity Matrix' in Electrostatic equation - - - - - - - Counter of the body (or face) with a capacitance - - - false - - - 1 - - - 1 - - - - - - - - - - - - Neumann - - - - - - Surface Charge Density: - - - - - - - Surface charge density - - - C/m^2 - - - + + diff --git a/src/Mod/Fem/femobjects/constraint_electrostaticpotential.py b/src/Mod/Fem/femobjects/constraint_electrostaticpotential.py index f1e7f595ec9d..13e3888d9204 100644 --- a/src/Mod/Fem/femobjects/constraint_electrostaticpotential.py +++ b/src/Mod/Fem/femobjects/constraint_electrostaticpotential.py @@ -68,11 +68,20 @@ def _get_properties(self): value=True, ) ) + prop.append( + _PropHelper( + type="App::PropertyElectricPotential", + name="AV_re", + group="Electromagnetic Potential", + doc="Real part of scalar potential", + value="0 V", + ) + ) prop.append( _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_re_1", - group="Vector Potential", + group="Electromagnetic Potential", doc="Real part of potential x-component", value="0 Wb/m", ) @@ -81,7 +90,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_re_2", - group="Vector Potential", + group="Electromagnetic Potential", doc="Real part of potential y-component", value="0 Wb/m", ) @@ -90,7 +99,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_re_3", - group="Vector Potential", + group="Electromagnetic Potential", doc="Real part of potential z-component", value="0 Wb/m", ) @@ -99,7 +108,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_im_1", - group="Vector Potential", + group="Electromagnetic Potential", doc="Imaginary part of potential x-component", value="0 Wb/m", ) @@ -108,7 +117,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_im_2", - group="Vector Potential", + group="Electromagnetic Potential", doc="Imaginary part of potential y-component", value="0 Wb/m", ) @@ -117,7 +126,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectromagneticPotential", name="AV_im_3", - group="Vector Potential", + group="Electromagnetic Potential", doc="Imaginary part of potential z-component", value="0 Wb/m", ) @@ -144,7 +153,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyElectricPotential", name="AV_im", - group="Parameter", + group="Electromagnetic Potential", doc="Imaginary part of scalar potential", value="0 V", ) @@ -153,7 +162,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_re_1_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -162,7 +171,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_re_2_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -171,7 +180,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_re_3_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -180,7 +189,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_im_1_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -189,7 +198,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_im_2_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -198,7 +207,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_im_3_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) @@ -207,7 +216,7 @@ def _get_properties(self): _PropHelper( type="App::PropertyBool", name="AV_im_Disabled", - group="Vector Potential", + group="Electromagnetic Potential", doc="", value=True, ) diff --git a/src/Mod/Fem/femsolver/elmer/equations/magnetodynamic_writer.py b/src/Mod/Fem/femsolver/elmer/equations/magnetodynamic_writer.py index c67ddf22ba36..8235bb121047 100644 --- a/src/Mod/Fem/femsolver/elmer/equations/magnetodynamic_writer.py +++ b/src/Mod/Fem/femsolver/elmer/equations/magnetodynamic_writer.py @@ -289,47 +289,44 @@ def _outputMagnetodynamicBndConditions(self, obj, name, equation): currentDensity = float(obj.CurrentDensity_im_1.getValueAs("A/m^2")) self.write.boundary(name, "Current Density Im 1", round(currentDensity, 6)) - if hasattr(obj, "PotentialEnabled"): - # check for PotentialEnabled not Potential since PotentialEnabled was - # added later and only with this the vectorial properties are available - if obj.PotentialEnabled: - potential = float(obj.Potential.getValueAs("V")) - if equation.IsHarmonic: - self.write.boundary(name, "AV re", round(potential, 6)) - else: - self.write.boundary(name, "AV", round(potential, 6)) - if not obj.AV_re_1_Disabled: - potential = float(obj.AV_re_1.getValueAs("V")) - if equation.IsHarmonic: - self.write.boundary(name, "AV re {e} 1", round(potential, 6)) - else: - self.write.boundary(name, "AV {e} 1", round(potential, 6)) - if not obj.AV_re_2_Disabled: - potential = float(obj.AV_re_2.getValueAs("V")) - if equation.IsHarmonic: - self.write.boundary(name, "AV re {e} 2", round(potential, 6)) - else: - self.write.boundary(name, "AV {e} 2", round(potential, 6)) - if not obj.AV_re_3_Disabled: - potential = float(obj.AV_re_3.getValueAs("V")) - if equation.IsHarmonic: - self.write.boundary(name, "AV re {e} 3", round(potential, 6)) - else: - self.write.boundary(name, "AV {e} 3", round(potential, 6)) - # imaginaries are only needed for harmonic equation + if obj.PotentialEnabled: + potential = obj.AV_re.getValueAs("V").Value if equation.IsHarmonic: - if not obj.AV_im_Disabled: - potential = float(obj.AV_im.getValueAs("V")) - self.write.boundary(name, "AV im", round(potential, 6)) - if not obj.AV_im_1_Disabled: - potential = float(obj.AV_im_1.getValueAs("V")) - self.write.boundary(name, "AV im {e} 1", round(potential, 6)) - if not obj.AV_im_2_Disabled: - potential = float(obj.AV_im_2.getValueAs("V")) - self.write.boundary(name, "AV im {e} 2", round(potential, 6)) - if not obj.AV_im_3_Disabled: - potential = float(obj.AV_im_3.getValueAs("V")) - self.write.boundary(name, "AV im {e} 3", round(potential, 6)) + self.write.boundary(name, "AV re", round(potential, 6)) + else: + self.write.boundary(name, "AV", round(potential, 6)) + if not obj.AV_re_1_Disabled: + potential = obj.AV_re_1.getValueAs("Wb/m").Value + if equation.IsHarmonic: + self.write.boundary(name, "AV re {e} 1", round(potential, 6)) + else: + self.write.boundary(name, "AV {e} 1", round(potential, 6)) + if not obj.AV_re_2_Disabled: + potential = obj.AV_re_2.getValueAs("Wb/m").Value + if equation.IsHarmonic: + self.write.boundary(name, "AV re {e} 2", round(potential, 6)) + else: + self.write.boundary(name, "AV {e} 2", round(potential, 6)) + if not obj.AV_re_3_Disabled: + potential = obj.AV_re_3.getValueAs("Wb/m").Value + if equation.IsHarmonic: + self.write.boundary(name, "AV re {e} 3", round(potential, 6)) + else: + self.write.boundary(name, "AV {e} 3", round(potential, 6)) + # imaginaries are only needed for harmonic equation + if equation.IsHarmonic: + if not obj.AV_im_Disabled: + potential = obj.AV_im.getValueAs("V").Value + self.write.boundary(name, "AV im", round(potential, 6)) + if not obj.AV_im_1_Disabled: + potential = obj.AV_im_1.getValueAs("Wb/m").Value + self.write.boundary(name, "AV im {e} 1", round(potential, 6)) + if not obj.AV_im_2_Disabled: + potential = obj.AV_im_2.getValueAs("Wb/m").Value + self.write.boundary(name, "AV im {e} 2", round(potential, 6)) + if not obj.AV_im_3_Disabled: + potential = obj.AV_im_3.getValueAs("Wb/m").Value + self.write.boundary(name, "AV im {e} 3", round(potential, 6)) def handleMagnetodynamicBndConditions(self, equation): # the current density can either be a body force or a boundary constraint diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_electrostaticpotential.py b/src/Mod/Fem/femtaskpanels/task_constraint_electrostaticpotential.py index 33a17dcff20f..7ab9ca46a05f 100644 --- a/src/Mod/Fem/femtaskpanels/task_constraint_electrostaticpotential.py +++ b/src/Mod/Fem/femtaskpanels/task_constraint_electrostaticpotential.py @@ -108,6 +108,11 @@ def __init__(self, obj): QtCore.SIGNAL("toggled(bool)"), self.av_re_enabled_changed, ) + QtCore.QObject.connect( + self.parameter_widget.qsb_av_re, + QtCore.SIGNAL("valueChanged(Base::Quantity)"), + self.av_re_changed, + ) QtCore.QObject.connect( self.parameter_widget.ckb_av_re_1, QtCore.SIGNAL("toggled(bool)"), @@ -198,11 +203,6 @@ def __init__(self, obj): QtCore.SIGNAL("toggled(bool)"), self.electric_infinity_changed, ) - QtCore.QObject.connect( - self.parameter_widget.ckb_electric_forcecalculation, - QtCore.SIGNAL("toggled(bool)"), - self.electric_forcecalculation_changed, - ) QtCore.QObject.connect( self.parameter_widget.qsb_surface_charge_density, QtCore.SIGNAL("valueChanged(Base::Quantity)"), @@ -249,6 +249,7 @@ def _get_params(self): self.potential = self.obj.Potential self.potential_enabled = self.obj.PotentialEnabled + self.av_re = self.obj.AV_re self.av_re_1 = self.obj.AV_re_1 self.av_re_2 = self.obj.AV_re_2 self.av_re_3 = self.obj.AV_re_3 @@ -269,16 +270,15 @@ def _get_params(self): self.boundary_condition = self.obj.BoundaryCondition self.potential_constant = self.obj.PotentialConstant self.electric_infinity = self.obj.ElectricInfinity - self.electric_forcecalculation = self.obj.ElectricForcecalculation self.capacitance_body_enabled = self.obj.CapacitanceBodyEnabled self.capacitance_body = self.obj.CapacitanceBody - self.surface_charge_density = self.obj.SurfaceChargeDensity def _set_params(self): self.obj.Potential = self.potential self.obj.PotentialEnabled = self.potential_enabled + self.obj.AV_re = self.av_re self.obj.AV_re_1 = self.av_re_1 self.obj.AV_re_2 = self.av_re_2 self.obj.AV_re_3 = self.av_re_3 @@ -298,7 +298,6 @@ def _set_params(self): self.obj.BoundaryCondition = self.boundary_condition self.obj.PotentialConstant = self.potential_constant self.obj.ElectricInfinity = self.electric_infinity - self.obj.ElectricForcecalculation = self.electric_forcecalculation self.obj.CapacitanceBodyEnabled = self.capacitance_body_enabled self.obj.CapacitanceBody = self.capacitance_body @@ -313,11 +312,15 @@ def init_parameter_widget(self): ) self.parameter_widget.ckb_potential.setChecked(self.potential_enabled) - # the vector potentials - self.parameter_widget.qsb_av_re.setProperty("value", self.potential) + # scalar potential + self.parameter_widget.qsb_av_re.setProperty("value", self.av_re) self.parameter_widget.qsb_av_re.setEnabled(self.av_re_enabled) - FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_re).bind(self.obj, "Potential") + FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_re).bind(self.obj, "AV_re") + self.parameter_widget.qsb_av_im.setProperty("value", self.av_im) + self.parameter_widget.qsb_av_im.setEnabled(self.av_im_enabled) + FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_im).bind(self.obj, "AV_im") + # vector potential self.parameter_widget.qsb_av_re_1.setProperty("value", self.av_re_1) self.parameter_widget.qsb_av_re_1.setEnabled(self.av_re_1_enabled) FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_re_1).bind(self.obj, "AV_re_1") @@ -327,9 +330,7 @@ def init_parameter_widget(self): self.parameter_widget.qsb_av_re_3.setProperty("value", self.av_re_3) self.parameter_widget.qsb_av_re_3.setEnabled(self.av_re_3_enabled) FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_re_3).bind(self.obj, "AV_re_3") - self.parameter_widget.qsb_av_im.setProperty("value", self.av_im) - self.parameter_widget.qsb_av_im.setEnabled(self.av_im_enabled) - FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_im).bind(self.obj, "AV_im") + self.parameter_widget.qsb_av_im_1.setProperty("value", self.av_im_1) self.parameter_widget.qsb_av_im_1.setEnabled(self.av_im_1_enabled) FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_av_im_1).bind(self.obj, "AV_im_1") @@ -352,10 +353,6 @@ def init_parameter_widget(self): self.parameter_widget.ckb_electric_infinity.setChecked(self.electric_infinity) - self.parameter_widget.ckb_electric_forcecalculation.setChecked( - self.electric_forcecalculation - ) - self.parameter_widget.ckb_capacitance_body.setChecked(self.capacitance_body_enabled) self.parameter_widget.spb_capacitance_body.setValue(self.capacitance_body) @@ -367,10 +364,9 @@ def init_parameter_widget(self): ) self.bc_enum = self.obj.getEnumerationsOfProperty("BoundaryCondition") - self.parameter_widget.cb_boundary_condition.addItems(self.bc_enum) index = self.bc_enum.index(self.boundary_condition) + self.parameter_widget.cb_boundary_condition.addItems(self.bc_enum) self.parameter_widget.cb_boundary_condition.setCurrentIndex(index) - self.boundary_condition_changed(index) def potential_changed(self, value): self.potential = value @@ -411,6 +407,9 @@ def av_im_3_enabled_changed(self, value): self.av_im_3_enabled = value self.parameter_widget.qsb_av_im_3.setEnabled(value) + def av_re_changed(self, value): + self.av_re = value + def av_re_1_changed(self, value): self.av_re_1 = value @@ -438,9 +437,6 @@ def potential_constant_changed(self, value): def electric_infinity_changed(self, value): self.electric_infinity = value - def electric_forcecalculation_changed(self, value): - self.electric_forcecalculation = value - def capacitance_body_enabled_changed(self, value): self.capacitance_body_enabled = value self.parameter_widget.spb_capacitance_body.setEnabled(value) @@ -460,53 +456,3 @@ def boundary_condition_changed(self, index): elif self.boundary_condition == "Neumann": self.parameter_widget.gb_neumann.setEnabled(True) self.parameter_widget.gb_dirichlet.setEnabled(False) - - def _applyPotentialChanges(self, enabledBox, potentialQSB): - enabled = enabledBox.isChecked() - potential = None - try: - potential = potentialQSB.property("value") - except ValueError: - FreeCAD.Console.PrintMessage( - "Wrong input. Not recognised input: '{}' " - "Potential has not been set.\n".format(potentialQSB.text()) - ) - potential = "0.0 mm^2*kg/(s^3*A)" - return enabled, potential - - def _applyWidgetChanges(self): - # apply the voltages and their enabled state - self.obj.AV_re_1_Disabled, self.obj.AV_re_1 = self._applyPotentialChanges( - self.parameter_widget.reXunspecBox, self.parameter_widget.realXQSB - ) - self.obj.AV_re_2_Disabled, self.obj.AV_re_2 = self._applyPotentialChanges( - self.parameter_widget.reYunspecBox, self.parameter_widget.realYQSB - ) - self.obj.AV_re_3_Disabled, self.obj.AV_re_3 = self._applyPotentialChanges( - self.parameter_widget.reZunspecBox, self.parameter_widget.realZQSB - ) - self.obj.AV_im_Disabled, self.obj.AV_im = self._applyPotentialChanges( - self.parameter_widget.imScalarunspecBox, self.parameter_widget.imagScalarQSB - ) - self.obj.AV_im_1_Disabled, self.obj.AV_im_1 = self._applyPotentialChanges( - self.parameter_widget.imXunspecBox, self.parameter_widget.imagXQSB - ) - self.obj.AV_im_2_Disabled, self.obj.AV_im_2 = self._applyPotentialChanges( - self.parameter_widget.imYunspecBox, self.parameter_widget.imagYQSB - ) - self.obj.AV_im_3_Disabled, self.obj.AV_im_3 = self._applyPotentialChanges( - self.parameter_widget.imZunspecBox, self.parameter_widget.imagZQSB - ) - # because this is an enable the others are disabled, reverse - self.obj.PotentialEnabled = not self.obj.PotentialEnabled - - self.obj.PotentialConstant = self.parameter_widget.potentialConstantBox.isChecked() - - self.obj.ElectricInfinity = self.parameter_widget.electricInfinityBox.isChecked() - - calc_is_checked = self.parameter_widget.electricForcecalculationBox.isChecked() - self.obj.ElectricForcecalculation = calc_is_checked # two lines because max line length - - self.obj.SurfaceChargeDensity = self.parameter_widget.surfacechargedensityQSB.property( - "value" - )