From df6d74c811ca5ff3ef9fe96d29613c21b88281d4 Mon Sep 17 00:00:00 2001
From: Klaus <klaus.boehnlein@tu-dresden.de>
Date: Mon, 9 Oct 2023 22:09:46 +0200
Subject: [PATCH] Update Tests

---
 src/Cell-Problem.cc              |  2 +-
 test/orthotropicrotation_1.py    |  8 +++
 test/orthotropicrotation_2.py    |  8 +++
 test/orthotropicrotationtest.cc  | 61 ++++++++++++++------
 test/parametrized_laminate.py    | 97 +++++++++++++++++++++++++++-----
 test/parametrizedlaminatetest.cc | 61 ++++++++++++++------
 6 files changed, 185 insertions(+), 52 deletions(-)

diff --git a/src/Cell-Problem.cc b/src/Cell-Problem.cc
index 0877756b..a86425e3 100644
--- a/src/Cell-Problem.cc
+++ b/src/Cell-Problem.cc
@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
     // read possible further parameters from the command line
     ParameterTreeParser::readOptions(argc, argv, parameterSet);
     // Print all parameters, to make them appear in the log file
-    std::cout << "Executable: harmonicmaps, with parameters:" << std::endl;
+    std::cout << "Input parameters:" << std::endl;
     parameterSet.report();
 
 //   ParameterTree parameterSet;
diff --git a/test/orthotropicrotation_1.py b/test/orthotropicrotation_1.py
index 7d15aba6..c17b0add 100644
--- a/test/orthotropicrotation_1.py
+++ b/test/orthotropicrotation_1.py
@@ -3,6 +3,14 @@ import ctypes
 import os
 import sys
 import numpy as np
+
+class ParameterSet(dict):
+    def __init__(self, *args, **kwargs):
+        super(ParameterSet, self).__init__(*args, **kwargs)
+        self.__dict__ = self
+
+parameterSet = ParameterSet()
+
 #---------------------------------------------------------------
 
 #--- define indicator function
diff --git a/test/orthotropicrotation_2.py b/test/orthotropicrotation_2.py
index 9a325f52..ff5757d6 100644
--- a/test/orthotropicrotation_2.py
+++ b/test/orthotropicrotation_2.py
@@ -3,6 +3,14 @@ import ctypes
 import os
 import sys
 import numpy as np
+
+class ParameterSet(dict):
+    def __init__(self, *args, **kwargs):
+        super(ParameterSet, self).__init__(*args, **kwargs)
+        self.__dict__ = self
+
+parameterSet = ParameterSet()
+
 #---------------------------------------------------------------
 
 #--- define indicator function
diff --git a/test/orthotropicrotationtest.cc b/test/orthotropicrotationtest.cc
index 962652fa..8f0a4268 100644
--- a/test/orthotropicrotationtest.cc
+++ b/test/orthotropicrotationtest.cc
@@ -96,23 +96,42 @@ int main(int argc, char *argv[])
   std::cout << "dir_path: " << file_path.parent_path() << std::endl;
   std::string dir_path  = file_path.parent_path();
 
-  ParameterTree parameterSet;
-  if (argc < 2)
-    ParameterTreeParser::readINITree(dir_path + "/orthotropicrotation_1.parset", parameterSet);
-  else
-  {
-    ParameterTreeParser::readINITree(argv[1], parameterSet);
+  // ParameterTree parameterSet;
+  // if (argc < 2)
+  //   ParameterTreeParser::readINITree(dir_path + "/orthotropicrotation_1.parset", parameterSet);
+  // else
+  // {
+  //   ParameterTreeParser::readINITree(argv[1], parameterSet);
+  //   ParameterTreeParser::readOptions(argc, argv, parameterSet);
+  // }
+
+  // //--- Start Python interpreter
+  // Python::start();
+  // Python::Reference main = Python::import("__main__");
+  // Python::run("import math");
+  // Python::runStream()
+  //   << std::endl << "import sys"
+  //   << std::endl << "sys.path.append('" << dir_path  << "')"
+  //   << std::endl;
+
+
+   // Start Python interpreter
+    Python::start();
+    auto pyMain = Python::main();
+    pyMain.runStream()
+        << std::endl << "import math"
+        << std::endl << "import sys"
+        << std::endl << "sys.path.append('" << dir_path << "')"  << std::endl;
+    auto pyModule = pyMain.import("orthotropicrotation_1");
+
+    ParameterTree parameterSet;
+    pyModule.get("parameterSet").toC(parameterSet);
+    // read possible further parameters from the command line
     ParameterTreeParser::readOptions(argc, argv, parameterSet);
-  }
+    // Print all parameters, to make them appear in the log file
+    std::cout << "Input parameters:" << std::endl;
+    parameterSet.report();
 
