From 701c53a4a55b8559d5ba5ab1d11e8fe40231db37 Mon Sep 17 00:00:00 2001
From: Wenqing Wang <wenqing.wang@ufz.de>
Date: Wed, 10 May 2017 17:49:34 +0200
Subject: [PATCH] [PETSc] Changed two related processes

---
 MathLib/LinAlg/PETSc/PETScVector.cpp                | 10 +---------
 MathLib/LinAlg/PETSc/PETScVector.h                  | 10 ----------
 ProcessLib/HeatConduction/HeatConductionProcess.cpp |  3 +++
 ProcessLib/TES/TESProcess.cpp                       |  4 ++++
 ProcessLib/UncoupledProcessesTimeLoop.cpp           |  2 ++
 5 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/MathLib/LinAlg/PETSc/PETScVector.cpp b/MathLib/LinAlg/PETSc/PETScVector.cpp
index 8381982c0b1..d1d40e7ddeb 100644
--- a/MathLib/LinAlg/PETSc/PETScVector.cpp
+++ b/MathLib/LinAlg/PETSc/PETScVector.cpp
@@ -83,14 +83,7 @@ PETScVector::PETScVector(PETScVector &&other)
     , _size_loc{other._size_loc}
     , _size_ghosts{other._size_ghosts}
     , _has_ghost_id{other._has_ghost_id}
-{
-    if (!_global_v)
-    {
-        _global_v = std::unique_ptr<PetscScalar[]>{ new PetscScalar[_size] };
-    }
-
-    getGlobalVector(_global_v.get());
-}
+{}
 
 void PETScVector::config()
 {
@@ -264,7 +257,6 @@ void PETScVector::shallowCopy(const PETScVector &v)
 void finalizeVectorAssembly(PETScVector &vec)
 {
     vec.finalizeAssembly();
-    vec.setGlobalVector();
 }
 
 } //end of namespace
diff --git a/MathLib/LinAlg/PETSc/PETScVector.h b/MathLib/LinAlg/PETSc/PETScVector.h
index b9722deb9d5..67e0d0d5261 100644
--- a/MathLib/LinAlg/PETSc/PETScVector.h
+++ b/MathLib/LinAlg/PETSc/PETScVector.h
@@ -299,16 +299,6 @@ class PETScVector
         /// A funtion called by constructors to configure members
         void config();
 
-        /// Set _global_v
-        void setGlobalVector()
-        {
-            if (!_global_v)
-            {
-                _global_v = std::unique_ptr<PetscScalar[]>{ new PetscScalar[_size] };;
-            }
-            getGlobalVector(_global_v.get());
-        }
-
         friend void finalizeVectorAssembly(PETScVector &vec);
 };
 
diff --git a/ProcessLib/HeatConduction/HeatConductionProcess.cpp b/ProcessLib/HeatConduction/HeatConductionProcess.cpp
index d341c30a4f9..94e61d25717 100644
--- a/ProcessLib/HeatConduction/HeatConductionProcess.cpp
+++ b/ProcessLib/HeatConduction/HeatConductionProcess.cpp
@@ -47,6 +47,9 @@ void HeatConductionProcess::preTimestepConcreteProcess(GlobalVector const& x,
         auto& x0 = *_x_previous_timestep;
         MathLib::LinAlg::copy(x, x0);
     }
+
+    auto& x0 = *_x_previous_timestep;
+    MathLib::LinAlg::setLocalAccessibleVector(x0);
 }
 
 void HeatConductionProcess::initializeConcreteProcess(
diff --git a/ProcessLib/TES/TESProcess.cpp b/ProcessLib/TES/TESProcess.cpp
index 55d9b8566ac..ffdeb5dd6be 100644
--- a/ProcessLib/TES/TESProcess.cpp
+++ b/ProcessLib/TES/TESProcess.cpp
@@ -285,6 +285,10 @@ NumLib::IterationResult TESProcess::postIterationConcreteProcess(
         std::vector<double> local_x_cache;
         std::vector<double> local_x_prev_ts_cache;
 
+        // The function only has computation if DDC is appied,
+        // e.g. Parallel comuting.
+        MathLib::LinAlg::setLocalAccessibleVector(*_x_previous_timestep);
+
         auto check_variable_bounds = [&](std::size_t id,
                                          TESLocalAssemblerInterface& loc_asm) {
             auto const r_c_indices = NumLib::getRowColumnIndices(
diff --git a/ProcessLib/UncoupledProcessesTimeLoop.cpp b/ProcessLib/UncoupledProcessesTimeLoop.cpp
index 2ed13eb7e58..f0465c12d4e 100644
--- a/ProcessLib/UncoupledProcessesTimeLoop.cpp
+++ b/ProcessLib/UncoupledProcessesTimeLoop.cpp
@@ -520,6 +520,7 @@ bool UncoupledProcessesTimeLoop::setCoupledSolutions()
                 const std::size_t c_id =
                     std::distance(_per_process_data.begin(), found_item);
 
+                MathLib::LinAlg::setLocalAccessibleVector(*_process_solutions[c_id]);
                 BaseLib::insertIfTypeIndexKeyUniqueElseError(
                     coupled_xs, coupled_process_pair.first,
                     *_process_solutions[c_id], "global_coupled_x");
@@ -532,6 +533,7 @@ bool UncoupledProcessesTimeLoop::setCoupledSolutions()
         // Create a vector to store the solution of the last coupling iteration
         auto& x_coupling0 = NumLib::GlobalVectorProvider::provider.getVector(x);
         MathLib::LinAlg::copy(x, x_coupling0);
+        MathLib::LinAlg::setLocalAccessibleVector(x_coupling0);
 
         // append a solution vector of suitable size
         _solutions_of_last_cpl_iteration.emplace_back(&x_coupling0);
-- 
GitLab