mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Feature single precision solve type
This commit is contained in:
committed by
Andrew Heather
parent
f2eb3e1cee
commit
2d080ff331
@ -390,14 +390,16 @@ TMP_UNARY_FUNCTION(Type, min)
|
||||
template<class Type>
|
||||
Type sum(const UList<Type>& f)
|
||||
{
|
||||
Type Sum = Zero;
|
||||
typedef typename Foam::typeOfSolve<Type>::type solveType;
|
||||
|
||||
solveType Sum = Zero;
|
||||
|
||||
if (f.size())
|
||||
{
|
||||
TFOR_ALL_S_OP_F(Type, Sum, +=, Type, f)
|
||||
TFOR_ALL_S_OP_FUNC_F(solveType, Sum, +=, solveType, Type, f)
|
||||
}
|
||||
|
||||
return Sum;
|
||||
return Type(Sum);
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, sum)
|
||||
|
||||
@ -30,6 +30,7 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "primitiveMesh.H"
|
||||
#include "PrecisionAdaptor.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -75,10 +76,17 @@ void Foam::primitiveMesh::makeCellCentresAndVols
|
||||
(
|
||||
const vectorField& fCtrs,
|
||||
const vectorField& fAreas,
|
||||
vectorField& cellCtrs,
|
||||
scalarField& cellVols
|
||||
vectorField& cellCtrs_s,
|
||||
scalarField& cellVols_s
|
||||
) const
|
||||
{
|
||||
typedef Vector<solveScalar> solveVector;
|
||||
|
||||
PrecisionAdaptor<solveVector, vector> tcellCtrs(cellCtrs_s);
|
||||
Field<solveVector>& cellCtrs = tcellCtrs.ref();
|
||||
PrecisionAdaptor<solveScalar, scalar> tcellVols(cellVols_s);
|
||||
Field<solveScalar>& cellVols = tcellVols.ref();
|
||||
|
||||
// Clear the fields for accumulation
|
||||
cellCtrs = Zero;
|
||||
cellVols = 0.0;
|
||||
@ -89,18 +97,18 @@ void Foam::primitiveMesh::makeCellCentresAndVols
|
||||
// first estimate the approximate cell centre as the average of
|
||||
// face centres
|
||||
|
||||
vectorField cEst(nCells(), Zero);
|
||||
Field<solveVector> cEst(nCells(), Zero);
|
||||
labelField nCellFaces(nCells(), Zero);
|
||||
|
||||
forAll(own, facei)
|
||||
{
|
||||
cEst[own[facei]] += fCtrs[facei];
|
||||
cEst[own[facei]] += solveVector(fCtrs[facei]);
|
||||
++nCellFaces[own[facei]];
|
||||
}
|
||||
|
||||
forAll(nei, facei)
|
||||
{
|
||||
cEst[nei[facei]] += fCtrs[facei];
|
||||
cEst[nei[facei]] += solveVector(fCtrs[facei]);
|
||||
++nCellFaces[nei[facei]];
|
||||
}
|
||||
|
||||
@ -111,12 +119,15 @@ void Foam::primitiveMesh::makeCellCentresAndVols
|
||||
|
||||
forAll(own, facei)
|
||||
{
|
||||
const solveVector fc(fCtrs[facei]);
|
||||
const solveVector fA(fAreas[facei]);
|
||||
|
||||
// Calculate 3*face-pyramid volume
|
||||
scalar pyr3Vol =
|
||||
fAreas[facei] & (fCtrs[facei] - cEst[own[facei]]);
|
||||
solveScalar pyr3Vol =
|
||||
fA & (fc - cEst[own[facei]]);
|
||||
|
||||
// Calculate face-pyramid centre
|
||||
vector pc = (3.0/4.0)*fCtrs[facei] + (1.0/4.0)*cEst[own[facei]];
|
||||
solveVector pc = (3.0/4.0)*fc + (1.0/4.0)*cEst[own[facei]];
|
||||
|
||||
// Accumulate volume-weighted face-pyramid centre
|
||||
cellCtrs[own[facei]] += pyr3Vol*pc;
|
||||
@ -127,12 +138,15 @@ void Foam::primitiveMesh::makeCellCentresAndVols
|
||||
|
||||
forAll(nei, facei)
|
||||
{
|
||||
const solveVector fc(fCtrs[facei]);
|
||||
const solveVector fA(fAreas[facei]);
|
||||
|
||||
// Calculate 3*face-pyramid volume
|
||||
scalar pyr3Vol =
|
||||
fAreas[facei] & (cEst[nei[facei]] - fCtrs[facei]);
|
||||
solveScalar pyr3Vol =
|
||||
fA & (cEst[nei[facei]] - fc);
|
||||
|
||||
// Calculate face-pyramid centre
|
||||
vector pc = (3.0/4.0)*fCtrs[facei] + (1.0/4.0)*cEst[nei[facei]];
|
||||
solveVector pc = (3.0/4.0)*fc + (1.0/4.0)*cEst[nei[facei]];
|
||||
|
||||
// Accumulate volume-weighted face-pyramid centre
|
||||
cellCtrs[nei[facei]] += pyr3Vol*pc;
|
||||
|
||||
@ -61,22 +61,22 @@ bool Foam::primitiveMesh::checkClosedBoundary
|
||||
// Loop through all boundary faces and sum up the face area vectors.
|
||||
// For a closed boundary, this should be zero in all vector components
|
||||
|
||||
vector sumClosed(Zero);
|
||||
scalar sumMagClosedBoundary = 0;
|
||||
Vector<solveScalar> sumClosed(Zero);
|
||||
solveScalar sumMagClosedBoundary = 0;
|
||||
|
||||
for (label facei = nInternalFaces(); facei < areas.size(); facei++)
|
||||
{
|
||||
if (!internalOrCoupledFaces.size() || !internalOrCoupledFaces[facei])
|
||||
{
|
||||
sumClosed += areas[facei];
|
||||
sumClosed += Vector<solveScalar>(areas[facei]);
|
||||
sumMagClosedBoundary += mag(areas[facei]);
|
||||
}
|
||||
}
|
||||
|
||||
reduce(sumClosed, sumOp<vector>());
|
||||
reduce(sumMagClosedBoundary, sumOp<scalar>());
|
||||
reduce(sumClosed, sumOp<Vector<solveScalar>>());
|
||||
reduce(sumMagClosedBoundary, sumOp<solveScalar>());
|
||||
|
||||
vector openness = sumClosed/(sumMagClosedBoundary + VSMALL);
|
||||
Vector<solveScalar> openness = sumClosed/(sumMagClosedBoundary + VSMALL);
|
||||
|
||||
if (cmptMax(cmptMag(openness)) > closedThreshold_)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2012-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -420,6 +420,7 @@ Foam::tmp<Foam::scalarField> Foam::primitiveMeshTools::faceFlatness
|
||||
tmp<scalarField> tfaceFlatness(new scalarField(mesh.nFaces(), 1.0));
|
||||
scalarField& faceFlatness = tfaceFlatness.ref();
|
||||
|
||||
typedef Vector<solveScalar> solveVector;
|
||||
|
||||
forAll(fcs, facei)
|
||||
{
|
||||
@ -427,20 +428,20 @@ Foam::tmp<Foam::scalarField> Foam::primitiveMeshTools::faceFlatness
|
||||
|
||||
if (f.size() > 3 && magAreas[facei] > ROOTVSMALL)
|
||||
{
|
||||
const point& fc = fCtrs[facei];
|
||||
const solveVector fc = fCtrs[facei];
|
||||
|
||||
// Calculate the sum of magnitude of areas and compare to magnitude
|
||||
// of sum of areas.
|
||||
|
||||
scalar sumA = 0.0;
|
||||
solveScalar sumA = 0.0;
|
||||
|
||||
forAll(f, fp)
|
||||
{
|
||||
const point& thisPoint = p[f[fp]];
|
||||
const point& nextPoint = p[f.nextLabel(fp)];
|
||||
const solveVector thisPoint = p[f[fp]];
|
||||
const solveVector nextPoint = p[f.nextLabel(fp)];
|
||||
|
||||
// Triangle around fc.
|
||||
vector n = 0.5*((nextPoint - thisPoint)^(fc - thisPoint));
|
||||
solveVector n = 0.5*((nextPoint - thisPoint)^(fc - thisPoint));
|
||||
sumA += mag(n);
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ void Foam::primitiveMesh::makeFaceCentresAndAreas
|
||||
forAll(fs, facei)
|
||||
{
|
||||
const labelList& f = fs[facei];
|
||||
label nPoints = f.size();
|
||||
const label nPoints = f.size();
|
||||
|
||||
// If the face is a triangle, do a direct calculation for efficiency
|
||||
// and to avoid round-off error-related problems
|
||||
@ -95,26 +95,29 @@ void Foam::primitiveMesh::makeFaceCentresAndAreas
|
||||
}
|
||||
else
|
||||
{
|
||||
vector sumN = Zero;
|
||||
scalar sumA = 0.0;
|
||||
vector sumAc = Zero;
|
||||
typedef Vector<solveScalar> solveVector;
|
||||
|
||||
point fCentre = p[f[0]];
|
||||
solveVector sumN = Zero;
|
||||
solveScalar sumA = 0.0;
|
||||
solveVector sumAc = Zero;
|
||||
|
||||
solveVector fCentre = p[f[0]];
|
||||
for (label pi = 1; pi < nPoints; pi++)
|
||||
{
|
||||
fCentre += p[f[pi]];
|
||||
fCentre += solveVector(p[f[pi]]);
|
||||
}
|
||||
|
||||
fCentre /= nPoints;
|
||||
|
||||
for (label pi = 0; pi < nPoints; pi++)
|
||||
{
|
||||
const point& nextPoint = p[f[(pi + 1) % nPoints]];
|
||||
|
||||
vector c = p[f[pi]] + nextPoint + fCentre;
|
||||
vector n = (nextPoint - p[f[pi]])^(fCentre - p[f[pi]]);
|
||||
scalar a = mag(n);
|
||||
const label nextPi(pi == nPoints-1 ? 0 : pi+1);
|
||||
const solveVector nextPoint(p[f[nextPi]]);
|
||||
const solveVector thisPoint(p[f[pi]]);
|
||||
|
||||
solveVector c = thisPoint + nextPoint + fCentre;
|
||||
solveVector n = (nextPoint - thisPoint)^(fCentre - thisPoint);
|
||||
solveScalar a = mag(n);
|
||||
sumN += n;
|
||||
sumA += a;
|
||||
sumAc += a*c;
|
||||
|
||||
@ -154,7 +154,7 @@ namespace Foam
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Additional transcendental functions
|
||||
// Additional transcendental functions and specialisations
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
@ -172,6 +172,15 @@ namespace Foam
|
||||
|
||||
//- Lower incomplete gamma function
|
||||
scalar incGamma_P(const scalar a, const scalar x);
|
||||
|
||||
//- Type to use for extended precision
|
||||
template<>
|
||||
class typeOfSolve<scalar>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef solveScalar type;
|
||||
};
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -137,6 +137,15 @@ struct is_contiguous_scalar<SphericalTensor<Cmpt>>
|
||||
{};
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
class typeOfSolve<SphericalTensor<Cmpt>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SphericalTensor<solveScalar> type;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -176,6 +176,15 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
class typeOfSolve<SymmTensor<Cmpt>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef SymmTensor<solveScalar> type;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -344,6 +344,15 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
class typeOfSolve<Tensor<Cmpt>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Tensor<solveScalar> type;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -167,6 +167,15 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
class typeOfSolve<Vector<Cmpt>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Vector<solveScalar> type;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -35,6 +35,7 @@ Description
|
||||
#ifndef products_H
|
||||
#define products_H
|
||||
|
||||
#include "direction.H"
|
||||
#include "pTraits.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -72,6 +73,16 @@ class symmTypeOfRank
|
||||
{};
|
||||
|
||||
|
||||
//- The extended precision type (solveScalar for float)
|
||||
template<class Type>
|
||||
class typeOfSolve
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Type type;
|
||||
};
|
||||
|
||||
|
||||
//- The magnitude type for given argument.
|
||||
template<class arg1>
|
||||
class typeOfMag
|
||||
|
||||
Reference in New Issue
Block a user