1 //-----------------------------------------------------------------------bl- 2 //-------------------------------------------------------------------------- 3 // 4 // Antioch - A Gas Dynamics Thermochemistry Library 5 // 6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk, 7 // Sylvain Plessis, Roy H. Stonger 8 // 9 // Copyright (C) 2013 The PECOS Development Team 10 // 11 // This library is free software; you can redistribute it and/or 12 // modify it under the terms of the Version 2.1 GNU Lesser General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This library is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 // Lesser General Public License for more details. 19 // 20 // You should have received a copy of the GNU Lesser General Public 21 // License along with this library; if not, write to the Free Software 22 // Foundation, Inc. 51 Franklin Street, Fifth Floor, 23 // Boston, MA 02110-1301 USA 24 // 25 //-----------------------------------------------------------------------el- 26 // 27 // $Id$ 28 // 29 //-------------------------------------------------------------------------- 30 //-------------------------------------------------------------------------- 31 32 #ifndef ANTIOCH_MIXTURE_VISCOSITY_H 33 #define ANTIOCH_MIXTURE_VISCOSITY_H 34 35 // Antioch 36 #include "antioch/antioch_asserts.h" 37 #include "antioch/mixture_transport_base.h" 38 #include "antioch/species_viscosity_base.h" 39 // C++ 40 #include <string> 41 #include <vector> 42 43 namespace Antioch 44 { 45 //! Container class for species viscosities 46 /*! For the given set of chemical species in the input TransportMixture, this contains 47 all the viscosities for each of those species and provides and interface for 48 computing the species viscosity. Total viscosity is computed by a mixing model, 49 e.g. MixtureAveragedTransportMixture. This class is templated on the viscosity model, 50 so an inherent assumption is that all species viscosities have the same model. */ 51 template<typename Viscosity, class CoeffType=double> 52 class MixtureViscosity : public MixtureTransportBase<CoeffType> 53 { 54 public: 55 56 MixtureViscosity( const TransportMixture<CoeffType>& transport_mixture ); 57 ~MixtureViscosity(); 58 59 //! Evaluate viscosity for species s 60 /*! Total viscosity computed by mixing model, e.g. MixtureAveragedTransportEvaluator */ 61 template <typename StateType> 62 StateType operator()( const unsigned int s, const StateType& T ) const; 63 64 //! Add species viscosity 65 void add( const std::string& species_name, 66 const std::vector<CoeffType>& coeffs ); 67 68 //! Reset model coefficients for viscosity model of species s 69 void reset_coeffs( const unsigned int s, 70 const std::vector<CoeffType> coeffs ); 71 72 //! Extrapolate to input maximum temperature, given in [K] 73 /*! 74 * For certain species viscosity models, interpolation of various quantities may be 75 * done based on the temperature. This method will use linear extrapolation to extend 76 * the range of temperature for all the species viscosity models. 77 */ 78 template <typename StateType> 79 void extrapolate_max_temp(const StateType& Tmax); 80 81 const std::vector<SpeciesViscosityBase<Viscosity,CoeffType>*> & 82 species_viscosities() const; 83 84 //! Formatted print, by default to \p std::cout 85 void print(std::ostream& os = std::cout) const; 86 87 //! Formatted print. 88 friend std::ostream& operator<<(std::ostream& os, const MixtureViscosity& mu) 89 { 90 mu.print(os); 91 return os; 92 } 93 94 typedef Viscosity species_viscosity_type; 95 96 protected: 97 98 std::vector<SpeciesViscosityBase<Viscosity,CoeffType>*> _species_viscosities; 99 100 private: 101 102 MixtureViscosity(); 103 104 }; 105 106 template<typename Viscosity, class CoeffType> MixtureViscosity(const TransportMixture<CoeffType> & transport_mixture)107 MixtureViscosity<Viscosity,CoeffType>::MixtureViscosity( const TransportMixture<CoeffType>& transport_mixture ) 108 : MixtureTransportBase<CoeffType>(transport_mixture), 109 _species_viscosities( transport_mixture.n_species(), NULL ) 110 {} 111 112 template<typename Viscosity, class CoeffType> ~MixtureViscosity()113 MixtureViscosity<Viscosity,CoeffType>::~MixtureViscosity() 114 { 115 // Need to delete all the species viscosities we allocated 116 for( typename std::vector<SpeciesViscosityBase<Viscosity,CoeffType>*>::iterator it = _species_viscosities.begin(); 117 it != _species_viscosities.end(); ++it ) 118 { 119 delete (*it); 120 } 121 } 122 123 template<typename Viscosity, class CoeffType> add(const std::string & species_name,const std::vector<CoeffType> & coeffs)124 void MixtureViscosity<Viscosity,CoeffType>::add( const std::string& species_name, 125 const std::vector<CoeffType>& coeffs ) 126 { 127 antioch_assert( this->_transport_mixture.species_name_map().find(species_name) != 128 this->_transport_mixture.species_name_map().end() ); 129 130 unsigned int s = this->_transport_mixture.species_name_map().find(species_name)->second; 131 132 antioch_assert_less_equal( s, _species_viscosities.size() ); 133 antioch_assert( !_species_viscosities[s] ); 134 135 _species_viscosities[s] = new Viscosity(coeffs); 136 return; 137 } 138 139 template<typename Viscosity, class CoeffType> reset_coeffs(const unsigned int s,const std::vector<CoeffType> coeffs)140 void MixtureViscosity<Viscosity,CoeffType>::reset_coeffs( const unsigned int s, 141 const std::vector<CoeffType> coeffs ) 142 { 143 _species_viscosities[s]->reset_coeffs(coeffs); 144 } 145 146 template<typename Viscosity, class CoeffType> 147 template<typename StateType> 148 inline operator()149 StateType MixtureViscosity<Viscosity,CoeffType>::operator()( const unsigned int s, 150 const StateType& T ) const 151 { 152 antioch_assert_less_equal( s, _species_viscosities.size() ); 153 antioch_assert( _species_viscosities[s] ); 154 155 return (*_species_viscosities[s])(T); 156 } 157 158 template<typename Viscosity, class CoeffType> 159 template <typename StateType> 160 inline extrapolate_max_temp(const StateType & Tmax)161 void MixtureViscosity<Viscosity,CoeffType>::extrapolate_max_temp(const StateType& Tmax) 162 { 163 for( typename std::vector<SpeciesViscosityBase<Viscosity,CoeffType>*>::iterator it = _species_viscosities.begin(); 164 it != _species_viscosities.end(); ++it ) 165 { 166 (*it)->extrapolate_max_temp(Tmax); 167 } 168 } 169 170 template<typename Viscosity, class CoeffType> 171 inline 172 const std::vector<SpeciesViscosityBase<Viscosity,CoeffType>*> & species_viscosities()173 MixtureViscosity<Viscosity,CoeffType>::species_viscosities() const 174 { 175 return _species_viscosities; 176 } 177 178 template<typename Viscosity, class CoeffType> print(std::ostream & os)179 void MixtureViscosity<Viscosity,CoeffType>::print(std::ostream& os) const 180 { 181 antioch_assert_equal_to( _species_viscosities.size(), this->_transport_mixture.n_species() ); 182 183 for( unsigned int s = 0; s < this->_transport_mixture.n_species(); s++ ) 184 { 185 const Species& species = this->_transport_mixture.species_list()[s]; 186 const std::string& name = this->_transport_mixture.species_inverse_name_map().find( species )->second; 187 188 os << "mu(" << name << ") = " << (*_species_viscosities[s]) << std::endl; 189 } 190 191 return; 192 } 193 194 } // end namespace Antioch 195 196 #endif // ANTIOCH_MIXTURE_VISCOSITY_H 197