23template<
typename FieldValueType,
typename AssemblyType = FieldValueType>
26 LaplacianOperatorFactory<FieldValueType, AssemblyType>,
27 Parameters<const Executor&, const UnstructuredMesh&, const Input&>>
32 static std::unique_ptr<LaplacianOperatorFactory<FieldValueType, AssemblyType>>
35 std::string key = (std::holds_alternative<Dictionary>(inputs))
36 ? std::get<Dictionary>(inputs).get<std::string>(
"LaplacianOperator")
37 : std::get<TokenList>(inputs).next<std::string>();
44 static std::string
name() {
return "LaplacianOperatorFactory"; }
79 virtual std::unique_ptr<LaplacianOperatorFactory<FieldValueType, AssemblyType>>
89template<
typename FieldValueType>
102 gamma_(lapOp.gamma_),
103 sameTypeStrategy_(lapOp.sameTypeStrategy_ ? lapOp.sameTypeStrategy_->clone() : nullptr),
105 lapOp.scalarMtxStrategy_ ? lapOp.scalarMtxStrategy_->clone() : nullptr
115 phi.
exec(), dsl::Coeff(1.0), phi, termType
119 this->
exec_, phi.mesh(), input
121 scalarMtxStrategy_(nullptr)
123 if constexpr (!std::is_same_v<FieldValueType, scalar>)
127 if (std::holds_alternative<NeoN::TokenList>(input))
129 std::get<NeoN::TokenList>(input).reset();
143 phi.
exec(), dsl::Coeff(1.0), phi, termType
145 gamma_(gamma), sameTypeStrategy_(nullptr), scalarMtxStrategy_(nullptr) {};
150 NF_ASSERT(sameTypeStrategy_,
"LaplacianOperatorStrategy not initialized");
153 source.exec(), source.size(), zero<FieldValueType>()
155 sameTypeStrategy_->laplacian(tmpsource, gamma_, this->
field_, operatorScaling);
161 NF_ASSERT(sameTypeStrategy_,
"LaplacianOperatorStrategy not initialized");
163 sameTypeStrategy_->laplacian(ls, gamma_, this->
field_, operatorScaling);
169 template<
typename F = FieldValueType>
170 requires(!std::is_same_v<F, scalar>)
173 NF_ASSERT(scalarMtxStrategy_,
"Scalar-matrix LaplacianOperatorStrategy not initialized");
175 scalarMtxStrategy_->laplacian(ls, gamma_, this->
field_, operatorScaling);
182 if (std::holds_alternative<NeoN::Dictionary>(input))
184 auto dict = std::get<NeoN::Dictionary>(input);
185 std::string schemeName =
"laplacian(" + gamma_.
name +
"," + this->
field_.
name +
")";
190 tokens = std::get<NeoN::TokenList>(input);
193 this->
exec(), mesh, tokens
195 if constexpr (!std::is_same_v<FieldValueType, scalar>)
199 this->
exec(), mesh, tokens
204 std::string
getName()
const {
return "LaplacianOperator"; }
222 std::unique_ptr<LaplacianOperatorFactory<FieldValueType, FieldValueType>> sameTypeStrategy_;
225 std::unique_ptr<LaplacianOperatorFactory<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
const UnstructuredMesh & mesh() const
Returns a const reference to the unstructured mesh object.
virtual std::unique_ptr< LaplacianOperatorFactory< FieldValueType, AssemblyType > > clone() const =0
virtual void laplacian(la::LinearSystem< AssemblyType, FieldValueType > &ls, const SurfaceField< scalar > &gamma, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling)=0
virtual VolumeField< FieldValueType > laplacian(const SurfaceField< scalar > &gamma, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling) const =0
virtual void laplacian(Vector< FieldValueType > &lapPhi, const SurfaceField< scalar > &gamma, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling)=0
static std::unique_ptr< LaplacianOperatorFactory< FieldValueType, AssemblyType > > create(const Executor &exec, const UnstructuredMesh &mesh, const Input &inputs)
virtual void laplacian(VolumeField< FieldValueType > &lapPhi, const SurfaceField< scalar > &gamma, const VolumeField< FieldValueType > &phi, const dsl::Coeff operatorScaling)=0
virtual ~LaplacianOperatorFactory()
static std::string name()
const UnstructuredMesh & mesh_
LaplacianOperatorFactory(const Executor &exec, const UnstructuredMesh &mesh)
FieldValueType VectorValueType
Dictionary getConfig() const
void implicitOperation(la::LinearSystem< scalar, FieldValueType > &ls) const
void implicitOperation(la::LinearSystem< FieldValueType, FieldValueType > &ls) const
LaplacianOperator(dsl::Operator::Type termType, const SurfaceField< scalar > &gamma, VolumeField< FieldValueType > &phi, Input input)
std::string getName() const
void read(const Input &input)
LaplacianOperator(dsl::Operator::Type termType, const SurfaceField< scalar > &gamma, VolumeField< FieldValueType > &phi)
LaplacianOperator(const LaplacianOperator &lapOp)
void explicitOperation(Vector< FieldValueType > &source) const
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...