Skip to content

Commit

Permalink
Removal of pointers from gas routines. Some minor cleanups too.
Browse files Browse the repository at this point in the history
  • Loading branch information
vidanovic committed Dec 14, 2022
1 parent 6a069ab commit 9713915
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 99 deletions.
7 changes: 7 additions & 0 deletions src/Common/src/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ namespace FenestrationCommon
std::vector<IndexRange> chunkIt(size_t start, size_t end, size_t numberOfSplits);

size_t getNumberOfThreads(size_t numberOfJobs);

template <typename Map>
bool map_compare (Map const &lhs, Map const &rhs) {
return lhs.size() == rhs.size()
&& std::equal(lhs.begin(), lhs.end(),
rhs.begin());
}
}
24 changes: 12 additions & 12 deletions src/Gases/src/Gas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ namespace Gases
}
for(const auto & item : gases)
{
m_GasItem.emplace_back(item.first, Gases::Gas::intance().get(item.second));
m_GasItem.emplace_back(item.first, Gases::Gas::instance().get(item.second));
}
}

void CGas::addGasItem(double percent, Gases::GasDef def)
{
addGasItem(percent, Gases::Gas::intance().get(def));
addGasItem(percent, Gases::Gas::instance().get(def));
}

double CGas::totalPercent()
Expand All @@ -109,10 +109,10 @@ namespace Gases

