From d63cf5fa1865cd69d6f724acfd0fd9ba8dbe694a Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Fri, 12 Aug 2016 09:31:48 +0200
Subject: [PATCH] [PL] code review changes.

* context: class -> struct
* global vector from named fct: result_cache -> result
* cached 2ndary var: fixed member name
---
 ProcessLib/CachedSecondaryVariable.cpp              |  6 +++---
 ProcessLib/CachedSecondaryVariable.h                |  2 +-
 ProcessLib/GlobalVectorFromNamedFunction.cpp        | 12 ++++++------
 ProcessLib/GlobalVectorFromNamedFunction.h          |  2 +-
 .../GroundwaterFlow/GroundwaterFlowProcess.cpp      |  4 ++--
 ProcessLib/SecondaryVariableContext.h               | 13 ++++---------
 6 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/ProcessLib/CachedSecondaryVariable.cpp b/ProcessLib/CachedSecondaryVariable.cpp
index 8bc4b112dc6..ebc3494a1c2 100644
--- a/ProcessLib/CachedSecondaryVariable.cpp
+++ b/ProcessLib/CachedSecondaryVariable.cpp
@@ -25,7 +25,7 @@ double CachedSecondaryVariable::getValue() const
 {
     if (_needs_recomputation)
         evalFieldNoArgs();
-    return _solid_density.get(_context.getIndex());
+    return _cached_nodal_values.get(_context.index);
 }
 
 SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator()
@@ -57,12 +57,12 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const
     if (!_needs_recomputation) {
         DBUG("%s does not need to be recomputed. Returning cached values",
              _internal_variable_name.c_str());
-        return _solid_density;
+        return _cached_nodal_values;
     }
     DBUG("Recomputing %s.", _internal_variable_name.c_str());
     _extrapolator.extrapolate(*_extrapolatables);
     auto const& nodal_values = _extrapolator.getNodalValues();
-    MathLib::LinAlg::copy(nodal_values, _solid_density);
+    MathLib::LinAlg::copy(nodal_values, _cached_nodal_values);
     _needs_recomputation = false;
     return nodal_values;
 }
diff --git a/ProcessLib/CachedSecondaryVariable.h b/ProcessLib/CachedSecondaryVariable.h
index efd9f206778..783fae5f6c1 100644
--- a/ProcessLib/CachedSecondaryVariable.h
+++ b/ProcessLib/CachedSecondaryVariable.h
@@ -77,7 +77,7 @@ private:
     GlobalVector const& evalFieldNoArgs() const;
 
     //! Cache for the computed values.
-    mutable GlobalVector _solid_density;
+    mutable GlobalVector _cached_nodal_values;
     mutable bool _needs_recomputation = true;
 
     NumLib::Extrapolator& _extrapolator;
diff --git a/ProcessLib/GlobalVectorFromNamedFunction.cpp b/ProcessLib/GlobalVectorFromNamedFunction.cpp
index 9b53196d0e4..7d38dceb536 100644
--- a/ProcessLib/GlobalVectorFromNamedFunction.cpp
+++ b/ProcessLib/GlobalVectorFromNamedFunction.cpp
@@ -29,9 +29,9 @@ GlobalVectorFromNamedFunction::GlobalVectorFromNamedFunction(
 GlobalVector const& GlobalVectorFromNamedFunction::call(
     GlobalVector const& x,
     NumLib::LocalToGlobalIndexMap const& dof_table,
-    std::unique_ptr<GlobalVector>& result_cache)
+    std::unique_ptr<GlobalVector>& result)
 {
-    result_cache = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(
+    result = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(
         {_dof_table_single.dofSizeWithoutGhosts(),
          _dof_table_single.dofSizeWithoutGhosts(),
          &_dof_table_single.getGhostIndices(), nullptr});
@@ -50,14 +50,14 @@ GlobalVector const& GlobalVectorFromNamedFunction::call(
             args[i] = getNodalValue(x, _mesh, dof_table, node_id, i);
         }
 
-        _context.setIndex(node_id);
-        auto const result = _function_caller.call(args);
+        _context.index = node_id;
+        auto const value = _function_caller.call(args);
 
         // TODO Problems with PETSc? (local vs. global index)
-        result_cache->set(node_id, result);
+        result->set(node_id, value);
     }
 
-    return *result_cache;
+    return *result;
 }
 
 }  // namespace ProcessLib
diff --git a/ProcessLib/GlobalVectorFromNamedFunction.h b/ProcessLib/GlobalVectorFromNamedFunction.h
index af682d99b2d..7c78e335d9a 100644
--- a/ProcessLib/GlobalVectorFromNamedFunction.h
+++ b/ProcessLib/GlobalVectorFromNamedFunction.h
@@ -45,7 +45,7 @@ public:
     //! compute a secondary variable.
     GlobalVector const& call(GlobalVector const& x,
                              NumLib::LocalToGlobalIndexMap const& dof_table,
-                             std::unique_ptr<GlobalVector>& result_cache);
+                             std::unique_ptr<GlobalVector>& result);
 
 private:
     NumLib::SpecificFunctionCaller _function_caller;
diff --git a/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.cpp b/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.cpp
index 7277f28f857..8fa3b807172 100644
--- a/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.cpp
+++ b/ProcessLib/GroundwaterFlow/GroundwaterFlowProcess.cpp
@@ -28,8 +28,8 @@ GroundwaterFlowProcess::GroundwaterFlowProcess(
     NumLib::NamedFunctionCaller&& named_function_caller)
     : Process(mesh, nonlinear_solver, std::move(time_discretization),
               std::move(process_variables), std::move(secondary_variables),
-              std::move(process_output), std::move(named_function_caller))
-    , _process_data(std::move(process_data))
+              std::move(process_output), std::move(named_function_caller)),
+      _process_data(std::move(process_data))
 {
     if (dynamic_cast<NumLib::ForwardEuler*>(
             &Base::getTimeDiscretization()) != nullptr)
diff --git a/ProcessLib/SecondaryVariableContext.h b/ProcessLib/SecondaryVariableContext.h
index e62334ba40c..4514abf1ded 100644
--- a/ProcessLib/SecondaryVariableContext.h
+++ b/ProcessLib/SecondaryVariableContext.h
@@ -18,17 +18,12 @@ namespace ProcessLib
  * NamedFunction which needs additional external data apart from the unbound
  * variables that are configured.
  */
-class SecondaryVariableContext
+struct SecondaryVariableContext
 {
 public:
-    //! Returns the current index value.
-    GlobalIndexType getIndex() const { return _index; }
-
-    //! Sets the index.
-    void setIndex(GlobalIndexType index) { _index = index; }
-
-private:
-    GlobalIndexType _index = 0;
+    //! Points to the position in a GlobalVector being read or written right
+    //! now.
+    GlobalIndexType index = 0;
 };
 
 }  // namespace ProcessLib
-- 
GitLab