Commit 35307112 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Refactored the dummyFvMesh code

parent a3228f86
Info<< "Constructing single cell mesh" << nl << endl;
autoPtr<fvMesh> meshPtr = dummyFvMesh::singleCellMesh(runTime);
fvMesh& mesh = meshPtr();
Foam::proxyMeshes::hexCellFvMesh mesh(runTime);
......@@ -9,7 +9,7 @@ if (args.optionFound("dry-run") || args.optionFound("dry-run-write"))
Foam::FieldBase::allowConstructFromLargerSize = true;
// Create a simplified 1D mesh and attempt to re-create boundary conditions
meshPtr.reset(Foam::dummyFvMesh::equivalent1DMesh(runTime));
meshPtr.reset(new Foam::proxyMeshes::columnFvMesh(runTime));
// Stopping after 1 iteration of the simplified mesh
// Note: using saNoWriteNow will only trigger the function object execute
......
......@@ -3,7 +3,9 @@ fvMesh/fvMesh.C
fvMesh/singleCellFvMesh/singleCellFvMesh.C
fvMesh/dummyFvMesh/dummyFvMesh.C
fvMesh/proxyFvMesh/proxyFvMesh.C
fvMesh/proxyFvMesh/columnFvMesh.C
fvMesh/proxyFvMesh/hexCellFvMesh.C
fvBoundaryMesh = fvMesh/fvBoundaryMesh
$(fvBoundaryMesh)/fvBoundaryMesh.C
......
......@@ -21,7 +21,10 @@
#include "findRefCell.H"
#include "IOMRFZoneList.H"
#include "constants.H"
#include "dummyFvMesh.H"
#include "proxyFvMesh.H"
#include "columnFvMesh.H"
#include "hexCellFvMesh.H"
#include "OSspecific.H"
#include "argList.H"
......
......@@ -23,122 +23,45 @@ License
\*---------------------------------------------------------------------------*/
#include "dummyFvMesh.H"
#include "Time.H"
#include "columnFvMesh.H"
#include "polyBoundaryMeshEntries.H"
#include "IOobjectList.H"
#include "fieldDictionary.H"
#include "topoSet.H"
#include "calculatedFvPatchField.H"
#include "vectorIOField.H"
#include "emptyPolyPatch.H"
#include "processorPolyPatch.H"
#include "processorCyclicPolyPatch.H"
#include "cyclicPolyPatch.H"
#include "cyclicAMIPolyPatch.H"
#include "cyclicACMIPolyPatch.H"
#include "fvPatchField.H"
#include "pointPatchField.H"
#include "topoSet.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(dummyFvMesh, 0);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::dummyFvMesh::fvPatchFieldExists(const word& patchType)
namespace proxyMeshes
{
if
(
fvPatchField<scalar>::dictionaryConstructorTablePtr_->found(patchType)
|| fvPatchField<vector>::dictionaryConstructorTablePtr_->found(patchType)
|| fvPatchField<sphericalTensor>::
dictionaryConstructorTablePtr_->found(patchType)
|| fvPatchField<symmTensor>::
dictionaryConstructorTablePtr_->found(patchType)
|| fvPatchField<tensor>::dictionaryConstructorTablePtr_->found(patchType)
)
{
return true;
}
return false;
}
defineTypeNameAndDebug(columnFvMeshInfo, 0);
defineTypeNameAndDebug(columnFvMesh, 0);
Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::singleCellMesh
(
const Time& runTime,
const scalar d
)
{
pointField points(8);
points[0] = vector(0, 0, 0);
points[1] = vector(d, 0, 0);
points[2] = vector(d, d, 0);
points[3] = vector(0, d, 0);
points[4] = vector(0, 0, d);
points[5] = vector(d, 0, d);
points[6] = vector(d, d, d);
points[7] = vector(0, d, d);
faceList faces = cellModel::ref(cellModel::HEX).modelFaces();
autoPtr<fvMesh> meshPtr
addToRunTimeSelectionTable
(
new Foam::fvMesh
(
IOobject
(
polyMesh::defaultRegion,
runTime.timeName(),
runTime,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
std::move(points),
std::move(faces),
labelList(6, Zero),
labelList()
)
proxyFvMesh,
columnFvMesh,
time
);
fvMesh& mesh = meshPtr();
List<polyPatch*> patches(1);
patches[0] = new emptyPolyPatch
(
"boundary",
6,
0,
0,
mesh.boundaryMesh(),
emptyPolyPatch::typeName
);
mesh.addFvPatches(patches);
return meshPtr;
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::dummyFvMesh::setPatchEntries
bool Foam::proxyMeshes::columnFvMeshInfo::setPatchEntries
(
const Time& runTime,
const word& instance,
dictionary& patchEntries,
label& nPatchWithFace
const Time& runTime
)
{
IOobject boundaryIO
(
"boundary",
instance,
localInstance_,
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
......@@ -152,7 +75,7 @@ bool Foam::dummyFvMesh::setPatchEntries
{
polyBoundaryMeshEntries allPatchEntries(boundaryIO);
Info<< "Creating dummy mesh using " << allPatchEntries.path() << endl;
Info<< "Creating proxy mesh using " << allPatchEntries.path() << endl;
for (const entry& e : allPatchEntries)
{
......@@ -162,9 +85,9 @@ bool Foam::dummyFvMesh::setPatchEntries
{
if (readLabel(e.dict().lookup("nFaces")))
{
++nPatchWithFace;
++nPatchWithFace_;
}
patchEntries.add(e.keyword(), e.dict());
patchEntries_.add(e.keyword(), e.dict());
}
}
......@@ -192,7 +115,7 @@ bool Foam::dummyFvMesh::setPatchEntries
const fieldDictionary fieldDict(io, io.headerClassName());
Info<< "Creating dummy mesh from field "
Info<< "Creating proxy mesh from field "
<< fieldDict.objectPath()
<< endl;
......@@ -203,17 +126,17 @@ bool Foam::dummyFvMesh::setPatchEntries
{
const word type(e.dict().lookup("type"));
if (fvPatchFieldExists(type))
if (proxyFvMesh::fvPatchFieldExists(type))
{
if (!constraintPatches.found(type))
{
++nPatchWithFace;
dictionary dummyEntries;
dummyEntries.add("startFace", 0);
dummyEntries.add("nFaces", 1);
dummyEntries.add("type", "wall"); // default to wall type
++nPatchWithFace_;
dictionary proxyEntries;
proxyEntries.add("startFace", 0);
proxyEntries.add("nFaces", 1);
proxyEntries.add("type", "wall"); // default to wall type
patchEntries.add(e.keyword(), dummyEntries);
patchEntries_.add(e.keyword(), proxyEntries);
}
}
else
......@@ -227,28 +150,14 @@ bool Foam::dummyFvMesh::setPatchEntries
}
Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
(
const Time& runTime
)
void Foam::proxyMeshes::columnFvMeshInfo::initialise(const Time& runTime)
{
DebugInfo << "Constructing 1-D mesh" << nl << endl;
const word instance =
runTime.findInstance
(
polyMesh::meshSubDir,
"boundary",
IOobject::READ_IF_PRESENT
);
// Read patches - filter out proc patches for parallel runs
dictionary patchEntries;
label nPatchWithFace = 0;
bool createFromMesh =
setPatchEntries(runTime, instance, patchEntries, nPatchWithFace);
createFromMesh_ = setPatchEntries(runTime);
const label nPatch = patchEntries.size();
const label nPatch = patchEntries_.size();
DebugPout << "Read " << nPatch << " patches" << endl;
......@@ -272,11 +181,11 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
// - rotational cyclic - convert to separated and warn not handled?
// - proc patches - faces need to be collocated?
pointField points(nPatchWithFace*4 + 4);
faceList faces(nPatchWithFace*5 + 1);
points1D_.setSize(nPatchWithFace_*4 + 4);
faces1D_.setSize(nPatchWithFace_*5 + 1);
labelList owner(faces.size(), label(-1));
labelList neighbour(owner);
owner1D_.setSize(faces1D_.size(), label(-1));
neighbour1D_.setSize(owner1D_.size(), label(-1));
vector dx(Zero);
{
......@@ -284,7 +193,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
IOobject pointsIO
(
"points",
instance,
localInstance_,
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
......@@ -307,7 +216,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
origin = meshBb.min();
vector span = meshBb.span();
dxi = span.x()/scalar(nPatchWithFace);
dxi = span.x()/scalar(nPatchWithFace_);
dyi = span.y();
dzi = span.z();
}
......@@ -315,7 +224,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
{
scalar Lref = GREAT;
origin = point(-Lref, -Lref, -Lref);
dxi = 2.0*Lref/scalar(nPatchWithFace);
dxi = 2.0*Lref/scalar(nPatchWithFace_);
dyi = Lref;
dzi = Lref;
}
......@@ -325,109 +234,139 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
const vector dz(0, 0, dzi);
// End face
points[0] = origin;
points[1] = origin + dy;
points[2] = origin + dy + dz;
points[3] = origin + dz;
points1D_[0] = origin;
points1D_[1] = origin + dy;
points1D_[2] = origin + dy + dz;
points1D_[3] = origin + dz;
}
label n = 4;
for (label i = 1; i <= nPatchWithFace; ++i)
for (label i = 1; i <= nPatchWithFace_; ++i)
{
const vector idx(i*dx);
points[i*n] = points[0] + idx;
points[i*n + 1] = points[1] + idx;
points[i*n + 2] = points[2] + idx;
points[i*n + 3] = points[3] + idx;
points1D_[i*n] = points1D_[0] + idx;
points1D_[i*n + 1] = points1D_[1] + idx;
points1D_[i*n + 2] = points1D_[2] + idx;
points1D_[i*n + 3] = points1D_[3] + idx;
}
if (debug) Pout<< "points:" << points << endl;
if (debug) Pout<< "points:" << points1D_ << endl;
label facei = 0;
// Internal faces first
for (label i = 0; i < nPatchWithFace - 1; ++i)
for (label i = 0; i < nPatchWithFace_ - 1; ++i)
{
label o = i*4;
faces[facei] = face({4 + o, 5 + o, 6 + o, 7 + o});
owner[facei] = i;
neighbour[facei] = i + 1;
faces1D_[facei] = face({4 + o, 5 + o, 6 + o, 7 + o});
owner1D_[facei] = i;
neighbour1D_[facei] = i + 1;
++facei;
}
// Boundary conditions
for (label i = 0; i < nPatchWithFace; ++i)
for (label i = 0; i < nPatchWithFace_; ++i)
{
label o = i*4;
faces[facei] = face({0 + o, 4 + o, 7 + o, 3 + o});
owner[facei] = i;
faces1D_[facei] = face({0 + o, 4 + o, 7 + o, 3 + o});
owner1D_[facei] = i;
++facei;
faces[facei] = face({0 + o, 1 + o, 5 + o, 4 + o});
owner[facei] = i;
faces1D_[facei] = face({0 + o, 1 + o, 5 + o, 4 + o});
owner1D_[facei] = i;
++facei;
faces[facei] = face({1 + o, 2 + o, 6 + o, 5 + o});
owner[facei] = i;
faces1D_[facei] = face({1 + o, 2 + o, 6 + o, 5 + o});
owner1D_[facei] = i;
++facei;
faces[facei] = face({3 + o, 7 + o, 6 + o, 2 + o});
owner[facei] = i;
faces1D_[facei] = face({3 + o, 7 + o, 6 + o, 2 + o});
owner1D_[facei] = i;
++facei;
}
{
// End caps
faces[facei] = face({0, 3, 2, 1});
owner[facei] = 0;
faces1D_[facei] = face({0, 3, 2, 1});
owner1D_[facei] = 0;
++facei;
label o = 4*nPatchWithFace;
faces[facei] = face({0 + o, 1 + o, 2 + o, 3 + o});
owner[facei] = nPatchWithFace - 1;
label o = 4*nPatchWithFace_;
faces1D_[facei] = face({0 + o, 1 + o, 2 + o, 3 + o});
owner1D_[facei] = nPatchWithFace_ - 1;
++facei;
}
DebugPout
<< "faces:" << faces << nl
<< "owner:" << owner << nl
<< "neighbour:" << neighbour
<< "faces:" << faces1D_ << nl
<< "owner:" << owner1D_ << nl
<< "neighbour:" << neighbour1D_
<< endl;
}
autoPtr<fvMesh> meshPtr
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::proxyMeshes::columnFvMeshInfo::columnFvMeshInfo(const Time& runTime)
:
localInstance_
(
new Foam::fvMesh
runTime.findInstance
(
IOobject
(
fvMesh::defaultRegion,
runTime.constant(),
runTime,
IOobject::NO_READ, // Do not read any existing mesh
IOobject::NO_WRITE
),
std::move(points),
std::move(faces),
std::move(owner),
std::move(neighbour)
polyMesh::meshSubDir,
"boundary",
IOobject::READ_IF_PRESENT
)
);
),
createFromMesh_(false),
points1D_(),
faces1D_(),
owner1D_(),
neighbour1D_(),
patchEntries_(),
nPatchWithFace_(0)
{
initialise(runTime);
}
Foam::fvMesh& mesh = meshPtr();
// Workaround to read fvSchemes and fvSolution
Foam::proxyMeshes::columnFvMesh::columnFvMesh(const Time& runTime)
:
columnFvMeshInfo(runTime),
proxyFvMesh
(
IOobject
(
fvMesh::defaultRegion,
runTime.constant(),
runTime,
IOobject::NO_READ, // Do not read any existing mesh
IOobject::NO_WRITE
),
std::move(points1D_),
std::move(faces1D_),
std::move(owner1D_),
std::move(neighbour1D_)
)
{
// Workaround to read fvSchemes and fvSolution after setting NO_READ
// when creating the mesh
{
mesh.fvSchemes::readOpt() = IOobject::MUST_READ;
mesh.fvSchemes::read();
mesh.fvSolution::readOpt() = IOobject::MUST_READ;
mesh.fvSolution::read();
fvSchemes::readOpt() = IOobject::MUST_READ;
fvSchemes::read();
fvSolution::readOpt() = IOobject::MUST_READ;
fvSolution::read();
}
// Add the patches
const label nPatch = patchEntries_.size();
List<polyPatch*> patches(nPatch + 1);
label nInternalFace = nPatchWithFace - 1;
label nInternalFace = nPatchWithFace_ - 1;
label startFace = nInternalFace;
label entryi = 0;
for (const entry& e : patchEntries)
for (const entry& e : patchEntries_)
{
// Re-create boundary types, but reset nFaces and startFace settings
dictionary patchDict = e.dict();
......@@ -451,7 +390,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
patchName,
patchDict,
entryi,
mesh.boundaryMesh()
boundaryMesh()
).ptr();
++entryi;
......@@ -462,13 +401,13 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
(
typeName + ":default", // name
2, // number of faces
nInternalFace + 4*nPatchWithFace, // start face
nInternalFace + 4*nPatchWithFace_, // start face
nPatch - 1, // index in boundary list
mesh.boundaryMesh(), // polyBoundaryMesh
boundaryMesh(), // polyBoundaryMesh
emptyPolyPatch::typeName // patchType
);
mesh.addFvPatches(patches);
addFvPatches(patches);
if (debug)
{
......@@ -480,12 +419,14 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
}
}
if (createFromMesh)
// Add the zones
if (createFromMesh_)
{
// Initialise the zones
initialiseZone<pointZoneMesh>("point", instance, mesh.pointZones());
initialiseZone<faceZoneMesh>("face", instance, mesh.faceZones());
initialiseZone<cellZoneMesh>("cell", instance, mesh.cellZones());
initialiseZone<pointZoneMesh>("point", localInstance_, pointZones());
initialiseZone<faceZoneMesh>("face", localInstance_, faceZones());
initialiseZone<cellZoneMesh>("cell", localInstance_, cellZones());
// Dummy sets created on demand
topoSet::disallowGenericSets = 1;
......@@ -499,11 +440,9 @@ Foam::autoPtr<Foam::fvMesh> Foam::dummyFvMesh::equivalent1DMesh
if (debug)
{
mesh.setInstance(runTime.timeName());
mesh.objectRegistry::write();
setInstance(runTime.timeName());
objectRegistry::write();
}
return meshPtr;
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ 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 <http://www.gnu.org/licenses/>.
Class
Foam::proxyMeshes::columnFvMesh
Description
Generates a 1D column representation of a mesh based on an existing mesh
and/or fields
SourceFiles
columnFvMesh.C
\*---------------------------------------------------------------------------*/
#ifndef proxyMeshes_columnFvMesh_H
#define proxyMeshes_columnFvMesh_H
#include "proxyFvMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace proxyMeshes