-  //--- Start Python interpreter
-  Python::start();
-  Python::Reference main = Python::import("__main__");
-  Python::run("import math");
-  Python::runStream()
-    << std::endl << "import sys"
-    << std::endl << "sys.path.append('" << dir_path  << "')"
-    << std::endl;
 
 
   constexpr int dim = 3;
@@ -157,7 +176,7 @@ int main(int argc, char *argv[])
   ///////////////////////////////////
   //  Create prestrained material object
   ///////////////////////////////////
-  auto material_ = prestrainedMaterial(gridView_CE,parameterSet);
+  auto material_ = prestrainedMaterial(gridView_CE,parameterSet,pyModule);
 
   // --- Get scale ratio
   double gamma = parameterSet.get<double>("gamma",1.0);
@@ -165,6 +184,7 @@ int main(int argc, char *argv[])
   //------------------------------------------------------------------------------------------------
   //--- Compute Correctors
   auto correctorComputer = CorrectorComputer(Basis_CE, material_, gamma, log, parameterSet);
+  correctorComputer.assemble();
   correctorComputer.solve();
 
 
@@ -184,11 +204,16 @@ int main(int argc, char *argv[])
    *
    */
 //  ParameterTreeParser::readINITree("../test/orthotropicrotation_2.parset", parameterSet);
- ParameterTreeParser::readINITree(dir_path + "/orthotropicrotation_2.parset", parameterSet);
- auto material_2 = prestrainedMaterial(gridView_CE,parameterSet);
+//  ParameterTreeParser::readINITree(dir_path + "/orthotropicrotation_2.parset", parameterSet);
+ pyModule = pyMain.import("orthotropicrotation_2");
+ pyModule.get("parameterSet").toC(parameterSet);
+
+
+ auto material_2 = prestrainedMaterial(gridView_CE,parameterSet,pyModule);
 
   //--- Compute Correctors
   auto correctorComputer_2 = CorrectorComputer(Basis_CE, material_2, gamma, log, parameterSet);
+  correctorComputer_2.assemble();
   correctorComputer_2.solve();
 
   //--- Compute effective quantities
diff --git a/test/parametrized_laminate.py b/test/parametrized_laminate.py
index 9007b436..dad1d9b3 100644
--- a/test/parametrized_laminate.py
+++ b/test/parametrized_laminate.py
@@ -1,8 +1,22 @@
 import math
-import ctypes
-import os
-import sys
-#---------------------------------------------------------------
+
+class ParameterSet(dict):
+    def __init__(self, *args, **kwargs):
+        super(ParameterSet, self).__init__(*args, **kwargs)
+        self.__dict__ = self
+
+parameterSet = ParameterSet()
+
+#############################################
+#  Paths
+#############################################
+parameterSet.outputPath = '/home/klaus/Desktop/Dune_release/dune-microstructure/outputs'
+parameterSet.baseName= 'parametrized_laminate'   #(needed for Output-Filename)
+
+#############################################
+#  Material Setup
+#############################################
+
 
 #Parameters used:
 theta = 0.25;
@@ -14,7 +28,13 @@ theta_rho = 2.0;
 rho_2 = rho_1*theta_rho;
 
 
