Skip to content
Snippets Groups Projects
Commit d63cf5fa authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[PL] code review changes.

* context: class -> struct
* global vector from named fct: result_cache -> result
* cached 2ndary var: fixed member name
parent 98d7b068
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ double CachedSecondaryVariable::getValue() const ...@@ -25,7 +25,7 @@ double CachedSecondaryVariable::getValue() const
{ {
if (_needs_recomputation) if (_needs_recomputation)
evalFieldNoArgs(); evalFieldNoArgs();
return _solid_density.get(_context.getIndex()); return _cached_nodal_values.get(_context.index);
} }
SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator() SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator()
...@@ -57,12 +57,12 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const ...@@ -57,12 +57,12 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const
if (!_needs_recomputation) { if (!_needs_recomputation) {
DBUG("%s does not need to be recomputed. Returning cached values", DBUG("%s does not need to be recomputed. Returning cached values",
_internal_variable_name.c_str()); _internal_variable_name.c_str());
return _solid_density; return _cached_nodal_values;
} }
DBUG("Recomputing %s.", _internal_variable_name.c_str()); DBUG("Recomputing %s.", _internal_variable_name.c_str());
_extrapolator.extrapolate(*_extrapolatables); _extrapolator.extrapolate(*_extrapolatables);
auto const& nodal_values = _extrapolator.getNodalValues(); auto const& nodal_values = _extrapolator.getNodalValues();
MathLib::LinAlg::copy(nodal_values, _solid_density); MathLib::LinAlg::copy(nodal_values, _cached_nodal_values);
_needs_recomputation = false; _needs_recomputation = false;
return nodal_values; return nodal_values;
} }
......
...@@ -77,7 +77,7 @@ private: ...@@ -77,7 +77,7 @@ private:
GlobalVector const& evalFieldNoArgs() const; GlobalVector const& evalFieldNoArgs() const;
//! Cache for the computed values. //! Cache for the computed values.
mutable GlobalVector _solid_density; mutable GlobalVector _cached_nodal_values;
mutable bool _needs_recomputation = true; mutable bool _needs_recomputation = true;
NumLib::Extrapolator& _extrapolator; NumLib::Extrapolator& _extrapolator;
......
...@@ -29,9 +29,9 @@ GlobalVectorFromNamedFunction::GlobalVectorFromNamedFunction( ...@@ -29,9 +29,9 @@ GlobalVectorFromNamedFunction::GlobalVectorFromNamedFunction(
GlobalVector const& GlobalVectorFromNamedFunction::call( GlobalVector const& GlobalVectorFromNamedFunction::call(
GlobalVector const& x, GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table, 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.dofSizeWithoutGhosts(), _dof_table_single.dofSizeWithoutGhosts(),
&_dof_table_single.getGhostIndices(), nullptr}); &_dof_table_single.getGhostIndices(), nullptr});
...@@ -50,14 +50,14 @@ GlobalVector const& GlobalVectorFromNamedFunction::call( ...@@ -50,14 +50,14 @@ GlobalVector const& GlobalVectorFromNamedFunction::call(
args[i] = getNodalValue(x, _mesh, dof_table, node_id, i); args[i] = getNodalValue(x, _mesh, dof_table, node_id, i);
} }
_context.setIndex(node_id); _context.index = node_id;
auto const result = _function_caller.call(args); auto const value = _function_caller.call(args);
// TODO Problems with PETSc? (local vs. global index) // 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 } // namespace ProcessLib
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
//! compute a secondary variable. //! compute a secondary variable.
GlobalVector const& call(GlobalVector const& x, GlobalVector const& call(GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table, NumLib::LocalToGlobalIndexMap const& dof_table,
std::unique_ptr<GlobalVector>& result_cache); std::unique_ptr<GlobalVector>& result);
private: private:
NumLib::SpecificFunctionCaller _function_caller; NumLib::SpecificFunctionCaller _function_caller;
......
...@@ -28,8 +28,8 @@ GroundwaterFlowProcess::GroundwaterFlowProcess( ...@@ -28,8 +28,8 @@ GroundwaterFlowProcess::GroundwaterFlowProcess(
NumLib::NamedFunctionCaller&& named_function_caller) NumLib::NamedFunctionCaller&& named_function_caller)
: Process(mesh, nonlinear_solver, std::move(time_discretization), : Process(mesh, nonlinear_solver, std::move(time_discretization),
std::move(process_variables), std::move(secondary_variables), std::move(process_variables), std::move(secondary_variables),
std::move(process_output), std::move(named_function_caller)) std::move(process_output), std::move(named_function_caller)),
, _process_data(std::move(process_data)) _process_data(std::move(process_data))
{ {
if (dynamic_cast<NumLib::ForwardEuler*>( if (dynamic_cast<NumLib::ForwardEuler*>(
&Base::getTimeDiscretization()) != nullptr) &Base::getTimeDiscretization()) != nullptr)
......
...@@ -18,17 +18,12 @@ namespace ProcessLib ...@@ -18,17 +18,12 @@ namespace ProcessLib
* NamedFunction which needs additional external data apart from the unbound * NamedFunction which needs additional external data apart from the unbound
* variables that are configured. * variables that are configured.
*/ */
class SecondaryVariableContext struct SecondaryVariableContext
{ {
public: public:
//! Returns the current index value. //! Points to the position in a GlobalVector being read or written right
GlobalIndexType getIndex() const { return _index; } //! now.
GlobalIndexType index = 0;
//! Sets the index.
void setIndex(GlobalIndexType index) { _index = index; }
private:
GlobalIndexType _index = 0;
}; };
} // namespace ProcessLib } // namespace ProcessLib
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment