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

[PL] num_components moved to other class

parent 9e07ba74
No related branches found
No related tags found
No related merge requests found
...@@ -36,10 +36,10 @@ SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator() ...@@ -36,10 +36,10 @@ SecondaryVariableFunctions CachedSecondaryVariable::getExtrapolator()
NumLib::LocalToGlobalIndexMap const& dof_table, NumLib::LocalToGlobalIndexMap const& dof_table,
std::unique_ptr<GlobalVector> & /*result_cache*/ std::unique_ptr<GlobalVector> & /*result_cache*/
) -> GlobalVector const& { ) -> GlobalVector const& {
_extrapolator.calculateResiduals(*_extrapolatables, x, dof_table); _extrapolator.calculateResiduals(1, *_extrapolatables, x, dof_table);
return _extrapolator.getElementResiduals(); return _extrapolator.getElementResiduals();
}; };
return {BaseLib::easyBind(&CachedSecondaryVariable::evalField, this), return {1, BaseLib::easyBind(&CachedSecondaryVariable::evalField, this),
eval_residuals}; eval_residuals};
} }
...@@ -63,7 +63,7 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const ...@@ -63,7 +63,7 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const
} }
DBUG("Recomputing %s.", _internal_variable_name.c_str()); DBUG("Recomputing %s.", _internal_variable_name.c_str());
_extrapolator.extrapolate( _extrapolator.extrapolate(
*_extrapolatables, *_current_solution, *_dof_table); 1, *_extrapolatables, *_current_solution, *_dof_table);
auto const& nodal_values = _extrapolator.getNodalValues(); auto const& nodal_values = _extrapolator.getNodalValues();
MathLib::LinAlg::copy(nodal_values, _cached_nodal_values); MathLib::LinAlg::copy(nodal_values, _cached_nodal_values);
_needs_recomputation = false; _needs_recomputation = false;
......
...@@ -217,16 +217,14 @@ void Process::finishNamedFunctionsInitialization() ...@@ -217,16 +217,14 @@ void Process::finishNamedFunctionsInitialization()
for (auto const& named_function : for (auto const& named_function :
_named_function_caller.getNamedFunctions()) { _named_function_caller.getNamedFunctions()) {
auto const& name = named_function.getName(); auto const& name = named_function.getName();
// secondary variables generated from named functions have the prefix
// "fct_".
_secondary_variables.addSecondaryVariable( _secondary_variables.addSecondaryVariable(
"fct_" + name, 1, name,
{BaseLib::easyBind( {1, BaseLib::easyBind(
&GlobalVectorFromNamedFunction::call, &GlobalVectorFromNamedFunction::call,
GlobalVectorFromNamedFunction( GlobalVectorFromNamedFunction(
_named_function_caller.getSpecificFunctionCaller(name), _mesh, _named_function_caller.getSpecificFunctionCaller(name),
getSingleComponentDOFTable(), _mesh, getSingleComponentDOFTable(),
_secondary_variable_context)), _secondary_variable_context)),
nullptr}); nullptr});
} }
} }
......
...@@ -120,9 +120,8 @@ void doProcessOutput(std::string const& file_name, ...@@ -120,9 +120,8 @@ void doProcessOutput(std::string const& file_name,
// the following section is for the output of secondary variables // the following section is for the output of secondary variables
auto add_secondary_var = [&](SecondaryVariable const& var, auto add_secondary_var = [&](SecondaryVariable const& var,
std::string const& output_name) std::string const& output_name) {
{ assert(var.fcts.num_components == 1); // TODO implement other cases
assert(var.n_components == 1); // TODO implement other cases
{ {
DBUG(" secondary variable %s", output_name.c_str()); DBUG(" secondary variable %s", output_name.c_str());
...@@ -135,7 +134,8 @@ void doProcessOutput(std::string const& file_name, ...@@ -135,7 +134,8 @@ void doProcessOutput(std::string const& file_name,
var.fcts.eval_field(x, dof_table, result_cache); var.fcts.eval_field(x, dof_table, result_cache);
// Copy result // Copy result
for (GlobalIndexType i = 0; i < nodal_values.size(); ++i) { for (GlobalIndexType i = 0; i < nodal_values.size(); ++i)
{
assert(!std::isnan(nodal_values[i])); assert(!std::isnan(nodal_values[i]));
(*result)[i] = nodal_values[i]; (*result)[i] = nodal_values[i];
} }
......
...@@ -25,16 +25,15 @@ void SecondaryVariableCollection::addNameMapping(std::string const& internal_nam ...@@ -25,16 +25,15 @@ void SecondaryVariableCollection::addNameMapping(std::string const& internal_nam
} }
void SecondaryVariableCollection::addSecondaryVariable( void SecondaryVariableCollection::addSecondaryVariable(
std::string const& internal_name, std::string const& internal_name, SecondaryVariableFunctions&& fcts)
const unsigned num_components,
SecondaryVariableFunctions&& fcts)
{ {
if (!_configured_secondary_variables if (!_configured_secondary_variables
.emplace(std::make_pair( .emplace(std::make_pair(
internal_name, internal_name,
SecondaryVariable{internal_name /* TODO change */, SecondaryVariable{internal_name /* TODO change */,
num_components, std::move(fcts)})) std::move(fcts)}))
.second) { .second)
{
OGS_FATAL( OGS_FATAL(
"The secondary variable with internal name `%s' has already been " "The secondary variable with internal name `%s' has already been "
"set up.", "set up.",
......
...@@ -43,10 +43,12 @@ struct SecondaryVariableFunctions final ...@@ -43,10 +43,12 @@ struct SecondaryVariableFunctions final
SecondaryVariableFunctions() = default; SecondaryVariableFunctions() = default;
template<typename F1, typename F2> template <typename F1, typename F2>
SecondaryVariableFunctions(F1&& eval_field_, F2&& eval_residuals_) SecondaryVariableFunctions(const unsigned num_components_, F1&& eval_field_,
: eval_field(std::forward<F1>(eval_field_)) F2&& eval_residuals_)
, eval_residuals(std::forward<F2>(eval_residuals_)) : num_components(num_components_),
eval_field(std::forward<F1>(eval_field_)),
eval_residuals(std::forward<F2>(eval_residuals_))
{ {
// Used to detect nasty implicit conversions. // Used to detect nasty implicit conversions.
static_assert(std::is_same<GlobalVector const&, static_assert(std::is_same<GlobalVector const&,
...@@ -66,9 +68,11 @@ struct SecondaryVariableFunctions final ...@@ -66,9 +68,11 @@ struct SecondaryVariableFunctions final
" to a GlobalVector"); " to a GlobalVector");
} }
template<typename F1> template <typename F1>
SecondaryVariableFunctions(F1&& eval_field_, std::nullptr_t) SecondaryVariableFunctions(const unsigned num_components_, F1&& eval_field_,
: eval_field(std::forward<F1>(eval_field_)) std::nullptr_t)
: num_components(num_components_),
eval_field(std::forward<F1>(eval_field_))
{ {
// Used to detect nasty implicit conversions. // Used to detect nasty implicit conversions.
static_assert(std::is_same<GlobalVector const&, static_assert(std::is_same<GlobalVector const&,
...@@ -80,15 +84,15 @@ struct SecondaryVariableFunctions final ...@@ -80,15 +84,15 @@ struct SecondaryVariableFunctions final
" to a GlobalVector"); " to a GlobalVector");
} }
Function eval_field; const unsigned num_components; //!< Number of components of the variable.
Function eval_residuals; Function const eval_field;
Function const eval_residuals;
}; };
//! Stores information about a specific secondary variable //! Stores information about a specific secondary variable
struct SecondaryVariable final struct SecondaryVariable final
{ {
std::string const name; //!< Name of the variable; used, e.g., for output. std::string const name; //!< Name of the variable; used, e.g., for output.
const unsigned n_components; //!< Number of components of the variable.
//! Functions used for computing the secondary variable. //! Functions used for computing the secondary variable.
SecondaryVariableFunctions fcts; SecondaryVariableFunctions fcts;
...@@ -106,7 +110,6 @@ public: ...@@ -106,7 +110,6 @@ public:
* *
* \param internal_name the tag in the project file associated with this * \param internal_name the tag in the project file associated with this
* secondary variable. * secondary variable.
* \param num_components the variable's number of components.
* \param fcts functions that compute the variable. * \param fcts functions that compute the variable.
* *
* \note * \note
...@@ -115,7 +118,6 @@ public: ...@@ -115,7 +118,6 @@ public:
* All other variables are silently ignored. * All other variables are silently ignored.
*/ */
void addSecondaryVariable(std::string const& internal_name, void addSecondaryVariable(std::string const& internal_name,
const unsigned num_components,
SecondaryVariableFunctions&& fcts); SecondaryVariableFunctions&& fcts);
//! Returns the secondary variable with the given external name. //! Returns the secondary variable with the given external name.
...@@ -147,13 +149,14 @@ private: ...@@ -147,13 +149,14 @@ private:
*/ */
template <typename LocalAssemblerCollection> template <typename LocalAssemblerCollection>
SecondaryVariableFunctions makeExtrapolator( SecondaryVariableFunctions makeExtrapolator(
const unsigned num_components,
NumLib::Extrapolator& extrapolator, NumLib::Extrapolator& extrapolator,
LocalAssemblerCollection const& local_assemblers, LocalAssemblerCollection const& local_assemblers,
typename NumLib::ExtrapolatableLocalAssemblerCollection< typename NumLib::ExtrapolatableLocalAssemblerCollection<
LocalAssemblerCollection>::IntegrationPointValuesMethod LocalAssemblerCollection>::IntegrationPointValuesMethod
integration_point_values_method) integration_point_values_method)
{ {
auto const eval_field = [&extrapolator, &local_assemblers, auto const eval_field = [num_components, &extrapolator, &local_assemblers,
integration_point_values_method]( integration_point_values_method](
GlobalVector const& x, GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table, NumLib::LocalToGlobalIndexMap const& dof_table,
...@@ -161,11 +164,12 @@ SecondaryVariableFunctions makeExtrapolator( ...@@ -161,11 +164,12 @@ SecondaryVariableFunctions makeExtrapolator(
) -> GlobalVector const& { ) -> GlobalVector const& {
auto const extrapolatables = NumLib::makeExtrapolatable( auto const extrapolatables = NumLib::makeExtrapolatable(
local_assemblers, integration_point_values_method); local_assemblers, integration_point_values_method);
extrapolator.extrapolate(extrapolatables, x, dof_table); extrapolator.extrapolate(num_components, extrapolatables, x, dof_table);
return extrapolator.getNodalValues(); return extrapolator.getNodalValues();
}; };
auto const eval_residuals = [&extrapolator, &local_assemblers, auto const eval_residuals = [num_components, &extrapolator,
&local_assemblers,
integration_point_values_method]( integration_point_values_method](
GlobalVector const& x, GlobalVector const& x,
NumLib::LocalToGlobalIndexMap const& dof_table, NumLib::LocalToGlobalIndexMap const& dof_table,
...@@ -173,10 +177,11 @@ SecondaryVariableFunctions makeExtrapolator( ...@@ -173,10 +177,11 @@ SecondaryVariableFunctions makeExtrapolator(
) -> GlobalVector const& { ) -> GlobalVector const& {
auto const extrapolatables = NumLib::makeExtrapolatable( auto const extrapolatables = NumLib::makeExtrapolatable(
local_assemblers, integration_point_values_method); local_assemblers, integration_point_values_method);
extrapolator.calculateResiduals(extrapolatables, x, dof_table); extrapolator.calculateResiduals(num_components, extrapolatables, x,
dof_table);
return extrapolator.getElementResiduals(); return extrapolator.getElementResiduals();
}; };
return {eval_field, eval_residuals}; return {num_components, eval_field, eval_residuals};
} }
} // 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