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-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
28 #include "exactPatchDistMethod.H"
31 #include "volFields.H"
32 #include "DynamicField.H"
33 #include "OBJstream.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace patchDistMethods
40 {
41  defineTypeNameAndDebug(exact, 0);
42  addToRunTimeSelectionTable(patchDistMethod, exact, dictionary);
43 }
44 }
45 
47 Foam::patchDistMethods::exact::patchSurface() const
48 {
49  if (!patchSurfPtr_)
50  {
51  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
52 
53  Random rndGen(0);
54 
55  treeBoundBox localBb(mesh_.points());
56 
57  // Determine mesh bounding boxes:
58  List<treeBoundBox> meshBb
59  (
60  1,
61  localBb.extend(rndGen, 1E-3)
62  );
63 
64  // Add any missing properties (but not override existing ones)
65  dict_.add("bounds", meshBb);
66  dict_.add
67  (
68  "distributionType",
70  [
71  //distributedTriSurfaceMesh::FOLLOW // use mesh bb
72  //distributedTriSurfaceMesh::INDEPENDENT // master-only
74  ]
75  );
76  dict_.add("mergeDistance", 1e-6*localBb.mag());
77 
78  Info<< "Triangulating local patch faces" << nl << endl;
79 
80  labelList mapTriToGlobal;
81 
82  patchSurfPtr_.reset
83  (
84  new distributedTriSurfaceMesh
85  (
86  IOobject
87  (
88  "wallSurface.stl",
89  mesh_.time().constant(),// directory
90  "triSurface", // instance
91  mesh_.time(), // registry
94  ),
96  (
97  pbm,
98  patchIDs_,
99  mapTriToGlobal
100  ),
101  dict_
102  )
103  );
104 
105  // Do redistribution
106  Info<< "Redistributing surface" << nl << endl;
107  autoPtr<mapDistribute> faceMap;
108  autoPtr<mapDistribute> pointMap;
109  patchSurfPtr_().distribute
110  (
111  meshBb,
112  false, //keepNonMapped,
113  faceMap,
114  pointMap
115  );
116  faceMap.clear();
117  pointMap.clear();
118  }
119  return patchSurfPtr_();
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
125 Foam::patchDistMethods::exact::exact
126 (
127  const dictionary& dict,
128  const fvMesh& mesh,
129  const labelHashSet& patchIDs
130 )
131 :
133  dict_(dict.subOrEmptyDict(typeName + "Coeffs"))
134 {}
135 
136 
137 Foam::patchDistMethods::exact::exact
138 (
139  const fvMesh& mesh,
140  const labelHashSet& patchIDs
141 )
142 :
144 {}
145 
146 
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148 
150 {
151  return correct(y, volVectorField::null().constCast());
152 }
153 
154 
156 (
157  volScalarField& y,
159 )
160 {
161  const distributedTriSurfaceMesh& surf = patchSurface();
162 
163  List<pointIndexHit> info;
164  surf.findNearest
165  (
166  mesh_.cellCentres(),
167  scalarField(mesh_.nCells(), Foam::sqr(GREAT)),
168  info
169  );
170 
171  // Take over hits
172  // label nHits = 0;
173  forAll(info, celli)
174  {
175  if (info[celli].hit())
176  {
177  const point& cc = mesh_.cellCentres()[celli];
178  y[celli] = info[celli].point().dist(cc);
179  // ++nHits;
180  }
181  //else
182  //{
183  // // Miss. Do what? Not possible with GREAT hopefully ...
184  //}
185  }
186  y.correctBoundaryConditions();
187 
188  if (debug)
189  {
190  OBJstream str(mesh_.time().timePath()/"wallPoint.obj");
191  Info<< type() << ": dumping nearest wall point to "
192  << str.name() << endl;
193  forAll(mesh_.cellCentres(), celli)
194  {
195  const point& cc = mesh_.cellCentres()[celli];
196  str.writeLine(cc, info[celli].point());
197  }
198  }
199 
200 
201  // Only calculate n if the field is defined
202  if (notNull(n))
203  {
204  surf.getNormal(info, n.primitiveFieldRef());
205  n.correctBoundaryConditions();
206  }
207 
208  return true;
209 }
210 
211 
212 // ************************************************************************* //
static const Enum< distributionType > distributionTypeNames_
const labelList patchIDs(pbm.indices(polyPatchNames, true))
const polyBoundaryMesh & pbm
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
addToRunTimeSelectionTable(patchDistMethod, advectionDiffusion, dictionary)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
static triSurface triangulate(const polyBoundaryMesh &mBesh, const labelHashSet &includePatches, labelList &faceMap, const bool verbose=false)
Simple triangulation of (selected patches of) boundaryMesh. Needs.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Random rndGen
Definition: createFields.H:23
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
Ignore writing from objectRegistry::writeObject()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
Macros for easy insertion into run-time selection tables.
const fvMesh & mesh_
Reference to the mesh.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1063
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:801
scalar y
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
IOoject and searching on distributed triSurface. All processor hold (possibly overlapping) part of th...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
int debug
Static debugging option.
virtual void findNearest(const pointField &sample, const scalarField &nearestDistSqr, List< pointIndexHit > &) const
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil) - psi) *pSat, rhoMin);# 1 "/home/chef2/andy/OpenFOAM/release/v2506/OpenFOAM-v2506/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{});alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:63
static const this_type & null() noexcept
Return a null GeometricField (reference to a nullObject).
vector point
Point is a vector.
Definition: point.H:37
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:267
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
defineTypeNameAndDebug(advectionDiffusion, 0)
virtual bool correct(volScalarField &y)
Correct the given distance-to-patch field.
Nothing to be read.
const labelHashSet patchIDs_
Set of patch IDs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
List< label > labelList
A List of labels.
Definition: List.H:61
Specialisation of patchDist for wall distance calculation.
List< treeBoundBox > meshBb(1, treeBoundBox(coarseMesh.points()).extend(rndGen, 1e-3))
Namespace for OpenFOAM.