MGIS 3.1.0
Loading...
Searching...
No Matches
Algorithms.hxx File Reference

Declaration of the algorithms which can be applied to the functions and the evaluators of the MGIS/Function library, that is assign and scalar_reduce, and of the helpers used to check if an evaluator can be assigned to a function. More...

#include <version>
#include <concepts>
#include <optional>
#include "MGIS/Config.hxx"
#include "MGIS/AbstractErrorHandler.hxx"
#include "MGIS/Function/SpaceConcept.hxx"
#include "MGIS/Function/EvaluatorConcept.hxx"
#include "MGIS/Function/FunctionConcept.hxx"
#include "MGIS/Function/Algorithms.ixx"

Namespaces

namespace  mgis
 the namespace mgis encloses all the MGIS project.

Concepts

concept  mgis::function::internals::isEvaluatorAssignableToFunction
 concept stating that an evaluator can be assigned to a function

Functions

constexpr void mgis::function::internals::assign_value (std::span< real >, const auto &)
 assigns to a span of dynamic size the values of any container which can be iterated over
constexpr void mgis::function::internals::assign_value (std::span< real >, const std::span< const real >)
 assigns to a span of dynamic size the values of a constant span
constexpr void mgis::function::internals::assign_value (std::span< real >, const std::span< real >)
 assigns to a span of dynamic size the values of a mutable span
constexpr void mgis::function::internals::assign_value (real &, const std::span< real > &)
 assigns to a scalar value the first value of a mutable span
constexpr void mgis::function::internals::assign_value (real &, const std::span< const real > &)
 assigns to a scalar value the first value of a constant span
constexpr void mgis::function::internals::assign_value (real &, const std::span< real, 1u > &)
 assigns to a scalar value the value of a mutable span of one element
constexpr void mgis::function::internals::assign_value (real &, const std::span< const real, 1u > &)
 assigns to a scalar value the value of a constant span of one element
constexpr void mgis::function::internals::assign_value (real &, const std::array< real, 1u > &)
 assigns to a scalar value the value of an array of one element
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const real)
 assigns a scalar value to the unique element of an array
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const std::array< real, 1u >)
 assigns the value of an array of one element to an array of one element
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const std::span< real >)
 assigns the first value of a mutable span to an array of one element
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const std::span< const real >)
 assigns the first value of a constant span to an array of one element
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const std::span< real, 1u >)
 assigns the value of a mutable one element span to an array of one element
constexpr void mgis::function::internals::assign_value (std::array< real, 1u > &, const std::span< const real, 1u >)
 assigns the value of a constant span of one element to an array of one element
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const real)
 assigns a scalar value to the unique element of a span
constexpr void mgis::function::internals::assign_value (std::span< real >, const real)
 assigns a scalar value to the first element of a span of dynamic size
constexpr void mgis::function::internals::assign_value (std::span< real >, const std::span< real, 1u >)
 assigns the value of a mutable span of one element to the first element of a span of dynamic size
constexpr void mgis::function::internals::assign_value (std::span< real >, const std::span< const real, 1u >)
 assigns the value of a constant span of one element to the first element of a span of dynamic size
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const std::span< real >)
 assigns the first value of a mutable span to a span of one element
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const std::span< const real >)
 assigns the first value of a constant span to a span of one element
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const std::span< real, 1u >)
 assigns the value of a mutable span of one element to a span of one element
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const std::span< const real, 1u >)
 assigns the value of a constant span of one element to a span of one element
constexpr void mgis::function::internals::assign_value (std::span< real, 1u >, const std::array< real, 1u > &)
 assigns the value of an array of one element to a span of one element