-#--- define indicator function
+# --- Choose scale ratio gamma:
+parameterSet.gamma = 1.0
+
+# --- Number of material phases
+Phases = 4 
+
+#--- Indicator function for material phases
 def indicatorFunction(x):
     theta=0.25
     factor=1
@@ -26,8 +46,7 @@ def indicatorFunction(x):
         return 3    #Phase3
     else :
         return 4    #Phase4
-
-
+    
 ########### Options for material phases: #################################
 #     1. "isotropic"     2. "orthotropic"      3. "transversely_isotropic"   4. "general_anisotropic"
 #########################################################################
@@ -38,11 +57,7 @@ def indicatorFunction(x):
 # general_anisotropic         : full compliance matrix C
 ######################################################################
 
-# --- Number of material phases
-Phases=4
-
 #--- Define different material phases:
-
 #- PHASE 1
 phase1_type="isotropic"
 materialParameters_phase1 = [2.0, 0]   
@@ -50,7 +65,6 @@ materialParameters_phase1 = [2.0, 0]
 #- PHASE 2
 phase2_type="isotropic"
 materialParameters_phase2 = [1.0, 0]   
- 
 
 #- PHASE 3
 phase3_type="isotropic"
@@ -60,9 +74,7 @@ materialParameters_phase3 = [2.0, 0]
 phase4_type="isotropic"
 materialParameters_phase4 = [1.0, 0]
 
-
-#--- define prestrain function for each phase
-# (also works with non-constant values)
+#--- Define prestrain function for each phase (also works with non-constant values)
 def prestrain_phase1(x):
     return [[2, 0, 0], [0,2,0], [0,0,2]]
 
@@ -75,3 +87,58 @@ def prestrain_phase3(x):
 def prestrain_phase4(x):
     return [[0, 0, 0], [0,0,0], [0,0,0]]
 
+
+
+#############################################
+#  Grid parameters
+#############################################
+## numLevels : Number of Levels on which solution is computed. starting with a 2x2x2 cube mesh.
+## {start,finish} computes on all grid from 2^(start) to 2^finish refinement
+#----------------------------------------------------
+parameterSet.numLevels= '3 3'      # computes all levels from first to second entry
+
+#############################################
+#  Assembly options
+#############################################
+parameterSet.set_IntegralZero = 1            #(default = false)
+parameterSet.set_oneBasisFunction_Zero = 1   #(default = false)
+#parameterSet.arbitraryLocalIndex = 7            #(default = 0)
+#parameterSet.arbitraryElementNumber = 3         #(default = 0)
+
+#############################################
+#  Solver Options, Type: #1: CG - SOLVER , #2: GMRES - SOLVER, #3: QR - SOLVER (default), #4: UMFPACK - SOLVER
+#############################################
+parameterSet.Solvertype = 3        # recommended to use iterative solver (e.g GMRES) for finer grid-levels
+parameterSet.Solver_verbosity = 0  #(default = 2)  degree of information for solver output
+
+
+#############################################
+#  Write/Output options      #(default=false)
+#############################################
+# --- (Optional output) write Material / prestrain / Corrector functions to .vtk-Files:
+parameterSet.write_materialFunctions = 1   # VTK indicator function for material/prestrain definition
+#parameterSet.write_prestrainFunctions = 1  # VTK norm of B (currently not implemented)
+
+# --- (Additional debug output)
+parameterSet.print_debug = 0  #(default=false)
+
+# --- Write Correctos to VTK-File:  
+parameterSet.write_VTK = 1
+
+# --- (Optional output) L2Error, integral mean: 
+#parameterSet.write_L2Error = 1
+#parameterSet.write_IntegralMean = 1      
+
+# --- check orthogonality (75) from paper: 
+parameterSet.write_checkOrthogonality = 1
+
+# --- Write corrector-coefficients to log-File:
+#parameterSet.write_corrector_phi1 = 1
+#parameterSet.write_corrector_phi2 = 1
+#parameterSet.write_corrector_phi3 = 1
+
+# --- Print Condition number of matrix (can be expensive):
+#parameterSet.print_conditionNumber= 1  #(default=false)
+
+# --- write effective quantities to Matlab-folder for symbolic minimization:
+#parameterSet.write_toMATLAB = 0  # writes effective quantities to .txt-files QMatrix.txt and BMatrix.txt
diff --git a/test/parametrizedlaminatetest.cc b/test/parametrizedlaminatetest.cc
index 636df2be..81db1c03 100644
--- a/test/parametrizedlaminatetest.cc
+++ b/test/parametrizedlaminatetest.cc
@@ -96,14 +96,14 @@ int main(int argc, char *argv[])
   std::cout << "dir_path: " << file_path.parent_path() << std::endl;
   std::string dir_path  = file_path.parent_path();
 
