areaWriteImpl.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-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 "areaWrite.H"
29 #include "areaFields.H"
30 #include "faMesh.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
35 void Foam::areaWrite::writeSurface
36 (
37  surfaceWriter& writer,
38  const Field<Type>* fieldPtr,
39  const word& fieldName
40 )
41 {
42  const Field<Type>& values = (fieldPtr ? *fieldPtr : Field<Type>::null());
43 
44  fileName outputName = writer.write(fieldName, values);
45 
46  // Case-local file name with "<case>" to make relocatable
47 
49  propsDict.add
50  (
51  "file",
53  );
54  setProperty(fieldName, propsDict);
55 }
56 
57 
58 template<class GeoField>
59 void Foam::areaWrite::performAction
60 (
61  surfaceWriter& writer,
62  const faMesh& areaMesh,
63  const IOobjectList& objects
64 )
65 {
66  wordList fieldNames;
67  if (loadFromFiles_)
68  {
69  // With syncPar (sorted and parallel-consistent)
70  fieldNames = objects.names<GeoField>(fieldSelection_, true);
71  }
72  else
73  {
74  fieldNames = areaMesh.thisDb().names<GeoField>(fieldSelection_);
75 
76  // Synchronize names
77  Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
78  Foam::sort(fieldNames); // Consistent order
79  }
80 
81  for (const word& fieldName : fieldNames)
82  {
83  if (verbose_)
84  {
85  Info<< "write: " << fieldName << endl;
86  }
87 
88  refPtr<GeoField> tfield;
89 
90  if (loadFromFiles_)
91  {
92  tfield.emplace
93  (
94  IOobject
95  (
96  fieldName,
97  time_.timeName(),
98  areaMesh.thisDb(),
102  ),
103  areaMesh
104  );
105  }
106  else
107  {
108  tfield.cref(areaMesh.thisDb().cfindObject<GeoField>(fieldName));
109  }
110 
111  writeSurface(writer, tfield.get(), fieldName);
112  }
113 }
114 
115 
116 // ************************************************************************* //
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath...
Definition: TimePathsI.H:103
Ignore writing from objectRegistry::writeObject()
IOdictionary propsDict(dictIO)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
word outputName("finiteArea-edges.obj")
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
static void combineReduce(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
void setProperty(const word &entryName, const Type &value)
Add generic property.
List< word > wordList
List of word.
Definition: fileName.H:59
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
messageStream Info
Information stream (stdout output on master, null elsewhere)
Do not request registration (bool: false)
const Time & time_
Reference to the time database.