implementation of an incompressible headlosspressure...
TRANSCRIPT
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Implementation of an incompressibleheadLossPressure boundary condition
Jonathan Fahlbeck
Mechanics and Maritime Sciences/Fluid Dynamics,Chalmers University of Technology,
Gothenburg, Sweden
January 21, 2021
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 1 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Outline
Introduction
Analytical models
Pressure and velocity coupling
New implementations
Test case
Results
Concluding words
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 2 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Introduction
Model head losses before/after the domain.
Take any number of loss factors.
One time, minor, lossesFriction losses
Adjust the pressure/flow rate according to the losses.
Pressure drop scale quadratic to change in velocity.
Illustrative view of a full system
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 3 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Pressure and the Bernoulli equation
Static pressure, pDynamic pressure, 0.5ρU2
Hydrostatic pressure, ρgHBernoulli Equation
p1 +ρU2
1
2︸︷︷︸U1=0
+ρgH1 = p2 +ρU2
2
2+ ρgH2 + ∆pminor + ∆pfriction
kinematic pressure, p∗ = p/ρJonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 4 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Analytical models
The kinematic pressure at 2 with the Bernoulli equation:
p∗2 =︸︷︷︸H1−H2=H
p∗1 −U22
2+ gH −∆p∗minor −∆p∗friction
The minor loss:
∆p∗minor =N∑i=1
U2i
2ki
The friction losses:
∆p∗friction =N∑j=1
U2j
2
Ljdh,j
fj
f =64
Red1
f 1/2=− 2.0 log10
(ε/d
3.7+
2.51
Red f 1/2
)These are the implemented equations in the headLossPressure boundarycondition.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 5 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Pressure and velocity boundary conditions
The pressureInletVelocity boundary condition
123 operator==(n*phip/magS);
Which in a matematical description equal to:
Up,i = nφiAi
The totalPressure boundary condition:
214 operator==(p0p - 0.5*(1.0 - pos0(phip))*magSqr(Up));
In mathematical description this is equal to:
p∗p,i = p∗0 − 0.5|Up,i |2 for inflow
p∗p,i = p∗0 for outflow
The function pos0() returns one or zero.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 6 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Pressure and velocity coupling
Velocity, Up, is calculated from the flux.
Pressure, pp, calculated from velocity and total pressure.
The flux, φ, is adjusted at the end of the iteration/time-step.
φ
Uppp
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 7 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Origin of the headLossPressure boundary condition
The headLossPressure is derived from the totalPressure
Only the incompressible parts.
Customised to take any number of minor and friction input parameters.
Allow the user to specify head and/or reservoir kinematic pressure.
Can be used for both up- and down-stream pressure calculations.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 8 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Boundary condition input
Typical input headLossPressure
<patchName>
{
type headLossPressure;
patm uniform 0; // m2/s2
H 10; // m
d 1; // m
frictionLossFactor
(
(($d 2e-05 8) pipe1)
(($d 2e-05 5) pipe2)
);
minorLossFactor
(
(($d 0.05) bend)
(($d 0.01) valve)
);
}
Typical input totalPressure
<patchName>
{
type totalPressure;
p0 uniform 1e5;
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 9 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Create the headLossPressure
These commands∗ set-up a renamed copy of the totalPressure:
cd $WM_PROJECT_DIRcp -r --parents src/finiteVolume/fields/fvPatchFields/derived/totalPressure
$WM_PROJECT_USER_DIR/cd $WM_PROJECT_USER_DIR/src/finiteVolume/fields/fvPatchFields/derived/foamNewBC -f -s headLossPressure
rm headLossPressure/headLossPressureFvPatchScalarField.*
cp -r totalPressure/totalPressureFvPatchScalarField.* headLossPressure/
rm -r totalPressure/
cd headLossPressure/
mv totalPressureFvPatchScalarField.C headLossPressureFvPatchScalarField.C
mv totalPressureFvPatchScalarField.H headLossPressureFvPatchScalarField.H
sed -i s/’totalPressure’/’headLossPressure’/g headLossPressure*
∗Note that OpenFOAM-v1912 is used.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 10 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Clean the headLossPressure
These commands∗ clean the headLossPressure:
sed -i ’149,157d’ headLossPressureFvPatchScalarField.H
sed -i ’252,289d’ headLossPressureFvPatchScalarField.H
sed -i ’/rhoName_/d’ headLossPressureFvPatchScalarField.C
sed -i ’/psiName_/d’ headLossPressureFvPatchScalarField.C
sed -i ’/gamma_/d’ headLossPressureFvPatchScalarField.C
sed -i ’157,190d’ headLossPressureFvPatchScalarField.C
sed -i s/’else if’/’if’/g headLossPressureFvPatchScalarField.C
sed -i s/’p0_’/’patm_’/g headLossPressureFvPatchScalarField.*
sed -i s/’"p0"’/’"patm"’/g headLossPressureFvPatchScalarField.*
sed -i s/’p0()’/’patm()’/g headLossPressureFvPatchScalarField.*
sed -i s/’p0p’/’patmp’/g headLossPressureFvPatchScalarField.*
∗Note that OpenFOAM-v1912 is used.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 11 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Declaration of input variables in the .H file
Pressure unchanged fromtotalPressure
Diameter, gravity, heightas const scalar
Losses as list of Tuple2
Any number of loss factors
Friction loss supplied asvector, word
Minor loss supplied asvector2D, word
Not possible to usevectorField
New private member data
// Atmospheric pressure
scalarField patm_;
// Hydraulic diameter of the pipe
const scalar d_;
// Gravity
const scalar g_;
// Height
const scalar H_;
// Friction loss factors ((d, epsilon, L) name)
typedef Tuple2<vector, word> indexedVector;
const List<indexedVector> frictionLossFactor_;
// Minor loss factors ((d, k) name)
typedef Tuple2<vector2D, word> indexedVector2D;
const List<indexedVector2D> minorLossFactor_;
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 12 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Assign values to the variables in .C file
patm_ added as in the totalPressure and is of size p.
The gravity has a default values if not specified.
dict.getOrDefault<scalar>("Name",value)
Diameter, and head are read as scalars
dict.get<scalar>("Name")
The two loss factors are simply read from the boundary file.
dict.lookup("Name")
From 1st constructor
patm_(p.size(), Zero),
d_(Zero),
g_(9.81),
H_(Zero),
frictionLossFactor_(),
minorLossFactor_()
From 2nd constructor
patm_("patm", dict, p.size()),
d_(dict.get<scalar>("d")),
g_(dict.getOrDefault<scalar>("g",9.81)),
H_(dict.get<scalar>("H")),
frictionLossFactor_(dict.lookup("frictionLossFactor")),
minorLossFactor_(dict.lookup("minorLossFactor"))
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 13 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Update OpenFOAM functionality .C file
The new variables need to be added to the three last constructors.
Example from the 3rd constructor:
From 3rd constructor
patm_(ptf.patm_, mapper),
d_(ptf.d_),
g_(ptf.g_),
H_(ptf.H_),
frictionLossFactor_(ptf.frictionLossFactor_),
minorLossFactor_(ptf.minorLossFactor_)
Similar with 4th and 5th constructors.
Replace ptf to tppsf.
Careful with mapper, only used in 3rd constructor.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 14 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Modifications to main function .C file
Calculate average velocity on patch, Uavg.Required to calculate pressure losses and Re-number
Uavg =N∑i=1
φiAi
From updateCoeffs (main function)
scalar sumPhi =
gSum(patch().lookupPatchField<surfaceScalarField, scalar>(phiName_));
const scalar& totalArea = gSum(patch().magSf());
scalar Uavg;
if (sumPhi != 0)
{
Uavg = mag(sumPhi)/totalArea;
}
else
{
Info << "Zero flux on patch" << endl;
sumPhi = 1e-20;
Uavg = mag(sumPhi)/totalArea;
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 15 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Minor loss calculation .C file
Loops through the minorLossFactor_
Scale the velocity to match the loss
∆pminor,i = ki
(Uavg
(dpatchdi
)2)2
2+ ∆pminor,i−1
From updateCoeffs (main function)
scalar dpMinor(0);
const scalar * dMinor;
const scalar * k;
for(int i = 0; i < minorLossFactor_.size(); i++)
{
dMinor = &minorLossFactor_[i].first().component(0);
k = &minorLossFactor_[i].first().component(1);
dpMinor = *k * sqr(Uavg * sqr(d_ / *dMinor))/2 + dpMinor;
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 16 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Friction loss calculation and kinematic viscosity
Similar as philosophy as with the minor losses
Solve the friction loss factor, f , iterative.
Read the kinematic viscosity from transportProperties
Required to calculate Re to estimated f .
Read kinematic viscosity, from updateCoeffs
const dictionary& transportProperties=
db().lookupObject<dictionary>("transportProperties");
const dimensionedScalar nuDimScal("nu", dimViscosity, transportProperties);
const scalar& nu = nuDimScal.value();
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 17 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Friction loss calculation .C file
Calculating friction losses, from updateCoeffs
scalar f(0);
scalar dpFriction(0);
const scalar * dFriction;
const scalar * epsilon;
const scalar * L;
for(int i = 0; i < frictionLossFactor_.size(); i++)
{
dFriction = &frictionLossFactor_[i].first().component(0);
epsilon = &frictionLossFactor_[i].first().component(1);
L = &frictionLossFactor_[i].first().component(2);
f = fFunc(*dFriction,*epsilon,Uavg,nu);
dpFriction = f * *L / *dFriction * sqr(Uavg * sqr(d_ / *dFriction))/2 +
dpFriction;
}
Calculation of the friction factor with a function.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 18 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Declare fFunc, and inputs .
The declaration file
double fFunc
(
const scalar&,
const scalar&,
const scalar&,
const scalar&
);
Four inputs
Re-number
Fail-safe
Laminar flow
else, next slide
The definition fille
double Foam::headLossPressureFvPatchScalarField::fFunc
(
const scalar& dia,
const scalar& eps,
const scalar& Usim,
const scalar& nu
)
{
const scalar& U = Usim*sqr(d_/dia);
const scalar& Re = dia*U/nu;
scalar f(0);
if ( Re == 0 ) { f = 0; } //fail-safe
else if ( Re < 2300 )
{
f = 64/Re;
Info << "Laminar Flow" << endl;
Info << "Re = " << Re << endl;
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 19 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
fFunc, friction loss-factor function.
Part of the fFunc function, from the .C file
const scalar tol = 1e-5;
const scalar fInitaL = sqr(1/(-1.8*log10(6.9/Re + pow((eps/dia)/3.7 ,1.11))));
scalar fOld = fInitaL;
for(int i = 0; i < 20; i++)
{
f = sqr(1/(-2*log10((eps/dia)/3.7 + 2.51/(Re*sqrt(fOld)))));
if (mag(f - fOld)/fOld <= tol )
{
break;
}
fOld = f;
}
if ( mag(f - fInitaL)/fInitaL >= 0.1 )
{
Info << "Using f Inital" << endl;
f = fInitaL;
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 20 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Flow chart of friction coefficient calculation
fold =finitial
f =f (fold)
f−f oldfold
≤tol
fold = f
f−finitialfinitial
≤0.1
f = f
f = finitial
returns f
no
yes yes
no
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 21 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Friction loss calculation
The dFunc also contain:
dia, eps, Usim, and nu are function inputs.Calculation of the Reynolds number.Adoptions for laminar flow.Fail-safe to prevent zero division.
The final calculation of the friction loss:
dpFriction = f * *L / *dFriction * sqr(Uavg * sqr(d_ / *dFriction))/2 +
dpFriction;
Corresponding mathematical formulation:
∆pfriction,i = fiLidi
(Uavg
(dpatchdi
)2)2
2+ ∆pfriction,i−1
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 22 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Patch pressure calculation
operator==
(
patmp - 0.5*(1.0 - pos0(phip))*magSqr(Up)
+ sumPhi/mag(sumPhi)*(dpFriction + dpMinor) + g_*H_
);
pp,i = patm,p︸ ︷︷ ︸I
−X1(φi )0.5|Up,i|2︸ ︷︷ ︸II
+X2(φsum)(∆pfriction + ∆pminor)︸ ︷︷ ︸III
+ gH︸︷︷︸IV
where the functions X are defined as
X1(φi ) =
{1 if φi ≤ 0
0 if φi > 0X2(φsum) =
{−1 if φsum < 0
1 if φsum > 0.
∗The φsum 6= 0 due to fail-safe.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 23 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Patch pressure calculation
In relation to the hydrostatic pressure:
Inflow - the pressure decreases (up-stream losses)Outflow - the pressure increases (down-stream losses)
The sign of the flux control the X functions.
The dynamic pressure is excluded for outflow to uphold continuity.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 24 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Write data output
Diameter and head written as scalars.
writeEntry<scalar>("Name", variable)
The gravity only written if supplied
writeEntryIfDifferent<scalar>("Name", value, variable)
The loss-factors written to the file.
writeEntry("Name")
Part of the write function, from the .C file
os.writeEntry<scalar>("d", d_);
os.writeEntryIfDifferent<scalar>("g", 9.81,g_);
os.writeEntry<scalar>("H", H_);
os.writeEntry("frictionLossFactor",frictionLossFactor_);
os.writeEntry("minorLossFactor",minorLossFactor_);
patm_.writeEntry("patm", os);
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 25 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
System to model
Steady-state simulation of ‘CFD’ part
Compare pressure losses.
Compare flow rate.
The system full system
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 26 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Table with loss factors
Table with loss factors
Inlet Outletpatm 0 m2/s2 0 m2/s2
H 5 m 1 md 0.1 m 0.1 mMinor Loss Factor k kBend 0.2 0.2Valve 0.05 0.05Instrument 0.03 -Entrance/Exit 0.4 1.0Friction Loss Factor L [m] ε [m] L [m] ε [m]Horizontal pipe 2.0 2.0× 10−5 0.5 2.0× 10−5
Vertical pipe 2.0 2.0× 10−5 0.5 2.0× 10−5
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 27 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Boundary condition set-up
inlet
{
type headLossPressure;
patm uniform 0;
H 5;
d 0.1;
minorLossFactor
(
((0.1 0.2) Bend)
((0.1 0.05) Valve)
((0.1 0.03) Instrument)
((0.1 0.4) Entrance))
);
frictionLossFactor
(
((0.1 2e-5 2.0) Horizontal)
((0.1 2e-5 2.0) Vertical)
);
}
outlet
{
type headLossPressure;
patm uniform 0;
H 1;
d 0.1;
minorLossFactor
(
((0.1 0.2) Bend)
((0.1 0.05) Valve)
((0.1 1.0) Exit)
);
frictionLossFactor
(
((0.1 2e-5 0.5) Horizontal)
((0.1 2e-5 0.5) Vertical)
);
}
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 28 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Case set-up
Steady-state with simpleFoam
pressureInletOutletVelocity at inlet and outlet
Turbulence modeled with k-ω SST
Block-structured mesh
Add lib to controlDict
libs("libheadLossPressure.so");
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 29 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Colourful Figure Display (CFD)
Pressure decreases gradually in the domain.
Inlet - the losses are subtracted.
Outlet - the losses are added.
Fairly uniform velocity.
(a) Kinematic pressure with velocity vectors as arrows.
(b) Velocity magnitude with velocity vectors as arrows.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 30 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Numerical vs. analytical results
Can the boundary condition estimate valid pressure losses and flow rate?
Numerical results compared to analytical from the Bernoulli equation.
Pressure drop comparison:
∆p∗ = p∗inlet − p∗outlet
∆p∗sim = 1.801 m2/s2
∆p∗ana = 1.799 m2/s2
Percentual difference of 0.1 %.*Flow rate from simulation.
Flow rate comparison:Analytical flow rate solved iteratively.Balance between flow, losses, and head.
Qsim =0.0351 m3/s
Qana =0.0352 m3/s
Percentual difference of 0.3 %.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 31 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Analytical model
The correct height g∆H is known.
Q increased until desired g∆H is achieved.
Qguess =⇒
U =Qguess
A
Red = Udν
1f 1/2
= −2.0 log10
(ε/d3.7 + 2.51
Red f 1/2
)∆p∗friction = fU2
2d (Lup-stream + Lsim-domain + Ldown-stream)
∆p∗minor = U2
2
N∑i=1
ki
g∆H = U2
2 + ∆p∗friction + ∆p∗minor
δH = |g∆H − g(Hup-stream − Hdown-stream)|.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 32 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Conclusions
Works as intended
Can take any number of loss factorsHeight elevation to drive the flow.Pressure difference to drive flow.
Possible to simulate larger systems.
Results are according to theory.
Difference in pressure drop of 0.1 %.Difference in flow rate of 0.3 %.
Evaluate under unsteady and transient conditions.
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 33 / 34
Introduction headLossPressure Test Case Results Conclusions and further work Acknowledgement
Acknowledgement
Thanks for your attention!Acknowledgements:
Hakan Nilsson (supervisor and course examiner)
Saeed Salehi (co-supervisor and course assistant)
OpenFOAM developers and community
Jonathan Fahlbeck Implementation of an incompressible headLossPressure boundary condition January 21, 2021 34 / 34