Commit d02546ab by Christophe Geuzaine

simplify: get rid of constant -> always use functions

parent 33079d70
Pipeline #1502 passed with stage
in 9 minutes 34 seconds
......@@ -170,68 +170,50 @@ Function {
EndIf
Else
DefineConstant[
f_fct~{i} = {"Vector[0,0,0]", Visible (source~{i} == 1),
f_fct~{i} = {"Vector[0,0,0]",
Visible (source~{i} == 1),
Name StrCat[volPath, name~{i}, "/5f function"],
Label "f [N/m³]", Help "Force density"},
material_preset~{i} = {#linearElasticMaterials() > 2 ? 2 : 0,
material_preset~{i} = {#linearElasticMaterials() > 1 ? 1 : 0,
Visible (material~{i} == 0),
Choices{ 0:#linearElasticMaterials()-1 = linearElasticMaterials() },
Name StrCat[volPath, name~{i}, "/1material preset"],
Label "Material choice"}
nu_cst~{i} = {0.32, Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2nu value"],
Label "ν [-]", Help "Poisson's ratio"},
nu_fct~{i} = {"0.32", Visible (material~{i} == 0 && material_preset~{i} == 1),
nu_fct~{i} = {"0.32",
Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2nu function"],
Label "ν [-]", Help "Poisson's ratio"}
E_cst~{i} = {69e9, Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2E value"],
Label "E [N/m²]", Help "Poisson's ratio"},
E_fct~{i} = {"69e9", Visible (material~{i} == 0 && material_preset~{i} == 1),
E_fct~{i} = {"69e9",
Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2E function"],
Label "E [N/m²]", Help "Poisson's ratio"}
rho_cst~{i} = {2700,
Visible (material~{i} == 0 && Flag_Regime && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2rho value"],
Label "ρ [kg/m³]", Help "Mass density"},
rho_fct~{i} = {"2700",
Visible (material~{i} == 0 && Flag_Regime && material_preset~{i} == 1),
Visible (material~{i} == 0 && Flag_Regime && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2rho function"],
Label "ρ [kg/m³]", Help "Mass density"}
];
// f[]
// source
If(source~{i} == 1) // function
str = StrCat[str, "f", reg, " = ", f_fct~{i}, "; "];
EndIf
// nu[]
If(material~{i} == 0 && material_preset~{i} == 0) // constant
str = StrCat[str, "nu", reg, Sprintf[" = %g;", nu_cst~{i}]];
ElseIf(material~{i} == 0 && material_preset~{i} == 1) // function
str = StrCat[str, "nu", reg, " = ", nu_fct~{i}, ";"];
ElseIf(material~{i} == 0 && material_preset~{i} > 1) // preset
str = StrCat[str, "nu", reg, " = ", linearElasticMaterials(material_preset~{i}),
"_elastic_poisson_ratio;"];
EndIf
// E[]
If(material~{i} == 0 && material_preset~{i} == 0) // constant
str = StrCat[str, "E", reg, Sprintf[" = %g;", E_cst~{i}]];
ElseIf(material~{i} == 0 && material_preset~{i} == 1) // function
str = StrCat[str, "E", reg, " = ", E_fct~{i}, ";"];
ElseIf(material~{i} == 0 && material_preset~{i} > 1) // preset
str = StrCat[str, "E", reg, " = ", linearElasticMaterials(material_preset~{i}),
"_elastic_young_modulus;"];
EndIf
// rho[]
If(Flag_Regime)
If(material~{i} == 0 && material_preset~{i} == 0) // constant
str = StrCat[str, "rho", reg, Sprintf[" = %g;", rho_cst~{i}]];
ElseIf(material~{i} == 0 && material_preset~{i} == 1) // function
// linear material
If(material~{i} == 0)
If(material_preset~{i} == 0)
str = StrCat[str, "nu", reg, " = ", nu_fct~{i}, ";"];
str = StrCat[str, "E", reg, " = ", E_fct~{i}, ";"];
str = StrCat[str, "rho", reg, " = ", rho_fct~{i}, ";"];
ElseIf(material~{i} == 0 && material_preset~{i} > 1) // preset
str = StrCat[str, "rho", reg, " = ", linearElasticMaterials(material_preset~{i}),
Else
str = StrCat[str, "nu", reg, " = ",
linearElasticMaterials(material_preset~{i}),
"_elastic_poisson_ratio;"];
str = StrCat[str, "E", reg, " = ",
linearElasticMaterials(material_preset~{i}),
"_elastic_young_modulus;"];
str = StrCat[str, "rho", reg, " = ",
linearElasticMaterials(material_preset~{i}),
"_mass_density;"];
EndIf
EndIf
EndIf
EndIf
Parse[str];
If(export && StrLen[str])
......
......@@ -146,43 +146,35 @@ Function {
EndIf
Else
DefineConstant[
rho_preset~{i} = {0, Visible (source~{i} == 1),
Choices{ 0="Constant", 1="Function" },
Name StrCat[volPath, name~{i}, "/4rho preset"],
Label "Source choice"},
rho_cst~{i} = {1, Visible (source~{i} == 1 && rho_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/5rho value"],
Label "ρ [C/m³]", Help "Charge density"},
rho_fct~{i} = {"1", Visible (source~{i} == 1 && rho_preset~{i} == 1),
rho_fct~{i} = {"1",
Visible (source~{i} == 1),
Name StrCat[volPath, name~{i}, "/5rho function"],
Label "ρ [C/m³]", Help "Charge density"},
material_preset~{i} = {#linearDielectricMaterials() > 2 ? 2 : 0,
material_preset~{i} = {#linearDielectricMaterials() > 1 ? 1 : 0,
Visible (material~{i} == 0),
Choices{ 0:#linearDielectricMaterials()-1 = linearDielectricMaterials() },
Name StrCat[volPath, name~{i}, "/1epsr preset"],
Label "Material choice"}
epsr_cst~{i} = {1, Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2epsr value"],
Label "εr [-]", Help "Relative dielectric permittivity"},
epsr_fct~{i} = {"1", Visible (material~{i} == 0 && material_preset~{i} == 1),
epsr_fct~{i} = {"1",
Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2epsr function"],
Label "εr [-]", Help "Relative dielectric permittivity"}
];
// rho[]
If(source~{i} == 1 && rho_preset~{i} == 0) // constant
str = StrCat[str, "rho", reg, Sprintf[" = %g; ", rho_cst~{i}]];
ElseIf(source~{i} == 1 && rho_preset~{i} == 1) // function
// source
If(source~{i} == 1)
str = StrCat[str, "rho", reg, " = ", rho_fct~{i}, "; "];
EndIf
// epsr[]
If(material~{i} == 0 && material_preset~{i} == 0) // constant
str = StrCat[str, "epsr", reg, Sprintf[" = %g;", epsr_cst~{i}]];
ElseIf(material~{i} == 0 && material_preset~{i} == 1) // function
str = StrCat[str, "epsr", reg, " = ", epsr_fct~{i}, ";"];
ElseIf(material~{i} == 0 && material_preset~{i} > 1) // preset
str = StrCat[str, "epsr", reg, " = ", linearDielectricMaterials(material_preset~{i}),
"_relative_dielectric_permittivity;"];
ElseIf(material~{i} == 1) // infinite air region
// linear material
If(material~{i} == 0)
If(material_preset~{i} == 0)
str = StrCat[str, "epsr", reg, " = ", epsr_fct~{i}, ";"];
Else
str = StrCat[str, "epsr", reg, " = ",
linearDielectricMaterials(material_preset~{i}),
"_relative_dielectric_permittivity;"];
EndIf
// infinite shell
ElseIf(material~{i} == 1)
str = StrCat[str, "epsr", reg, " = 1;"];
EndIf
EndIf
......
......@@ -151,49 +151,21 @@ Function{
EndIf
Else
DefineConstant[
hc_preset~{i} = {0, Visible (source~{i} == 1),
Choices{ 0="Constant", 1="Function" },
Name StrCat[volPath, name~{i}, "/7hc preset"],
Label "Source choice"},
hcx_cst~{i} = {920000, Visible (source~{i} == 1 && hc_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/8hcx value"],
Label "hcx [A/m]", Help "Coercive magnetic field along x-axis"},
hcy_cst~{i} = {0, Visible (source~{i} == 1 && hc_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/8hcy value"],
Label "hcy [A/m]", Help "Coercive magnetic field along y-axis"},
hcz_cst~{i} = {0, Visible (source~{i} == 1 && hc_preset~{i} == 0 && dim~{i} == 3),
Name StrCat[volPath, name~{i}, "/8hcz value"],
Label "hcz [A/m]", Help "Coercive magnetic field along z-axis"},
hc_fct~{i} = {"Vector[92000, 0, 0]",
Visible (source~{i} == 1 && hc_preset~{i} == 1),
Visible (source~{i} == 1),
Name StrCat[volPath, name~{i}, "/8hc function"],
Label "hc [A/m]", Help "Coercive magnetic field"},
js_preset~{i} = {0, Visible (source~{i} == 2),
Choices{ 0="Constant", 1="Function" },
Name StrCat[volPath, name~{i}, "/7js preset"],
Label "Source choice"},
jsx_cst~{i} = {0, Visible (source~{i} == 2 && js_preset~{i} == 0 && dim~{i} == 3),
Name StrCat[volPath, name~{i}, "/8jx value"],
Label "jsx [A/m²]", Help "Current density along x-axis"},
jsy_cst~{i} = {0, Visible (source~{i} == 2 && js_preset~{i} == 0 && dim~{i} == 3),
Name StrCat[volPath, name~{i}, "/8jy value"],
Label "jsy [A/m²]", Help "Current density along y-axis"},
jsz_cst~{i} = {1, Visible (source~{i} == 2 && js_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/8jz value"],
Label "jsz [A/m²]", Help "Current density along z-axis"},
js_fct~{i} = {"Vector[0, 0, 1]",
Visible (source~{i} == 2 && js_preset~{i} == 1),
Visible (source~{i} == 2),
Name StrCat[volPath, name~{i}, "/8js function"],
Label "js [A/m²]", Help "Current density"},
material_preset~{i} = {#linearMagneticMaterials() > 2 ? 2 : 0,
material_preset~{i} = {#linearMagneticMaterials() > 1 ? 1 : 0,
Visible (material~{i} == 0),
Choices{ 0:#linearMagneticMaterials()-1 = linearMagneticMaterials() },
Name StrCat[volPath, name~{i}, "/1mur preset"],
Label "Material choice"}
mur_cst~{i} = {1, Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2mur value"],
Label "μr [-]", Help "Relative magnetic permeability"},
mur_fct~{i} = {"1", Visible (material~{i} == 0 && material_preset~{i} == 1),
mur_fct~{i} = {"1",
Visible (material~{i} == 0 && material_preset~{i} == 0),
Name StrCat[volPath, name~{i}, "/2mur function"],
Label "μr [-]", Help "Relative magnetic permeability"},
nl_material_preset~{i} = {#nonlinearMagneticMaterials() > 2 ? 2 : 0,
......@@ -215,40 +187,35 @@ Function{
Visible (material~{i} == 1 && nl_material_preset~{i} == 1),
Name StrCat[volPath, name~{i}, "/3dnudb2 function"],
Label "dν(b)/db²"},
mu_fct~{i} = {"***", Visible (material~{i} == 1 && nl_material_preset~{i} == 1),
mu_fct~{i} = {"***",
Visible (material~{i} == 1 && nl_material_preset~{i} == 1),
Name StrCat[volPath, name~{i}, "/4mu function"],
Label "μ(h) [H/m]", Help "Magnetic permeability"},
dmudh2_fct~{i} = {"***", Visible (material~{i} == 1 && nl_material_preset~{i} == 1),
dmudh2_fct~{i} = {"***",
Visible (material~{i} == 1 && nl_material_preset~{i} == 1),
Name StrCat[volPath, name~{i}, "/5dmudh2 function"],
Label "dμ(h)/dh²"}
];
// hc[] and js[]
If(source~{i} == 1 && hc_preset~{i} == 0) // magnet, constant
str = StrCat[str, "hc", reg,
Sprintf[" = Vector[%g, %g, %g]; ", hcx_cst~{i}, hcy_cst~{i}, hcz_cst~{i}]];
ElseIf(source~{i} == 1 && hc_preset~{i} == 1) // magnet, function
// sources
If(source~{i} == 1)
str = StrCat[str, "hc", reg, " = ", hc_fct~{i}, "; "];
ElseIf(source~{i} == 2 && js_preset~{i} == 0) // current source, constant
str = StrCat[str, "js", reg, " = ",
Sprintf["Vector[%g, %g, %g]; ", jsx_cst~{i}, jsy_cst~{i}, jsz_cst~{i}]];
ElseIf(source~{i} == 2 && js_preset~{i} == 1) // current source, function
ElseIf(source~{i} == 2)
str = StrCat[str, "js", reg, " = ", js_fct~{i}, "; "];
EndIf
// mu[], nu[], dhdb[], etc.
If(material~{i} == 0 && material_preset~{i} == 0) // linear material, constant
str = StrCat[str,
"mu", reg, " = ", Sprintf["%g", mur_cst~{i}], "*mu0; ",
"nu", reg, " = 1/(", Sprintf["%g", mur_cst~{i}], "*mu0); "];
ElseIf(material~{i} == 0 && material_preset~{i} == 1) // linear material, function
str = StrCat[str,
"mu", reg, " = (", mur_fct~{i}, ")*mu0; ",
"nu", reg, " = 1/((", mur_fct~{i}, ")*mu0); "];
ElseIf(material~{i} == 0 && material_preset~{i} > 1) // linear material, preset
n = Str[ linearMagneticMaterials(material_preset~{i}) ];
str = StrCat[str,
"mu", reg, " = ", n, "_relative_magnetic_permeability*mu0; ",
"nu", reg, " = 1/(", n, "_relative_magnetic_permeability*mu0); "];
ElseIf(material~{i} == 1) // nonlinear material
// linear material
If(material~{i} == 0)
If(material_preset~{i} == 0)
str = StrCat[str,
"mu", reg, " = (", mur_fct~{i}, ")*mu0; ",
"nu", reg, " = 1/((", mur_fct~{i}, ")*mu0); "];
Else
n = Str[ linearMagneticMaterials(material_preset~{i}) ];
str = StrCat[str,
"mu", reg, " = ", n, "_relative_magnetic_permeability*mu0; ",
"nu", reg, " = 1/(", n, "_relative_magnetic_permeability*mu0); "];
EndIf
// nonlinear material
ElseIf(material~{i} == 1)
If(nl_material_preset~{i} == 0) // data points
n = Sprintf["UserMaterialPts_%g", i];
str = StrCat[str,
......@@ -272,7 +239,8 @@ Function{
"dbdh", reg, " = ", n, "_dbdh[$1]; ",
"nu", reg, " = ", n, "_nu[$1]; ",
"dhdb", reg, " = ", n, "_dhdb[$1]; "];
ElseIf(material~{i} == 2) // infinite shell
// infinite shell
ElseIf(material~{i} == 2)
str = StrCat[str, "mu", reg, " = mu0; ", "nu", reg, " = 1/mu0; "];
EndIf
EndIf
......
......@@ -231,12 +231,13 @@ Return
Function{
// create lists of available material names of various types:
linearMagneticMaterials() = Str["Constant", "Function"];
nonlinearMagneticMaterials() = Str["Data points", "Function"];
permanentMagnetMaterials() = Str["Constant", "Function"];
linearDielectricMaterials() = Str["Constant", "Function"];
electricConductors() = Str["Constant", "Function"];
linearElasticMaterials() = Str["Constant", "Function"];
linearMagneticMaterials() = Str["User-defined"];
nonlinearMagneticMaterials() = Str["User-defined data points",
"User-defined function"];
permanentMagnetMaterials() = Str["User-defined"];
linearDielectricMaterials() = Str["User-defined"];
electricConductors() = Str["User-defined"];
linearElasticMaterials() = Str["User-defined"];
For i In {1 : #Materials()}
_materialName = Str[ Materials(i - 1) ];
Call DefineMaterialFunctions;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment