KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
|
#include <expression_utils.h>
Public Types | |
Type definitions | |
using | IndexType = std::size_t |
Static Public Member Functions | |
Static entity value operations | |
static Expression::ConstPointer | Collapse (const Expression::ConstPointer &rpExpression) |
Collapse the lazy expression tree structure in the expression. More... | |
static Expression::ConstPointer | Slice (const Expression::ConstPointer &rpExpression, std::size_t Offset, std::size_t Stride) |
Construct an expression containing a subset of the components of all items. More... | |
template<class TIterator > | |
static Expression::ConstPointer | Reshape (const Expression::ConstPointer &rpExpression, TIterator NewShapeBegin, TIterator NewShapeEnd) |
Construct an expression with identical data but interpreted with a new item shape. More... | |
static Expression::ConstPointer | Reshape (const Expression::ConstPointer &rpExpression, const std::vector< IndexType > &rNewShape) |
Construct an expression with identical data but interpreted with a new item shape. More... | |
static Expression::ConstPointer | Comb (const std::vector< Expression::ConstPointer > &rpExpressions) |
Append the components of a set of expressions to the current expression's components. More... | |
template<class TIterator > | |
static Expression::ConstPointer | Comb (TIterator ExpressionBegin, TIterator ExpressionEnd) |
Append the components of a set of expressions to the current expression's components. More... | |
static Expression::ConstPointer | Abs (const Expression::ConstPointer &rpExpression) |
Returns an expression which represents the component wise absolute value of the given expression. More... | |
static Expression::ConstPointer | Pow (const Expression::ConstPointer &rpExpression, const double Power) |
Returns an expression which raises each component to the given power. More... | |
static Expression::ConstPointer | Pow (const Expression::ConstPointer &rpExpression, const Expression::ConstPointer &rpPowerpExpression) |
Returns an expression which raises each component to the given power from another expression. More... | |
static Expression::ConstPointer | Scale (const Expression::ConstPointer &rpExpression, const double Scale) |
Returns an expression which scales each component to the specified value. More... | |
static Expression::ConstPointer | Scale (const Expression::ConstPointer &rpExpression, const Expression::ConstPointer &rpScaleExpression) |
Returns an expression which scales each component by a value from another expression. More... | |
static Expression::ConstPointer | EntityMin (const Expression::ConstPointer &rpExpression) |
Returns an expression having min value from all the components for each entity. More... | |
static Expression::ConstPointer | EntityMax (const Expression::ConstPointer &rpExpression) |
Returns an expression having max value from all the components for each entity. More... | |
static Expression::ConstPointer | EntitySum (const Expression::ConstPointer &rpExpression) |
Returns an expression having sum of component values for each entity. More... | |
Static scalar reduction operations | |
static double | Sum (const Expression::ConstPointer &rpExpression, const DataCommunicator &rDataCommunicator) |
Returns the sum of the expression assuming it is a flat vector [Shape is not considered]. More... | |
static double | NormInf (const Expression::ConstPointer &rpExpression, const DataCommunicator &rDataCommunicator) |
Returns the infinity norm of the expression assuming it is a flat vector [Shape is not considered]. More... | |
static double | NormL2 (const Expression::ConstPointer &rpExpression, const DataCommunicator &rDataCommunicator) |
Returns the L2 norm of the expression assuming it is a flat vector [Shape is not considered]. More... | |
static double | NormP (const Expression::ConstPointer &rpExpression, const double P, const DataCommunicator &rDataCommunicator) |
Returns the P norm of the expression assuming it is a flat vector [Shape is not considered]. More... | |
static double | InnerProduct (const Expression::ConstPointer &rpExpression1, const Expression::ConstPointer &rpExpression2, const DataCommunicator &rDataCommunicator) |
Returns the inner product between two expressions. More... | |
Static Container expression operations | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Collapse (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a container expression having Collapse evaluated on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Abs (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a container expression having Abs evaluated on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | EntityMin (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a container expression having EntityMin evaluated on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | EntityMax (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a container expression having EntityMax evaluated on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | EntitySum (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a container expression having EntitySum evaluated on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static double | Sum (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a reduced value by evaluating Sum on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static double | NormInf (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a reduced value by evaluating NormInf on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static double | NormL2 (const ContainerExpression< TContainerType > &rContainerExpression) |
Returns a reduced value by evaluating NormL2 on the given rContainerExpression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Pow (const ContainerExpression< TContainerType > &rContainerExpression, const double Value) |
Returns a container expression by evaluating Pow on the given rContainerExpression's expression using Value. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Pow (const ContainerExpression< TContainerType > &rContainerExpression1, const ContainerExpression< TContainerType > &rContainerExpression2) |
Returns a container expression by evaluating Pow on the given rContainerExpression's expression using rContainerExpression2's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Scale (const ContainerExpression< TContainerType > &rContainerExpression, const double Value) |
Returns a container expression by evaluating Scale on the given rContainerExpression's expression using Value. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Scale (const ContainerExpression< TContainerType > &rContainerExpression1, const ContainerExpression< TContainerType > &rContainerExpression2) |
Returns a container expression by evaluating Scale on the given rContainerExpression's expression using rContainerExpression2's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Slice (const ContainerExpression< TContainerType > &rContainerExpression, std::size_t Offset, std::size_t Stride) |
Slicing given container expression's expression. More... | |
template<class TContainerType , class TIterator > | |
static ContainerExpression< TContainerType > | Reshape (const ContainerExpression< TContainerType > &rContainerExpression, TIterator NewShapeBegin, TIterator NewShapeEnd) |
Reshape the data in the given container expression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Reshape (const ContainerExpression< TContainerType > &rContainerExpression, const std::vector< IndexType > &rNewShape) |
Reshape the data in the given container expression's expression. More... | |
template<class TContainerType > | |
static ContainerExpression< TContainerType > | Comb (const std::vector< typename ContainerExpression< TContainerType >::Pointer > &rpContainerExpressions) |
Append the components of a set of container expressions' expression to the current container expression's expression components. More... | |
template<class TContainerType > | |
static double | NormP (const ContainerExpression< TContainerType > &rContainerExpression, const double P) |
Computes the P norm of the given container expression's expression. More... | |
template<class TContainerType > | |
static double | InnerProduct (const ContainerExpression< TContainerType > &rContainerExpression1, const ContainerExpression< TContainerType > &rContainerExpression2) |
Computes inner product between two container expressions's expressions. More... | |
using Kratos::ExpressionUtils::IndexType = std::size_t |
|
inlinestatic |
Returns a container expression having Abs evaluated on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply Abs . |
|
static |
Returns an expression which represents the component wise absolute value of the given expression.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity , then the returned expression \(\left|\underline{\mathbb{u}}\right|\)
\[ \left|\underline{\mathbb{u}}\right| = \left|u_{ij}\right| \]
|
inlinestatic |
Returns a container expression having Collapse evaluated on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply Collapse . |
|
static |
Collapse the lazy expression tree structure in the expression.
This method returns an expression which is created by collapsing the tree structure in the rpExpression. This is useful in cases, when the expression tree becomes large and memory intensive, so the tree can be collapsed to a one leaf expression releasing memory. This has to evaluate the expression for each entity, hence this is a computationly expensive task.
This method is optimized and compatible with OpenMP and MPI.
rpExpression | Expression to collapse the lazy expression tree. |
|
static |
Append the components of a set of expressions to the current expression's components.
This method combines a set of expressions into the current one as explained in the following example: All provided expressions in rpExpressions must have the same number of items.
For example, let rpExpressions contain the following expressions:
The resulting expression has item shape [3] with 3 items:
This creates a lazy expression, hence it has a constant cost complexity irrespective of the data size (The expression won't be evaluated unless Expression::Evaluate is called).
rpExpressions | Expressions to comb components from. |
|
inlinestatic |
Append the components of a set of container expressions' expression to the current container expression's expression components.
If | the rpContainerExpressions is empty. |
TContainerType | Type of the data container |
rpContainerExpressions | List of container expressions to comb through. |
|
inlinestatic |
Append the components of a set of expressions to the current expression's components.
This method combines a set of expressions into the current one as explained in the following example: All provided expressions in the { ExpressionBegin, ExpressionEnd } range must have the same number of items.
For example, let the { ExpressionBegin, ExpressionEnd } range contain the following expressions:
The resulting expression has item shape [3] with 3 items:
This creates a lazy expression, hence it has a constant cost complexity irrespective of the data size (The expression won't be evaluated unless Expression::Evaluate is called).
ExpressionBegin | Iterator pointing to the first expression to comb components from. |
ExpressionEnd | Iterator past the last expression to comb components from. |
|
inlinestatic |
Returns a container expression having EntityMax evaluated on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply EntityMax . |
|
static |
Returns an expression having max value from all the components for each entity.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity , Following illustrates the returned expression which is always a scalar expression having \(m_i\) representing the \(i^{th}\) entity data.
\[ EntityMax(\underline{\mathbb{u}}) = m_{i} \]
Where,
\[ m_{i} = \max_{j\in \left[0, N\right)} u_{ij} \]
|
inlinestatic |
Returns a container expression having EntityMin evaluated on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply EntityMin . |
|
static |
Returns an expression having min value from all the components for each entity.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity , Following illustrates the returned expression which is always a scalar expression having \(m_i\) representing the \(i^{th}\) entity data.
\[ EntityMin(\underline{\mathbb{u}}) = m_{i} \]
Where,
\[ m_{i} = \min_{j\in \left[0, N\right)} u_{ij} \]
|
inlinestatic |
Returns a container expression having EntitySum evaluated on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply EntitySum . |
|
static |
Returns an expression having sum of component values for each entity.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity , Following illustrates the returned expression which is always a scalar expression having \(m_i\) representing the \(i^{th}\) entity data.
\[ EntitySum(\underline{\mathbb{u}}) = m_{i} \]
Where,
\[ m_{i} = \sum_{j\in \left[0, N\right)} u_{ij} \]
|
inlinestatic |
Computes inner product between two container expressions's expressions.
TContainerType | Container type. |
rContainerExpression1 | Container expression 1. |
rContainerExpression2 | Container expression 2. |
|
static |
Returns the inner product between two expressions.
If the input rpExpression1 is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities) and the input rpExpression2 is \(\underline{\mathbb{v}}\), where \(v_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities), Following illustrates the returned value where the entity data is flattened. This does not consider shapes of the expressions. They should have same size of flattened vectors.
\[ InnerProduct(\underline{\mathbb{u}}, \underline{\mathbb{v}}) = \sum_{i\in \left[0, M\right)} \sum_{j\in \left[0, N\right)} u_{ij} \times v_{ij} \]
This method is compatible with shared and distributed memory parallelized runs.
If | the flattend size mismatch. |
If | the number of entities mismatch. |
rpExpression1 | Expression1. |
rpExpression1 | Expression2. |
rDataCommunicator | Data communicator for MPI communication. |
|
inlinestatic |
Returns a reduced value by evaluating NormInf on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply NormInf . |
|
static |
Returns the infinity norm of the expression assuming it is a flat vector [Shape is not considered].
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities) , Following illustrates the returned value where the entity data is flattened.
\[ NormInf(\underline{\mathbb{u}}) = \max_{(i,j)\in \left[0, M\right)\times \left[0, N\right)} \left|u_{ij}\right| \]
This method is compatible with shared and distributed memory parallelized runs.
rpExpression | Expressions to be summed. |
rDataCommunicator | Data communicator for MPI communication. |
|
inlinestatic |
Returns a reduced value by evaluating NormL2 on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply NormL2 . |
|
static |
Returns the L2 norm of the expression assuming it is a flat vector [Shape is not considered].
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities) , Following illustrates the returned value where the entity data is flattened.
\[ NormL2(\underline{\mathbb{u}}) = \sqrt {\sum_{i\in \left[0, M\right)} \sum_{j\in \left[0, N\right)} u_{ij}^2} \]
This method is compatible with shared and distributed memory parallelized runs.
rpExpression | Expressions to be summed. |
rDataCommunicator | Data communicator for MPI communication. |
|
inlinestatic |
Computes the P norm of the given container expression's expression.
TContainerType | Container type. |
rContainerExpression | Input container expression. |
P | Norm coefficient. |
|
static |
Returns the P norm of the expression assuming it is a flat vector [Shape is not considered].
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities) , Following illustrates the returned value where the entity data is flattened.
\[ NormP(\underline{\mathbb{u}}, P) = \left(\sum_{i\in \left[0, M\right)} \sum_{j\in \left[0, N\right)} \left|u_{ij}\right|^P\right)^{1/P} \]
This method is compatible with shared and distributed memory parallelized runs.
rpExpression | Expressions to be summed. |
rDataCommunicator | Data communicator for MPI communication. |
P | P norm coefficent. |
|
inlinestatic |
Returns a container expression by evaluating Pow on the given rContainerExpression's expression using Value.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply Pow . |
|
inlinestatic |
Returns a container expression by evaluating Pow on the given rContainerExpression's expression using rContainerExpression2's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression1 to apply Pow . |
ContainerExpression<TContainerType> | Container expression1 to apply Pow . |
|
static |
Returns an expression which raises each component to the given power.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity , where P is specified by Power.
\[ Pow(\underline{\mathbb{u}}, P) = u_{ij}^P \]
|
static |
Returns an expression which raises each component to the given power from another expression.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity and the rpPowerpExpression is \(\underline{\mathbb{P}}\), where \(p_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity , then the returned expression can be illustrated as below.
\[ Pow(\underline{\mathbb{u}}, \underline{\mathbb{p}}) = u_{ij}^{p_{ij}} \]
If the given rpPowerpExpression is a scalar expression then the following will be returned
\[ Pow(\underline{\mathbb{u}}, \underline{\mathbb{p}}) = u_{ij}^{p_{i}} \]
If | the number of entities mismatch between rpExpression and rpPowerpExpression |
If | the shape of the rpExpression and rpPowerpExpression does not match or rpPowerpExpression is not representing a scalar expression. |
|
inlinestatic |
Reshape the data in the given container expression's expression.
TContainerType | Container type |
rContainerExpression | Container expression to be sliced. |
rNewShape | New shape. |
|
inlinestatic |
Reshape the data in the given container expression's expression.
TContainerType | Container type |
TIterator | Iterator type for the shape. |
rContainerExpression | Container expression to be sliced. |
NewShapeBegin | Starting iterator for the new shape. |
NewShapeEnd | Ending iterator for the new shape |
|
static |
Construct an expression with identical data but interpreted with a new item shape.
Reshaping is done on each entitiy's data array, and not on the flattened expression. For example:
Assume an Expression of shape [2, 3] and 2 entities with following data in the flattened representation:
The underlying data of the reshaped expression is interpreted as follows:
This creates a lazy expression, hence it has a constant cost complexity irrespective of the data size.
rpExpression | Expression to reshape. |
rNewShape | New shape to used to reshape the existing expression. |
|
inlinestatic |
Construct an expression with identical data but interpreted with a new item shape.
Reshaping is done on each entitiy's data array, and not on the flattened expression. For example:
Assume an Expression of shape [2, 3] and 2 entities with following data in the flattened representation:
The underlying data of the reshaped expression is interpreted as follows:
This creates a lazy expression, hence it has a constant cost complexity irrespective of the data size.
rpExpression | Expression to reshape. |
NewShapeBegin | Iterator pointing to the first component of the new shape. |
NewShapeEnd | Iterator past the last component of the new shape. |
|
inlinestatic |
Returns a container expression by evaluating Scale on the given rContainerExpression's expression using Value.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply Scale . |
|
inlinestatic |
Returns a container expression by evaluating Scale on the given rContainerExpression's expression using rContainerExpression2's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression1 to apply Scale . |
ContainerExpression<TContainerType> | Container expression1 to apply Scale . |
|
static |
Returns an expression which scales each component to the specified value.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity , where Scale is specified by Scale.
\[ Scale(\underline{\mathbb{u}}, S) = u_{ij}^S \]
|
static |
Returns an expression which scales each component by a value from another expression.
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity and the rpScaleExpression is \(\underline{\mathbb{s}}\), where \(s_{ij}\) representss \(j^{th}\) component of the flattened entity data for \(i^{th}\) entity , then the returned expression can be illustrated as below.
\[ Scale(\underline{\mathbb{u}}, \underline{\mathbb{s}}) = u_{ij}^{s_{ij}} \]
If the given rpScaleExpression is a scalar expression then the following will be returned
\[ Scale(\underline{\mathbb{u}}, \underline{\mathbb{s}}) = u_{ij}^{s_{i}} \]
If | the number of entities mismatch between rpExpression and rpScaleExpression |
If | the shape of the rpExpression and rpScaleExpression does not match or rpScaleExpression is not representing a scalar expression. |
|
inlinestatic |
Slicing given container expression's expression.
TContainerType | Container type |
rContainerExpression | Container expression to be sliced. |
Offset | Index of the first component to begin slicing at. |
Stride | Number of components from the offset in the sliced item. |
|
static |
Construct an expression containing a subset of the components of all items.
Slicing is done on each entitiy's data array, and not on the flattened expression. For example:
Assume an Expression of shape [5] and 2 entities with the following data in the flattened representation:
Data for entity 1 is represented with <–1-->.
Let
. The resulting sliced expression then represents the following data:
output_data = [2, 3, 4, 7, 8, 9] output container shape = [3] = equal to Stride.
Slicing will always create a one dimensional array even if the input expression is multidimensional.
This creates a lazy expression, hence it has a constant cost complexity irrespective of the data size.
Offset | Index of the first component to begin slicing at. |
Stride | Number of components from the offset in the sliced item. |
|
inlinestatic |
Returns a reduced value by evaluating Sum on the given rContainerExpression's expression.
TContainerType | Container type. |
ContainerExpression<TContainerType> | Container expression to apply Sum . |
|
static |
Returns the sum of the expression assuming it is a flat vector [Shape is not considered].
If the input rpExpression is \(\underline{\mathbb{u}}\), where \(u_{ij}\) representss \(j^{th}\) component of the flattened (having \(N\) total components) entity data for \(i^{th}\) entity (having \(M\) entities) , Following illustrates the returned value where the entity data is flattened.
\[ Sum(\underline{\mathbb{u}}) = \sum_{i\in \left[0, M\right)} \sum_{j\in \left[0, N\right)} u_{ij} \]
This method is compatible with shared and distributed memory parallelized runs.
rpExpression | Expressions to be summed. |
rDataCommunicator | Data communicator for MPI communication. |