exactPatchDistMethod.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) 2018-2020 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
31#include "volFields.H"
32#include "DynamicField.H"
33#include "OBJstream.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace patchDistMethods
40{
43}
44}
45
47Foam::patchDistMethods::exact::patchSurface() const
48{
49 if (!patchSurfPtr_)
50 {
51 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
52
53 Random rndGen(0);
54
55 boundBox localBb(mesh_.points(), false);
56
57 // Determine mesh bounding boxes:
58 List<treeBoundBox> meshBb
59 (
60 1,
61 treeBoundBox(localBb).extend(rndGen, 1E-3)
62 );
63
64 // Dummy bounds dictionary
65 dictionary dict;
66 dict.add("bounds", meshBb);
67 dict.add
68 (
69 "distributionType",
71 [
72 //distributedTriSurfaceMesh::FOLLOW // use mesh bb
73 //distributedTriSurfaceMesh::INDEPENDENT // master-only
75 ]
76 );
77 dict.add("mergeDistance", 1e-6*localBb.mag());
78
79
80 Info<< "Triangulating local patch faces" << nl << endl;
81
82 labelList mapTriToGlobal;
83
84 patchSurfPtr_.reset
85 (
86 new distributedTriSurfaceMesh
87 (
88 IOobject
89 (
90 "wallSurface.stl",
91 mesh_.time().constant(),// directory
92 "triSurface", // instance
93 mesh_.time(), // registry
96 ),
98 (
99 pbm,
100 patchIDs_,
101 mapTriToGlobal
102 ),
103 dict
104 )
105 );
106
107 // Do redistribution
108 Info<< "Redistributing surface" << nl << endl;
109 autoPtr<mapDistribute> faceMap;
110 autoPtr<mapDistribute> pointMap;
111 patchSurfPtr_().distribute
112 (
113 meshBb,
114 false, //keepNonMapped,
115 faceMap,
116 pointMap
117 );
118 faceMap.clear();
119 pointMap.clear();
120 }
121 return patchSurfPtr_();
122}
123
124
125// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126
128(
129 const dictionary& dict,
130 const fvMesh& mesh,
131 const labelHashSet& patchIDs
132)
133:
134 patchDistMethod(mesh, patchIDs)
135{}
136
137
139(
140 const fvMesh& mesh,
141 const labelHashSet& patchIDs
142)
143:
144 patchDistMethod(mesh, patchIDs)
145{}
146
147
148// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
149
151{
152 return correct(y, const_cast<volVectorField&>(volVectorField::null()));
153}
154
155
157(
160)
161{
162 const distributedTriSurfaceMesh& surf = patchSurface();
163
165 surf.findNearest
166 (
167 mesh_.cellCentres(),
168 scalarField(mesh_.nCells(), Foam::sqr(GREAT)),
169 info
170 );
171
172 // Take over hits
173 label nHits = 0;
174 forAll(info, cellI)
175 {
176 if (info[cellI].hit())
177 {
178 const point& cc = mesh_.cellCentres()[cellI];
179 y[cellI] = mag(cc-info[cellI].hitPoint());
180 nHits++;
181 }
182 //else
183 //{
184 // // Miss. Do what? Not possible with GREAT hopefully ...
185 //}
186 }
187 y.correctBoundaryConditions();
188
189 if (debug)
190 {
191 OBJstream str(mesh_.time().timePath()/"wallPoint.obj");
192 Info<< type() << ": dumping nearest wall point to " << str.name()
193 << endl;
194 forAll(mesh_.cellCentres(), cellI)
195 {
196 const point& cc = mesh_.cellCentres()[cellI];
197 str.write(linePointRef(cc, info[cellI].hitPoint()));
198 }
199 }
200
201
202 // Only calculate n if the field is defined
203 if (notNull(n))
204 {
205 surf.getNormal(info, n.primitiveFieldRef());
206 n.correctBoundaryConditions();
207 }
208
209 return true;
210}
211
212
213// ************************************************************************* //
scalar y
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
virtual label triangulate()
Triangulate in-place, returning the number of triangles added.
OFstream that keeps track of vertices.
Definition: OBJstream.H:61
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
virtual void correct()
Solve the turbulence equations and correct the turbulence viscosity.
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
IOoject and searching on distributed triSurface. All processor hold (possibly overlapping) part of th...
static const Enum< distributionType > distributionTypeNames_
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
Specialisation of patchDist for wall distance calculation.
const fvMesh & mesh_
Reference to the mesh.
const labelHashSet patchIDs_
Set of patch IDs.
Calculation of exact distance to nearest patch for all cells and boundary by constructing a search tr...
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
thermo correct()
dynamicFvMesh & mesh
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< label > labelList
A List of labels.
Definition: List.H:66
dimensionedSymmTensor sqr(const dimensionedVector &dv)
line< point, const point & > linePointRef
A line using referred points.
Definition: linePointRef.H:47
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:207
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(rndGen, 1e-3))
dictionary dict
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Random rndGen
Definition: createFields.H:23