Skip to content

Commit

Permalink
update class names
Browse files Browse the repository at this point in the history
  • Loading branch information
greole committed Oct 25, 2024
1 parent c0996f9 commit 6436f3f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
35 changes: 18 additions & 17 deletions doc/DSL/eqnSystem.rst → doc/DSL/equation.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
EqnSystem
Equation
---------


The `EqnSystem` template class in NeoFOAM holds, manages, builds and solves the expressed/programmed equation and its core responsibilities lie in the answering of the following questions:
The `Equation` class in NeoFOAM holds, manages, builds and solves the expressed/programmed equation.
Its core responsibility lie in the answering of the following questions:

- How to discretize the spatial terms?
- In OpenFOAM this information is provided in **fvSchemes**
Expand All @@ -12,38 +13,38 @@ The `EqnSystem` template class in NeoFOAM holds, manages, builds and solves the
- In OpenFOAM this information is provided in **fvSolution**

The main difference between NeoFOAM and OpenFOAM is that the DSL is evaluated lazily, i.e. evaluation is not performed on construction by default.
Since, the evaluation is not tied to the construction but rather delayde, other numerical integration strategies (e.g. RK methods or even substepping within an the equation) are possible.
Since, the evaluation is not tied to the construction but rather delayed, other numerical integration strategies (e.g. RK methods or even sub-stepping within an the equation) are possible.

To implement lazy evaluation, the `EqnSystem` stores 3 vectors:
To implement lazy evaluation, the `Equation` stores 3 vectors:

.. mermaid::

