NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
surfaceInterpolation.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoFOAM authors
3
4#pragma once
5
6#include <functional>
7
8#include <Kokkos_Core.hpp>
9
17
19{
20
23 SurfaceInterpolationFactory,
24 Parameters<const Executor&, const UnstructuredMesh&, Input>>
25{
27
28public:
29
30 static std::unique_ptr<SurfaceInterpolationFactory>
31 create(const Executor& exec, const UnstructuredMesh& uMesh, Input inputs)
32 {
33 // input is dictionary the key is "interpolation"
34 std::string key =
35 (std::holds_alternative<NeoFOAM::Dictionary>(inputs))
36 ? std::get<NeoFOAM::Dictionary>(inputs).get<std::string>("surfaceInterpolation")
37 : std::get<NeoFOAM::TokenList>(inputs).get<std::string>(0);
38
39 keyExistsOrError(key);
40 return table().at(key)(exec, uMesh, inputs);
41 }
42
43 static std::string name() { return "SurfaceInterpolationFactory"; }
44
46 : exec_(exec), mesh_(mesh) {};
47
48 virtual ~SurfaceInterpolationFactory() {} // Virtual destructor
49
50 virtual void
51 interpolate(const VolumeField<scalar>& volField, ScalarSurfaceField& surfaceField) const = 0;
52
53 virtual void interpolate(
54 const ScalarSurfaceField& faceFlux,
55 const VolumeField<scalar>& volField,
56 ScalarSurfaceField& surfaceField
57 ) const = 0;
58
59 // Pure virtual function for cloning
60 virtual std::unique_ptr<SurfaceInterpolationFactory> clone() const = 0;
61
62protected:
63
66};
67
69{
71
72public:
73
75 : exec_(surfInterp.exec_), mesh_(surfInterp.mesh_),
76 interpolationKernel_(surfInterp.interpolationKernel_->clone()) {};
77
79 : exec_(surfInterp.exec_), mesh_(surfInterp.mesh_),
80 interpolationKernel_(std::move(surfInterp.interpolationKernel_)) {};
81
83 const Executor& exec,
84 const UnstructuredMesh& mesh,
85 std::unique_ptr<SurfaceInterpolationFactory> interpolationKernel
86 )
87 : exec_(exec), mesh_(mesh), interpolationKernel_(std::move(interpolationKernel)) {};
88
89 SurfaceInterpolation(const Executor& exec, const UnstructuredMesh& mesh, Input input)
90 : exec_(exec), mesh_(mesh),
91 interpolationKernel_(SurfaceInterpolationFactory::create(exec, mesh, input)) {};
92
93
94 void interpolate(const VolumeField<scalar>& volField, ScalarSurfaceField& surfaceField) const
95 {
96 interpolationKernel_->interpolate(volField, surfaceField);
97 }
98
100 {
101 std::string nameInterpolated = "interpolated_" + volField.name;
102 ScalarSurfaceField surfaceField(
103 exec_, nameInterpolated, mesh_, createCalculatedBCs<SurfaceBoundary<scalar>>(mesh_)
104 );
105 interpolate(surfaceField, volField);
106 return surfaceField;
107 }
108
110 const ScalarSurfaceField& faceFlux,
111 const VolumeField<scalar>& volField,
112 ScalarSurfaceField& surfaceField
113 ) const
114 {
115 interpolationKernel_->interpolate(faceFlux, volField, surfaceField);
116 }
117
118 ScalarSurfaceField
119 interpolate(const ScalarSurfaceField& faceFlux, const VolumeField<scalar>& volField) const
120 {
121 std::string name = "interpolated_" + volField.name;
122 ScalarSurfaceField surfaceField(
124 );
125 interpolate(faceFlux, volField, surfaceField);
126 return surfaceField;
127 }
128
129private:
130
131 const Executor exec_;
132 const UnstructuredMesh& mesh_;
133 std::unique_ptr<SurfaceInterpolationFactory> interpolationKernel_;
134};
135
136
137} // namespace NeoFOAM
A factory class for runtime selection of derived classes.
Represents an unstructured mesh in NeoFOAM.
Represents a surface boundary field for a cell-centered finite volume method.
static std::unique_ptr< SurfaceInterpolationFactory > create(const Executor &exec, const UnstructuredMesh &uMesh, Input inputs)
SurfaceInterpolationFactory(const Executor &exec, const UnstructuredMesh &mesh)
virtual std::unique_ptr< SurfaceInterpolationFactory > clone() const =0
virtual void interpolate(const VolumeField< scalar > &volField, ScalarSurfaceField &surfaceField) const =0
virtual void interpolate(const ScalarSurfaceField &faceFlux, const VolumeField< scalar > &volField, ScalarSurfaceField &surfaceField) const =0
SurfaceInterpolation(const Executor &exec, const UnstructuredMesh &mesh, std::unique_ptr< SurfaceInterpolationFactory > interpolationKernel)
ScalarSurfaceField interpolate(const ScalarSurfaceField &faceFlux, const VolumeField< scalar > &volField) const
ScalarSurfaceField interpolate(const VolumeField< scalar > &volField) const
void interpolate(const ScalarSurfaceField &faceFlux, const VolumeField< scalar > &volField, ScalarSurfaceField &surfaceField) const
SurfaceInterpolation(const SurfaceInterpolation &surfInterp)
void interpolate(const VolumeField< scalar > &volField, ScalarSurfaceField &surfaceField) const
SurfaceInterpolation(const Executor &exec, const UnstructuredMesh &mesh, Input input)
Represents a volume field in a finite volume method.
std::vector< BoundaryType > createCalculatedBCs(const UnstructuredMesh &mesh)
Definition boundary.hpp:26
std::variant< Dictionary, TokenList > Input
Definition input.hpp:13
const std::string & name(const NeoFOAM::Document &doc)
Retrieves the name of a Document.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16