Loading...
Searching...
No Matches
mapFieldsTemplates.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) 2016-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#include "fvMesh.H"
29#include "polyPatch.H"
30#include "lduSchedule.H"
31#include "meshToMesh.H"
32
33template<class Type>
34void Foam::functionObjects::mapFields::evaluateConstraintTypes
35(
36 GeometricField<Type, fvPatchField, volMesh>& fld
37) const
38{
39 fld.boundaryFieldRef().evaluate_if
40 (
41 [](const auto& pfld) -> bool
42 {
43 return
44 (
45 pfld.type() == pfld.patch().patch().type()
46 && polyPatch::constraintType(pfld.patch().patch().type())
47 );
48 },
50 );
51}
52
53
54template<class Type>
55bool Foam::functionObjects::mapFields::mapFieldType() const
56{
57 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
58
59 const fvMesh& mapRegion = lookupMapRegion();
60
61 wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
62
63 const bool processed = !fieldNames.empty();
64
65 for (const word& fieldName : fieldNames)
66 {
67 const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
68
69 auto* mapFieldPtr = mapRegion.getObjectPtr<VolFieldType>(fieldName);
70
71 if (!mapFieldPtr)
72 {
73 mapFieldPtr = new VolFieldType
74 (
75 IOobject
76 (
77 fieldName,
78 time_.timeName(),
79 mapRegion,
83 ),
84 mapRegion,
85 dimensioned<Type>(field.dimensions(), Zero)
86 );
87
88 mapFieldPtr->store();
89 }
90
91 auto& mappedField = *mapFieldPtr;
92
93 mappedField = interpPtr_->mapTgtToSrc(field);
94
95 Log << " " << fieldName << ": interpolated\n";
96
97 evaluateConstraintTypes(mappedField);
98 }
99
100 return processed;
101}
102
103
104template<class Type>
105bool Foam::functionObjects::mapFields::writeFieldType() const
106{
107 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
108
109 const fvMesh& mapRegion = lookupMapRegion();
110
111 wordList fieldNames(this->mesh_.sortedNames<VolFieldType>(fieldNames_));
112
113 const bool processed = !fieldNames.empty();
114
115 for (const word& fieldName : fieldNames)
116 {
117 const VolFieldType& mappedField =
118 mapRegion.template lookupObject<VolFieldType>(fieldName);
119
120 mappedField.write();
121
122 Log << " " << fieldName << ": written\n";
123 }
124
125 return processed;
126}
127
128
129// ************************************************************************* //
#define Log
Definition PDRblock.C:28
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))
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
static commsTypes defaultCommsType
Default commsType.
Definition UPstream.H:1045
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition polyPatch.C:255
rDeltaTY field()
List< word > wordList
List of word.
Definition fileName.H:60
void evaluateConstraintTypes(GeometricField< Type, fvPatchField, volMesh > &fld)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127