sample.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-2013 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 Application
25  sample
26 
27 Description
28  Sample field data with a choice of interpolation schemes, sampling options
29  and write formats.
30 
31  Keywords:
32 
33  \param setFormat : set output format, choice of \n
34  - xmgr
35  - jplot
36  - gnuplot
37  - raw
38 
39  \param surfaceFormat : surface output format, choice of \n
40  - null : suppress output
41  - foamFile : separate points, faces and values file
42  - dx : DX scalar or vector format
43  - vtk : VTK ascii format
44  - raw : x y z value format for use with e.g. gnuplot 'splot'.
45  - obj : Wavefron stl. Does not contain values!
46  - stl : ascii stl. Does not contain values!
47 
48  \param interpolationScheme : interpolation scheme, choice of \n
49  - cell : use cell-centre value; constant over cells (default)
50  - cellPoint : use cell-centre and vertex values
51  - cellPointFace : use cell-centre, vertex and face values. \n
52  -# vertex values determined from neighbouring cell-centre values
53  -# face values determined using the current face interpolation scheme
54  for the field (linear, limitedLinear, etc.)
55 
56  \param fields : list of fields to sample
57 
58  \param sets : list of sets to sample, choice of \n
59  - uniform evenly distributed points on line
60  - face one point per face intersection
61  - midPoint one point per cell, inbetween two face intersections
62  - midPointAndFace combination of face and midPoint
63 
64  - curve specified points, not nessecary on line, uses
65  tracking
66  - cloud specified points, uses findCell
67 
68  Option axis: how to write point coordinate. Choice of
69  - x/y/z: x/y/z coordinate only
70  - xyz: three columns
71  (probably does not make sense for anything but raw)
72  - distance: distance from start of sampling line (if uses line)
73  or distance from first specified sampling point
74 
75  Type specific options:
76  uniform, face, midPoint, midPointAndFace : start and end coordinate
77  uniform: extra number of sampling points
78  curve, cloud: list of coordinates
79 
80  \param surfaces : list of surfaces to sample, choice of \n
81  - plane : values on plane defined by point, normal.
82  - patch : values on patch.
83 
84 Notes
85  Runs in parallel
86 
87 \*---------------------------------------------------------------------------*/
88 
89 #include "argList.H"
90 #include "timeSelector.H"
91 #include "IOsampledSets.H"
92 #include "IOsampledSurfaces.H"
93 
94 using namespace Foam;
95 
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 
98 int main(int argc, char *argv[])
99 {
101  #include "addRegionOption.H"
102  #include "addDictOption.H"
103  #include "setRootCase.H"
104  #include "createTime.H"
106  #include "createNamedMesh.H"
107 
108  const word dictName("sampleDict");
109 
110  autoPtr<IOsampledSets> sSetsPtr;
111  autoPtr<IOsampledSurfaces> sSurfsPtr;
112 
113  if (args.optionFound("dict"))
114  {
115  // Construct from fileName
116 
117  fileName dictPath = args["dict"];
118  if (isDir(dictPath))
119  {
121  }
122 
123  sSetsPtr.reset
124  (
125  new IOsampledSets
126  (
127  sampledSets::typeName,
128  mesh,
129  dictPath,
131  true
132  )
133  );
134 
135  // Note: both IOsampledSets and IOsampledSurfaces read the
136  // same dictionary. Unregister one to make sure no duplicates
137  // trying to register
138  sSetsPtr().checkOut();
139 
140  sSurfsPtr.reset
141  (
143  (
144  sampledSurfaces::typeName,
145  mesh,
146  dictPath,
148  true
149  )
150  );
151  }
152  else
153  {
154  // Construct from name in system() directory
155 
156  sSetsPtr.reset
157  (
158  new IOsampledSets
159  (
160  sampledSets::typeName,
161  mesh,
162  dictName,
164  true
165  )
166  );
167 
168  sSetsPtr().checkOut();
169 
170  sSurfsPtr.reset
171  (
173  (
174  sampledSurfaces::typeName,
175  mesh,
176  dictName,
178  true
179  )
180  );
181  }
182 
183  IOsampledSets& sSets = sSetsPtr();
184  IOsampledSurfaces& sSurfs = sSurfsPtr();
185 
186  forAll(timeDirs, timeI)
187  {
188  runTime.setTime(timeDirs[timeI], timeI);
189  Info<< "Time = " << runTime.timeName() << endl;
190 
191  // Handle geometry/topology changes
193 
194 // Info << sSurfs <<endl;
195  sSets.readUpdate(state);
196  sSurfs.readUpdate(state);
197 
198  sSets.write();
199  sSurfs.write();
200 
201 // Info << sSurfs <<endl;
202  Info<< endl;
203  }
204 
205  Info<< "End\n" << endl;
206 
207  return 0;
208 }
209 
210 
211 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
IOsampledSurfaces.H
IOsampledSets.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
addDictOption.H
Foam::fvMesh::readUpdate
virtual readUpdateState readUpdate()
Update the mesh based on the mesh files saved in time.
Definition: fvMesh.C:498
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:109
dictName
const word dictName("particleTrackDict")
main
int main(int argc, char *argv[])
Definition: sample.C:95
Foam::Info
messageStream Info
argList.H
Foam::IOOutputFilter
IOdictionary wrapper around OutputFilter to allow them to read from their associated dictionaries.
Definition: IOOutputFilter.H:59
addRegionOption.H
createNamedMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:88
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::IOOutputFilter::write
virtual void write()
Sample and write.
Definition: IOOutputFilter.C:118
timeSelector.H
createTime.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::autoPtr::reset
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Foam::timeSelector::select0
static instantList select0(Time &runTime, const argList &args)
Return the set of times selected based on the argList options.
Definition: timeSelector.C:253
args
Foam::argList args(argc, argv)
dictPath
fileName dictPath
Definition: setConstantMeshDictionaryIO.H:5