Test-ExtendedStencil2.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) 2012-2015 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  testExtendedStencil2
26 
27 Description
28  Test app for determining extended cell-to-cell stencil.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "fvMesh.H"
34 #include "volFields.H"
35 #include "surfaceFields.H"
36 #include "Time.H"
37 #include "OFstream.H"
38 #include "meshTools.H"
39 
40 #include "CFCCellToCellStencil.H"
41 
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 void writeStencilOBJ
48 (
49  const fileName& fName,
50  const point& fc,
51  const List<point>& stencilCc
52 )
53 {
54  OFstream str(fName);
55  label vertI = 0;
56 
57  meshTools::writeOBJ(str, fc);
58  vertI++;
59 
60  forAll(stencilCc, i)
61  {
62  meshTools::writeOBJ(str, stencilCc[i]);
63  vertI++;
64  str << "l 1 " << vertI << nl;
65  }
66 }
67 
68 
69 // Stats
70 void writeStencilStats(const labelListList& stencil)
71 {
72  label sumSize = 0;
73  label nSum = 0;
74  label minSize = labelMax;
75  label maxSize = labelMin;
76 
77  forAll(stencil, i)
78  {
79  const labelList& sCells = stencil[i];
80 
81  if (sCells.size() > 0)
82  {
83  sumSize += sCells.size();
84  nSum++;
85  minSize = min(minSize, sCells.size());
86  maxSize = max(maxSize, sCells.size());
87  }
88  }
89  reduce(sumSize, sumOp<label>());
90  reduce(nSum, sumOp<label>());
91  sumSize /= nSum;
92 
93  reduce(minSize, minOp<label>());
94  reduce(maxSize, maxOp<label>());
95 
96  Info<< "Stencil size :" << nl
97  << " average : " << sumSize << nl
98  << " min : " << minSize << nl
99  << " max : " << maxSize << nl
100  << endl;
101 }
102 
103 
104 // Main program:
105 
106 int main(int argc, char *argv[])
107 {
108  #include "addTimeOptions.H"
109  #include "setRootCase.H"
110  #include "createTime.H"
111 
112  // Get times list
113  instantList Times = runTime.times();
114  #include "checkTimeOptions.H"
115  runTime.setTime(Times[startTime], startTime);
116  #include "createMesh.H"
117 
118 
119  //---- CELL CENTRED STENCIL -----
120 
121  // Centred, cell stencil
122  // ~~~~~~~~~~~~~~~~~~~~~
123 
124  {
125  // Full stencil. This is per local cell a set of global indices, either
126  // into cells or also boundary faces.
127  CFCCellToCellStencil stencil(mesh);
128 
129  // Construct exchange map and renumber stencil
130  List<Map<label> > compactMap(Pstream::nProcs());
131  mapDistribute map
132  (
133  stencil.globalNumbering(),
134  stencil,
135  compactMap
136  );
137 
138 
139  // Print some stats
140  Info<< "cellFaceCell:" << endl;
141  writeStencilStats(stencil);
142 
143 
144  // Collect the data in stencil form
145  List<List<vector> > stencilPoints;
146  {
147  const volVectorField& fld = mesh.C();
148 
149  // 1. Construct cell data in compact addressing
151 
152  // Insert my internal values
153  forAll(fld, cellI)
154  {
155  compactFld[cellI] = fld[cellI];
156  }
157  // Insert my boundary values
158  label nCompact = fld.size();
159  forAll(fld.boundaryField(), patchI)
160  {
161  const fvPatchField<vector>& pfld = fld.boundaryField()[patchI];
162 
163  forAll(pfld, i)
164  {
165  compactFld[nCompact++] = pfld[i];
166  }
167  }
168 
169  // Do all swapping
170  map.distribute(compactFld);
171 
172  // 2. Pull to stencil
173  stencilPoints.setSize(stencil.size());
174 
175  forAll(stencil, cellI)
176  {
177  const labelList& compactCells = stencil[cellI];
178 
179  stencilPoints[cellI].setSize(compactCells.size());
180 
181  forAll(compactCells, i)
182  {
183  stencilPoints[cellI][i] = compactFld[compactCells[i]];
184  }
185  }
186  }
187 
188 
189  forAll(stencilPoints, cellI)
190  {
192  (
193  runTime.path()/"centredCell" + Foam::name(cellI) + ".obj",
194  mesh.cellCentres()[cellI],
195  stencilPoints[cellI]
196  );
197  }
198  }
199 
200  Pout<< "End\n" << endl;
201 
202  return 0;
203 }
204 
205 
206 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
volFields.H
Foam::maxOp
Definition: ops.H:172
meshTools.H
writeStencilOBJ
void writeStencilOBJ(const fileName &fName, const point &fc, const List< point > &stencilCc)
Definition: Test-ExtendedStencil2.C:45
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
main
int main(int argc, char *argv[])
Definition: Test-ExtendedStencil2.C:103
writeStencilStats
void writeStencilStats(const labelListList &stencil)
Definition: Test-ExtendedStencil2.C:67
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
Foam::labelMax
static const label labelMax
Definition: label.H:62
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:387
Foam::minOp
Definition: ops.H:173
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
addTimeOptions.H
OFstream.H
Foam::cellToCellStencil::globalNumbering
const globalIndex & globalNumbering() const
Global numbering for cells and boundary faces.
Definition: cellToCellStencil.H:128
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
Foam::labelMin
static const label labelMin
Definition: label.H:61
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:152
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:155
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
fld
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
checkTimeOptions.H
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::CFCCellToCellStencil
Definition: CFCCellToCellStencil.H:47
Foam::mapDistributeBase::constructSize
label constructSize() const
Constructed data size.
Definition: mapDistributeBase.H:244
Foam::List::setSize
void setSize(const label)
Reset size of List.
setRootCase.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:369
Foam::sumOp
Definition: ops.H:162
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::Vector< scalar >
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::pTraits
Traits class for primitives.
Definition: pTraits.H:50
createMesh.H
createTime.H
startTime
Foam::label startTime
Definition: checkTimeOptions.H:5
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
CFCCellToCellStencil.H
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47