52 Foam::refinementRegions::refineModeNames_;
57 void Foam::refinementRegions::setAndCheckLevels
60 const dictionary&
dict
63 const searchableSurface& shell = allGeometry_[shells_[shelli]];
71 if (!allGeometry_[shells_[shelli]].hasVolumeType())
74 <<
"Shell " << shell.name()
75 <<
" is not closed so testing for '"
76 << refineModeNames_[modes_[shelli]]
77 <<
"' may fail." <<
endl;
83 if (
dict.found(
"levels") && !(
dict.found(
"level")))
86 const List<Tuple2<scalar, label>> distLevels(
dict.lookup(
"levels"));
88 if (distLevels.size() != 1)
91 <<
"For refinement mode "
92 << refineModeNames_[modes_[shelli]]
93 <<
" specify only one distance+level."
94 <<
" (its distance gets discarded)"
98 levels_[shelli][0] = distLevels[0].second();
102 if (
dict.found(
"levels"))
105 <<
"Found both 'level' and 'levels' entries, using 'level'."
114 Info<<
"Refinement level " << levels_[shelli][0]
115 <<
" for all cells inside " << shell.name() <<
endl;
119 Info<<
"Refinement level " << levels_[shelli][0]
120 <<
" for all cells outside " << shell.name() <<
endl;
129 if (!allGeometry_[shells_[shelli]].hasVolumeType())
132 <<
"Shell " << shell.name()
133 <<
" is not closed so testing for '"
134 << refineModeNames_[modes_[shelli]]
135 <<
"' may fail." <<
endl;
140 const Tuple2<scalar, label> distLevel(
dict.lookup(
"level"));
141 distances_[shelli][0] = distLevel.
first();
142 levels_[shelli][0] = distLevel.second();
146 Info<<
"Refinement level " << levels_[shelli][0]
147 <<
" for all cells inside " << shell.name()
148 <<
" within distance " << distances_[shelli][0] <<
endl;
152 Info<<
"Refinement level " << levels_[shelli][0]
153 <<
" for all cells outside " << shell.name()
154 <<
" within distance " << distances_[shelli][0] <<
endl;
159 const List<Tuple2<scalar, label>> distLevels(
dict.lookup(
"levels"));
162 distances_[shelli].
setSize(distLevels.size());
163 levels_[shelli].
setSize(distLevels.size());
167 distances_[shelli][j] = distLevels[j].
first();
168 levels_[shelli][j] = distLevels[j].second();
175 (distances_[shelli][j] <= distances_[shelli][j-1])
176 || (levels_[shelli][j] > levels_[shelli][j-1])
180 <<
"For refinement mode "
181 << refineModeNames_[modes_[shelli]]
182 <<
" : Refinement should be specified in order"
183 <<
" of increasing distance"
184 <<
" (and decreasing refinement level)." <<
endl
185 <<
"Distance:" << distances_[shelli][j]
186 <<
" refinementLevel:" << levels_[shelli][j]
194 Info<<
"Refinement level according to distance to "
195 << shell.name() <<
endl;
197 forAll(levels_[shelli], j)
199 Info<<
" level " << levels_[shelli][j]
200 <<
" for all cells within " << distances_[shelli][j]
201 <<
" metre." <<
endl;
208 void Foam::refinementRegions::orient()
213 bool hasSurface =
false;
217 const searchableSurface&
s = allGeometry_[shells_[shelli]];
219 if (modes_[shelli] != refineMode::distance && isA<triSurfaceMesh>(
s))
221 const triSurfaceMesh& shell = refCast<const triSurfaceMesh>(
s);
223 if (shell.triSurface::size())
225 tmp<pointField> tpoints(shell.points());
235 shellBb.min() =
min(shellBb.min(), pt);
236 shellBb.max() =
max(shellBb.max(), pt);
239 overallBb.min() =
min(overallBb.min(), shellBb.min());
240 overallBb.max() =
max(overallBb.max(), shellBb.max());
247 const point outsidePt = overallBb.
max() + overallBb.span();
253 const searchableSurface&
s = allGeometry_[shells_[shelli]];
257 modes_[shelli] != refineMode::distance
258 && isA<triSurfaceMesh>(
s)
261 triSurfaceMesh& shell =
const_cast<triSurfaceMesh&
>
263 refCast<const triSurfaceMesh>(
s)
283 Info<<
"refinementRegions : Flipped orientation of surface "
285 <<
" so point " << outsidePt <<
" is outside." <<
endl;
293 Foam::scalar Foam::refinementRegions::interpolate
295 const triSurfaceMesh& tsm,
306 tsm.triSurface::operator[](index)
307 ).pointToBarycentric(pt)
310 const labelledTri& lf = tsm.localFaces()[index];
312 return closeness[lf[0]]*bary[0]
313 + closeness[lf[1]]*bary[1]
314 + closeness[lf[2]]*bary[2];
318 void Foam::refinementRegions::findHigherLevel
322 const scalar level0EdgeLength,
326 const labelList& levels = levels_[shelli];
328 if (modes_[shelli] == refineMode::distance)
341 label candidatei = 0;
347 if (levels[leveli] > maxLevel[pointi])
349 candidates[candidatei] = pt[pointi];
350 candidateMap[candidatei] = pointi;
351 candidateDistSqr[candidatei] =
sqr(distances[leveli]);
357 candidates.setSize(candidatei);
358 candidateMap.setSize(candidatei);
359 candidateDistSqr.setSize(candidatei);
363 allGeometry_[shells_[shelli]].findNearest
379 mag(
nearInfo[candidatei].hitPoint()-candidates[candidatei])
382 label pointi = candidateMap[candidatei];
385 maxLevel[pointi] = levels[minDistI+1];
391 modes_[shelli] == refineMode::insideSpan
392 || modes_[shelli] == refineMode::outsideSpan
395 const triSurfaceMesh& tsm =
396 refCast<const triSurfaceMesh>(allGeometry_[shells_[shelli]]);
404 label candidatei = 0;
408 if (levels[0] > maxLevel[pointi])
410 candidates[candidatei] = pt[pointi];
411 candidateMap[candidatei] = pointi;
412 candidateDistSqr[candidatei] =
sqr(distances_[shelli][0]);
416 candidates.setSize(candidatei);
417 candidateMap.setSize(candidatei);
418 candidateDistSqr.setSize(candidatei);
432 cellsAcrossSpan_[shelli]*level0EdgeLength/(1 << (levels[0] - 1))
455 log2(cellsAcrossSpan_[shelli]*level0EdgeLength/span) + 1
458 maxLevel[candidateMap[candidatei]] =
min(levels[0], level);
462 maxLevel[candidateMap[candidatei]] = levels[0];
476 label candidatei = 0;
480 if (levels[0] > maxLevel[pointi])
482 candidates[candidatei] = pt[pointi];
483 candidateMap[candidatei] = pointi;
487 candidates.setSize(candidatei);
488 candidateMap.setSize(candidatei);
491 List<volumeType> volType;
492 allGeometry_[shells_[shelli]].getVolumeType(candidates, volType);
496 label pointi = candidateMap[i];
501 modes_[shelli] == refineMode::inside
505 modes_[shelli] == refineMode::outside
510 maxLevel[pointi] = levels[0];
525 allGeometry_(allGeometry)
533 const word& geomName = allGeometry_.
names()[geomi];
535 if (shellsDict.
found(geomName))
546 cellsAcrossSpan_.
setSize(shelli);
547 closeness_.setSize(shelli);
554 const word& geomName = allGeometry_.
names()[geomi];
563 shells_[shelli] = geomi;
564 modes_[shelli] = refineModeNames_.
read(
dict.lookup(
"mode"));
567 setAndCheckLevels(shelli,
dict);
577 if (isA<triSurfaceMesh>(surface))
579 dict.lookup(
"cellsAcrossSpan") >> cellsAcrossSpan_[shelli];
582 refCast<const triSurfaceMesh>(surface);
599 surface.searchableSurface::time().constant(),
602 surface.searchableSurface::time()
604 surface.searchableSurface::time(),
616 <<
"Surface " << surface.
name()
617 <<
" is not a triSurface as required by"
629 if (unmatchedKeys.
size() > 0)
634 ) <<
"Not all entries in refinementRegions dictionary were used."
635 <<
" The following entries were not used : "
651 label overallMax = 0;
655 overallMax =
max(overallMax,
max(levels_[shelli]));
662 void Foam::refinementRegions::findHigherLevel
666 const scalar level0EdgeLength,
675 findHigherLevel(pt, shelli, level0EdgeLength, maxLevel);
#define forAll(list, i)
Loop across all elements in list.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A HashTable with keys but without contents.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
label size() const
Return number of elements in table.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const word & name() const
Return name.
void setSize(const label)
Reset size of List.
Initialise the NamedEnum HashTable from the static list of names.
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
T & first()
Return the first element of the list.
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- vGreat.
A list of keyword definitions, which are a keyword followed by any number of values (e....
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
wordList toc() const
Return the table of contents.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
A keyword and a list of tokens is an 'entry'.
const keyType & keyword() const
Return keyword.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
label maxLevel() const
Highest shell level.
refinementRegions(const searchableSurfaces &allGeometry, const dictionary &shellsDict)
Construct from geometry and dictionary.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
static const word & geometryDir()
Return the geometry directory name.
Container for searchableSurfaces.
const wordList & names() const
A surface geometry formed of discrete facets, e.g. triangles and/or quadrilaterals,...
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Tuple2< scalar, label > nearInfo
Private class for finding nearest.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
label log2(label i)
Return the log base 2 by successive bit-shifting of the given 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.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
const dimensionSet dimLength
Foam::DimensionedField< scalar, triSurfacePointGeoMesh > triSurfacePointScalarField
vectorField pointField
pointField is a vectorField.
Barycentric2D< scalar > barycentric2D
A scalar version of the templated Barycentric2D.
vector point
Point is a vector.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
triangle< point, const point & > triPointRef
label readLabel(Istream &is)