classDiagram
class EqnTerm {
class Operator {
+explicitOperation(...)
+implicitOperation(...)
}
class DivEqnTerm {
class DivOperator {
+explicitOperation(...)
+implicitOperation(...)
}
class TemporalEqnTerm {
class TemporalOperator {
+explicitOperation(...)
+implicitOperation(...)
}
class Others["..."] {
+explicitOperation(...)
+implicitOperation(...)
}
class EqnSystem {
+temporalTerms_: vector~EqnTerm~
+implicitTerms_: vector~EqnTerm~
+explicitTerms_: vector~EqnTerm~
class Equation {
+temporalTerms_: vector~Operator~
+implicitTerms_: vector~Operator~
+explicitTerms_: vector~Operator~
}
EqnTerm <|-- DivEqnTerm
EqnTerm <|-- TemporalEqnTerm
EqnTerm <|-- Others
EqnSystem <|-- EqnTerm
Operator <|-- DivOperator
Operator <|-- TemporalOperator
Operator <|-- Others
Equation <|-- Operator

Thus, an `EqnSystem` consists of multiple `EqnTerms` which are either explicit, implicit, or temporal.
Consequently, addition, subtraction, and scaling with a field needs to be handled by the `EqnTerm`.
Thus, an `Equation` consists of multiple `Operators` which are either explicit, implicit, or temporal.
Consequently, addition, subtraction, and scaling with a field needs to be handled by the `Operator`.
6 changes: 3 additions & 3 deletions doc/DSL/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The NeoFOAM DSL is designed as drop in replacement for OpenFOAM DSL and the adop

.. code-block:: cpp
dsl::EqnSystem<NeoFOAM::scalar> UEqn
dsl::Equation<NeoFOAM::scalar> UEqn
(
fvcc::impOp::ddt(U)
+ fvcc::impOp::div(phi, U)
Expand All @@ -67,5 +67,5 @@ After the system is assembled or solved, it provides access to the linear system
:maxdepth: 2
:glob:

eqnSystem.rst
eqnTerm.rst
equation.rst
operator.rst
41 changes: 20 additions & 21 deletions doc/DSL/eqnTerm.rst → doc/DSL/operator.rst
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
EqnTerm
Operator
=======


The template `EqnTerm` represents a term in an equation and can be instantiated with different value types.
An `EqnTerm` is either explicit, implicit or temporal, and needs to be scalable by a scalar value or a further field.
The `EqnTerm` implementation uses Type Erasure (more details `[1] <https://medium.com/@gealleh/type-erasure-idiom-in-c-0d1cb4f61cf0>`_ `[2] <https://www.youtube.com/watch?v=4eeESJQk-mw>`_ `[3] <https://www.youtube.com/watch?v=qn6OqefuH08>`_) to achieve polymorphism without inheritance. Consequently, the class needs only to implement the interface which is used in the DSL and which is shown in the below example:

The `Operator` class represents a term in an equation and can be instantiated with different value types.
An `Operator` is either explicit, implicit or temporal, and can be scalable by a an additional coefficient, for example a scalar value or a further field.
The `Operator` implementation uses Type Erasure (more details `[1] <https://medium.com/@gealleh/type-erasure-idiom-in-c-0d1cb4f61cf0>`_ `[2] <https://www.youtube.com/watch?v=4eeESJQk-mw>`_ `[3] <https://www.youtube.com/watch?v=qn6OqefuH08>`_) to achieve polymorphism without inheritance. Consequently, the class needs only to implement the interface which is used in the DSL and which is shown in the below example:

Example:
.. code-block:: cpp
NeoFOAM::DSL::EqnTerm<NeoFOAM::scalar> divTerm =
Divergence(NeoFOAM::DSL::EqnTerm<NeoFOAM::scalar>::Type::Explicit, exec, ...);
NeoFOAM::DSL::Operator<NeoFOAM::scalar> divTerm =
Divergence(NeoFOAM::DSL::Operator<NeoFOAM::scalar>::Type::Explicit, exec, ...);
NeoFOAM::DSL::EqnTerm<NeoFOAM::scalar> ddtTerm =
TimeTerm(NeoFOAM::DSL::EqnTerm<NeoFOAM::scalar>::Type::Temporal, exec, ..);
NeoFOAM::DSL::Operator<NeoFOAM::scalar> ddtTerm =
TimeTerm(NeoFOAM::DSL::Operator<NeoFOAM::scalar>::Type::Temporal, exec, ..);
To fit the specification of the EqnSystem (storage in a vector), the EqnTerm needs to be able to be scaled:
To fit the specification of the EqnSystem (storage in a vector), the Operator needs to be able to be scaled:

.. code-block:: cpp
NeoFOAM::Field<NeoFOAM::scalar> scalingField(exec, nCells, 2.0);
auto sF = scalingField.span();
dsl::EqnTerm<NeoFOAM::scalar> customTerm =
CustomTerm(dsl::EqnTerm<NeoFOAM::scalar>::Type::Explicit, exec, nCells, 1.0);
dsl::Operator<NeoFOAM::scalar> customTerm =
CustomTerm(dsl::Operator<NeoFOAM::scalar>::Type::Explicit, exec, nCells, 1.0);
auto constantScaledTerm = 2.0 * customTerm; // A constant scaling factor of 2 for the term.
auto fieldScaledTerm = scalingField * customTerm; // scalingField is used to scale the term.
// EqnTerm also supports a similar syntax as OpenFOAM
// Operator also supports a similar syntax as OpenFOAM
auto multiScaledTerm = (scale + scale + scale + scale) * customTerm;
// EqnTerm also supports the use of a lambda as scaling function to reduce the number of temporaries generated
// Operator also supports the use of a lambda as scaling function to reduce the number of temporaries generated
auto lambdaScaledTerm =
(KOKKOS_LAMBDA(const NeoFOAM::size_t i) { return sF[i] + sF[i] + sF[i] + sF[i]; }) * customTerm;
To add a user-defined `EqnTerm`, a new derived class must be created, inheriting from `EqnTermMixin`,
and provide the definitions of the below virtual functions that are required for the `EqnTerm` interface:
To add a user-defined `Operator`, a new derived class must be created, inheriting from `OperatorMixin`,
and provide the definitions of the below virtual functions that are required for the `Operator` interface:

- build: build the term
- explicitOperation: perform the explicit operation
Expand All @@ -53,7 +52,7 @@ An example is given below:

.. code-block:: cpp
class CustomEqnTerm : public dsl::EqnTermMixin<NeoFOAM::scalar>
class CustomOperator : public dsl::OperatorMixin<NeoFOAM::scalar>
{
public:
Expand All @@ -75,7 +74,7 @@ An example is given below:
void explicitOperation(NeoFOAM::Field<NeoFOAM::scalar>& source)
{
NeoFOAM::scalar setValue = value;
// scaleField is defined in EqnTermMixin
// scaleField is defined in OperatorMixin
// and accounts for the scaling of the terms
// and considers scaling by fields and scalars
auto scale = scaleField();
Expand All @@ -88,23 +87,23 @@ An example is given below:
}
// other helper functions
dsl::EqnTerm<NeoFOAM::scalar>::Type getType() const { return termType_; }
dsl::Operator<NeoFOAM::scalar>::Type getType() const { return termType_; }
const NeoFOAM::Executor& exec() const { return exec_; }
std::size_t nCells() const { return nCells_; }
fvcc::VolumeField<NeoFOAM::scalar>* volumeField() { return nullptr; }
dsl::EqnTerm<NeoFOAM::scalar>::Type termType_;
dsl::Operator<NeoFOAM::scalar>::Type termType_;
const NeoFOAM::Executor exec_;
std::size_t nCells_;
NeoFOAM::scalar value = 1.0;
};
The required scaling of the term is handle by the `scaleField` function, provided by `EqnTermMixin`. The `scaleField` function returns the 'ScalingField' class that is used to scale by fields and scalars.
The required scaling of the term is handle by the `scaleField` function, provided by `OperatorMixin`. The `scaleField` function returns the 'ScalingField' class that is used to scale by fields and scalars.

.. code-block:: cpp
Expand Down

0 comments on commit 6436f3f

Please sign in to comment.