Loading...
Searching...
No Matches
surfMeshTemplates.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2019-2024 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "surfMesh.H"
29#include "surfFields.H"
30
31// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32
33template<class Type, class GeoMeshType>
36(
37 const word& fieldName,
38 const dimensionSet& dims
39)
40{
42
43 const objectRegistry& fieldDb = *this;
44
45 auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
46
47 if (fldptr)
48 {
49 fldptr->dimensions().reset(dims); // Dimensions may have changed
50 fldptr->field() = Foam::zero{};
51 }
52 else
53 {
54 fldptr = new fieldType
55 (
56 fieldDb.newIOobject
57 (
58 fieldName,
62 ),
63 *this,
64 Foam::zero{},
65 dims
66 );
67
68 regIOobject::store(fldptr);
69 }
71 return *fldptr;
72}
73
74
75template<class Type, class GeoMeshType>
78(
79 const word& fieldName,
80 const dimensionSet& dims,
81 const Field<Type>& values
82)
83{
85
86 const objectRegistry& fieldDb = *this;
87
88 auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
89
90 if (fldptr)
91 {
92 fldptr->dimensions().reset(dims); // Dimensions may have changed
93 fldptr->field() = values;
94 }
95 else
96 {
97 fldptr = new fieldType
98 (
99 fieldDb.newIOobject
100 (
101 fieldName,
105 ),
106 *this,
107 dims,
108 values
109 );
110
111 regIOobject::store(fldptr);
112 }
114 return *fldptr;
115}
116
117
118template<class Type, class GeoMeshType>
121(
122 const word& fieldName,
123 const dimensionSet& dims,
124 Field<Type>&& values
125)
126{
127 typedef DimensionedField<Type, GeoMeshType> fieldType;
128
129 const objectRegistry& fieldDb = *this;
130
131 auto* fldptr = fieldDb.getObjectPtr<fieldType>(fieldName);
132
133 if (fldptr)
134 {
135 fldptr->dimensions().reset(dims); // Dimensions may have changed
136 fldptr->field() = std::move(values);
137 }
138 else
139 {
140 fldptr = new fieldType
141 (
142 fieldDb.newIOobject
143 (
144 fieldName,
148 ),
149 *this,
150 dims,
151 std::move(values)
152 );
153
154 regIOobject::store(fldptr);
155 }
156
157 return *fldptr;
158}
159
160
161// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Registry of regIOobjects.
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
bool store()
Register object with its registry and transfer ownership to the registry.
DimensionedField< Type, GeoMeshType > & storeField(const word &fieldName, const dimensionSet &dims, const Field< Type > &values)
Copy/store named field as face or point data (template parameter).
DimensionedField< Type, GeoMeshType > & newField(const word &fieldName, const dimensionSet &dims)
Create/store named zero field as face or point data (template parameter).
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58