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

code clean-up - still not great...

parent 871d2afc
......@@ -32,17 +32,15 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(commonRailInjector, 0);
addToRunTimeSelectionTable
(
injectorType,
commonRailInjector,
dictionary
);
defineTypeNameAndDebug(commonRailInjector, 0);
addToRunTimeSelectionTable
(
injectorType,
commonRailInjector,
dictionary
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -71,38 +69,58 @@ Foam::commonRailInjector::commonRailInjector
averageParcelMass_(mass_/nParcels_),
pressureIndependentVelocity_(false)
{
// convert CA to real time
forAll(massFlowRateProfile_, i)
{
massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
massFlowRateProfile_[i][0] =
t.userTimeToTime(massFlowRateProfile_[i][0]);
velocityProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
}
forAll(injectionPressureProfile_, i)
{
injectionPressureProfile_[i][0] = t.userTimeToTime(injectionPressureProfile_[i][0]);
injectionPressureProfile_[i][0] =
t.userTimeToTime(injectionPressureProfile_[i][0]);
}
if (mag(injectionPressureProfile_[0][0]-massFlowRateProfile_[0][0]) > SMALL)
if
(
mag(injectionPressureProfile_[0][0] - massFlowRateProfile_[0][0])
> SMALL
)
{
FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
<< " start-time entries for injectionPressureProfile and massFlowRateProfile do no match"
<< abort(FatalError);
FatalErrorIn
(
"commonRailInjector::commonRailInjector"
"(const time& t, const dictionary dict)"
) << " start-time entries for injectionPressureProfile and "
<< "massFlowRateProfile do no match"
<< abort(FatalError);
}
Info << "injectionPressureProfile_.size() = " << injectionPressureProfile_.size()
Info<< "injectionPressureProfile_.size() = "
<< injectionPressureProfile_.size()
<< ", massFlowRateProfile_.size() = " << massFlowRateProfile_.size()
<< endl;
if (mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]-massFlowRateProfile_[massFlowRateProfile_.size()-1][0]) > SMALL)
if
(
mag(injectionPressureProfile_[injectionPressureProfile_.size()-1][0]
- massFlowRateProfile_[massFlowRateProfile_.size()-1][0])
> SMALL
)
{
FatalError << "commonRailInjector::commonRailInjector(const time& t, const dictionary dict) " << endl
<< " end-time entries for injectionPressureProfile and massFlowRateProfile do no match"
<< abort(FatalError);
FatalErrorIn
(
"commonRailInjector::commonRailInjector"
"(const time& t, const dictionary dict)"
) << "End-time entries for injectionPressureProfile and "
<< "massFlowRateProfile do no match"
<< abort(FatalError);
}
scalar integratedMFR = integrateTable(massFlowRateProfile_);
scalar integratedP = integrateTable(injectionPressureProfile_)/(teoi()-tsoi());
scalar integratedP =
integrateTable(injectionPressureProfile_)/(teoi() - tsoi());
forAll(massFlowRateProfile_, i)
{
......@@ -113,7 +131,6 @@ Foam::commonRailInjector::commonRailInjector
TProfile_[i][1] = T_;
CdProfile_[i][0] = massFlowRateProfile_[i][0];
}
forAll(injectionPressureProfile_, i)
......@@ -122,7 +139,7 @@ Foam::commonRailInjector::commonRailInjector
}
// Normalize the direction vector
direction_ /= mag(direction_);
setTangentialVectors();
// check molar fractions
......@@ -134,18 +151,22 @@ Foam::commonRailInjector::commonRailInjector
if (mag(Xsum - 1.0) > SMALL)
{
Info << "Warning!!!\n commonRailInjector::commonRailInjector(const time& t, Istream& is)"
<< "X does not add up to 1.0, correcting molar fractions."
WarningIn
(
"commonRailInjector::commonRailInjector"
"(const time& t, const dictionary dict)"
) << "X does not add up to 1.0, correcting molar fractions."
<< endl;
forAll(X_, i)
{
X_[i] /= Xsum;
}
}
Info << "end constructor. in commonRail" << endl;
Info << "end constructor. in commonRail" << endl;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::commonRailInjector::~commonRailInjector()
......@@ -181,17 +202,20 @@ Foam::label Foam::commonRailInjector::nParcelsToInject
) const
{
scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
scalar mInj =
mass_*(fractionOfInjection(time1) - fractionOfInjection(time0));
label nParcels = label(mInj/averageParcelMass_ + 0.49);
return nParcels;
}
const Foam::vector Foam::commonRailInjector::position(const label n) const
{
return position_;
}
Foam::vector Foam::commonRailInjector::position
(
const label n,
......@@ -223,30 +247,32 @@ Foam::vector Foam::commonRailInjector::position
scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
return
(
(
position_
+ iRadius
* (
tangentialInjectionVector1_*cos(iAngle)
+ tangentialInjectionVector2_*sin(iAngle)
)
*(
tangentialInjectionVector1_*cos(iAngle)
+ tangentialInjectionVector2_*sin(iAngle)
)
);
}
return position_;
}
Foam::label Foam::commonRailInjector::nHoles() const
{
return 1;
}
Foam::scalar Foam::commonRailInjector::d() const
{
return d_;
}
const Foam::vector& Foam::commonRailInjector::direction
(
const label i,
......@@ -256,6 +282,7 @@ const Foam::vector& Foam::commonRailInjector::direction
return direction_;
}
Foam::scalar Foam::commonRailInjector::mass
(
const scalar time0,
......@@ -264,9 +291,10 @@ Foam::scalar Foam::commonRailInjector::mass
const scalar angleOfWedge
) const
{
scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
scalar mInj =
mass_*(fractionOfInjection(time1) - fractionOfInjection(time0));
// correct mass if calculation is 2D
// correct mass if calculation is 2D
if (twoD)
{
mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
......@@ -275,36 +303,43 @@ Foam::scalar Foam::commonRailInjector::mass
return mInj;
}
Foam::scalar Foam::commonRailInjector::mass() const
{
return mass_;
}
const Foam::scalarField& Foam::commonRailInjector::X() const
{
return X_;
}
Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::T() const
{
return TProfile_;
}
Foam::scalar Foam::commonRailInjector::T(const scalar time) const
{
return T_;
}
Foam::scalar Foam::commonRailInjector::tsoi() const
{
return massFlowRateProfile_[0][0];
}
Foam::scalar Foam::commonRailInjector::teoi() const
{
return massFlowRateProfile_[massFlowRateProfile_.size()-1][0];
}
Foam::scalar Foam::commonRailInjector::massFlowRate
(
const scalar time
......@@ -313,6 +348,7 @@ Foam::scalar Foam::commonRailInjector::massFlowRate
return getTableValue(massFlowRateProfile_, time);
}
Foam::scalar Foam::commonRailInjector::injectionPressure
(
const scalar time
......@@ -321,6 +357,7 @@ Foam::scalar Foam::commonRailInjector::injectionPressure
return getTableValue(injectionPressureProfile_, time);
}
Foam::scalar Foam::commonRailInjector::velocity
(
const scalar time
......@@ -329,11 +366,14 @@ Foam::scalar Foam::commonRailInjector::velocity
return getTableValue(velocityProfile_, time);
}
Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile() const
Foam::List<Foam::commonRailInjector::pair> Foam::commonRailInjector::CdProfile()
const
{
return CdProfile_;
}
Foam::scalar Foam::commonRailInjector::Cd
(
const scalar time
......@@ -342,11 +382,13 @@ Foam::scalar Foam::commonRailInjector::Cd
return getTableValue(CdProfile_, time);
}
Foam::scalar Foam::commonRailInjector::fractionOfInjection(const scalar time) const
{
return integrateTable(massFlowRateProfile_, time)/mass_;
}
Foam::scalar Foam::commonRailInjector::injectedMass
(
const scalar t
......@@ -368,7 +410,8 @@ void Foam::commonRailInjector::correctProfiles
forAll(velocityProfile_, i)
{
scalar Pinj = getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
scalar Pinj =
getTableValue(injectionPressureProfile_, velocityProfile_[i][0]);
scalar Vinj = sqrt(2.0*(Pinj - referencePressure)/rho);
scalar mfr = massFlowRateProfile_[i][1]/(rho*A);
scalar Cd = mfr/Vinj;
......@@ -377,14 +420,17 @@ void Foam::commonRailInjector::correctProfiles
}
}
Foam::vector Foam::commonRailInjector::tan1(const label n) const
{
return tangentialInjectionVector1_;
}
Foam::vector Foam::commonRailInjector::tan2(const label n) const
{
return tangentialInjectionVector2_;
}
// ************************************************************************* //
......@@ -47,7 +47,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class commonRailInjector Declaration
Class commonRailInjector Declaration
\*---------------------------------------------------------------------------*/
class commonRailInjector
......@@ -110,16 +110,11 @@ public:
// Constructors
//- Construct from components
commonRailInjector
(
const Time& t,
const dictionary& dict
);
commonRailInjector(const Time& t, const dictionary& dict);
// Destructor
~commonRailInjector();
//- Destructor
virtual ~commonRailInjector();
// Member Functions
......@@ -146,7 +141,7 @@ public:
const vector& axisOfWedgeNormal,
Random& rndGen
) const;
//- Return the number of holes
label nHoles() const;
......@@ -201,14 +196,14 @@ public:
{
return injectionPressureProfile_;
}
scalar injectionPressure(const scalar time) const;
List<pair> velocityProfile() const
{
return velocityProfile_;
}
scalar velocity(const scalar time) const;
List<pair> CdProfile() const;
......@@ -227,7 +222,6 @@ public:
{
return pressureIndependentVelocity_;
}
};
......
......@@ -32,16 +32,14 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(definedInjector, 0);
addToRunTimeSelectionTable
(
injectorType,
definedInjector,
dictionary
);
defineTypeNameAndDebug(definedInjector, 0);
addToRunTimeSelectionTable
(
injectorType,
definedInjector,
dictionary
);
}
......@@ -73,12 +71,13 @@ Foam::definedInjector::definedInjector
// convert CA to real time - mass flow rate profile
forAll(massFlowRateProfile_, i)
{
massFlowRateProfile_[i][0] = t.userTimeToTime(massFlowRateProfile_[i][0]);
// dummy
injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
injectionPressureProfile_[i][1] = 0.0;
CdProfile_[i][0] = massFlowRateProfile_[i][0];
CdProfile_[i][1] = 1.0;
massFlowRateProfile_[i][0] =
t.userTimeToTime(massFlowRateProfile_[i][0]);
// dummy
injectionPressureProfile_[i][0] = massFlowRateProfile_[i][0];
injectionPressureProfile_[i][1] = 0.0;
CdProfile_[i][0] = massFlowRateProfile_[i][0];
CdProfile_[i][1] = 1.0;
}
forAll(velocityProfile_, i)
......@@ -89,15 +88,28 @@ Foam::definedInjector::definedInjector
// check if time entries match
if (mag(massFlowRateProfile_[0][0]-velocityProfile_[0][0]) > SMALL)
{
FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
<< " start-times do not match for velocityProfile and massFlowRateProfile."
FatalErrorIn
(
"definedInjector::definedInjector"
"(const time& t, const dictionary dict)"
) << "Start-times do not match for velocityProfile and "
<< "massFlowRateProfile." << nl
<< abort(FatalError);
}
if (mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]-velocityProfile_[velocityProfile_.size()-1][0]) > SMALL)
if
(
mag(massFlowRateProfile_[massFlowRateProfile_.size()-1][0]
- velocityProfile_[velocityProfile_.size()-1][0])
> SMALL
)
{
FatalError << "definedInjector::definedInjector(const time& t, const dictionary dict) " << endl
<< " end-times do not match for velocityProfile and massFlowRateProfile."
FatalErrorIn
(
"definedInjector::definedInjector"
"(const time& t, const dictionary dict)"
) << "End-times do not match for velocityProfile and "
<< "massFlowRateProfile."
<< abort(FatalError);
}
......@@ -112,7 +124,7 @@ Foam::definedInjector::definedInjector
// Normalize the direction vector
direction_ /= mag(direction_);
setTangentialVectors();
// check molar fractions
......@@ -126,7 +138,8 @@ Foam::definedInjector::definedInjector
{
WarningIn
(
"definedInjector::definedInjector(const time& t, Istream& is)"
"definedInjector::definedInjector"
"(const time& t, const dictionary dict)"
) << "X does not add up to 1.0, correcting molar fractions."
<< endl;
......@@ -174,15 +187,17 @@ Foam::label Foam::definedInjector::nParcelsToInject
scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
label nParcels = label(mInj/averageParcelMass_ + 0.49);
return nParcels;
}
const Foam::vector Foam::definedInjector::position(const label n) const
{
return position_;
}
Foam::vector Foam::definedInjector::position
(
const label n,
......@@ -214,7 +229,7 @@ Foam::vector Foam::definedInjector::position
scalar iAngle = 2.0*mathematicalConstant::pi*rndGen.scalar01();
return
(
(
position_
+ iRadius
* (
......@@ -222,22 +237,25 @@ Foam::vector Foam::definedInjector::position
+ tangentialInjectionVector2_*sin(iAngle)
)
);
}
return position_;
}
Foam::label Foam::definedInjector::nHoles() const
{
return 1;
}
Foam::scalar Foam::definedInjector::d() const
{
return d_;
}
const Foam::vector& Foam::definedInjector::direction
(
const label i,
......@@ -247,6 +265,7 @@ const Foam::vector& Foam::definedInjector::direction
return direction_;
}
Foam::scalar Foam::definedInjector::mass
(
const scalar time0,
......@@ -255,9 +274,10 @@ Foam::scalar Foam::definedInjector::mass
const scalar angleOfWedge
) const
{
scalar mInj = mass_*(fractionOfInjection(time1)-fractionOfInjection(time0));
scalar mInj =
mass_*(fractionOfInjection(time1) - fractionOfInjection(time0));
// correct mass if calculation is 2D
// correct mass if calculation is 2D
if (twoD)
{
mInj *= 0.5*angleOfWedge/mathematicalConstant::pi;
......@@ -266,51 +286,61 @@ Foam::scalar Foam::definedInjector::mass
return mInj;
}
Foam::scalar Foam::definedInjector::mass() const
{
return mass_;
}
Foam::scalar Foam::definedInjector::massFlowRate(const scalar time) const
{
return getTableValue(massFlowRateProfile_, time);
}
Foam::scalar Foam::definedInjector::injectionPressure(const scalar time) const
{
return getTableValue(injectionPressureProfile_, time);
}
Foam::scalar Foam::definedInjector::Cd(const scalar time) const
{
return getTableValue(CdProfile_, time);
}
const Foam::scalarField& Foam::definedInjector::X() const
{
return X_;
}
Foam::List<Foam::definedInjector::pair> Foam::definedInjector::T() const
{
return TProfile_;
}