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{
15
16namespace detail
17{
18// Without this function the compiler warns that calling a __host__ function
19// from a __device__ function is not allowed
20template<typename ValueType>
22 DomainField<ValueType>& domainField, std::pair<size_t, size_t> range, ValueType fixedValue
23)
24{
25 auto refValue = domainField.boundaryField().refValue().span();
26 auto value = domainField.boundaryField().value().span();
27
29 domainField.exec(),
30 range,
31 KOKKOS_LAMBDA(const size_t i) {
32 refValue[i] = fixedValue;
33 value[i] = fixedValue;
34 }
35 );
36}
37
38}
39
40template<typename ValueType>
41class FixedValue : public VolumeBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
42{
44
45public:
46
47 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, std::size_t patchID)
48 : Base(mesh, dict, patchID), fixedValue_(dict.get<ValueType>("fixedValue"))
49 {}
50
51 virtual void correctBoundaryCondition(DomainField<ValueType>& domainField) final
52 {
53 detail::setFixedValue(domainField, this->range(), fixedValue_);
54 }
55
56 static std::string name() { return "fixedValue"; }
57
58 static std::string doc() { return "Set a fixed value on the boundary"; }
59
60 static std::string schema() { return "none"; }
61
62 virtual std::unique_ptr<VolumeBoundaryFactory<ValueType>> clone() const final
63 {
64 return std::make_unique<FixedValue>(*this);
65 }
66
67private:
68
69 ValueType fixedValue_;
70};
71
72}
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
Represents an unstructured mesh in NeoFOAM.
virtual std::unique_ptr< VolumeBoundaryFactory< ValueType > > clone() const final
virtual void correctBoundaryCondition(DomainField< ValueType > &domainField) final
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, 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")