diff --git a/src/Common/src/Utility.hpp b/src/Common/src/Utility.hpp index 3ca5540c..367d9169 100644 --- a/src/Common/src/Utility.hpp +++ b/src/Common/src/Utility.hpp @@ -15,4 +15,11 @@ namespace FenestrationCommon std::vector chunkIt(size_t start, size_t end, size_t numberOfSplits); size_t getNumberOfThreads(size_t numberOfJobs); + + template + bool map_compare (Map const &lhs, Map const &rhs) { + return lhs.size() == rhs.size() + && std::equal(lhs.begin(), lhs.end(), + rhs.begin()); + } } \ No newline at end of file diff --git a/src/Gases/src/Gas.cpp b/src/Gases/src/Gas.cpp index f65cf713..55602b02 100644 --- a/src/Gases/src/Gas.cpp +++ b/src/Gases/src/Gas.cpp @@ -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() @@ -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; @@ -172,8 +172,8 @@ 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) @@ -181,7 +181,7 @@ namespace Gases 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) @@ -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; } @@ -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( @@ -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)) { @@ -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)) { diff --git a/src/Gases/src/Gas.hpp b/src/Gases/src/Gas.hpp index 978d3383..c29f1b63 100644 --- a/src/Gases/src/Gas.hpp +++ b/src/Gases/src/Gas.hpp @@ -27,7 +27,8 @@ namespace Gases const GasProperties & getGasProperties(); void setTemperatureAndPressure(double t_Temperature, double t_Pressure); - [[nodiscard]] std::vector gasItems() const;; + [[nodiscard]] std::vector gasItems() const; + ; CGas & operator=(CGas const & t_Gas); bool operator==(CGas const & t_Gas) const; @@ -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; diff --git a/src/Gases/src/GasCreator.cpp b/src/Gases/src/GasCreator.cpp index 843a320c..945bce54 100644 --- a/src/Gases/src/GasCreator.cpp +++ b/src/Gases/src/GasCreator.cpp @@ -2,7 +2,7 @@ namespace Gases { - Gas & Gas::intance() + Gas & Gas::instance() { static Gas instant; return instant; diff --git a/src/Gases/src/GasCreator.hpp b/src/Gases/src/GasCreator.hpp index f2f43320..b3801681 100644 --- a/src/Gases/src/GasCreator.hpp +++ b/src/Gases/src/GasCreator.hpp @@ -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(); diff --git a/src/Gases/src/GasData.cpp b/src/Gases/src/GasData.cpp index 5a951b4d..76c43ec7 100644 --- a/src/Gases/src/GasData.cpp +++ b/src/Gases/src/GasData.cpp @@ -1,5 +1,7 @@ #include + +#include "WCECommon.hpp" #include "GasProperties.hpp" #include "GasData.hpp" @@ -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 diff --git a/src/Gases/src/GasData.hpp b/src/Gases/src/GasData.hpp index fd10d464..c1807340 100644 --- a/src/Gases/src/GasData.hpp +++ b/src/Gases/src/GasData.hpp @@ -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; diff --git a/src/Gases/src/GasItem.cpp b/src/Gases/src/GasItem.cpp index daa4cb29..589d473e 100644 --- a/src/Gases/src/GasItem.cpp +++ b/src/Gases/src/GasItem.cpp @@ -9,7 +9,7 @@ namespace Gases { - CGasItem::CGasItem() : m_Fraction(1.0), m_GasData(new CGasData()) + CGasItem::CGasItem() : m_Fraction(1.0) { initialize(); } @@ -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()), - m_FractionalGasProperties(std::make_shared()), - 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(); } @@ -37,55 +34,53 @@ 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(); - m_GasProperties = std::make_shared(); } double CGasItem::fraction() const @@ -93,10 +88,10 @@ namespace Gases 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) @@ -111,9 +106,9 @@ namespace Gases resetCalculatedProperties(); } - std::shared_ptr CGasItem::getGasProperties() const + GasProperties CGasItem::getGasProperties() { - if(!m_GasProperties->m_PropertiesCalculated) + if(!m_GasProperties.m_PropertiesCalculated) { auto aSettings = CGasSettings::instance(); @@ -125,30 +120,30 @@ namespace Gases { flllVacuumPressureProperties(); } - m_GasProperties->m_PropertiesCalculated = true; + m_GasProperties.m_PropertiesCalculated = true; } return m_GasProperties; } - std::shared_ptr 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; @@ -169,7 +164,7 @@ namespace Gases std::string CGasItem::name() const { - return m_GasData->name(); + return m_GasData.name(); } } // namespace Gases diff --git a/src/Gases/src/GasItem.hpp b/src/Gases/src/GasItem.hpp index d0130de6..6bdb1022 100644 --- a/src/Gases/src/GasItem.hpp +++ b/src/Gases/src/GasItem.hpp @@ -4,11 +4,11 @@ #include #include +#include "GasData.hpp" +#include "GasProperties.hpp" + namespace Gases { - class CGasData; - struct GasProperties; - double const DefaultPressure = 101325; double const DefaultTemperature = 273.15; @@ -22,24 +22,24 @@ namespace Gases void setTemperature(double t_Temperature); void setPressure(double t_Pressure); [[nodiscard]] double fraction() const; - [[nodiscard]] std::shared_ptr getFractionalGasProperties() const; - [[nodiscard]] std::shared_ptr getGasProperties() const; + [[nodiscard]] GasProperties getFractionalGasProperties(); + [[nodiscard]] GasProperties getGasProperties(); bool operator==(CGasItem const & rhs) const; bool operator!=(CGasItem const & rhs) const; [[nodiscard]] std::string name() const; private: - void fillStandardPressureProperites() const; - void flllVacuumPressureProperties() const; + void fillStandardPressureProperites(); + void flllVacuumPressureProperties(); void initialize(); - void resetCalculatedProperties() const; + void resetCalculatedProperties(); double m_Temperature; // unit in Kelvins double m_Pressure; // unit in Pa double m_Fraction; // value between 0 and 1 - std::shared_ptr m_GasProperties; - std::shared_ptr m_FractionalGasProperties; - std::unique_ptr m_GasData; + GasProperties m_GasProperties; + GasProperties m_FractionalGasProperties; + CGasData m_GasData; }; } // namespace Gases diff --git a/src/Gases/src/GasProperties.cpp b/src/Gases/src/GasProperties.cpp index fc952df6..1f592405 100644 --- a/src/Gases/src/GasProperties.cpp +++ b/src/Gases/src/GasProperties.cpp @@ -36,6 +36,17 @@ namespace Gases return *this; } + bool CIntCoeff::operator==(const CIntCoeff & rhs) const + { + using FenestrationCommon::isEqual; + return isEqual(m_A, rhs.m_A) && isEqual(m_B, rhs.m_B) && isEqual(m_C, rhs.m_C); + } + + bool CIntCoeff::operator!=(const CIntCoeff & rhs) const + { + return !(rhs == *this); + } + //////////////////////////////////////////////////////////////////////////////////////////// // GasProperties //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Gases/src/GasProperties.hpp b/src/Gases/src/GasProperties.hpp index 6620e53b..3173fd21 100644 --- a/src/Gases/src/GasProperties.hpp +++ b/src/Gases/src/GasProperties.hpp @@ -1,5 +1,4 @@ -#ifndef GASPROPERTIES_H -#define GASPROPERTIES_H +#pragma once namespace Gases { @@ -14,11 +13,14 @@ namespace Gases { public: CIntCoeff(); - CIntCoeff(double const t_A, double const t_B, double const t_C); - double interpolationValue(double const t_Temperature) const; + CIntCoeff(double t_A, double t_B, double t_C); + [[nodiscard]] double interpolationValue(double t_Temperature) const; CIntCoeff(CIntCoeff const & t_IntCoeff); CIntCoeff & operator=(CIntCoeff const & t_IntCoeff); + bool operator==(const CIntCoeff & rhs) const; + bool operator!=(const CIntCoeff & rhs) const; + private: double m_A; double m_B; @@ -40,8 +42,8 @@ namespace Gases GasProperties(GasProperties const & t_GasProperties); - double getLambdaPrim() const; - double getLambdaSecond() const; + [[nodiscard]] double getLambdaPrim() const; + [[nodiscard]] double getLambdaSecond() const; GasProperties & operator+(const GasProperties & t_A); GasProperties & operator+=(const GasProperties & t_A); GasProperties & operator=(const GasProperties & t_A); @@ -59,5 +61,3 @@ namespace Gases }; } // namespace Gases - -#endif diff --git a/src/Gases/src/GasSetting.hpp b/src/Gases/src/GasSetting.hpp index a3c6cd92..8b4eba3c 100644 --- a/src/Gases/src/GasSetting.hpp +++ b/src/Gases/src/GasSetting.hpp @@ -1,5 +1,4 @@ -#ifndef GASSETTING_H -#define GASSETTING_H +#pragma once namespace Gases { @@ -8,8 +7,8 @@ namespace Gases public: static CGasSettings & instance(); - double getVacuumPressure() const; - void setVacuumPressure(double const t_Value); + [[nodiscard]] double getVacuumPressure() const; + void setVacuumPressure(double t_Value); private: CGasSettings(); @@ -20,5 +19,3 @@ namespace Gases }; } // namespace Gases - -#endif