diff --git a/DiffractionGratings/README.txt b/DiffractionGratings/README.txt
index 51f62708652f3c5dc65fdc1a85408b034acfed1a..9c4559e92cc669c54ac8f29d1c73e7062ec9b2de 100644
--- a/DiffractionGratings/README.txt
+++ b/DiffractionGratings/README.txt
@@ -11,7 +11,7 @@ Quick start 3D
 To run the test cases, type in terminal :
 gmsh grating3D.pro -setstring test_case pyramid
 gmsh grating3D.pro -setstring test_case hole
-gmsh grating3D.pro -setstring test_case torus
+gmsh grating3D.pro -setstring test_case U
 gmsh grating3D.pro -setstring test_case half_ellipsoid
 gmsh grating3D.pro -setstring test_case checker
 gmsh grating3D.pro -setstring test_case bisin
diff --git a/DiffractionGratings/grating2D_scalar.pro b/DiffractionGratings/grating2D_scalar.pro
index 740f7d8fc37a1f544eeb16046427479ab04085bb..44cdaaee668eb49701a56544867c817c2fd76387 100644
--- a/DiffractionGratings/grating2D_scalar.pro
+++ b/DiffractionGratings/grating2D_scalar.pro
@@ -372,6 +372,7 @@ Resolution {
 PostProcessing {
   { Name postpro_energy; NameOfFormulation helmoltz_scalar;
     Quantity {
+      { Name SSize      ; Value { Local { [ $KSPSystemSize  ]; In Omega; Jacobian JVol; } } }
       { Name u           ; Value { Local { [ {u2d}       ]; In Omega; Jacobian JVol; } } }
       { Name u_diff      ; Value { Local { [ {u2d}+u1d[] ]; In Omega; Jacobian JVol; } } }
       { Name u_tot       ; Value { Local { [ {u2d}+u1[]  ]; In Omega; Jacobian JVol; } } }
@@ -422,6 +423,7 @@ PostProcessing {
 PostOperation {
   { Name postop_energy; NameOfPostProcessing postpro_energy ;
     Operation {
+      Print[ SSize, OnPoint{0,0,0}, Format Table, File > StrCat[myDir, "SSize.txt"]] ;
       Print[ lambda_step, OnPoint{0,0,0}, Format Table, File > StrCat[myDir, "temp_lambda_step.txt"], SendToServer "GetDP/Lambda_step" ] ;
       For i In {0:2*nb_orders}
         Print[ s_r~{i}[SurfCutSuper1], OnGlobal, StoreInVariable $sr~{i}, Format Table , File > StrCat[myDir, Sprintf("temp_s_r_%g.txt", i-nb_orders)]];
diff --git a/DiffractionGratings/grating3D.geo b/DiffractionGratings/grating3D.geo
index a2671b5fc7a4824dfdf75e2af3d4cfca029aa881..82419019a6a732b6844bd7ec1f81069bb64e4b58 100644
--- a/DiffractionGratings/grating3D.geo
+++ b/DiffractionGratings/grating3D.geo
@@ -15,118 +15,131 @@
 // You should have received a copy of the GNU General Public License
 // along with This program. If not, see <https://www.gnu.org/licenses/>.
 
-Include "grating3D_data.geo";
+  Include "grating3D_data.geo";
 
-SetFactory("OpenCASCADE");
-e = 5*nm;
-E = 10*(period_x+period_x/2);
-
-Macro SetPBCs
-  BlochXm() = Surface In BoundingBox{.5*(-period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,(-period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
-  BlochXp() = Surface In BoundingBox{.5*( period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
-  BlochYm() = Surface In BoundingBox{.5*(-period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e,-dyc/2+e, PML_top_hh+PML_top+e};
-  BlochYp() = Surface In BoundingBox{.5*(-period_x-dys)-e, dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
-  // For k In {1:#BlochXm()-1}
-  //   Printf("BlochXm surf %g",BlochXm(k));
-  // EndFor
-  // For k In {1:#BlochYm()-1}
-  //   Printf("BlochYm surf %g",BlochYm(k));
-  // EndFor
-  // For k In {1:#BlochXp()-1}
-  //   Printf("BlochXp surf %g",BlochXp(k));
-  // EndFor
-  // For k In {1:#BlochYp()-1}
-  //   Printf("BlochYp surf %g",BlochYp(k));
-  // EndFor
-  If (tag_geom==6) // bi-sin : BoundingBox does not catch BSpline Surfaces?
-    BlochXm()+={17,12};
-    BlochXp()+={19,14};
-    BlochYm()+={15,20};
-    BlochYp()+={13,18};
-  EndIf
-  Periodic Surface{BlochXp()} = {BlochXm()} Translate{period_x,        0,        0};
-  Periodic Surface{BlochYp()} = {BlochYm()} Translate{    dys, dyc,        0};
-Return
-
-If (tag_geom==6)
-  // Bi-sinusoidal profile by Spline surface filling
-  // not the most general way to implement a freesurface height=f(x,y) and relies on multiple Coherence calls
-  // several hacks are used, one of them is to do all this at the very begining
-  nsin = 20;
-  For i In {0:nsin}
-      xx1~{i} = -period_x/2+i*period_x/2/(nsin-1);
-      xx2~{i} =             i*period_x/2/(nsin-1);
-  EndFor
-  pp=newp;//pp=pp-1;
-  For i In {0:nsin-1}
-    yy=-period_y/2;
-    Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
-    yy=0;
-    Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
-    yy=period_y/2;
-    Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
-    yy=-period_y/2;
-    Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
-    yy=0;
-    Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
-    yy=period_y/2;
-    Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
-    Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
-  EndFor
-  For k In {1:11}
-    BSpline(newl) = {pp+k:pp+12*nsin:12};
-  EndFor
-  BSpline(newl) = {pp  :pp+12*(nsin-1):12};
-  Coherence;
-  Box(1) = {-period_x/2,-period_y/2,     hh_L_3,period_x,period_y, thick_L_3};
-  Delete{Volume{1}; Surface{1,2,3,4} ; Line{13,15,17,19};}
-  Curve Loop(7) = {21, 20, -23, -16};
-  Curve Loop(8) = {1, 2, -3, -12};
-  Surface(7) = {8};
-  Curve Loop(10) = {6, 5, -8, -3};
-  Surface(8) = {10};
-  Curve Loop(12) = {9, 10, -11, -8};
-  Surface(9) = {12};
-  Curve Loop(14) = {2, 9, -4, -7};
-  Surface(10) = {14};
-  Line(25) = {239, 229};
-  Line(26) = {229, 238};
-  Line(27) = {243, 235};
-  Line(28) = {235, 242};
-  Line(29) = {237, 244};
-  Line(30) = {233, 240};
-  Line(31) = {237, 245};
-  Line(32) = {241, 233};
-  Curve Loop(16) = {25, 12, 6, -27, -21};
-  Surface(11) = {16};
-  Curve Loop(18) = {20, -31, -11, -5, -27};
-  Surface(12) = {18};
-  Curve Loop(20) = {29, -18, -28, 5, 11};
-  Surface(13) = {20};
-  Curve Loop(22) = {10, 29, -24, -30, 4};
-  Surface(14) = {22};
-  Curve Loop(24) = {30, -14, -26, 1, 7};
-  Surface(15) = {24};
-  Curve Loop(26) = {25, 1, 7, -32, -16};
-  Surface(16) = {26};
-  Curve Loop(28) = {26, 22, -28, -6, -12};
-  Surface(17) = {28};
-  Curve Loop(30) = {31, -23, 32, 4, 10};
-  Surface(18) = {30};
-  Surface Loop(3) = {5, 16, 18, 12, 11, 9, 8, 7, 10};
-  Volume(1) = {3};
-  Surface Loop(2) = {6, 15, 14, 10, 7, 8, 9, 13, 17};
-  Volume(2) = {2};
-EndIf
-
-For k In {7:0:-1}
+  SetFactory("OpenCASCADE");
+  e = 5*nm;
+  E = 10*(period_x+period_x/2);
+  
+  Macro SetPBCs
+    BlochXm() = Surface In BoundingBox{.5*(-period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,(-period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
+    BlochXp() = Surface In BoundingBox{.5*( period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
+    BlochYm() = Surface In BoundingBox{.5*(-period_x-dys)-e,-dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e,-dyc/2+e, PML_top_hh+PML_top+e};
+    BlochYp() = Surface In BoundingBox{.5*(-period_x-dys)-e, dyc/2-e, PML_bot_hh-e,( period_x+dys)/2+e, dyc/2+e, PML_top_hh+PML_top+e};
+    // For k In {1:#BlochXm()-1}
+    //   Printf("BlochXm surf %g",BlochXm(k));
+    // EndFor
+    // For k In {1:#BlochYm()-1}
+    //   Printf("BlochYm surf %g",BlochYm(k));
+    // EndFor
+    // For k In {1:#BlochXp()-1}
+    //   Printf("BlochXp surf %g",BlochXp(k));
+    // EndFor
+    // For k In {1:#BlochYp()-1}
+    //   Printf("BlochYp surf %g",BlochYp(k));
+    // EndFor
+    If (tag_geom==6) // bi-sin : BoundingBox does not catch BSpline Surfaces?
+      BlochXm()+={17,12};
+      BlochXp()+={19,14};
+      BlochYm()+={15,20};
+      BlochYp()+={13,18};
+    EndIf
+    Periodic Surface{BlochXp()} = {BlochXm()} Translate{period_x,        0,        0};
+    Periodic Surface{BlochYp()} = {BlochYm()} Translate{    dys, dyc,        0};
+  Return
+  
   If (tag_geom==6)
-    If (k!=3)
+    // Bi-sinusoidal profile by Spline surface filling
+    // not the most general way to implement a freesurface height=f(x,y) and relies on multiple Coherence calls
+    // several hacks are used, one of them is to do all this at the very begining
+    nsin = 20;
+    For i In {0:nsin}
+        xx1~{i} = -period_x/2+i*period_x/2/(nsin-1);
+        xx2~{i} =             i*period_x/2/(nsin-1);
+    EndFor
+    pp=newp;//pp=pp-1;
+    For i In {0:nsin-1}
+      yy=-period_y/2;
+      Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
+      yy=0;
+      Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
+      yy=period_y/2;
+      Point(newp) = {xx1~{i},yy,rz/4*(Cos(2*Pi*xx1~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx1~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx1~{i}/period_y))+hh_L_3+thick_L_3/2};
+      yy=-period_y/2;
+      Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
+      yy=0;
+      Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
+      yy=period_y/2;
+      Point(newp) = {xx2~{i},yy,rz/4*(Cos(2*Pi*xx2~{i}/period_x)+Cos(2*Pi*yy/period_y))+hh_L_3+thick_L_3/2};
+      Point(newp) = {yy,xx2~{i},rz/4*(Cos(2*Pi*yy/period_x)+Cos(2*Pi*xx2~{i}/period_y))+hh_L_3+thick_L_3/2};
+    EndFor
+    For k In {1:11}
+      BSpline(newl) = {pp+k:pp+12*nsin:12};
+    EndFor
+    BSpline(newl) = {pp  :pp+12*(nsin-1):12};
+    Coherence;
+    Box(1) = {-period_x/2,-period_y/2,     hh_L_3,period_x,period_y, thick_L_3};
+    Delete{Volume{1}; Surface{1,2,3,4} ; Line{13,15,17,19};}
+    Curve Loop(7) = {21, 20, -23, -16};
+    Curve Loop(8) = {1, 2, -3, -12};
+    Surface(7) = {8};
+    Curve Loop(10) = {6, 5, -8, -3};
+    Surface(8) = {10};
+    Curve Loop(12) = {9, 10, -11, -8};
+    Surface(9) = {12};
+    Curve Loop(14) = {2, 9, -4, -7};
+    Surface(10) = {14};
+    Line(25) = {239, 229};
+    Line(26) = {229, 238};
+    Line(27) = {243, 235};
+    Line(28) = {235, 242};
+    Line(29) = {237, 244};
+    Line(30) = {233, 240};
+    Line(31) = {237, 245};
+    Line(32) = {241, 233};
+    Curve Loop(16) = {25, 12, 6, -27, -21};
+    Surface(11) = {16};
+    Curve Loop(18) = {20, -31, -11, -5, -27};
+    Surface(12) = {18};
+    Curve Loop(20) = {29, -18, -28, 5, 11};
+    Surface(13) = {20};
+    Curve Loop(22) = {10, 29, -24, -30, 4};
+    Surface(14) = {22};
+    Curve Loop(24) = {30, -14, -26, 1, 7};
+    Surface(15) = {24};
+    Curve Loop(26) = {25, 1, 7, -32, -16};
+    Surface(16) = {26};
+    Curve Loop(28) = {26, 22, -28, -6, -12};
+    Surface(17) = {28};
+    Curve Loop(30) = {31, -23, 32, 4, 10};
+    Surface(18) = {30};
+    Surface Loop(3) = {5, 16, 18, 12, 11, 9, 8, 7, 10};
+    Volume(1) = {3};
+    Surface Loop(2) = {6, 15, 14, 10, 7, 8, 9, 13, 17};
+    Volume(2) = {2};
+  EndIf
+  
+  For k In {7:0:-1}
+    If (tag_geom==6)
+      If (k!=3)
+        p=newp; l=newl; ll=newll; s=news;
+        Point(p)   = {0.5*(-period_x-dys), -dyc/2, hh_L~{k}};
+        Point(p+1) = {0.5*( period_x-dys), -dyc/2, hh_L~{k}};
+        Point(p+2) = {0.5*( period_x+dys),  dyc/2, hh_L~{k}};
+        Point(p+3) = {0.5*(-period_x+dys),  dyc/2, hh_L~{k}};
+        Line(l)={p,p+1};Line(l+1)={p+1,p+2};Line(l+2)={p+2,p+3};Line(l+3)={p+3,p};
+        Curve Loop(ll) = {l,l+1,l+2,l+3};
+        Surface(s) = {ll};
+        Extrude {0, 0, thick_L~{k}} {Surface{s};}
+      Else
+        v=newv;
+      EndIf
+    Else
       p=newp; l=newl; ll=newll; s=news;
       Point(p)   = {0.5*(-period_x-dys), -dyc/2, hh_L~{k}};
       Point(p+1) = {0.5*( period_x-dys), -dyc/2, hh_L~{k}};
@@ -136,164 +149,166 @@ For k In {7:0:-1}
       Curve Loop(ll) = {l,l+1,l+2,l+3};
       Surface(s) = {ll};
       Extrude {0, 0, thick_L~{k}} {Surface{s};}
-    Else
-      v=newv;
     EndIf
+  EndFor
+  // Box(1) = {-period_x/2,-period_y/2, PML_bot_hh,period_x,period_y, PML_bot  };
+  // Box(2) = {-period_x/2,-period_y/2,     hh_L_6,period_x,period_y, thick_L_6};
+  // Box(3) = {-period_x/2,-period_y/2,     hh_L_5,period_x,period_y, thick_L_5};
+  // Box(4) = {-period_x/2,-period_y/2,     hh_L_4,period_x,period_y, thick_L_4};
+  // If (tag_geom!=6)
+  //   Box(5) = {-period_x/2,-period_y/2,     hh_L_3,period_x,period_y, thick_L_3};
+  // EndIf
+  // Box(6) = {-period_x/2,-period_y/2,     hh_L_2,period_x,period_y, thick_L_2};
+  // Box(7) = {-period_x/2,-period_y/2,     hh_L_1,period_x,period_y, thick_L_1};
+  // Box(8) = {-period_x/2,-period_y/2, PML_top_hh,period_x,period_y, PML_top  };
+  
+  If (tag_geom==1)
+    p=newp;
+    Point(p) = {0,0,hh_L_3+rz};
+    Line(97) = {29, 65};
+    Line(98) = {65, 32};
+    Line(99) = {65, 30};
+    Line(100) = {65, 31};
+    Curve Loop(92) = {97, 99, -43};
+    Plane Surface(91) = {92};
+    Curve Loop(93) = {99, 45, -100};
+    Plane Surface(92) = {93};
+    Curve Loop(94) = {100, 47, -98};
+    Plane Surface(93) = {94};
+    Curve Loop(95) = {97, 98, 48};
+    Plane Surface(94) = {95};
+    Surface Loop(9) = {91, 94, 93, 92, 42};
+    Volume(9) = {9};
+  EndIf
+  
+  If (tag_geom==2)
+    Cylinder(9) = {0,0,hh_L_3,0,0,thick_L_3,rx};
+  EndIf
+  
+  If (tag_geom==3)
+    Lx = 210*nm;
+    Ly = 232*nm;
+    Box(9)  = {-Lx/2   , -Ly/2    , hh_L_3 , Lx, ry, rz};
+    Box(10) = {-Lx/2   ,  Ly/2-ry , hh_L_3 , Lx, ry, rz};
+    Box(11) = {-Lx/2   , -Ly/2    , hh_L_3 , rx, Ly, rz};
+    scat() = BooleanUnion{ Volume{9}; Delete; }{ Volume{10,11}; Delete;} ;
+    r_fillet = 10*nm;
+    fscat() = Abs(Boundary{ Volume{scat()}  ; });
+    escat() = Unique(Abs(Boundary{ Surface{fscat()}; }));
+    // Fillet{scat()}{escat()}{r_fillet}
+  EndIf
+  
+  If (tag_geom==4)
+    Sphere(9) = {0,0,hh_L_3,rx};
+    Dilate { { 0,0,hh_L_3 }, { 1, ry/rx, rz/rx } } { Volume{9}; }
+    BooleanDifference{ Volume{9}; Delete; }{ Volume{4}; }
+  EndIf
+  
+  If (tag_geom==5)
+    Box(9) = {-rx/2,-ry/2, hh_L_2-rz, rx, ry, rz};
+    Rotate {{0, 0, 1}, {0,0,0}, Pi/4} {Volume{9};}
+  EndIf
+  
+  If (tag_geom==7)
+    Box(9) = {-period_x/2,-ry/2, hh_L_3, period_x, ry, rz};
+  EndIf
+  
+  If (tag_geom==8)
+    Cylinder(9) = {0,0,hh_L_3 , 0,0,rz , rx};
+    Dilate { { 0,0,hh_L_3 }, { 1, ry/rx, 1 } } { Volume{9}; }
+  EndIf
+  
+  
+  Coherence;
+  Call SetPBCs;
+  If (tag_geom==6)
+    Physical Volume("PMLBOT"        ,1) = {3};
+    Physical Volume("LAYER_L6_SUBS" ,2) = {4};
+    Physical Volume("LAYER_L5"      ,3) = {5};
+    Physical Volume("LAYER_L4"      ,4) = {6};
+    Physical Volume("LAYER_L3"      ,5) = {2};
+    Physical Volume("LAYER_L2"      ,6) = {7};
+    Physical Volume("LAYER_L1_SUPER",7) = {8};
+    Physical Volume("PMLTOP"        ,8) = {9};
+    Physical Volume("SCAT"          ,9) = {1};
   Else
-    p=newp; l=newl; ll=newll; s=news;
-    Point(p)   = {0.5*(-period_x-dys), -dyc/2, hh_L~{k}};
-    Point(p+1) = {0.5*( period_x-dys), -dyc/2, hh_L~{k}};
-    Point(p+2) = {0.5*( period_x+dys),  dyc/2, hh_L~{k}};
-    Point(p+3) = {0.5*(-period_x+dys),  dyc/2, hh_L~{k}};
-    Line(l)={p,p+1};Line(l+1)={p+1,p+2};Line(l+2)={p+2,p+3};Line(l+3)={p+3,p};
-    Curve Loop(ll) = {l,l+1,l+2,l+3};
-    Surface(s) = {ll};
-    Extrude {0, 0, thick_L~{k}} {Surface{s};}
+    Physical Volume("PMLBOT"        ,1) = {1};
+    Physical Volume("LAYER_L6_SUBS" ,2) = {2};
+    Physical Volume("LAYER_L5"      ,3) = {3};
+    Physical Volume("LAYER_L4"      ,4) = {4};
+    Physical Volume("LAYER_L3"      ,5) = {10};
+    Physical Volume("LAYER_L2"      ,6) = {6};
+    Physical Volume("LAYER_L1_SUPER",7) = {7};
+    Physical Volume("PMLTOP"        ,8) = {8};
+    Physical Volume("SCAT"          ,9) = {9};
   EndIf
-EndFor
-// Box(1) = {-period_x/2,-period_y/2, PML_bot_hh,period_x,period_y, PML_bot  };
-// Box(2) = {-period_x/2,-period_y/2,     hh_L_6,period_x,period_y, thick_L_6};
-// Box(3) = {-period_x/2,-period_y/2,     hh_L_5,period_x,period_y, thick_L_5};
-// Box(4) = {-period_x/2,-period_y/2,     hh_L_4,period_x,period_y, thick_L_4};
-// If (tag_geom!=6)
-//   Box(5) = {-period_x/2,-period_y/2,     hh_L_3,period_x,period_y, thick_L_3};
-// EndIf
-// Box(6) = {-period_x/2,-period_y/2,     hh_L_2,period_x,period_y, thick_L_2};
-// Box(7) = {-period_x/2,-period_y/2,     hh_L_1,period_x,period_y, thick_L_1};
-// Box(8) = {-period_x/2,-period_y/2, PML_top_hh,period_x,period_y, PML_top  };
-
-If (tag_geom==1)
-  p=newp;
-  Point(p) = {0,0,hh_L_3+rz};
-  Line(97) = {29, 65};
-  Line(98) = {65, 32};
-  Line(99) = {65, 30};
-  Line(100) = {65, 31};
-  Curve Loop(92) = {97, 99, -43};
-  Plane Surface(91) = {92};
-  Curve Loop(93) = {99, 45, -100};
-  Plane Surface(92) = {93};
-  Curve Loop(94) = {100, 47, -98};
-  Plane Surface(93) = {94};
-  Curve Loop(95) = {97, 98, 48};
-  Plane Surface(94) = {95};
-  Surface Loop(9) = {91, 94, 93, 92, 42};
-  Volume(9) = {9};
-EndIf
-
-If (tag_geom==2)
-  Cylinder(9) = {0,0,hh_L_3,0,0,thick_L_3,rx};
-EndIf
-
-If (tag_geom==3)
-  Torus(9) = {0,0,hh_L_3+ry-1*nm,rx,ry};
-  Dilate { { 0,0,hh_L_3 }, { 1, 1, rz/ry } } { Volume{9}; }
-  BooleanDifference{ Volume{9}; Delete; }{ Volume{4}; }
-EndIf
-
-If (tag_geom==4)
-  Sphere(9) = {0,0,hh_L_3,rx};
-  Dilate { { 0,0,hh_L_3 }, { 1, ry/rx, rz/rx } } { Volume{9}; }
-  BooleanDifference{ Volume{9}; Delete; }{ Volume{4}; }
-EndIf
-
-If (tag_geom==5)
-  Box(9) = {-rx/2,-ry/2, hh_L_2-rz, rx, ry, rz};
-  Rotate {{0, 0, 1}, {0,0,0}, Pi/4} {Volume{9};}
-EndIf
-
-If (tag_geom==7)
-  Box(9) = {-period_x/2,-ry/2, hh_L_3, period_x, ry, rz};
-EndIf
-
-
-Coherence;
-Call SetPBCs;
-If (tag_geom==6)
-  Physical Volume("PMLBOT"        ,1) = {3};
-  Physical Volume("LAYER_L6_SUBS" ,2) = {4};
-  Physical Volume("LAYER_L5"      ,3) = {5};
-  Physical Volume("LAYER_L4"      ,4) = {6};
-  Physical Volume("LAYER_L3"      ,5) = {2};
-  Physical Volume("LAYER_L2"      ,6) = {7};
-  Physical Volume("LAYER_L1_SUPER",7) = {8};
-  Physical Volume("PMLTOP"        ,8) = {9};
-  Physical Volume("SCAT"          ,9) = {1};
-Else
-  Physical Volume("PMLBOT"        ,1) = {1};
-  Physical Volume("LAYER_L6_SUBS" ,2) = {2};
-  Physical Volume("LAYER_L5"      ,3) = {3};
-  Physical Volume("LAYER_L4"      ,4) = {4};
-  Physical Volume("LAYER_L3"      ,5) = {10};
-  Physical Volume("LAYER_L2"      ,6) = {6};
-  Physical Volume("LAYER_L1_SUPER",7) = {7};
-  Physical Volume("PMLTOP"        ,8) = {8};
-  Physical Volume("SCAT"          ,9) = {9};
-EndIf
-Physical Surface("BXM" ,101 ) = BlochXm();
-Physical Surface("BXP" ,102 ) = BlochXp();
-Physical Surface("BYM" ,201 ) = BlochYm();
-Physical Surface("BYP" ,202 ) = BlochYp();
-Physical Surface("STOP",301 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_top_hh-e,period_x/2+E, period_y/2+E, PML_top_hh+e};
-Physical Surface("SBOT",302 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, hh_L_6-e,period_x/2+E    , period_y/2+E, hh_L_6+e};
-Physical Surface("SPMLTOP",401 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_top_hh+PML_top-e,period_x/2+E, period_y/2+E, PML_top_hh+PML_top+e};
-Physical Surface("SPMLBOT",402 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_bot_hh-e,period_x/2+E, period_y/2+E, PML_bot_hh+e};
-Physical Surface("SVIS",500 )    = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, hh_L_3-e,period_x/2+E    , period_y/2+E, hh_L_3+e};
-
-pts_PMLBOT()   = PointsOf{ Physical Volume{1}; };
-pts_LAYER_L6() = PointsOf{ Physical Volume{2}; };
-pts_LAYER_L5() = PointsOf{ Physical Volume{3}; };
-pts_LAYER_L4() = PointsOf{ Physical Volume{4}; };
-pts_LAYER_L3() = PointsOf{ Physical Volume{5}; };
-pts_LAYER_L2() = PointsOf{ Physical Volume{6}; };
-pts_LAYER_L1() = PointsOf{ Physical Volume{7}; };
-pts_PMLTOP()   = PointsOf{ Physical Volume{8}; };
-pts_ROD()      = PointsOf{ Physical Volume{9}; };
-
-// if test_case==conv, we want to remesh the scatterer as well
-// the following enforces to update lc_scat when paramaille changes
-If (tag_geom==4)
-  lc_scat = lambda_m/(paramaille*5);
-EndIf
-
-lc_PML = lambda_m/(paramaille*.5);
-list_lc(0) = lc_PML;
-For k In {1:6}
-  n_L~{k}  = Sqrt(Abs(eps_re_L~{k}));
-  lc_L~{k} = lambda_m/(paramaille*n_L~{k})/refine_mesh_L~{k};
-  list_lc(7-k) = lc_L~{k};
-EndFor
-list_lc(7) = lc_PML;
-list_lc(8) = lc_scat;
-
-// This helps meshing: The default behavior of the PointsOf technique
-// overides points belonging to several domains (by order of call of Characteristic Length)
-If (tag_geom==7)
-  meshing_sequence() = {1,8,2,3,5,6,7,4,9};
-Else
-    meshing_sequence() = {1,8,2,3,4,6,7,5,9};
-EndIf
-
-// Start with coarsest
-Characteristic Length{:} = lc_PML;
-
-For k In {0:8}
-  which_dom = meshing_sequence(k);
-  Characteristic Length{PointsOf{Physical Volume{which_dom};}} = list_lc(which_dom-1);
-EndFor
-
-
-If (tag_geom==3) // Split torus weird otherwise
-  Mesh.Algorithm = 6;
-EndIf
-// Mesh.SurfaceEdges = 0;
-Mesh.VolumeEdges = 0;
-Mesh.ElementOrder = og;
-If (og==2)
-  Mesh.HighOrderOptimize = 1;
-EndIf
-If (og==1)
-  Mesh.Optimize = 1;
-EndIf
-
-// Solver.SocketName=Sprintf("socktest%g",socketid);
+  Physical Surface("BXM" ,101 ) = BlochXm();
+  Physical Surface("BXP" ,102 ) = BlochXp();
+  Physical Surface("BYM" ,201 ) = BlochYm();
+  Physical Surface("BYP" ,202 ) = BlochYp();
+  Physical Surface("STOP",301 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_top_hh-e,period_x/2+E, period_y/2+E, PML_top_hh+e};
+  Physical Surface("SBOT",302 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, hh_L_6-e,period_x/2+E    , period_y/2+E, hh_L_6+e};
+  Physical Surface("SPMLTOP",401 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_top_hh+PML_top-e,period_x/2+E, period_y/2+E, PML_top_hh+PML_top+e};
+  Physical Surface("SPMLBOT",402 ) = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, PML_bot_hh-e,period_x/2+E, period_y/2+E, PML_bot_hh+e};
+  Physical Surface("SVIS",500 )    = Surface In BoundingBox{-period_x/2-E,-period_y/2-E, hh_L_3-e,period_x/2+E    , period_y/2+E, hh_L_3+e};
+  
+  pts_PMLBOT()   = PointsOf{ Physical Volume{1}; };
+  pts_LAYER_L6() = PointsOf{ Physical Volume{2}; };
+  pts_LAYER_L5() = PointsOf{ Physical Volume{3}; };
+  pts_LAYER_L4() = PointsOf{ Physical Volume{4}; };
+  pts_LAYER_L3() = PointsOf{ Physical Volume{5}; };
+  pts_LAYER_L2() = PointsOf{ Physical Volume{6}; };
+  pts_LAYER_L1() = PointsOf{ Physical Volume{7}; };
+  pts_PMLTOP()   = PointsOf{ Physical Volume{8}; };
+  pts_ROD()      = PointsOf{ Physical Volume{9}; };
+  
+  // if test_case==conv, we want to remesh the scatterer as well
+  // the following enforces to update lc_scat when paramaille changes
+  If (tag_geom==4)
+    lc_scat = lambda_m/(paramaille*5);
+  EndIf
+  
+  lc_PML = lambda_m/(paramaille*.5);
+  list_lc(0) = lc_PML;
+  For k In {1:6}
+    n_L~{k}  = Sqrt(Abs(eps_re_L~{k}));
+    lc_L~{k} = lambda_m/(paramaille*n_L~{k})/refine_mesh_L~{k};
+    list_lc(7-k) = lc_L~{k};
+  EndFor
+  list_lc(7) = lc_PML;
+  list_lc(8) = lc_scat;
+  
+  // This helps meshing: The default behavior of the PointsOf technique
+  // overides points belonging to several domains (by order of call of Characteristic Length)
+  If (tag_geom==7)
+    meshing_sequence() = {1,8,2,3,5,6,7,4,9};
+  Else
+      meshing_sequence() = {1,8,2,3,4,6,7,5,9};
+  EndIf
+  
+  // Start with coarsest
+  Characteristic Length{:} = lc_PML;
+  
+  For k In {0:8}
+    which_dom = meshing_sequence(k);
+    Characteristic Length{PointsOf{Physical Volume{which_dom};}} = list_lc(which_dom-1);
+  EndFor
+  
+  
+  // If (tag_geom==3) // Split U weird otherwise
+    Mesh.Algorithm = 1;
+  // EndIf
+  
+  
+  // Mesh.SurfaceEdges = 0;
+  Mesh.VolumeEdges = 0;
+  Mesh.ElementOrder = og;
+  If (og==2)
+    Mesh.HighOrderOptimize = 1;
+  EndIf
+  If (og==1)
+    Mesh.Optimize = 1;
+  EndIf
+  
+  // Solver.SocketName=Sprintf("socktest%g",socketid);
+  
\ No newline at end of file
diff --git a/DiffractionGratings/grating3D.pro b/DiffractionGratings/grating3D.pro
index 64f8f7001e8e3f603b705a9efae27bee3d1908a3..4bd19e1d18adac76588566a938a58f621a496a42 100644
--- a/DiffractionGratings/grating3D.pro
+++ b/DiffractionGratings/grating3D.pro
@@ -15,529 +15,564 @@
 // You should have received a copy of the GNU General Public License
 // along with This program. If not, see <https://www.gnu.org/licenses/>.
 
-Include "grating3D_data.geo";
-Include "grating3D_materials.pro";
-
-myDir = "res3D/";
-
-Group {
-	// SubDomains
-	PMLbot   = Region[1];
-	L_6_temp = Region[2];
-	L_5      = Region[3];
-	L_4      = Region[4];
-	L_3      = Region[5];
-	L_2      = Region[6];
-	L_1_temp = Region[7];
-	PMLtop   = Region[8];
-	Scat     = Region[9];
-
-	// Boundaries
-	SurfBlochXm    = Region[101];
-	SurfBlochXp    = Region[102];
-	SurfBlochYm    = Region[201];
-	SurfBlochYp    = Region[202];
-  SurfIntTop     = Region[301];
-  SurfIntBot     = Region[302];
-
-
-	SurfDirichlet  = Region[{401,402}];
-  SurfBloch      = Region[{SurfBlochXm,SurfBlochXp,SurfBlochYm,SurfBlochYp}];
-
-  If (FlagLinkFacets==1)
-    SurfExcludeFacets  = Region[{}];
-  Else
-    SurfExcludeFacets  = Region[{SurfBloch}];
-  EndIf
-
-  L_1 = Region[{L_1_temp,SurfIntTop}];
-  L_6 = Region[{L_6_temp,SurfIntBot}];
-
-  Omega          = Region[{PMLbot,L_6,L_5,L_4,L_3,L_2,L_1,PMLtop,Scat}];
-  Omega_nosource = Region[{PMLbot,L_6,L_1,PMLtop}];
-  Omega_source   = Region[{Scat,L_2,L_3,L_4,L_5}];
-  Omega_super    = Region[{Scat,L_1,L_2,L_3,L_4,L_5,PMLtop}];
-  Omega_subs     = Region[{L_6,PMLbot}];
-  Omega_plot     = Region[{L_6,L_5,L_4,L_3,L_2,L_1,Scat}];
-
-  // get normal comp of E field on integ surfaces
-  Gama = Region[{SurfIntBot,SurfIntTop}];
-  Tr   = ElementsOf[Omega_plot, ConnectedTo Gama];
-}
-
-
-
-Function{
-  I[] = Complex[0,1];
-  zhat[] = Vector[0,0,1];
-
-  ispecular  = Nmax;
-  jspecular  = Nmax;
-
-  small_delta = 0.0*nm;
-	mu0         = 4*Pi*1.e2*nm;
-	ep0         = 8.854187817e-3*nm;
-	cel         = 1/Sqrt[ep0 * mu0];
-	om0         = 2*Pi*cel/lambda0;
-	k0          = 2.*Pi/lambda0;
-	Ae          = 1;
-	Pinc        = 0.5*Ae^2*Sqrt[eps_re_L_1*ep0/mu0] * Cos[theta0];
-
-  // permittivities
-  For i In {1:6}
-    If (flag_mat~{i}==0)
-      epsr[L~{i}]  = Complex[eps_re_L~{i} , eps_im_L~{i}] * TensorDiag[1,1,1];
-      If (i==1)
-        epsr1[] = Complex[eps_re_L~{i} , eps_im_L~{i}];
-      EndIf
-      If (i==6)
-        epsr2[] = Complex[eps_re_L~{i} , eps_im_L~{i}];
-      EndIf
+  Include "grating3D_data.geo";
+  Include "grating3D_materials.pro";
+  
+  myDir = "res3D/";
+  
+  Group {
+    // SubDomains
+    PMLbot   = Region[1];
+    L_6 = Region[2];
+    L_5      = Region[3];
+    L_4      = Region[4];
+    L_3      = Region[5];
+    L_2      = Region[6];
+    L_1 = Region[7];
+    PMLtop   = Region[8];
+    Scat     = Region[9];
+  
+    // Boundaries
+    SurfBlochXm    = Region[101];
+    SurfBlochXp    = Region[102];
+    SurfBlochYm    = Region[201];
+    SurfBlochYp    = Region[202];
+    SurfIntTop     = Region[301];
+    SurfIntBot     = Region[302];
+  
+  
+    SurfDirichlet  = Region[{401,402}];
+    SurfBloch      = Region[{SurfBlochXm,SurfBlochXp,SurfBlochYm,SurfBlochYp}];
+  
+    If (FlagLinkFacets==1)
+      SurfExcludeFacets  = Region[{}];
     Else
-      For j In {1:nb_available_materials}
-        If(flag_mat~{i}==j)
-          epsr[L~{i}]  = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]] * TensorDiag[1,1,1];
-          If (i==1)
-            epsr1[] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]];
-          EndIf
-          If (i==6)
-            epsr2[] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]];
-          EndIf
+      SurfExcludeFacets  = Region[{SurfBloch}];
+    EndIf
+  
+    // L_1 = Region[{L_1_temp,SurfIntTop}];
+    // L_6 = Region[{L_6_temp,SurfIntBot}];
+  
+    Omega          = Region[{PMLbot,L_6,L_5,L_4,L_3,L_2,L_1,PMLtop,Scat}];
+    Omega_nosource = Region[{PMLbot,L_6,L_1,PMLtop}];
+    Omega_source   = Region[{Scat,L_2,L_3,L_4,L_5}];
+    Omega_super    = Region[{Scat,L_1,L_2,L_3,L_4,L_5,PMLtop}];
+    Omega_subs     = Region[{L_6,PMLbot}];
+    Omega_plot     = Region[{L_6,L_5,L_4,L_3,L_2,L_1,Scat}];
+  
+    // get normal comp of E field on integ surfaces
+    Gama = Region[{SurfIntBot,SurfIntTop}];
+    Tr   = ElementsOf[Omega_plot, ConnectedTo Gama];
+  }
+  
+  
+  
+  Function{
+    I[] = Complex[0,1];
+    zhat[] = Vector[0,0,1];
+  
+    ispecular  = Nmax;
+    jspecular  = Nmax;
+  
+    small_delta = 0.0*nm;
+    mu0         = 4*Pi*1.e2*nm;
+    ep0         = 8.854187817e-3*nm;
+    cel         = 1/Sqrt[ep0 * mu0];
+    om0         = 2*Pi*cel/lambda0;
+    k0          = 2.*Pi/lambda0;
+    Ae          = 1;
+    Pinc        = 0.5*Ae^2*Sqrt[eps_re_L_1*ep0/mu0] * Cos[theta0];
+  
+    // permittivities
+    For i In {1:6}
+      If (flag_mat~{i}==0)
+        epsr[L~{i}]  = Complex[eps_re_L~{i} , eps_im_L~{i}] * TensorDiag[1,1,1];
+        If (i==1)
+          epsr1[] = Complex[eps_re_L~{i} , eps_im_L~{i}];
         EndIf
+        If (i==6)
+          epsr2[] = Complex[eps_re_L~{i} , eps_im_L~{i}];
+        EndIf
+      Else
+        For j In {1:nb_available_materials}
+          If(flag_mat~{i}==j)
+            epsr[L~{i}]  = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]] * TensorDiag[1,1,1];
+            If (i==1)
+              epsr1[] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]];
+            EndIf
+            If (i==6)
+              epsr2[] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]];
+            EndIf
+          EndIf
+        EndFor
+      EndIf
+    EndFor
+  
+    If (flag_mat_scat==0)
+      epsr[Scat] = Complex[eps_re_Scat , eps_im_Scat] * TensorDiag[1,1,1];
+    Else
+      For j In {flag_mat_scat:flag_mat_scat}
+        epsr[Scat] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]] * TensorDiag[1,1,1];
       EndFor
     EndIf
-  EndFor
-
-  If (flag_mat_scat==0)
-    epsr[Scat] = Complex[eps_re_Scat , eps_im_Scat] * TensorDiag[1,1,1];
-  Else
-    For j In {flag_mat_scat:flag_mat_scat}
-      epsr[Scat] = Complex[epsr_re_interp_mat~{j}[lambda0/nm*1e-9] , epsr_im_interp_mat~{j}[lambda0/nm*1e-9]] * TensorDiag[1,1,1];
+  
+    For i In {1:6}
+      mur[L~{i}]     = TensorDiag[1,1,1];
     EndFor
-  EndIf
-
-	For i In {1:6}
-		mur[L~{i}]   = TensorDiag[1,1,1];
-	EndFor
-	mur[Scat]  = TensorDiag[1,1,1];
-
-  ////// PMLS
-	a_pml           = 1.;
-	b_pml           = 1.;
-  // bermu
-  n1[]     = Sqrt[epsr1[]];
-  n2[]     = Sqrt[epsr2[]];
-  k1norm[] = k0*n1[];
-  k2norm[] = k0*n2[];
-
-  Zmax     = PML_top_hh;
-  Zmin     = hh_L_6;
-  Damp_pml_top[] = 1/(Zmax + PML_top - Fabs[Z[]]) - 1/(PML_top);
-  Damp_pml_bot[] = 1/(Zmin + PML_top - Fabs[Z[]]) - 1/(PML_bot);
-  Sigma_top[] = 0.5*(Damp_pml_top[] + Fabs[Damp_pml_top[]]);
-  Sigma_bot[] = 0.5*(Damp_pml_bot[] + Fabs[Damp_pml_bot[]]);
-
-	If (PML_TYPE==0)
-    sz[]          = Complex[a_pml,b_pml];
-	Else
-    sz[PMLtop] = Complex[1,Damp_pml_top[]/k1norm[]];
-	  sz[PMLbot] = Complex[1,Damp_pml_bot[]/k2norm[]];
-  EndIf
-  sx = 1.;
-	sy = 1.;
-
-	epsr[PMLtop]  = Re[epsr1[]]*TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
-	mur[PMLtop]   =             TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
-  epsr[PMLbot]  = Re[epsr2[]]*TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
-  mur[PMLbot]   =             TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
-
-  // epsr[PMLtop]  = Re[epsr1[]]*TensorDiag[sz_bermutop[]*sy/sx,sx*sz_bermutop[]/sy,sx*sy/sz_bermutop[]];
-	// mur[PMLtop]   =             TensorDiag[sz_bermutop[]*sy/sx,sx*sz_bermutop[]/sy,sx*sy/sz_bermutop[]];
-  // epsr[PMLbot]  = Re[epsr2[]]*TensorDiag[sz_bermubot[]*sy/sx,sx*sz_bermubot[]/sy,sx*sy/sz_bermubot[]];
-  // mur[PMLbot]   =             TensorDiag[sz_bermubot[]*sy/sx,sx*sz_bermubot[]/sy,sx*sy/sz_bermubot[]];
-
-  // epsr[PMLbot] = epsr2[];
-  // mur[PMLbot]  = TensorDiag[1,1,1];
-
-	epsr_annex[PMLbot]       = epsr[];
-	epsr_annex[PMLtop]       = epsr[];
-	epsr_annex[Omega_source] = epsr1[] * TensorDiag[1,1,1];
-	epsr_annex[L_1]          = epsr[];
-	epsr_annex[L_6]          = epsr[];
-
-  //// Reference Field solution of annex problem (simple diopter)
-  k1x[] = -k0*n1[]*Sin[theta0]*Cos[phi0];
-  k1y[] = -k0*n1[]*Sin[theta0]*Sin[phi0];
-  k1z[] = -k0*n1[]*Cos[theta0];
-  k2x[] =  k1x[];
-  k2y[] =  k1y[];
-  k2z[] = -Sqrt[k0^2*epsr2[]-k1x[]^2-k1y[]^2];
-  k1[]  = Vector[k1x[],k1y[], k1z[]];
-  k2[]  = Vector[k2x[],k2y[], k2z[]];
-  k1r[] = Vector[k1x[],k1y[],-k1z[]];
-
-  rs[] = (k1z[]-k2z[])/(k1z[]+k2z[]);
-  ts[] =    2.*k1z[] /(k1z[]+k2z[]);
-  rp[] = (k1z[]*epsr2[]-k2z[]*epsr1[])/(k1z[]*epsr2[]+k2z[]*epsr1[]);
-  tp[] =            (2.*k1z[]*epsr2[])/(k1z[]*epsr2[]+k2z[]*epsr1[]);
-
-  spol[] = Vector[Sin[phi0],-Cos[phi0],0];
-  ppol[] = (k1r[]/Norm[k1r[]]) /\ spol[];
-
-  AmplEis[] =      spol[];
-  AmplErs[] = rs[]*spol[];
-  AmplEts[] = ts[]*spol[];
-  AmplHis[] = Sqrt[ep0*epsr1[]/mu0]     *spol[];
-  AmplHrs[] = Sqrt[ep0*epsr1[]/mu0]*rp[]*spol[];
-  AmplHts[] = Sqrt[ep0*epsr1[]/mu0]*tp[]*spol[];
-
-  Eis[]     = AmplEis[] * Exp[I[]*k1[] *XYZ[]];
-  Ers[]     = AmplErs[] * Exp[I[]*k1r[]*XYZ[]];
-  Ets[]     = AmplEts[] * Exp[I[]*k2[] *XYZ[]];
-  His[]     = AmplHis[] * Exp[I[]*k1[] *XYZ[]];
-  Hrs[]     = AmplHrs[] * Exp[I[]*k1r[]*XYZ[]];
-  Hts[]     = AmplHts[] * Exp[I[]*k2[] *XYZ[]];
-  Eip[]     = -1/(om0*ep0*epsr1[]) * k1[]  /\ His[];
-  Erp[]     = -1/(om0*ep0*epsr1[]) * k1r[] /\ Hrs[];
-  Etp[]     = -1/(om0*ep0*epsr2[]) * k2[]  /\ Hts[];
-
-  Ei[] = Ae*(Cos[psi0]*Eip[]-Sin[psi0]*Eis[]);
-  Er[] = Ae*(Cos[psi0]*Erp[]-Sin[psi0]*Ers[]);
-  Et[] = Ae*(Cos[psi0]*Etp[]-Sin[psi0]*Ets[]);
-  Hi[] =  1/(om0*mu0*mur[]) * k1[]  /\ Ei[];
-  Hr[] =  1/(om0*mu0*mur[]) * k1r[] /\ Er[];
-  Ht[] =  1/(om0*mu0*mur[]) * k2[]  /\ Et[];
-
-  E1[Omega_super]  = Ei[]+Er[];
-  E1[Omega_subs]   = Et[];
-  E1d[Omega_super] = Er[];
-  E1d[Omega_subs]  = Et[];
-  H1[Omega_super]  = Hi[]+Hr[];
-  H1[Omega_subs]   = Ht[];
-  H1d[Omega_super] = Hr[];
-  H1d[Omega_subs]  = Ht[];
-
-  source_vol_scat[] = (om0/cel)^2*(epsr[]-epsr_annex[])*E1[];
-  source_surf_tot[] = -2*I[]*om0*mu0*Vector[0,0,1] /\ Hi[];
-  // Bloch phase shifts
-  skx1[] =  k1x[];
-  // sky1[] = -k0*n1[]*Sin[theta0]*Sin[phi0+xsi];
-  sky1[] = -k0*n1[]*Sin[theta0]*Sin[phi0+xsi];
-
-  dephX[] = Exp[I[]*skx1[]*period_x];
-	dephY[] = Exp[I[]*sky1[]*period_y];
-
-	// Fourier coefficients variables
-  Nb_ordre = 2*Nmax+1;
-  For i In {0:Nb_ordre-1}
-    For j In {0:Nb_ordre-1}
-      alpha~{i}~{j}[] = -k1x[] + 2*Pi/period_x*(i-Nmax);
-      beta~{i}~{j}[]  = -k1y[] + 2*Pi/period_y*(j-Nmax)/Cos[xsi] - 2*Pi/period_x*(i-Nmax)*Tan[xsi];
-      expialphaxy~{i}~{j}[] = Exp[I[]*(alpha~{i}~{j}[]*X[]+beta~{i}~{j}[]*Y[])];
+    mur[Scat]        = TensorDiag[1,1,1];
+    mur[SurfIntTop]  = TensorDiag[1,1,1];
+  
+    ////// PMLS
+    a_pml           = 1.;
+    b_pml           = 1.;
+    // bermu
+    n1[]     = Sqrt[epsr1[]];
+    n2[]     = Sqrt[epsr2[]];
+    k1norm[] = k0*n1[];
+    k2norm[] = k0*n2[];
+  
+    Zmax     = PML_top_hh;
+    Zmin     = hh_L_6;
+    Damp_pml_top[] = 1/(Zmax + PML_top - Fabs[Z[]]) - 1/(PML_top);
+    Damp_pml_bot[] = 1/(Zmin + PML_top - Fabs[Z[]]) - 1/(PML_bot);
+    Sigma_top[] = 0.5*(Damp_pml_top[] + Fabs[Damp_pml_top[]]);
+    Sigma_bot[] = 0.5*(Damp_pml_bot[] + Fabs[Damp_pml_bot[]]);
+  
+    If (PML_TYPE==0)
+      sz[]          = Complex[a_pml,b_pml];
+    Else
+      sz[PMLtop] = Complex[1,Damp_pml_top[]/k1norm[]];
+      sz[PMLbot] = Complex[1,Damp_pml_bot[]/k2norm[]];
+    EndIf
+    sx = 1.;
+    sy = 1.;
+  
+    epsr[PMLtop]  = Re[epsr1[]]*TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
+    mur[PMLtop]   =             TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
+    epsr[PMLbot]  = Re[epsr2[]]*TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
+    mur[PMLbot]   =             TensorDiag[sz[]*sy/sx,sx*sz[]/sy,sx*sy/sz[]];
+  
+    // epsr[PMLtop]  = Re[epsr1[]]*TensorDiag[sz_bermutop[]*sy/sx,sx*sz_bermutop[]/sy,sx*sy/sz_bermutop[]];
+    // mur[PMLtop]   =             TensorDiag[sz_bermutop[]*sy/sx,sx*sz_bermutop[]/sy,sx*sy/sz_bermutop[]];
+    // epsr[PMLbot]  = Re[epsr2[]]*TensorDiag[sz_bermubot[]*sy/sx,sx*sz_bermubot[]/sy,sx*sy/sz_bermubot[]];
+    // mur[PMLbot]   =             TensorDiag[sz_bermubot[]*sy/sx,sx*sz_bermubot[]/sy,sx*sy/sz_bermubot[]];
+  
+    // epsr[PMLbot] = epsr2[];
+    // mur[PMLbot]  = TensorDiag[1,1,1];
+  
+    epsr_annex[PMLbot]       = epsr[];
+    epsr_annex[PMLtop]       = epsr[];
+    epsr_annex[Omega_source] = epsr1[] * TensorDiag[1,1,1];
+    epsr_annex[L_1]          = epsr[];
+    epsr_annex[L_6]          = epsr[];
+  
+    //// Reference Field solution of annex problem (simple diopter)
+    k1x[] = -k0*n1[]*Sin[theta0]*Cos[phi0];
+    k1y[] = -k0*n1[]*Sin[theta0]*Sin[phi0];
+    k1z[] = -k0*n1[]*Cos[theta0];
+    k2x[] =  k1x[];
+    k2y[] =  k1y[];
+    k2z[] = -Sqrt[k0^2*epsr2[]-k1x[]^2-k1y[]^2];
+    k1[]  = Vector[k1x[],k1y[], k1z[]];
+    k2[]  = Vector[k2x[],k2y[], k2z[]];
+    k1r[] = Vector[k1x[],k1y[],-k1z[]];
+  
+    rs[] = (k1z[]-k2z[])/(k1z[]+k2z[]);
+    ts[] =    2.*k1z[] /(k1z[]+k2z[]);
+    rp[] = (k1z[]*epsr2[]-k2z[]*epsr1[])/(k1z[]*epsr2[]+k2z[]*epsr1[]);
+    tp[] =            (2.*k1z[]*epsr2[])/(k1z[]*epsr2[]+k2z[]*epsr1[]);
+  
+    spol[] = Vector[Sin[phi0],-Cos[phi0],0];
+    ppol_r[] = (k1r[]/Norm[k1r[]]) /\ spol[];
+    ppol_t[] = (k2[] /Norm[k2[]] ) /\ spol[];
+  
+    AmplEis[] =      spol[];
+    AmplErs[] = rs[]*spol[];
+    AmplEts[] = ts[]*spol[];
+    AmplHis[] = Sqrt[ep0*epsr1[]/mu0]     *spol[];
+    AmplHrs[] = Sqrt[ep0*epsr1[]/mu0]*rp[]*spol[];
+    AmplHts[] = Sqrt[ep0*epsr1[]/mu0]*tp[]*spol[];
+  
+    Eis[]     = AmplEis[] * Exp[I[]*k1[] *XYZ[]];
+    Ers[]     = AmplErs[] * Exp[I[]*k1r[]*XYZ[]];
+    Ets[]     = AmplEts[] * Exp[I[]*k2[] *XYZ[]];
+    His[]     = AmplHis[] * Exp[I[]*k1[] *XYZ[]];
+    Hrs[]     = AmplHrs[] * Exp[I[]*k1r[]*XYZ[]];
+    Hts[]     = AmplHts[] * Exp[I[]*k2[] *XYZ[]];
+    Eip[]     = -1/(om0*ep0*epsr1[]) * k1[]  /\ His[];
+    Erp[]     = -1/(om0*ep0*epsr1[]) * k1r[] /\ Hrs[];
+    Etp[]     = -1/(om0*ep0*epsr2[]) * k2[]  /\ Hts[];
+  
+    Ei[] = Ae*(Cos[psi0]*Eip[]-Sin[psi0]*Eis[]);
+    Er[] = Ae*(Cos[psi0]*Erp[]-Sin[psi0]*Ers[]);
+    Et[] = Ae*(Cos[psi0]*Etp[]-Sin[psi0]*Ets[]);
+    Hi[] =  1/(om0*mu0*mur[]) * k1[]  /\ Ei[];
+    Hr[] =  1/(om0*mu0*mur[]) * k1r[] /\ Er[];
+    Ht[] =  1/(om0*mu0*mur[]) * k2[]  /\ Et[];
+  
+    E1[SurfIntTop]   = Ei[]+Er[];
+    E1[Omega_super]  = Ei[]+Er[];
+    E1[Omega_subs]   = Et[];
+    E1[SurfIntBot]   = Et[];
+    E1d[SurfIntTop] = Er[];
+    E1d[Omega_super] = Er[];
+    E1d[Omega_subs]  = Et[];
+    E1d[SurfIntBot]  = Et[];
+  
+    H1[Omega_super]  = Hi[]+Hr[];
+    H1[Omega_subs]   = Ht[];
+    H1d[Omega_super] = Hr[];
+    H1d[Omega_subs]  = Ht[];
+  
+    source_vol_scat[] = (om0/cel)^2*(epsr[]-epsr_annex[])*E1[];
+    source_surf_tot[] = -2*I[]*om0*mu0*Vector[0,0,1] /\ Hi[];
+    // Bloch phase shifts
+    skx1[] =  k1x[];
+    // sky1[] = -k0*n1[]*Sin[theta0]*Sin[phi0+xsi];
+    sky1[] = -k0*n1[]*Sin[theta0]*Sin[phi0+xsi];
+  
+    dephX[] = Exp[I[]*skx1[]*period_x];
+    dephY[] = Exp[I[]*sky1[]*period_y];
+  
+    // Fourier coefficients variables
+    Nb_ordre = 2*Nmax+1;
+    For i In {0:Nb_ordre-1}
+      For j In {0:Nb_ordre-1}
+        alpha~{i}~{j}[] = -k1x[] + 2*Pi/period_x*(i-Nmax);
+        beta~{i}~{j}[]  = -k1y[] + 2*Pi/period_y*(j-Nmax)/Cos[xsi] - 2*Pi/period_x*(i-Nmax)*Tan[xsi];
+        expialphaxy~{i}~{j}[] = Exp[I[]*(alpha~{i}~{j}[]*X[]+beta~{i}~{j}[]*Y[])];
+      EndFor
     EndFor
-  EndFor
-  For i In {0:Nb_ordre-1}
-    For j In {0:Nb_ordre-1}
-      gammar~{i}~{j}[] = Sqrt[k0^2*epsr1[] - alpha~{i}~{j}[]^2 - beta~{i}~{j}[]^2];
-      gammat~{i}~{j}[] = Sqrt[k0^2*epsr2[] - alpha~{i}~{j}[]^2 - beta~{i}~{j}[]^2];
+    For i In {0:Nb_ordre-1}
+      For j In {0:Nb_ordre-1}
+        gammar~{i}~{j}[] = Sqrt[k0^2*epsr1[] - alpha~{i}~{j}[]^2 - beta~{i}~{j}[]^2];
+        gammat~{i}~{j}[] = Sqrt[k0^2*epsr2[] - alpha~{i}~{j}[]^2 - beta~{i}~{j}[]^2];
+      EndFor
     EndFor
-  EndFor
-
-}
-
-Constraint {
-  { Name Dirichlet; Type Assign;
-    Case {
-      { Region SurfDirichlet; Value 0.; }
-    }
+  
   }
-  { Name BlochX;
-    Case {
-    { Region SurfBlochXp; Type LinkCplx ; RegionRef SurfBlochXm;
-      Coefficient dephX[]; Function Vector[$X-period_x,$Y,$Z] ; }
+  
+  Constraint {
+    { Name Dirichlet; Type Assign;
+      Case {
+        { Region SurfDirichlet; Value 0.; }
+      }
     }
-  }
-  { Name BlochY;
-    Case {
-      { Region SurfBlochYp; Type LinkCplx ; RegionRef SurfBlochYm;
-      Coefficient dephY[]; Function Vector[$X-dys,$Y-dyc,$Z] ; }
+    { Name BlochX;
+      Case {
+      { Region SurfBlochXp; Type LinkCplx ; RegionRef SurfBlochXm;
+        Coefficient dephX[]; Function Vector[$X-period_x,$Y,$Z] ; }
+      }
     }
-  }
-}
-
-Jacobian {
-  { Name JVol ; Case {{ Region All ; Jacobian Vol ; }}}
-  { Name JSur ; Case {{ Region All ; Jacobian Sur ; }}}
-  { Name JLin ; Case {{ Region All ; Jacobian Lin ; }}}
-}
-
-Integration {
-  { Name I1 ;
-    Case {
-      { Type Gauss ;
-        Case {
-          { GeoElement Point       ; NumberOfPoints   1 ; }
-          { GeoElement Line        ; NumberOfPoints   4 ; }
-          { GeoElement Triangle    ; NumberOfPoints  12 ; }
-          { GeoElement Triangle2   ; NumberOfPoints  12 ; }
-          { GeoElement Tetrahedron ; NumberOfPoints  16 ; }
-          { GeoElement Tetrahedron2; NumberOfPoints  16 ; }
-        }
+    { Name BlochY;
+      Case {
+        { Region SurfBlochYp; Type LinkCplx ; RegionRef SurfBlochYm;
+        Coefficient dephY[]; Function Vector[$X-dys,$Y-dyc,$Z] ; }
       }
     }
   }
-}
-
-FunctionSpace {
-  { Name Hcurl; Type Form1;
-    BasisFunction {
-      { Name sn; NameOfCoef un; Function BF_Edge; Support Region[{Omega}]; Entity EdgesOf[All]; }
-      { Name sn2; NameOfCoef un2; Function BF_Edge_2E;Support Region[{Omega}]; Entity EdgesOf[All]; }
-      If(oi==2)
-        { Name sn3; NameOfCoef un3; Function BF_Edge_3F_b; Support Region[Omega]; Entity FacetsOf[Omega, Not SurfExcludeFacets]; }
-        { Name sn4; NameOfCoef un4; Function BF_Edge_3F_c; Support Region[Omega]; Entity FacetsOf[Omega, Not SurfExcludeFacets]; }
-        { Name sn5; NameOfCoef un5; Function BF_Edge_4E  ; Support Region[Omega]; Entity  EdgesOf[Omega, Not SurfExcludeFacets]; }
-      EndIf
-    }
-    Constraint {
-      { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint BlochX; }
-      { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint BlochY; }
-      { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint Dirichlet; }
-      { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint BlochX; }
-      { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint BlochY; }
-      { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint Dirichlet; }
-      If (FlagLinkFacets==1)
-        { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint BlochX; }
-        { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint BlochY; }
-        { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint BlochX; }
-        { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint BlochY; }
-        { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint BlochX; }
-        { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint BlochY; }
-      EndIf
-      If(oi==2)
-        { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint Dirichlet; }
-        { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint Dirichlet; }
-        { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint Dirichlet; }
-      EndIf
-    }
+  
+  Jacobian {
+    { Name JVol ; Case {{ Region All ; Jacobian Vol ; }}}
+    { Name JSur ; Case {{ Region All ; Jacobian Sur ; }}}
+    { Name JLin ; Case {{ Region All ; Jacobian Lin ; }}}
   }
-  { Name L2_lambda; Type Form0;
-    BasisFunction{
-      { Name ln ; NameOfCoef lambda_n ; Function BF_Node   ; Support Region[Gama]; Entity NodesOf[All];}
-      { Name ln2; NameOfCoef lambda_n2; Function BF_Node_2E; Support Region[Gama]; Entity EdgesOf[All];}
+  
+  Integration {
+    { Name I1 ;
+      Case {
+        { Type Gauss ;
+          Case {
+            { GeoElement Point       ; NumberOfPoints   1 ; }
+            { GeoElement Line        ; NumberOfPoints   4 ; }
+            { GeoElement Triangle    ; NumberOfPoints  12 ; }
+            { GeoElement Triangle2   ; NumberOfPoints  12 ; }
+            { GeoElement Tetrahedron ; NumberOfPoints  16 ; }
+            { GeoElement Tetrahedron2; NumberOfPoints  16 ; }
+          }
+        }
+      }
     }
   }
-}
-
-Formulation {
-  { Name helmholtz_vector; Type FemEquation;
-    Quantity {
-      { Name u  ; Type Local; NameOfSpace Hcurl; }
-      { Name uz ; Type Local; NameOfSpace L2_lambda; }
+  
+  FunctionSpace {
+    { Name Hcurl; Type Form1;
+      BasisFunction {
+        { Name sn; NameOfCoef un; Function BF_Edge; Support Region[{Omega,Gama}]; Entity EdgesOf[All]; }
+        { Name sn2; NameOfCoef un2; Function BF_Edge_2E;Support Region[{Omega,Gama}]; Entity EdgesOf[All]; }
+        If(oi==2)
+          { Name sn3; NameOfCoef un3; Function BF_Edge_3F_b; Support Region[{Omega,Gama}]; Entity FacetsOf[Omega, Not SurfExcludeFacets]; }
+          { Name sn4; NameOfCoef un4; Function BF_Edge_3F_c; Support Region[{Omega,Gama}]; Entity FacetsOf[Omega, Not SurfExcludeFacets]; }
+          { Name sn5; NameOfCoef un5; Function BF_Edge_4E  ; Support Region[{Omega,Gama}]; Entity  EdgesOf[Omega, Not SurfExcludeFacets]; }
+        EndIf
+      }
+      Constraint {
+        { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint BlochX; }
+        { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint BlochY; }
+        { NameOfCoef un;  EntityType EdgesOf ; NameOfConstraint Dirichlet; }
+        { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint BlochX; }
+        { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint BlochY; }
+        { NameOfCoef un2; EntityType EdgesOf ; NameOfConstraint Dirichlet; }
+        If (FlagLinkFacets==1)
+          { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint BlochX; }
+          { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint BlochY; }
+          { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint BlochX; }
+          { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint BlochY; }
+          { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint BlochX; }
+          { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint BlochY; }
+        EndIf
+        If(oi==2)
+          { NameOfCoef un3; EntityType FacetsOf ; NameOfConstraint Dirichlet; }
+          { NameOfCoef un4; EntityType FacetsOf ; NameOfConstraint Dirichlet; }
+          { NameOfCoef un5; EntityType EdgesOf  ; NameOfConstraint Dirichlet; }
+        EndIf
+      }
     }
-		Equation{
-      Galerkin { [-1/mur[]    * Dof{Curl u} , {Curl u}]; In Omega       ; Jacobian JVol; Integration I1; }
-      Galerkin { [k0^2*epsr[] * Dof{u}      ,      {u}]; In Omega       ; Jacobian JVol; Integration I1; }
-      If (FLAG_TOTAL==0)
-        Galerkin { [source_vol_scat[] ,      {u}]; In Omega_source; Jacobian JVol; Integration I1; }
-      Else
-        Galerkin { [source_surf_tot[] ,      {u}]; In SurfIntTop; Jacobian JVol; Integration I1; }
-      EndIf
-      Galerkin{ [                         Dof{uz}  , {uz}]; In Gama; Jacobian JSur; Integration I1;}
-      Galerkin{ [ Trace[Dof{u}, Tr]*Vector[0,0,-1] , {uz}]; In Gama; Jacobian JSur; Integration I1;}
+    { Name L2_lambda; Type Form0;
+      BasisFunction{
+        { Name ln ; NameOfCoef lambda_n ; Function BF_Node   ; Support Region[Gama]; Entity NodesOf[All];}
+        { Name ln2; NameOfCoef lambda_n2; Function BF_Node_2E; Support Region[Gama]; Entity EdgesOf[All];}
+      }
     }
   }
-}
-
-Resolution {
-  { Name helmholtz_vector;
-    System {
-      { Name M; NameOfFormulation helmholtz_vector; Type ComplexValue; }
+  
+  Formulation {
+    { Name helmholtz_vector; Type FemEquation;
+      Quantity {
+        { Name u  ; Type Local; NameOfSpace Hcurl; }
+        { Name uz ; Type Local; NameOfSpace L2_lambda; }
+      }
+      Equation{
+        Galerkin { [-1/mur[]    * Dof{Curl u} , {Curl u}]; In Omega       ; Jacobian JVol; Integration I1; }
+        Galerkin { [k0^2*epsr[] * Dof{u}      ,      {u}]; In Omega       ; Jacobian JVol; Integration I1; }
+        If (FLAG_TOTAL==0)
+          Galerkin { [source_vol_scat[] ,      {u}]; In Omega_source; Jacobian JVol; Integration I1; }
+        Else
+          Galerkin { [source_surf_tot[] ,      {u}]; In SurfIntTop; Jacobian JVol; Integration I1; }
+        EndIf
+        Galerkin{ [                         Dof{uz}  , {uz}]; In Gama; Jacobian JSur; Integration I1;}
+        Galerkin{ [ Trace[Dof{u}, Tr]*Vector[0,0,-1] , {uz}]; In Gama; Jacobian JSur; Integration I1;}
+      }
     }
-    Operation {
-      CreateDir[Str[myDir]];
-      Generate[M];
-      Solve[M]; //SaveSolution[M];
+  }
+  
+  Resolution {
+    { Name helmholtz_vector;
+      System {
+        { Name M; NameOfFormulation helmholtz_vector; Type ComplexValue; }
+      }
+      Operation {
+        CreateDir[Str[myDir]];
+        Generate[M];
+        Solve[M]; //SaveSolution[M];
+      }
     }
   }
-}
-
-PostProcessing {
-  { Name postpro_helmholtz_vector; NameOfFormulation helmholtz_vector; NameOfSystem M;
-    Quantity {
-      { Name u      ; Value { Local { [ {u}       ]; In Omega; Jacobian JVol; } } }
-      { Name uz     ; Value { Local { [ {uz}       ]; In Gama; Jacobian JSur; } } }
-      { Name Damp_pml_top; Value { Local { [Damp_pml_top[]  ]; In Omega; Jacobian JVol; } } }
-      { Name epsr_xx; Value { Local { [  CompXX[epsr[]] ]; In Omega; Jacobian JVol; } } }
-      { Name Poy_inc; Value { Local { [ 0.5*Re[Cross[    Ei[] , Conj[Hi[]]]] ]; In Omega; Jacobian JVol; } } }
-      { Name E1     ; Value { Local { [     E1[]  ]; In Omega; Jacobian JVol; } } }
-      { Name lambda_step   ; Value { Local { [ lambda0/nm ]; In Omega ; Jacobian JVol; } } }
-      
-      If (FLAG_TOTAL==0)
-        { Name Etot   ; Value { Local { [ {u}+E1[]  ]; In Omega; Jacobian JVol; } } }
-        { Name Htot   ; Value { Local { [ H1[]-I[]/(mur[]*mu0*om0)*{Curl u}]; In Omega; Jacobian JVol; } } }
-        { Name Poy_tot; Value { Local { [ 0.5*Re[Cross[{u}+E1[] , Conj[ H1[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
-        { Name Poy_ref; Value { Local { [ 0.5*Re[Cross[{u}+E1d[], Conj[H1d[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
-        For k In {2:6}
-          { Name Abs_L~{k} ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}+E1[]]) / (Pinc*period_x*dyc) ] ; In L~{k} ; Integration I1 ; Jacobian JVol ; } } }
-        EndFor
-        { Name Abs_scat ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}+E1[]]) / (Pinc*period_x*dyc) ] ; In Scat ; Integration I1 ; Jacobian JVol ; } } }
-      Else
-        { Name Etot   ; Value { Local { [ {u}  ]; In Omega; Jacobian JVol; } } }
-        { Name Htot   ; Value { Local { [ -I[]/(mur[]*mu0*om0)*{Curl u}]; In Omega; Jacobian JVol; } } }
-        { Name Poy_tot; Value { Local { [ 0.5*Re[Cross[{u} , Conj[ -I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
-        { Name Poy_ref; Value { Local { [ 0.5*Re[Cross[{u}-Ei[], Conj[-Hi[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
-        For k In {2:6}
-          { Name Abs_L~{k} ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}]) / (Pinc*period_x*dyc) ] ; In L~{k} ; Integration I1 ; Jacobian JVol ; } } }
-        EndFor
-        { Name Abs_scat ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}]) / (Pinc*period_x*dyc) ] ; In Scat ; Integration I1 ; Jacobian JVol ; } } }
-      EndIf
-
-      For i In {0:Nb_ordre-1}
-        For j In {0:Nb_ordre-1}
-          If (FLAG_TOTAL==0)
-            { Name int_x_t~{i}~{j} ; Value { Integral { [   CompX[{u}+E1[] ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_y_t~{i}~{j} ; Value { Integral { [   CompY[{u}+E1[] ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_z_t~{i}~{j} ; Value { Integral { [ ({uz}+CompZ[E1[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_x_r~{i}~{j} ; Value { Integral { [   CompX[{u}+E1d[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_y_r~{i}~{j} ; Value { Integral { [   CompY[{u}+E1d[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_z_r~{i}~{j} ; Value { Integral { [({uz}+CompZ[E1d[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+  
+  PostProcessing {
+    { Name postpro_helmholtz_vector; NameOfFormulation helmholtz_vector; NameOfSystem M;
+      Quantity {
+        { Name u      ; Value { Local { [ {u}        ]; In Omega; Jacobian JVol; } } }
+        { Name CompZu ; Value { Local { [ CompZ[{u}] ]; In Omega; Jacobian JVol; } } }
+        { Name uz     ; Value { Local { [ {uz}       ]; In Gama; Jacobian JSur; } } }
+        { Name Damp_pml_top; Value { Local { [Damp_pml_top[]  ]; In Omega; Jacobian JVol; } } }
+        { Name epsr_xx; Value { Local { [  CompXX[epsr[]] ]; In Omega; Jacobian JVol; } } }
+        { Name Poy_inc; Value { Local { [ 0.5*Re[Cross[    Ei[] , Conj[Hi[]]]] ]; In Omega; Jacobian JVol; } } }
+        { Name E1     ; Value { Local { [     E1[]  ]; In Omega; Jacobian JVol; } } }
+        { Name lambda_step   ; Value { Local { [ lambda0/nm ]; In Omega ; Jacobian JVol; } } }
+        
+        If (FLAG_TOTAL==0)
+          { Name Etot   ; Value { Local { [ {u}+E1[]  ]; In Omega; Jacobian JVol; } } }
+          { Name Htot   ; Value { Local { [ H1[]-I[]/(mur[]*mu0*om0)*{Curl u}]; In Omega; Jacobian JVol; } } }
+          { Name Poy_tot; Value { Local { [ 0.5*Re[Cross[{u}+E1[] , Conj[ H1[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
+          { Name Poy_ref; Value { Local { [ 0.5*Re[Cross[{u}+E1d[], Conj[H1d[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
+          For k In {2:6}
+            { Name Abs_L~{k} ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}+E1[]]) / (Pinc*period_x*dyc) ] ; In L~{k} ; Integration I1 ; Jacobian JVol ; } } }
+          EndFor
+          { Name Abs_scat ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}+E1[]]) / (Pinc*period_x*dyc) ] ; In Scat ; Integration I1 ; Jacobian JVol ; } } }
+        Else
+          { Name Etot   ; Value { Local { [ {u}  ]; In Omega; Jacobian JVol; } } }
+          { Name Htot   ; Value { Local { [ -I[]/(mur[]*mu0*om0)*{Curl u}]; In Omega; Jacobian JVol; } } }
+          { Name Poy_tot; Value { Local { [ 0.5*Re[Cross[{u} , Conj[ -I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
+          { Name Poy_ref; Value { Local { [ 0.5*Re[Cross[{u}-Ei[], Conj[-Hi[]-I[]/(mur[]*mu0*om0)*{Curl u}]]] ]; In Omega; Jacobian JVol; } } }
+          For k In {2:6}
+            { Name Abs_L~{k} ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}]) / (Pinc*period_x*dyc) ] ; In L~{k} ; Integration I1 ; Jacobian JVol ; } } }
+          EndFor
+          { Name Abs_scat ; Value { Integral { [ ep0*om0 * 0.5*Im[CompXX[epsr[]]]*(SquNorm[{u}]) / (Pinc*period_x*dyc) ] ; In Scat ; Integration I1 ; Jacobian JVol ; } } }
+        EndIf
+  
+        For i In {0:Nb_ordre-1}
+          For j In {0:Nb_ordre-1}
+            If (FLAG_TOTAL==0)
+              { Name int_x_t~{i}~{j} ; Value { Integral { [   CompX[{u}+E1[] ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_y_t~{i}~{j} ; Value { Integral { [   CompY[{u}+E1[] ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_z_t~{i}~{j} ; Value { Integral { [ ({uz}+CompZ[E1[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_x_r~{i}~{j} ; Value { Integral { [   CompX[{u}+E1d[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_y_r~{i}~{j} ; Value { Integral { [   CompY[{u}+E1d[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_z_r~{i}~{j} ; Value { Integral { [({uz}+CompZ[E1d[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
             Else
-            { Name int_x_t~{i}~{j} ; Value { Integral { [   CompX[{u}     ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_y_t~{i}~{j} ; Value { Integral { [   CompY[{u}     ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_z_t~{i}~{j} ; Value { Integral { [         {uz}     *expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_x_r~{i}~{j} ; Value { Integral { [   CompX[{u}-Ei[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_y_r~{i}~{j} ; Value { Integral { [   CompY[{u}-Ei[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
-            { Name int_z_r~{i}~{j} ; Value { Integral { [({uz}-CompZ[Ei[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
-          EndIf
-            { Name eff_t1~{i}~{j}   ; Value { Term{ Type Global; [
-                  1/(gammat~{i}~{j}[]*-k1z[]*Cos[xsi]^2) * ((gammat~{i}~{j}[]^2+alpha~{i}~{j}[]^2)*SquNorm[$int_x_t~{i}~{j}]+
-                                                            (gammat~{i}~{j}[]^2+ beta~{j}~{j}[]^2)*SquNorm[$int_y_t~{i}~{j}]+
-                                                              2*alpha~{i}~{j}[]*beta~{i}~{j}[]*Re[$int_x_t~{i}~{j}*Conj[$int_y_t~{i}~{j}]] ) ] ; In SurfIntBot ; } } }
-            { Name eff_r1~{i}~{j}   ; Value { Term{ Type Global; [
-                  1/(gammar~{i}~{j}[]*-k1z[]*Cos[xsi]^2) * ((gammar~{i}~{j}[]^2+alpha~{i}~{j}[]^2)*SquNorm[$int_x_r~{i}~{j}]+
-                                                            (gammar~{i}~{j}[]^2+ beta~{i}~{j}[]^2)*SquNorm[$int_y_r~{i}~{j}]+
-                                                              2*alpha~{i}~{j}[]*beta~{i}~{j}[]*Re[$int_x_r~{i}~{j}*Conj[$int_y_r~{i}~{j}]]) ] ; In SurfIntTop ; } } }
-            { Name eff_t2~{i}~{j}   ; Value { Term{ Type Global; [
-              gammat~{i}~{j}[]/(-k1z[]*Cos[xsi]^2) * ( SquNorm[$int_x_t~{i}~{j}]+
-                                                       SquNorm[$int_y_t~{i}~{j}]+
-                                                       SquNorm[$int_z_t~{i}~{j}] ) ] ; In SurfIntBot ; } } }
-            { Name eff_r2~{i}~{j}   ; Value { Term{ Type Global; [
-              gammar~{i}~{j}[]/(-k1z[]*Cos[xsi]^2) * ( SquNorm[$int_x_r~{i}~{j}]+
-                                                       SquNorm[$int_y_r~{i}~{j}]+
-                                                       SquNorm[$int_z_r~{i}~{j}] ) ] ; In SurfIntTop ; } } }
-            { Name numbering_ij~{i}~{j}   ; Value { Term{ Type Global; [Vector[i-Nmax,j-Nmax,0]] ; In SurfIntBot ; } } }
+              { Name int_x_t~{i}~{j} ; Value { Integral { [   CompX[{u}     ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_y_t~{i}~{j} ; Value { Integral { [   CompY[{u}     ]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_z_t~{i}~{j} ; Value { Integral { [         {uz}     *expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntBot ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_x_r~{i}~{j} ; Value { Integral { [   CompX[{u}-Ei[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_y_r~{i}~{j} ; Value { Integral { [   CompY[{u}-Ei[]]*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+              { Name int_z_r~{i}~{j} ; Value { Integral { [({uz}-CompZ[Ei[]])*expialphaxy~{i}~{j}[]/(period_x*period_y) ] ; In SurfIntTop ; Integration I1 ; Jacobian JSur ; } } }
+            EndIf
+              { Name eff_t1~{i}~{j}   ; Value { Term{ Type Global; [
+                    1/(gammat~{i}~{j}[]*-k1z[]*Cos[xsi]^2) * ((gammat~{i}~{j}[]^2+alpha~{i}~{j}[]^2)*SquNorm[$int_x_t~{i}~{j}]+
+                                                              (gammat~{i}~{j}[]^2+ beta~{j}~{j}[]^2)*SquNorm[$int_y_t~{i}~{j}]+
+                                                                2*alpha~{i}~{j}[]*beta~{i}~{j}[]*Re[$int_x_t~{i}~{j}*Conj[$int_y_t~{i}~{j}]] ) ] ; In SurfIntBot ; } } }
+              { Name eff_r1~{i}~{j}   ; Value { Term{ Type Global; [
+                    1/(gammar~{i}~{j}[]*-k1z[]*Cos[xsi]^2) * ((gammar~{i}~{j}[]^2+alpha~{i}~{j}[]^2)*SquNorm[$int_x_r~{i}~{j}]+
+                                                              (gammar~{i}~{j}[]^2+ beta~{i}~{j}[]^2)*SquNorm[$int_y_r~{i}~{j}]+
+                                                                2*alpha~{i}~{j}[]*beta~{i}~{j}[]*Re[$int_x_r~{i}~{j}*Conj[$int_y_r~{i}~{j}]]) ] ; In SurfIntTop ; } } }
+              { Name eff_t2~{i}~{j}   ; Value { Term{ Type Global; [
+                gammat~{i}~{j}[]/(-k1z[]*Cos[xsi]^2) * ( SquNorm[$int_x_t~{i}~{j}]+
+                                                         SquNorm[$int_y_t~{i}~{j}]+
+                                                         SquNorm[$int_z_t~{i}~{j}] ) ] ; In SurfIntBot ; } } }
+              { Name eff_r2~{i}~{j}   ; Value { Term{ Type Global; [
+                gammar~{i}~{j}[]/(-k1z[]*Cos[xsi]^2) * ( SquNorm[$int_x_r~{i}~{j}]+
+                                                         SquNorm[$int_y_r~{i}~{j}]+
+                                                         SquNorm[$int_z_r~{i}~{j}] ) ] ; In SurfIntTop ; } } }
+              { Name numbering_ij~{i}~{j}   ; Value { Term{ Type Global; [Vector[i-Nmax,j-Nmax,0]] ; In SurfIntBot ; } } }
+          EndFor
         EndFor
-      EndFor
-      // Mmatrix computation : Retrieve the complex vector amplitude of the plane wave corresponding to the reflected specular order
-      // it is phase shifted by Exp[I[]*k1z[]*(thick_L_1+thick_L_2+thick_L_3)] because we measure it on SurfIntTop
-      // but it is better to have it at the surface on which the scatterer is relying (so that if there is no scatterer,
-      // it just corresponds to the usual definition of rs/rp for a simple diopter).
-      { Name er_specular ; Value { Term{ Type Global; [ 
-        Exp[I[]*k1z[]*(thick_L_1+thick_L_2+thick_L_3)] * 
-        Vector[$int_x_r~{ispecular}~{jspecular},
-               $int_y_r~{ispecular}~{jspecular},
-               $int_z_r~{ispecular}~{jspecular}] ] ; In SurfIntTop ; } } }
-      // Project er_specular on the (s,p) basis
-      { Name rp ; Value { Term{ Type Global; [ ppol[] * $er_specular]   ; In SurfIntTop ; } } }
-      { Name rs ; Value { Term{ Type Global; [ spol[] * $er_specular]   ; In SurfIntTop ; } } }
-}
+        // Mmatrix computation : Retrieve the complex vector amplitude of the plane wave corresponding to the reflected specular order
+        // it is phase shifted by Exp[I[]*k1z[]*(thick_L_1+thick_L_2+thick_L_3)] because we measure it on SurfIntTop...
+        // Is it better to compute it at the surface on which the scatterer is relying? (so that if there is no scatterer,
+        // it just corresponds to the usual definition of rs/rp for a simple diopter). Maybe... uncomment phasor if necessary.
+        // For the Mmatrix, we do not care about the phase.
+        { Name er_specular ; Value { Term{ Type Global; [ 
+          // Exp[I[]*k1z[]*(thick_L_1+thick_L_2+thick_L_3)] * 
+          Vector[$int_x_r~{ispecular}~{jspecular},
+                 $int_y_r~{ispecular}~{jspecular},
+                 $int_z_r~{ispecular}~{jspecular}] ] ; In SurfIntTop ; } } }
+        { Name et_specular ; Value { Term{Type Global; [ 
+          Vector[$int_x_t~{ispecular}~{jspecular},
+                 $int_y_t~{ispecular}~{jspecular},
+                 $int_z_t~{ispecular}~{jspecular}] ] ; In SurfIntBot ; } } }
+      
+        // Project er_specular on the (s,p) basis
+        { Name rp ; Value { Term{ Type Global; [ ppol_r[] * $er_specular]   ; In SurfIntTop ; } } }
+        { Name rs ; Value { Term{ Type Global; [ spol[]   * $er_specular]   ; In SurfIntTop ; } } }
+        { Name tp ; Value { Term{ Type Global; [ ppol_t[] * $et_specular]   ; In SurfIntBot ; } } }
+        { Name ts ; Value { Term{ Type Global; [ spol[]   * $et_specular]   ; In SurfIntBot ; } } }
+  
   }
-}
-
-PostOperation {
-  { Name postop_helmholtz_vector; NameOfPostProcessing postpro_helmholtz_vector ;
-    Operation {
-      If (FlagOutEscaFull==1)
-        If (Flag_interp_cubic==1)
-          Print [ u , OnBox { {-period_x/2,-period_y/2,hh_L_6-PML_bot} {period_x/2,-period_y/2,hh_L_6-PML_bot} {-period_x/2,period_y/2,hh_L_6-PML_bot} {-period_x/2,-period_y/2,hh_L_1+thick_L_1+PML_top} } {npts_interpX,npts_interpY,npts_interpZSca} , File StrCat[myDir,"u_grid.pos"], Name "u_grid"];
-        Else
-          Print [ u , OnElementsOf Omega, File StrCat[myDir,"Etot.pos"]];
+    }
+  }
+  
+  PostOperation {
+    { Name postop_helmholtz_vector; NameOfPostProcessing postpro_helmholtz_vector ;
+      Operation {
+        // // Normal component of the unknown via Trace projection on L2 / extracted via OnPlane
+        // Print [ uz    , OnElementsOf SurfIntTop, File StrCat[myDir,"uz_ZP.pos"]];
+        // Print [ uz    , OnElementsOf SurfIntBot, File StrCat[myDir,"uz_ZM.pos"]];
+        // Print [ CompZu , OnPlane { {-period_x/2,-period_y/2,hh_L_6+0.5*nm} { period_x/2,-period_y/2,hh_L_6+0.5*nm} {-period_x/2, period_y/2,hh_L_6+0.5*nm} } {npts_interpX,npts_interpY} , File StrCat[myDir,"u_cut_ZM.pos"]];
+        // Print [ CompZu , OnPlane { {-period_x/2,-period_y/2,hh_L_1+thick_L_1-0.5*nm} { period_x/2,-period_y/2,hh_L_1+thick_L_1-0.5*nm} {-period_x/2, period_y/2,hh_L_1+thick_L_1-0.5*nm} } {npts_interpX,npts_interpY} , File StrCat[myDir,"u_cut_ZP.pos"]];
+        // // Debug : print opto-geometric parameters 
+        // Print [ epsr_xx    , OnElementsOf Omega, File StrCat[myDir,"epsr_xx.pos"]];
+        // // Debug : print raw u and Etot
+        // Print [ u    , OnElementsOf Omega, File StrCat[myDir,"Edif.pos"]];
+        // Print [ Etot , OnElementsOf Omega, File StrCat[myDir,"Etot.pos"]];
+  
+  
+        If (FlagOutEscaFull==1)
+          If (Flag_interp_cubic==1)
+            Print [ u , OnBox { {-period_x/2,-period_y/2,hh_L_6-PML_bot} {period_x/2,-period_y/2,hh_L_6-PML_bot} {-period_x/2,period_y/2,hh_L_6-PML_bot} {-period_x/2,-period_y/2,hh_L_1+thick_L_1+PML_top} } {npts_interpX,npts_interpY,npts_interpZSca} , File StrCat[myDir,"u_grid.pos"], Name "u_grid"];
+          Else
+            Print [ u , OnElementsOf Omega, File StrCat[myDir,"Etot.pos"]];
+          EndIf
         EndIf
-      EndIf
-      If (FlagOutEtotFull==1)
-        If (Flag_interp_cubic==1)
-          Print [ Etot , OnBox { {-period_x/2,-period_y/2,hh_L_6} {period_x/2,-period_y/2,hh_L_6} {-period_x/2,period_y/2,hh_L_6} {-period_x/2,-period_y/2,hh_L_1+thick_L_1} } {npts_interpX,npts_interpY,npts_interpZTot} , File StrCat[myDir,"Etot_grid.pos"], Name "Etot_grid"];
-        Else
-          Print [ Etot , OnElementsOf Omega_plot, File StrCat[myDir,"Etot.pos"]];
+        If (FlagOutEtotFull==1)
+          If (Flag_interp_cubic==1)
+            Print [ Etot , OnBox { {-period_x/2,-period_y/2,hh_L_6} {period_x/2,-period_y/2,hh_L_6} {-period_x/2,period_y/2,hh_L_6} {-period_x/2,-period_y/2,hh_L_1+thick_L_1} } {npts_interpX,npts_interpY,npts_interpZTot} , File StrCat[myDir,"Etot_grid.pos"], Name "Etot_grid"];
+          Else
+            Print [ Etot , OnElementsOf Omega_plot, File StrCat[myDir,"Etot.pos"]];
+          EndIf
         EndIf
-      EndIf
-      If (FlagOutPoyFull==1)
-        If (Flag_interp_cubic==1)
-          Print [ Poy_tot , OnBox { {-period_x/2,-period_y/2,hh_L_6} {period_x/2,-period_y/2,hh_L_6} {-period_x/2,period_y/2,hh_L_6} {-period_x/2,-period_y/2,hh_L_1+thick_L_1} } {npts_interpX,npts_interpY,npts_interpZTot} , File StrCat[myDir,"Poy_tot_grid.pos"], Name "Poy_tot_grid"];
-        Else
-          Print [ Poy_tot , OnElementsOf Omega_plot, File StrCat[myDir,"Poy_tot.pos"]];
+        If (FlagOutPoyFull==1)
+          If (Flag_interp_cubic==1)
+            Print [ Poy_tot , OnBox { {-period_x/2,-period_y/2,hh_L_6} {period_x/2,-period_y/2,hh_L_6} {-period_x/2,period_y/2,hh_L_6} {-period_x/2,-period_y/2,hh_L_1+thick_L_1} } {npts_interpX,npts_interpY,npts_interpZTot} , File StrCat[myDir,"Poy_tot_grid.pos"], Name "Poy_tot_grid"];
+          Else
+            Print [ Poy_tot , OnElementsOf Omega_plot, File StrCat[myDir,"Poy_tot.pos"]];
+          EndIf
         EndIf
-      EndIf
-      If (FlagOutEscaCuts==1)
-        Print [ u , OnPlane { {-period_x/2,0,hh_L_6-PML_bot} {period_x/2,0,hh_L_6-PML_bot} {-period_x/2,0,hh_L_1+thick_L_1+PML_top} } {npts_interpX,npts_interpZSca} , File StrCat[myDir,"u_cut_Y=0.pos"], Name "u_cut_Y=0"];
-        Print [ u , OnPlane { {0,-period_y/2,hh_L_6-PML_bot} {0,period_y/2,hh_L_6-PML_bot} {0,-period_y/2,hh_L_1+thick_L_1+PML_top} } {npts_interpY,npts_interpZSca} , File StrCat[myDir,"u_cut_X=0.pos"], Name "u_cut_X=0"];
-      EndIf
-      If (FlagOutEtotCuts==1)
-        Print [ Etot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Etot_cut_Y=0.pos"], Name "Etot_cut_Y=0"];
-        Print [ Etot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Etot_cut_X=0.pos"], Name "Etot_cut_X=0"];
-      EndIf
-      If (FlagOutHtotCuts==1)
-        Print [ Htot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Htot_cut_Y=0.pos"], Name "Htot_cut_Y=0"];
-        Print [ Htot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Htot_cut_X=0.pos"], Name "Htot_cut_X=0"];
-      EndIf
-      If (FlagOutPoyCut==1)
-        Print [ Poy_tot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Poy_tot_cut_Y=0.pos"], Name "Poy_tot_cut_Y=0"];
-        Print [ Poy_tot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Poy_tot_cut_X=0.pos"], Name "Poy_tot_cut_X=0"];
-      EndIf
-
-      Print [ Poy_tot , OnPlane { {0.5*(-period_x-dys), -dyc/2,(hh_L_6+hh_L_5)/2}
-                                  {0.5*( period_x-dys), -dyc/2,(hh_L_6+hh_L_5)/2}
-                                  {0.5*(-period_x+dys),  dyc/2,(hh_L_6+hh_L_5)/2} }
-                                  {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_tot_gd.pos"], Format Table];
-      Print [ Poy_ref , OnPlane { {0.5*(-period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
-                                  {0.5*( period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
-                                  {0.5*(-period_x+dys),  dyc/2, hh_L_1+thick_L_1/2} }
-                                  {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_ref_gd.pos"], Format Table];
-      Print [ Poy_inc , OnPlane { {0.5*(-period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
-                                  {0.5*( period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
-                                  {0.5*(-period_x+dys),  dyc/2, hh_L_1+thick_L_1/2} }
-                                  {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_inc_gd.pos"], Format Table];
-
-      For k In {2:6}
-        Print[ Abs_L~{k}[L~{k}], OnGlobal, File > StrCat[myDir,Sprintf["temp-Q_L_%g.txt",k]], Format Table ];
-      EndFor
-      Print[ Abs_scat[Scat]  , OnGlobal, File > StrCat[myDir,"temp-Q_scat.txt"], Format Table ];
-
-      For i In {0:Nb_ordre-1}
-        For j In {0:Nb_ordre-1}
-          Print[ int_x_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_x_t~{i}~{j}, Format Table];
-          Print[ int_y_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_y_t~{i}~{j}, Format Table];
-          Print[ int_z_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_z_t~{i}~{j}, Format Table];          
-          Print[ int_x_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_x_r~{i}~{j}, Format Table];
-          Print[ int_y_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_y_r~{i}~{j}, Format Table];
-          Print[ int_z_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_z_r~{i}~{j}, Format Table];
+        If (FlagOutEscaCuts==1)
+          Print [ u , OnPlane { {-period_x/2,0,hh_L_6-PML_bot} {period_x/2,0,hh_L_6-PML_bot} {-period_x/2,0,hh_L_1+thick_L_1+PML_top} } {npts_interpX,npts_interpZSca} , File StrCat[myDir,"u_cut_Y=0.pos"], Name "u_cut_Y=0"];
+          Print [ u , OnPlane { {0,-period_y/2,hh_L_6-PML_bot} {0,period_y/2,hh_L_6-PML_bot} {0,-period_y/2,hh_L_1+thick_L_1+PML_top} } {npts_interpY,npts_interpZSca} , File StrCat[myDir,"u_cut_X=0.pos"], Name "u_cut_X=0"];
+        EndIf
+        If (FlagOutEtotCuts==1)
+          Print [ Etot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Etot_cut_Y=0.pos"], Name "Etot_cut_Y=0"];
+          Print [ Etot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Etot_cut_X=0.pos"], Name "Etot_cut_X=0"];
+          Print [ E1   , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"E1_cut_Y=0.pos"], Name "E1_cut_Y=0"];
+          Print [ E1   , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"E1_cut_X=0.pos"], Name "E1_cut_X=0"];
+        EndIf
+        If (FlagOutHtotCuts==1)
+          Print [ Htot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Htot_cut_Y=0.pos"], Name "Htot_cut_Y=0"];
+          Print [ Htot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Htot_cut_X=0.pos"], Name "Htot_cut_X=0"];
+        EndIf
+        If (FlagOutPoyCut==1)
+          Print [ Poy_tot , OnPlane { {-period_x/2,0,hh_L_6} {period_x/2,0,hh_L_6} {-period_x/2,0,hh_L_1+thick_L_1} } {npts_interpX,npts_interpZTot} , File StrCat[myDir,"Poy_tot_cut_Y=0.pos"], Name "Poy_tot_cut_Y=0"];
+          Print [ Poy_tot , OnPlane { {0,-period_y/2,hh_L_6} {0,period_y/2,hh_L_6} {0,-period_y/2,hh_L_1+thick_L_1} } {npts_interpY,npts_interpZTot} , File StrCat[myDir,"Poy_tot_cut_X=0.pos"], Name "Poy_tot_cut_X=0"];
+        EndIf
+  
+        Print [ Poy_tot , OnPlane { {0.5*(-period_x-dys), -dyc/2,(hh_L_6+hh_L_5)/2}
+                                    {0.5*( period_x-dys), -dyc/2,(hh_L_6+hh_L_5)/2}
+                                    {0.5*(-period_x+dys),  dyc/2,(hh_L_6+hh_L_5)/2} }
+                                    {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_tot_gd.pos"], Format Table];
+        Print [ Poy_ref , OnPlane { {0.5*(-period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
+                                    {0.5*( period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
+                                    {0.5*(-period_x+dys),  dyc/2, hh_L_1+thick_L_1/2} }
+                                    {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_ref_gd.pos"], Format Table];
+        Print [ Poy_inc , OnPlane { {0.5*(-period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
+                                    {0.5*( period_x-dys), -dyc/2, hh_L_1+thick_L_1/2}
+                                    {0.5*(-period_x+dys),  dyc/2, hh_L_1+thick_L_1/2} }
+                                    {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"Poy_inc_gd.pos"], Format Table];
+  
+        For k In {2:6}
+          Print[ Abs_L~{k}[L~{k}], OnGlobal, File > StrCat[myDir,Sprintf["temp-Q_L_%g.txt",k]], Format Table ];
         EndFor
-      EndFor
-
-      For i In {0:Nb_ordre-1}
-        For j In {0:Nb_ordre-1}
-          Print[ eff_t1~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir, "eff_t1.txt"], Format Table ];
-          Print[ eff_r1~{i}~{j}[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir, "eff_r1.txt"], Format Table ];
-          Print[ eff_t2~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir, "eff_t2.txt"], Format Table ];
-          Print[ eff_r2~{i}~{j}[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir, "eff_r2.txt"], Format Table ];
+        Print[ Abs_scat[Scat]  , OnGlobal, File > StrCat[myDir,"temp-Q_scat.txt"], Format Table ];
+  
+        For i In {0:Nb_ordre-1}
+          For j In {0:Nb_ordre-1}
+            Print[ int_x_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_x_t~{i}~{j}, Format Table];
+            Print[ int_y_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_y_t~{i}~{j}, Format Table];
+            Print[ int_z_t~{i}~{j}[SurfIntBot], OnGlobal, StoreInVariable $int_z_t~{i}~{j}, Format Table];          
+            Print[ int_x_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_x_r~{i}~{j}, Format Table];
+            Print[ int_y_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_y_r~{i}~{j}, Format Table];
+            Print[ int_z_r~{i}~{j}[SurfIntTop], OnGlobal, StoreInVariable $int_z_r~{i}~{j}, Format Table];
+          EndFor
         EndFor
-      EndFor
-      Print[ er_specular[SurfIntTop]  , OnRegion SurfIntTop, StoreInVariable $er_specular, Format Table];
-      Print[ rp[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir,"rp.txt"], Format Table ];
-      Print[ rs[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir,"rs.txt"], Format Table ];      
-      For i In {0:Nb_ordre-1}
-        For j In {0:Nb_ordre-1}
-          Print[ numbering_ij~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir,"numbering_ij.txt"], Format Table ];
+  
+        For i In {0:Nb_ordre-1}
+          For j In {0:Nb_ordre-1}
+            Print[ eff_t1~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir, "eff_t1.txt"], Format Table ];
+            Print[ eff_r1~{i}~{j}[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir, "eff_r1.txt"], Format Table ];
+            Print[ eff_t2~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir, "eff_t2.txt"], Format Table ];
+            Print[ eff_r2~{i}~{j}[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir, "eff_r2.txt"], Format Table ];
+          EndFor
         EndFor
-      EndFor
-      Print[ lambda_step, OnPoint{0,0,0}, Format Table, File > StrCat[myDir, "temp_lambda_step.txt"], SendToServer "GetDP/Lambda_step" ] ;
+        Print[ er_specular[SurfIntTop]  , OnRegion SurfIntTop, StoreInVariable $er_specular, Format Table];
+        Print[ et_specular[SurfIntBot]  , OnRegion SurfIntBot, StoreInVariable $et_specular, Format Table];
+        Print[ rp[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir,"rp.txt"], Format Table ];
+        Print[ rs[SurfIntTop], OnRegion SurfIntTop, File > StrCat[myDir,"rs.txt"], Format Table ];
+        Print[ tp[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir,"tp.txt"], Format Table ];
+        Print[ ts[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir,"ts.txt"], Format Table ];
+        For i In {0:Nb_ordre-1}
+          For j In {0:Nb_ordre-1}
+            Print[ numbering_ij~{i}~{j}[SurfIntBot], OnRegion SurfIntBot, File > StrCat[myDir,"numbering_ij.txt"], Format Table ];
+          EndFor
+        EndFor
+        Print[ lambda_step, OnPoint{0,0,0}, Format Table, File > StrCat[myDir, "temp_lambda_step.txt"], SendToServer "GetDP/Lambda_step" ] ;
+      }
     }
   }
-}
-
-DefineConstant[
-  R_ = {"helmholtz_vector", Name "GetDP/1ResolutionChoices", Visible 1},
-  C_ = {"-solve -pos -petsc_prealloc 500 -ksp_type preonly -pc_type lu -pc_factor_mat_solver_type mumps -ksp_error_if_not_converged", Name "GetDP/9ComputeCommand", Visible 1},
-  P_ = {"postop_helmholtz_vector", Name "GetDP/2PostOperationChoices", Visible 1}
-];
+  
+  DefineConstant[
+    R_ = {"helmholtz_vector", Name "GetDP/1ResolutionChoices", Visible 1},
+    C_ = {"-solve -pos -petsc_prealloc 500 -ksp_type preonly -pc_type lu -pc_factor_mat_solver_type mumps -ksp_error_if_not_converged", Name "GetDP/9ComputeCommand", Visible 1},
+    P_ = {"postop_helmholtz_vector", Name "GetDP/2PostOperationChoices", Visible 1}
+  ];
+  
\ No newline at end of file
diff --git a/DiffractionGratings/grating3D_data.geo b/DiffractionGratings/grating3D_data.geo
index 4862669594cefcc756bcc12166cb94972dd43976..d7588084f3c8d3af6453a6e3e27a15ca81d61406 100644
--- a/DiffractionGratings/grating3D_data.geo
+++ b/DiffractionGratings/grating3D_data.geo
@@ -1,8 +1,8 @@
 
 DefineConstant[
-  test_case = {"half_ellipsoid",
+  test_case = {"skewed_lattice",
     Name "1Geometry",
-    Choices {"half_ellipsoid", "hole", "pyramid", "torus", "bi_sinusoidal", "retrieve_2D_lamellar", "nanowire_solarcell", "convergence", "skewed_lattice"},
+    Choices {"half_ellipsoid", "hole", "pyramid", "U", "bi_sinusoidal", "retrieve_2D_lamellar", "nanowire_solarcell", "convergence", "skewed_lattice"},
     GmshOption "Reset", Autocheck 0
   }
 ];
diff --git a/DiffractionGratings/grating3D_data_torus.geo b/DiffractionGratings/grating3D_data_U.geo
similarity index 87%
rename from DiffractionGratings/grating3D_data_torus.geo
rename to DiffractionGratings/grating3D_data_U.geo
index bc27227d377d6b0b47cb37a3576cf86583b3a451..ef63dada944441d0562805a59ed331ee6927aede 100644
--- a/DiffractionGratings/grating3D_data_torus.geo
+++ b/DiffractionGratings/grating3D_data_U.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -11,23 +11,23 @@ DefineConstant[
     thetadeg      = {0     , Name StrCat[pp1,"/2theta0 [deg]"]},
     phideg        = {0     , Name StrCat[pp1,"/3phi0 [deg]"]},
     psideg        = {0     , Name StrCat[pp1,"/4psi0 [deg]"]},
-    period_x      = {300   , Name StrCat[pp2,"/1X period [nm]"]},
-    period_y      = {300   , Name StrCat[pp2,"/2Y period [nm]"]},
+    period_x      = {390   , Name StrCat[pp2,"/1X period [nm]"]},
+    period_y      = {390   , Name StrCat[pp2,"/2Y period [nm]"]},
     thick_L_1     = {50    , Name StrCat[pp2,"/3thickness layer 1 [nm] (superstrate)"]},
     thick_L_2     = {100   , Name StrCat[pp2,"/4thickness layer 2 [nm]"]},
     thick_L_3     = {100   , Name StrCat[pp2,"/5thickness layer 3 [nm]"]},
     thick_L_4     = {100   , Name StrCat[pp2,"/6thickness layer 4 [nm]"]},
     thick_L_5     = {50    , Name StrCat[pp2,"/7thickness layer 5 [nm]"]},
     thick_L_6     = {50    , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
-    xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
+    xsideg        = {0     , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  3      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
-    rx            = {150/2 , Name StrCat[pp3,"/1rx"]},
-    ry            = { 50   , Name StrCat[pp3,"/2ry"]},
-    rz            = { 25   , Name StrCat[pp3,"/3rz"]},
-    flag_mat_scat = { 0    , Name StrCat[pp3,"/4Scatterer permittivity model"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
-    eps_re_Scat   = {-21   , Name StrCat[pp3,"/5Custom real part of relative permittivity"]},
-    eps_im_Scat   = { 20   , Name StrCat[pp3,"/6Custom real part of relative permittivity"]},
+    tag_geom      = {  3  , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    rx            = { 90  , Name StrCat[pp3,"/1rx"]},
+    ry            = { 74  , Name StrCat[pp3,"/2ry"]},
+    rz            = { 40  , Name StrCat[pp3,"/3rz"]},
+    flag_mat_scat = { 4   , Name StrCat[pp3,"/4Scatterer permittivity model"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    eps_re_Scat   = {-21  , Name StrCat[pp3,"/5Custom real part of relative permittivity"]},
+    eps_im_Scat   = { 20  , Name StrCat[pp3,"/6Custom real part of relative permittivity"]},
 
     flag_mat_1    = { 0    , Name StrCat[pp4,"/1Layer 1"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
     flag_mat_2    = { 0    , Name StrCat[pp4,"/2Layer 2"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
diff --git a/DiffractionGratings/grating3D_data_bi_sinusoidal.geo b/DiffractionGratings/grating3D_data_bi_sinusoidal.geo
index 216ef0b2710c139bc04ae748e9b7f8ba6b3596d8..df20cbd5270accdd8b3b8cb16a94b35dc8ddd082 100644
--- a/DiffractionGratings/grating3D_data_bi_sinusoidal.geo
+++ b/DiffractionGratings/grating3D_data_bi_sinusoidal.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -21,7 +21,7 @@ DefineConstant[
     thick_L_6     = {200   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  6      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  6      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {1.25*lambda0, Name StrCat[pp3,"/1rx"]},
     ry            = {1.25*lambda0, Name StrCat[pp3,"/2ry"]},
     rz            = { 200    , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_checker.geo b/DiffractionGratings/grating3D_data_checker.geo
index 2e43fc200373707d35adaf8da31d31146fedf512..b057c232a9d8ae1c2386ffaace2adefebb3d9c9d 100644
--- a/DiffractionGratings/grating3D_data_checker.geo
+++ b/DiffractionGratings/grating3D_data_checker.geo
@@ -1,4 +1,4 @@
-nm  = 10000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -21,7 +21,7 @@ DefineConstant[
     thick_L_6     = {50    , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  5      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  5      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {1.25*lambda0, Name StrCat[pp3,"/1rx"]},
     ry            = {1.25*lambda0, Name StrCat[pp3,"/2ry"]},
     rz            = {lambda0     , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_convergence.geo b/DiffractionGratings/grating3D_data_convergence.geo
index fff7de0d3a6b12761fd84bf1d53b7f34d282334b..ef58fbd254a735a0a55fa27a22e02dc41f790f02 100644
--- a/DiffractionGratings/grating3D_data_convergence.geo
+++ b/DiffractionGratings/grating3D_data_convergence.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -21,7 +21,7 @@ DefineConstant[
     thick_L_6     = {50   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  4  , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  4  , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {107  , Name StrCat[pp3,"/1rx"]},
     ry            = {47   , Name StrCat[pp3,"/2ry"]},
     rz            = {40   , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_half_ellipsoid.geo b/DiffractionGratings/grating3D_data_half_ellipsoid.geo
index 6ae275ac87b899029145b2abdf98068bda4607d1..38f5932acb3551f1998d73cd8eaf1931259e00d7 100644
--- a/DiffractionGratings/grating3D_data_half_ellipsoid.geo
+++ b/DiffractionGratings/grating3D_data_half_ellipsoid.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -11,8 +11,8 @@ DefineConstant[
     thetadeg      = {40   , Name StrCat[pp1,"/2theta0 [deg]"]},
     phideg        = {36   , Name StrCat[pp1,"/3phi0 [deg]"]},
     psideg        = {72   , Name StrCat[pp1,"/4psi0 [deg]"]},
-    period_x      = {250  , Name StrCat[pp2,"/1X period [nm]"]},
-    period_y      = {250  , Name StrCat[pp2,"/2Y period [nm]"]},
+    period_x      = {473  , Name StrCat[pp2,"/1X period [nm]"]},
+    period_y      = {322  , Name StrCat[pp2,"/2Y period [nm]"]},
     thick_L_1     = {50   , Name StrCat[pp2,"/3thickness layer 1 [nm] (superstrate)"]},
     thick_L_2     = {50   , Name StrCat[pp2,"/4thickness layer 2 [nm]"]},
     thick_L_3     = {100  , Name StrCat[pp2,"/5thickness layer 3 [nm]"]},
@@ -21,29 +21,29 @@ DefineConstant[
     thick_L_6     = {50   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  4      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
-    rx            = {107  , Name StrCat[pp3,"/1rx"]},
-    ry            = {47   , Name StrCat[pp3,"/2ry"]},
-    rz            = {40   , Name StrCat[pp3,"/3rz"]},
-    flag_mat_scat = { 0   , Name StrCat[pp3,"/4Scatterer permittivity model"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
-    eps_re_Scat   = {-2.23, Name StrCat[pp3,"/7eps_re_Scat"]},
-    eps_im_Scat   = { 3.89, Name StrCat[pp3,"/8eps_im_Scat"]},
+    tag_geom      = { 4  , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    rx            = {107 , Name StrCat[pp3,"/1rx"]},
+    ry            = {47  , Name StrCat[pp3,"/2ry"]},
+    rz            = {40  , Name StrCat[pp3,"/3rz"]},
+    flag_mat_scat = { 4  , Name StrCat[pp3,"/4Scatterer permittivity model"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    eps_re_Scat   = { 9  , Name StrCat[pp3,"/7eps_re_Scat"]},
+    eps_im_Scat   = { 1  , Name StrCat[pp3,"/8eps_im_Scat"]},
 
     flag_mat_1    = { 0    , Name StrCat[pp4,"/1Layer 1"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
     flag_mat_2    = { 0    , Name StrCat[pp4,"/2Layer 2"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
     flag_mat_3    = { 0    , Name StrCat[pp4,"/3Layer 3"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
-    flag_mat_4    = { 0    , Name StrCat[pp4,"/4Layer 4"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
-    flag_mat_5    = { 0    , Name StrCat[pp4,"/5Layer 5"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
-    flag_mat_6    = { 0    , Name StrCat[pp4,"/6Layer 6"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_4    = { 1    , Name StrCat[pp4,"/4Layer 4"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_5    = { 1    , Name StrCat[pp4,"/5Layer 5"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_6    = { 1    , Name StrCat[pp4,"/6Layer 6"], Choices {0="Custom (Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
     eps_re_L_1    = {1    , Name StrCat[pp4,"/layer 1: real part of relative permittivity"]},
     eps_im_L_1    = {0    , Name StrCat[pp4,"/layer 1: imag part of relative permittivity"]},
     eps_re_L_2    = {1    , Name StrCat[pp4,"/layer 2: real part of relative permittivity"]},
     eps_im_L_2    = {0    , Name StrCat[pp4,"/layer 2: imag part of relative permittivity"]},
     eps_re_L_3    = {1    , Name StrCat[pp4,"/layer 3: real part of relative permittivity"]},
     eps_im_L_3    = {0    , Name StrCat[pp4,"/layer 3: imag part of relative permittivity"]},
-    eps_re_L_4    = {1    , Name StrCat[pp4,"/layer 4: real part of relative permittivity"]},
+    eps_re_L_4    = {4    , Name StrCat[pp4,"/layer 4: real part of relative permittivity"]},
     eps_im_L_4    = {0    , Name StrCat[pp4,"/layer 4: imag part of relative permittivity"]},
-    eps_re_L_5    = {1    , Name StrCat[pp4,"/layer 5: real part of relative permittivity"]},
+    eps_re_L_5    = {4    , Name StrCat[pp4,"/layer 5: real part of relative permittivity"]},
     eps_im_L_5    = {0    , Name StrCat[pp4,"/layer 5: imag part of relative permittivity"]},
     eps_re_L_6    = {4    , Name StrCat[pp4,"/layer 6: real part of relative permittivity"]},
     eps_im_L_6    = {0    , Name StrCat[pp4,"/layer 6: imag part of relative permittivity"]},
@@ -51,9 +51,9 @@ DefineConstant[
     og            = {0          , Name StrCat[pp5,"/0geometrical order [-]"]  , Choices {0="1",1="2"} },
     oi            = {1          , Name StrCat[pp5,"/0interpolation order [-]"], Choices {0="1",1="2"} },
     paramaille    = {8    , Name StrCat[pp5,"/1Number of mesh elements per wavelength [-]"]},
-    lc_scat       = {10   , Name StrCat[pp5,"/2metal mesh size [nm]"]},
-    PML_top       = {lambda0 , Name StrCat[pp5,"/4PML top thickness [nm]"]},
-    PML_bot       = {lambda0 , Name StrCat[pp5,"/5PML bot thickness [nm]"]},
+    lc_scat       = {1   , Name StrCat[pp5,"/2metal mesh size [nm]"]},
+    PML_top       = {800 , Name StrCat[pp5,"/4PML top thickness [nm]"]},
+    PML_bot       = {800 , Name StrCat[pp5,"/5PML bot thickness [nm]"]},
     Nmax          = {1     , Name StrCat[pp5,"/6Number of non specular order to output [-]"]},
     refine_mesh_L_1= {1     , Name StrCat[pp5,"/7refine layers/1refine mesh layer 1 [-]"]},
     refine_mesh_L_2= {1     , Name StrCat[pp5,"/7refine layers/2refine mesh layer 2 [-]"]},
@@ -64,11 +64,11 @@ DefineConstant[
     FlagLinkFacets = {0      , Name StrCat[pp5,"/8FlagLinkFacets? [-]"], Choices {0,1}, Visible 0},
     PML_TYPE       = {0      , Name StrCat[pp5,"/9PML damping profile [-]"], Choices {0="constant profile",1="Bermudez profile"}, Visible 0},
         
-    InterpSampling     = { 10   , Name StrCat[pp6,"/0Interpolation grid step [nm]"]},
+    InterpSampling     = { 2   , Name StrCat[pp6,"/0Interpolation grid step [nm]"]},
     Flag_interp_cubic  = { 0    , Name StrCat[pp6,"/1Interpolate on cubic grid?"], Choices {0,1} },
     FlagOutEtotCuts    = { 1    , Name StrCat[pp6,"/2Output Total Electric Field cuts?"] , Choices {0,1} },
     FlagOutHtotCuts    = { 0    , Name StrCat[pp6,"/3Output Total Magnetic Field cuts?"] , Choices {0,1} },
-    FlagOutEscaCuts    = { 0    , Name StrCat[pp6,"/4Output Scattered Electric Field cuts?"] , Choices {0,1} },
+    FlagOutEscaCuts    = { 1    , Name StrCat[pp6,"/4Output Scattered Electric Field cuts?"] , Choices {0,1} },
     FlagOutPoyCut      = { 0    , Name StrCat[pp6,"/5Output Poynting cuts?"] , Choices {0,1} },
     FlagOutEtotFull    = { 0    , Name StrCat[pp6,"/6Total Electric Field Full Output?"] , Choices {0,1} },
     FlagOutEscaFull    = { 0    , Name StrCat[pp6,"/7Scattered Electric Field Full Output?"] , Choices {0,1} },
diff --git a/DiffractionGratings/grating3D_data_hole.geo b/DiffractionGratings/grating3D_data_hole.geo
index 32bf71279b1423c4b2368d8e9975b12b9db39d3b..1298f1a86aecd5f779283a0ef033b80ee3712398 100644
--- a/DiffractionGratings/grating3D_data_hole.geo
+++ b/DiffractionGratings/grating3D_data_hole.geo
@@ -27,7 +27,7 @@ DefineConstant[
     thick_L_6     = {100   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = { 2      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = { 2      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {250   , Name StrCat[pp3,"/1rx"]},
     ry            = {47    , Name StrCat[pp3,"/2ry"]},
     rz            = {500   , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_nanowire_solarcell.geo b/DiffractionGratings/grating3D_data_nanowire_solarcell.geo
index ccfd3c968465d3930db4930155f5fa1efa384ec5..dd7d05224b2a396556fffe1cf27ef1e4b06fe8a1 100644
--- a/DiffractionGratings/grating3D_data_nanowire_solarcell.geo
+++ b/DiffractionGratings/grating3D_data_nanowire_solarcell.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -22,7 +22,7 @@ DefineConstant[
     thick_L_6     = {25   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = { 2      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = { 2      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = { 50   , Name StrCat[pp3,"/1rx"]},
     ry            = {47    , Name StrCat[pp3,"/2ry"]},
     rz            = {400   , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_pillar.geo b/DiffractionGratings/grating3D_data_pillar.geo
new file mode 100644
index 0000000000000000000000000000000000000000..8871b7873589e78d6480c31f5cb3845bbeb430f4
--- /dev/null
+++ b/DiffractionGratings/grating3D_data_pillar.geo
@@ -0,0 +1,131 @@
+// note : invcreasing paramaille to 7 leads to:
+// Ndofs 1116912
+// solve wall time mumps  : 634.318s - R00=0.2432916553175037
+// solve wall time pastix : 966.046s - R00=0.2432916553175064
+// beware : very near a Rayleigh anomaly
+
+nm  = 1;
+pp1 = "1Incident Plane Wave";
+pp2 = "2Layers Thicknesses";
+pp3 = "3Scatterer Properties";
+pp4 = "4Layer Materials";
+pp5 = "5Computational Parameters";
+pp6 = "6Output";
+DefineConstant[
+    FLAG_TOTAL    = {0     , Name StrCat[pp1,"/0Formulation"],Choices {0="scattered field",1="total field"}},
+    lambda0       = {500   , Name StrCat[pp1,"/1lambda0 [nm]"]},
+    thetadeg      = {0     , Name StrCat[pp1,"/2theta0 [deg]"]},
+    phideg        = {0     , Name StrCat[pp1,"/3phi0 [deg]"]},
+    psideg        = {45    , Name StrCat[pp1,"/4psi0 [deg]"]},
+    period_x      = {390   , Name StrCat[pp2,"/1X period [nm]"]},
+    period_y      = {390   , Name StrCat[pp2,"/2Y period [nm]"]},
+    thick_L_1     = {50   , Name StrCat[pp2,"/3thickness layer 1 [nm] (superstrate)"]},
+    thick_L_2     = {50   , Name StrCat[pp2,"/4thickness layer 2 [nm]"]},
+    thick_L_3     = {200  , Name StrCat[pp2,"/5thickness layer 3 [nm]"]},
+    thick_L_4     = {50   , Name StrCat[pp2,"/6thickness layer 4 [nm]"]},
+    thick_L_5     = {50   , Name StrCat[pp2,"/7thickness layer 5 [nm]"]},
+    thick_L_6     = {50   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
+    xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
+
+    tag_geom      = { 8    , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar",8="cylindrical pillar"}},
+    rx            = {60    , Name StrCat[pp3,"/1rx"]},
+    ry            = {60    , Name StrCat[pp3,"/2ry"]},
+    rz            = {130   , Name StrCat[pp3,"/3rz"]},
+    flag_mat_scat = {10    , Name StrCat[pp3,"/4Scatterer permittivity model"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    eps_re_Scat   = {1     , Name StrCat[pp3,"/7eps_re_Scat"]},
+    eps_im_Scat   = {0     , Name StrCat[pp3,"/8eps_im_Scat"]},
+
+    flag_mat_1    = { 0    , Name StrCat[pp4,"/1Layer 1"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_2    = { 0    , Name StrCat[pp4,"/2Layer 2"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_3    = { 0    , Name StrCat[pp4,"/3Layer 3"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_4    = { 0    , Name StrCat[pp4,"/4Layer 4"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_5    = { 0    , Name StrCat[pp4,"/5Layer 5"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    flag_mat_6    = { 0    , Name StrCat[pp4,"/6Layer 6"], Choices {0="Custom (Set Value Below)",1="SiO2",2="Ag (palik)",3="Al (palik)",4="Au (johnson)",5="Nb2O5",6="ZnSe",7="MgF2",8="TiO2",9="PMMA",10="Si",11="ITO",12="Cu (palik)"} },
+    eps_re_L_1    = {1     , Name StrCat[pp4,"/layer 1: real part of relative permittivity"]},
+    eps_im_L_1    = {0     , Name StrCat[pp4,"/layer 1: imag part of relative permittivity"]},
+    eps_re_L_2    = {1     , Name StrCat[pp4,"/layer 2: real part of relative permittivity"]},
+    eps_im_L_2    = {0     , Name StrCat[pp4,"/layer 2: imag part of relative permittivity"]},
+    eps_re_L_3    = {1     , Name StrCat[pp4,"/layer 3: real part of relative permittivity"]},
+    eps_im_L_3    = {0     , Name StrCat[pp4,"/layer 3: imag part of relative permittivity"]},
+    eps_re_L_4    = {2.25  , Name StrCat[pp4,"/layer 4: real part of relative permittivity"]},
+    eps_im_L_4    = {0     , Name StrCat[pp4,"/layer 4: imag part of relative permittivity"]},
+    eps_re_L_5    = {2.25  , Name StrCat[pp4,"/layer 5: real part of relative permittivity"]},
+    eps_im_L_5    = {0     , Name StrCat[pp4,"/layer 5: imag part of relative permittivity"]},
+    eps_re_L_6    = {2.25  , Name StrCat[pp4,"/layer 6: real part of relative permittivity"]},
+    eps_im_L_6    = {0     , Name StrCat[pp4,"/layer 6: imag part of relative permittivity"]},
+    
+    og            = {0          , Name StrCat[pp5,"/0geometrical order [-]"]  , Choices {0="1",1="2"} },
+    oi            = {1          , Name StrCat[pp5,"/0interpolation order [-]"], Choices {0="1",1="2"} },
+    paramaille    = {5.         , Name StrCat[pp5,"/1Number of mesh elements per wavelength [-]"]},
+    lc_scat       = {lambda0/(5*paramaille)    , Name StrCat[pp5,"/2Scatterer absolute mesh size [nm]"]},
+    PML_top       = {lambda0, Name StrCat[pp5,"/4PML top thickness [nm]"]},
+    PML_bot       = {lambda0, Name StrCat[pp5,"/5PML bot thickness [nm]"]},
+    Nmax          = {1      , Name StrCat[pp5,"/6Number of non specular order to output [-]"]},
+    refine_mesh_L_1= {1      , Name StrCat[pp5,"/7refine layers/1refine mesh layer 1 [-]"]},
+    refine_mesh_L_2= {1      , Name StrCat[pp5,"/7refine layers/2refine mesh layer 2 [-]"]},
+    refine_mesh_L_3= {1      , Name StrCat[pp5,"/7refine layers/3refine mesh layer 3 [-]"]},
+    refine_mesh_L_4= {1      , Name StrCat[pp5,"/7refine layers/4refine mesh layer 4 [-]"]},
+    refine_mesh_L_5= {1      , Name StrCat[pp5,"/7refine layers/5refine mesh layer 5 [-]"]},
+    refine_mesh_L_6= {1      , Name StrCat[pp5,"/7refine layers/6refine mesh layer 6 [-]"]},
+    FlagLinkFacets = {0      , Name StrCat[pp5,"/8FlagLinkFacets? [-]"], Choices {0,1}, Visible 0},
+    PML_TYPE       = {0      , Name StrCat[pp5,"/9PML damping profile [-]"], Choices {0="constant profile",1="Bermudez profile"}, Visible 0},
+
+    InterpSampling     = { 30   , Name StrCat[pp6,"/0Interpolation grid step [nm]"]},
+    Flag_interp_cubic  = { 1    , Name StrCat[pp6,"/1Interpolate on cubic grid?"], Choices {0,1} },
+    FlagOutEtotCuts    = { 1    , Name StrCat[pp6,"/2Output Total Electric Field cuts?"] , Choices {0,1} },
+    FlagOutHtotCuts    = { 0    , Name StrCat[pp6,"/3Output Total Magnetic Field cuts?"] , Choices {0,1} },
+    FlagOutEscaCuts    = { 1    , Name StrCat[pp6,"/4Output Scattered Electric Field cuts?"] , Choices {0,1} },
+    FlagOutPoyCut      = { 1    , Name StrCat[pp6,"/5Output Poynting cuts?"] , Choices {0,1} },
+    FlagOutEtotFull    = { 0    , Name StrCat[pp6,"/6Total Electric Field Full Output?"] , Choices {0,1} },
+    FlagOutEscaFull    = { 0    , Name StrCat[pp6,"/7Scattered Electric Field Full Output?"] , Choices {0,1} },
+    FlagOutPoyFull     = { 0    , Name StrCat[pp6,"/8Poynting Full Output?"] , Choices {0,1} }
+];
+
+lambda0       = nm * lambda0;
+period_x      = nm * period_x;
+period_y      = nm * period_y;
+thick_L_1     = nm * thick_L_1;
+thick_L_2     = nm * thick_L_2;
+thick_L_3     = nm * thick_L_3;
+thick_L_4     = nm * thick_L_4;
+thick_L_5     = nm * thick_L_5;
+thick_L_6     = nm * thick_L_6;
+rx            = nm * rx;
+ry            = nm * ry;
+rz            = nm * rz;
+lc_scat       = nm * lc_scat;
+PML_top       = nm * PML_top;
+PML_bot       = nm * PML_bot;
+InterpSampling= nm * InterpSampling;
+
+lambda_m = lambda0;
+og+=1;
+oi+=1;
+
+hh_L_6 = -thick_L_6;
+For k In {1:5}
+    hh_L~{6-k} = hh_L~{7-k}+thick_L~{7-k};
+EndFor
+PML_bot_hh = hh_L_6-PML_bot;
+PML_top_hh = hh_L_1+thick_L_1;
+hh_L_7     = PML_bot_hh;
+hh_L_0     = PML_top_hh;
+thick_L_7  = PML_bot;
+thick_L_0  = PML_top;
+
+theta0 = thetadeg*Pi/180;
+phi0   = phideg*Pi/180;
+psi0   = psideg*Pi/180;
+xsi    = xsideg*Pi/180;
+
+dyc = period_y*Cos[xsi];
+dys = period_y*Sin[xsi];
+
+DomainZsizeSca  = PML_top_hh+PML_bot-(hh_L_6-PML_bot);
+DomainZsizeTot  = PML_top_hh-hh_L_6;
+npts_interpX    = period_x/InterpSampling;
+npts_interpY    = period_y/InterpSampling;
+npts_checkpoyX  = 50;
+npts_checkpoyY  = 50;
+npts_interpZSca = DomainZsizeSca/InterpSampling;
+npts_interpZTot = DomainZsizeTot/InterpSampling;
diff --git a/DiffractionGratings/grating3D_data_pyramid.geo b/DiffractionGratings/grating3D_data_pyramid.geo
index 579361b100742a5e1cce49e1295d8b12c95b4721..f2e456f966c68afbd2dfd6c0a01da8c8aa522ad0 100644
--- a/DiffractionGratings/grating3D_data_pyramid.geo
+++ b/DiffractionGratings/grating3D_data_pyramid.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -21,7 +21,7 @@ DefineConstant[
     thick_L_6     = {50    , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  1      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  1      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {107   , Name StrCat[pp3,"/1rx"]},
     ry            = {250   , Name StrCat[pp3,"/2ry"]},
     rz            = {250   , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_retrieve_2D_lamellar.geo b/DiffractionGratings/grating3D_data_retrieve_2D_lamellar.geo
index 83f95d704f1c440ed906799040ed370010be504c..a8591b35fd7ba939ae3f2d6ad8047bfad30cc867 100644
--- a/DiffractionGratings/grating3D_data_retrieve_2D_lamellar.geo
+++ b/DiffractionGratings/grating3D_data_retrieve_2D_lamellar.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -21,7 +21,7 @@ DefineConstant[
     thick_L_6     = {100    , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {0    , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  7      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  7      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = { 0     , Name StrCat[pp3,"/1rx"]},
     ry            = {500        , Name StrCat[pp3,"/2ry"]},
     rz            = {1000     , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_data_skewed_lattice.geo b/DiffractionGratings/grating3D_data_skewed_lattice.geo
index 2bf61c73e048e313d0e685bd570ef1235ca1f4c9..53e66b36cf420413c8acbe6d1784f1f1a04e6b9c 100644
--- a/DiffractionGratings/grating3D_data_skewed_lattice.geo
+++ b/DiffractionGratings/grating3D_data_skewed_lattice.geo
@@ -1,4 +1,4 @@
-nm  = 1000;
+nm  = 1;
 pp1 = "1Incident Plane Wave";
 pp2 = "2Layers Thicknesses";
 pp3 = "3Scatterer Properties";
@@ -22,7 +22,7 @@ DefineConstant[
     thick_L_6     = {50   , Name StrCat[pp2,"/8thickness layer 6 [nm] (substrate)"]},
     xsideg        = {30   , Name StrCat[pp2,"/9skew angle [deg]"],Visible 1},
 
-    tag_geom      = {  4      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="Torus",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
+    tag_geom      = {  4      , Name StrCat[pp3,"/0Shape"], Choices {1="Pyramid",2="Cylindrical Hole",3="U",4="HalfEllipspoid",5="Checkerboard",6="bi-sinusoidal",7="2D lamellar"}},
     rx            = {100 , Name StrCat[pp3,"/1rx"]},
     ry            = {100   , Name StrCat[pp3,"/2ry"]},
     rz            = {50    , Name StrCat[pp3,"/3rz"]},
diff --git a/DiffractionGratings/grating3D_parallel_Mmatrix.sh b/DiffractionGratings/grating3D_parallel_Mmatrix.sh
index 91287d8fd7e245dbf7b051f52dc1e9715aa8a902..73dac5e36cacfab085e06829bda9966884d027eb 100644
--- a/DiffractionGratings/grating3D_parallel_Mmatrix.sh
+++ b/DiffractionGratings/grating3D_parallel_Mmatrix.sh
@@ -1,41 +1,75 @@
 #!/bin/bash
+
+### set threads to 1: parallelization is handled by gnuparallel (NPROC) only
 export OPENBLAS_NUM_THREADS=1
 export OMP_NUM_THREADS=1
 export NPROC=96
 
-export nb_lam=100
-export nb_phi=59
-export lambda_min=350
-export lambda_max=800
+### set gmsh/getdp path if necessary
+# export mygmsh='/path/to/onelabdir/gmsh'
+# export mygetdp='/path/to/onelabdir/getdp'
+export mygmsh='gmsh'
+export mygetdp='getdp'
+
+### choose configuration
+## theta loop study for the "U" case
+## config 1
+# export flag_angle_study="theta"
+# export loop_angle_max=50
+# export fixed_angle=90
+# export GRATING_CASE="U"
+
+## phi loop study for the "U" case
+## config 2
+export flag_angle_study="phi"
+export loop_angle_max=360
+export fixed_angle=50
+export GRATING_CASE="U"
+
+export nb_angle=40
+export nb_lam=50
+export lambda_min=400
+export lambda_max=1200
 export FLAG_TOTAL=0
-export GRATING_CASE="half_ellipsoid"
-export myDir="res_Matrix_nb_lam"$nb_lam"_nb_phi"$nb_phi"_total"$FLAG_TOTAL
+export myDir="res_Matrix_nb_lam"$nb_lam"_nb_"$flag_angle_study$nb_angle"_total"$FLAG_TOTAL
 
 rm -r $myDir
 mkdir $myDir
-gmsh grating3D.geo -3 -o grating3D.msh
+$mygmsh grating3D.geo -setstring test_case $GRATING_CASE -3 -o grating3D.msh
 
 myfunc() {
-    local mysubDir=$myDir/run_lam$1_phi$2_psi$3
+    local mysubDir=$myDir/run_lam$1_$flag_angle_study$2_psi$3
     mkdir $mysubDir
     cp grating3D.msh grating3D.pro grating3D_data_$GRATING_CASE.geo grating3D_data.geo grating3D_materials.pro $mysubDir
-    local lam=$(echo "scale=10;400+400/($nb_lam-1)*$1" | bc )
-    local phi=$(echo "scale=10;360/($nb_phi)*$2" | bc )
+    local lam=$(echo "scale=10;$lambda_min+($lambda_max-$lambda_min)/($nb_lam-1)*$1" | bc )
+    if [ $flag_angle_study = "phi" ]; then
+        local phi=$(echo "scale=10;$loop_angle_max/($nb_angle-1)*$2" | bc )
+        local theta=$(echo "scale=10;$fixed_angle" | bc )
+    else
+        local theta=$(echo "scale=10;$loop_angle_max/($nb_angle-1)*$2" | bc )
+        local phi=$(echo "scale=10;$fixed_angle" | bc )
+    fi
     local psi=$(echo "scale=10;90*$3" | bc )
     cd $mysubDir
-    getdp grating3D.pro -pre helmholtz_vector -msh grating3D.msh -cal -pos postop_helmholtz_vector -petsc_prealloc 200 -setstring test_case $GRATING_CASE -setnumber lambda0 $lam -setnumber thetadeg 50 -setnumber phideg $phi -setnumber psideg $psi -setnumber FLAG_TOTAL $FLAG_TOTAL
-    if [ $3 -eq 0 ]; then cp res3D/rs.txt ../r_pin_sout_lam$1_phi$2.out ; fi
-    if [ $3 -eq 0 ]; then cp res3D/rp.txt ../r_pin_pout_lam$1_phi$2.out ; fi
-    if [ $3 -eq 1 ]; then cp res3D/rs.txt ../r_sin_sout_lam$1_phi$2.out ; fi
-    if [ $3 -eq 1 ]; then cp res3D/rp.txt ../r_sin_pout_lam$1_phi$2.out ; fi
-    cp res3D/eff_t1.txt ../eff_t1_lam$1_phi$2_psi$3.out
-    cp res3D/eff_r1.txt ../eff_r1_lam$1_phi$2_psi$3.out
-    cp res3D/eff_t2.txt ../eff_t2_lam$1_phi$2_psi$3.out
-    cp res3D/eff_r2.txt ../eff_r2_lam$1_phi$2_psi$3.out
-    cp res3D/temp-Q_scat.txt ../Q_scat_lam$1_phi$2_psi$3.out
+    $mygetdp grating3D.pro -pre helmholtz_vector -msh grating3D.msh -cal -pos postop_helmholtz_vector -petsc_prealloc 200 -setstring test_case $GRATING_CASE -setnumber lambda0 $lam -setnumber thetadeg $theta -setnumber phideg $phi -setnumber psideg $psi -setnumber FLAG_TOTAL $FLAG_TOTAL
+    if [ $3 -eq 0 ]; then cp res3D/rs.txt ../r_pin_sout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 0 ]; then cp res3D/rp.txt ../r_pin_pout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 1 ]; then cp res3D/rs.txt ../r_sin_sout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 1 ]; then cp res3D/rp.txt ../r_sin_pout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 0 ]; then cp res3D/ts.txt ../t_pin_sout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 0 ]; then cp res3D/tp.txt ../t_pin_pout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 1 ]; then cp res3D/ts.txt ../t_sin_sout_lam$1_$flag_angle_study$2.out ; fi
+    if [ $3 -eq 1 ]; then cp res3D/tp.txt ../t_sin_pout_lam$1_$flag_angle_study$2.out ; fi
+    cp res3D/eff_t1.txt ../eff_t1_lam$1_$flag_angle_study$2_psi$3.out
+    cp res3D/eff_r1.txt ../eff_r1_lam$1_$flag_angle_study$2_psi$3.out
+    cp res3D/eff_t2.txt ../eff_t2_lam$1_$flag_angle_study$2_psi$3.out
+    cp res3D/eff_r2.txt ../eff_r2_lam$1_$flag_angle_study$2_psi$3.out
+    cp res3D/temp-Q_scat.txt ../Q_scat_lam$1_$flag_angle_study$2_psi$3.out
     cd ../..
     rm -r $mysubDir
 }
 
 export -f myfunc
-parallel -j $NPROC myfunc ::: $(seq 0 $(($nb_lam-1))) ::: $(seq 0 $(($nb_phi-1))) ::: 0 1
+parallel -j $NPROC myfunc ::: $(seq 0 $(($nb_lam-1))) ::: $(seq 0 $(($nb_angle-1))) ::: 0 1
+
+python grating3D_postplot_Mmatrix.py -flag_angle_study $flag_angle_study -nb_angle $nb_angle -loop_angle_max $loop_angle_max -fixed_angle $fixed_angle -nb_lam $nb_lam -lambda_min $lambda_min -lambda_max $lambda_max
diff --git a/DiffractionGratings/grating3D_postplot.py b/DiffractionGratings/grating3D_postplot.py
index 7fa28648586bdeca3d2171aa3abdf1120356a7ad..c266946db3471927105e4b5fd23fa6937169f0a9 100644
--- a/DiffractionGratings/grating3D_postplot.py
+++ b/DiffractionGratings/grating3D_postplot.py
@@ -27,6 +27,7 @@ def dtrap_poy(fname_in,nx,ny):
     return np.trapz(temp,y_export2D[0,:]) #[x_export2D,y_export2D,poy_y_grid_re] #
 
 myDir = sys.argv[1]
+str_FLAG_TOTAL = myDir[myDir.find('FLAG_TOTAL'):]
 
 intpoyz_tot = abs(dtrap_poy(myDir+'/Poy_tot_gd.pos',50,50))
 intpoyz_ref = abs(dtrap_poy(myDir+'/Poy_ref_gd.pos',50,50))
@@ -44,7 +45,7 @@ Q=np.array(Q)
 TOT1 = R1nm.real.sum()+T1nm.real.sum()+Q.sum()
 TOT2 = R2nm.real.sum()+T2nm.real.sum()+Q.sum()
 
-if myDir[6:]=='solarcell':
+if 'nanowire_solarcell' in myDir:
     print('cf pdf')
     Nmax=2
     tab_lambdas=np.loadtxt(myDir+'/temp_lambda_step.txt',ndmin=2)[:,8]
@@ -55,26 +56,29 @@ if myDir[6:]=='solarcell':
     Ttot = [T1nm[i].real.sum() for i in range(nb_lambdas)]
     Abs_rods = Q[-1]
     Abs_ITO  = Q[0]
-    Abs_subs  = Q[2]+Q[3]+Q[4]+Ttot
+    Abs_subs = Q[2]+Q[3]+Q[4]+Ttot
     TOT = Rtot+Abs_rods+Abs_ITO+Abs_subs
     pl.figure()
     pl.plot(tab_lambdas,Abs_ITO,label='absorption ITO electrode')
-    pl.plot(tab_lambdas,Abs_rods,label='absorption in Si rods')
-    pl.plot(tab_lambdas,Abs_subs,label='absorption in Si subs')
+    pl.plot(tab_lambdas,Abs_rods,label='absorption in Silicon rods')
+    pl.plot(tab_lambdas,Abs_subs,label='absorption in Silicon subs')
     pl.plot(tab_lambdas,Rtot,label='reflection')
     pl.plot(tab_lambdas,TOT,label='total')
     pl.legend()
     pl.xlabel(r'$\lambda$ [nm]')
     pl.ylabel('fraction of incident energy')
     pl.savefig('fig_solar_balance.pdf')
-elif myDir[6:]=='conv':
-    print('cf pdf')
+elif 'convergence' in myDir:
     pl.figure()
     data_abs = np.loadtxt(myDir+'/temp-Q_scat.txt',ndmin=2)[:,1]
     pl.plot(data_abs[0:int(len(data_abs)/2)],label='linear elements')
     pl.plot(data_abs[int(len(data_abs)/2):] ,label='curved elements')
+    pl.xlabel('N / mesh size=$\lambda_0/N$')
+    pl.xlabel('Absorption$')
     pl.legend()
-    pl.savefig('fig_convergence_absorption.pdf')
+    fname = 'fig_convergence_absorption_%s.pdf'%str_FLAG_TOTAL
+    pl.savefig(fname)
+    print('cf %s'%fname)
 else:
     print(colored_i('===> Computed from diffraction efficiencies with tangential components only'))
     print(colored_R('Rtot1  = %.9f'%R1nm.real.sum()))
diff --git a/DiffractionGratings/grating3D_postplot_Mmatrix.py b/DiffractionGratings/grating3D_postplot_Mmatrix.py
index 5499df969898e1c4051e114376bafce1b87d5c0e..a01548db60fd38a68f9332572e57d3c2637dbd9b 100644
--- a/DiffractionGratings/grating3D_postplot_Mmatrix.py
+++ b/DiffractionGratings/grating3D_postplot_Mmatrix.py
@@ -1,6 +1,8 @@
 import numpy as np
 import matplotlib.pyplot as plt
 import matplotlib as mpl
+import scipy.constants as scc
+import argparse
 plt.rcParams.update({"text.usetex": True, "font.family": "serif"})
 
 def add_colorbar(mappable):
@@ -22,30 +24,48 @@ def load_getdp_integral(fname):
     else:
         return temp[:,1]+1j*temp[:,2]
 
-nb_lam = 100
-nb_phi = 60
+parser = argparse.ArgumentParser()
+parser.add_argument("-flag_angle_study" , help="flag_angle_study" , type=str   , default='theta')
+parser.add_argument("-nb_angle"         , help="nb_angle"         , type=int   , default=20)
+parser.add_argument("-loop_angle_max"   , help="loop_angle_max"   , type=float , default=50)
+parser.add_argument("-fixed_angle"      , help="fixed_angle"      , type=float , default=90)
+parser.add_argument("-nb_lam"           , help="nb_lam"           , type=int   , default=100)
+parser.add_argument("-lambda_min"       , help="lambda_min"       , type=float , default=400)
+parser.add_argument("-lambda_max"       , help="lambda_max"       , type=float , default=1200)
+args = parser.parse_args()
+
+flag_angle_study = args.flag_angle_study
+nb_angle         = args.nb_angle
+loop_angle_max   = args.loop_angle_max
+fixed_angle      = args.fixed_angle
+nb_lam           = args.nb_lam
+lambda_min       = args.lambda_min
+lambda_max       = args.lambda_max
+
 FLAG_TOT = 0
-respath  = 'res_Matrix_nb_lam100_nb_phi59_total0/'
-rpp = np.zeros((nb_lam,nb_phi),dtype=complex)
-rps = np.zeros((nb_lam,nb_phi),dtype=complex)
-rsp = np.zeros((nb_lam,nb_phi),dtype=complex)
-rss = np.zeros((nb_lam,nb_phi),dtype=complex)
-efft1_pin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-efft2_pin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-effr1_pin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-effr2_pin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-Qscat_pin = np.zeros((nb_lam,nb_phi))
-efft1_sin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-efft2_sin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-effr1_sin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-effr2_sin = np.zeros((9,nb_lam,nb_phi),dtype=complex)
-Qscat_sin = np.zeros((nb_lam,nb_phi))
-
-
-tab_lam = np.linspace(350,800,nb_lam)
-tab_phi = np.linspace(0,360,nb_phi)
-M = np.zeros((4,4,len(tab_lam),len(tab_phi)),dtype=complex)
+str_reftrans = 'r'
+
+respath  = 'res_Matrix_nb_lam%g_nb_%s%g_total0/'%(nb_lam,flag_angle_study,nb_angle)
 
+rpp = np.zeros((nb_lam,nb_angle),dtype=complex)
+rps = np.zeros((nb_lam,nb_angle),dtype=complex)
+rsp = np.zeros((nb_lam,nb_angle),dtype=complex)
+rss = np.zeros((nb_lam,nb_angle),dtype=complex)
+efft1_pin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+efft2_pin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+effr1_pin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+effr2_pin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+Qscat_pin = np.zeros((nb_lam,nb_angle))
+efft1_sin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+efft2_sin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+effr1_sin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+effr2_sin = np.zeros((9,nb_lam,nb_angle),dtype=complex)
+Qscat_sin = np.zeros((nb_lam,nb_angle))
+
+tab_lam   = np.linspace(lambda_min,lambda_max,nb_lam)
+tab_angle = np.linspace(0,loop_angle_max,nb_angle)
+tab_hnu = 2*scc.pi*scc.c/(tab_lam*1e-9/scc.hbar*scc.eV)
+M = np.zeros((4,4,nb_lam,nb_angle),dtype=complex)
 
 ### Convention used e.g. in https://doi.org/10.1364/JOSAB.36.000E78
 # [Ep]      [ rpp    rps ] [Ep]    
@@ -56,28 +76,22 @@ M = np.zeros((4,4,len(tab_lam),len(tab_phi)),dtype=complex)
 # rps : send Es_inc (s-in), project the reflected field along p (p-out)
 
 for i in range(nb_lam):
-    for j in range(nb_phi-1):
-        print(i,j)
-        rpp[i,j] = load_getdp_integral(respath+'r_pin_pout_lam%g_phi%g.out'%(i,j))
-        rss[i,j] = load_getdp_integral(respath+'r_sin_sout_lam%g_phi%g.out'%(i,j))
-        rps[i,j] = load_getdp_integral(respath+'r_sin_pout_lam%g_phi%g.out'%(i,j))
-        rsp[i,j] = load_getdp_integral(respath+'r_pin_sout_lam%g_phi%g.out'%(i,j))
-        efft1_pin[:,i,j] = load_getdp_integral(respath+'eff_t1_lam%g_phi%g_psi0.out'%(i,j))
-        efft2_pin[:,i,j] = load_getdp_integral(respath+'eff_t2_lam%g_phi%g_psi0.out'%(i,j))
-        effr1_pin[:,i,j] = load_getdp_integral(respath+'eff_r1_lam%g_phi%g_psi0.out'%(i,j))
-        effr2_pin[:,i,j] = load_getdp_integral(respath+'eff_r2_lam%g_phi%g_psi0.out'%(i,j))
-        Qscat_pin[i,j]   = np.real(load_getdp_integral(respath+'Q_scat_lam%g_phi%g_psi0.out'%(i,j)))
-        efft1_sin[:,i,j] = load_getdp_integral(respath+'eff_t1_lam%g_phi%g_psi1.out'%(i,j))
-        efft2_sin[:,i,j] = load_getdp_integral(respath+'eff_t2_lam%g_phi%g_psi1.out'%(i,j))
-        effr1_sin[:,i,j] = load_getdp_integral(respath+'eff_r1_lam%g_phi%g_psi1.out'%(i,j))
-        effr2_sin[:,i,j] = load_getdp_integral(respath+'eff_r2_lam%g_phi%g_psi1.out'%(i,j))
-        Qscat_sin[i,j]   = np.real(load_getdp_integral(respath+'Q_scat_lam%g_phi%g_psi1.out'%(i,j)))
-
-## replicate data for phi=2\pi from phi=0 
-rpp[:,-1] = rpp[:,0]
-rss[:,-1] = rss[:,0]
-rps[:,-1] = rps[:,0]
-rsp[:,-1] = rsp[:,0]
+    print(i)
+    for j in range(nb_angle):
+        rpp[i,j] = load_getdp_integral(respath+str_reftrans+'_pin_pout_lam%g_%s%g.out'%(i,flag_angle_study,j))
+        rss[i,j] = load_getdp_integral(respath+str_reftrans+'_sin_sout_lam%g_%s%g.out'%(i,flag_angle_study,j))
+        rps[i,j] = load_getdp_integral(respath+str_reftrans+'_sin_pout_lam%g_%s%g.out'%(i,flag_angle_study,j))
+        rsp[i,j] = load_getdp_integral(respath+str_reftrans+'_pin_sout_lam%g_%s%g.out'%(i,flag_angle_study,j))
+        efft1_pin[:,i,j] = load_getdp_integral(respath+'eff_t1_lam%g_%s%g_psi0.out'%(i,flag_angle_study,j))
+        efft2_pin[:,i,j] = load_getdp_integral(respath+'eff_t2_lam%g_%s%g_psi0.out'%(i,flag_angle_study,j))
+        effr1_pin[:,i,j] = load_getdp_integral(respath+'eff_r1_lam%g_%s%g_psi0.out'%(i,flag_angle_study,j))
+        effr2_pin[:,i,j] = load_getdp_integral(respath+'eff_r2_lam%g_%s%g_psi0.out'%(i,flag_angle_study,j))
+        Qscat_pin[i,j]   = np.real(load_getdp_integral(respath+'Q_scat_lam%g_%s%g_psi0.out'%(i,flag_angle_study,j)))
+        efft1_sin[:,i,j] = load_getdp_integral(respath+'eff_t1_lam%g_%s%g_psi1.out'%(i,flag_angle_study,j))
+        efft2_sin[:,i,j] = load_getdp_integral(respath+'eff_t2_lam%g_%s%g_psi1.out'%(i,flag_angle_study,j))
+        effr1_sin[:,i,j] = load_getdp_integral(respath+'eff_r1_lam%g_%s%g_psi1.out'%(i,flag_angle_study,j))
+        effr2_sin[:,i,j] = load_getdp_integral(respath+'eff_r2_lam%g_%s%g_psi1.out'%(i,flag_angle_study,j))
+        Qscat_sin[i,j]   = np.real(load_getdp_integral(respath+'Q_scat_lam%g_%s%g_psi1.out'%(i,flag_angle_study,j)))
 
 T1_sin = np.sum(efft1_sin,axis=0)
 T2_sin = np.sum(efft2_sin,axis=0)
@@ -87,6 +101,10 @@ T1_pin = np.sum(efft1_pin,axis=0)
 T2_pin = np.sum(efft2_pin,axis=0)
 R1_pin = np.sum(effr1_pin,axis=0)
 R2_pin = np.sum(effr2_pin,axis=0)
+T00_sin = efft2_sin[4,:,:]
+R00_sin = effr2_sin[4,:,:]
+T00_pin = efft2_pin[4,:,:]
+R00_pin = effr2_pin[4,:,:]
 TOT1_pin = T1_pin+R1_pin+Qscat_pin
 TOT2_pin = T2_pin+R2_pin+Qscat_pin
 TOT1_sin = T1_sin+R1_sin+Qscat_sin
@@ -109,52 +127,69 @@ M[4-1,2-1,:,:] =-np.imag(rpp*np.conj(rsp)-rps*np.conj(rss))
 M[4-1,3-1,:,:] =-np.imag(rpp*np.conj(rss)+rps*np.conj(rsp))
 M[4-1,4-1,:,:] = np.real(rpp*np.conj(rss)-rps*np.conj(rsp))
 
-# ### Energy balance
-# fig, axes = plt.subplots(2, 2, figsize=(12,12))
-# L,P = np.meshgrid(tab_lam,tab_phi,indexing='ij')
-# for form in range(2):
-#     for pol in range(2):
-#         if form==0 and pol==0:
-#             data=TOT1_pin
-#             title = 'TOT1_pin'
-#         if form==0 and pol==1:
-#             data=TOT1_sin
-#             title = 'TOT1_sin'
-#         if form==1 and pol==0:
-#             data=TOT2_pin
-#             title = 'TOT2_pin'
-#         if form==1 and pol==1:
-#             data=TOT2_sin
-#             title = 'TOT2_sin'
-#         zplot = axes[form,pol].pcolormesh(L,P,data.real,vmin=0.99,vmax=1.01)
-#         add_colorbar(zplot)
-# plt.savefig('BALANCE_FLAG_TOT%g.jpg'%FLAG_TOT)
+### Energy balance
+fig, axes = plt.subplots(3, 2, figsize=(12,12))
+L,P = np.meshgrid(tab_lam,tab_angle,indexing='ij')
+for form in range(2):
+    for pol in range(2):
+        if form==0 and pol==0:
+            data=TOT1_pin
+            title = 'TOT1 pin'
+        if form==0 and pol==1:
+            data=TOT1_sin
+            title = 'TOT1 sin'
+        if form==1 and pol==0:
+            data=TOT2_pin
+            title = 'TOT2 pin'
+        if form==1 and pol==1:
+            data=TOT2_sin
+            title = 'TOT2 sin'
+        zplot = axes[form,pol].pcolormesh(L,P,data.real,vmin=0.99,vmax=1.01)
+        axes[form,pol].title.set_text(title)
+        add_colorbar(zplot)
+    zplot = axes[2,0].pcolormesh(L,P,T1_sin.real);add_colorbar(zplot)
+    axes[2,0].title.set_text('efft1 pin')
+    zplot = axes[2,1].pcolormesh(L,P,R1_sin.real);add_colorbar(zplot)
+    axes[2,1].title.set_text('effr1 pin')
+plt.savefig('BALANCE_FLAG_TOT%g.jpg'%FLAG_TOT)
+
+fig, axes = plt.subplots(3, 2, figsize=(12,12))
+L,P = np.meshgrid(tab_lam,tab_angle,indexing='ij')
+ax=axes[0,0];zplot = ax.pcolormesh(L,P,T00_sin.real  );add_colorbar(zplot);ax.title.set_text('T00 sin')
+ax=axes[1,0];zplot = ax.pcolormesh(L,P,R00_sin.real  );add_colorbar(zplot);ax.title.set_text('R00 sin')
+ax=axes[2,0];zplot = ax.pcolormesh(L,P,Qscat_sin.real);add_colorbar(zplot);ax.title.set_text('Abs sin')
+ax=axes[0,1];zplot = ax.pcolormesh(L,P,T00_pin.real  );add_colorbar(zplot);ax.title.set_text('T00 pin')
+ax=axes[1,1];zplot = ax.pcolormesh(L,P,R00_pin.real  );add_colorbar(zplot);ax.title.set_text('R00 pin')
+ax=axes[2,1];zplot = ax.pcolormesh(L,P,Qscat_pin.real);add_colorbar(zplot);ax.title.set_text('Abs pin')
+plt.savefig('BALANCE_new_code.jpg')
 
 fig, axes = plt.subplots(4, 4, subplot_kw=dict(projection='polar') ,figsize=(12,12))
 flag_lam = True
-rlabel =  r"$\lambda_0$ (nm)"
-which_r =  tab_lam
-which_orig = 0  if not flag_lam else 350
+rlabel = r"$\hbar \nu$" if not flag_lam else r"$\lambda_0$"
+anglelabel = r"$\varphi_0$" if flag_angle_study=='phi' else r"$\theta_0$"
+which_r = tab_hnu if not flag_lam else tab_lam
+which_orig = 0  #if not flag_lam else 350
 for i in range(4):
     for j in range(4):
         ax=axes[i,j]
         if i!=0 or j!=0:
-            sm=ax.contourf(tab_phi*np.pi/180,which_r,M[i,j]/M[0,0],cmap=plt.cm.bwr,levels=30)
+            # sm=ax.contourf(tab_angle*np.pi/180,which_r,M[i,j]/M[0,0],cmap=plt.cm.bwr,levels=30,vmin=-1,vmax=1)
+            sm=ax.contourf(tab_angle*np.pi/180,which_r,M[i,j]/M[0,0],cmap=plt.cm.bwr,levels=30)
             ax.text(0. , 1. , r"$M_{%d%d}$"%(i+1,j+1) , fontsize=16 , transform=ax.transAxes)
             ax.set_xticks([])
             ax.set_yticks([])
-            cbar = plt.colorbar(sm, ax=ax, fraction=0.046, pad=0.04)
-            cbar.ax.locator_params(nbins=5)
-            cbar.ax.tick_params(labelsize=14)
+            # cbar = plt.colorbar(sm, ax=ax, fraction=0.046, pad=0.04)
+            # cbar.ax.locator_params(nbins=5)
+            # cbar.ax.tick_params(labelsize=14)
         else:
-            p00 = ax.contourf(tab_phi*np.pi/180,which_r,M[i,j]/M[0,0]-1,cmap=plt.cm.bwr,vmin=-1,vmax=1)
+            p00 = ax.contourf(tab_angle*np.pi/180,which_r,M[i,j]/M[0,0]-1,cmap=plt.cm.bwr,vmin=-1,vmax=1)
             ax.xaxis.label.set_color('C0')        #setting up X-axis label color to yellow
             ax.yaxis.label.set_color('C3')          #setting up Y-axis label color to blue
             ax.tick_params(axis='x', colors='C0')    #setting up X-axis tick color to red
             ax.tick_params(axis='y', colors='C3')  #setting up Y-axis tick color to black
             ax.set_rlabel_position(70)
             ax.tick_params(axis='both', which='major', labelsize=14)
-            ax.text(np.radians(22.5),tab_lam.max()*1.03,r"$\varphi_0$",fontsize=16,color='C0')
+            ax.text(np.radians(22.5),tab_lam.max()*1.03,anglelabel,fontsize=16,color='C0')
             ax.text(np.radians(90),ax.get_rmax()/1.3,rlabel,
                     rotation=70,ha='center',va='center',fontsize=16,color='C3')
             norm = mpl.colors.Normalize(vmin=-1,vmax=1)
@@ -162,7 +197,7 @@ for i in range(4):
             sm.set_array([])
         ax.set_rorigin(which_orig)
 plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,wspace=0.35)
-# plt.savefig('Mmatrix.jpg')
-plt.savefig('Mmatrix.pdf',bbox_inches='tight',pad_inches=0)
-plt.show()
+plt.savefig('Mmatrix_%s_%s.jpg'%(flag_angle_study,str_reftrans))
+# plt.savefig('Mmatrix.pdf',bbox_inches='tight',pad_inches=0)
+# plt.show()
 
diff --git a/DiffractionGratings/grating3D_runall.sh b/DiffractionGratings/grating3D_runall.sh
index 9a90a02bb23252922d994c1b6ecfc46454d397c4..d64474eca3388bdd8b07ff97bec48f3029baeab5 100644
--- a/DiffractionGratings/grating3D_runall.sh
+++ b/DiffractionGratings/grating3D_runall.sh
@@ -1,7 +1,8 @@
 rm -r res3D*
+export OMP_NUM_THREADS=1
+export OPENBLAS_NUM_THREADS=1
 
-# for t in bi_sinusoidal checker half_ellipsoid hole pyramid torus retrieve_2D_lamellar nanowire_solarcell convergence skewed_lattice
-for t in half_ellipsoid 
+for t in bi_sinusoidal checker half_ellipsoid hole pyramid U retrieve_2D_lamellar nanowire_solarcell convergence skewed_lattice
 do
     for f in 0 1
     do
@@ -10,8 +11,7 @@ do
     done
 done
 
-# for t in bi_sinusoidal checker half_ellipsoid hole pyramid torus retrieve_2D_lamellar nanowire_solarcell convergence skewed_lattice
-for t in half_ellipsoid  
+for t in bi_sinusoidal checker half_ellipsoid hole pyramid U retrieve_2D_lamellar nanowire_solarcell convergence skewed_lattice
 do
     for f in 0 1
     do
diff --git a/DiffractionGratings/gratings_clean_all.sh b/DiffractionGratings/gratings_clean_all.sh
index a41c803309833596125beb0195ca7f8d8f83ee4b..8a635b54bf7bb2c40c1b31d291cf31a3491cd57f 100644
--- a/DiffractionGratings/gratings_clean_all.sh
+++ b/DiffractionGratings/gratings_clean_all.sh
@@ -1,7 +1,15 @@
-rm -rf res2D*
-rm -rf res3D*
+rm -r res*
+rm -r res2D*
+rm -r res3D*
 rm *.msh
 rm *.pre
 rm *.db
 rm *.pdf
+rm *.jpg
 rm *.npz
+rm *.out
+rm *.tgz
+rm *.*~
+
+
+
diff --git a/ECE_full_wave_E-H_Academic/README.txt b/ECE_full_wave_E-H_Academic/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b0259ecdd786cf910bafcf32aad4f5e7b6876127
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/README.txt
@@ -0,0 +1,49 @@
+Electric circuit element  (ECE) boundary conditions in full-wave electromagnetic problems.
+
+  Models developed by G. Ciuprina, D. Ioan and R.V. Sabariego.
+
+
+This directory contains the pro and geo files necessary to run the test cases in article:
+
+G. Ciuprina, D. Ioan, and R.V. Sabariego. Implementation and validation of the dual full-wave E and H
+  formulations with electric circuit element boundary conditions.
+  Scientific Computing in Electrical Engineering SCEE 2022. Under review, Springer International Publishing.
+
+
+Quick start
+-----------
+  Open "cyliderCoax.pro" with Gmsh.
+
+Cylinder benchmark in geo_pro/
+------------------------------
+  "cylinder2Daxi_data.pro" - contains geometrical and physical parameters used by the geo and pro files.
+  "cylinder2Daxi.geo" - contains the geometry description.
+  "cylinder2Daxi.pro" - contains the problem definition.
+
+  "cylinder3D_data.pro" - contains geometrical and physical parameters used by the geo and pro files.
+  "cylinder3D.geo" - contains the geometry description.
+  "cylinder3D.pro" - contains the problem definition.
+
+Coaxial cable benchmark in geo_pro/
+-----------------------------------
+  "coax2Daxi_data.pro" - contains geometrical and physical parameters used by the geo and pro files.
+  "coax2Daxi.geo" - contains the geometry description.
+  "coax2Daxi.pro" - contains the problem definition.
+
+  "coax3D_data.pro" - contains geometrical and physical parameters used by the geo and pro files.
+  "coax3D.geo" - contains the geometry description.
+  "coax3D.pro" - contains the problem definition.
+
+Common formulation files in formulations/
+----------------------------------------
+  "only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro" - function spaces and E-formulation
+  "FullWave_E_ece_MIMO2terminals_secondOrder.pro" - resolution and postprocessing for E-formulation, MIMO terminals
+  "FullWave_E_ece_SISO_secondOrder.pro" - resolution and postprocessing for E-formulation, SISO terminals
+
+  "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro" - function spaces and H-formulation in 2D \& 2D axi
+  "FullWave_H_ece_MIMO2terminals_cplx_2D_and_AXI_secondOrder.pro" - resolution and postprocessing for H-formulation, MIMO terminals, 2D \& 2D axi
+  "FullWave_H_ece_SISO_cplx_2D_and_AXI_secondOrder.pro" - resolution and postprocessing for H-formulation, SISO terminals, 2D \& 2D axi
+
+  "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro" - function spaces and H-formulation in 3D
+  "FullWave_H_ece_MIMO2terminals_cplx_3D_secondOrder.pro" - resolution and postprocessing for H-formulation, MIMO terminals, 2D \& 2D axi
+  "FullWave_H_ece_SISO_cplx_3D_secondOrder.pro" - resolution and postprocessing for H-formulation, SISO terminals, 3D
diff --git a/ECE_full_wave_E-H_Academic/cylinderCoax.geo b/ECE_full_wave_E-H_Academic/cylinderCoax.geo
new file mode 100644
index 0000000000000000000000000000000000000000..46b494abb6ccbad30bb18d26b540bf0425b1c0db
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/cylinderCoax.geo
@@ -0,0 +1,17 @@
+Include "cylinderCoax_data.pro";
+
+If (Flag_model == 1)     // cylinder
+  If (Flag_3Dmodel == 0) // 2D axi
+    Include "./geo_pro/cylinder2Daxi.geo";
+  Else // 3D
+    Include "./geo_pro/cylinder3D.geo";
+  EndIf
+EndIf
+
+If (Flag_model == 2)  // coaxial cable
+  If (Flag_3Dmodel == 0) // 2D axi
+    Include "./geo_pro/coax2Daxi.geo";
+  Else // 3D
+    Include "./geo_pro/coax3D.geo";
+  EndIf
+EndIf
diff --git a/ECE_full_wave_E-H_Academic/cylinderCoax.pro b/ECE_full_wave_E-H_Academic/cylinderCoax.pro
new file mode 100644
index 0000000000000000000000000000000000000000..7bacc6080e23d0c805a746e9a771985883d188c3
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/cylinderCoax.pro
@@ -0,0 +1,17 @@
+Include "cylinderCoax_data.pro";
+
+If (Flag_model == 1)     // cylinder
+  If (Flag_3Dmodel == 0) // 2D axi
+    Include "./geo_pro/cylinder2Daxi.pro";
+  Else // 3D
+    Include "./geo_pro/cylinder3D.pro";
+  EndIf
+EndIf
+
+If (Flag_model == 2)  // coaxial cable
+  If (Flag_3Dmodel == 0) // 2D axi
+    Include "./geo_pro/coax2Daxi.pro";
+  Else // 3D
+    Include "./geo_pro/coax3D.pro";
+  EndIf
+EndIf
diff --git a/ECE_full_wave_E-H_Academic/cylinderCoax_data.pro b/ECE_full_wave_E-H_Academic/cylinderCoax_data.pro
new file mode 100644
index 0000000000000000000000000000000000000000..28276da0505fe7dae3bf0636cd5d0fd25c99892a
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/cylinderCoax_data.pro
@@ -0,0 +1,120 @@
+// Cylinder and Coaxial Cable with ECE
+// uncomment only one of the lines TEST = ..... below
+
+// The geometries are in separate .geo files 2.5D / 3D   cylinder/coax => 4 geo files in the geo folder
+//                                           
+// They use separate pro files => see pro folder
+
+// The following tests should work without errors
+// TEST code of the test 7 digits - their meaning is given in the following order:
+// 1234567
+// 1 model ID: 1 for cylinder, 2 for coaxial cable
+// 2 is the submodel number 
+// 3 is 0 for voltage excitation and 1 for current excitation of terminal no 1 (cylinder - there is only one excited terminal)
+// 4 is 0 for voltage excitation and 1 for current excitation of terminal no 1 (it has a meaning only for the coaxial cable example)
+// 5 is for the model flag 0 for 2.5D and 1 for 3D
+// 6 is for the formulation 0 for E and 1 for H
+// 7 id for FE order 1 or  2
+
+DefineConstant [ // allowing an external call (-set_number), e.g. from Matlab, python or a shell	
+    TEST = 0  // for no predefined tests
+	
+	// TEST code of the test 7 digits - their meaning is given in the following order:
+	// 1234567
+	// 1 - model ID: 1 for cylindrical, 2 for coax
+	// 2 - is the submodel ID
+	// 3 is 0 for voltage excitation and 1 for current excitation - for the first excited terminal (the only one for the cylinder test)
+	// 4 is 0 for voltage excitation and 1 for current excitation - for the second excited terminal (relevant only for the coax test)
+	// 5 is for the model flag 0 for 2.5D and 1 for 3D
+	// 6 is for the formulation 0 for E and 1 for H
+	// 7 id for FE order 1 or  2
+
+	// TESTS - you can look in the s1p files in the res folder
+	//------ cylinder HF, v1, 2.5D ------
+	//TEST = 1100001    // 1) cylinder, v1, voltage excitation, - , 2.5D, formulation in E, 1st order elements  
+	//TEST = 1100002    // 2) cylinder, v1, voltage excitation, - , 2.5D, formulation in E, 2nd order elements 
+	//TEST = 1100011    // 3) cylinder, v1, voltage excitation, - , 2.5D, formulation in H, 1st order elements 
+	//TEST = 1100012    // 4) cylinder, v1, voltage excitation, - , 2.5D, formulation in H, 2nd order elements 
+    //TEST = 1110001    // 5) cylinder, v1, current excitation, - , 2.5D, formulation in E, 1st order elements  
+    //TEST = 1110002    // 6) cylinder, v1, current excitation, - , 2.5D, formulation in E, 2nd order elements
+	//TEST = 1110011    // 7) cylinder, v1, current excitation, - , 2.5D, formulation in H, 1st order elements   
+	//TEST = 1110012    // 8) cylinder, v1, current excitation, - , 2.5D, formulation in H, 2nd order elements 
+    //------ coax HF, 2.5D ------
+	//TEST = 2100001    // 9) coax HF, voltage excitation, - , 2.5D, formulation in E, 1st order elements       // needed for fig 5 in the SCEE 2022 paper
+	//TEST = 2100002    // 10) coax HF, voltage excitation, - , 2.5D, formulation in E, 2nd order elements      // needed for fig 5 in the SCEE 2022 paper
+	//TEST = 2100011    // 11) coax HF, voltage excitation, - , 2.5D, formulation in H, 1st order elements      // needed for fig 5 in the SCEE 2022 paper
+	//TEST = 2100012    // 12) coax HF, voltage excitation, - , 2.5D, formulation in H, 2nd order elements      // needed for fig 5 in the SCEE 2022 paper
+    //TEST = 2111001    // 13) coax HF, current excitation, - , 2.5D, formulation in E, 1st order elements  
+    //TEST = 2111002    // 14) coax HF, current excitation, - , 2.5D, formulation in E, 2nd order elements
+	//TEST = 2111011    // 15) coax HF, current excitation, - , 2.5D, formulation in H, 1st order elements   
+	//TEST = 2111012    // 16) coax HF, current excitation, - , 2.5D, formulation in H, 2nd order elements 
+    //------ coax LF, 2.5D ------
+	//TEST = 2200001    // 17) coax LF, voltage excitation, - , 2.5D, formulation in E, 1st order elements      // needed for fig 6 in the SCEE 2022 paper
+	//TEST = 2200002    // 18) coax LF, voltage excitation, - , 2.5D, formulation in E, 2nd order elements      // needed for fig 6 in the SCEE 2022 paper
+	//TEST = 2200011    // 19) coax LF, voltage excitation, - , 2.5D, formulation in H, 1st order elements      // needed for fig 6 in the SCEE 2022 paper
+	//TEST = 2200012    // 20) coax LF, voltage excitation, - , 2.5D, formulation in H, 2nd order elements      // needed for fig 6 in the SCEE 2022 paper
+    //TEST = 2211001    // 21) coax LF, current excitation, - , 2.5D, formulation in E, 1st order elements  
+    //TEST = 2211002    // 22) coax LF, current excitation, - , 2.5D, formulation in E, 2nd order elements
+	//TEST = 2211011    // 23) coax LF, current excitation, - , 2.5D, formulation in H, 1st order elements   
+	//TEST = 2211012    // 24) coax LF, current excitation, - , 2.5D, formulation in H, 2nd order elements 
+
+	//------ 3D
+	//------ cylinder, v1, 3D ------
+	//TEST = 1100101    // 101) cylinder, v1, voltage excitation, - , 3D, formulation in E, 1st order elements  
+	//TEST = 1100102    // 102) cylinder, v1, voltage excitation, - , 3D, formulation in E, 2nd order elements 
+	//TEST = 1100111    // 103) cylinder, v1, voltage excitation, - , 3D, formulation in H, 1st order elements 
+	//TEST = 1100112    // 104) cylinder, v1, voltage excitation, - , 3D, formulation in H, 2nd order elements 
+    //TEST = 1110101    // 105) cylinder, v1, current excitation, - , 3D, formulation in E, 1st order elements   // needed for fig 1 in the SCEE 2022 paper
+    //TEST = 1110102    // 106) cylinder, v1, current excitation, - , 3D, formulation in E, 2nd order elements
+	//TEST = 1110111    // 107) cylinder, v1, current excitation, - , 3D, formulation in H, 1st order elements   // needed for fig 1 in the SCEE 2022 paper
+	//TEST = 1110112    // 108) cylinder, v1, current excitation, - , 3D, formulation in H, 2nd order elements 
+];
+
+
+
+If (TEST == 0)  // some default setting if no predefined test is used
+	MODEL_ID = 0;   // no model chosen
+	FLAG_MODEL = 0; // 2D axi
+	
+	TERMINAL_EXC = 1;
+	TERMINAL_EXC2 = 1; 
+	FORMULATION = 0;
+	FE_ORDER = 1;
+	
+	MODEL_ID = 1 ;               // 1 for cylindrical, 2 for coax
+	MODEL_ID2 =1 ;              // 1 vor version v1 - not really used for the moment
+	TERMINAL_EXC = 0;        // 0 for voltage excitation, 1 for current excitation
+	TERMINAL_EXC2 = 0;       // second terminal - relevant only for the coax test
+	FLAG_MODEL = 1;          // 0 for 2.5 D, 1 for 3D
+	FORMULATION = 0;         // 0 for E, 1 for H
+	FE_ORDER = 1;            // 1 for order 1, 2 for order 2
+EndIf
+
+/* 2.5D */
+// Include "./tests/tests_1to8_data.pro";         /* cylinder - version v1 (SCEE 2020, JMI) - 2.5D */
+// Include "./tests/tests_9to16_data.pro";        /* coaxial cable [Wu04] with conductor inside, HF (SCEE 2022)  - 2.5D */
+// Include "./tests/tests_17to24_data.pro";       /* coaxial cable [Wu04] with conductor inside, LF (SCEE 2022)  - 2.5D */
+
+/* 3D */
+// Include "./tests/tests_101to108_data.pro";    /* cylinder - version v1 (SCEE 2020, 2022, JMI) - 3D */
+//Include "./tests/tests_109to116_data.pro";       /* coaxial cable [Wu04] with conductor inside - 3D */
+
+// If TEST == 0 , all the tests above were commented 
+/* _______Choice 1_______  chose the model 2.5D (2D axi) or 3D  */
+DefineConstant[
+	Flag_3Dmodel = {0, Choices {0,1}, 
+		Name "{Model/1Use 3D model?", Highlight "Pink"}
+	ang_section_degrees = 360
+	Flag_model = {1, Choices{1="Cylinder (SISO)",2="Coaxial cable (MIMO)"}, 
+		Name "{Model/2Choose model", Highlight "Tomato"}
+];	
+
+modelDim = (!Flag_3Dmodel)? 2: 3;
+Flag_Axi = (!Flag_3Dmodel)? 1:-1; // 2.5 D; if this flag is zero, this would mean a 2D problem, not an axisymmetric one
+h2Ddepth = (!Flag_3Dmodel)? 2*Pi:360/ang_section_degrees;
+
+
+// just to be sure that the parameters are correct
+Printf("========================= MAIN PARAMETERS =========================");
+Printf("*** *** *** ==> Flag_model   (1-Cylinder, 2-Coaxial cable, 0-Not selected) = %e",Flag_model);
+Printf("*** *** *** ==> Flag_3Dmodel (0-for 2.5D, 1 for 3D) = %e",Flag_3Dmodel);
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_MIMO2terminals_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_MIMO2terminals_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..bdb34341bc7eadc25c3d74e1804f316c245a1076
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_MIMO2terminals_secondOrder.pro
@@ -0,0 +1,92 @@
+/* FullWave_E_ece_MIMO2terminals.pro  (old name "formulationFW_E_eceBC_v6_MIMO2terminals")  
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with ECE boundary conditions.
+
+ It uses a formulation with vec{E} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in 
+ voltage or current excited terminal) and the other one is set to zero.
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro"
+
+Resolution {
+
+  { Name FullWave_E_ece;
+    System {
+      { Name Sys_Ele; NameOfFormulation FullWave_E_ece;
+        Type Complex; Frequency Freq;}
+    }
+    Operation {
+      CreateDir[StrCat[modelDir,Dir]];
+      SetTime[Freq]; // usefull to save (and print) the current frequency
+      Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+    }
+  }
+
+}
+
+PostProcessing {
+
+  { Name FW_E_ece; NameOfFormulation FullWave_E_ece;
+    Quantity {
+      { Name E; Value {
+            Local { [ {e} ]; In Vol_FW; Jacobian Vol; } // complex
+          }
+      }
+      
+      { Name J; Value {
+          Local { [ sigma[]*{e} ]; In Vol_FW; Jacobian Vol; } // complex
+        }
+      }
+      
+      { Name rmsJ; Value {
+          Local { [ Norm[sigma[]*{e}] ]; In Vol_FW; Jacobian Vol; } // real
+        }
+      }
+
+      { Name gradV; Value {
+          Local { [ {dv} ]; In Vol_FW; Jacobian Vol; } // complex
+        }
+      }
+
+      { Name Vterminal; Value {
+        Term { [ -{V} ]; In Terminal1; } 
+        Term { [ -{V} ]; In Terminal2; } 
+        }
+      }
+
+      { Name Iterminal; Value { 
+        Term { [ -1*{I}*h2Ddepth ]; In Terminal1; } 
+        Term { [ -1*{I}*h2Ddepth ]; In Terminal2; } 
+        }  
+      } 
+      
+      { Name VnotTerminals; Value {
+          Local { [ -{dInv dv} ]; In Vol_FW; Jacobian Vol; }
+        }
+      }
+	  
+      { Name B; Value {
+          Local { [ CompZ[{d e}]/(2*Pi*Freq*Complex[0,1]) ]; In Vol_FW; Jacobian Vol; }
+        }
+      }
+
+      { Name H; Value {
+        Local { [ -nu[]*{d e}/(2*Pi*Freq*Complex[0,1]) ]; In Vol_FW; Jacobian Vol; }
+        }
+      }
+      
+      { Name Hz; Value {
+        Local { [ nu[]*CompZ[{d e}]/(2*Pi*Freq*Complex[0,1]) ]; In Vol_FW; Jacobian Vol; }
+        }
+      }
+    }
+  }
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_SISO_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_SISO_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..d61512454c155ab3825fac73ef7d1023c0fefde3
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_E_ece_SISO_secondOrder.pro
@@ -0,0 +1,89 @@
+/* FullWave_E_ece_SISO.pro 
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with radiant ECE boundary conditions.
+
+ It uses a formulation with vec{E} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in
+ voltage or current excited terminal).
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro"
+
+Resolution {
+	{ Name FullWave_E_ece;
+		System {
+			{ Name Sys_Ele; NameOfFormulation FullWave_E_ece; Type Complex; Frequency Freq;}
+		}
+		Operation {
+			CreateDir[StrCat[modelDir,Dir]];
+			SetTime[Freq];  // usefull to save (and print) the current frequency
+			Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+		}
+	}
+}
+
+PostProcessing {
+
+	{ Name FW_E_ece; NameOfFormulation FullWave_E_ece;
+		Quantity {
+			{ Name E; Value {Local { [ {e} ]; In Vol_FW; Jacobian Vol; }}} // complex
+			{ Name rmsE;  Value { Local { [ Norm[{e}] ];         In Vol_FW; Jacobian Vol; }}} // complex
+			{ Name J;     Value { Local { [ sigma[]*{e} ];       In Vol_FW; Jacobian Vol; }}} // complex
+			{ Name rmsJ;  Value { Local { [ Norm[sigma[]*{e}] ]; In Vol_FW; Jacobian Vol; }}} // real
+			{ Name gradV; Value { Local { [ {dv} ];              In Vol_FW; Jacobian Vol; }}} // complex
+
+			{ Name Vterminal; Value {
+				  Term { [ -{V} ]; In Sur_Terminals_FWece; } // => unknowns only in Sur_Terminals_FWece, outside it will be zero
+				}
+			}
+
+			{ Name Rin;  Value { Term { [ Re[-{V}] ]; In Sur_Terminals_FWece; }}}
+			{ Name Xin;  Value { Term { [ Im[-{V}] ]; In Sur_Terminals_FWece; }}}
+      { Name AbsZin; Value { Term { [Norm[-{V}] ]; In Sur_Terminals_FWece; }}}
+			{ Name ArgZin; Value { Term { [Atan2[ Im[-{V}], Re[-{V}]] ]; In Sur_Terminals_FWece; }}}
+
+			{ Name I; Value {
+        Term { [ -{I}*h2Ddepth ]; In Sur_Terminals_FWece; }
+				}
+			}  // h2Ddepth is the depth for 2D problems,  and it has to be 1 for 3D problems
+
+			// Yin = I/V = Gin + j Bin
+			{ Name Yin;    Value { Term { [ -{I}*h2Ddepth * Conj[-{V}]/SquNorm[{V}] ]; In Sur_Terminals_FWece; }}}
+			{ Name AbsYin; Value { Term { [ Norm[-{I}*h2Ddepth * Conj[-{V}]/SquNorm[{V}]] ]; In Sur_Terminals_FWece; }}}
+			{ Name ArgYin; Value { Term { [ Atan2[ Im[-{I}*h2Ddepth * Conj[-{V}]/SquNorm[{V}]], Re[ -{I}*h2Ddepth * Conj[-{V}]/SquNorm[{V}]] ] ]; In Sur_Terminals_FWece; }}}
+
+			{ Name Gin;  Value { Term { [Re[ -{I}*h2Ddepth ]]; In Sur_Terminals_FWece; }}}
+			{ Name Bin;  Value { Term { [Im[ -{I}*h2Ddepth ]]; In Sur_Terminals_FWece; }}}
+			{ Name AbsYin_; Value { Term { [ Norm[-{I}*h2Ddepth ] ]; In Sur_Terminals_FWece; }}}
+			{ Name ArgYin_; Value { Term { [ Atan2[ Im[-{I}*h2Ddepth ], Re[-{I}*h2Ddepth ]] ]; In Sur_Terminals_FWece; }}}
+
+			{ Name VnotTerminals; Value { 
+				Local { [ -{dInv dv} ];  In Vol_FW; Jacobian Vol; }
+				Local { [ -{dInv dvf} ]; In Vol_FW; Jacobian Vol; }
+			}}
+
+			{ Name B; Value {
+					Local { [ {d e}/(2*Pi*Freq*Complex[0,1]) ]; In Vol_FW; Jacobian Vol; }
+				}
+			}
+
+			{ Name H; Value {
+					Local { [ -nu[]*{d e}/(2*Pi*Freq*Complex[0,1]) ]; In Vol_FW; Jacobian Vol; }
+				}
+			}
+
+			{ Name rmsH; Value {
+          Local { [Norm[ -nu[]*{d e}/(2*Pi*Freq*Complex[0,1]) ]]; In Vol_FW; Jacobian Vol; }
+				}
+			}
+			
+		}
+	}
+ }
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_2D_and_AXI_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_2D_and_AXI_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..16badf76d17a01e1cfc19b6e3334a0c995c7ba39
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_2D_and_AXI_secondOrder.pro
@@ -0,0 +1,87 @@
+/* FullWave_H_ece_SISO_cplx_3D.pro  
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with ECE boundary conditions.
+
+ It uses a formulation with vec{H} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in 
+ voltage or current excited terminal). 
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro"
+
+Resolution {
+  
+  { Name FullWave_H_ece;
+    System {
+      { Name Sys_Ele; NameOfFormulation FullWave_H_ece;
+        Type Complex; Frequency Freq;}
+
+    }
+    Operation {
+	  CreateDir[StrCat[modelDir,Dir]];
+	  SetTime[Freq];               // usefull to save (and print) the current frequency
+    Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+    }
+  }
+
+}
+
+PostProcessing {
+ { Name FW_H_ece; NameOfFormulation FullWave_H_ece;
+    Quantity {
+      { Name H; Value {
+        Local { [ {h} ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+      { Name Hz ; Value { 
+        Local{ [ CompZ[{h}] ] ; In Dom_FW ; Jacobian Vol ; }
+        }
+      }
+
+      { Name E; Value {
+        Local { [ {d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+      
+      { Name Ey; Value {
+          Local { [ CompY[{d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+      { Name J; Value {
+        Local { [ {d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+    
+      { Name rmsJ; Value {
+        Local { [ Norm[{d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+      
+      { Name rmsH; Value {
+        Local { [ Norm[{h}] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }      
+
+      { Name Vterminal; Value {
+        Term { [  {V} ]; In Cut1Hterminal1; }  
+        Term { [ -{V} ]; In Cut1Hterminal2; }
+        }
+      }
+      
+      { Name Iterminal; Value { 
+        Term { [ -{I}*h2Ddepth ]; In Cut1Hterminal1; } 
+        Term { [  {I}*h2Ddepth ]; In Cut1Hterminal2; } 
+        }     
+      }
+    } 
+  }
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_3D_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_3D_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..b3ee31c59411e7f32504cd952e62c2804dd87f25
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_MIMO2terminals_cplx_3D_secondOrder.pro
@@ -0,0 +1,87 @@
+/* FullWave_H_ece_SISO_cplx_3D.pro  
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with ECE boundary conditions.
+
+ It uses a formulation with vec{H} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in 
+ voltage or current excited terminal). 
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro"
+
+Resolution {
+  { Name FullWave_H_ece;
+    System {
+      { Name Sys_Ele; NameOfFormulation FullWave_H_ece;
+        Type Complex; Frequency Freq;}
+
+    }
+    Operation {
+	    CreateDir[StrCat[modelDir,Dir]];
+	    SetTime[Freq];              
+      Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+    }
+  }
+
+}
+
+PostProcessing {
+  { Name FW_H_ece; NameOfFormulation FullWave_H_ece;
+    Quantity {
+      { Name H; Value {
+          Local { [ {h} ]; In Dom_FW; Jacobian Vol; } 
+        }
+      }
+
+      { Name Hz ; Value { 
+		      Local{ [ CompZ[{h}] ] ; In Dom_FW ; Jacobian Vol ; }
+        }
+      }
+
+	    { Name E; Value {
+          Local { [ {d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+	    { Name J; Value {
+          Local { [ {d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+	    { Name rmsJ; Value {
+          Local { [ Norm[{d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+	  
+	    { Name rmsH; Value {
+          Local { [ Norm[{h}] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+	    { Name Ey; Value {
+          Local { [ CompY[{d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Dom_FW; Jacobian Vol; }
+        }
+      }
+
+	    { Name Vterminal; Value {
+		    Term { [  {V} ]; In Cut1Hterminal1; }
+		    Term { [ -{V} ]; In Cut1Hterminal2; }
+        }
+      }
+	  
+      { Name Iterminal; Value { 
+          Term { [ -{I}*h2Ddepth ]; In Cut1Hterminal1; }   
+          Term { [ -{I}*h2Ddepth ]; In Cut1Hterminal2; }   
+          // h is the depth for 2D problems,  and it has to be 1 for 3D problems
+  	    }
+      }    
+    }
+  } 
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_2D_and_AXI_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_2D_and_AXI_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..4a776b5fb34f804facf238ba20db4cbc22dd5f54
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_2D_and_AXI_secondOrder.pro
@@ -0,0 +1,104 @@
+/* FullWave_H_ece_SISO_cplx_2D.pro/
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with ECE boundary conditions.
+
+ It uses a formulation with vec{H} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in
+ voltage or current excited terminal).
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro"
+
+Resolution {
+	{ Name FullWave_H_ece;
+		System {
+			{ Name Sys_Ele; NameOfFormulation FullWave_H_ece; Type Complex; Frequency Freq;}
+		}
+		Operation {
+			CreateDir[StrCat[modelDir,Dir]];
+			SetTime[Freq];               
+			Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+		}
+	}
+}
+
+PostProcessing {
+
+	{ Name FW_H_ece; NameOfFormulation FullWave_H_ece;
+		Quantity {
+			{ Name H;    Value { Local { [ {h} ];       In Vol_FW; Jacobian Vol; }}} 
+			{ Name rmsH; Value { Local { [ Norm[{h}] ]; In Vol_FW; Jacobian Vol; }}}
+			{ Name Hz ;  Value { Local{ [ CompZ[{h}] ]; In Vol_FW ; Jacobian Vol ;}}}
+
+			{ Name E;	 Value {	Local { [ {d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Vol_FW; Jacobian Vol; }}}
+			{ Name J;	 Value {	Local { [ {d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Vol_FW; Jacobian Vol; }}}
+			{ Name rmsJ; Value {	Local { [ Norm[{d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Vol_FW; Jacobian Vol; }}}
+			{ Name Ey;	Value {	Local { [ CompY[{d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Vol_FW; Jacobian Vol; }}}
+
+			{ Name Vterminal;	Value {	Term { [ -1*{V} ]; In Cut1H; }}}
+
+			{ Name Rin;	Value {Term { [ Re[-1*{V}] ]; In Cut1H; }}}
+			{ Name Xin;	Value {Term { [ Im[-1*{V}] ]; In Cut1H; }}}
+			{ Name AbsZin; Value { 
+          Term { [ Norm[-1*{V}] ]; In Cut1H; } 
+				}
+			}
+			{ Name ArgZin; Value { 
+          Term { [Atan2[Im[-1*{V} ],Re[ -1*{V} ]]]; In Cut1H; } 
+				}
+			}
+	  
+			{ Name I;         	     
+				Value { 
+					If(Flag_Axi == 0) // 2D 
+						Term { [ -2*{I}*h2Ddepth ]; In Cut1H; } 
+					Else  // 2D axisymmetric
+						Term { [ -{I}*h2Ddepth ]; In Cut1H; } 
+					EndIf
+				}   // h is the depth for 2D problems,  and it has to be 1 for 3D problems
+			} 
+
+			{ Name Gin; Value { 
+					If(Flag_Axi == 0) // 2D 
+						Term { [Re[ -2*{I}*h2Ddepth ]]; In Cut1H; } 
+					Else
+						Term { [Re[ -{I}*h2Ddepth ]]; In Cut1H; } 
+					EndIf
+				}  
+			}	
+
+			{ Name Bin; Value { 
+					If(Flag_Axi == 0) // 2D 
+						Term { [Im[ -2*{I}*h2Ddepth ]]; In Cut1H; } 
+					Else
+						Term { [Im[ -{I}*h2Ddepth ]]; In Cut1H; } 
+					EndIf
+				}  
+			}
+
+			{ Name AbsYin; Value { 
+					If(Flag_Axi == 0) // 2D 
+						Term { [ Norm[-2*{I}*h2Ddepth ] ]; In Cut1H; } 
+					Else
+						Term { [ Norm[ -{I}*h2Ddepth ] ]; In Cut1H; } 
+					EndIf  
+				}
+			}
+			{ Name ArgYin; Value { 
+          Term { [Atan2[Im[ -{I}*h2Ddepth ],Re[ -{I}*h2Ddepth ]]]; In Cut1H; } 
+				}
+			} 	    
+		}
+	}
+}  
+ 
+ 
+	  
+	
diff --git a/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_3D_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_3D_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..e53aafd460b109e66733f1a18d66251115a968bd
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/FullWave_H_ece_SISO_cplx_3D_secondOrder.pro
@@ -0,0 +1,61 @@
+/* FullWave_H_ece_SISO_cplx_3D_secondOrder.pro   
+
+ Problem independent pro file
+ for passive, linear domains in Full Wave with ECE boundary conditions.
+
+ It uses a formulation with vec{H} strictly inside the domain and V strictly on the boundary.
+ The domain is simply connected, it has only electric terminals.
+ The terminals can be voltage or current excited.
+ The material inside is linear from all points of view: electric, magnetic, conduction
+ It is compulsory that there exists a ground terminal (its voltage is set to zero).
+ The post-operation assumes that there is one excited (active) terminal  (excitation equal to 1 - it can be in 
+ voltage or current excited terminal). 
+ Frequency domain simulations.
+*/
+
+Include "Jacobian_and_Integration.pro"
+Include "only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro"
+
+Resolution {
+  { Name FullWave_H_ece;
+    System {
+      { Name Sys_Ele; NameOfFormulation FullWave_H_ece; Type Complex; Frequency Freq;}
+    }
+    Operation {
+      CreateDir[StrCat[modelDir,Dir]];
+      SetTime[Freq]; 
+      Generate[Sys_Ele]; Solve[Sys_Ele]; SaveSolution[Sys_Ele];
+    }
+  }
+}
+
+
+PostProcessing {
+
+  { Name FW_H_ece; NameOfFormulation FullWave_H_ece;
+    Quantity {
+      { Name H;    Value { Local { [ {h} ];       In Vol_FW; Jacobian Vol; }}} 
+      { Name rmsH; Value { Local { [ Norm[{h}] ]; In Vol_FW; Jacobian Vol; }}}
+      { Name Hz ;  Value { Local{ [ CompZ[{h}] ]; In Vol_FW ; Jacobian Vol ;}}}
+
+      { Name E;	 Value {	Local { [ {d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Vol_FW; Jacobian Vol; }}}
+      { Name J;	 Value {	Local { [ {d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[]) ]; In Vol_FW; Jacobian Vol; }}}
+      { Name rmsJ; Value {	Local { [ Norm[{d h}*sigma[]/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Vol_FW; Jacobian Vol; }}}
+      { Name Ey;	Value {	Local { [ CompY[{d h}/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])] ]; In Vol_FW; Jacobian Vol; }}}
+
+      { Name Vterminals;	Value {	Term { [ -1*{V} ]; In Cut1H; }}}
+
+      { Name Rin;	Value {Term { [ Re[-1*{V}] ]; In Cut1H; }}}
+      { Name Xin;	Value {Term { [ Im[-1*{V}] ]; In Cut1H; }}}
+      { Name AbsZin;   	Value { Term { [Sqrt[Im[ -1*{V} ]^2 + Re[ -1*{V} ]^2]]; In Cut1H; }}}
+      { Name ArgZin; 		Value { Term { [Atan2[Im[ -1*{V} ],Re[ -1*{V} ]]]; In Cut1H; }}}	
+
+            { Name I;           Value { Term { [ -{I}*h2Ddepth ]; In Cut1H; }}}  // h2depth = 1 for 3D problems
+            
+      { Name Gin;         Value { Term { [Re[ -{I}*h2Ddepth ]]; In Cut1H; }}} 
+      { Name Bin;         Value { Term { [Im[ -{I}*h2Ddepth ]]; In Cut1H; }}}
+      { Name AbsYin;   	Value { Term { [Norm[ -{I}*h2Ddepth ]]; In Cut1H; }}}
+      { Name ArgYin; 		Value { Term { [Atan2[Im[ -{I}*h2Ddepth ],Re[ -{I}*h2Ddepth ]]]; In Cut1H; }}}	    
+    }
+  }
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/Jacobian_and_Integration.pro b/ECE_full_wave_E-H_Academic/formulations/Jacobian_and_Integration.pro
new file mode 100644
index 0000000000000000000000000000000000000000..42eb12f44fd310b5720303c730b3c9c4b6466ebf
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/Jacobian_and_Integration.pro
@@ -0,0 +1,68 @@
+Jacobian {
+	{ Name Vol;
+		Case {
+			If(Flag_Axi) 
+				{ Region All; Jacobian VolAxiSqu; }  
+			Else
+				{ Region All; Jacobian Vol; }
+			EndIf
+		}
+	}
+	{ Name Sur;
+		Case {
+			If(Flag_Axi) // 2D axisymetric problems
+				{ Region All; Jacobian SurAxi; }
+			Else
+				{ Region All; Jacobian Sur; }
+			EndIf
+		}
+	}
+}
+
+Integration {
+	{ Name Int;
+		If(FE_Order !=2)  // Adapt gauss integration points with higher order
+			Case {
+				{ Type Gauss;
+					Case {
+						{ GeoElement Point; NumberOfPoints  1; }
+						{ GeoElement Line; NumberOfPoints  3; }
+						{ GeoElement Triangle; NumberOfPoints  3; }
+						{ GeoElement Quadrangle; NumberOfPoints  4; }
+						{ GeoElement Tetrahedron; NumberOfPoints  4; }
+						{ GeoElement Hexahedron; NumberOfPoints  6; }
+						{ GeoElement Prism; NumberOfPoints  9; }
+						{ GeoElement Pyramid; NumberOfPoints  8; }
+
+						// 2nd order with geometry
+						{ GeoElement Line2; NumberOfPoints 4; }
+						{ GeoElement Triangle2; NumberOfPoints 12; }
+						{ GeoElement Quadrangle2; NumberOfPoints 12; }
+						{ GeoElement Tetrahedron2; NumberOfPoints 17; }
+					}
+				}
+			}
+		Else
+			Case {
+				{ Type Gauss;
+					Case {
+						{ GeoElement Point; NumberOfPoints  1; }
+						{ GeoElement Line; NumberOfPoints  10; }
+						{ GeoElement Triangle; NumberOfPoints 16 ; }
+						{ GeoElement Quadrangle; NumberOfPoints  7; }
+						{ GeoElement Tetrahedron; NumberOfPoints  15; }
+						{ GeoElement Hexahedron; NumberOfPoints  6; }
+						{ GeoElement Prism; NumberOfPoints  9; }
+						{ GeoElement Pyramid; NumberOfPoints  8; }
+
+						// 2nd order with geometry
+						{ GeoElement Line2; NumberOfPoints 4; }
+						{ GeoElement Triangle2; NumberOfPoints 12; }
+						{ GeoElement Quadrangle2; NumberOfPoints 12; }
+						{ GeoElement Tetrahedron2; NumberOfPoints 17; }
+					}
+				}
+			}
+		EndIf
+	}
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..68ac29bb51e8aa4ef4704589fb26115933418e7c
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_E_ece_secondOrder.pro
@@ -0,0 +1,78 @@
+FunctionSpace {
+
+	{ Name Hcurl_E; Type Form1;
+		BasisFunction {
+			{ Name se; NameOfCoef ee; Function BF_Edge; 
+				Support Dom_FW ; Entity EdgesOf[All, Not Sur_FW]; }
+			
+			If(FE_Order == 2)
+			// additional basis functions for 2nd order interpolation (hierachical)
+        { Name se2; NameOfCoef ee2; Function BF_Edge_2E;  
+					Support Dom_FW; Entity EdgesOf[All, Not Sur_FW]; }        
+				// Reduced 2nd order
+				{ Name se3a ; NameOfCoef ee3a ; Function BF_Edge_3F_a ;
+					Support Dom_FW ; Entity FacetsOf[All, Not Sur_FW] ; }
+				{ Name se3b ; NameOfCoef ee3b ; Function BF_Edge_3F_b ;
+					Support Dom_FW ; Entity FacetsOf[ All, Not Sur_FW] ; }
+				// 2nd order
+				{ Name se4; NameOfCoef ee4; Function BF_Edge_4E;
+					Support Dom_FW ; Entity EdgesOf[All, Not Sur_FW]; }
+			EndIf
+
+      { Name sn; NameOfCoef vn; Function BF_GradNode; 
+        Support Dom_FW ; Entity NodesOf[Sur_FW, Not Sur_Terminals_FWece]; } 
+      If(FE_Order == 2)
+        // GradNode BFs
+        { Name sn2; NameOfCoef vn2; Function BF_GradNode_2E;
+          Support Dom_FW ; Entity EdgesOf[Sur_FW, Not Sur_Terminals_FWece]; }
+      EndIf		 
+
+	    { Name sf; NameOfCoef vf; Function BF_GradGroupOfNodes; 
+		  Support Dom_FW ; Entity GroupsOfNodesOf[Sur_Terminals_FWece]; }
+    }
+
+		GlobalQuantity {
+			{ Name TerminalPotential; Type AliasOf       ; NameOfCoef vf; }
+			{ Name TerminalCurrent  ; Type AssociatedWith; NameOfCoef vf; }
+		}
+
+		SubSpace {
+			{ Name dv ; NameOfBasisFunction {sn}; } // Subspace, it maybe use in equations or post-pro
+			{ Name dvf ; NameOfBasisFunction {sf}; } 
+		}
+
+		Constraint {
+			{ NameOfCoef TerminalPotential; EntityType GroupsOfNodesOf;
+				NameOfConstraint SetTerminalPotential; }
+			{ NameOfCoef TerminalCurrent; EntityType GroupsOfNodesOf;
+				NameOfConstraint SetTerminalCurrent; }
+		}
+	}
+}
+ 
+Formulation {
+
+	{ Name FullWave_E_ece; Type FemEquation;
+		Quantity {
+			{ Name e;  Type Local; NameOfSpace Hcurl_E; }
+			{ Name dv; Type Local; NameOfSpace Hcurl_E[dv]; } // Just for post-processing issues
+			{ Name dvf; Type Local; NameOfSpace Hcurl_E[dvf]; } 
+			{ Name V;  Type Global; NameOfSpace Hcurl_E[TerminalPotential]; }
+			{ Name I;  Type Global; NameOfSpace Hcurl_E[TerminalCurrent]; }
+		}
+		Equation {
+			// \int_D curl(\vec{E}) \cdot  curl(\vec{e}) dv
+			Galerkin { [ nu[] * Dof{d e} , {d e} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+
+			// \int_D j*\omega*(\sigma + j*\omega*\epsilon) \vec{E} \cdot \vec{e} dv
+			Galerkin { DtDof   [ sigma[]   * Dof{e} , {e} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+			Galerkin { DtDtDof [ epsilon[] * Dof{e} , {e} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+
+			//    alternative // j*\omega*sum (vk Ik);  for k - current excited terminals
+			//    GlobalTerm {DtDof [ -Dof{I} , {V} ]; In SurBCec; }
+
+			// j*\omega*sum (vk Ik);  for k - all terminals so that the currents through the terminals will be computed as well
+			GlobalTerm { DtDof [ -Dof{I} , {V} ]; In Sur_Terminals_FWece; }  
+		}
+	}
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..a6606a1b5988b853ec82fe9106d18a096692b08e
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_2D_and_AXI_secondOrder.pro
@@ -0,0 +1,72 @@
+//=========================================================
+// Function spaces
+//=========================================================
+
+FunctionSpace {
+  
+	{ Name Hcurl_H; Type Form1P;  // Hspace for 2D problems with H perpendicular to the plane
+		BasisFunction {
+      { Name se; NameOfCoef he; Function BF_PerpendicularEdge;
+        Support Dom_FW; Entity NodesOf[All, Not BoundaryNotTerminal]; }
+      { Name sc; NameOfCoef ic; Function BF_GroupOfPerpendicularEdges;
+        Support Dom_FW; Entity GroupsOfNodesOf[BoundaryNotTerminal]; }
+    
+      If(FE_Order == 2) // hierarchical basis functions for 2nd order interpolation 
+        { Name se2; NameOfCoef he2; Function BF_PerpendicularEdge_2E;
+          Support Dom_FW; Entity EdgesOf[All, Not BoundaryNotTerminal]; }
+        { Name sf2; NameOfCoef hf2; Function BF_PerpendicularEdge_2F;
+          Support Dom_FW; Entity FacetsOf[All, Not BoundaryNotTerminal]; }
+      EndIf		  
+		}
+
+		GlobalQuantity {
+			{ Name TerminalCurrent;   Type AliasOf       ; NameOfCoef ic; }
+			{ Name TerminalPotential; Type AssociatedWith; NameOfCoef ic; }
+		}
+
+		Constraint {
+			{ NameOfCoef TerminalPotential; EntityType Auto; NameOfConstraint SetTerminalPotentialH; }
+			{ NameOfCoef TerminalCurrent;   EntityType Auto; NameOfConstraint SetTerminalCurrentH; }
+     
+			{ NameOfCoef he; EntityType Auto; NameOfConstraint ImposeHonAxis; }
+			If(FE_Order==2)
+				{ NameOfCoef he2; EntityType Auto; NameOfConstraint ImposeHonAxis; }  
+				{ NameOfCoef hf2; EntityType Auto; NameOfConstraint ImposeHonAxis; }
+			EndIf
+		}
+	}
+}
+
+Function{
+  Omega = 2*Pi*Freq;
+  jOmega[] = Complex[0,1]*Omega;
+  jOmega2[] = -Omega^2;
+
+  tensSuma[] = sigma[]/jOmega[] + epsilon[];
+  alpha[] = 1/tensSuma[];
+  alphaIm[] = Complex[0,1]*Im[alpha[]];
+  alphaRe[] = Re[alpha[]];
+}
+
+Formulation {
+  
+	{ Name FullWave_H_ece; Type FemEquation;
+		Quantity {
+			{ Name h; Type Local;  NameOfSpace Hcurl_H; }
+			{ Name V; Type Global; NameOfSpace Hcurl_H[TerminalPotential]; }
+			{ Name I; Type Global; NameOfSpace Hcurl_H[TerminalCurrent]; }
+		}
+		Equation {
+			// multiplying with j omega
+			// \int_D \alpha * curl(\vec{H}) \cdot  curl(\vec{h}) dv
+			Galerkin { [ alphaRe[] * Dof{d h} , {d h} ];      In Vol_FW; Jacobian Vol; Integration Int; }
+			Galerkin { [ alphaIm[] * Dof{d h} , {d h} ];      In Vol_FW; Jacobian Vol; Integration Int; }
+	    
+			// \int_D j*\omega*(j*\omega*\mu) \vec{H} \cdot \vec{h} dv
+			Galerkin { [ jOmega2[] * mu[] * Dof{h} , {h} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+	  
+			// sum (Vk ik);  for k - all terminals so that the terminal voltages will be computed as well
+			GlobalTerm { [ jOmega[]*Dof{V}, {I} ]; In Cut1H; }
+		}
+	}
+}
diff --git a/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro
new file mode 100644
index 0000000000000000000000000000000000000000..4d4992a8024ed480f4a8a66a7c4b0d247f446b8e
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/formulations/only_FunctionSpace_and_Formulation_FullWave_H_ece_cplx_3D_secondOrder.pro
@@ -0,0 +1,103 @@
+//=========================================================
+// Function spaces
+//=========================================================
+
+FunctionSpace {
+
+	{ Name Hcurl_H; Type Form1;   // Hspace for 3D
+		BasisFunction {	
+      { Name se; NameOfCoef he; Function BF_Edge;
+        Support Dom_FW;	Entity EdgesOf[All, Not BoundaryNotTerminal]; }
+        
+      { Name sn; NameOfCoef phin; Function BF_GradNode;
+        Support Dom_FW; Entity NodesOf[BoundaryNotTerminal]; }
+
+      { Name sc; NameOfCoef ic; Function BF_GroupOfEdges;
+        Support Dom_FW;	Entity GroupsOfEdgesOf[Cut1H]; }
+
+      If(FE_Order == 2) // hierarchical basis functions for 2nd order interpolation 
+        // Edge BFs => FEorder = {0.5, Choices{0.5="Lowest",1="1st order",1.5="Reduced 2nd order",2="2nd order"}
+        // 1st order
+        { Name se2; NameOfCoef ee2; Function BF_Edge_2E;  
+        Support Dom_FW; Entity EdgesOf[All, Not BoundaryNotTerminal]; }        
+        // Reduced 2nd order
+        { Name se3a ; NameOfCoef ee3a ; Function BF_Edge_3F_a ;
+        Support Dom_FW ; Entity FacetsOf[All, Not BoundaryNotTerminal] ; }
+        { Name se3b ; NameOfCoef ee3b ; Function BF_Edge_3F_b ;
+        Support Dom_FW ; Entity FacetsOf[ All, Not BoundaryNotTerminal] ; }
+        // 2nd order
+        { Name se4; NameOfCoef ee4; Function BF_Edge_4E;
+        Support Dom_FW ; Entity EdgesOf[All, Not BoundaryNotTerminal]; }
+      
+        // GradNode BFs
+        { Name sn2; NameOfCoef vn2; Function BF_GradNode_2E;
+        Support Dom_FW ; Entity EdgesOf[BoundaryNotTerminal]; }
+      EndIf	
+    }
+	
+    GlobalQuantity {
+      { Name TerminalCurrent;   Type AliasOf       ; NameOfCoef ic; }
+      { Name TerminalPotential; Type AssociatedWith; NameOfCoef ic; }
+    }
+	
+    Constraint {
+      { NameOfCoef TerminalPotential; EntityType GroupsOfEdgesOf;
+        NameOfConstraint SetTerminalPotentialH; }
+      { NameOfCoef TerminalCurrent; EntityType GroupsOfEdgesOf;
+        NameOfConstraint SetTerminalCurrentH; }
+    }
+  }  
+}
+
+Function{
+  Omega = 2*Pi*Freq;
+  jOmega[] = Complex[0,1]*Omega;
+  jOmega2[] = -Omega^2;
+
+  alphaIm[] = jOmega[]*sigma[]/(sigma[]^2+Omega^2*epsilon[]^2);
+  alphaRe[] = Omega^2*epsilon[]/(sigma[]^2+Omega^2*epsilon[]^2);
+  
+  alphaImSigmaZero[] = 0;
+  alphaReSigmaZero[] = 1/epsilon[];
+  
+}
+
+Formulation {
+
+   { Name FullWave_H_ece; Type FemEquation;
+    Quantity {
+      { Name h; Type Local;  NameOfSpace Hcurl_H; }
+      { Name V; Type Global; NameOfSpace Hcurl_H[TerminalPotential]; }
+      { Name I; Type Global; NameOfSpace Hcurl_H[TerminalCurrent]; }
+    }
+    Equation {
+      // multiplying with j omega
+      // \int_D \alpha * curl(\vec{H}) \cdot  curl(\vec{h}) dv
+	
+      Galerkin { [ alphaRe[] * Dof{d h} , {d h} ];      In Vol_FW; Jacobian Vol; Integration Int; }
+      Galerkin { [ alphaIm[] * Dof{d h} , {d h} ];      In Vol_FW; Jacobian Vol; Integration Int; }
+
+      // \int_D j*\omega*(j*\omega*\mu) \vec{H} \cdot \vec{h} dv
+      Galerkin { [ jOmega2[] * mu[] * Dof{h} , {h} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+	  
+      // sum (Vk ik);  for k - all terminals so that the terminal voltages will be computed as well
+      GlobalTerm { [ jOmega[]*Dof{V}, {I} ]; In Cut1H; }
+    }
+  }
+  
+  { Name FullWave_H_ece_G; Type FemEquation;
+    Quantity {
+      { Name h; Type Local;  NameOfSpace Hcurl_H; }
+      { Name V; Type Global; NameOfSpace Hcurl_H[TerminalPotential]; }
+      { Name I; Type Global; NameOfSpace Hcurl_H[TerminalCurrent]; }
+    }
+    Equation {
+      // without multiplying with j omega
+      Galerkin { [ (1/(sigma[]+Complex[0,1]*2*Pi*Freq*epsilon[])) * Dof{d h} , {d h} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+      Galerkin { [ Complex[0,1]*2*Pi*Freq* mu[] * Dof{h} , {h} ]; In Vol_FW; Jacobian Vol; Integration Int; }
+
+      // sum (Vk ik);  for k - all terminals so that the terminal voltages will be computed as well
+      GlobalTerm { [ Dof{V}, {I} ]; In Cut1H; }
+    }
+  }
+}
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.geo b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.geo
new file mode 100644
index 0000000000000000000000000000000000000000..c829d7dcc9562b9ef50f263c54f64f479d250c7d
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.geo
@@ -0,0 +1,55 @@
+Include "coax2Daxi_data.pro";
+
+// Definition of parameters for local mesh dimensions
+p0 = s*l/10; // characteristic length of mesh element
+
+// Definition of gemetrical points
+Point(1) = { 0, 0, 0, p0} ;
+Point(2) = { a, 0, 0, p0} ;
+Point(3) = { a, l, 0, p0} ;
+Point(4) = { 0, l, 0, p0} ;
+Point(5) = { b, 0, 0, p0} ;
+Point(6) = { b, l, 0, p0} ;
+
+// Definition of gemetrical lines
+Line(1) = {1,2};
+Line(2) = {2,3};
+Line(3) = {3,4};
+Line(4) = {4,1};
+Line(5) = {2,5};
+Line(6) = {5,6};
+Line(7) = {3,6};
+
+// Definition of geometrical surfaces
+Line Loop(5) = {1, 2, 3, 4};
+Plane Surface(6) = {5};
+Line Loop(7) = {5, 6, -7, -2};
+Plane Surface(8) = {7};
+
+If(_use_transfinite)
+  Transfinite Line {2,4,6} = 9*s; // 8  discretizations
+  Transfinite Line {1,3,5,7} = 4*s; 
+  Transfinite Surface {6,8};
+  If (_use_recombine)
+    Recombine Surface{6,8};
+  EndIf
+EndIf
+
+/* Definition of Physical entities (surfaces, lines). The Physical
+   entities tell GMSH the elements and their associated region numbers
+   to save in the file 'Ishape2d.msh'. */
+
+Physical Surface ("Conductor", 100) = {6} ;   
+Physical Surface ("Air", 101) = {8} ;    
+
+Physical Line ("Terminal1", 121) = {1} ;          
+Physical Line ("Terminal2", 122) = {3} ;          
+Physical Line ("Ground",   120) = {6} ;          
+
+Physical Line ("LeftBoundary", 132) = {4} ;      
+Physical Line ("BottomBoundary", 133) = {5} ; 
+Physical Line ("TopBoundary", 134) = {7} ; 
+
+// For aestetics
+Recursive Color SkyBlue { Surface{8};}
+Recursive Color Red  { Surface{6};}
\ No newline at end of file
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.pro b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.pro
new file mode 100644
index 0000000000000000000000000000000000000000..6ac9de314565ed6cd809251cecbc803312b5aec6
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi.pro
@@ -0,0 +1,253 @@
+Include "coax2Daxi_data.pro";
+
+Group{
+  Conductor = Region[100]; 
+  Air = Region[101];
+  
+  Ground = Region[120];    /* Boundary - various parts */
+  Terminal1 = Region[121];
+  Terminal2 = Region[122];
+  
+
+  BottomBoundary = Region[133];
+  TopBoundary = Region[134];
+  BoundaryNotTerminal = Region[{BottomBoundary,TopBoundary}];
+
+  If(Flag_Axi == 0) // 2D
+    LeftBoundary = Region[132];
+    Axis = Region[{}];
+    BoundaryNotTerminal += Region[{LeftBoundary}];
+  Else // axi
+    LeftBoundary = Region[{}];
+    Axis = Region[132];
+  EndIf
+  
+  Cut1Hterminal1 = Region[{BottomBoundary}];
+  Cut1Hterminal2 = Region[{TopBoundary}];
+  
+  Cut1H = Region[{Cut1Hterminal1,Cut1Hterminal2}];
+  
+  Sur_Terminals_FWece = Region[{Ground, Terminal1, Terminal2}]; // all terminals
+  
+  Vol_FW = Region[{Conductor,Air}]; // domain without the boundary
+  Sur_FW = Region[{Sur_Terminals_FWece, TopBoundary, BottomBoundary, LeftBoundary, Axis}];
+  Dom_FW = Region[ {Vol_FW, Sur_FW} ];
+
+  If (sigmaExt == 0) // used only with H formulation
+    Vol_FW_SigmaZero = Region[{Air}];
+    Vol_FW_SigmaNonZero = Region[{Conductor}];
+  Else
+    Vol_FW_SigmaZero = Region[{}];
+    Vol_FW_SigmaNonZero = Region[{Air,Conductor}];
+  EndIf
+  
+}
+
+Function{
+   /* Material properties are defined piecewise, for elementary groups */
+   /* the values in the right hand side are defined in Ishape2d_data.pro */
+   
+   nu[#{Conductor,Terminal1,Terminal2,Axis}] = nuInt;  // magnetic reluctivity [m/H]
+   mu[#{Conductor,Terminal1,Terminal2,Axis}] = muInt;  // permeability [H/m]
+   epsilon[#{Conductor,Terminal1,Terminal2,Axis}] = epsInt;       // permittivity [F/m]
+   sigma[#{Conductor,Terminal1,Terminal2,Axis}]  = sigmaInt;      // conductivity [S/m]
+   
+   nu[#{Air,BoundaryNotTerminal}] = nuExt;  // magnetic reluctivity [m/H]
+   mu[#{Air,BoundaryNotTerminal}] = muExt;  // permeability [H/m]
+   epsilon[#{Air,BoundaryNotTerminal}] = epsExt;       // permittivity [F/m]
+   sigma[#{Air,BoundaryNotTerminal}]  = sigmaExt;      // conductivity [S/m]
+   
+   
+   // This is a problem with 2 terminals, out of which one is grounded.
+   // The non-grounded can be excited in voltage or in current.
+   // Depending on the excitation type, one of the following functions will be useful.
+   //
+   // When imposing voltage or current via a constraint, the region appears there
+   // If you have a complex, the value has to be a function => use square brackets []
+   Printf(" ************************ Flag_AnalysisTypeFormulation = %g",Flag_AnalysisTypeFormulation);
+   Printf(" ************************ Flag_AnalysisType = %g",Flag_AnalysisType);
+   If (Flag_AnalysisTypeFormulation==0) // E
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+			VTerminal1[] = -VTerm1RMS*Complex[Cos[VTerm1Phase],Sin[VTerm1Phase]];
+	   Else
+			ITerminal1[] = -ITerm1RMS*Complex[Cos[ITerm1Phase],Sin[ITerm1Phase]];
+	   EndIf
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+			VTerminal2[] = -VTerm2RMS*Complex[Cos[VTerm2Phase],Sin[VTerm2Phase]];
+	   Else
+			ITerminal2[] = -ITerm2RMS*Complex[Cos[ITerm2Phase],Sin[ITerm2Phase]];
+	   EndIf
+	Else // H
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+			VTerminal1[] = VTerm1RMS*Complex[Cos[VTerm1Phase],Sin[VTerm1Phase]];
+	   Else
+			ITerminal1[] = ITerm1RMS*Complex[Cos[ITerm1Phase],Sin[ITerm1Phase]];
+	   EndIf
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+			VTerminal2[] = VTerm2RMS*Complex[Cos[VTerm2Phase],Sin[VTerm2Phase]];
+	   Else
+			ITerminal2[] = ITerm2RMS*Complex[Cos[ITerm2Phase],Sin[ITerm2Phase]];
+	   EndIf
+	EndIf
+   
+ }
+
+
+ Constraint{
+
+   // ece BC
+   { Name SetTerminalPotential; Type Assign;  // voltage excited terminals
+     Case {
+       { Region Ground; Value 0.; }
+       If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+         { Region Terminal1; Value VTerminal1[]; }
+       EndIf
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+         { Region Terminal2; Value VTerminal2[]; }
+       EndIf
+     }
+   }
+   { Name SetTerminalCurrent; Type Assign;   // current excited terminals
+     Case {
+       If((Flag_AnalysisType==2)|| (Flag_AnalysisType==3))
+         { Region Terminal1; Value ITerminal1[]/h2Ddepth; }  // here the depth is needed
+       EndIf
+	   If((Flag_AnalysisType==1)|| (Flag_AnalysisType==3))
+         { Region Terminal2; Value ITerminal2[]/h2Ddepth; }  // here the depth is needed
+       EndIf
+     }
+   }
+   
+   { Name ImposeE ;
+     Case {
+     }
+   }
+   
+   
+      { Name SetTerminalCurrentH; Type Assign;   // current excited terminals
+     Case {
+       If((Flag_AnalysisType==2)|| (Flag_AnalysisType==3))
+         { Region Cut1Hterminal1; Value ITerminal1[]/h2Ddepth; }  // here the depth is needed
+       EndIf
+	   If((Flag_AnalysisType==1)|| (Flag_AnalysisType==3))
+         { Region Cut1Hterminal2; Value ITerminal2[]/h2Ddepth; }  // here the depth is needed
+       EndIf
+     }
+   }
+   
+   
+  
+  { Name SetTerminalPotentialH; Type Assign;  // voltage excited terminals
+     Case {
+       If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+         { Region Cut1Hterminal1; Value VTerminal1[]; }
+       EndIf
+	   If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+         { Region Cut1Hterminal2; Value VTerminal2[]; }
+       EndIf
+     }
+   }
+  
+  
+   { Name ImposeHonAxis ;
+     Case {
+       If(Flag_AnalysisTypeFormulation==1) // H
+   	    If(Flag_Axi == 1) // axi
+            { Region Axis; Value 0 ; }
+   		EndIf
+        EndIf
+    }
+   }
+  
+}
+
+modelDir = "../";
+Dir = "res/";
+
+// The formulation and its tools
+
+ If (Flag_AnalysisTypeFormulation==0)  // E inside
+    Include "../formulations/FullWave_E_ece_MIMO2terminals_secondOrder.pro"
+ Else // H inside
+    Include "../formulations/FullWave_H_ece_MIMO2terminals_cplx_2D_and_AXI_secondOrder.pro"
+ EndIf
+ 
+Macro Change_post_options
+Echo[Str[ "nv = PostProcessing.NbViews;",
+    "For v In {0:nv-1}",
+    "View[v].NbIso = 25;",
+    "View[v].RangeType = 3;" ,// per timestep
+    "View[v].ShowTime = 3;",
+    "View[v].IntervalsType = 3;",
+    "EndFor"
+  ], File "post.opt"];
+Return
+
+PostOperation {
+  If (Flag_AnalysisTypeFormulation==0)   // E
+
+    { Name Maps; NameOfPostProcessing FW_E_ece;
+      Operation {
+      Print [ gradV, OnElementsOf ElementsOf[Vol_FW,OnOneSideOf Sur_FW], File StrCat[Dir,"map_gradV.pos" ]];
+      Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+      Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+      Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+      Print [ Vterminal, OnElementsOf ElementsOf[Sur_FW], File StrCat[Dir,"map_Vterminals.pos" ]];
+      Print [ VnotTerminals, OnElementsOf Vol_FW, File StrCat[Dir,"map_VnotTerminals.pos" ]];
+      Call Change_post_options;
+     }
+    }     
+
+    { Name TransferMatrix; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        If(Flag_AnalysisType==3)  // current excitation
+          Print [ Vterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_Z1_RI_formE.txt"]] ;
+		      Print [ Vterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_Z2_RI_formE.txt"]] ;  
+        ElseIf(Flag_AnalysisType==0)  // voltage excitation
+		      Print [ Iterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_Y1_RI_formE.txt"]] ;
+		      Print [ Iterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_Y2_RI_formE.txt"]] ;  
+        ElseIf(Flag_AnalysisType==2)  // hybrid excitation (first ec, second ev)
+          Print [ Vterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_H1_RI_formE.txt"]] ;
+		      Print [ Iterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_H2_RI_formE.txt"]] ;  
+	      Else // reverse hybrid excitation (first ev, second ec)
+          Print [ Iterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_G1_RI_formE.txt"]];
+		      Print [ Vterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_G2_RI_formE.txt"]] ;  
+	      EndIf
+      } 
+    }
+  
+  Else // H
+
+    { Name Maps; NameOfPostProcessing FW_H_ece ;
+      Operation {
+      Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+      Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+      Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+      // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+      Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+      Print [ rmsH, OnElementsOf Vol_FW, File StrCat[Dir,"map_absH.pos" ]];
+      Call Change_post_options;
+      }
+    }
+
+    { Name TransferMatrix; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        If(Flag_AnalysisType==3)  // current excitation
+          Print [ Vterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_Z1_RI_formH.txt"]] ;
+          Print [ Vterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_Z2_RI_formH.txt"]] ;   
+        ElseIf(Flag_AnalysisType==0)  // voltage excitation
+          Print [ Iterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_Y1_RI_formH.txt"]] ;
+          Print [ Iterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_Y2_RI_formH.txt"]] ;  
+        ElseIf(Flag_AnalysisType==2)  // hybrid excitation (first ec, second ev)
+          Print [ Vterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_H1_RI_formH.txt"]] ;
+          Print [ Iterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_H2_RI_formH.txt"]] ;  
+        Else // reverse hybrid excitation (first ev, second ec)
+          Print [ Iterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_G1_RI_formH.txt"]] ;
+          Print [ Vterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_G2_RI_formH.txt"]] ;  
+        EndIf
+      }  
+    }
+ 
+  EndIf
+
+}
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi_data.pro b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi_data.pro
new file mode 100644
index 0000000000000000000000000000000000000000..a7d8854a42b7058dcd49e344e9d81b576b7c16da
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax2Daxi_data.pro
@@ -0,0 +1,178 @@
+colorro = "LightGrey";
+
+// new menu for the interface - holds geometrical data
+cGUI= "{TEST-Coax2Daxi-ProblemData/";
+mGeo = StrCat[cGUI,"0Geometrical parameters/0"];
+colorMGeo = "Ivory";
+close_menu = 1;
+DefineConstant[
+  a = {4e-3, Name StrCat[mGeo, "0a=radius of inner conductor"], Units "m", Highlight Str[colorMGeo], Closed close_menu},
+  b = {8e-3, Name StrCat[mGeo, "0a=radius of outer conductor"], Units "m", Highlight Str[colorMGeo], Closed close_menu},
+  l = {1, Name StrCat[mGeo, "1l=cable length"], Units "m", Highlight Str[colorMGeo]}
+];
+
+// new menu for the interface - holds material data
+mMat = StrCat[cGUI,"1Material parameters/0"];
+colorMMat = "AliceBlue";
+DefineConstant[
+  epsrInt = {1, Name StrCat[mMat, "0Relative permittivity int part"], Units "-", Highlight Str[colorMMat], Closed close_menu},
+  murInt = {1, Name StrCat[mMat, "1Relative permeability int part"], Units "-", Highlight Str[colorMMat]},
+  sigmaInt = {6.6e7, Name StrCat[mMat, "2Conductivity int part"], Units "S/m", Highlight Str[colorMMat]},
+  epsrExt = {1, Name StrCat[mMat, "3Relative permittivity ext part"], Units "-", Highlight Str[colorMMat], Closed close_menu},
+  murExt = {1, Name StrCat[mMat, "4Relative permeability ext part"], Units "-", Highlight Str[colorMMat]},
+  sigmaExt = {0, Name StrCat[mMat, "5Conductivity ext part"], Units "S/m", Highlight Str[colorMMat]}
+];
+
+eps0 = 8.854187818e-12; // F/m - absolute permitivity of vacuum
+mu0  = 4.e-7 * Pi;      // H/m - absolute permeability of vacuum
+nu0  = 1/mu0;           // m/H - absolute reluctivity of vacuum
+
+epsInt = eps0*epsrInt;        // F/m - absolute permitivity  - int
+muInt = mu0*murInt;           // F/m - absolute permeability - int
+nuInt = 1/muInt;              // m/H - absolute reluctivity  - int
+
+epsExt = eps0*epsrExt;        // F/m - absolute permitivity  - ext
+muExt = mu0*murExt;           // F/m - absolute permeability - ext
+nuExt = 1/muExt;              // m/H - absolute reluctivity  - ext
+
+// new menu for the interface - type of BC
+mTypeBC = StrCat[cGUI,"2Type of BC/0"];
+colorMTypeBC = "Red";
+
+// new menu for the interface - type of formulation
+mTypeBC2 = StrCat[cGUI,"3Type of formulation/0"];
+colorMTypeBC = "Blue";
+DefineConstant[
+  Flag_AnalysisTypeFormulation = { FORMULATION,
+    Choices{
+      0="0: formulation in E inside + ECE",
+      1="1: formulation in H inside + ECE"
+    },
+    Name Str[mTypeBC2], Highlight Str[colorMTypeBC], Closed !close_menu,
+    Help Str["E inside, electric V on the boundary",
+      "H inside, reduced magnetic V on the boundary"],
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+];
+
+// new menu for the interface - values of excitations - significance depends on the type of BC
+mValuesBC = StrCat[cGUI,"4Values of BC (frequency analysis)/0"];
+colorMValuesBC = "Ivory";
+
+If (MODEL_ID2 == 1) // HF simulations
+	fmin = 1e7; fmax = 6e8; nop = 100; 
+	freqs()=LinSpace[fmin,fmax,nop];
+EndIf
+If  (MODEL_ID2 == 2) // LF simulations
+	fmin = 1;   fmax = 1e7; nop = 20;
+	freqs()=LogSpace[Log10[fmin],Log10[fmax],nop];
+EndIf
+
+DefineConstant[
+  _use_freq_loop = {0,  Choices{0,1}, Name StrCat[mValuesBC, "0Loop on frequencies?"],
+    ServerAction Str["Reset", StrCat[mValuesBC, "0Working Frequency"]], Highlight "Yellow"}
+  Freq  = {freqs(0), Choices{freqs()}, Loop _use_freq_loop, Name StrCat[mValuesBC, "0Working Frequency"],
+    Units "Hz", Highlight  Str[colorMValuesBC], Closed !close_menu }
+];
+
+NbTerminals = 2; // No of terminals which are not grounded
+
+Type1 = (TERMINAL_EXC == 0)  ? 2 : 1 ;  // 2 ==> voltage exc
+Type2 = (TERMINAL_EXC2 == 0) ? 2 : 1 ; 
+	
+DefineConstant[
+	TypeExcTerminal1 = {Type1,Choices{1="ec",2="ev"},Name StrCat[mValuesBC, "4Exitation type/0Terminal 1 (bottom)"]}
+	TypeExcTerminal2 = {Type2,Choices{1="ec",2="ev"},Name StrCat[mValuesBC, "4Exitation type/1Terminal 2 (top)"]}
+	ActiveTerminal = {1,Choices{1="1",2="2"},Name StrCat[mValuesBC, "4Exitation type/Active terminal"]}
+
+	VGroundRMS  = {0, Name StrCat[mValuesBC, "3Ground-CylSurf/1Potential on gnd (rms)"], Units "V" , 
+		ReadOnly 1, Highlight Str[colorro]}
+  	VGroundPhase  = {0, Name StrCat[mValuesBC, "3Ground-CylSurf/1Potential on gnd, phase"], Units "rad",  
+		ReadOnly 1, Highlight Str[colorro]}
+];
+
+If (ActiveTerminal == 1)
+	PassiveTerminal = 2;
+Else
+	PassiveTerminal = 1;
+EndIf
+  
+If ((TypeExcTerminal1==1)&(TypeExcTerminal2==1))  // current exc
+	Flag_AnalysisType = 3;
+	Printf("======================> Both terminals are current excited => Z transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing Z%g%g and Z%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		ITerm1RMS = 1; ITerm1Phase = 0;
+		ITerm2RMS = 0; ITerm2Phase = 0;
+		If (Flag_AnalysisTypeFormulation==1)   // H - to understand why I have to do this
+		   ITerm1RMS = -1;
+		EndIf
+	Else
+	    ITerm1RMS = 0; ITerm1Phase = 0;
+		ITerm2RMS = 1; ITerm2Phase = 0;
+	EndIf
+ElseIf ((TypeExcTerminal1==2)&(TypeExcTerminal2==2))  // voltage exc
+	Flag_AnalysisType = 0;
+	Printf("======================> Both terminals are voltage excited => Y transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing Y%g%g and Y%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		VTerm1RMS = 1; VTerm1Phase = 0;
+		VTerm2RMS = 0; VTerm2Phase = 0;
+	Else
+	    VTerm1RMS = 0; VTerm1Phase = 0;
+		VTerm2RMS = (Flag_AnalysisTypeFormulation==1) ? -1 : 1; 
+		// H - constraint is linked to an automatically generated cut, which is oriented and depends on geo/msh
+		// the change of sign here is due to the orientation of this cut. It may need to be adapted with another geo/msh
+		VTerm2Phase = 0;  
+	EndIf
+ElseIf ((TypeExcTerminal1==1)&(TypeExcTerminal2==2))  //hybrid H exc
+	Flag_AnalysisType = 2;
+	Printf("======================> Terminal 1 (top) is current excited, Terminal 2 (right) is voltage excited => H transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing H%g%g and H%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		ITerm1RMS = (Flag_AnalysisTypeFormulation==1)?-1:1; // change of sign due to cut orientation
+		ITerm1Phase = 0;
+		VTerm2RMS = 0; VTerm2Phase = 0;
+	Else
+	    ITerm1RMS = 0; ITerm1Phase = 0;
+		VTerm2RMS = 1; VTerm2Phase = 0;  
+	EndIf
+Else  //hybrid G exc
+	Flag_AnalysisType = 1;
+	Printf("======================> Terminal 1 (top) is voltage excited, Terminal 2 (right) is current excited => G transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing G%g%g and G%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		VTerm1RMS = 1; VTerm1Phase = 0;
+		ITerm2RMS = 0; ITerm2Phase = 0;
+	Else
+	    VTerm1RMS = 0; VTerm1Phase = 0;
+		ITerm2RMS = 1; ITerm2Phase = 0;
+	EndIf
+EndIf
+
+meshSettings = StrCat[cGUI,"5MeshSettings/0"];
+
+DefineConstant[
+  _use_transfinite = {1, Choices{0,1}, Name StrCat[meshSettings, "0Transfinite mesh?"], Highlight "Yellow", Closed !close_menu}
+   s = {1, Name  StrCat[meshSettings, "1Mesh factor"]}
+   Flag_ElementOrder = { FE_ORDER,
+    Choices{
+      1="1: first order elements",
+      2="2: second order elements"
+    },
+	Name StrCat[meshSettings, "2Element order"], Highlight "Red", Closed !close_menu,
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+	_use_recombine = {0, Choices{0,1}, Name StrCat[meshSettings, "3Use recombine?"], Highlight "Yellow", Closed !close_menu}
+];
+
+FE_Order = Flag_ElementOrder;
+
+Printf("FE_Order = %g",FE_Order);
+
+modelDim = 2; 
+Flag_Axi = 1; 
+h2Ddepth = (modelDim==3) ? 1 : (Flag_Axi ? 2*Pi : l);
+
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax3D.geo b/ECE_full_wave_E-H_Academic/geo_pro/coax3D.geo
new file mode 100644
index 0000000000000000000000000000000000000000..cddc159b1e4fe568561fd6cc81646c735b9a9137
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax3D.geo
@@ -0,0 +1,99 @@
+Include "coax3D_data.pro";
+
+p =0.25; // portion of a
+
+nop = 4/4;  // no of slices per 1/4 circle
+nopR = s*4; //5; //5*2; // no of points on the Oa and atob points
+nopA = s*5; //5*4;
+
+
+pc = newp; Point(pc) = {0,0,0};
+angle = Pi/2/nop;
+
+For k1 In {0:4*nop-1}
+  alpha = angle*k1;
+  pa[] += newp ; Point(pa[k1]) = {a*Cos[alpha],a*Sin[alpha],0};
+
+  // for controlling the mesh a bit better
+  pp[] += newp ; Point(pp[k1]) = {p*a*Cos[alpha],p*a*Sin[alpha],0};
+  la[] += newl ; Line(la[k1]) = {pp[k1],pa[k1]};
+
+  pb[] += newp ; Point(pb[k1]) = {b*Cos[alpha],b*Sin[alpha],0};
+  lb[] += newl ; Line(lb[k1]) = {pa[k1],pb[k1]};
+EndFor
+
+For k1 In {0:4*nop-1}
+  k2 = (k1==4*nop-1) ? 0 : k1+1;
+  cla[] += newl ; Circle(newl) = {pa[k1],pc,pa[k2]};
+  clp[] += newl ; Circle(newl) = {pp[k1],pc,pp[k2]}; 
+  clb[] += newl ; Circle(newl) = {pb[k1],pc,pb[k2]};
+
+  //In
+  Curve Loop(newcl) = {la[k1],cla[k1],-la[k2], -clp[k1]};
+  scable_a[] += news; Plane Surface(news) = newcl-1;
+  // Out
+  Curve Loop(newcl) = {lb[k1],clb[k1],-lb[k2],-cla[k1]};
+  scable_b[] += news; Plane Surface(news) = newcl-1;
+EndFor
+Curve Loop(newcl) = {clp[]};
+scable_a[] += news; Plane Surface(news) = newcl-1; // center
+
+Transfinite Curve{la[]} = nopR; 
+Transfinite Curve{lb[]} = nopR;
+
+Transfinite Curve{cla[],clb[],clp[]} = nopA;
+Transfinite Surface{scable_a[]};
+Transfinite Surface{scable_b[]};
+
+If (_use_recombine)
+  Recombine Surface{scable_a[]};
+  Recombine Surface{scable_b[]};
+EndIf
+
+nbPointAlongOz = Ceil[l/lcarLambda];
+Printf("nbPointAlongOz = %g",nbPointAlongOz);
+//nbPointAlongOz = 16;  // just to see if I can generate second order systems
+
+// You may use a loop, much easier
+For k1 In {0:4*nop}
+  aux_a[]=Extrude {0,0,l} {
+    Surface{scable_a[k1]}; Layers{ {nbPointAlongOz}, {1} }; Recombine _use_recombine;
+  }; // array containing: 0=top surface; 1=volume; the rest of the surfaces
+  vcable_a[] += aux_a[1]; // volume
+  scable_aa[] += aux_a[0]; // top surface after extruding
+EndFor
+
+For k1 In {0:4*nop-1}
+  aux_b[]=Extrude {0,0,l} {
+    Surface{scable_b[k1]}; Layers{ {nbPointAlongOz}, {1} }; Recombine _use_recombine;
+  };
+  vcable_b[] += aux_b[1]; // volume
+  scable_bb[] += aux_b[0]; // top surface after extruding
+EndFor
+
+// and no need of hunting :-)
+ground[] = Abs[CombinedBoundary{Volume{:};}] ; // Total boundary + getting rid of possible 'signed' surfaces
+ground[] -= {scable_a[],scable_aa[], scable_b[], scable_bb[]}; // Removing top and bottom from array
+
+
+
+// Physical regions
+// --------------------------
+
+Physical Volume ("Conductor", 100) = {vcable_a[]} ;         
+Physical Volume ("Air", 101) = {vcable_b[]} ;
+
+Physical Surface ("Ground",   120) = {ground[]} ;          
+Physical Surface ("Terminal1", 121) = {scable_a[]} ;       
+Physical Surface ("Terminal2", 122) = {scable_aa[]} ;      
+Physical Surface ("BottomBoundary", 133) = {scable_b[]} ;
+Physical Surface ("TopBoundary", 134) = {scable_bb[]} ;
+
+Physical Surface ("BoundaryNotTerminal", 131) = {scable_b[],scable_bb[]} ;
+
+// cut for the H formulation
+Cohomology(1) {{131},{}}; 
+
+// For aestetics
+Recursive Color SkyBlue { Volume{vcable_b[]};}
+Recursive Color Red  { Volume{vcable_a[]};}
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax3D.pro b/ECE_full_wave_E-H_Academic/geo_pro/coax3D.pro
new file mode 100644
index 0000000000000000000000000000000000000000..7635b390ae3662808e59dfd85a4bcb85c3bce980
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax3D.pro
@@ -0,0 +1,217 @@
+Include "coax3D_data.pro";
+
+Group{
+  Conductor = Region[100]; 
+  Air = Region[101];
+
+  Terminal1 = Region[121]; 
+  Terminal2 = Region[122]; 
+
+  Ground = Region[120];    
+  BottomBoundary = Region[133];
+  TopBoundary = Region[134];
+
+
+  BoundaryNotTerminal = Region[{BottomBoundary,TopBoundary}];
+  Sur_Terminals_FWece = Region[{Terminal1,Terminal2,Ground}];
+
+  Vol_FW =  Region[{Conductor,Air}];
+
+  Sur_FW = Region[{BoundaryNotTerminal,Sur_Terminals_FWece}]; //all boundary
+  Dom_FW = Region[ {Vol_FW, Sur_FW} ];
+
+  Cut1Hterminal1 = Region[{135}];
+  Cut1Hterminal2 = Region[{136}];
+  Cut1H = Region[{Cut1Hterminal1,Cut1Hterminal2}];
+}
+
+Function{
+  // Material properties are defined piecewise, for elementary groups
+  // the values in the right hand side are defined in Ishape2d_data.pro
+  
+  nu[#{Conductor,Terminal1,Terminal2}] = nuInt;  // magnetic reluctivity [m/H]
+  mu[#{Conductor,Terminal1,Terminal2}] = muInt;  // permeability [H/m]
+  epsilon[#{Conductor,Terminal1,Terminal2}] = epsInt;       // permittivity [F/m]
+  sigma[#{Conductor,Terminal1,Terminal2}]  = sigmaInt;      // conductivity [S/m]
+
+  nu[#{Air,BoundaryNotTerminal,Ground}] = nuExt;  // magnetic reluctivity [m/H]
+  mu[#{Air,BoundaryNotTerminal,Ground}] = muExt;  // permeability [H/m]
+  epsilon[#{Air,BoundaryNotTerminal,Ground}] = epsExt;       // permittivity [F/m]
+  sigma[#{Air,BoundaryNotTerminal,Ground}]  = sigmaExt;      // conductivity [S/m]
+  
+  // This is a problem with 2 terminals, out of which one is grounded.
+  // The non-grounded can be excited in voltage or in current.
+  // Depending on the excitation type, one of the following functions will be useful.
+  //
+  // When imposing voltage or current via a constraint, the region appears there
+  // If you have a complex, the value has to be a function => use square brackets []
+  If (Flag_AnalysisTypeFormulation==0) // E
+    If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+    VTerminal1[] = -VTerm1RMS*Complex[Cos[VTerm1Phase],Sin[VTerm1Phase]];
+    Else
+    ITerminal1[] = -ITerm1RMS*Complex[Cos[ITerm1Phase],Sin[ITerm1Phase]];
+    EndIf
+    If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+    VTerminal2[] = -VTerm2RMS*Complex[Cos[VTerm2Phase],Sin[VTerm2Phase]];
+    Else
+    ITerminal2[] = -ITerm2RMS*Complex[Cos[ITerm2Phase],Sin[ITerm2Phase]];
+    EndIf
+	Else // H
+    If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+    VTerminal1[] = VTerm1RMS*Complex[Cos[VTerm1Phase],Sin[VTerm1Phase]];
+    Else
+    ITerminal1[] = ITerm1RMS*Complex[Cos[ITerm1Phase],Sin[ITerm1Phase]];
+    EndIf
+    If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+    VTerminal2[] = VTerm2RMS*Complex[Cos[VTerm2Phase],Sin[VTerm2Phase]];
+    Else
+    ITerminal2[] = ITerm2RMS*Complex[Cos[ITerm2Phase],Sin[ITerm2Phase]];
+    EndIf
+	EndIf  
+}
+
+Constraint{
+  // ece BC
+  { Name SetTerminalPotential; Type Assign;  // voltage excited terminals
+    Case {
+      { Region Ground; Value 0.; }
+      If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+        { Region Terminal1; Value VTerminal1[]; }
+      EndIf
+      If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+        { Region Terminal2; Value VTerminal2[]; }
+      EndIf
+    }
+  }
+   
+  { Name SetTerminalCurrent; Type Assign;   // current excited terminals
+    Case {
+      If((Flag_AnalysisType==2)|| (Flag_AnalysisType==3))
+        { Region Terminal1; Value ITerminal1[]/h2Ddepth; }  // depth is needed
+      EndIf
+      If((Flag_AnalysisType==1)|| (Flag_AnalysisType==3))
+        { Region Terminal2; Value ITerminal2[]/h2Ddepth; }  // depth is needed
+      EndIf
+    }
+   }
+   
+  { Name ImposeE ;
+    Case {
+    }
+  }
+  
+  { Name SetTerminalCurrentH; Type Assign;   // current excited terminals
+    Case {
+      If((Flag_AnalysisType==2)|| (Flag_AnalysisType==3))
+      { Region Cut1Hterminal1; Value ITerminal1[]/h2Ddepth; }  // here the depth is needed
+      EndIf
+	    If((Flag_AnalysisType==1)|| (Flag_AnalysisType==3))
+        { Region Cut1Hterminal2; Value ITerminal2[]/h2Ddepth; }  // here the depth is needed
+      EndIf
+    }
+  }
+   
+  { Name SetTerminalPotentialH; Type Assign;  // voltage excited terminals
+    Case {
+      If((Flag_AnalysisType==0)||(Flag_AnalysisType==1))
+        { Region Cut1Hterminal1; Value VTerminal1[]; }
+      EndIf
+      If((Flag_AnalysisType==0)||(Flag_AnalysisType==2))
+        { Region Cut1Hterminal2; Value VTerminal2[]; }
+      EndIf
+    }
+  }
+  
+}
+
+modelDir = "../";
+Dir = "res/";
+ 
+// The formulation and its tools
+If (Flag_AnalysisTypeFormulation==0)  // E inside
+  Include "../formulations/FullWave_E_ece_MIMO2terminals_secondOrder.pro"
+Else // H inside
+  Include "../formulations/FullWave_H_ece_MIMO2terminals_cplx_3D_secondOrder.pro"
+EndIf
+
+// Output results
+Macro Change_post_options
+Echo[Str[ "nv = PostProcessing.NbViews;",
+    "For v In {0:nv-1}",
+    "View[v].NbIso = 25;",
+    "View[v].RangeType = 3;" ,// per timestep
+    "View[v].ShowTime = 3;",
+    "View[v].IntervalsType = 3;",
+    "EndFor"
+  ], File "post.opt"];
+Return
+
+PostOperation {
+
+  If (Flag_AnalysisTypeFormulation==0)   // E
+
+    { Name Maps; NameOfPostProcessing FW_E_ece;
+      Operation {
+      Print [ gradV, OnElementsOf ElementsOf[Vol_FW,OnOneSideOf Sur_FW], File StrCat[Dir,"map_gradV.pos" ]];
+      Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+      Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+      Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+      Print [ Vterminal, OnElementsOf ElementsOf[Sur_FW], File StrCat[Dir,"map_Vterminals.pos" ]];
+      Print [ VnotTerminals, OnElementsOf Vol_FW, File StrCat[Dir,"map_VnotTerminals.pos" ]];
+      Call Change_post_options;
+     }
+    }     
+
+	  { Name TransferMatrix; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        If(Flag_AnalysisType==3)  // current excitation
+          Print [ Vterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_Z1_RI_formE.txt"]] ;
+		      Print [ Vterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_Z2_RI_formE.txt"]] ;  
+        ElseIf(Flag_AnalysisType==0)  // voltage excitation
+		      Print [ Iterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_Y1_RI_formE.txt"]] ;
+		      Print [ Iterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_Y2_RI_formE.txt"]] ;  
+        ElseIf(Flag_AnalysisType==2)  // hybrid excitation (first ec, second ev)
+          Print [ Vterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_H1_RI_formE.txt"]] ;
+		      Print [ Iterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_H2_RI_formE.txt"]] ;  
+	      Else // reverse hybrid excitation (first ev, second ec)
+          Print [ Iterminal, OnRegion Terminal1, Format Table , File  > StrCat[Dir,"test_G1_RI_formE.txt"]] ;
+		      Print [ Vterminal, OnRegion Terminal2, Format Table , File  > StrCat[Dir,"test_G2_RI_formE.txt"]] ;  
+	      EndIf
+      } 
+    }
+	
+  Else // H
+
+    { Name Maps; NameOfPostProcessing FW_H_ece ;
+      Operation {
+      Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+      Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+      Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+      // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+      Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+      Print [ rmsH, OnElementsOf Vol_FW, File StrCat[Dir,"map_absH.pos" ]];
+      Call Change_post_options;
+      }
+    }
+
+    { Name TransferMatrix; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        If(Flag_AnalysisType==3)  // current excitation
+          Print [ Vterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_Z1_RI_formH.txt"]] ;
+          Print [ Vterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_Z2_RI_formH.txt"]] ;   
+        ElseIf(Flag_AnalysisType==0)  // voltage excitation
+          Print [ Iterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_Y1_RI_formH.txt"]] ;
+          Print [ Iterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_Y2_RI_formH.txt"]] ;  
+        ElseIf(Flag_AnalysisType==2)  // hybrid excitation (first ec, second ev)
+          Print [ Vterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_H1_RI_formH.txt"]] ;
+          Print [ Iterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_H2_RI_formH.txt"]] ;  
+        Else // reverse hybrid excitation (first ev, second ec)
+          Print [ Iterminal, OnRegion Cut1Hterminal1, Format Table , File  > StrCat[Dir,"test_G1_RI_formH.txt"]] ;
+          Print [ Vterminal, OnRegion Cut1Hterminal2, Format Table , File  > StrCat[Dir,"test_G2_RI_formH.txt"]] ;  
+        EndIf
+      }  
+    }
+      
+  EndIf
+
+}
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/coax3D_data.pro b/ECE_full_wave_E-H_Academic/geo_pro/coax3D_data.pro
new file mode 100644
index 0000000000000000000000000000000000000000..6b11b753dc7be323fa84cc2d37748a22e777f57e
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/coax3D_data.pro
@@ -0,0 +1,174 @@
+
+
+colorro = "LightGrey";
+
+// new menu for the interface - holds geometrical data
+cGUI= "{TEST-Coax3D-ProblemData/";
+mGeo = StrCat[cGUI,"0Geometrical parameters/0"];
+colorMGeo = "Ivory";
+close_menu = 1;
+DefineConstant[
+  a = {4e-3, Name StrCat[mGeo, "0a=radius of inner conductor"], Units "m", Highlight Str[colorMGeo], Closed close_menu},
+  b = {8e-3, Name StrCat[mGeo, "0a=radius of outer conductor"], Units "m", Highlight Str[colorMGeo], Closed close_menu},
+  l = {1, Name StrCat[mGeo, "1l=cable length"], Units "m", Highlight Str[colorMGeo]}
+];
+
+/* new menu for the interface - holds material data */
+mMat = StrCat[cGUI,"1Material parameters/0"];
+colorMMat = "AliceBlue";
+DefineConstant[
+  epsrInt = {1, Name StrCat[mMat, "0Relative permittivity int part"], Units "-", Highlight Str[colorMMat], Closed close_menu},
+  murInt = {1, Name StrCat[mMat, "1Relative permeability int part"], Units "-", Highlight Str[colorMMat]},
+  sigmaInt = {6.6e7, Name StrCat[mMat, "2Conductivity int part"], Units "S/m", Highlight Str[colorMMat]},
+  epsrExt = {1, Name StrCat[mMat, "3Relative permittivity ext part"], Units "-", Highlight Str[colorMMat], Closed close_menu},
+  murExt = {1, Name StrCat[mMat, "4Relative permeability ext part"], Units "-", Highlight Str[colorMMat]},
+  sigmaExt = {0, Name StrCat[mMat, "5Conductivity ext part"], Units "S/m", Highlight Str[colorMMat]}
+];
+
+eps0 = 8.854187818e-12; // F/m - absolute permitivity of vacuum
+mu0  = 4.e-7 * Pi;      // H/m - absolute permeability of vacuum
+nu0  = 1/mu0;           // m/H - absolute reluctivity of vacuum
+
+epsInt = eps0*epsrInt;        // F/m - absolute permitivity  - int
+muInt = mu0*murInt;           // F/m - absolute permeability - int
+nuInt = 1/muInt;              // m/H - absolute reluctivity  - int
+//
+epsExt = eps0*epsrExt;        // F/m - absolute permitivity  - ext
+muExt = mu0*murExt;           // F/m - absolute permeability - ext
+nuExt = 1/muExt;              // m/H - absolute reluctivity  - ext
+
+// new menu for the interface - type of BC 
+mTypeBC = StrCat[cGUI,"2Type of BC/0"];
+colorMTypeBC = "Red";
+
+
+// new menu for the interface - type of formulation
+mTypeBC2 = StrCat[cGUI,"3Type of formulation/0"];
+colorMTypeBC = "Blue";
+DefineConstant[
+  Flag_AnalysisTypeFormulation = { 0,
+    Choices{
+      0="0: formulation in E inside + ECE",
+      1="1: formulation in H inside + ECE"
+    },
+    Name Str[mTypeBC2], Highlight Str[colorMTypeBC], Closed !close_menu,
+    Help Str["E inside, electric V on the boundary",
+      "H inside, reduced magnetic V on the boundary"],
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+];
+
+// new menu for the interface - values of excitations - significance depends on the type of BC
+mValuesBC = StrCat[cGUI,"4Values of BC (frequency analysis)/0"];
+colorMValuesBC = "Ivory";
+
+fmin = 1e7;
+fmin = 3e8;      
+fmax = 6e8; 
+nop = 50; 
+
+freqs()=LinSpace[fmin,fmax,nop];
+
+DefineConstant[
+  _use_freq_loop = {0,  Choices{0,1}, Name StrCat[mValuesBC, "0Loop on frequencies?"],
+    ServerAction Str["Reset", StrCat[mValuesBC, "0Working Frequency"]], Highlight "Yellow"}
+    Freq  = {freqs(0), Choices{freqs()}, Loop _use_freq_loop, Name StrCat[mValuesBC, "0Working Frequency"],
+    Units "Hz", Highlight  Str[colorMValuesBC], Closed !close_menu }
+];
+
+
+NbTerminals = 2; // No of terminals which are not grounded
+
+DefineConstant[
+  TypeExcTerminal1 = {2,Choices{1="ec",2="ev"},Name StrCat[mValuesBC, "4Exitation type/0Terminal 1 (bottom)"]}
+  TypeExcTerminal2 = {2,Choices{1="ec",2="ev"},Name StrCat[mValuesBC, "4Exitation type/1Terminal 2 (top)"]}
+  ActiveTerminal = {1,Choices{1="1",2="2"},Name StrCat[mValuesBC, "4Exitation type/Active terminal"]}
+
+  VGroundRMS  = {0, Name StrCat[mValuesBC, "3Ground-CylSurf/1Potential on gnd (rms)"], Units "V" , 
+    ReadOnly 1, Highlight Str[colorro]}
+  VGroundPhase  = {0, Name StrCat[mValuesBC, "3Ground-CylSurf/1Potential on gnd, phase"], Units "rad",  
+    ReadOnly 1, Highlight Str[colorro]}
+];
+
+
+PassiveTerminal = (ActiveTerminal == 1)?2:1;
+
+meshSettings = StrCat[cGUI,"5MeshSettings/0"];
+
+DefineConstant[
+  s = {1, Name StrCat[meshSettings, "1Mesh factor"]}
+  Flag_ElementOrder = { 1,
+  Choices{
+    1="1: first order elements",
+    2="2: second order elements"
+  },
+  Name StrCat[meshSettings, "2Element order"], Highlight "Red", Closed !close_menu,
+  ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+	_use_recombine = {0, Choices{0,1}, Name StrCat[meshSettings, "3Use recombine?"], Highlight "Yellow", Closed !close_menu}
+];
+
+FE_Order = Flag_ElementOrder;
+
+c0 = 3e8;
+lambdaMin = c0/fmax;
+lcarLambda = s*lambdaMin/10;
+
+If ((TypeExcTerminal1==1)&(TypeExcTerminal2==1))  // current exc
+	Flag_AnalysisType = 3;
+	Printf("======================> Both terminals are current excited => Z transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing Z%g%g and Z%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		ITerm1RMS = 1; ITerm1Phase = 0;
+		ITerm2RMS = 0; ITerm2Phase = 0;
+	Else
+	    ITerm1RMS = 0; ITerm1Phase = 0;
+		ITerm2RMS = 1; ITerm2Phase = 0;
+	EndIf
+ElseIf ((TypeExcTerminal1==2)&(TypeExcTerminal2==2))  // voltage exc
+	Flag_AnalysisType = 0;
+	Printf("======================> Both terminals are voltage excited => Y transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing Y%g%g and Y%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		VTerm1RMS = 1; VTerm1Phase = 0;
+		VTerm2RMS = 0; VTerm2Phase = 0;
+	Else
+	    VTerm1RMS = 0; VTerm1Phase = 0;
+		VTerm2RMS = 1; VTerm2Phase = 0;  
+		If(Flag_AnalysisTypeFormulation==1)  // H - uncomment when no recombine
+		  If(_use_recombine==0)  
+		   VTerm2RMS = -1;
+		  EndIf
+		EndIf
+	EndIf
+ElseIf ((TypeExcTerminal1==1)&(TypeExcTerminal2==2))  //hybrid H exc
+	Flag_AnalysisType = 2;
+	Printf("======================> Terminal 1 (top) is current excited, Terminal 2 (right) is voltage excited => H transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing H%g%g and H%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		ITerm1RMS = 1; ITerm1Phase = 0;
+		VTerm2RMS = 0; VTerm2Phase = 0;
+	Else
+	    ITerm1RMS = 0; ITerm1Phase = 0;
+		VTerm2RMS = 1; VTerm2Phase = 0;  
+	EndIf
+Else  //hybrid G exc
+	Flag_AnalysisType = 1;
+	Printf("======================> Terminal 1 (top) is voltage excited, Terminal 2 (right) is current excited => G transfer matrix");
+	Printf("======================> Active terminal is %g",ActiveTerminal);
+	Printf("======================> Two s1p files are created, containing G%g%g and G%g%g",ActiveTerminal,ActiveTerminal,PassiveTerminal,ActiveTerminal);
+	If (ActiveTerminal == 1)
+		VTerm1RMS = 1; VTerm1Phase = 0;
+		ITerm2RMS = 0; ITerm2Phase = 0;
+	Else
+	    VTerm1RMS = 0; VTerm1Phase = 0;
+		  ITerm2RMS = 1; ITerm2Phase = 0;
+	EndIf
+EndIf
+
+
+modelDim = 3; // 
+Flag_Axi = 0; // 1 for AXI - not tested for the moment, it makes sense only for modelDim = 2
+
+h2Ddepth = (modelDim==3) ? 1 : (Flag_Axi ? 2*Pi : l);
\ No newline at end of file
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.geo b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.geo
new file mode 100644
index 0000000000000000000000000000000000000000..1d3732ea6a3c8c8d1bd3cdcfad34113e7c970feb
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.geo
@@ -0,0 +1,145 @@
+Include "cylinder2Daxi_data.pro";
+
+// hereafter there are two variants of code, both are correct
+
+delta = Sqrt(2.0/(2*Pi*Freq*mu*sigma));
+If (delta < a)
+	lcar_p0 = a - delta;
+    lcar_p1 = delta;
+	If (lcar_p0 < lcar_p1)
+		lcar_p1 = lcar_p0;
+	    Printf(" ------------------- > lcar_p0 < l_car_p1 at Freg = %g",Freq);
+	Else
+		Printf(" ==== > lcar_p0 > l_car_p1 at Freg = %g",Freq);
+	EndIf
+Else
+	Printf(" :::::::::::: delta > a at Freg = %g",Freq);
+	lcar_p0 = a;
+    lcar_p1 = a;
+EndIf
+
+lcar_p0 = s*lcar_p0 ;
+lcar_p1 = s*lcar_p1 ;
+
+If (_use_uniformMesh==1)
+    lcar = s*a/10;
+
+	pp[]+=newp; Point(newp) = {0, 0, 0, lcar};
+	pp[]+=newp; Point(newp) = {a, 0, 0, lcar};
+	pp[]+=newp; Point(newp) = {a, l, 0, lcar};
+	pp[]+=newp; Point(newp) = {0, l, 0, lcar};
+	For k In {0:3}
+		If (k == 3)
+			ll[]+=newl; Line(newl) = {pp[k],pp[0]};
+		Else
+			ll[]+=newl; Line(newl) = {pp[k],pp[k+1]};
+		EndIf
+	EndFor
+
+	cl = newll;  Line Loop(cl) = ll[];
+	surfRectangle = news; Plane Surface(surfRectangle) = {cl};
+	
+	If(_use_transfinite)
+		nopa = Ceil[a/lcar] ;
+		Transfinite Line {ll[0],ll[2]} = nopa; 
+		nopl = Ceil[l/lcar] ;
+		Transfinite Line {ll[1],ll[3]} = nopl; 
+		Transfinite Surface(surfRectangle);
+	EndIf
+
+	If (_use_recombine)
+		Recombine Surface{surfRectangle};
+	EndIf
+	
+	/* Definition of Physical entities (surfaces, lines). The Physical
+       entities tell GMSH the elements and their associated region numbers
+       to save in the file 'Ishape2d.msh'. */
+
+	Physical Surface ("MaterialX", MATERIALX) = {surfRectangle};     
+
+	Physical Line ("Ground",   GROUND) = {ll[2]};                 
+	Physical Line ("Terminal", TERMINAL) = {ll[0]};               
+	Physical Line ("RightBoundary", RIGHTBOUNDARY) = {ll[1]} ;     
+	Physical Line ("LeftBoundary", LEFTBOUNDARY) = {ll[3]} ;      
+
+	Physical Line ("Boundary", BOUNDARY) = {ll[]} ; 
+	
+Else
+
+    // non-uniform mesh
+	
+	pp[]+=newp; Point(newp) = {0, 0, 0, lcar_p0};
+	pp[]+=newp; Point(newp) = {a, 0, 0, lcar_p1};
+	pp[]+=newp; Point(newp) = {a, l, 0, lcar_p1};
+	pp[]+=newp; Point(newp) = {0, l, 0, lcar_p0};
+	For k In {0:3}
+		If (k == 3)
+			ll[]+=newl; Line(newl) = {pp[k],pp[0]};
+		Else
+			ll[]+=newl; Line(newl) = {pp[k],pp[k+1]};
+		EndIf
+	EndFor
+
+	cl = newll;  Line Loop(cl) = ll[];
+	surfRectangle = news; Plane Surface(surfRectangle) = {cl};
+	
+	Printf("================================ _use_progression = %g",_use_progression);
+	
+	
+    If (_use_progression == 1)
+		Printf("================================ delta = %g",delta);
+		    
+		pr1 =  0.5;
+		pr2 =  2;
+		
+		noptest = Log[1-a*(1-pr2)/delta]/Log[pr2]-1;
+		noptest = Ceil[noptest];
+		Printf("================================ noptest = %g",noptest);
+	    If (noptest < 4)
+					noptest = 4;
+		EndIf
+		Printf("================================ noptest2 = %g",noptest);
+ 		nopp = noptest;
+		Transfinite Line {ll[0]}= nopp*s Using Progression pr1; 
+		Transfinite Line {ll[2]}= nopp*s Using Progression pr2; 
+	EndIf	
+		
+		
+	
+	If(_use_transfinite)
+		nopl = 2; 
+		Transfinite Line {ll[1],ll[3]} = nopl; 
+		Transfinite Surface(surfRectangle);
+		If (_use_recombine)
+			Recombine Surface{surfRectangle};
+		EndIf
+	EndIf
+
+	/* Definition of Physical entities (surfaces, lines). The Physical
+       entities tell GMSH the elements and their associated region numbers
+       to save in the file 'Ishape2d.msh'. */
+
+	Physical Surface ("MaterialX", MATERIALX) = {surfRectangle};      
+
+	Physical Line ("Ground",   GROUND) = {ll[2]};                 
+	Physical Line ("Terminal", TERMINAL) = {ll[0]};               
+	Physical Line ("RightBoundary", RIGHTBOUNDARY) = {ll[1]} ;     
+	Physical Line ("LeftBoundary", LEFTBOUNDARY) = {ll[3]} ;       
+
+	Physical Line ("Boundary", BOUNDARY) = {ll[]} ; 
+	
+EndIf
+
+If(_use_transfinite)
+	If (_use_recombine)
+		Recursive Color Red { Surface{surfRectangle};}
+	Else
+		Recursive Color Blue { Surface{surfRectangle};}
+	EndIf
+Else
+	If (_use_recombine)
+		Recursive Color Orange { Surface{surfRectangle};}
+	Else
+		Recursive Color Black { Surface{surfRectangle};}
+	EndIf
+EndIf
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.pro b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.pro
new file mode 100644
index 0000000000000000000000000000000000000000..4832b2a4998723d71b8d44263e6731216808766f
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi.pro
@@ -0,0 +1,175 @@
+Include "cylinder2Daxi_data.pro";
+
+Group{
+   MaterialX = Region[MATERIALX]; /* MaterialX - homogenous domain */
+   Ground = Region[GROUND];       /* Boundary - various parts */
+   Terminal = Region[TERMINAL];
+   RightBoundary = Region[RIGHTBOUNDARY];
+   Axis = Region[LEFTBOUNDARY];                 // the axis is taken out of the domain
+   Cut1H = Region[RIGHTBOUNDARY];               // for the H formulation
+   BoundaryNotTerminal = Region[{RIGHTBOUNDARY}];
+  
+   Sur_Terminals_FWece = Region[{Ground, Terminal}]; // all terminals
+  
+   Vol_FW = Region[{MaterialX}]; // domain without the boundary
+   Sur_FW = Region[{Sur_Terminals_FWece, RightBoundary}]; //all boundary
+   Dom_FW = Region[ {Vol_FW, Sur_FW, Axis} ];
+ }
+ 
+ Function{
+  nu[#{MaterialX,Sur_FW}] = nu;             // magnetic reluctivity [m/H]
+  mu[#{MaterialX,Sur_FW}] = mu;             // permeability [H/m]
+  epsilon[#{MaterialX,Sur_FW}] = eps;       // permittivity [F/m]
+  sigma[#{MaterialX,Sur_FW}]  = sigma;      // conductivity [S/m]
+
+  // This is a problem with 2 terminals, out of which one is grounded.
+  // The non-grounded can be excited in voltage or in current.
+
+  If (Flag_AnalysisType == 0)    // voltage excitation 
+    // (Flag_AnalysisTypeFormulation==0) => formulation in E
+    VTerminal1[] = (Flag_AnalysisTypeFormulation==0) ? -1 : 1;
+  Else                            // current excitation
+    ITerminal1[] = (Flag_AnalysisTypeFormulation==0) ? -1 : 1;
+  EndIf
+
+ }
+
+Constraint{
+
+  // ece BC
+  { Name SetTerminalPotential; Type Assign;  // voltage excited terminals
+    Case {
+      { Region Ground; Value 0.; }
+      If((Flag_AnalysisType==0))    
+        { Region Terminal; Value VTerminal1[]; }
+      EndIf
+    }
+  }
+  { Name SetTerminalCurrent; Type Assign;   // current excited terminals
+    Case {
+      If((Flag_AnalysisType==1))
+        { Region Terminal; Value ITerminal1[]/h2Ddepth; }  // here the depth is needed
+      EndIf
+    }
+  }
+  { Name SetTerminalCurrentH; Type Assign;   // current excited terminals - formulation in H
+    Case {
+      If(Flag_AnalysisType==1)
+        { Region Cut1H; Value ITerminal1[]/h2Ddepth; }  
+      EndIf
+    }
+  }
+   
+  { Name SetTerminalPotentialH ;
+    Case {
+    If(Flag_AnalysisType==0)
+      { Region Cut1H; Value VTerminal1[] ; }
+    EndIf
+    }
+  }
+  
+  { Name ImposeHonAxis ;
+    Case {
+      If( Flag_AnalysisTypeFormulation==1 && Flag_Axi==1 ) // H
+          { Region Axis; Value 0 ; }
+      EndIf
+    }
+	}
+	
+  { Name ImposeHorder2onAxis ;
+    Case {
+      If( Flag_AnalysisTypeFormulation==1 && Flag_Axi==1 ) // H
+        { Region Axis; Value 0 ; }
+      EndIf
+    }
+  }
+   
+  { Name ImposeE ;
+  }
+
+}
+
+modelDir = "../";
+Dir = "res/";
+
+// The formulation and its tools
+If (Flag_AnalysisTypeFormulation==0)          
+  Include "../formulations/FullWave_E_ece_SISO_secondOrder.pro"                    // formulation in E
+Else 
+  Include "../formulations/FullWave_H_ece_SISO_cplx_2D_and_AXI_secondOrder.pro"    // formulation in H
+EndIf
+
+ 
+Macro Change_post_options
+Echo[Str[ "nv = PostProcessing.NbViews;",
+    "For v In {0:nv-1}",
+    "View[v].NbIso = 25;",
+    "View[v].RangeType = 3;" ,// per timestep
+    "View[v].ShowTime = 3;",
+    "View[v].IntervalsType = 3;",
+    "EndFor"
+  ], File "post.opt"];
+Return
+
+PostOperation {
+  If (Flag_AnalysisTypeFormulation==0)   // E
+
+    { Name Maps; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        Print [ gradV, OnElementsOf ElementsOf[Vol_FW,OnOneSideOf Sur_FW], File StrCat[Dir,"map_gradV.pos" ]];
+        Print [ Vterminal, OnElementsOf ElementsOf[Sur_FW], File StrCat[Dir,"map_Vterminals.pos" ]];
+
+        Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+        Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+        Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+
+        // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+        Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+
+        Print [ VnotTerminals, OnElementsOf Vol_FW, File StrCat[Dir,"map_VnotTerminals.pos" ]];
+
+        Call Change_post_options;
+      }
+    }   
+
+    { Name TransferMatrix; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        If(Flag_AnalysisType==1)  // current excitation
+          Print [ Vterminal, OnRegion Terminal,
+            Format Table , File  > StrCat[Dir, "test_Z_RI_formE.s1p"]] ;
+        Else
+          Print [ I, OnRegion Terminal,
+            Format Table , File  > StrCat[Dir, "test_Y_RI_formE.s1p"]] ;
+        EndIf
+      }  
+    }
+  
+  Else // H
+
+    { Name Maps; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]]; 
+	      Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+        Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+
+        // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+        Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+        Call Change_post_options;
+      }    
+    }
+
+    { Name TransferMatrix; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        If(Flag_AnalysisType==1)  // current excitation
+          Print [ Vterminal, OnRegion Cut1H,
+            Format Table , File  > StrCat[Dir, "test_Z_RI_formH.s1p"]] ;
+        Else
+          Print [ I, OnRegion Cut1H,
+             Format Table , File  > StrCat[Dir, "test_Y_RI_formH.s1p"]] ;
+        EndIf
+      }  
+    }  
+
+  EndIf
+}
+
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi_data.pro b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi_data.pro
new file mode 100644
index 0000000000000000000000000000000000000000..a7150d695218ed916c11163b3539e8b480face81
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder2Daxi_data.pro
@@ -0,0 +1,163 @@
+/*
+Geometry:
+a = radius of the cylinder [m]
+l = height of the cylinder [m]
+==
+Material 
+epsr = relative permittivity
+mur = relative permeability
+sigma = conductivity [S/m]
+*/
+
+cGUI= "{TEST-Cilinder2Daxi-ProblemData/";
+cGUI0 = StrCat[cGUI, "0"];
+cGUI1 = StrCat[cGUI, "1"];
+cGUI2 = StrCat[cGUI, "2"];
+cGUI3 = StrCat[cGUI, "3"];
+cGUI4 = StrCat[cGUI, "4"];
+close_menu = 1;
+
+/* new menu for the interface - which test */
+mTypeTest = StrCat[cGUI0,"Test/0"];
+colorMTypeTest = "Orange";
+/* new menu for the interface - frequencies */
+mValuesBC = StrCat[cGUI1,"Frequency/0"];
+colorMValuesBC = "Ivory";
+/* new menu for the interface - type of terminal excitation */
+mTypeBC = StrCat[cGUI2,"Type of BC/0"];
+colorMTypeBC = "Red";
+/* new menu for the interface - type of formulation */
+mTypeBC2 = StrCat[cGUI3,"Type of formulation/0"];
+colorMTypeBC = "Blue";
+/* new menu for the interface - type of formulation */
+mTypeMesh = StrCat[cGUI4,"MeshSettings/"];
+colorMTypeMesh = "Red";
+
+/* Test */
+DefineConstant[
+  Flag_WhichTest = { 0,
+    Choices{
+      0="a = 2.5 um, l = 10 um",
+      1="a = 4 mm, l = 10 mm"},
+    Name Str[mTypeTest], Highlight Str[colorMTypeTest], Closed !close_menu,
+	ServerAction Str["Reset", "GetDP/1ResolutionChoices" , ',' , StrCat[mValuesBC, "0Working Frequency"] ]}
+	];
+	
+If (Flag_WhichTest==0)
+	// dimensions used in the SCEE 2020 and JMI papers
+	a = 2.5e-6;
+	l = 10e-6;
+	fmin = 1e7;   // Hz
+	fmax = 100e9; // Hz
+	nop = 20;
+  freqs()=LogSpace[Log10[fmin],Log10[fmax],nop];
+Else
+	// a inspired  from Wu coax, but l is short
+	a = 4e-3;
+	l = 10e-3;
+	fmin = 1;   // Hz
+	fmax = 100e6; // Hz
+	nop = 20;
+	freqs()=LogSpace[Log10[fmin],Log10[fmax],nop];
+EndIf
+	
+epsr = 1;
+mur = 1;
+sigma = 6.6e7;
+
+eps0 = 8.854187818e-12; // F/m - absolute permitivity of vacuum
+mu0  = 4.e-7 * Pi;      // H/m - absolute permeability of vacuum
+nu0  = 1/mu0;           // m/H - absolute reluctivity of vacuum
+
+eps = eps0*epsr;        // F/m - absolute permitivity
+mu = mu0*mur;           // F/m - absolute permeability
+nu = 1/mu;   	
+	
+/* Frequencies */
+DefineConstant[
+_use_freq_loop = {0,  Choices{0,1}, Name StrCat[mValuesBC, "0Loop on frequencies?"],
+    ServerAction Str["Reset", StrCat[mValuesBC, "0Working Frequency"]], Highlight "Yellow"}
+  Freq  = {freqs(0), Choices{freqs()}, Loop _use_freq_loop, Name StrCat[mValuesBC, "0Working Frequency"],
+    Units "Hz", Highlight  Str[colorMValuesBC], Closed !close_menu}
+];
+
+/* Excitation type */
+DefineConstant[
+  Flag_AnalysisType = {  TERMINAL_EXC,
+    Choices{
+      0="bottomTerm ev",
+      1="bottomTerm ec"},
+    Name Str[mTypeBC], Highlight Str[colorMTypeBC], Closed !close_menu,
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+	];
+	
+	
+	
+
+/* Which formulation */
+DefineConstant[
+  Flag_AnalysisTypeFormulation = { FORMULATION,
+    Choices{
+      0="0: formulation in E inside + ECE",
+      1="1: formulation in H inside + ECE"
+    },
+    Name Str[mTypeBC2], Highlight Str[colorMTypeBC], Closed !close_menu,
+    Help Str["E inside, electric V on the boundary",
+      "H inside, reduced magnetic V on the boundary"],
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+];
+
+s_min = 1;
+s_max = 1.414213562373095; 
+nops = 7;
+
+s_values()=LinSpace[s_min,s_max,nops];
+
+DefineConstant[
+   _use_uniformMesh = {1, Choices{0,1}, Name StrCat[mTypeMesh,"0Uniform mesh?"], Highlight "Pink", Closed !close_menu},
+   _use_progression = {0, Choices{0,1}, Name StrCat[mTypeMesh,"1Use geometric progression on the bottom line (only for non-uniform mesh)?"], Highlight "Pink", Closed !close_menu, ReadOnly _use_uniformMesh},
+   _use_transfinite = {0, Choices{0,1}, Name StrCat[mTypeMesh,"2One element along Oy ; Transfinite for uniform mesh?"], Highlight "Pink", Closed !close_menu, ReadOnly _use_uniformMesh},
+   _use_recombine = {0, Choices{0,1}, Name StrCat[mTypeMesh,"3Use recombine"], Highlight "Pink", Closed !close_menu},
+   s = {s_min, Name StrCat[mTypeMesh,"6Mesh factor"]}
+   
+   FE_Order = { FE_ORDER,
+    Choices{
+      1="1: first order elements",
+      2="2: second order elements"
+    },
+    Name StrCat[mTypeMesh,"7Element order"], Highlight Str[colorMTypeMesh], Closed !close_menu,
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+];
+
+Printf("a = %g  m",a);
+Printf("l = %g  m",l);
+Printf("fmin = %g  Hz",fmin);
+Printf("fmax = %g  Hz",fmax);
+Printf("s = %g ",s);
+Printf("FE order = %g ",FE_Order);
+
+
+modelDim = 2; // 
+Flag_Axi = 1; // 1 for AXI - it makes sense only for modelDim = 2
+
+If ((modelDim == 2)&&(Flag_Axi == 0)) // 2D
+	h2Ddepth = h;
+ElseIf ((modelDim == 2)&&(Flag_Axi == 1))   // 2D AXI // 2.5 D
+	h2Ddepth = 2*Pi;
+Else // 3D
+    h2Ddepth = 1;
+EndIf
+
+//=============================
+// Indexes of physical entities
+// Surfaces
+MATERIALX = 100;
+
+// boundaries
+GROUND   = 120 ;
+TERMINAL = 121 ;
+RIGHTBOUNDARY = 131 ;
+LEFTBOUNDARY  = 132; // axis
+
+BOUNDARY  = 331; 
+
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.geo b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.geo
new file mode 100644
index 0000000000000000000000000000000000000000..78861eea899911584eb4451e58e0207032808d76
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.geo
@@ -0,0 +1,89 @@
+Include "cylinder3D_data.pro";
+
+delta = Sqrt(2.0/(2*Pi*Freq*mu*sigma));
+Printf("Freq = %e",Freq);
+If (delta < a)
+	Printf("delta less than a");
+	lcar = delta/nbDelta;
+Else
+	Printf("delta GREATER than a");
+	lcar = l/10;
+EndIf
+
+
+lcarCenter = a/3;
+
+p0 = newp; Point(p0) = {0,0,0,lcarCenter};
+p1 = newp; Point(p1) = {a,0,0,lcar};
+p2 = newp; Point(p2) = {0,a,0,lcar};
+p3 = newp; Point(p3) = {-a,0,0,lcar};
+p4 = newp; Point(p4) = {0,-a,0,lcar};
+
+p0l = newp; Point(p0l) = {0,0,l,lcarCenter};
+p1l = newp; Point(p1l) = {a,0,l,lcar};
+p2l = newp; Point(p2l) = {0,a,l,lcar};
+p3l = newp; Point(p3l) = {-a,0,l,lcar};
+p4l = newp; Point(p4l) = {0,-a,l,lcar};
+
+
+c1 = newc; Circle(c1) = {p1,p0,p2};
+c2 = newc; Circle(c2) = {p2,p0,p3};
+c3 = newc; Circle(c3) = {p3,p0,p4};
+c4 = newc; Circle(c4) = {p4,p0,p1};
+
+c1l = newc; Circle(c1l) = {p1l,p0l,p2l};
+c2l = newc; Circle(c2l) = {p2l,p0l,p3l};
+c3l = newc; Circle(c3l) = {p3l,p0l,p4l};
+c4l = newc; Circle(c4l) = {p4l,p0l,p1l};
+
+l1 = newl; Line(l1) = {p1, p1l};
+l2 = newl; Line(l2) = {p2, p2l};
+l3 = newl; Line(l3) = {p3, p3l};
+l4 = newl; Line(l4) = {p4, p4l};
+
+cL = newll;   Curve Loop(cL) = {c1,c2,c3,c4};      scL = news;  Surface(scL) = {cL};
+cLl = newll;  Curve Loop(cLl) = {c1l,c2l,c3l,c4l}; scLl = news; Surface(scLl) = {cLl};
+cL12 = newll; Curve Loop(cL12) = {c1,l2,-c1l,-l1}; scL12 = news; Surface(scL12) = {cL12};
+cL23 = newll; Curve Loop(cL23) = {c2,l3,-c2l,-l2}; scL23 = news; Surface(scL23) = {cL23};
+cL34 = newll; Curve Loop(cL34) = {c3,l4,-c3l,-l3}; scL34 = news; Surface(scL34) = {cL34};
+cL41 = newll; Curve Loop(cL41) = {c4,l1,-c4l,-l4}; scL41 = news; Surface(scL41) = {cL41};
+
+closedS = newsl; Surface Loop(closedS) = {scL,scLl,scL12,scL23,scL34,scL41};
+volDom = newv; Volume(volDom) = {closedS};
+
+Transfinite Line{l1} = 10*s;
+Transfinite Line{l2} = 10*s;
+Transfinite Line{l3} = 10*s;
+Transfinite Line{l4} = 10*s;
+Transfinite Surface {scL12};
+Transfinite Surface {scL23};
+Transfinite Surface {scL34};
+Transfinite Surface {scL41};
+
+Field[1] = Distance;
+Field[1].SurfacesList = {scL12,scL23,scL34,scL41};
+Field[1].Sampling = 50;
+Field[2] = Threshold;
+Field[2].InField = 1;
+Field[2].SizeMin = lcar;
+Field[2].SizeMax = a/3;
+Field[2].DistMin = 0;
+Field[2].DistMax = 3*delta;
+
+Background Field = 2; 
+Mesh.MeshSizeExtendFromBoundary = 0;
+Mesh.MeshSizeFromPoints = 0;
+Mesh.MeshSizeFromCurvature = 0;
+Mesh.Algorithm = 5;
+
+
+
+Physical Volume ("MaterialX", 100) = {volDom} ;      
+
+Physical Surface ("Ground",   120) = {scLl} ;          
+Physical Surface ("Terminal", 121) = {scL} ;          
+Physical Surface ("BoundaryNotTerminal", 131) = {scL12,scL23,scL34,scL41} ;  
+
+// cut for the H formulation
+Cohomology(1) {{131},{}}; // bnd fara term
+CUT1H = 132;
\ No newline at end of file
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.pro b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.pro
new file mode 100644
index 0000000000000000000000000000000000000000..1822241207179b445a75bf67900e0116457a683f
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D.pro
@@ -0,0 +1,160 @@
+Include "cylinder3D_data.pro";
+
+Group{
+   MaterialX = Region[MATERIALX]; /* MaterialX - homogenous domain */
+   Ground = Region[GROUND];       /* Boundary - various parts */
+   Terminal = Region[TERMINAL];
+   
+   BoundaryNotTerminal = Region[BOUNDARYNOTTERMINAL];
+   Cut1H = Region[132];  // for the H formulation  // this is CUT1H
+
+   Vol_FW = Region[{MaterialX}]; // domain without the boundary
+   Sur_Terminals_FWece = Region[{Ground, Terminal}]; // all terminals
+   Sur_FW = Region[{Sur_Terminals_FWece, BoundaryNotTerminal}]; //all boundary
+   Dom_FW = Region[ {Vol_FW, Sur_FW} ];
+ }
+
+ Function{
+   /* Material properties are defined piecewise, for elementary groups */
+   /* the values in the right hand side are defined in Ishape2d_data.pro */
+
+   nu[#{MaterialX,Sur_FW}] = nu;  // magnetic reluctivity [m/H]
+   mu[#{MaterialX,Sur_FW}] = mu;  // permeability [H/m]
+   epsilon[#{MaterialX,Sur_FW}] = eps;       // permittivity [F/m]
+   sigma[#{MaterialX,Sur_FW}]  = sigma;      // conductivity [S/m]
+
+   // FW in E, ece BC, voltage excitation on bottom, ground on top
+   // When imposing voltage or current via a constraint, the region appears there
+   // If you have a complex, the value  has to be a function => use square brackets []
+   If (Flag_AnalysisTypeFormulation==0) // E
+      If(Flag_AnalysisType==0) // voltage excitation
+         VTerminal1[] = -VTermRMS*Complex[Cos[VTermPhase],Sin[VTermPhase]];
+      Else  // current excitation
+         ITerminal1[] = -ITermRMS*Complex[Cos[ITermPhase],Sin[ITermPhase]];
+      EndIf
+   Else // H
+      If(Flag_AnalysisType==0) // voltage excitation
+         VTerminal1[] = VTermRMS*Complex[Cos[VTermPhase],Sin[VTermPhase]];
+      Else  // current excitation
+         ITerminal1[] = ITermRMS*Complex[Cos[ITermPhase],Sin[ITermPhase]];
+      EndIf
+   EndIf
+ }
+
+ Constraint{
+
+   // ece BC or electrokinetics
+   { Name SetTerminalPotential; Type Assign;  // voltage excited terminals
+     Case {
+       { Region Ground; Value 0.; }
+       If(Flag_AnalysisType==0)
+         { Region Terminal; Value VTerminal1[]; }
+       EndIf
+     }
+   }
+   { Name SetTerminalCurrent; Type Assign;   // current excited terminals
+     Case {
+       If(Flag_AnalysisType==1)
+         { Region Terminal; Value ITerminal1[]/h2Ddepth; }  
+       EndIf
+     }
+   }
+   
+   { Name SetTerminalCurrentH; Type Assign;   // current excited terminals - formulation in H
+     Case {
+       If(Flag_AnalysisType==1)
+         { Region Cut1H; Value ITerminal1[]/h2Ddepth; }  
+       EndIf
+     }
+   }
+   
+   { Name SetTerminalPotentialH ;
+    Case {
+      If(Flag_AnalysisType==0)
+      { Region Cut1H; Value VTerminal1[] ; }
+      EndIf
+    }
+  }
+
+}
+
+modelDir = "../";
+Dir = "res/";
+
+// The formulation and its tools
+If (Flag_AnalysisTypeFormulation==0)  // E inside
+  Include "../formulations/FullWave_E_ece_SISO_secondOrder.pro"
+Else // H inside
+  Include "../formulations/FullWave_H_ece_SISO_cplx_3D_secondOrder.pro"
+EndIf
+
+Macro Change_post_options
+Echo[Str[ "nv = PostProcessing.NbViews;",
+    "For v In {0:nv-1}",
+    "View[v].NbIso = 25;",
+    "View[v].RangeType = 3;" ,// per timestep
+    "View[v].ShowTime = 3;",
+    "View[v].IntervalsType = 3;",
+    "EndFor"
+  ], File "post.opt"];
+Return
+
+
+PostOperation {
+  If (Flag_AnalysisTypeFormulation==0)   // E
+
+    { Name Maps; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        Print [ gradV, OnElementsOf ElementsOf[Vol_FW,OnOneSideOf Sur_FW], File StrCat[Dir,"map_gradV.pos" ]];
+        Print [ Vterminal, OnElementsOf ElementsOf[Sur_FW], File StrCat[Dir,"map_Vterminals.pos" ]];
+        Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+        Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+        Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+        // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+        Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+        Print [ VnotTerminals, OnElementsOf Vol_FW, File StrCat[Dir,"map_VnotTerminals.pos" ]];
+
+        Call Change_post_options;
+      }
+    }
+
+    { Name TransferMatrix; NameOfPostProcessing FW_E_ece ;
+      Operation {
+        If(Flag_AnalysisType==1)  // current excitation        
+          Print [ Vterminal, OnRegion Terminal,
+            Format Table , File  > StrCat[Dir, "test_Z_RI_formE.s1p"]] ;
+        Else 
+          Print [ I, OnRegion Terminal,
+            Format Table , File  > StrCat[Dir, "test_Y_RI_formE.s1p"]] ;
+        EndIf
+      }
+    }
+  
+  Else // H
+ 
+    { Name TransferMatrix; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        If(Flag_AnalysisType==1)  // current excitation        
+          Print [ Vterminal, OnRegion Cut1H,
+            Format Table , File  > StrCat[Dir, "test_Z_RI_formH.s1p"]] ;
+          Else      
+          Print [ I, OnRegion Cut1H,
+            Format Table , File  > StrCat[Dir, "test_Y_RI_formH.s1p"]] ;
+        EndIf
+      }
+    }
+
+    { Name Maps; NameOfPostProcessing FW_H_ece ;
+      Operation {
+        Print [ E, OnElementsOf Vol_FW, File StrCat[Dir,"map_E.pos" ]];
+        Print [ J, OnElementsOf Vol_FW, File StrCat[Dir,"map_J.pos" ]];
+        Print [ rmsJ, OnElementsOf Vol_FW, File StrCat[Dir,"map_absJ.pos" ]];
+
+        // Print [ B, OnElementsOf Vol_FW, File StrCat[Dir,"map_B.pos" ]];
+        Print [ H, OnElementsOf Vol_FW, File StrCat[Dir,"map_H.pos" ]];
+        Call Change_post_options;
+      }
+    }  
+  EndIf
+
+}
\ No newline at end of file
diff --git a/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D_data.pro b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D_data.pro
new file mode 100644
index 0000000000000000000000000000000000000000..310098bdd5bad9bd5e7cfd436f3ab506a99fb2d8
--- /dev/null
+++ b/ECE_full_wave_E-H_Academic/geo_pro/cylinder3D_data.pro
@@ -0,0 +1,167 @@
+/*
+Geometry:
+a = radius of the cylinder [m]
+l = height of the cylinder [m]
+==
+Material 
+epsr = relative permittivity
+mur = relative permeability
+sigma = conductivity [S/m]
+*/
+colorro = "LightGrey";
+
+cGUI= "{TEST-Cilinder3D-ProblemData/";
+cGUI0 = StrCat[cGUI, "0"];
+cGUI1 = StrCat[cGUI, "1"];
+cGUI2 = StrCat[cGUI, "2"];
+cGUI3 = StrCat[cGUI, "3"];
+cGUI4 = StrCat[cGUI, "4"];
+close_menu = 1;
+
+/* new menu for the interface - which test */
+mTypeTest = StrCat[cGUI0,"Test/0"];
+colorMTypeTest = "Orange";
+/* new menu for the interface - frequencies */
+mValuesBC = StrCat[cGUI1,"Frequency/0"];
+colorMValuesBC = "Ivory";
+/* new menu for the interface - type of terminal excitation */
+mTypeBC = StrCat[cGUI2,"Type of BC/0"];
+colorMTypeBC = "Red";
+/* new menu for the interface - type of formulation */
+mTypeBC2 = StrCat[cGUI3,"Type of formulation/0"];
+colorMTypeBC = "Blue";
+/* new menu for the interface - type of formulation */
+mTypeMesh = StrCat[cGUI4,"MeshSettings/"];
+colorMTypeMesh = "Red";
+
+/* Test */
+DefineConstant[
+  Flag_WhichTest = { 0,
+    Choices{
+      0="a = 2.5 um, l = 10 um",
+      1="a = 4 mm, l = 10 mm"},
+    Name Str[mTypeTest], Highlight Str[colorMTypeTest], Closed !close_menu,
+	ServerAction Str["Reset", "GetDP/1ResolutionChoices" , ',' , StrCat[mValuesBC, "0Working Frequency"] ]}
+	];
+	
+If (Flag_WhichTest==0)
+	/* dimensions used in the SCEE 2020, 2022 and JMI papers */
+	a = 2.5e-6;
+	l = 10e-6;
+	fmin = 1e7;   // Hz
+	fmax = 100e9; // Hz
+	nop = 10;
+    //freqs()=LogSpace[Log10[fmin],Log10[fmax],nop];
+    freqs()=LinSpace[fmin,fmax,nop];
+Else
+	/* a inspired  from Wu coax, but l is short */
+	a = 4e-3;
+	l = 10e-3;
+	fmin = 1;   // Hz
+	//fmax = 600e6; // Hz
+	fmax = 100e6; // Hz
+	//fmax = 1e4; 
+	nop = 20;
+	freqs()=LogSpace[Log10[fmin],Log10[fmax],nop];
+    //freqs()=LinSpace[fmin,fmax,nop];
+EndIf
+
+epsr = 1;
+mur = 1;
+sigma = 6.6e7;
+
+eps0 = 8.854187818e-12; // F/m - absolute permitivity of vacuum
+mu0  = 4.e-7 * Pi;      // H/m - absolute permeability of vacuum
+nu0  = 1/mu0;           // m/H - absolute reluctivity of vacuum
+
+eps = eps0*epsr;        // F/m - absolute permitivity
+mu = mu0*mur;           // F/m - absolute permeability
+nu = 1/mu;   	
+	
+// Frequencies
+DefineConstant[
+_use_freq_loop = {0,  Choices{0,1}, Name StrCat[mValuesBC, "0Loop on frequencies?"],
+    ServerAction Str["Reset", StrCat[mValuesBC, "0Working Frequency"]], Highlight "Yellow"}
+  Freq  = {freqs(0), Choices{freqs()}, Loop _use_freq_loop, Name StrCat[mValuesBC, "0Working Frequency"],
+    Units "Hz", Highlight  Str[colorMValuesBC], Closed !close_menu}
+];
+
+// Excitation type
+DefineConstant[
+  Flag_AnalysisType = { TERMINAL_EXC,
+    Choices{
+      0="bottomTerm ev",
+      1="bottomTerm ec"},
+    Name Str[mTypeBC], Highlight Str[colorMTypeBC], Closed !close_menu,
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+	];
+
+
+// Which formulation
+DefineConstant[
+  Flag_AnalysisTypeFormulation = { FORMULATION,
+    Choices{
+      0="0: formulation in E inside + ECE",
+      1="1: formulation in H inside + ECE"
+    },
+    Name Str[mTypeBC2], Highlight Str[colorMTypeBC], Closed !close_menu,
+    Help Str["E inside, electric V on the boundary",
+      "H inside, reduced magnetic V on the boundary"],
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+];
+
+
+meshSettings = StrCat[cGUI,"5MeshSettings/0"];
+
+DefineConstant[
+   s = {1, Name StrCat[meshSettings, "1Mesh factor/1Mesh factor for Oz (1 means 10 nodes on Oz)"]}
+   nbDelta = {1, Name StrCat[meshSettings, "1Mesh factor/2Nb of elems per skin depth (lcar is delta over nbDelta)"]}
+   Flag_ElementOrder = { FE_ORDER,
+    Choices{
+      1="1: first order elements",
+      2="2: second order elements"
+    },
+    Name StrCat[meshSettings, "2Element order"], Highlight "Red", Closed !close_menu,
+    ServerAction Str["Reset", "GetDP/1ResolutionChoices"]}
+	_use_recombine = {0, Choices{0,1}, Name StrCat[meshSettings, "3Use recombine?"], Highlight "Yellow", Closed !close_menu}
+];
+
+FE_Order = Flag_ElementOrder;
+modelDim = 3; 
+Flag_Axi = 0; // 1 for AXI - it makes sense only for modelDim = 2
+
+h2Ddepth = (modelDim==3) ? 1 : (Flag_Axi ? 2*Pi : l);
+
+DefineConstant[
+  // Flag_AnalysisType
+  // ==0 bottom ev
+  // ==1 bottom ec
+
+  VGroundRMS  = {0, Name StrCat[mValuesBC, "2Top/1Potential on bottom (rms)"], Units "V" , ReadOnly 1, Highlight Str[colorro],
+    Visible (Flag_AnalysisType==0) || (Flag_AnalysisType==1)}
+  VGroundPhase  = {0, Name StrCat[mValuesBC, "2Top/1Potential on bottom, phase"], Units "rad",  ReadOnly 1, Highlight Str[colorro],
+    Visible (Flag_AnalysisType==0) || (Flag_AnalysisType==1)}
+	
+  VTermRMS  = {1, Name StrCat[mValuesBC, "1Bottom/1Potential on Term1 (rms)"], Units "V" , ReadOnly 0, Highlight Str[colorMValuesBC],
+    Visible (Flag_AnalysisType==0)}
+  VTermPhase  = {0, Name StrCat[mValuesBC, "1Bottom/1Potential on Term1, phase"], Units "rad",  ReadOnly 0, Highlight Str[colorMValuesBC],
+    Visible (Flag_AnalysisType==0)}
+	
+  ITermRMS  = {1, Name StrCat[mValuesBC, "1Bottom/1Current through Term1 (enters the domain) (rms)"], Units "A" , ReadOnly 0, Highlight Str[colorMValuesBC],
+    Visible (Flag_AnalysisType==1) }
+  ITermPhase  = {0, Name StrCat[mValuesBC, "1Bottom/Current through Term1 (enters the domain), phase"], Units "rad",  ReadOnly 0, Highlight Str[colorMValuesBC],
+    Visible (Flag_AnalysisType==1) } 		
+];
+
+
+//=============================
+// Indexes of physical entities
+// Surfaces
+MATERIALX = 100;
+
+// boundaries
+GROUND   = 120 ;
+TERMINAL = 121 ;
+BOUNDARYNOTTERMINAL = 131 ;
+
+BOUNDARY  = 331; 
diff --git a/ElectromagneticScattering/scattererTmatrix.geo b/ElectromagneticScattering/scattererTmatrix.geo
index 65b5a7797995298711b67393deadc67b58c46480..3b5cbce7b95bad4fa18bb909aeea638c80222efb 100644
--- a/ElectromagneticScattering/scattererTmatrix.geo
+++ b/ElectromagneticScattering/scattererTmatrix.geo
@@ -30,7 +30,7 @@ If (flag_shape==CONE)
   Dilate { { 0,0,0 }, { 1 , cone_ry/cone_rx , 1} } { Volume{1}; }
 EndIf
 If (flag_shape==TOR)
-  Torus (1) = {0,0,0,tor_r1,tor_r2x,tor_angle*Pi/180};
+  U (1) = {0,0,0,tor_r1,tor_r2x,tor_angle*Pi/180};
   Dilate { { 0,0,0 }, { 1 , 1 , tor_r2z/tor_r2x} } { Volume{1}; }
 EndIf
 
diff --git a/ElectromagneticScattering/scattererTmatrix_data.geo b/ElectromagneticScattering/scattererTmatrix_data.geo
index 8699e8983744a091acea15fe287c1a3a06666bfb..764c01ae51c2b6b9cb657c19d56412018d9f9f38 100644
--- a/ElectromagneticScattering/scattererTmatrix_data.geo
+++ b/ElectromagneticScattering/scattererTmatrix_data.geo
@@ -34,7 +34,7 @@ RES_QNM   = 3;
 
 DefineConstant[
   flag_shape = {ELL , Name StrCat[pp0, "0Scatterer shape"], 
-    Choices {ELL="ellispoid",PARALL="parallelepiped",CYL="cylinder",CONE="cone",TOR="split torus"},Closed 0}];
+    Choices {ELL="ellispoid",PARALL="parallelepiped",CYL="cylinder",CONE="cone",TOR="split U"},Closed 0}];
 
 If (flag_shape==ELL)
   DefineConstant[
@@ -88,10 +88,10 @@ If (flag_shape==CONE)
 EndIf
 If (flag_shape==TOR)
   DefineConstant[
-    tor_r1    = { 300 , Name StrCat[pp0 , "1torus radius 1  [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_r2x   = { 100 , Name StrCat[pp0 , "2torus radius 2x [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_r2z   = { 50  , Name StrCat[pp0 , "3torus radius 2z [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_angle = { 340 , Name StrCat[pp0 , "4torus angle [deg]"]   , Highlight Str[colorppOK] , Closed 0, Min 5, Max 355}];
+    tor_r1    = { 300 , Name StrCat[pp0 , "1U radius 1  [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_r2x   = { 100 , Name StrCat[pp0 , "2U radius 2x [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_r2z   = { 50  , Name StrCat[pp0 , "3U radius 2z [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_angle = { 340 , Name StrCat[pp0 , "4U angle [deg]"]   , Highlight Str[colorppOK] , Closed 0, Min 5, Max 355}];
   rbb = tor_r1+tor_r2x;
 EndIf
 DefineConstant[
diff --git a/ElectromagneticScattering/scattering_data.geo b/ElectromagneticScattering/scattering_data.geo
index 8cea03ed354067b62804b7b297c237710caf08fd..ab086e3c43e0028adfad68d46a7355a38926ad55 100644
--- a/ElectromagneticScattering/scattering_data.geo
+++ b/ElectromagneticScattering/scattering_data.geo
@@ -34,7 +34,7 @@ RES_QNM   = 3;
 
 DefineConstant[
   flag_shape = {ELL , Name StrCat[pp0, "0Scatterer shape"], 
-    Choices {ELL="ellispoid",PARALL="parallelepiped",CYL="cylinder",CONE="cone",TOR="split torus"},Closed 0}];
+    Choices {ELL="ellispoid",PARALL="parallelepiped",CYL="cylinder",CONE="cone",TOR="split U"},Closed 0}];
 
 If (flag_shape==ELL)
   DefineConstant[
@@ -88,10 +88,10 @@ If (flag_shape==CONE)
 EndIf
 If (flag_shape==TOR)
   DefineConstant[
-    tor_r1    = { 300 , Name StrCat[pp0 , "1torus radius 1  [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_r2x   = { 100 , Name StrCat[pp0 , "2torus radius 2x [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_r2z   = { 50  , Name StrCat[pp0 , "3torus radius 2z [nm]"], Highlight Str[colorppOK] , Closed 0},
-    tor_angle = { 340 , Name StrCat[pp0 , "4torus angle [deg]"]   , Highlight Str[colorppOK] , Closed 0, Min 5, Max 355}];
+    tor_r1    = { 300 , Name StrCat[pp0 , "1U radius 1  [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_r2x   = { 100 , Name StrCat[pp0 , "2U radius 2x [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_r2z   = { 50  , Name StrCat[pp0 , "3U radius 2z [nm]"], Highlight Str[colorppOK] , Closed 0},
+    tor_angle = { 340 , Name StrCat[pp0 , "4U angle [deg]"]   , Highlight Str[colorppOK] , Closed 0, Min 5, Max 355}];
   rbb = tor_r1+tor_r2x;
 EndIf
 DefineConstant[