const GasProperties & CGas::getSimpleGasProperties()
{
m_SimpleProperties = *((m_GasItem)[0].getFractionalGasProperties());
m_SimpleProperties = m_GasItem[0].getFractionalGasProperties();
for(auto it = next(m_GasItem.begin()); it != m_GasItem.end(); ++it)
{
m_SimpleProperties += *(it->getFractionalGasProperties());
m_SimpleProperties += it->getFractionalGasProperties();
}

return m_SimpleProperties;
Expand Down Expand Up @@ -172,16 +172,16 @@ namespace Gases
for(auto & it : m_GasItem)
{
auto itGasProperties = it.getGasProperties();
auto lambdaPrim(itGasProperties->getLambdaPrim());
auto lambdaSecond(itGasProperties->getLambdaSecond());
auto lambdaPrim(itGasProperties.getLambdaPrim());
auto lambdaSecond(itGasProperties.getLambdaSecond());

auto sumMix = 1.0;
for(size_t i = 0; i < gasSize; ++i)
{
sumMix += miItem[counter][i];
}

miMix += itGasProperties->m_Viscosity / sumMix;
miMix += itGasProperties.m_Viscosity / sumMix;

sumMix = 1.0;
for(size_t i = 0; i < gasSize; ++i)
Expand All @@ -199,8 +199,8 @@ namespace Gases

lambdaSecondMix += lambdaSecond / sumMix;

cpMix += itGasProperties->m_SpecificHeat * it.fraction()
* itGasProperties->m_MolecularWeight;
cpMix += itGasProperties.m_SpecificHeat * it.fraction()
* itGasProperties.m_MolecularWeight;
++counter;
}

Expand Down Expand Up @@ -252,7 +252,7 @@ namespace Gases
double CGas::viscDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const
{
auto phiValue =
viscTwoGases(*t_GasItem1.getGasProperties(), *t_GasItem2.getGasProperties());
viscTwoGases(t_GasItem1.getGasProperties(), t_GasItem2.getGasProperties());
if((t_GasItem1.fraction() == 0) || (t_GasItem2.fraction() == 0))
{
throw std::runtime_error(
Expand Down Expand Up @@ -319,7 +319,7 @@ namespace Gases
double CGas::lambdaPrimDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const
{
auto phiValue =
lambdaPrimTwoGases(*t_GasItem1.getGasProperties(), *t_GasItem2.getGasProperties());
lambdaPrimTwoGases(t_GasItem1.getGasProperties(), t_GasItem2.getGasProperties());

if((t_GasItem1.fraction() == 0) || (t_GasItem2.fraction() == 0))
{
Expand All @@ -334,7 +334,7 @@ namespace Gases
double CGas::lambdaSecondDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const
{
auto phiValue =
lambdaSecondTwoGases(*t_GasItem1.getGasProperties(), *t_GasItem2.getGasProperties());
lambdaSecondTwoGases(t_GasItem1.getGasProperties(), t_GasItem2.getGasProperties());

if((t_GasItem1.fraction() == 0) || (t_GasItem2.fraction() == 0))
{
Expand Down
15 changes: 8 additions & 7 deletions src/Gases/src/Gas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace Gases
const GasProperties & getGasProperties();
void setTemperatureAndPressure(double t_Temperature, double t_Pressure);

[[nodiscard]] std::vector<CGasItem> gasItems() const;;
[[nodiscard]] std::vector<CGasItem> gasItems() const;
;

CGas & operator=(CGas const & t_Gas);
bool operator==(CGas const & t_Gas) const;
Expand All @@ -37,14 +38,14 @@ namespace Gases
const GasProperties & getStandardPressureGasProperties();
const GasProperties & getVacuumPressureGasProperties();

double viscTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;
[[nodiscard]] double viscTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;
double viscDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const;

double lambdaPrimTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;
double lambdaSecondTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;
[[nodiscard]] double lambdaPrimTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;
[[nodiscard]] double lambdaSecondTwoGases(GasProperties const & t_Gas1Properties,
GasProperties const & t_Gas2Properties) const;

double lambdaPrimDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const;
double lambdaSecondDenomTwoGases(CGasItem & t_GasItem1, CGasItem & t_GasItem2) const;
Expand Down
2 changes: 1 addition & 1 deletion src/Gases/src/GasCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gases
{
Gas & Gas::intance()
Gas & Gas::instance()
{
static Gas instant;
return instant;
Expand Down
4 changes: 2 additions & 2 deletions src/Gases/src/GasCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Gases
class Gas
{
public:
static Gas & intance();
static Gas & instance();

CGasData get(GasDef gasDef) const;
[[nodiscard]] CGasData get(GasDef gasDef) const;

private:
Gas();
Expand Down
14 changes: 14 additions & 0 deletions src/Gases/src/GasData.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <stdexcept>


#include "WCECommon.hpp"
#include "GasProperties.hpp"
#include "GasData.hpp"

Expand Down Expand Up @@ -61,4 +63,16 @@ namespace Gases
return m_gasName;
}

bool CGasData::operator==(const CGasData & rhs) const
{
return m_gasName == rhs.m_gasName && m_molWeight == rhs.m_molWeight
&& m_specificHeatRatio == rhs.m_specificHeatRatio
&& m_Coefficients == rhs.m_Coefficients;
}

bool CGasData::operator!=(const CGasData & rhs) const
{
return !(rhs == *this);
}

} // namespace Gases
3 changes: 3 additions & 0 deletions src/Gases/src/GasData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace Gases
[[nodiscard]] double getSpecificHeatRatio() const;
[[nodiscard]] std::string name() const;

bool operator==(const CGasData & rhs) const;
bool operator!=(const CGasData & rhs) const;

private:
std::string m_gasName;
double m_molWeight;
Expand Down
99 changes: 47 additions & 52 deletions src/Gases/src/GasItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Gases
{
CGasItem::CGasItem() : m_Fraction(1.0), m_GasData(new CGasData())
CGasItem::CGasItem() : m_Fraction(1.0)
{
initialize();
}
Expand All @@ -18,16 +18,13 @@ namespace Gases
m_Temperature(t_GasItem.m_Temperature),
m_Pressure(t_GasItem.m_Pressure),
m_Fraction(t_GasItem.m_Fraction),
m_GasProperties(std::make_shared<GasProperties>()),
m_FractionalGasProperties(std::make_shared<GasProperties>()),
m_GasData(new CGasData(*t_GasItem.m_GasData.get()))
{
(*m_FractionalGasProperties) = (*t_GasItem.m_FractionalGasProperties);
(*m_GasProperties) = (*t_GasItem.m_GasProperties);
}
m_GasProperties(t_GasItem.m_GasProperties),
m_FractionalGasProperties(t_GasItem.m_FractionalGasProperties),
m_GasData(t_GasItem.m_GasData)
{}

CGasItem::CGasItem(double const t_Fraction, CGasData const & t_GasData) :
m_Fraction(t_Fraction), m_GasData(new CGasData(t_GasData))
m_Fraction(t_Fraction), m_GasData(t_GasData)
{
initialize();
}
Expand All @@ -37,66 +34,64 @@ namespace Gases
m_Fraction = t_GasItem.m_Fraction;
m_Pressure = t_GasItem.m_Pressure;
m_Temperature = t_GasItem.m_Temperature;
*m_GasData = *t_GasItem.m_GasData;
(*m_FractionalGasProperties) = (*t_GasItem.m_FractionalGasProperties);
(*m_GasProperties) = (*t_GasItem.m_GasProperties);
m_GasData = t_GasItem.m_GasData;
m_FractionalGasProperties = t_GasItem.m_FractionalGasProperties;
m_GasProperties = t_GasItem.m_GasProperties;

return *this;
}

void CGasItem::fillStandardPressureProperites() const
void CGasItem::fillStandardPressureProperites()
{
using ConstantsData::UNIVERSALGASCONSTANT;
m_GasProperties->m_ThermalConductivity =
m_GasData->getPropertyValue(CoeffType::cCond, m_Temperature);
m_GasProperties->m_Viscosity = m_GasData->getPropertyValue(CoeffType::cVisc, m_Temperature);
m_GasProperties->m_SpecificHeat =
m_GasData->getPropertyValue(CoeffType::cCp, m_Temperature);
m_GasProperties->m_MolecularWeight = m_GasData->getMolecularWeight();
m_GasProperties->m_Density =
m_Pressure * m_GasProperties->m_MolecularWeight / (UNIVERSALGASCONSTANT * m_Temperature);
m_GasProperties->calculateAlphaAndPrandl();
m_GasProperties.m_ThermalConductivity =
m_GasData.getPropertyValue(CoeffType::cCond, m_Temperature);
m_GasProperties.m_Viscosity = m_GasData.getPropertyValue(CoeffType::cVisc, m_Temperature);
m_GasProperties.m_SpecificHeat =
m_GasData.getPropertyValue(CoeffType::cCp, m_Temperature);
m_GasProperties.m_MolecularWeight = m_GasData.getMolecularWeight();
m_GasProperties.m_Density =
m_Pressure * m_GasProperties.m_MolecularWeight / (UNIVERSALGASCONSTANT * m_Temperature);
m_GasProperties.calculateAlphaAndPrandl();
}

void CGasItem::flllVacuumPressureProperties() const
void CGasItem::flllVacuumPressureProperties()
{
using ConstantsData::UNIVERSALGASCONSTANT;
using ConstantsData::WCE_PI;
auto const alpha1 = 0.79;
auto const alpha2 = 0.79;
auto const alpha = alpha1 * alpha2 / (alpha2 + alpha1 * (1 - alpha2));
auto const specificHeatRatio = m_GasData->getSpecificHeatRatio();
auto const specificHeatRatio = m_GasData.getSpecificHeatRatio();
if(specificHeatRatio == 1)
{
throw std::runtime_error("Specific heat ratio of a gas cannot be equal to one.");
}
auto const mWght = m_GasData->getMolecularWeight();
auto const mWght = m_GasData.getMolecularWeight();
auto B = alpha * (specificHeatRatio + 1) / (specificHeatRatio - 1);
B *= sqrt(UNIVERSALGASCONSTANT / (8 * WCE_PI * mWght * m_Temperature));
m_GasProperties->m_ThermalConductivity = B * m_Pressure;
m_GasProperties->m_Viscosity = 0;
m_GasProperties->m_SpecificHeat = 0;
m_GasProperties->m_MolecularWeight = mWght;
m_GasProperties->m_Density = 0;
m_GasProperties.m_ThermalConductivity = B * m_Pressure;
m_GasProperties.m_Viscosity = 0;
m_GasProperties.m_SpecificHeat = 0;
m_GasProperties.m_MolecularWeight = mWght;
m_GasProperties.m_Density = 0;
}

void CGasItem::initialize()
{
m_Temperature = DefaultTemperature;
m_Pressure = DefaultPressure;
m_FractionalGasProperties = std::make_shared<GasProperties>();
m_GasProperties = std::make_shared<GasProperties>();
}

double CGasItem::fraction() const
{
return m_Fraction;
}

void CGasItem::resetCalculatedProperties() const
void CGasItem::resetCalculatedProperties()
{
m_GasProperties->m_PropertiesCalculated = false;
m_FractionalGasProperties->m_PropertiesCalculated = false;
m_GasProperties.m_PropertiesCalculated = false;
m_FractionalGasProperties.m_PropertiesCalculated = false;
}

void CGasItem::setTemperature(double const t_Temperature)
Expand All @@ -111,9 +106,9 @@ namespace Gases
resetCalculatedProperties();
}

std::shared_ptr<GasProperties> CGasItem::getGasProperties() const
GasProperties CGasItem::getGasProperties()
{
if(!m_GasProperties->m_PropertiesCalculated)
if(!m_GasProperties.m_PropertiesCalculated)
{
auto aSettings = CGasSettings::instance();

Expand All @@ -125,30 +120,30 @@ namespace Gases
{
flllVacuumPressureProperties();
}
m_GasProperties->m_PropertiesCalculated = true;
m_GasProperties.m_PropertiesCalculated = true;
}

return m_GasProperties;
}

std::shared_ptr<GasProperties> CGasItem::getFractionalGasProperties() const
GasProperties CGasItem::getFractionalGasProperties()
{
if(!m_FractionalGasProperties->m_PropertiesCalculated)
if(!m_FractionalGasProperties.m_PropertiesCalculated)
{
auto itemGasProperties = getGasProperties();

// update for fractional data
m_FractionalGasProperties->m_ThermalConductivity =
itemGasProperties->m_ThermalConductivity * m_Fraction;
m_FractionalGasProperties->m_Viscosity = itemGasProperties->m_Viscosity * m_Fraction;
m_FractionalGasProperties->m_SpecificHeat =
itemGasProperties->m_SpecificHeat * m_Fraction;
m_FractionalGasProperties->m_MolecularWeight =
itemGasProperties->m_MolecularWeight * m_Fraction;
m_FractionalGasProperties->m_Density = itemGasProperties->m_Density * m_Fraction;
m_FractionalGasProperties->m_Alpha = itemGasProperties->m_Alpha * m_Fraction;
m_FractionalGasProperties->m_PrandlNumber =
itemGasProperties->m_PrandlNumber * m_Fraction;
m_FractionalGasProperties.m_ThermalConductivity =
itemGasProperties.m_ThermalConductivity * m_Fraction;
m_FractionalGasProperties.m_Viscosity = itemGasProperties.m_Viscosity * m_Fraction;
m_FractionalGasProperties.m_SpecificHeat =
itemGasProperties.m_SpecificHeat * m_Fraction;
m_FractionalGasProperties.m_MolecularWeight =
itemGasProperties.m_MolecularWeight * m_Fraction;
m_FractionalGasProperties.m_Density = itemGasProperties.m_Density * m_Fraction;
m_FractionalGasProperties.m_Alpha = itemGasProperties.m_Alpha * m_Fraction;
m_FractionalGasProperties.m_PrandlNumber =
itemGasProperties.m_PrandlNumber * m_Fraction;
}

return m_FractionalGasProperties;
Expand All @@ -169,7 +164,7 @@ namespace Gases

std::string CGasItem::name() const
{
return m_GasData->name();
return m_GasData.name();
}

} // namespace Gases
Loading

0 comments on commit 9713915

Please sign in to comment.