From 32d86c888683e9dd89a86ee6bad328141300ceca Mon Sep 17 00:00:00 2001
From: Wenqing Wang <wenqing.wang@ufz.de>
Date: Wed, 10 Jan 2018 18:12:51 +0100
Subject: [PATCH] [PCS] Changed some documentations and names

---
 .../t_convergence_criterion.md                |  3 +--
 NumLib/ODESolver/TimeDiscretizedODESystem.h   |  1 +
 .../CoupledSolutionsForStaggeredScheme.h      | 14 +++++++++++
 .../GroundwaterFlow/GroundwaterFlowProcess.h  |  1 +
 ProcessLib/HT/HTProcess.cpp                   |  4 ++--
 ProcessLib/HT/HTProcess.h                     |  3 +++
 .../HydroMechanicsProcess-impl.h              | 12 +++++++---
 ProcessLib/Process.cpp                        | 11 +++++----
 ProcessLib/Process.h                          | 24 +++++++++++++++----
 ProcessLib/UncoupledProcessesTimeLoop.cpp     |  8 ++++---
 ProcessLib/UncoupledProcessesTimeLoop.h       |  2 +-
 ProcessLib/VectorMatrixAssembler.cpp          | 23 +++++++++++-------
 ProcessLib/VectorMatrixAssembler.h            | 10 ++++----
 .../InjectionProduction1D.prj                 |  4 ++--
 14 files changed, 87 insertions(+), 33 deletions(-)

diff --git a/Documentation/ProjectFile/prj/time_loop/global_process_coupling/convergence_criteria/t_convergence_criterion.md b/Documentation/ProjectFile/prj/time_loop/global_process_coupling/convergence_criteria/t_convergence_criterion.md
index 4e4aa84b97b..5c47ba5b296 100644
--- a/Documentation/ProjectFile/prj/time_loop/global_process_coupling/convergence_criteria/t_convergence_criterion.md
+++ b/Documentation/ProjectFile/prj/time_loop/global_process_coupling/convergence_criteria/t_convergence_criterion.md
@@ -1,2 +1 @@
-Defines the convergence criteria of the global un-coupling loop of the staggered
- scheme for each individual process.
+Defines the convergence criterion for each weakly coupled process.
diff --git a/NumLib/ODESolver/TimeDiscretizedODESystem.h b/NumLib/ODESolver/TimeDiscretizedODESystem.h
index 9a9d351adb5..68ec900cad0 100644
--- a/NumLib/ODESolver/TimeDiscretizedODESystem.h
+++ b/NumLib/ODESolver/TimeDiscretizedODESystem.h
@@ -73,6 +73,7 @@ public:
 
     /*! Constructs a new instance.
      *
+     * \param equation_id ID of the ODE to be solved.
      * \param ode the ODE to be wrapped.
      * \param time_discretization the time discretization to be used.
      */
diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.h b/ProcessLib/CoupledSolutionsForStaggeredScheme.h
index 91e1ab67558..f38f9509563 100644
--- a/ProcessLib/CoupledSolutionsForStaggeredScheme.h
+++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.h
@@ -74,12 +74,26 @@ struct LocalCoupledSolutions
     std::vector<std::vector<double>> const local_coupled_xs;
 };
 
+/**
+ * Fetch the nodal solutions of all coupled processes of the previous time step
+ * of an element.
+ * @param cpl_xs  Solutions of all coupled equations.
+ * @param indices Nodal indices of an element.
+ * @return Nodal solutions of the previous time step of an element
+ */
 std::vector<std::vector<double>> getPreviousLocalSolutions(
     const CoupledSolutionsForStaggeredScheme& cpl_xs,
     const std::vector<
         std::reference_wrapper<const std::vector<GlobalIndexType>>>&
         indices);
 
