[FEM] fix handling of vacuum permittivity
- fix message that permittivity object was not handled - set an expression, otherwise the user gets only "0.000" for the default of 8.8e-12 - use as unit the common "F/m" (this is also more user-friendly than "s^4*A^2 / (m^3*kg)") - fix a ToDo
This commit is contained in:
@@ -435,6 +435,10 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
|
||||
factor = 1e6;
|
||||
}
|
||||
}
|
||||
else if (unit == Unit::VacuumPermittivity) {
|
||||
unitString = QString::fromLatin1("F/m");
|
||||
factor = 1;
|
||||
}
|
||||
else if (unit == Unit::Frequency) {
|
||||
if (UnitValue < 1e3) {
|
||||
unitString = QString::fromLatin1("Hz");
|
||||
|
||||
@@ -383,6 +383,10 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
|
||||
factor = 1e6;
|
||||
}
|
||||
}
|
||||
else if (unit == Unit::VacuumPermittivity) {
|
||||
unitString = QString::fromLatin1("F/m");
|
||||
factor = 1;
|
||||
}
|
||||
else if (unit == Unit::Work) {
|
||||
if (UnitValue < 1.602176634e-10) {
|
||||
unitString = QString::fromLatin1("eV");
|
||||
|
||||
@@ -45,6 +45,7 @@ class ConstantVacuumPermittivity(base_fempythonobject.BaseFemPythonObject):
|
||||
"App::PropertyVacuumPermittivity",
|
||||
"VacuumPermittivity",
|
||||
"Constants",
|
||||
"Set the permittivity of vacuum"
|
||||
"Overwrites default permittivity of vacuum"
|
||||
)
|
||||
obj.VacuumPermittivity = Units.Quantity(constants.vacuum_permittivity())
|
||||
# we must set an expression so that the small value can actually be entered
|
||||
obj.setExpression("VacuumPermittivity", "8.85419e-12")
|
||||
|
||||
@@ -198,13 +198,6 @@ class Writer(object):
|
||||
"BoltzmannConstant": constants.boltzmann_constant(),
|
||||
}
|
||||
|
||||
def _setConstant(self, name, quantityStr):
|
||||
# TODO without method directly use self.constsdef[name]
|
||||
if name == "PermittivityOfVacuum":
|
||||
theUnit = "s^4*A^2 / (m^3*kg)"
|
||||
self.constsdef[name] = "{} {}".format(self._convert(quantityStr, theUnit), theUnit)
|
||||
return True
|
||||
|
||||
def _writeMesh(self):
|
||||
mesh = self._getSingleMember("Fem::FemMeshObject")
|
||||
unvPath = os.path.join(self.directory, "mesh.unv")
|
||||
@@ -300,15 +293,19 @@ class Writer(object):
|
||||
"""
|
||||
redefine constants in self.constsdef according constant redefine objects
|
||||
"""
|
||||
permittivity_objs = self._getMember("Fem::ConstantVacuumPermittivity")
|
||||
if len(permittivity_objs) == 1:
|
||||
Console.PrintLog("Constand permittivity overwriting.\n")
|
||||
self._setConstant("PermittivityOfVacuum", permittivity_objs[0].VacuumPermittivity)
|
||||
elif len(permittivity_objs) > 1:
|
||||
objs = self._getMember("Fem::ConstantVacuumPermittivity")
|
||||
if len(objs) == 1:
|
||||
permittivity = float(objs[0].VacuumPermittivity.getValueAs("F/m"))
|
||||
# since the base unit of FC is in mm, we must scale it to get plain SI
|
||||
permittivity = permittivity * 1e-9
|
||||
Console.PrintLog("Overwriting vacuum permittivity with: {}\n".format(permittivity))
|
||||
self.constsdef["PermittivityOfVacuum"] = "{} {}".format(permittivity, "F/m")
|
||||
self._handled(objs[0])
|
||||
elif len(objs) > 1:
|
||||
Console.PrintError(
|
||||
"More than one permittivity constant overwriting objects ({} objs). "
|
||||
"The permittivity constant overwriting is ignored.\n"
|
||||
.format(len(permittivity_objs))
|
||||
.format(len(objs))
|
||||
)
|
||||
|
||||
def _handleSimulation(self):
|
||||
|
||||
@@ -45,7 +45,7 @@ def stefan_boltzmann():
|
||||
def vacuum_permittivity():
|
||||
# https://forum.freecadweb.org/viewtopic.php?f=18&p=400959#p400959
|
||||
# https://en.wikipedia.org/wiki/Permittivity#Vacuum_permittivity
|
||||
return "8.85419e-12 s^4*A^2 / (m^3*kg)"
|
||||
return "8.85419e-12 F/m"
|
||||
|
||||
|
||||
def boltzmann_constant():
|
||||
|
||||
Reference in New Issue
Block a user