Test-MappedPatch.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 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  testMappedPatch
26 
27 Description
28  Test mapped b.c. by mapping face centres (mesh.C().boundaryField()).
29 
30 \*---------------------------------------------------------------------------*/
31 
32 
33 #include "argList.H"
34 #include "fvMesh.H"
35 #include "volFields.H"
36 #include "meshTools.H"
37 #include "Time.H"
38 #include "OFstream.H"
39 #include "volFields.H"
40 #include "mappedPolyPatch.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 
48 // Main program:
49 
50 int main(int argc, char *argv[])
51 {
52  #include "addTimeOptions.H"
53  #include "setRootCase.H"
54  #include "createTime.H"
55  #include "createMesh.H"
56 //定义了一个字符串数组,里面存放的是calculated的字符,有几个边界就存几个,在下面注册cc对象的时候使用
57  wordList patchFieldTypes
58  (
60  calculatedFvPatchVectorField::typeName
61  );
62 
63  Info << "wordList patchFieldTypes " << patchFieldTypes << endl;
64  Info << "mesh.boundaryMesh.size() is " << mesh.boundaryMesh().size() << endl;
65  Info << "calculatedFvPatchVectorField::typeName is " << calculatedFvPatchVectorField::typeName << endl;
66 
67  forAll(mesh.boundaryMesh(), patchI)
68  {
69  Info << "mesh.boundaryMesh() ID number " << patchI << endl;
70 
71  Info << "mesh.boundaryField type is " << mappedFixedValueFvPatchVectorField::typeName << endl;
72  if (isA<mappedPolyPatch>(mesh.boundaryMesh()[patchI]))
73  {
74  patchFieldTypes[patchI] =
75  mappedFixedValueFvPatchVectorField::typeName;
76  }
77  }
78 
79  Pout<< "patchFieldTypes:" << patchFieldTypes << endl;
80 
81  Info << "add cc to volVectorField " <<endl;
82 
84  (
85  IOobject
86  (
87  "cc",
88  runTime.timeName(),
89  mesh,
92  ),
93  mesh,
95  patchFieldTypes
96  );
97  Info << "the new object cc is ===============" << endl;
98 
99  // Info << "cc 's internalFiled is " << endl << mesh.C().internalField();
100  cc.internalField() = mesh.C().internalField();
101  Info << "=============================================" << endl;
102  Info << "before update ,cc 's boundaryField is " << endl << cc.boundaryField();
104  Info << "after update ,cc 's boundaryField is " << endl << cc.boundaryField();
105  Info << "=============================================" << endl;
106 
107  Info << "begion loop all the cc's boundaryField" << endl;
108  forAll(cc.boundaryField(), patchI)
109  {
110  Info << "begin to judge wether the cc boundaryField is a mappedFixedValueFvPatchVectorField, if so , begin write into a obj file"<< endl<< endl;
111  if
112  (
113  isA<mappedFixedValueFvPatchVectorField>
114  (
115  cc.boundaryField()[patchI]
116  )
117  )
118 
119  {
120  Pout<< "Detected a mapped patch:" << patchI << endl;
121  OFstream str(mesh.boundaryMesh()[patchI].name() + ".obj");
122  Pout<< "Writing mapped values to " << str.name() << endl;
123  label vertI = 0;
124  const fvPatchVectorField& fvp = cc.boundaryField()[patchI];
125  forAll(fvp, i)
126  {
127  meshTools::writeOBJ(str, fvp.patch().Cf()[i]);
128  vertI++;
129  meshTools::writeOBJ(str, fvp[i]);
130  vertI++;
131  str << "l " << vertI-1 << ' ' << vertI << nl;
132  }
133  }
134  else
135  {
136  Info<< endl << " cc boundaryField " << patchI << " is not a mappedPatch!" << endl;
137  }
138  }
139 
140  Info<< "End\n" << endl;
141 
142  return 0;
143 }
144 
145 
146 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
mappedPolyPatch.H
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
meshTools.H
Foam::GeometricField::GeometricBoundaryField::updateCoeffs
void updateCoeffs()
Update the boundary condition coefficients.
Definition: GeometricBoundaryField.C:447
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
mappedFixedValueFvPatchFields.H
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
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::GeometricField::boundaryField
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
Definition: GeometricField.C:735
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
addTimeOptions.H
OFstream.H
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::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::GeometricField::internalField
InternalField & internalField()
Return internal field.
Definition: GeometricField.C:724
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::fvPatch::Cf
const vectorField & Cf() const
Return face centres.
Definition: fvPatch.C:99
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
setRootCase.H
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:369
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
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
createMesh.H
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
createTime.H
main
int main(int argc, char *argv[])
Definition: Test-MappedPatch.C:47
Foam::OFstream::name
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Foam::fvPatchField::patch
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:300
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52