From 3ef833dbd1089eecbe98ad42b6f97d48de7f900f Mon Sep 17 00:00:00 2001
From: Guillaume D <guillaume.demesy@fresnel.fr>
Date: Fri, 23 Sep 2022 11:34:59 +0200
Subject: [PATCH] gnu parallel

---
 DiffractionGratings/grating3D.pro             |  5 ---
 .../grating3D_data_halfellipsoid.geo          |  6 +--
 .../grating3D_parallel_Mmatrix.sh             | 37 ++++++++++++-------
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/DiffractionGratings/grating3D.pro b/DiffractionGratings/grating3D.pro
index 07461d4..b9396c3 100644
--- a/DiffractionGratings/grating3D.pro
+++ b/DiffractionGratings/grating3D.pro
@@ -436,11 +436,6 @@ PostProcessing {
 PostOperation {
   { Name postop_helmholtz_vector; NameOfPostProcessing postpro_helmholtz_vector ;
     Operation {
-      Print [ uz , OnElementsOf Gama, File StrCat[myDir,"uz.pos"]];
-      Print [ u  , OnPlane { {0.5*(-period_x-dys), -dyc/2,hh_L_6}
-                             {0.5*( period_x-dys), -dyc/2,hh_L_6}
-                             {0.5*(-period_x+dys),  dyc/2,hh_L_6} }
-                              {npts_checkpoyX-1,npts_checkpoyY-1} , File StrCat[myDir,"uz_check.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"];
diff --git a/DiffractionGratings/grating3D_data_halfellipsoid.geo b/DiffractionGratings/grating3D_data_halfellipsoid.geo
index 5095cab..04cd83c 100644
--- a/DiffractionGratings/grating3D_data_halfellipsoid.geo
+++ b/DiffractionGratings/grating3D_data_halfellipsoid.geo
@@ -65,11 +65,11 @@ DefineConstant[
     FlagLinkFacets = {0      , Name StrCat[pp5,"/8FlagLinkFacets? [-]"], Choices {0,1}, Visible 0},
         
     InterpSampling     = { 10   , Name StrCat[pp6,"/0Interpolation grid step [nm]"]},
-    Flag_interp_cubic  = { 1    , Name StrCat[pp6,"/1Interpolate on cubic grid?"], Choices {0,1} },
+    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    = { 1    , Name StrCat[pp6,"/4Output Scattered Electric Field cuts?"] , Choices {0,1} },
-    FlagOutPoyCut      = { 1    , Name StrCat[pp6,"/5Output Poynting cuts?"] , Choices {0,1} },
+    FlagOutEscaCuts    = { 0    , 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} },
     FlagOutPoyFull     = { 0    , Name StrCat[pp6,"/8Poynting Full Output?"] , Choices {0,1} },
diff --git a/DiffractionGratings/grating3D_parallel_Mmatrix.sh b/DiffractionGratings/grating3D_parallel_Mmatrix.sh
index 1efafd1..c7de727 100644
--- a/DiffractionGratings/grating3D_parallel_Mmatrix.sh
+++ b/DiffractionGratings/grating3D_parallel_Mmatrix.sh
@@ -2,30 +2,41 @@
 export OPENBLAS_NUM_THREADS=1
 export OMP_NUM_THREADS=1
 
-export NPROC=64
-export nb_phi=64
+# export NPROC=18
+# export nb_phi=3
+# export nb_lam=3
+export NPROC=100
+export nb_phi=50
+export nb_lam=100
 export myDir="res_Matrix_nb_phi"$nb_phi
 export myFile="run_phideg_values_"$nb_phi".out"
 
 rm -r $myDir
 rm $myFile
 mkdir $myDir
+gmsh grating3D.geo -3 -o grating3D.msh
 
 myfunc() {
-    local mysubDir=$myDir/run$1_psi$2
+    local mysubDir=$myDir/run_lam$1_phi$2_psi$3
     mkdir $mysubDir
-    cp grating3D.geo grating3D.pro grating3D_data_halfellipsoid.geo grating3D_data.geo grating3D_materials.pro $mysubDir
-    local phi=$(echo "scale=10;360/($nb_phi)*$1" | bc )
-    if [ $2 -eq 0 ]; then echo $1"  "$phi >> $myDir/$myFile ; fi
+    cp grating3D.msh grating3D.pro grating3D_data_halfellipsoid.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 psi=$(echo "scale=10;90*$3" | bc )
     cd $mysubDir
-    echo gmsh grating3D.pro -setstring test_case halfellipsoid -setnumber thetadeg 50 -setnumber phideg $phi -setnumber psideg $2 -setstring Solver.SocketName id$1$2 -
-    if [ $2 -eq  0 ]; then cp res3D/rs.txt ../r_pin_sout_phi$1.out ; fi
-    if [ $2 -eq  0 ]; then cp res3D/rp.txt ../r_pin_pout_phi$1.out ; fi
-    if [ $2 -eq 90 ]; then cp res3D/rs.txt ../r_sin_sout_phi$1.out ; fi
-    if [ $2 -eq 90 ]; then cp res3D/rp.txt ../r_sin_pout_phi$1.out ; fi
+    getdp grating3D.pro -pre helmholtz_vector -msh grating3D.msh -cal -pos postop_helmholtz_vector -petsc_prealloc 200 -setstring test_case halfellipsoid -setnumber lambda0 $lam -setnumber thetadeg 50 -setnumber phideg $phi -setnumber psideg $psi
+    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
     cd ../..
+    rm -r $mysubDir
 }
 
 export -f myfunc
-# parallel --lb -j $NPROC myfunc ::: $(seq 1 $nb_phi) ::: 0 90
-parallel -j $NPROC myfunc ::: $(seq 1 $nb_phi) ::: 0 90
+parallel -j $NPROC myfunc ::: $(seq 0 $(($nb_lam-1))) ::: $(seq 0 $(($nb_phi-1))) ::: 0 1
-- 
GitLab