+/**
+ * Fetch the nodal solutions of all coupled processes of the current time step
+ * of an element.
+ * @param cpl_xs  Solutions of all coupled equations.
+ * @param indices Nodal indices of an element.
+ * @return Nodal solutions of the current time step of an element
+ */
 std::vector<std::vector<double>> getCurrentLocalSolutions(
     const CoupledSolutionsForStaggeredScheme& cpl_xs,
     const std::vector<
diff --git a/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.h b/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.h
index 882dab4ee90..84087293874 100644
--- a/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.h
+++ b/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.h
@@ -70,6 +70,7 @@ public:
             MeshLib::addPropertyToMesh(*_balance_mesh, _balance_pv_name,
                                        MeshLib::MeshItemType::Cell, 1,
                                        init_values);
+            //For this single process, process_id is always zero.
             const int process_id = 0;
             auto balance = ProcessLib::CalculateSurfaceFlux(
                 *_balance_mesh,
diff --git a/ProcessLib/HT/HTProcess.cpp b/ProcessLib/HT/HTProcess.cpp
index 55ace19d707..ac379c210ab 100644
--- a/ProcessLib/HT/HTProcess.cpp
+++ b/ProcessLib/HT/HTProcess.cpp
@@ -200,7 +200,7 @@ void HTProcess::setCoupledSolutionsOfPreviousTimeStep()
     const int process_id = _coupled_solutions->process_id;
     for (std::size_t i = 0; i < number_of_coupled_solutions; i++)
     {
-        const auto x_t0 = _xs_previous_timestep[process_id].get();
+        const auto& x_t0 = _xs_previous_timestep[process_id];
         if (x_t0 == nullptr)
         {
             OGS_FATAL(
@@ -212,7 +212,7 @@ void HTProcess::setCoupledSolutionsOfPreviousTimeStep()
         }
 
         MathLib::LinAlg::setLocalAccessibleVector(*x_t0);
-        _coupled_solutions->coupled_xs_t0.emplace_back(x_t0);
+        _coupled_solutions->coupled_xs_t0.emplace_back(x_t0.get());
     }
 }
 
diff --git a/ProcessLib/HT/HTProcess.h b/ProcessLib/HT/HTProcess.h
index 747d19c98d9..bdd86282f87 100644
--- a/ProcessLib/HT/HTProcess.h
+++ b/ProcessLib/HT/HTProcess.h
@@ -92,6 +92,9 @@ private:
     /// It only performs for the staggered scheme.
     void setCoupledSolutionsOfPreviousTimeStep();
 
+    /**
+     * @copydoc ProcessLib::Process::getDOFTableForExtrapolatorData()
+     */
     std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
         getDOFTableForExtrapolatorData() const override;
 
diff --git a/ProcessLib/HydroMechanics/HydroMechanicsProcess-impl.h b/ProcessLib/HydroMechanics/HydroMechanicsProcess-impl.h
index 3c00ac7124b..97a80e0b971 100644
--- a/ProcessLib/HydroMechanics/HydroMechanicsProcess-impl.h
+++ b/ProcessLib/HydroMechanics/HydroMechanicsProcess-impl.h
@@ -112,6 +112,7 @@ void HydroMechanicsProcess<DisplacementDim>::constructDofTable()
             std::make_unique<NumLib::LocalToGlobalIndexMap>(
                 std::move(all_mesh_subsets), vec_n_components,
                 NumLib::ComponentOrder::BY_LOCATION);
+        assert(_local_to_global_index_map);
     }
     else
     {
@@ -143,6 +144,9 @@ void HydroMechanicsProcess<DisplacementDim>::constructDofTable()
 
         _sparsity_pattern_with_linear_element = NumLib::computeSparsityPattern(
             *_local_to_global_index_map_with_base_nodes, _mesh);
+
+        assert(_local_to_global_index_map);
+        assert(_local_to_global_index_map_with_base_nodes);
     }
 }
 
@@ -230,7 +234,7 @@ void HydroMechanicsProcess<DisplacementDim>::initializeBoundaryConditions()
     if (_use_monolithic_scheme)
     {
         const int equation_id_of_up = 0;
-        initializeBoundaryConditionPerPDE(*_local_to_global_index_map,
+        initializeProcessBoundaryCondition(*_local_to_global_index_map,
                                           equation_id_of_up);
         return;
     }
@@ -238,12 +242,12 @@ void HydroMechanicsProcess<DisplacementDim>::initializeBoundaryConditions()
     // Staggered scheme:
     // for the equations of pressure
     const int equation_id_of_p = 0;
-    initializeBoundaryConditionPerPDE(
+    initializeProcessBoundaryCondition(
         *_local_to_global_index_map_with_base_nodes, equation_id_of_p);
 
     // for the equations of deformation.
     const int equation_id_of_u = 1;
-    initializeBoundaryConditionPerPDE(*_local_to_global_index_map,
+    initializeProcessBoundaryCondition(*_local_to_global_index_map,
                                       equation_id_of_u);
 }
 
@@ -301,6 +305,8 @@ void HydroMechanicsProcess<DisplacementDim>::
             "HydroMechanics for the staggered scheme.");
     }
 
