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-------------------------------------------------------------------------------
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 "areaWrite.H"
29#include "areaFields.H"
30#include "faMesh.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34template<class Type>
35void 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;
50 (
51 "file",
53 );
54 setProperty(fieldName, propsDict);
55}
56
57
58template<class GeoField>
59void 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 // With syncPar
77 if (Pstream::parRun())
78 {
79 // Synchronize names
80 Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>());
81 Pstream::broadcast(fieldNames);
82 }
83
84 // Sort for consistent order on all processors
85 Foam::sort(fieldNames);
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// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:31
static void combineGather(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag, const label comm)
static void broadcast(Type &value, const label comm=UPstream::worldComm)
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: TimePathsI.H:87
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
void setProperty(const word &entryName, const Type &value)
Add generic property.
const Time & time_
Reference to the time database.
word outputName("finiteArea-edges.obj")
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
List< word > wordList
A List of words.
Definition: fileName.H:63
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:342
IOdictionary propsDict(dictIO)