Commit 11c3f5b7 authored by Christophe Geuzaine's avatar Christophe Geuzaine

better interactive: Lib_* files are now completely clean of any interactive definition

parent 15a18b43
Pipeline #1450 passed with stage
in 11 minutes 27 seconds
......@@ -3,11 +3,18 @@
// Template library for electrostatics using a scalar electric potential (v)
// formulation, with floating potentials
// Default definitions of constants, groups and functions that can/should be
// redefined from outside the template:
DefineConstant[
modelPath = GetString["Gmsh/Model absolute path"],
resPath = StrCat[modelPath, "res/"],
eps0 = 8.854187818e-12,
interactive = 0
modelPath = "", // default path of the model
resPath = StrCat[modelPath, "res/"], // path for post-operation files
eps0 = 8.854187818e-12, // permittivity of vacuum
Val_Rint = 0, // internal radius of Vol_Inf_Ele annulus
Val_Rext = 0, // external radius of Vol_Inf_Ele annulus
Val_Cx = 0, // x-coordinate of center of Vol_Inf_Ele
Val_Cy = 0, // y-coordinate of center of Vol_Inf_Ele
Val_Cz = 0 // z-coordinate of center of Vol_Inf_Ele
];
Group {
......@@ -18,6 +25,7 @@ Group {
Sur_Neu_Ele, // Non-homogeneous Neumann boundary conditions (n.d)
Sur_C_Ele // boundary of conductors
];
Dom_Ele = Region[ {Vol_Ele, Sur_Neu_Ele} ];
}
Function{
......@@ -28,17 +36,7 @@ Function{
];
}
CallTest(interactive) Lib_EleSta_v_interactive;
DefineConstant[
Val_Rint = {1, Visible NbrRegions[Vol_Inf_Ele],
Name "Parameters/Geometry/1Internal shell radius"},
Val_Rext = {2, Visible NbrRegions[Vol_Inf_Ele],
Name "Parameters/Geometry/2External shell radius"},
Val_Cx = 0,
Val_Cy = 0,
Val_Cz = 0
];
// End of default definitions.
Jacobian {
{ Name Vol;
......@@ -80,7 +78,7 @@ FunctionSpace {
// v = v s + v s
// n n c,k c,k
{ Name sn; NameOfCoef vn; Function BF_Node;
Support Region[{Vol_Ele, Sur_Neu_Ele}]; Entity NodesOf[ All, Not Sur_C_Ele ]; }
Support Dom_Ele; Entity NodesOf[ All, Not Sur_C_Ele ]; }
{ Name sck; NameOfCoef vck; Function BF_GroupOfNodes;
Support Vol_Ele; Entity GroupsOfNodesOf[ Sur_C_Ele ]; }
}
......
......@@ -3,25 +3,36 @@
// Template library for magnetostatics using a scalar (phi) or a vector (a)
// potential formulation
// Default definitions of constants, groups and functions that can/should be
// redefined from outside the template:
DefineConstant[
modelPath = GetString["Gmsh/Model absolute path"],
resPath = StrCat[modelPath, "res/"],
exportFile = StrCat[modelPath, "export.pro"],
mu0 = 4*Pi*1e-7,
modelDim = 2,
interactive = 0
modelPath = "", // default path of the model
resPath = StrCat[modelPath, "res/"], // path for post-operation files
mu0 = 4*Pi*1e-7, // magnetic permeability of vacuum
modelDim = 2, // default model dimension (2D)
Val_Rint = 0, // internal radius of Vol_Inf_Ele annulus
Val_Rext = 0, // external radius of Vol_Inf_Ele annulus
Val_Cx = 0, // x-coordinate of center of Vol_Inf_Ele
Val_Cy = 0, // y-coordinate of center of Vol_Inf_Ele
Val_Cz = 0, // z-coordinate of center of Vol_Inf_Ele
NL_max_iter = 20, // max number of nonlinear iterations
NL_relax = 1, // nonlinear iteration relexation
NL_tol = 1e-5 // stopping criterion for nonlinear iterations
];
Group {
DefineGroup[
Vol_M_Mag, // magnets
Vol_L_Mag, // linear magnetic materials
Vol_NL_Mag, // nonlinear magnetic materials
Vol_M_Mag, // permenent magnets
Vol_S0_Mag, // imposed current density
Vol_Inf_Mag, // infinite domains
Vol_NL_Mag, // nonlinear magnetic materials
Vol_L_Mag, // linear magnetic materials
Sur_Dir_Mag // Dirichlet boundary conditions
Sur_Neu_Mag // Non-homogeneous Neumann boundary conditions
];
Vol_Mag = Region[{Vol_L_Mag, Vol_NL_Mag, Vol_M_Mag, Vol_S0_Mag, Vol_Inf_Mag}];
Dom_Mag = Region[{Vol_Mag, Sur_Neu_Mag}];
}
Function{
......@@ -30,37 +41,28 @@ Function{
nu, // magnetic reluctivity (= 1/nu)
hc, // coercive magnetic field (in magnets)
js, // source current density
dhdb_NL, dbdh_NL // nonlinear parts of the Jacobian
dhdb_NL, // nonlinar part of Jacobian for phi formulation
dbdh_NL, // nonlinear part of Jacobian for a formulation
bn, // normal magnetic flux density on Sur_Neu_Mag for phi formulation
nxh // tangential magnetic field on Sur_Neu_Mag for a formulation
];
}
CallTest(interactive) Lib_MagSta_a_phi_interactive;
DefineConstant[
Val_Rint = {1, Visible NbrRegions[Vol_Inf_Mag],
Name "Parameters/Geometry/1Internal shell radius"},
Val_Rext = {2, Visible NbrRegions[Vol_Inf_Mag],
Name "Parameters/Geometry/2External shell radius"},
Val_Cx, Val_Cy, Val_Cz,
Nb_max_iter = {30, Visible NbrRegions[Vol_NL_Mag],
Name "Parameters/Nonlinear solver/Maximum number of iterations"},
relaxation_factor = 1,
stop_criterion = {1e-5, Visible NbrRegions[Vol_NL_Mag],
Name "Parameters/Nonlinear solver/Tolerance"}
];
Group{
Vol_Mag = Region[{Vol_L_Mag, Vol_NL_Mag, Vol_M_Mag, Vol_S0_Mag, Vol_Inf_Mag}];
}
// End of default definitions.
Jacobian {
{ Name JVol;
{ Name Vol;
Case {
{ Region Vol_Inf_Mag;
Jacobian VolSphShell{Val_Rint, Val_Rext, Val_Cx, Val_Cy, Val_Cz}; }
{ Region All; Jacobian Vol; }
}
}
{ Name Sur;
Case {
{ Region All; Jacobian Sur; }
}
}
}
Integration {
......@@ -94,7 +96,7 @@ FunctionSpace {
{ Name Hgrad_phi; Type Form0;
BasisFunction {
{ Name sn; NameOfCoef phin; Function BF_Node;
Support Vol_Mag; Entity NodesOf[ All ]; }
Support Dom_Mag; Entity NodesOf[ All ]; }
}
Constraint {
{ NameOfCoef phin; EntityType NodesOf; NameOfConstraint phi; }
......@@ -103,8 +105,8 @@ FunctionSpace {
If(modelDim == 3)
{ Name Hcurl_a; Type Form1;
BasisFunction {
{ Name se; NameOfCoef ae; Function BF_Edge; Support Vol_Mag ;
Entity EdgesOf[ All ]; }
{ Name se; NameOfCoef ae; Function BF_Edge;
Support Dom_Mag ; Entity EdgesOf[ All ]; }
}
Constraint {
{ NameOfCoef ae; EntityType EdgesOf; NameOfConstraint a; }
......@@ -116,7 +118,7 @@ FunctionSpace {
{ Name Hcurl_a; Type Form1P;
BasisFunction {
{ Name se; NameOfCoef ae; Function BF_PerpendicularEdge;
Support Vol_Mag; Entity NodesOf[ All ]; }
Support Dom_Mag; Entity NodesOf[ All ]; }
}
Constraint {
{ NameOfCoef ae; EntityType NodesOf; NameOfConstraint a; }
......@@ -132,11 +134,13 @@ Formulation {
}
Equation {
Integral { [ - mu[-{d phi}] * Dof{d phi} , {d phi} ];
In Vol_Mag; Jacobian JVol; Integration I1; }
In Vol_Mag; Jacobian Vol; Integration I1; }
Integral { JacNL [ - dbdh_NL[-{d phi}] * Dof{d phi} , {d phi} ];
In Vol_NL_Mag; Jacobian JVol; Integration I1; }
In Vol_NL_Mag; Jacobian Vol; Integration I1; }
Integral { [ - mu[] * hc[] , {d phi} ];
In Vol_M_Mag; Jacobian JVol; Integration I1; }
In Vol_M_Mag; Jacobian Vol; Integration I1; }
Integral { [ bn[] , {phi} ];
In Sur_Neu_Mag; Jacobian Sur; Integration I1; }
}
}
{ Name MagSta_a; Type FemEquation;
......@@ -145,13 +149,15 @@ Formulation {
}
Equation {
Integral { [ nu[{d a}] * Dof{d a} , {d a} ];
In Vol_Mag; Jacobian JVol; Integration I1; }
In Vol_Mag; Jacobian Vol; Integration I1; }
Integral { JacNL [ dhdb_NL[{d a}] * Dof{d a} , {d a} ];
In Vol_NL_Mag; Jacobian JVol; Integration I1; }
In Vol_NL_Mag; Jacobian Vol; Integration I1; }
Integral { [ hc[] , {d a} ];
In Vol_M_Mag; Jacobian JVol; Integration I1; }
In Vol_M_Mag; Jacobian Vol; Integration I1; }
Integral { [ -js[] , {a} ];
In Vol_S0_Mag; Jacobian JVol; Integration I1; }
In Vol_S0_Mag; Jacobian Vol; Integration I1; }
Integral { [ nxh[] , {a} ];
In Sur_Neu_Mag; Jacobian Sur; Integration I1; }
}
}
}
......@@ -165,7 +171,7 @@ Resolution {
If(!NbrRegions[Vol_NL_Mag])
Generate[A]; Solve[A];
Else
IterativeLoop[Nb_max_iter, stop_criterion, relaxation_factor]{
IterativeLoop[NL_max_iter, NL_tol, NL_relax]{
GenerateJac[A]; SolveJac[A];
}
EndIf
......@@ -180,7 +186,7 @@ Resolution {
If(!NbrRegions[Vol_NL_Mag])
Generate[A]; Solve[A];
Else
IterativeLoop[Nb_max_iter, stop_criterion, relaxation_factor]{
IterativeLoop[NL_max_iter, NL_tol, NL_relax]{
GenerateJac[A]; SolveJac[A];
}
EndIf
......@@ -193,20 +199,20 @@ PostProcessing {
{ Name MagSta_phi; NameOfFormulation MagSta_phi;
Quantity {
{ Name b; Value {
Term { [ - mu[-{d phi}] * {d phi} ]; In Vol_Mag; Jacobian JVol; }
Term { [ - mu[] * hc[] ]; In Vol_M_Mag; Jacobian JVol; }
Term { [ - mu[-{d phi}] * {d phi} ]; In Vol_Mag; Jacobian Vol; }
Term { [ - mu[] * hc[] ]; In Vol_M_Mag; Jacobian Vol; }
}
}
{ Name h; Value {
Term { [ - {d phi} ]; In Vol_Mag; Jacobian JVol; }
Term { [ - {d phi} ]; In Vol_Mag; Jacobian Vol; }
}
}
{ Name hc; Value {
Term { [ hc[] ]; In Vol_M_Mag; Jacobian JVol; }
Term { [ hc[] ]; In Vol_M_Mag; Jacobian Vol; }
}
}
{ Name phi; Value {
Term { [ {phi} ]; In Vol_Mag; Jacobian JVol; }
Term { [ {phi} ]; In Vol_Mag; Jacobian Vol; }
}
}
}
......@@ -214,28 +220,28 @@ PostProcessing {
{ Name MagSta_a; NameOfFormulation MagSta_a;
Quantity {
{ Name az; Value {
Local { [ CompZ[{a}] ]; In Vol_Mag; Jacobian JVol; }
Local { [ CompZ[{a}] ]; In Vol_Mag; Jacobian Vol; }
}
}
{ Name b; Value {
Term { [ {d a} ]; In Vol_Mag; Jacobian JVol; }
Term { [ {d a} ]; In Vol_Mag; Jacobian Vol; }
}
}
{ Name a; Value {
Term { [ {a} ]; In Vol_Mag; Jacobian JVol; }
Term { [ {a} ]; In Vol_Mag; Jacobian Vol; }
}
}
{ Name h; Value {
Term { [ nu[{d a}] * {d a} ]; In Vol_Mag; Jacobian JVol; }
Term { [ hc[] ]; In Vol_M_Mag; Jacobian JVol; }
Term { [ nu[{d a}] * {d a} ]; In Vol_Mag; Jacobian Vol; }
Term { [ hc[] ]; In Vol_M_Mag; Jacobian Vol; }
}
}
{ Name hc; Value {
Term { [ hc[] ]; In Vol_M_Mag; Jacobian JVol; }
Term { [ hc[] ]; In Vol_M_Mag; Jacobian Vol; }
}
}
{ Name js; Value {
Term { [ js[] ]; In Vol_S0_Mag; Jacobian JVol; }
Term { [ js[] ]; In Vol_S0_Mag; Jacobian Vol; }
}
}
}
......@@ -246,7 +252,9 @@ PostOperation {
{ Name MagSta_phi; NameOfPostProcessing MagSta_phi;
Operation {
CreateDir[resPath];
Print[ hc, OnElementsOf Vol_M_Mag, File StrCat[resPath, "MagSta_phi_hc.pos"] ];
If(NbrRegions[Vol_M_Mag])
Print[ hc, OnElementsOf Vol_M_Mag, File StrCat[resPath, "MagSta_phi_hc.pos"] ];
EndIf
Print[ phi, OnElementsOf Vol_Mag, File StrCat[resPath, "MagSta_phi_phi.pos"] ];
Print[ h, OnElementsOf Vol_Mag, File StrCat[resPath, "MagSta_phi_h.pos"] ];
Print[ b, OnElementsOf Vol_Mag, File StrCat[resPath, "MagSta_phi_b.pos"] ];
......@@ -255,8 +263,12 @@ PostOperation {
{ Name MagSta_a; NameOfPostProcessing MagSta_a;
Operation {
CreateDir[resPath];
Print[ hc, OnElementsOf Vol_M_Mag, File StrCat[resPath, "MagSta_a_hc.pos"] ];
Print[ js, OnElementsOf Vol_S0_Mag, File StrCat[resPath, "MagSta_a_js.pos"] ];
If(NbrRegions[Vol_M_Mag])
Print[ hc, OnElementsOf Vol_M_Mag, File StrCat[resPath, "MagSta_a_hc.pos"] ];
EndIf
If(NbrRegions[Vol_S0_Mag])
Print[ js, OnElementsOf Vol_S0_Mag, File StrCat[resPath, "MagSta_a_js.pos"] ];
EndIf
If(modelDim == 2)
Print[ az, OnElementsOf Vol_Mag, File StrCat[resPath, "MagSta_a_az.pos"] ];
EndIf
......
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