From 81ec6a4a713cfc9c3f64963476bbaf097c02f2fe Mon Sep 17 00:00:00 2001
From: Wenqing Wang <wenqing.wang@ufz.de>
Date: Thu, 25 Jul 2019 15:59:30 +0200
Subject: [PATCH] [StaggeredScheme]  Modified Process::constructDofTable()

---
 ProcessLib/Process.cpp | 85 ++++++++++++++++++++++++++++--------------
 ProcessLib/Process.h   | 22 +++++++++++
 2 files changed, 80 insertions(+), 27 deletions(-)

diff --git a/ProcessLib/Process.cpp b/ProcessLib/Process.cpp
index 8e50afc2450..37a256ba356 100644
--- a/ProcessLib/Process.cpp
+++ b/ProcessLib/Process.cpp
@@ -232,7 +232,21 @@ void Process::assembleWithJacobian(const double t, GlobalVector const& x,
 
 void Process::constructDofTable()
 {
-    // Create single component dof in every of the mesh's nodes.
+    if (_use_monolithic_scheme)
+    {
+        constructMonolithicProcessDofTable();
+
+        return;
+    }
+
+    // For staggered scheme:
+    const int specified_prosess_id = 0;
+    constructDofTableOfSpecifiedProsessStaggerdScheme(specified_prosess_id);
+}
+
+void Process::constructMonolithicProcessDofTable()
+{
+    // Create single component dof in every of the mesh nodes.
     _mesh_subset_all_nodes =
         std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
 
@@ -241,41 +255,58 @@ void Process::constructDofTable()
 
     // Vector of the number of variable components
     std::vector<int> vec_var_n_components;
-    if (_use_monolithic_scheme)
+    // Collect the mesh subsets in a vector for the components of each
+    // variables.
+    for (ProcessVariable const& pv : _process_variables[0])
     {
-        // Collect the mesh subsets in a vector for each variables' components.
-        for (ProcessVariable const& pv : _process_variables[0])
-        {
-            std::generate_n(std::back_inserter(all_mesh_subsets),
-                            pv.getNumberOfComponents(),
-                            [&]() { return *_mesh_subset_all_nodes; });
-        }
-
-        // Create a vector of the number of variable components
-        for (ProcessVariable const& pv : _process_variables[0])
-        {
-            vec_var_n_components.push_back(pv.getNumberOfComponents());
-        }
-    }
-    else  // for staggered scheme
-    {
-        // Assuming that all equations of the coupled process use the same
-        // element order. Other cases can be considered by overloading this
-        // member function in the derived class.
-
-        // Collect the mesh subsets in a vector for each variables' components.
         std::generate_n(std::back_inserter(all_mesh_subsets),
-                        _process_variables[0][0].get().getNumberOfComponents(),
+                        pv.getNumberOfComponents(),
                         [&]() { return *_mesh_subset_all_nodes; });
+    }
 
-        // Create a vector of the number of variable components.
-        vec_var_n_components.push_back(
-            _process_variables[0][0].get().getNumberOfComponents());
+    // Create a vector of the number of variable components
+    for (ProcessVariable const& pv : _process_variables[0])
+    {
+        vec_var_n_components.push_back(pv.getNumberOfComponents());
     }
+
+    _local_to_global_index_map =
+        std::make_unique<NumLib::LocalToGlobalIndexMap>(
+            std::move(all_mesh_subsets), vec_var_n_components,
+            NumLib::ComponentOrder::BY_LOCATION);
+
+    assert(_local_to_global_index_map);
+}
+
+void Process::constructDofTableOfSpecifiedProsessStaggerdScheme(
+    const int specified_prosess_id)
+{
+    // Create single component dof in every of the mesh nodes.
+    _mesh_subset_all_nodes =
+        std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
+
+    // Vector of mesh subsets.
+    std::vector<MeshLib::MeshSubset> all_mesh_subsets;
+
+    // Vector of the number of variable components
+    std::vector<int> vec_var_n_components;
+    // Collect the mesh subsets in a vector for each variables' components.
+    std::generate_n(std::back_inserter(all_mesh_subsets),
+                    _process_variables[specified_prosess_id][0]
+                        .get()
+                        .getNumberOfComponents(),
+                    [&]() { return *_mesh_subset_all_nodes; });
+
+    // Create a vector of the number of variable components.
+    vec_var_n_components.push_back(_process_variables[specified_prosess_id][0]
+                                       .get()
+                                       .getNumberOfComponents());
     _local_to_global_index_map =
         std::make_unique<NumLib::LocalToGlobalIndexMap>(
             std::move(all_mesh_subsets), vec_var_n_components,
             NumLib::ComponentOrder::BY_LOCATION);
+
+    assert(_local_to_global_index_map);
 }
 
 std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h
index 5aaa5c52344..bfd1d077be7 100644
--- a/ProcessLib/Process.h
+++ b/ProcessLib/Process.h
@@ -235,8 +235,30 @@ private:
     }
 
 protected:
+    /** This function is for general cases, in which all equations of the
+     coupled processes have the same number of unknowns. For the general cases
+     with the staggered scheme, all equations of the coupled processes share one
+     DOF table hold by \verb{_local_to_global_index_map}. Other cases can be
+     considered by overloading this member function in the
+     derived class.
+     */
     virtual void constructDofTable();
 
+    /**
+     * Construct the DOF table for the monolithic scheme,
+     * which is stored in the
+     * member of this class, \verb{_local_to_global_index_map}.
+     */
+    void constructMonolithicProcessDofTable();
+
+    /**
+     * Construct the DOF table for a specified process in the staggered scheme,
+     * which is stored in the
+     * member of this class, \verb{_local_to_global_index_map}.
+     */
+    void constructDofTableOfSpecifiedProsessStaggerdScheme(
+        const int specified_prosess_id);
+
     /**
      * Get the address of a LocalToGlobalIndexMap, and the status of its memory.
      * If the LocalToGlobalIndexMap is created as new in this function, the
-- 
GitLab