-  ParameterTree parameterSet;
-  if (argc < 2)
-    ParameterTreeParser::readINITree(dir_path + "/parametrizedlaminate.parset", parameterSet);
-  else
-  {
-    ParameterTreeParser::readINITree(argv[1], parameterSet);
-    ParameterTreeParser::readOptions(argc, argv, parameterSet);
-  }
+  // ParameterTree parameterSet;
+  // if (argc < 2)
+  //   ParameterTreeParser::readINITree(dir_path + "/parametrizedlaminate.parset", parameterSet);
+  // else
+  // {
+  //   ParameterTreeParser::readINITree(argv[1], parameterSet);
+  //   ParameterTreeParser::readOptions(argc, argv, parameterSet);
+  // }
 
   // ParameterTree parameterSet;
   // if (argc < 2)
@@ -124,13 +124,37 @@ int main(int argc, char *argv[])
   // }
 
   //--- Start Python interpreter
-  Python::start();
-  Python::Reference main = Python::import("__main__");
-  Python::run("import math");
-  Python::runStream()
-    << std::endl << "import sys"
-    << std::endl << "sys.path.append('" << dir_path  << "')"
-    << std::endl;
+  // Python::start();
+  // Python::Reference main = Python::import("__main__");
+  // Python::run("import math");
+  // Python::runStream()
+  //   << std::endl << "import sys"
+  //   << std::endl << "sys.path.append('" << dir_path  << "')"
+  //   << std::endl;
+
+
+
+   // Start Python interpreter
+    Python::start();
+    auto pyMain = Python::main();
+    pyMain.runStream()
+        << std::endl << "import math"
+        << std::endl << "import sys"
+        << std::endl << "sys.path.append('" << dir_path << "')"  << std::endl;
+    auto pyModule = pyMain.import("parametrized_laminate");
+
+    ParameterTree parameterSet;
+    pyModule.get("parameterSet").toC(parameterSet);
+    // read possible further parameters from the command line
+    ParameterTreeParser::readOptions(argc, argv, parameterSet);
+    // Print all parameters, to make them appear in the log file
+    std::cout << "Input parameters:" << std::endl;
+    parameterSet.report();
+
+
+
+
+
 
 
   constexpr int dim = 3;
@@ -175,19 +199,20 @@ int main(int argc, char *argv[])
   ///////////////////////////////////
   //  Create prestrained material object
   ///////////////////////////////////
-  auto material_ = prestrainedMaterial(gridView_CE,parameterSet);
+  auto material = prestrainedMaterial(gridView_CE,parameterSet,pyModule);
 
   // --- Get scale ratio
   double gamma = parameterSet.get<double>("gamma",1.0);
 
   //------------------------------------------------------------------------------------------------
   //--- Compute Correctors
-  auto correctorComputer = CorrectorComputer(Basis_CE, material_, gamma, log, parameterSet);
+  auto correctorComputer = CorrectorComputer(Basis_CE, material, gamma, log, parameterSet);
+  correctorComputer.assemble();
   correctorComputer.solve();
 
 
   //--- Compute effective quantities
-  auto effectiveQuantitiesComputer = EffectiveQuantitiesComputer(correctorComputer,material_);
+  auto effectiveQuantitiesComputer = EffectiveQuantitiesComputer(correctorComputer,material);
   effectiveQuantitiesComputer.computeEffectiveQuantities();
 
   //--- get effective quantities
-- 
GitLab