+    // Note: _local_to_global_index_map_with_base_nodes is asserted in
+    //       constructDofTable().
     GlobalExecutor::executeMemberDereferenced(
         _global_assembler, &VectorMatrixAssembler::assembleWithJacobian,
         _local_assemblers, *_local_to_global_index_map, t, x, xdot, dxdot_dx,
diff --git a/ProcessLib/Process.cpp b/ProcessLib/Process.cpp
index 955b24fa99e..d332dd90486 100644
--- a/ProcessLib/Process.cpp
+++ b/ProcessLib/Process.cpp
@@ -51,8 +51,7 @@ Process::Process(
 {
 }
 
-/// Initialize the boundary conditions for single PDE
-void Process::initializeBoundaryConditionPerPDE(
+void Process::initializeProcessBoundaryCondition(
     const NumLib::LocalToGlobalIndexMap& dof_table, const int process_id)
 {
     auto const& per_process_variables = _process_variables[process_id];
@@ -77,9 +76,13 @@ void Process::initializeBoundaryConditionPerPDE(
 
 void Process::initializeBoundaryConditions()
 {
-    for (std::size_t pcs_id = 0; pcs_id < _process_variables.size(); pcs_id++)
+    // The number of processes is identical to the size of _process_variables,
+    // the vector contains variables for different processes. See the
+    // documentation of _process_variables.
+    const std::size_t number_of_processes = _process_variables.size();
+    for (std::size_t pcs_id = 0; pcs_id < number_of_processes; pcs_id++)
     {
-        initializeBoundaryConditionPerPDE(*_local_to_global_index_map, pcs_id);
+        initializeProcessBoundaryCondition(*_local_to_global_index_map, pcs_id);
     }
 }
 
diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h
index 0e0ae05d0a8..546780f9e9f 100644
--- a/ProcessLib/Process.h
+++ b/ProcessLib/Process.h
@@ -61,6 +61,8 @@ public:
     /// Postprocessing after a complete timestep.
     void postTimestep(GlobalVector const& x, int const process_id);
 
+    /// Calculates secondary variables, e.g. stress and strain for deformation
+    /// analysis, only after nonlinear solver being successfully conducted.
     void postNonLinearSolver(GlobalVector const& x, const double t,
                              int const process_id);
 
@@ -143,9 +145,15 @@ protected:
         return _extrapolator_data.getDOFTable();
     }
 
-    /// Initialize the boundary conditions for single PDE. It is called by
-    /// initializeBoundaryConditions().
-    void initializeBoundaryConditionPerPDE(
+    /**
+     * Initialize the boundary conditions for a single process or coupled
+     * processes modelled by the monolithic scheme. It is called by
+     * initializeBoundaryConditions().
+     * 
+     * @param dof_table DOF table
+     * @param process_id Process ID
+     */
+    void initializeProcessBoundaryCondition(
         const NumLib::LocalToGlobalIndexMap& dof_table, const int process_id);
 
 private:
@@ -210,8 +218,16 @@ private:
 protected:
     virtual void constructDofTable();
 
+    /**
+     * Get the address of a LocalToGlobalIndexMap, and the status of its memory.
+     * If the LocalToGlobalIndexMap is created as new in this function, the
+     * function also returns a true boolean value to let Extrapolator manage
+     * the memory by the address returned by this function.
+     *
+     * @return Address of a LocalToGlobalIndexMap and its memory status.
+     */
     virtual std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
-        getDOFTableForExtrapolatorData() const;
+    getDOFTableForExtrapolatorData() const;
 
 private:
     void initializeExtrapolator();
diff --git a/ProcessLib/UncoupledProcessesTimeLoop.cpp b/ProcessLib/UncoupledProcessesTimeLoop.cpp
index 52d438ac36c..cb08c01047c 100644
--- a/ProcessLib/UncoupledProcessesTimeLoop.cpp
+++ b/ProcessLib/UncoupledProcessesTimeLoop.cpp
@@ -126,6 +126,8 @@ struct SingleProcessData
     //! cast of \c tdisc_ode_sys to NumLib::InternalMatrixStorage
     NumLib::InternalMatrixStorage* mat_strg = nullptr;
 
+    /// Process ID. It is alway 0 when the monolithic scheme is used or
+    /// a single process is modelled.
     int equation_id = 0;
 
     Process& process;
@@ -326,7 +328,7 @@ std::unique_ptr<UncoupledProcessesTimeLoop> createUncoupledProcessesTimeLoop(
         = config.getConfigSubtreeOptional("global_process_coupling");
 
     std::vector<std::unique_ptr<NumLib::ConvergenceCriterion>>
-        _global_coupling_conv_criteria;
+        global_coupling_conv_criteria;
     unsigned max_coupling_iterations = 1;
     if (coupling_config)
     {
@@ -344,7 +346,7 @@ std::unique_ptr<UncoupledProcessesTimeLoop> createUncoupledProcessesTimeLoop(
             coupling_convergence_criteria_config.getConfigSubtreeList(
                 "convergence_criterion"))
         {
-            _global_coupling_conv_criteria.push_back(
+            global_coupling_conv_criteria.push_back(
                 NumLib::createConvergenceCriterion(
                     coupling_convergence_criterion_config));
         }
@@ -374,7 +376,7 @@ std::unique_ptr<UncoupledProcessesTimeLoop> createUncoupledProcessesTimeLoop(
 
     return std::make_unique<UncoupledProcessesTimeLoop>(
         std::move(output), std::move(per_process_data), max_coupling_iterations,
-        std::move(_global_coupling_conv_criteria), start_time, end_time);
+        std::move(global_coupling_conv_criteria), start_time, end_time);
 }
 
 std::vector<GlobalVector*> setInitialConditions(
diff --git a/ProcessLib/UncoupledProcessesTimeLoop.h b/ProcessLib/UncoupledProcessesTimeLoop.h
index b62cf9c3df0..ab83fe3144f 100644
--- a/ProcessLib/UncoupledProcessesTimeLoop.h
+++ b/ProcessLib/UncoupledProcessesTimeLoop.h
@@ -71,7 +71,7 @@ private:
 
     /// Maximum iterations of the global coupling.
     const unsigned _global_coupling_max_iterations;
-    /// Convergence criteria of the global coupling iterations.
+    /// Convergence criteria of processes for the global coupling iterations.
     std::vector<std::unique_ptr<NumLib::ConvergenceCriterion>>
         _global_coupling_conv_crit;
 
diff --git a/ProcessLib/VectorMatrixAssembler.cpp b/ProcessLib/VectorMatrixAssembler.cpp
index a88fb8bcf40..f5b7aaae341 100644
--- a/ProcessLib/VectorMatrixAssembler.cpp
+++ b/ProcessLib/VectorMatrixAssembler.cpp
@@ -42,7 +42,7 @@ void VectorMatrixAssembler::assemble(
     const std::size_t mesh_item_id, LocalAssemblerInterface& local_assembler,
     const NumLib::LocalToGlobalIndexMap& dof_table, const double t,
     const GlobalVector& x, GlobalMatrix& M, GlobalMatrix& K, GlobalVector& b,
-    const CoupledSolutionsForStaggeredScheme* cpl_xs)
+    CoupledSolutionsForStaggeredScheme const* const cpl_xs)
 {
     auto const indices = NumLib::getIndices(mesh_item_id, dof_table);
 
@@ -58,6 +58,12 @@ void VectorMatrixAssembler::assemble(
     }
     else
     {
+        // Different processes in a staggered loop are allowed to use different
+        // orders of element. That means that the global indices can be
+        // different among different processes. The following vector stores the
+        // reference of the vectors of the global indices of all processes, and
+        // it is used to fetch the nodal solutions of all processes of the
+        // current element.
         std::vector<std::reference_wrapper<const std::vector<GlobalIndexType>>>
             indices_of_all_coupled_processes;
         indices_of_all_coupled_processes.reserve(cpl_xs->coupled_xs.size());
@@ -106,13 +112,12 @@ void VectorMatrixAssembler::assembleWithJacobian(
     NumLib::LocalToGlobalIndexMap const& dof_table, const double t,
     GlobalVector const& x, GlobalVector const& xdot, const double dxdot_dx,
     const double dx_dx, GlobalMatrix& M, GlobalMatrix& K, GlobalVector& b,
-    GlobalMatrix& Jac, const CoupledSolutionsForStaggeredScheme* cpl_xs,
-    NumLib::LocalToGlobalIndexMap const* base_dof_table)
+    GlobalMatrix& Jac, CoupledSolutionsForStaggeredScheme const* const cpl_xs,
+    NumLib::LocalToGlobalIndexMap const* const base_dof_table)
 {
-    // If base_dof_table != nullptr, then the coupled processes contains the
-    // mechanical process, which is alway placed in the end of the coupled
-    // process and always user higher order element than other process in the
-    // coupling.
+    // If base_dof_table != nullptr, it means that the staggered scheme is
+    // applied for coupling, meanwhile DOF tables of different are different
+    // as well.
     auto const indices =
         ((base_dof_table == nullptr) ||
          (cpl_xs->process_id ==
@@ -202,8 +207,10 @@ void VectorMatrixAssembler::local_assembleWithJacobianForStaggeredScheme(
     std::vector<GlobalIndexType> const& full_indices,
     std::vector<double> const& local_xdot,
     LocalAssemblerInterface& local_assembler, const double dxdot_dx,
-    const double dx_dx, CoupledSolutionsForStaggeredScheme const* cpl_xs)
+    const double dx_dx, CoupledSolutionsForStaggeredScheme const* const cpl_xs)
 {
+    // The vector has the same purpose as that in assemble(..) in this file.
+    // For the detailed description, please see the comment inside assemble(..).
     std::vector<std::reference_wrapper<const std::vector<GlobalIndexType>>>
         indices_of_all_coupled_processes;
     indices_of_all_coupled_processes.reserve(cpl_xs->coupled_xs.size());
diff --git a/ProcessLib/VectorMatrixAssembler.h b/ProcessLib/VectorMatrixAssembler.h
index 01af18a6286..7961e7256c1 100644
--- a/ProcessLib/VectorMatrixAssembler.h
+++ b/ProcessLib/VectorMatrixAssembler.h
@@ -47,7 +47,7 @@ public:
                   NumLib::LocalToGlobalIndexMap const& dof_table,
                   double const t, GlobalVector const& x, GlobalMatrix& M,
                   GlobalMatrix& K, GlobalVector& b,
-                  const CoupledSolutionsForStaggeredScheme* cpl_xs);
+                  CoupledSolutionsForStaggeredScheme const* const cpl_xs);
 
     //! Assembles \c M, \c K, \c b, and the Jacobian \c Jac of the residual.
     //! \note The Jacobian must be assembled.
@@ -57,8 +57,9 @@ public:
         NumLib::LocalToGlobalIndexMap const& dof_table, const double t,
         GlobalVector const& x, GlobalVector const& xdot, const double dxdot_dx,
         const double dx_dx, GlobalMatrix& M, GlobalMatrix& K, GlobalVector& b,
-        GlobalMatrix& Jac, const CoupledSolutionsForStaggeredScheme* cpl_xs,
-        NumLib::LocalToGlobalIndexMap const* base_dof_table);
+        GlobalMatrix& Jac,
+        CoupledSolutionsForStaggeredScheme const* const cpl_xs,
+        NumLib::LocalToGlobalIndexMap const* const base_dof_table);
 
 private:
     // temporary data only stored here in order to avoid frequent memory
@@ -76,7 +77,8 @@ private:
         std::vector<GlobalIndexType> const& full_indices,
         std::vector<double> const& local_xdot,
         LocalAssemblerInterface& local_assembler, const double dxdot_dx,
-        const double dx_dx, CoupledSolutionsForStaggeredScheme const* cpl_xs);
+        const double dx_dx,
+        CoupledSolutionsForStaggeredScheme const* const cpl_xs);
 };
 
 }  // namespace ProcessLib
diff --git a/Tests/Data/HydroMechanics/StaggeredScheme/InjectionProduction1D/InjectionProduction1D.prj b/Tests/Data/HydroMechanics/StaggeredScheme/InjectionProduction1D/InjectionProduction1D.prj
index 97c7dacdbdf..549ddabebae 100644
--- a/Tests/Data/HydroMechanics/StaggeredScheme/InjectionProduction1D/InjectionProduction1D.prj
+++ b/Tests/Data/HydroMechanics/StaggeredScheme/InjectionProduction1D/InjectionProduction1D.prj
@@ -208,7 +208,7 @@
             <value>0</value>
         </parameter>
         <parameter>
-            <name>oberburden</name>
+            <name>overburden</name>
             <type>Constant</type>
             <value>-2.125e6</value>
         </parameter>
@@ -252,7 +252,7 @@
                     <geometry>top</geometry>
                     <type>Neumann</type>
                     <component>1</component>
-                    <parameter>oberburden</parameter>
+                    <parameter>overburden</parameter>
                 </boundary_condition>
             </boundary_conditions>
         </process_variable>
-- 
GitLab