/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "PDRblock.H"
#include "ListOps.H"
#include "gradingDescriptors.H"
#include "objectRegistry.H"
#include "Time.H"
#include "IOdictionary.H"
#include "Fstream.H"
#include "OTstream.H"
#include "edgeHashes.H"
#include "cellModel.H"
#include "blockMesh.H"
#include "polyMesh.H"
#include "searchableSphere.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Name for the projection geometry
static const word projKeyword("project");
// Name for the projection geometry
static const word projGeomName("sphere");
//- Calculate geometric ratio from relative ratio
inline scalar relativeToGeometricRatio
(
const scalar expRatio,
const label nDiv
)
{
return nDiv > 1 ? pow(expRatio, (nDiv - 1)) : 1.0;
}
// Output space-separated flat list. No size prefix.
template
static Ostream& outputFlatList(Ostream& os, const UList& list)
{
os << token::BEGIN_LIST;
label i = 0;
for (const label val : list)
{
if (i++) os << token::SPACE;
os << val;
}
os << token::END_LIST;
return os;
}
// Begin indent list
static inline Ostream& begIndentList(Ostream& os)
{
os << indent << incrIndent << token::BEGIN_LIST << nl;
return os;
}
// End indent list
static inline Ostream& endIndentList(Ostream& os)
{
os << decrIndent << indent << token::END_LIST;
return os;
}
// Output list contents (newline separated) indented.
template
static Ostream& outputIndent(Ostream& os, const UList& list)
{
for (const T& val : list)
{
os << indent << val << nl;
}
return os;
}
//
static Ostream& serializeHex
(
Ostream& os,
const labelUList& hexVerts,
const labelVector& hexCount,
const Vector hexGrade,
const word& zoneName = word::null
)
{
os << indent << cellModel::modelNames[cellModel::HEX] << token::SPACE;
outputFlatList(os, hexVerts);
if (!zoneName.empty())
{
os << token::SPACE << zoneName;
}
os << token::SPACE << hexCount << nl
<< indent << word("edgeGrading") << nl;
begIndentList(os);
// Grading (x/y/z)
for (const gradingDescriptors& gds : hexGrade)
{
begIndentList(os);
outputIndent(os, gds);
endIndentList(os) << nl;
}
endIndentList(os) << nl;
return os;
}
// Generate list with entries:
//
// project (x y z) (geometry)
//
static Ostream& serializeProjectPoints
(
Ostream& os,
const UList& list
)
{
for (const point& p : list)
{
os << indent << projKeyword << token::SPACE
<< p
<< token::SPACE
<< token::BEGIN_LIST << projGeomName << token::END_LIST << nl;
}
return os;
}
// Generate entry:
//
// project (beg end) (geometry)
//
static Ostream& serializeProjectEdge
(
Ostream& os,
const edge& e
)
{
os << indent << projKeyword << token::SPACE;
if (e.sorted())
{
os << e.first() << token::SPACE << e.second();
}
else
{
os << e.second() << token::SPACE << e.first();
}
os << token::SPACE
<< token::BEGIN_LIST << projGeomName << token::END_LIST << nl;
return os;
}
// Generate entry:
//
// (0 1 2 ..)
//
static Ostream& serializeFace
(
Ostream& os,
const face& list
)
{
os << indent;
outputFlatList(os, list);
os << nl;
return os;
}
// Generate entry:
//
// project (0 1 2 ..) geometry
//
static Ostream& serializeProjectFace
(
Ostream& os,
const face& list
)
{
os << indent << projKeyword << token::SPACE;
outputFlatList(os, list);
os << token::SPACE << projGeomName << nl;
return os;
}
} // namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::Ostream& Foam::PDRblock::blockMeshDict
(
Ostream& os,
const bool withHeader
) const
{
if (withHeader)
{
// Use dummy time for fake objectRegistry
autoPtr