Skip to content
Snippets Groups Projects
Commit a525370f authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] Drop CachedSecondaryVariable.

parent 83420365
No related branches found
No related tags found
No related merge requests found
/**
* \file
* \copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "CachedSecondaryVariable.h"
#include "BaseLib/Functional.h"
#include "MathLib/LinAlg/LinAlg.h"
namespace ProcessLib
{
std::vector<NumLib::NamedFunction> CachedSecondaryVariable::getNamedFunctions()
const
{
return {{_internal_variable_name, std::vector<std::string>{},
BaseLib::easyBind(&CachedSecondaryVariable::getValue, this)}};
}
double CachedSecondaryVariable::getValue() const
{
if (_needs_recomputation)
{
evalFieldNoArgs();
}
return _cached_nodal_values.get(_context.index);
}
SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator()
{
// TODO copied from makeExtrapolator()
auto const eval_residuals =
[this](const double t,
GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table,
std::unique_ptr<GlobalVector> & /*result_cache*/
) -> GlobalVector const& {
_extrapolator.calculateResiduals(1, *_extrapolatables, t, x, dof_table);
return _extrapolator.getElementResiduals();
};
return {1, BaseLib::easyBind(&CachedSecondaryVariable::evalField, this),
eval_residuals};
}
GlobalVector const& CachedSecondaryVariable::evalField(
const double t,
GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table,
std::unique_ptr<GlobalVector>& /*result_cache*/
) const
{
(void)t, (void)x, (void)dof_table;
assert(t == _t && &x == _current_solution && &dof_table == _dof_table);
return evalFieldNoArgs();
}
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 _cached_nodal_values;
}
DBUG("Recomputing %s.", _internal_variable_name.c_str());
_extrapolator.extrapolate(
1, *_extrapolatables, _t, *_current_solution, *_dof_table);
auto const& nodal_values = _extrapolator.getNodalValues();
MathLib::LinAlg::copy(nodal_values, _cached_nodal_values);
MathLib::LinAlg::setLocalAccessibleVector(
_cached_nodal_values); // For access in the getValue()
_needs_recomputation = false;
return nodal_values;
}
} // namespace ProcessLib
/**
* \file
* \copyright
* Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <utility>
#include "NumLib/Extrapolation/ExtrapolatableElementCollection.h"
#include "NumLib/NamedFunctionProvider.h"
#include "NumLib/NumericsConfig.h"
#include "SecondaryVariable.h"
#include "SecondaryVariableContext.h"
namespace ProcessLib
{
/*! Secondary variable which is extrapolated from integration points to mesh
* nodes; the resulting extrapolated values are cached for subsequent use.
*/
class CachedSecondaryVariable final : public NumLib::NamedFunctionProvider
{
public:
/*! Constructs a new instance.
*
* \param internal_variable_name the variable's name
* \param extrapolator extrapolates integration point values to nodal
* values.
* \param local_assemblers provide the integration point values
* \param integration_point_values_method extracts the integration point
* values from the \c local_assemblers
* \param context needed s.t. this class can act as a NamedFunction
*/
template <typename LocalAssemblerCollection,
typename IntegrationPointValuesMethod>
CachedSecondaryVariable(
std::string internal_variable_name,
NumLib::Extrapolator& extrapolator,
LocalAssemblerCollection const& local_assemblers,
IntegrationPointValuesMethod integration_point_values_method,
SecondaryVariableContext const& context)
: _extrapolator(extrapolator),
_extrapolatables(new NumLib::ExtrapolatableLocalAssemblerCollection<
LocalAssemblerCollection>{
local_assemblers, integration_point_values_method}),
_context(context),
_internal_variable_name(std::move(internal_variable_name))
{
}
CachedSecondaryVariable(CachedSecondaryVariable const&) = delete;
CachedSecondaryVariable(CachedSecondaryVariable&&) = delete;
std::vector<NumLib::NamedFunction> getNamedFunctions() const override;
//! Returns extrapolation functions that compute the secondary variable.
SecondaryVariableFunctions getExtrapolator();
void setTime(const double t)
{
_t = t;
_needs_recomputation = true;
}
void updateCurrentSolution(GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table)
{
_current_solution = &x;
_dof_table = &dof_table;
_needs_recomputation = true;
}
private:
//! Provides the value at the current index of the _context.
double getValue() const;
//! Computes the secondary Variable.
GlobalVector const& evalField(
const double t,
GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table,
std::unique_ptr<GlobalVector>& /*result_cache*/
) const;
//! Computes the secondary Variable.
GlobalVector const& evalFieldNoArgs() const;
//! Cache for the computed values.
mutable GlobalVector _cached_nodal_values;
mutable bool _needs_recomputation = true;
NumLib::Extrapolator& _extrapolator;
std::unique_ptr<NumLib::ExtrapolatableElementCollection> _extrapolatables;
SecondaryVariableContext const& _context;
std::string const _internal_variable_name;
double _t = 0.0;
GlobalVector const* _current_solution = nullptr;
NumLib::LocalToGlobalIndexMap const* _dof_table = nullptr;
};
} // namespace ProcessLib
......@@ -385,11 +385,6 @@ void Process::computeSparsityPattern()
void Process::preTimestep(std::vector<GlobalVector*> const& x, const double t,
const double delta_t, const int process_id)
{
for (auto& cached_var : _cached_secondary_variables)
{
cached_var->setTime(t);
}
for (auto* const solution : x)
MathLib::LinAlg::setLocalAccessibleVector(*solution);
preTimestepConcreteProcess(x, t, delta_t, process_id);
......@@ -422,12 +417,6 @@ void Process::computeSecondaryVariable(const double t, GlobalVector const& x,
void Process::preIteration(const unsigned iter, const GlobalVector& x)
{
// In every new iteration cached values of secondary variables are expired.
for (auto& cached_var : _cached_secondary_variables)
{
cached_var->updateCurrentSolution(x, *_local_to_global_index_map);
}
MathLib::LinAlg::setLocalAccessibleVector(x);
preIterationConcreteProcess(iter, x);
}
......
......@@ -18,7 +18,7 @@
#include "NumLib/ODESolver/TimeDiscretization.h"
#include "ParameterLib/Parameter.h"
#include "ProcessLib/BoundaryCondition/BoundaryConditionCollection.h"
#include "ProcessLib/Output/CachedSecondaryVariable.h"
#include "ProcessLib/Output/SecondaryVariableContext.h"
#include "ProcessLib/Output/ExtrapolatorData.h"
#include "ProcessLib/Output/IntegrationPointWriter.h"
#include "ProcessLib/Output/SecondaryVariable.h"
......@@ -304,8 +304,6 @@ protected:
SecondaryVariableCollection _secondary_variables;
NumLib::NamedFunctionCaller _named_function_caller;
std::vector<std::unique_ptr<CachedSecondaryVariable>>
_cached_secondary_variables;
SecondaryVariableContext _secondary_variable_context;
VectorMatrixAssembler _global_assembler;
......
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