Loading...
Searching...
No Matches
DimensionedFieldNew.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) 2022-2025 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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29
30template<class Type, class GeoMesh>
31template<class... Args>
33Foam::DimensionedField<Type, GeoMesh>::New_impl
34(
36 const word& name,
37 const Mesh& mesh,
38 Args&&... args
39)
40{
42 (
43 // == mesh.thisDb().newIOobject(name)
45 (
46 name,
47 mesh.thisDb().time().timeName(),
48 mesh.thisDb(),
52 ),
53 mesh,
54 std::forward<Args>(args)...
55 );
56
57 // Registration
58 {
59 if (IOobjectOption::REGISTER == regOpt)
60 {
61 ptr->checkIn();
62 }
63 else if
64 (
65 // LEGACY_REGISTER: detect if caching is desired
67 && ptr->db().is_cacheTemporaryObject(ptr.get())
68 )
69 {
70 ptr.protect(true);
71 ptr->checkIn();
72 }
73 }
74 return ptr;
76
77
78// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
79
80template<class Type, class GeoMesh>
83(
84 const word& name,
86 const Mesh& mesh,
87 const dimensionSet& dims,
88 const Field<Type>& iField
89)
90{
91 return DimensionedField<Type, GeoMesh>::New_impl
92 (
93 regOpt,
94 name,
95 mesh,
96 dims,
97 iField
98 );
99}
100
101
102template<class Type, class GeoMesh>
105(
106 const word& name,
107 const Mesh& mesh,
108 const dimensionSet& dims,
109 const Field<Type>& iField
110)
111{
112 return DimensionedField<Type, GeoMesh>::New_impl
113 (
115 name,
116 mesh,
117 dims,
118 iField
119 );
120}
121
122
123template<class Type, class GeoMesh>
126(
127 const word& name,
129 const Mesh& mesh,
130 const dimensionSet& dims,
131 Field<Type>&& iField
132)
133{
134 return DimensionedField<Type, GeoMesh>::New_impl
135 (
136 regOpt,
137 name,
138 mesh,
139 dims,
140 std::move(iField)
141 );
142}
143
144
145template<class Type, class GeoMesh>
148(
149 const word& name,
150 const Mesh& mesh,
151 const dimensionSet& dims,
152 Field<Type>&& iField
153)
154{
155 return DimensionedField<Type, GeoMesh>::New_impl
156 (
158 name,
159 mesh,
160 dims,
161 std::move(iField)
162 );
163}
164
165
166template<class Type, class GeoMesh>
169(
170 const word& name,
172 const Mesh& mesh,
173 const dimensionSet& dims,
174 const tmp<Field<Type>>& tfield
175)
176{
177 return DimensionedField<Type, GeoMesh>::New_impl
178 (
179 regOpt,
180 name,
181 mesh,
182 dims,
183 tfield
184 );
185}
186
187
188template<class Type, class GeoMesh>
191(
192 const word& name,
193 const Mesh& mesh,
194 const dimensionSet& dims,
195 const tmp<Field<Type>>& tfield
196)
197{
198 return DimensionedField<Type, GeoMesh>::New_impl
199 (
201 name,
202 mesh,
203 dims,
204 tfield
205 );
206}
207
208
209template<class Type, class GeoMesh>
212(
213 const word& name,
215 const Mesh& mesh,
216 const dimensionSet& dims
217)
218{
219 return DimensionedField<Type, GeoMesh>::New_impl
220 (
221 regOpt,
222 name,
223 mesh,
224 dims,
225 false // No checkIOFlags (is NO_READ anyhow)
226 );
227}
228
229
230template<class Type, class GeoMesh>
233(
234 const word& name,
235 const Mesh& mesh,
236 const dimensionSet& dims
237)
238{
239 return DimensionedField<Type, GeoMesh>::New_impl
240 (
242 name,
243 mesh,
244 dims,
245 false // No checkIOFlags (is NO_READ anyhow)
246 );
247}
248
249
250template<class Type, class GeoMesh>
253(
254 const word& name,
256 const Mesh& mesh,
257 const Type& value,
258 const dimensionSet& dims
259)
260{
261 return DimensionedField<Type, GeoMesh>::New_impl
262 (
263 regOpt,
264 name,
265 mesh,
266 value,
267 dims,
268 false // No checkIOFlags (is NO_READ anyhow)
269 );
270}
271
272
273template<class Type, class GeoMesh>
276(
277 const word& name,
278 const Mesh& mesh,
279 const Type& value,
280 const dimensionSet& dims
281)
282{
283 return DimensionedField<Type, GeoMesh>::New_impl
284 (
286 name,
287 mesh,
288 value,
289 dims,
290 false // No checkIOFlags (is NO_READ anyhow)
291 );
292}
293
294
295template<class Type, class GeoMesh>
298(
299 const word& name,
301 const Mesh& mesh,
302 const dimensioned<Type>& dt
303)
304{
306 (
307 name,
308 regOpt,
309 mesh,
310 dt.value(),
312 );
313}
314
315
316template<class Type, class GeoMesh>
319(
320 const word& name,
321 const Mesh& mesh,
322 const dimensioned<Type>& dt
323)
324{
326 (
327 name,
328 mesh,
329 dt.value(),
331 );
332}
333
334
335template<class Type, class GeoMesh>
338(
339 const word& name,
342)
343{
345 (
347 (
348 name,
349 tfld().instance(),
350 tfld().local(),
351 tfld().db(),
355 ),
356 tfld
357 );
358
359 // Registration
360 {
361 if (IOobjectOption::REGISTER == regOpt)
362 {
363 ptr->checkIn();
364 }
365 else if
366 (
367 // LEGACY_REGISTER: detect if caching is desired
368 (IOobjectOption::LEGACY_REGISTER == regOpt)
369 && ptr->db().is_cacheTemporaryObject(ptr.get())
370 )
371 {
372 ptr.protect(true);
373 ptr->checkIn();
374 }
376 return ptr;
377}
378
379
380template<class Type, class GeoMesh>
383(
384 const word& name,
385 const tmp<DimensionedField<Type, GeoMesh>>& tfld
386)
387{
388 return DimensionedField<Type, GeoMesh>::New
389 (
390 name,
391 IOobjectOption::LEGACY_REGISTER,
392 tfld
393 );
394}
395
396
397template<class Type, class GeoMesh>
398template<class AnyType>
401(
403 const word& name,
404 const dimensionSet& dims
405)
406{
408 (
410 (
411 name,
412 fld.instance(),
413 fld.db(),
417 ),
418 fld.mesh(),
419 dims
420 );
421
422 // Registration
423 {
424 if
425 (
426 ptr->db().is_cacheTemporaryObject(ptr.get())
427 )
428 {
429 ptr.protect(true);
430 ptr->checkIn();
431 }
432 }
433 return ptr;
434}
435
436
437template<class Type, class GeoMesh>
438template<class AnyType>
441(
443 const word& name,
444 const dimensioned<Type>& dt
445)
446{
448 (
450 (
451 name,
452 fld.instance(),
453 fld.db(),
457 ),
458 fld.mesh(),
459 dt.value(),
460 dt.dimensions()
461 );
462
463 // Registration
464 {
465 if
466 (
467 ptr->db().is_cacheTemporaryObject(ptr.get())
468 )
469 {
470 ptr.protect(true);
471 ptr->checkIn();
472 }
473 }
474 return ptr;
475}
476
477
478// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components, copy initial field content.
static tmp< DimensionedField< Type, areaMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &iField)
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ NO_REGISTER
Do not request registration (bool: false).
@ LEGACY_REGISTER
Legacy/default registration request (bool: true).
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition IOobject.C:450
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Generic dimensioned Type class.
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
const Type & value() const noexcept
Return const reference to value.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
dynamicFvMesh & mesh
auto & name
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Foam::argList args(argc, argv)