NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
fixedValue.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 <Kokkos_Core.hpp>
7
12
14{
15namespace detail
16{
17// Without this function the compiler warns that calling a __host__ function
18// from a __device__ function is not allowed
19template<typename ValueType>
21 DomainField<ValueType>& domainField,
22 const UnstructuredMesh& mesh,
23 std::pair<size_t, size_t> range,
24 ValueType fixedValue
25)
26{
27 auto refValue = domainField.boundaryField().refValue().span();
28 auto value = domainField.boundaryField().value().span();
29 auto internalValues = domainField.internalField().span();
30 auto nInternalFaces = mesh.nInternalFaces();
31
33 domainField.exec(),
34 range,
35 KOKKOS_LAMBDA(const size_t i) {
36 refValue[i] = fixedValue;
37 value[i] = fixedValue;
38 internalValues[nInternalFaces + i] = fixedValue;
39 }
40 );
41}
42}
43
44template<typename ValueType>
46 public SurfaceBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
47{
49
50public:
51
52 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, std::size_t patchID)
53 : Base(mesh, dict, patchID), mesh_(mesh), fixedValue_(dict.get<ValueType>("fixedValue"))
54 {}
55
56 virtual void correctBoundaryCondition(DomainField<ValueType>& domainField) override
57 {
58 detail::setFixedValue(domainField, mesh_, this->range(), fixedValue_);
59 }
60
61 static std::string name() { return "fixedValue"; }
62
63 static std::string doc() { return "Set a fixed value on the boundary"; }
64
65 static std::string schema() { return "none"; }
66
67 virtual std::unique_ptr<SurfaceBoundaryFactory<ValueType>> clone() const override
68 {
69 return std::make_unique<FixedValue>(*this);
70 }
71
72private:
73
74 const UnstructuredMesh& mesh_;
75 ValueType fixedValue_;
76};
77
78}
const NeoFOAM::Field< T > & value() const
Get the view storing the computed values from the boundary condition.
const NeoFOAM::Field< T > & refValue() const
Get the view storing the Dirichlet boundary values.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
const Executor & exec() const
const BoundaryFields< ValueType > & boundaryField() const
const Field< ValueType > & internalField() const
Represents an unstructured mesh in NeoFOAM.
size_t nInternalFaces() const
Get the number of internal faces in the mesh.
virtual void correctBoundaryCondition(DomainField< ValueType > &domainField) override
virtual std::unique_ptr< SurfaceBoundaryFactory< ValueType > > clone() const override
FixedValue(const UnstructuredMesh &mesh, const Dictionary &dict, std::size_t patchID)
A template class for registering derived classes with a base class.
void setFixedValue(DomainField< ValueType > &domainField, const UnstructuredMesh &mesh, std::pair< size_t, size_t > range, ValueType fixedValue)
void parallelFor(const Executor &exec, std::pair< size_t, size_t > range, Kernel kernel, std::string name="parallelFor")