/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "refinementFeatures.H"
#include "Time.H"
#include "Tuple2.H"
#include "DynamicField.H"
#include "featureEdgeMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::refinementFeatures::read
(
const objectRegistry& io,
const PtrList& featDicts
)
{
forAll(featDicts, feati)
{
const dictionary& dict = featDicts[feati];
fileName featFileName(dict.lookup("file"));
// Try reading extendedEdgeMesh first
typeIOobject extFeatObj
(
featFileName, // name
io.time().constant(), // instance
"extendedFeatureEdgeMesh", // local
io.time(), // registry
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
const fileName fName(extFeatObj.filePath());
if (!fName.empty() && extendedEdgeMesh::canRead(fName))
{
autoPtr eMeshPtr = extendedEdgeMesh::New
(
fName
);
Info<< "Read extendedFeatureEdgeMesh " << extFeatObj.name()
<< nl << incrIndent;
eMeshPtr().writeStats(Info);
Info<< decrIndent << endl;
set(feati, new extendedFeatureEdgeMesh(extFeatObj, eMeshPtr()));
}
else
{
// Try reading edgeMesh
typeIOobject featObj
(
featFileName,
io.time().constant(),
searchableSurface::geometryDir(io.time()),
io.time(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
const fileName fName(featObj.filePath());
if (fName.empty())
{
FatalIOErrorInFunction
(
dict
) << "Could not open "
<< featObj.objectPath()
<< exit(FatalIOError);
}
// Read as edgeMesh
autoPtr eMeshPtr = edgeMesh::New(fName);
const edgeMesh& eMesh = eMeshPtr();
Info<< "Read edgeMesh " << featObj.name() << nl
<< incrIndent;
eMesh.writeStats(Info);
Info<< decrIndent << endl;
// Analyse for feature points. These are all classified as mixed
// points for lack of anything better
const labelListList& pointEdges = eMesh.pointEdges();
labelList oldToNew(eMesh.points().size(), -1);
DynamicField newPoints(eMesh.points().size());
forAll(pointEdges, pointi)
{
if (pointEdges[pointi].size() > 2)
{
oldToNew[pointi] = newPoints.size();
newPoints.append(eMesh.points()[pointi]);
}
// else if (pointEdges[pointi].size() == 2)
// MEJ: do something based on a feature angle?
}
label nFeatures = newPoints.size();
forAll(oldToNew, pointi)
{
if (oldToNew[pointi] == -1)
{
oldToNew[pointi] = newPoints.size();
newPoints.append(eMesh.points()[pointi]);
}
}
const edgeList& edges = eMesh.edges();
edgeList newEdges(edges.size());
forAll(edges, edgei)
{
const edge& e = edges[edgei];
newEdges[edgei] = edge
(
oldToNew[e[0]],
oldToNew[e[1]]
);
}
// Construct an extendedEdgeMesh with
// - all points on more than 2 edges : mixed feature points
// - all edges : external edges
extendedEdgeMesh eeMesh
(
newPoints, // pts
newEdges, // eds
0, // (point) concaveStart
0, // (point) mixedStart
nFeatures, // (point) nonFeatureStart
edges.size(), // (edge) internalStart
edges.size(), // (edge) flatStart
edges.size(), // (edge) openStart
edges.size(), // (edge) multipleStart
vectorField(0), // normals
List(0),// normalVolumeTypes
vectorField(0), // edgeDirections
labelListList(0), // normalDirections
labelListList(0), // edgeNormals
labelListList(0), // featurePointNormals
labelListList(0), // featurePointEdges
identityMap(newEdges.size()) // regionEdges
);
// Info<< "Constructed extendedFeatureEdgeMesh " << featObj.name()
// << nl << incrIndent;
// eeMesh.writeStats(Info);
// Info<< decrIndent << endl;
set(feati, new extendedFeatureEdgeMesh(featObj, eeMesh));
}
const extendedEdgeMesh& eMesh = operator[](feati);
if (dict.found("levels"))
{
List> distLevels(dict["levels"]);
if (dict.size() < 1)
{
FatalErrorInFunction
<< " : levels should be at least size 1" << endl
<< "levels : " << dict["levels"]
<< exit(FatalError);
}
distances_[feati].setSize(distLevels.size());
levels_[feati].setSize(distLevels.size());
forAll(distLevels, j)
{
distances_[feati][j] = distLevels[j].first();
levels_[feati][j] = distLevels[j].second();
// Check in incremental order
if (j > 0)
{
if
(
(distances_[feati][j] <= distances_[feati][j-1])
|| (levels_[feati][j] > levels_[feati][j-1])
)
{
FatalErrorInFunction
<< " : Refinement should be specified in order"
<< " of increasing distance"
<< " (and decreasing refinement level)." << endl
<< "Distance:" << distances_[feati][j]
<< " refinementLevel:" << levels_[feati][j]
<< exit(FatalError);
}
}
}
}
else
{
// Look up 'level' for single level
levels_[feati] = labelList(1, dict.lookup