areaWriteTemplates.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-2021 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 {
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  // With syncPar
77  if (Pstream::parRun())
78  {
79  // Synchronize names
80  Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>());
82  }
83 
84  // Sort for consistent order on all processors
86  }
87 
88  for (const word& fieldName : fieldNames)
89  {
90  if (verbose_)
91  {
92  Info<< "write: " << fieldName << endl;
93  }
94 
95  if (loadFromFiles_)
96  {
97  const GeoField fld
98  (
99  IOobject
100  (
101  fieldName,
102  time_.timeName(),
103  areaMesh.thisDb(),
105  ),
106  areaMesh
107  );
108 
109  writeSurface(writer, &fld, fieldName);
110  }
111  else
112  {
113  const auto* fieldPtr =
114  areaMesh.thisDb().cfindObject<GeoField>(fieldName);
115 
116  writeSurface(writer, fieldPtr, fieldName);
117  }
118  }
119 }
120 
121 
122 // ************************************************************************* //
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::functionObjects::timeFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: timeFunctionObject.H:65
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
faMesh.H
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
outputName
word outputName("finiteArea-edges.obj")
Foam::TimePaths::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: TimePathsI.H:87
areaWrite.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
propsDict
IOdictionary propsDict(IOobject("particleTrackProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED))
fld
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))
Definition: gmvOutputLagrangian.H:23
areaFields.H
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
Foam::Pstream::combineGather
static void combineGather(const List< commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:48
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::functionObjects::stateFunctionObject::setProperty
void setProperty(const word &entryName, const Type &value)
Add generic property.
Definition: stateFunctionObjectTemplates.C:59
Foam::Pstream::combineScatter
static void combineScatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Definition: combineGatherScatter.C:183
Foam::Field::null
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:31
Foam::IOobject::MUST_READ
Definition: IOobject.H:185