[FEM] Elmer: fixes for Magneto2D writer

- assure a 2D coordinate system is used
- get rid of annoying numerical artifacts
This commit is contained in:
Uwe
2023-02-10 01:06:14 +01:00
parent 8e9f9bba53
commit a14efad44c
2 changed files with 17 additions and 18 deletions

View File

@@ -94,15 +94,14 @@ class MgDyn2Dwriter:
self.write.constsdef["PermeabilityOfVacuum"],
"M*L/(T^2*I^2)"
)
permeability = round(permeability, 20) # to get rid of numerical artifacts
self.write.constant("Permeability Of Vacuum", permeability)
# we round in the following to get rid of numerical artifacts
self.write.constant("Permeability Of Vacuum", round(permeability, 20))
permittivity = self.write.convert(
self.write.constsdef["PermittivityOfVacuum"],
"T^4*I^2/(L^3*M)"
)
permittivity = round(permittivity, 20) # to get rid of numerical artifacts
self.write.constant("Permittivity Of Vacuum", permittivity)
self.write.constant("Permittivity Of Vacuum", round(permittivity, 20))
def handleMagnetodynamic2DMaterial(self, bodies):
# check that all bodies have a set material
@@ -148,29 +147,29 @@ class MgDyn2Dwriter:
# output only if current density is enabled and needed
if not obj.CurrentDensity_re_1_Disabled:
currentDensity = float(obj.CurrentDensity_re_1.getValueAs("A/m^2"))
self.write.bodyForce(name, "Current Density", currentDensity)
self.write.bodyForce(name, "Current Density", round(currentDensity, 6))
# imaginaries are only needed for harmonic equation
if equation.IsHarmonic:
if not obj.CurrentDensity_im_1_Disabled:
currentDensity = float(obj.CurrentDensity_im_1.getValueAs("A/m^2"))
self.write.bodyForce(name, "Current Density Im", currentDensity)
self.write.bodyForce(name, "Current Density Im", round(currentDensity, 6))
if hasattr(obj, "Magnetization_re_1"):
# output only if magnetization is enabled and needed
if not obj.Magnetization_re_1_Disabled:
magnetization = float(obj.Magnetization_re_1.getValueAs("A/m"))
self.write.material(name, "Magnetization 1", magnetization)
self.write.material(name, "Magnetization 1", round(magnetization, 6))
if not obj.Magnetization_re_2_Disabled:
magnetization = float(obj.Magnetization_re_2.getValueAs("A/m"))
self.write.material(name, "Magnetization 2", magnetization)
self.write.material(name, "Magnetization 2", round(magnetization, 6))
# imaginaries are only needed for harmonic equation
if equation.IsHarmonic:
if not obj.Magnetization_im_1_Disabled:
magnetization = float(obj.Magnetization_im_1.getValueAs("A/m"))
self.write.material(name, "Magnetization Im 1", magnetization)
self.write.material(name, "Magnetization Im 1", round(magnetization, 6))
if not obj.Magnetization_im_2_Disabled:
magnetization = float(obj.Magnetization_im_2.getValueAs("A/m"))
self.write.material(name, "Magnetization Im 2", magnetization)
self.write.material(name, "Magnetization Im 2", round(magnetization, 6))
def handleMagnetodynamic2DBodyForces(self, bodies, equation):
currentDensities = self.write.getMember("Fem::ConstraintCurrentDensity")
@@ -221,7 +220,7 @@ class MgDyn2Dwriter:
if obj.PotentialEnabled:
if hasattr(obj, "Potential"):
potential = float(obj.Potential.getValueAs("V"))
self.write.boundary(name, "Potential", potential)
self.write.boundary(name, "Potential", round(potential, 6))
if obj.ElectricInfinity:
self.write.boundary(name, "Infinity BC", True)
self.write.handled(obj)
@@ -234,7 +233,7 @@ class MgDyn2Dwriter:
)
self.write.equation(b, "Name", equation.Name)
if equation.IsHarmonic:
frequency = Units.Quantity(equation.AngularFrequency).Value
self.write.equation(b, "Angular Frequency", float(frequency))
frequency = float(Units.Quantity(equation.AngularFrequency).Value)
self.write.equation(b, "Angular Frequency", round(frequency, 6))
## @}

View File

@@ -61,8 +61,8 @@ _STARTINFO_NAME = "ELMERSOLVER_STARTINFO"
_SIF_NAME = "case.sif"
_ELMERGRID_IFORMAT = "8"
_ELMERGRID_OFORMAT = "2"
_NON_CARTESIAN_CS = ["Polar 2D", "Polar 3D",
"Cylindric", "Cylindric Symmetric"]
_COORDS_NON_MAGNETO_2D = ["Polar 2D", "Polar 3D", "Cartesian 3D",
"Cylindric", "Cylindric Symmetric"]
def _getAllSubObjects(obj):
@@ -547,12 +547,12 @@ class Writer(object):
else:
activeIn = self.getAllBodies()
# Magnetodynamic2D cannot handle all coordinate sysytems
if self.solver.CoordinateSystem in _NON_CARTESIAN_CS:
if self.solver.CoordinateSystem in _COORDS_NON_MAGNETO_2D :
raise WriteError(
"The coordinate setting '{}'\n is not "
"supported by the equation 'Magnetodynamic2D'.\n\n"
"The possible settings are:\n'Cartesian 2D',\n"
"'Cartesian 3D',\nor 'Axi Symmetric'".format(self.solver.CoordinateSystem)
"Possible is:\n'Cartesian 2D' or 'Axi Symmetric'"
.format(self.solver.CoordinateSystem)
)
solverSection = MgDyn2D.getMagnetodynamic2DSolver(equation)