diff --git a/doc/basics/fields.rst b/doc/basics/fields.rst index c183955bb..44b44ad19 100644 --- a/doc/basics/fields.rst +++ b/doc/basics/fields.rst @@ -9,7 +9,7 @@ Fields Cell Centered Fields ^^^^^^^^^^^^^^^^^^^^ -The ``VolumeField`` stores the field values at cell centers and along boundaries, providing essential data for constructing the DSL (Domain Specific Language). This functionality also includes access to mesh data, integrating closely with the computational framework. +The ``VolumeField`` stores the field values at cell centers and along boundaries, providing essential data for constructing the Domain Specific Language (DSL). This functionality also includes access to mesh data, integrating closely with the computational framework. ``DomainField`` acts as the fundamental data container within this structure, offering both read and write to the ``internalField`` and ``boundaryFields`` provided by the ``DomainField``. The ``correctBoundaryConditions`` member function updates the field's boundary conditions, which are specified at construction. It does not hold the data but rather modifies the ``DomainField`` or ``BoundaryField`` container. @@ -26,7 +26,7 @@ Functionally, ``fvccVolField`` parallels several OpenFOAM classes such as ``volS Face Centered fields ^^^^^^^^^^^^^^^^^^^^ -The ``SurfaceField`` class stores the field values interpreted as face centers values. Additionally, it stores boundaries for the corresponding boundary conditions. This provides essential data for constructing the DSL (Domain Specific Language). The functionality also includes access to mesh data, integrating closely with the computational framework. +The ``SurfaceField`` class stores the field values interpreted as face centers values. Additionally, it stores boundaries for the corresponding boundary conditions. This provides essential data for constructing the DSL. The functionality also includes access to mesh data, integrating closely with the computational framework. ``DomainField`` acts as the fundamental data container within this structure, offering both read and to the ``internalField`` and ``boundaryField`` provided by the ``DomainField``. The ``correctBoundaryConditions`` member function updates field's boundary conditions, which are specified at construction. It does not hold the data, but modify the ``DomainField`` or ``BoundaryField`` container. diff --git a/doc/DSL/equation.rst b/doc/dsl/equation.rst similarity index 100% rename from doc/DSL/equation.rst rename to doc/dsl/equation.rst diff --git a/doc/DSL/index.rst b/doc/dsl/index.rst similarity index 100% rename from doc/DSL/index.rst rename to doc/dsl/index.rst diff --git a/doc/DSL/operator.rst b/doc/dsl/operator.rst similarity index 94% rename from doc/DSL/operator.rst rename to doc/dsl/operator.rst index 30c0d3c15..a56f2527c 100644 --- a/doc/DSL/operator.rst +++ b/doc/dsl/operator.rst @@ -9,11 +9,11 @@ The `Operator` implementation uses Type Erasure (more details `[1] divTerm = - Divergence(NeoFOAM::DSL::Operator::Type::Explicit, exec, ...); + NeoFOAM::dsl::Operator divTerm = + Divergence(NeoFOAM::dsl::Operator::Type::Explicit, exec, ...); - NeoFOAM::DSL::Operator ddtTerm = - TimeTerm(NeoFOAM::DSL::Operator::Type::Temporal, exec, ..); + NeoFOAM::dsl::Operator ddtTerm = + TimeTerm(NeoFOAM::dsl::Operator::Type::Temporal, exec, ..); To fit the specification of the EqnSystem (storage in a vector), the Operator needs to be able to be scaled: diff --git a/doc/finiteVolume/cellCentred/index.rst b/doc/finiteVolume/cellCentred/index.rst index 16b862c1e..c8c37828f 100644 --- a/doc/finiteVolume/cellCentred/index.rst +++ b/doc/finiteVolume/cellCentred/index.rst @@ -8,7 +8,6 @@ cellCenteredFiniteVolume :maxdepth: 2 :glob: - DSL.rst boundaryConditions.rst operators.rst stencil.rst diff --git a/doc/index.rst b/doc/index.rst index af18c2ae6..243b96f9e 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -26,7 +26,7 @@ Table of Contents contributing basics/index finiteVolume/cellCentred/index - DSL/index + dsl/index api/index Compatibility with OpenFOAM diff --git a/include/NeoFOAM/DSL/coeff.hpp b/include/NeoFOAM/DSL/coeff.hpp deleted file mode 100644 index d2b2a6623..000000000 --- a/include/NeoFOAM/DSL/coeff.hpp +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023 NeoFOAM authors -#pragma once - -namespace NeoFOAM::DSL -{ - -/** - * @class Coeff - * @brief A class that represents a coefficient for the NeoFOAM DSL. - * - * This class stores a single scalar coefficient and optionally span of values. - * It is used to delay the evaluation of a scalar multiplication with a field to - * avoid the creation of a temporary field copy. - * It provides an indexing operator `operator[]` that returns the evaluated value at the specified - * index. - */ -class Coeff -{ - -public: - - Coeff() : coeff_(1.0), span_(), hasSpan_(false) {} - - Coeff(scalar value) : coeff_(value), span_(), hasSpan_(false) {} - - Coeff(scalar coeff, const Field& field) - : coeff_(coeff), span_(field.span()), hasSpan_(true) - {} - - Coeff(const Field& field) : coeff_(1.0), span_(field.span()), hasSpan_(true) {} - - KOKKOS_INLINE_FUNCTION - scalar operator[](const size_t i) const { return (hasSpan_) ? span_[i] * coeff_ : coeff_; } - - bool hasSpan() { return hasSpan_; } - - std::span span() { return span_; } - - Coeff& operator*=(scalar rhs) - { - coeff_ *= rhs; - return *this; - } - - Coeff& operator*=(const Coeff& rhs) - { - if (hasSpan_ && rhs.hasSpan_) - { - NF_ERROR_EXIT("Not implemented"); - } - - if (!hasSpan_ && rhs.hasSpan_) - { - // Take over the span - span_ = rhs.span_; - hasSpan_ = true; - } - - return this->operator*=(rhs.coeff_); - } - - -private: - - scalar coeff_; - - std::span span_; - - bool hasSpan_; -}; - - -namespace detail - -{ -/* @brief function to force evaluation to a field, the field will be resized to hold either a - * single value or the full field - * - * @param field to store the result - */ -void toField(Coeff& coeff, Field& rhs) -{ - if (coeff.hasSpan()) - { - rhs.resize(coeff.span().size()); - fill(rhs, 1.0); - auto rhsSpan = rhs.span(); - // otherwise we are unable to capture values in the lambda - parallelFor( - rhs.exec(), rhs.range(), KOKKOS_LAMBDA(const size_t i) { rhsSpan[i] *= coeff[i]; } - ); - } - else - { - rhs.resize(1); - fill(rhs, coeff[0]); - } -} - -} - -inline Coeff operator*(const Coeff& lhs, const Coeff& rhs) -{ - Coeff result = lhs; - result *= rhs; - return result; -} - -} // namespace NeoFOAM::DSL diff --git a/include/NeoFOAM/DSL/equation.hpp b/include/NeoFOAM/DSL/equation.hpp deleted file mode 100644 index 87c2f6b01..000000000 --- a/include/NeoFOAM/DSL/equation.hpp +++ /dev/null @@ -1,192 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023-2024 NeoFOAM authors -#pragma once - -#include -#include -#include -#include - -#include "NeoFOAM/core/primitives/scalar.hpp" -#include "NeoFOAM/fields/field.hpp" -#include "NeoFOAM/DSL/operator.hpp" -#include "NeoFOAM/core/error.hpp" - -namespace NeoFOAM::DSL -{ - -class Equation -{ -public: - - Equation(const Executor& exec, std::size_t nCells) - : exec_(exec), nCells_(nCells), temporalOperators_(), implicitOperators_(), - explicitOperators_() - {} - - /* @brief perform all explicit operation and accumulate the result */ - Field explicitOperation() const - { - Field source(exec_, nCells_, 0.0); - return explicitOperation(source); - } - - /* @brief perform all explicit operation and accumulate the result */ - Field explicitOperation(Field& source) const - { - for (auto& Operator : explicitOperators_) - { - Operator.explicitOperation(source); - } - return source; - } - - void addOperator(const Operator& Operator) - { - switch (Operator.getType()) - { - case Operator::Type::Temporal: - temporalOperators_.push_back(Operator); - break; - case Operator::Type::Implicit: - implicitOperators_.push_back(Operator); - break; - case Operator::Type::Explicit: - explicitOperators_.push_back(Operator); - break; - } - } - - void addEquation(const Equation& equation) - { - for (auto& Operator : equation.temporalOperators_) - { - temporalOperators_.push_back(Operator); - } - for (auto& Operator : equation.implicitOperators_) - { - implicitOperators_.push_back(Operator); - } - for (auto& Operator : equation.explicitOperators_) - { - explicitOperators_.push_back(Operator); - } - } - - void solve() - { - if (temporalOperators_.size() == 0 && implicitOperators_.size() == 0) - { - NF_ERROR_EXIT("No temporal or implicit terms to solve."); - } - if (temporalOperators_.size() > 0) - { - NF_ERROR_EXIT("Not implemented."); - // integrate equations in time - } - else - { - NF_ERROR_EXIT("Not implemented."); - // solve sparse matrix system - } - } - - /* @brief getter for the total number of terms in the equation */ - size_t size() const - { - return temporalOperators_.size() + implicitOperators_.size() + explicitOperators_.size(); - } - - // getters - const std::vector& temporalOperators() const { return temporalOperators_; } - - const std::vector& implicitOperators() const { return implicitOperators_; } - - const std::vector& explicitOperators() const { return explicitOperators_; } - - std::vector& temporalOperators() { return temporalOperators_; } - - std::vector& implicitOperators() { return implicitOperators_; } - - std::vector& explicitOperators() { return explicitOperators_; } - - const Executor& exec() const { return exec_; } - - const std::size_t nCells() const { return nCells_; } - - scalar getDt() const { return dt_; } - - scalar dt_ = 0; - -private: - - const Executor exec_; - - const std::size_t nCells_; - - std::vector temporalOperators_; - - std::vector implicitOperators_; - - std::vector explicitOperators_; -}; - -Equation operator+(Equation lhs, const Equation& rhs) -{ - lhs.addEquation(rhs); - return lhs; -} - -Equation operator+(Equation lhs, const Operator& rhs) -{ - lhs.addOperator(rhs); - return lhs; -} - -Equation operator+(const Operator& lhs, const Operator& rhs) -{ - Equation equation(lhs.exec(), lhs.getSize()); - equation.addOperator(lhs); - equation.addOperator(rhs); - return equation; -} - -Equation operator*(scalar scale, const Equation& es) -{ - Equation results(es.exec(), es.nCells()); - for (const auto& Operator : es.temporalOperators()) - { - results.addOperator(scale * Operator); - } - for (const auto& Operator : es.implicitOperators()) - { - results.addOperator(scale * Operator); - } - for (const auto& Operator : es.explicitOperators()) - { - results.addOperator(scale * Operator); - } - return results; -} - -Equation operator-(Equation lhs, const Equation& rhs) -{ - lhs.addEquation(-1.0 * rhs); - return lhs; -} - -Equation operator-(Equation lhs, const Operator& rhs) -{ - lhs.addOperator(-1.0 * rhs); - return lhs; -} - -Equation operator-(const Operator& lhs, const Operator& rhs) -{ - Equation equation(lhs.exec(), lhs.getSize()); - equation.addOperator(lhs); - equation.addOperator(Coeff(-1) * rhs); - return equation; -} - -} // namespace NeoFOAM::DSL diff --git a/include/NeoFOAM/DSL/operator.hpp b/include/NeoFOAM/DSL/operator.hpp deleted file mode 100644 index 64480b7f8..000000000 --- a/include/NeoFOAM/DSL/operator.hpp +++ /dev/null @@ -1,254 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023-2024 NeoFOAM authors -#pragma once - -#include -#include -#include -#include -#include - -#include "NeoFOAM/core/primitives/scalar.hpp" -#include "NeoFOAM/fields/field.hpp" -#include "NeoFOAM/core/parallelAlgorithms.hpp" -#include "NeoFOAM/finiteVolume/cellCentred/fields/volumeField.hpp" -#include "NeoFOAM/core/input.hpp" -#include "NeoFOAM/DSL/coeff.hpp" - - -namespace fvcc = NeoFOAM::finiteVolume::cellCentred; - -namespace NeoFOAM::DSL -{ - -template -concept HasTemporalOperator = requires(T t) { - { - t.temporalOperation(std::declval&>(), std::declval()) - } -> std::same_as; // Adjust return type and arguments as needed -}; - -template -concept HasExplicitOperator = requires(T t) { - { - t.explicitOperation(std::declval&>()) - } -> std::same_as; // Adjust return type and arguments as needed -}; - - -/* @class OperatorMixin - * @brief A mixin class to represent simplify implementations of concrete operators - * in NeoFOAMs DSL - * - * - * @ingroup DSL - */ -class OperatorMixin -{ - -public: - - OperatorMixin(const Executor exec) : exec_(exec), coeffs_() {}; - - virtual ~OperatorMixin() = default; - - const Executor& exec() const { return exec_; } - - Coeff& getCoefficient() { return coeffs_; } - - const Coeff& getCoefficient() const { return coeffs_; } - - /* @brief Given an input this function reads required coeffs */ - void build(const Input& input) {} - -protected: - - const Executor exec_; //!< Executor associated with the field. (CPU, GPU, openMP, etc.) - - Coeff coeffs_; -}; - - -/* @class Operator - * @brief A class to represent a operator in NeoFOAMs DSL - * - * The design here is based on the type erasure design pattern - * see https://www.youtube.com/watch?v=4eeESJQk-mw - * - * Motivation for using type erasure is that concrete implementation - * of Operators e.g Divergence, Laplacian, etc can be stored in a vector of - * Operators - * - * @ingroup DSL - */ -class Operator -{ -public: - - enum class Type - { - Temporal, - Implicit, - Explicit - }; - - template - Operator(T cls) : model_(std::make_unique>(std::move(cls))) - {} - - Operator(const Operator& eqnOperator) : model_ {eqnOperator.model_->clone()} {} - - Operator(Operator&& eqnOperator) : model_ {std::move(eqnOperator.model_)} {} - - void explicitOperation(Field& source) const { model_->explicitOperation(source); } - - void temporalOperation(Field& field) { model_->temporalOperation(field); } - - /* returns the fundamental type of an operator, ie explicit, implicit, temporal */ - Operator::Type getType() const { return model_->getType(); } - - Coeff& getCoefficient() { return model_->getCoefficient(); } - - Coeff getCoefficient() const { return model_->getCoefficient(); } - - /* get the corresponding field size over which the operator operates */ - size_t getSize() const { return model_->getSize(); } - - /* @brief Given an input this function reads required coeffs */ - void build(const Input& input) { model_->build(input); } - - /* @brief Get the executor */ - const Executor& exec() const { return model_->exec(); } - - -private: - - /* @brief Base class defining the concept of a term. This effectively - * defines what functions need to be implemented by a concrete Operator implementation - * */ - struct OperatorConcept - { - virtual ~OperatorConcept() = default; - - virtual void explicitOperation(Field& source) const = 0; - - virtual void temporalOperation(Field& field) = 0; - - /* @brief Given an input this function reads required coeffs */ - virtual void build(const Input& input) = 0; - - /* returns the name of the operator */ - virtual std::string getName() const = 0; - - /* returns the fundamental type of an operator, ie explicit, implicit, temporal */ - virtual Operator::Type getType() const = 0; - - virtual size_t getSize() const = 0; - - /* @brief get the associated coefficient for this term */ - virtual Coeff& getCoefficient() = 0; - - /* @brief get the associated coefficient for this term */ - virtual Coeff getCoefficient() const = 0; - - /* @brief Get the executor */ - virtual const Executor& exec() const = 0; - - // The Prototype Design Pattern - virtual std::unique_ptr clone() const = 0; - }; - - // Templated derived class to implement the type-specific behavior - template - struct OperatorModel : OperatorConcept - { - /* @brief build with concrete operator */ - OperatorModel(ConcreteOperatorType concreteOp) : concreteOp_(std::move(concreteOp)) {} - - /* returns the name of the operator */ - std::string getName() const override { return concreteOp_.getName(); } - - virtual void explicitOperation(Field& source) const override - { - if constexpr (HasExplicitOperator) - { - concreteOp_.explicitOperation(source); - } - } - - virtual void temporalOperation(Field& field) override - { - if constexpr (HasTemporalOperator) - { - concreteOp_.temporalOperation(field); - } - } - - /* @brief Given an input this function reads required coeffs */ - virtual void build(const Input& input) override { concreteOp_.build(input); } - - /* returns the fundamental type of an operator, ie explicit, implicit, temporal */ - Operator::Type getType() const override { return concreteOp_.getType(); } - - /* @brief Get the executor */ - const Executor& exec() const override { return concreteOp_.exec(); } - - /* @brief get the associated coefficient for this term */ - virtual Coeff& getCoefficient() override { return concreteOp_.getCoefficient(); } - - /* @brief get the associated coefficient for this term */ - virtual Coeff getCoefficient() const override { return concreteOp_.getCoefficient(); } - - /* @brief get the associated coefficient for this term */ - virtual size_t getSize() const override { return concreteOp_.getSize(); } - - // The Prototype Design Pattern - std::unique_ptr clone() const override - { - return std::make_unique(*this); - } - - ConcreteOperatorType concreteOp_; - }; - - std::unique_ptr model_; -}; - - -auto operator*(scalar scalarCoeff, const Operator& rhs) -{ - Operator result = rhs; - result.getCoefficient() *= scalarCoeff; - return result; -} - -auto operator*(const Field& coeffField, const Operator& rhs) -{ - Operator result = rhs; - result.getCoefficient() *= Coeff(coeffField); - return result; -} - -auto operator*(const Coeff& coeff, const Operator& rhs) -{ - Operator result = rhs; - result.getCoefficient() *= coeff; - return result; -} - -template - requires std::invocable -Operator operator*(CoeffFunction coeffFunc, const Operator& lhs) -{ - // TODO implement - NF_ERROR_EXIT("Not implemented"); - Operator result = lhs; - // if (!result.getCoefficient().useSpan) - // { - // result.setField(std::make_shared>(result.exec(), result.nCells(), 1.0)); - // } - // map(result.exec(), result.getCoefficient().values, scaleFunc); - return result; -} - -} // namespace NeoFOAM::DSL diff --git a/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/forwardEuler.hpp b/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/forwardEuler.hpp deleted file mode 100644 index d27505611..000000000 --- a/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/forwardEuler.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023 NeoFOAM authors - -#pragma once - -#include "NeoFOAM/fields/field.hpp" -#include "NeoFOAM/core/executor/executor.hpp" -#include "NeoFOAM/finiteVolume/cellCentred/timeIntegration/timeIntegration.hpp" -#include "NeoFOAM/mesh/unstructured.hpp" - -#include - - -namespace NeoFOAM::finiteVolume::cellCentred -{ - - -class ForwardEuler : public TimeIntegrationFactory::Register -{ - -public: - - ForwardEuler(const DSL::Equation& eqnSystem, const Dictionary& dict); - - static std::string name() { return "forwardEuler"; } - - static std::string doc() { return "forwardEuler timeIntegration"; } - - static std::string schema() { return "none"; } - - - void solve() override; - - std::unique_ptr clone() const override; -}; - -} // namespace NeoFOAM diff --git a/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/timeIntegration.hpp b/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/timeIntegration.hpp deleted file mode 100644 index 483f2b8e7..000000000 --- a/include/NeoFOAM/finiteVolume/cellCentred/timeIntegration/timeIntegration.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023 NeoFOAM authors - -#pragma once - -#include "NeoFOAM/fields/field.hpp" -#include "NeoFOAM/core/executor/executor.hpp" -#include "NeoFOAM/mesh/unstructured.hpp" -#include "NeoFOAM/finiteVolume/cellCentred.hpp" - -#include "NeoFOAM/DSL/operator.hpp" -#include "NeoFOAM/DSL/equation.hpp" - -#include - -namespace dsl = NeoFOAM::DSL; - -namespace NeoFOAM::finiteVolume::cellCentred -{ - -class TimeIntegrationFactory : - public NeoFOAM::RuntimeSelectionFactory< - TimeIntegrationFactory, - Parameters> -{ - -public: - - static std::string name() { return "timeIntegrationFactory"; } - - TimeIntegrationFactory(const dsl::Equation& eqnSystem, const Dictionary& dict) - : eqnSystem_(eqnSystem), dict_(dict) - {} - - virtual ~TimeIntegrationFactory() {} // Virtual destructor - - virtual void solve() = 0; // Pure virtual function for solving - - // Pure virtual function for cloning - virtual std::unique_ptr clone() const = 0; - -protected: - - DSL::Equation eqnSystem_; - - const Dictionary& dict_; -}; - -class TimeIntegration -{ - -public: - - TimeIntegration(const TimeIntegration& timeIntegrate) - : timeIntegrateStrategy_(timeIntegrate.timeIntegrateStrategy_->clone()) {}; - - TimeIntegration(TimeIntegration&& timeIntegrate) - : timeIntegrateStrategy_(std::move(timeIntegrate.timeIntegrateStrategy_)) {}; - - TimeIntegration(const DSL::Equation& eqnSystem, const Dictionary& dict) - : timeIntegrateStrategy_( - TimeIntegrationFactory::create(dict.get("type"), eqnSystem, dict) - ) {}; - - - void solve() { timeIntegrateStrategy_->solve(); } - -private: - - - std::unique_ptr timeIntegrateStrategy_; -}; - - -} // namespace NeoFOAM diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 792d72901..bebd717ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,5 @@ # SPDX-License-Identifier: Unlicense # SPDX-FileCopyrightText: 2023 NeoFOAM authors -# add_subdirectory(DSL) add_library(NeoFOAM SHARED) @@ -27,8 +26,7 @@ target_sources( "finiteVolume/cellCentred/operators/gaussGreenGrad.cpp" "finiteVolume/cellCentred/operators/gaussGreenDiv.cpp" "finiteVolume/cellCentred/interpolation/linear.cpp" - "finiteVolume/cellCentred/interpolation/upwind.cpp" - "finiteVolume/cellCentred/timeIntegration/forwardEuler.cpp") + "finiteVolume/cellCentred/interpolation/upwind.cpp") if(NEOFOAM_ENABLE_MPI_SUPPORT) target_sources(NeoFOAM PRIVATE "core/mpi/halfDuplexCommBuffer.cpp" diff --git a/src/finiteVolume/cellCentred/timeIntegration/forwardEuler.cpp b/src/finiteVolume/cellCentred/timeIntegration/forwardEuler.cpp deleted file mode 100644 index 8e80367ba..000000000 --- a/src/finiteVolume/cellCentred/timeIntegration/forwardEuler.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023 NeoFOAM authors - -#include - -#include "NeoFOAM/finiteVolume/cellCentred/timeIntegration/forwardEuler.hpp" -#include "NeoFOAM/core/error.hpp" -#include "NeoFOAM/core/parallelAlgorithms.hpp" - -namespace NeoFOAM::finiteVolume::cellCentred -{ - - -ForwardEuler::ForwardEuler(const dsl::Equation& eqnSystem, const Dictionary& dict) - : TimeIntegrationFactory::Register(eqnSystem, dict) -{ - // Constructor -} - -void ForwardEuler::solve() -{ - std::cout << "Solving using Forward Euler" << std::endl; - scalar dt = eqnSystem_.getDt(); - // fvcc::VolumeField* refField = eqnSystem_.volumeField(); - // Field Phi(eqnSystem_.exec(), eqnSystem_.nCells()); - // NeoFOAM::fill(Phi, 0.0); - Field source = eqnSystem_.explicitOperation(); - - // for (auto& eqnTerm : eqnSystem_.temporalTerms()) - // { - // eqnTerm.temporalOperation(Phi); - // } - // Phi += source*dt; - // refField->internalField() -= source * dt; - // refField->correctBoundaryConditions(); - - // check if execturo is GPU - if (std::holds_alternative(eqnSystem_.exec())) - { - Kokkos::fence(); - } -} - -std::unique_ptr ForwardEuler::clone() const -{ - return std::make_unique(*this); -} - -} // namespace NeoFOAM diff --git a/test/dsl/CMakeLists.txt b/test/dsl/CMakeLists.txt index 419310dd5..c0b7c92f2 100644 --- a/test/dsl/CMakeLists.txt +++ b/test/dsl/CMakeLists.txt @@ -5,4 +5,4 @@ neofoam_unit_test(coeff) neofoam_unit_test(operator) neofoam_unit_test(expression) -add_subdirectory(timeIntegration) \ No newline at end of file +add_subdirectory(timeIntegration) diff --git a/test/dsl/equation.cpp b/test/dsl/equation.cpp deleted file mode 100644 index 11d917a71..000000000 --- a/test/dsl/equation.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: MIT -// SPDX-FileCopyrightText: 2023-2024 NeoFOAM authors -#define CATCH_CONFIG_RUNNER // Define this before including catch.hpp to create - // a custom main -#include "common.hpp" -#include "NeoFOAM/DSL/equation.hpp" - -using Equation = NeoFOAM::DSL::Equation; - -TEST_CASE("Equation") -{ - NeoFOAM::Executor exec = GENERATE( - NeoFOAM::Executor(NeoFOAM::SerialExecutor {}), - NeoFOAM::Executor(NeoFOAM::CPUExecutor {}), - NeoFOAM::Executor(NeoFOAM::GPUExecutor {}) - ); - - std::string execName = std::visit([](auto e) { return e.print(); }, exec); - auto mesh = NeoFOAM::createSingleCellMesh(exec); - - Field fA(exec, 1, 2.0); - BoundaryFields bf(exec, mesh.nBoundaryFaces(), mesh.nBoundaries()); - - std::vector> bcs {}; - auto vf = VolumeField(exec, mesh, fA, bf, bcs); - auto fB = Field(exec, 1, 4.0); - - auto a = Dummy(exec, vf); - auto b = Dummy(exec, vf); - - SECTION("Create equation and perform explicitOperation on " + execName) - { - auto eqnA = a + b; - auto eqnB = fB * Dummy(exec, vf) + 2 * Dummy(exec, vf); - auto eqnC = Equation(2 * a - b); - auto eqnD = 3 * (2 * a - b); - auto eqnE = (2 * a - b) + (2 * a - b); - auto eqnF = (2 * a - b) - (2 * a - b); - - REQUIRE(eqnA.size() == 2); - REQUIRE(eqnB.size() == 2); - REQUIRE(eqnC.size() == 2); - - REQUIRE(getField(eqnA.explicitOperation()) == 4); - REQUIRE(getField(eqnB.explicitOperation()) == 12); - REQUIRE(getField(eqnC.explicitOperation()) == 2); - REQUIRE(getField(eqnD.explicitOperation()) == 6); - REQUIRE(getField(eqnE.explicitOperation()) == 4); - REQUIRE(getField(eqnF.explicitOperation()) == 0); - } -}