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

STYLE: Code refactoring

parent 73fcd854
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -188,29 +188,22 @@ bool Foam::functionObjects::wallShearStress::read(const dictionary& dict)
bool Foam::functionObjects::wallShearStress::execute()
{
typedef compressible::turbulenceModel cmpModel;
typedef incompressible::turbulenceModel icoModel;
volVectorField& wallShearStress =
const_cast<volVectorField&>
(
mesh_.lookupObject<volVectorField>(type())
);
mesh_.lookupObjectRef<volVectorField>(type());
tmp<volSymmTensorField> Reff;
if (mesh_.foundObject<cmpModel>(turbulenceModel::propertiesName))
{
const cmpModel& model =
mesh_.lookupObject<cmpModel>(turbulenceModel::propertiesName);
const word& turbModelName = turbulenceModel::propertiesName;
auto cmpModelPtr =
mesh_.lookupObjectPtr<compressible::turbulenceModel>(turbModelName);
auto icoModelPtr =
mesh_.lookupObjectPtr<incompressible::turbulenceModel>(turbModelName);
Reff = model.devRhoReff();
if (cmpModelPtr)
{
calcShearStress(cmpModelPtr->devRhoReff(), wallShearStress);
}
else if (mesh_.foundObject<icoModel>(turbulenceModel::propertiesName))
else if (icoModelPtr)
{
const icoModel& model =
mesh_.lookupObject<icoModel>(turbulenceModel::propertiesName);
Reff = model.devReff();
calcShearStress(icoModelPtr->devReff(), wallShearStress);
}
else
{
......@@ -219,8 +212,6 @@ bool Foam::functionObjects::wallShearStress::execute()
<< "database" << exit(FatalError);
}
calcShearStress(Reff(), wallShearStress);
return true;
}
......
......@@ -73,15 +73,15 @@ const Foam::basicThermo& Foam::fv::tabulatedNTUHeatTransfer::thermo
const fvMesh& mesh
) const
{
if (!mesh.foundObject<basicThermo>("thermophysicalProperties"))
if (!mesh.foundObject<basicThermo>(basicThermo::dictName))
{
FatalErrorInFunction
<< " on mesh " << mesh.name()
<< " could not find thermophysicalProperties "
<< " could not find " << basicThermo::dictName
<< exit(FatalError);
}
return mesh.lookupObject<basicThermo>("thermophysicalProperties");
return mesh.lookupObject<basicThermo>(basicThermo::dictName);
}
......
......@@ -43,29 +43,26 @@ void Foam::AABBTree<Type>::writeOBJ
) const
{
const pointField pts(bb.points());
forAll(pts, i)
for (const point& pt : pts)
{
meshTools::writeOBJ(os, pts[i]);
meshTools::writeOBJ(os, pt);
}
if (writeLinesOnly)
{
forAll(bb.edges, i)
for (const edge& e : bb.edges)
{
const edge& e = bb.edges[i];
os << "l " << e[0] + vertI + 1 << ' ' << e[1] + vertI + 1 << nl;
}
}
else
{
forAll(bb.faces, i)
for (const face& f : bb.faces)
{
const face& f = bb.faces[i];
os << 'f';
forAll(f, fp)
for (const label fpi : f)
{
os << ' ' << f[fp] + vertI + 1;
os << ' ' << fpi + vertI + 1;
}
os << nl;
}
......@@ -144,7 +141,7 @@ void Foam::AABBTree<Type>::createBoxes
direction maxDir = 0;
scalar maxSpan = span[maxDir];
for (label dirI = 1; dirI < 3; dirI++)
for (label dirI = 1; dirI < 3; ++dirI)
{
if (span[dirI] > maxSpan)
{
......@@ -163,14 +160,12 @@ void Foam::AABBTree<Type>::createBoxes
PackedBoolList isUsedPoint(points.size());
DynamicList<scalar> component(points.size());
forAll(objectIDs, i)
for (const label objI : objectIDs)
{
const label objI = objectIDs[i];
const Type& obj = objects[objI];
forAll(obj, pI)
for (const label pointI : obj)
{
const label pointI = obj[pI];
if (isUsedPoint.set(pointI))
{
component.append(points[pointI][maxDir]);
......@@ -203,17 +198,15 @@ void Foam::AABBTree<Type>::createBoxes
DynamicList<label> maxBinObjectIDs(objectIDs.size());
treeBoundBox maxBb(boundBox::invertedBox);
forAll(objectIDs, i)
for (const label objI : objectIDs)
{
const label objI = objectIDs[i];
const Type& obj = objects[objI];
bool intoMin = false;
bool intoMax = false;
forAll(obj, pI)
for (const label pointI : obj)
{
const label pointI = obj[pI];
const point& pt = points[pointI];
if (pt[maxDir] < divMin)
{
......@@ -225,7 +218,8 @@ void Foam::AABBTree<Type>::createBoxes
}
}
// Note: object is inserted into both min/max child boxes (duplicated)
// if it crosses the bin boundaries
if (intoMin)
{
minBinObjectIDs.append(objI);
......@@ -238,7 +232,7 @@ void Foam::AABBTree<Type>::createBoxes
}
}
// inflate box in case geometry reduces to 2-D
// Inflate box in case geometry reduces to 2-D
if (minBinObjectIDs.size())
{
minBb.inflate(0.01);
......@@ -255,13 +249,13 @@ void Foam::AABBTree<Type>::createBoxes
label minI;
if (minBinObjectIDs.size() > minLeafSize_ && level < maxLevel_)
{
// new leaf
// New leaf
minI = nodes.size();
nodes.append(labelPair(-1, -1));
}
else
{
// update existing leaf
// Update existing leaf
minI = -addressing.size() - 1;
addressing.append(minBinObjectIDs);
}
......@@ -269,13 +263,13 @@ void Foam::AABBTree<Type>::createBoxes
label maxI;
if (maxBinObjectIDs.size() > minLeafSize_ && level < maxLevel_)
{
// new leaf
// New leaf
maxI = nodes.size();
nodes.append(labelPair(-1, -1));
}
else
{
// update existing leaf
// Update existing leaf
maxI = -addressing.size() - 1;
addressing.append(maxBinObjectIDs);
}
......@@ -283,7 +277,7 @@ void Foam::AABBTree<Type>::createBoxes
nodes(nodeI) = labelPair(minI, maxI);
bbs(nodeI) = Pair<treeBoundBox>(minBb, maxBb);
// recurse
// Recurse
if (minI >= 0)
{
createBoxes
......@@ -437,10 +431,8 @@ const Foam::List<Foam::labelList>& Foam::AABBTree<Type>::addressing() const
template<class Type>
bool Foam::AABBTree<Type>::pointInside(const point& pt) const
{
forAll(boundBoxes_, i)
for (const treeBoundBox& bb : boundBoxes_)
{
const treeBoundBox& bb = boundBoxes_[i];
if (bb.contains(pt))
{
return true;
......@@ -454,10 +446,8 @@ bool Foam::AABBTree<Type>::pointInside(const point& pt) const
template<class Type>
bool Foam::AABBTree<Type>::overlaps(const boundBox& bbIn) const
{
forAll(boundBoxes_, i)
for (const treeBoundBox& bb : boundBoxes_)
{
const treeBoundBox& bb = boundBoxes_[i];
if (bb.overlaps(bbIn))
{
return true;
......
......@@ -49,8 +49,7 @@ const Foam::word Foam::basicThermo::dictName("thermophysicalProperties");
Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()
{
const volScalarField::Boundary& tbf =
this->T_.boundaryField();
const volScalarField::Boundary& tbf = this->T_.boundaryField();
wordList hbt(tbf.size(), word::null);
......@@ -81,8 +80,7 @@ Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()
Foam::wordList Foam::basicThermo::heBoundaryTypes()
{
const volScalarField::Boundary& tbf =
this->T_.boundaryField();
const volScalarField::Boundary& tbf = this->T_.boundaryField();
wordList hbt = tbf.types();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment