21template<
typename FieldValueType,
typename AssemblyType = FieldValueType>
24 DivOperatorFactory<FieldValueType, AssemblyType>,
25 Parameters<const Executor&, const UnstructuredMesh&, const Input&>>
30 static std::unique_ptr<DivOperatorFactory<FieldValueType, AssemblyType>>
33 std::string key = (std::holds_alternative<Dictionary>(inputs))
34 ? std::get<Dictionary>(inputs).get<std::string>(
"DivOperator")
35 : std::get<TokenList>(inputs).next<std::string>();
42 static std::string
name() {
return "DivOperatorFactory"; }
73 virtual std::unique_ptr<DivOperatorFactory<FieldValueType, AssemblyType>>
clone()
const = 0;
82template<
typename FieldValueType>
95 faceFlux_(divOp.faceFlux_),
96 sameTypeStrategy_(divOp.sameTypeStrategy_ ? divOp.sameTypeStrategy_->clone() : nullptr),
98 divOp.scalarMtxStrategy_ ? divOp.scalarMtxStrategy_->clone() : nullptr
108 phi.
exec(), dsl::Coeff(1.0), phi, termType
112 phi.
exec(), phi.mesh(), input
114 scalarMtxStrategy_(nullptr)
116 if constexpr (!std::is_same_v<FieldValueType, scalar>)
120 if (std::holds_alternative<NeoN::TokenList>(input))
122 std::get<NeoN::TokenList>(input).reset();
135 phi.
exec(), dsl::Coeff(1.0), phi, termType
137 faceFlux_(faceFlux), sameTypeStrategy_(nullptr), scalarMtxStrategy_(nullptr) {};
142 NF_ASSERT(sameTypeStrategy_,
"DivOperatorStrategy not initialized");
146 sameTypeStrategy_->div(tmpsource, faceFlux_, this->
getVector(), operatorScaling);
152 NF_ASSERT(sameTypeStrategy_,
"DivOperatorStrategy not initialized");
154 sameTypeStrategy_->div(ls, faceFlux_, this->
getVector(), operatorScaling);
161 template<
typename F = FieldValueType>
162 requires(!std::is_same_v<F, scalar>)
165 NF_ASSERT(scalarMtxStrategy_,
"Scalar-matrix DivOperatorStrategy not initialized");
167 scalarMtxStrategy_->div(ls, faceFlux_, this->
getVector(), operatorScaling);
174 if (std::holds_alternative<NeoN::Dictionary>(input))
176 auto dict = std::get<NeoN::Dictionary>(input);
177 std::string schemeName =
"div(" + faceFlux_.
name +
"," + this->
getVector().
name +
")";
182 tokens = std::get<NeoN::TokenList>(input);
186 if constexpr (!std::is_same_v<FieldValueType, scalar>)
194 std::string
getName()
const {
return "DivOperator"; }
212 std::unique_ptr<DivOperatorFactory<FieldValueType, FieldValueType>> sameTypeStrategy_;
215 std::unique_ptr<DivOperatorFactory<FieldValueType, scalar>> scalarMtxStrategy_;
A class representing a dictionary that stores key-value pairs.
A factory class for runtime selection of derived classes.
A class representing a list of tokens.
ReturnType & get(const size_t &idx)
Retrieves the value associated with the given index, casting it to the specified type.
void reset() const
Rewind the read cursor used by next<>() so the list can be iterated again from the beginning.
Represents an unstructured mesh in NeoN.
A class to contain the data and executors for a field and define some basic operations.
A class that represents a coefficient for the NeoN dsl.
const VolumeField< FieldValueType > & field_
const Executor exec_
Executor associated with the field. (CPU, GPU, openMP, etc.)
OperatorMixin(const Executor exec, const Coeff &coeffs, const VolumeField< FieldValueType > &field, Operator::Type type)
const VolumeField< FieldValueType > & getVector() const
virtual const Executor & exec() const final
DivOperatorFactory(const Executor &exec, const UnstructuredMesh &mesh)
virtual ~DivOperatorFactory()
virtual void div(la::LinearSystem< AssemblyType, FieldValueType > &ls, const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling) const =0
static std::unique_ptr< DivOperatorFactory< FieldValueType, AssemblyType > > create(const Executor &exec, const UnstructuredMesh &uMesh, const Input &inputs)
virtual std::unique_ptr< DivOperatorFactory< FieldValueType, AssemblyType > > clone() const =0
virtual VolumeField< FieldValueType > div(const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling) const =0
virtual void div(Vector< FieldValueType > &divPhi, const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling) const =0
const UnstructuredMesh & mesh_
virtual void div(VolumeField< FieldValueType > &divPhi, const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling) const =0
static std::string name()
std::string getName() const
void read(const Input &input)
DivOperator(dsl::Operator::Type termType, const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi, Input input)
DivOperator(const DivOperator &divOp)
void implicitOperation(la::LinearSystem< FieldValueType, FieldValueType > &ls) const
void implicitOperation(la::LinearSystem< scalar, FieldValueType > &ls) const
FieldValueType VectorValueType
void explicitOperation(Vector< FieldValueType > &source) const
Dictionary getConfig() const
DivOperator(dsl::Operator::Type termType, const SurfaceField< scalar > &faceFlux, const VolumeField< FieldValueType > &phi)
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
const Executor & exec() const
Returns a const reference to the executor object.
Represents a surface field in a finite volume method.
Represents a volume field in a finite volume method.
A class representing a linear system of equations.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
std::variant< Dictionary, TokenList > Input
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
A wrapper class to put references in dictionaries to overcome the issue that std::any cannot hold a r...