From ca73a502f6f99f1d8dc4dc6f13cb533af3f07893 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong @ vulgaris" Date: Sun, 13 Nov 2016 20:21:55 +0100 Subject: [PATCH] Put T0 and p in Gas class. Updated Globalconf --- src/CMakeLists.txt | 2 +- src/material/air.h | 2 +- src/material/gas.cpp | 16 +++++++--- src/material/gas.h | 32 +++++++++++++------- src/material/helium.h | 2 +- src/material/nitrogen.h | 2 +- src/material/perfectgas.h | 2 +- src/sys/globalconf.cpp | 63 +++++++++++++++++++++++++++++++++++++++ src/sys/globalconf.h | 54 +++++++++++++++++++++++++++++++++ 9 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 src/sys/globalconf.cpp create mode 100644 src/sys/globalconf.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8d7204..2966575 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,7 @@ add_subdirectory(material) # add_subdirectory(mech) # add_subdirectory(seg) # add_subdirectory(sol) -# add_subdirectory(sys) +add_subdirectory(sys) # add_subdirectory(var) add_library(tasmet_src tasmet_tracer.cpp tasmet_exception.cpp tasmet_assert.cpp) diff --git a/src/material/air.h b/src/material/air.h index 1fa221d..8177768 100644 --- a/src/material/air.h +++ b/src/material/air.h @@ -15,7 +15,7 @@ class Air : public PerfectGas { protected: d Rs() const {return 287;} public: - Air():PerfectGas(air){} + Air(d T0,d p0):PerfectGas(air,T0,p0){} d cp(d T,d p) const; vd cp(const vd& T,const vd& p) const; d h(d T,d p) const; diff --git a/src/material/gas.cpp b/src/material/gas.cpp index f398d8a..943d860 100644 --- a/src/material/gas.cpp +++ b/src/material/gas.cpp @@ -12,16 +12,24 @@ #include "air.h" #include "nitrogen.h" -Gas* Gas::newGas(const GasType gastype) { +#include "tasmet_constants.h" + +Gas* Gas::newGas(const GasType gastype,d T0,d p0) { + + if(T0>constants::maxT || T0< constants::minT) + throw TaSMETError("Illegal reference temperature given"); + if(p0>constants::maxp || p0< constants::minp) + throw TaSMETError("Illegal reference pressure given"); + // End sanity checks switch (gastype) { case helium: - return new Helium(); + return new Helium(T0,p0); break; case air: - return new Air(); + return new Air(T0,p0); case nitrogen: - return new Nitrogen(); + return new Nitrogen(T0,p0); default: FATAL("Gas type not known"); break; diff --git a/src/material/gas.h b/src/material/gas.h index 3a401bc..3aba24b 100644 --- a/src/material/gas.h +++ b/src/material/gas.h @@ -12,7 +12,7 @@ #include #include "tasmet_enum.h" #include "tasmet_types.h" - +#include "tasmet_constants.h" class Gas{ @@ -21,19 +21,31 @@ public: private: GasType _gastype; protected: - Gas(GasType gastype):_gastype(gastype){} + d _T0,_p0; /* Reference temperature and pressure */ + + Gas(GasType gastype,d T0,d p0):_gastype(gastype),_T0(T0),_p0(p0){} public: - - - Gas(const Gas& other) =delete; Gas& operator=(const Gas&)=delete; virtual ~Gas(){} // Static method to generate a Gas - static Gas* newGas(const GasType gastype); + + + static Gas* newGas(const GasType gastype,d T0=constants::T0, + d p0=constants::p0); + operator GasType() { return _gastype;} + d T0() const {return _T0;} + d p0() const {return _p0;} + + // Speed of sound at the reference temperature and pressure + d c0() const {return cm(_T0,_p0);} + d rho0() const {return rho(_T0,_p0);} + d deltanu0(d freq) const{ return sqrt(2*mu(_T0,_p0)/(rho0()*2*number_pi*freq));} + d deltanu(d freq,d T,d p) const { return sqrt(2*mu(T,p)/(rho(T,p)*2*number_pi*freq)); } + // Dimensionless numbers: // Specific heat ratio @@ -49,6 +61,10 @@ public: virtual d rho(d T,d p) const=0; virtual vd rho(const vd& T,const vd& p) const=0; + // Adiabatic speed of sound + virtual d cm(d T,d p) const=0; + virtual vd cm(const vd& T,const vd& p) const=0; + // Internal energy [J/kg] virtual d e(d T,d p) const=0; virtual vd e(const vd& T,const vd& p) const=0; @@ -68,10 +84,6 @@ public: virtual d beta(d T,d p) const=0; virtual vd beta(const vd& T,const vd& p) const=0; - // Adiabatic speed of sound [m/s] - virtual d cm(d T,d p) const=0; - virtual vd cm(const vd& T,const vd& p) const=0; - // Dynamic viscosity [Pa*s] virtual d mu(d T,d p) const=0; virtual vd mu(const vd& T,const vd& p) const=0; diff --git a/src/material/helium.h b/src/material/helium.h index a422dc5..714e254 100644 --- a/src/material/helium.h +++ b/src/material/helium.h @@ -14,7 +14,7 @@ class Helium :public PerfectGas { protected: d Rs() const {return 2070;} public: - Helium():PerfectGas(helium){} + Helium(d T0,d p0):PerfectGas(helium,T0,p0){} d cp(d T,d p) const { return 5195;} vd cp(const vd& T,const vd& p) const; diff --git a/src/material/nitrogen.h b/src/material/nitrogen.h index c0fefb3..9e5068f 100644 --- a/src/material/nitrogen.h +++ b/src/material/nitrogen.h @@ -16,7 +16,7 @@ class Nitrogen : public PerfectGas { protected: d Rs() const {return 297;} public: - Nitrogen():PerfectGas(nitrogen){} + Nitrogen(d T0,d p0):PerfectGas(nitrogen,T0,p0){} d cp(d T,d p) const; vd cp(const vd& T,const vd& p) const; diff --git a/src/material/perfectgas.h b/src/material/perfectgas.h index 5ec3258..226be17 100644 --- a/src/material/perfectgas.h +++ b/src/material/perfectgas.h @@ -23,7 +23,7 @@ class PerfectGas: public Gas { protected: - PerfectGas(GasType gastype): Gas(gastype){} + PerfectGas(GasType gastype,d T0,d p0): Gas(gastype,T0,p0){} // Not implemented for a perfect gas: // mu, kappa, h, cp, Rs diff --git a/src/sys/globalconf.cpp b/src/sys/globalconf.cpp new file mode 100644 index 0000000..9a5557d --- /dev/null +++ b/src/sys/globalconf.cpp @@ -0,0 +1,63 @@ +#include "globalconf.h" +#include "tasmet_constants.h" +#include "tasmet_exception.h" +#include "tasmet_io.h" + +Globalconf::Globalconf(us Nf,d freq) + +{ + + set(Nf,freq); + TRACE(10,"Globalconf constructor done"); +} +void Globalconf::show() const { + cout << "------- Global configuration ------ \n"; + cout << "------- Number of harmonics to solve for: "<< _Nf <<"\n"; + cout << "------- Fundamental frequency : " << _omg/2/number_pi << " Hz\n"; +} +void Globalconf::set(us Nf,d freq){ + TRACE(15,"Globalconf::set(_Nf,freq)"); + d omg = 2*number_pi*freq; + //ctor + // Sanity checks + if(omgconstants::maxomg) + throw TaSMETError("Illegal frequency given"); + if(Nf>=constants::maxNf) + throw TaSMETError("Too large number of frequencies given"); + + this->_Nf=Nf; + this->_omg=omg; + + us Ns=this->Ns(); + // Reinitialize all operators + iDFT_=zeros(Ns,Ns); + fDFT_=zeros(Ns,Ns); + + DDTfd_=zeros(Ns,Ns); + fDFT_.row(0).fill(1.0/double(Ns)); + + for(us i=1;i<=_Nf;i++){ + for(us j=0; j