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-2022 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 
48  dictionary propsDict;
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  if (Pstream::parRun())
78  {
79  Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
80  }
81  Foam::sort(fieldNames); // Consistent order
82  }
83 
84  for (const word& fieldName : fieldNames)
85  {
86  if (verbose_)
87  {
88  Info<< "write: " << fieldName << endl;
89  }
90 
91  if (loadFromFiles_)
92  {
93  const GeoField fld
94  (
95  IOobject
96  (
97  fieldName,
98  time_.timeName(),
99  areaMesh.thisDb(),
101  ),
102  areaMesh
103  );
104 
105  writeSurface(writer, &fld, fieldName);
106  }
107  else
108  {
109  const auto* fieldPtr =
110  areaMesh.thisDb().cfindObject<GeoField>(fieldName);
111 
112  writeSurface(writer, fieldPtr, fieldName);
113  }
114  }
115 }
116 
117 
118 // ************************************************************************* //
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:639
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:80
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:334
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...
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
void setProperty(const word &entryName, const Type &value)
Add generic property.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
List< word > wordList
A List of words.
Definition: fileName.H:58
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
messageStream Info
Information stream (stdout output on master, null elsewhere)
const Time & time_
Reference to the time database.