template<ViewableFunctionArgumentConcept FunctionType, EvaluatorConcept EvaluatorType>
requires ( (internals::isEvaluatorAssignableToFunction< EvaluatorType, std::decay_t<FunctionType>>)&& // (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>))
constexpr bool mgis::function::assign (AbstractErrorHandler &, FunctionType &&, const EvaluatorType)
 assigns the values computed by an evaluator to a function, the evaluation being sequential
template<EvaluatorConcept EvaluatorType, typename OperatorType>
requires (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>)
constexpr std::optional< real > mgis::function::scalar_reduce (AbstractErrorHandler &, const EvaluatorType, const OperatorType, const real)
 reduces the values computed by a scalar evaluator to a single value using the given reduction operator, the evaluation being sequential

Detailed Description

Declaration of the algorithms which can be applied to the functions and the evaluators of the MGIS/Function library, that is assign and scalar_reduce, and of the helpers used to check if an evaluator can be assigned to a function.

Author
Thomas Helfer
Date
23/04/2025

Function Documentation

◆ assign()

template<ViewableFunctionArgumentConcept FunctionType, EvaluatorConcept EvaluatorType>
requires ( (internals::isEvaluatorAssignableToFunction< EvaluatorType, std::decay_t<FunctionType>>)&& // (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>))
bool mgis::function::assign ( AbstractErrorHandler & ctx,
FunctionType && f,
const EvaluatorType e )
nodiscardconstexpr

assigns the values computed by an evaluator to a function, the evaluation being sequential

implementation of the sequential assign algorithm

The spaces of the function and the evaluator are compared and the number of components of the values returned by both objects is checked to be the same before the values computed by the evaluator are assigned.

Template Parameters
FunctionTypetype of the function argument, which may be a reference type
EvaluatorTypeevaluator type
Parameters
[in]ctxerror handler used to report the errors
[in,out]ffunction assigned
[in]eevaluator providing the values assigned
Returns
true if the assignment succeeded, false otherwise
Note
the values computed by the evaluator are checked with the check function before being assigned. As no execution policy is used, this function can be called in a constexpr context

The error messages "unmatched spaces" and "unmatched number of components" are registered in the error handler when the spaces of the function and the evaluator are not equivalent or when the number of components of the values they return differs. The evaluator is then checked before the values are assigned.

◆ assign_value() [1/2]

void mgis::function::internals::assign_value ( std::span< real > lhs,
const auto & rhs )
constexpr

assigns to a span of dynamic size the values of any container which can be iterated over

implementation of the most generic assign_value function, which iterates over the values of the right hand side

Parameters
[out]lhsspan receiving the values
[in]rhscontainer providing the values
Note
the number of values of lhs must be greater than or equal to the number of values of rhs

The other overloads, declared in MGIS/Function/Algorithms.hxx, copy the values one by one, those connecting a scalar value and a container of a single value using only the first value of this container.

◆ assign_value() [2/2]

void mgis::function::internals::assign_value ( std::span< real > lhs,
const real rhs )
constexpr

assigns a scalar value to the first element of a span of dynamic size

Note
only the first element of the span is modified

◆ scalar_reduce()

template<EvaluatorConcept EvaluatorType, typename OperatorType>
requires (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>)
std::optional< real > mgis::function::scalar_reduce ( AbstractErrorHandler & ctx,
const EvaluatorType e,
const OperatorType op,
const real initial_value )
nodiscardconstexpr

reduces the values computed by a scalar evaluator to a single value using the given reduction operator, the evaluation being sequential

implementation of the sequential scalar_reduce algorithm

The values computed by the evaluator are checked before being reduced.

Template Parameters
EvaluatorTypeevaluator type
OperatorTypetype of the reduction operator, a binary operation taking two scalar values and returning a scalar value
Parameters
[in]ctxerror handler used to report the errors
[in]eevaluator reduced
[in]opreduction operator
[in]initial_valuevalue the reduction starts from
Returns
the reduced value or an empty std::optional if an error is reported
Note
this function requires the values returned by the evaluator to have a single component

The error message "non scalar evaluator" is registered in the error handler when the values returned by the evaluator have more than one component. The evaluator is then checked before being reduced.