NeoN
A framework for CFD software
Loading...
Searching...
No Matches
fixedValue.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <Kokkos_Core.hpp>
8
13
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 Field<ValueType>& domainVector,
23 const UnstructuredMesh& mesh,
24 std::pair<size_t, size_t> range,
25 ValueType fixedValue
26)
27{
28 auto refValue = domainVector.boundaryData().refValue().view();
29 auto value = domainVector.boundaryData().value().view();
30 auto internalValues = domainVector.internalVector().view();
31 auto nInternalFaces = mesh.nInternalFaces();
32
34 domainVector.exec(),
35 range,
36 KOKKOS_LAMBDA(const localIdx i) {
37 refValue[i] = fixedValue;
38 value[i] = fixedValue;
39 internalValues[nInternalFaces + i] = fixedValue;
40 }
41 );
42}
43}
44
45template<typename ValueType>
47 public SurfaceBoundaryFactory<ValueType>::template Register<FixedValue<ValueType>>
48{
50
51public:
52
53 FixedValue(const UnstructuredMesh& mesh, const Dictionary& dict, localIdx patchID)
54 : Base(mesh, dict, patchID), mesh_(mesh), fixedValue_(dict.get<ValueType>("fixedValue"))
55 {}
56
57 virtual void correctBoundaryCondition(Field<ValueType>& domainVector) override
58 {
59 detail::setFixedValue(domainVector, mesh_, this->range(), fixedValue_);
60 }
61
62 static std::string name() { return "fixedValue"; }
63
64 static std::string doc() { return "Set a fixed value on the boundary"; }
65
66 static std::string schema() { return "none"; }
67
68 virtual std::unique_ptr<SurfaceBoundaryFactory<ValueType>> clone() const override
69 {
70 return std::make_unique<FixedValue>(*this);
71 }
72
73private:
74
75 const UnstructuredMesh& mesh_;
76 ValueType fixedValue_;
77};
78
79}
const Vector< T > & refValue() const
Get the view storing the Dirichlet boundary values.
const Vector< T > & value() const
Get the view storing the computed values from the boundary condition.
A class representing a dictionary that stores key-value pairs.
Represents the domain fields for a computational domain.
Definition field.hpp:36
const BoundaryData< ValueType > & boundaryData() const
Definition field.hpp:98
const Executor & exec() const
Definition field.hpp:103
const Vector< ValueType > & internalVector() const
Definition field.hpp:92
Represents an unstructured mesh in NeoN.
localIdx nInternalFaces() const
Get the number of internal faces in the mesh.
virtual std::unique_ptr< SurfaceBoundaryFactory< ValueType > > clone() const override
FixedValue(const UnstructuredMesh &mesh, const Dictionary &dict, localIdx patchID)
virtual void correctBoundaryCondition(Field< ValueType > &domainVector) override
A template class for registering derived classes with a base class.
void setFixedValue(Field< ValueType > &domainVector, const UnstructuredMesh &mesh, std::pair< size_t, size_t > range, ValueType fixedValue)
void parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
int32_t localIdx
Definition label.hpp:32