writeCellCentres.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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Write the three components of the cell centres as volScalarFields so
26  they can be used in postprocessing in thresholding.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "argList.H"
31 #include "timeSelector.H"
32 #include "Time.H"
33 #include "fvMesh.H"
34 #include "vectorIOField.H"
35 #include "volFields.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 
42 int main(int argc, char *argv[])
43 {
45  #include "addRegionOption.H"
46 
47  #include "setRootCase.H"
48  #include "createTime.H"
49 
50  instantList timeDirs = timeSelector::select0(runTime, args);
51 
52  #include "createNamedMesh.H"
53 
54  forAll(timeDirs, timeI)
55  {
56  runTime.setTime(timeDirs[timeI], timeI);
57 
58  Info<< "Time = " << runTime.timeName() << endl;
59 
60  // Check for new mesh
61  mesh.readUpdate();
62 
63  //volVectorField cc
64  //(
65  // IOobject
66  // (
67  // "cellCentres",
68  // runTime.timeName(),
69  // mesh,
70  // IOobject::NO_READ,
71  // IOobject::AUTO_WRITE
72  // ),
73  // 1.0*mesh.C()
74  //);
75  //
76  //Info<< "Writing cellCentre positions to " << cc.name() << " in "
77  // << runTime.timeName() << endl;
78  //cc.write();
79 
80  Info<< "Writing components of cellCentre positions to volScalarFields"
81  << " ccx, ccy, ccz in " << runTime.timeName() << endl;
82 
83  for (direction i=0; i<vector::nComponents; i++)
84  {
85  volScalarField cci
86  (
87  IOobject
88  (
89  "cc" + word(vector::componentNames[i]),
90  runTime.timeName(),
91  mesh,
94  ),
95  mesh.C().component(i)
96  );
97 
98  cci.write();
99  }
100 
101 
103  (
104  IOobject
105  (
106  "V",
107  runTime.timeName(),
108  mesh,
111  false
112  ),
113  mesh,
114  dimensionedScalar("V", mesh.V().dimensions(), 0.0),
116  );
117 
118  V.ref() = mesh.V();
119 
120  volScalarField::Boundary& Vbf = V.boundaryFieldRef();
121 
122  forAll(Vbf, patchi)
123  {
124  Vbf[patchi] = Vbf[patchi].patch().magSf();
125  }
126 
127  Info<< "Writing cellVolumes and patch faceAreas to " << V.name()
128  << " in " << runTime.timeName() << endl;
129 
130  V.write();
131 
132  }
133 
134  Info<< "\nEnd\n" << endl;
135 
136  return 0;
137 }
138 
139 
140 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
uint8_t direction
Definition: direction.H:46
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const volVectorField & C() const
Return cell centres as volVectorField.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:96
dynamicFvMesh & mesh
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:494
A class for handling words, derived from string.
Definition: word.H:59
This boundary condition is not designed to be evaluated; it is assmued that the value is assigned via...
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
Internal & ref()
Return a reference to the dimensioned internal field.
label patchi
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
virtual bool write() const
Write using setting from DB.
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.