Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Control/Inciter/OutVar.hpp 4 : : \copyright 2012-2015 J. Bakosi, 5 : : 2016-2018 Los Alamos National Security, LLC., 6 : : 2019-2021 Triad National Security, LLC. 7 : : All rights reserved. See the LICENSE file for details. 8 : : \brief Types and associated functions to deal with output variables 9 : : \details Types and associated functions to deal with output variables. 10 : : */ 11 : : // ***************************************************************************** 12 : : #ifndef OutVar_h 13 : : #define OutVar_h 14 : : 15 : : #include "Types.hpp" 16 : : #include "Centering.hpp" 17 : : #include "Options/PDE.hpp" 18 : : 19 : : namespace inciter { 20 : : namespace ctr { 21 : : 22 : : //! Output variable 23 : : struct OutVar { 24 : : using Centering = tk::Centering; 25 : : 26 : : Centering centering; //!< Centering 27 : : std::string name; //!< Human readable name 28 : : tk::ncomp_t field; //!< Field ID 29 : : std::string varFnIdx; //!< Material-based physics label + material id 30 : : 31 : : //! Constructor: initialize all state data 32 : : //! \param[in] n Human readable name 33 : : //! \param[in] f Field ID 34 : : //! \param[in] c Variable centering 35 : : //! \param[in] vn Var function name 36 : 1479 : explicit OutVar( Centering c = Centering::NODE, 37 : : const std::string& n = {}, 38 : : tk::ncomp_t f = 0, 39 : 1479 : const std::string& vn = "null" ) : 40 [ + - ]: 2958 : centering(c), name(n), field(f), varFnIdx(vn) {} 41 : : 42 : : /** @name Pack/Unpack: Serialize OutVar object for Charm++ */ 43 : : ///@{ 44 : : //! Pack/Unpack serialize member function 45 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference 46 : 2653 : void pup( PUP::er& p ) { 47 : 2653 : p | centering; 48 : 2653 : p | name; 49 : 2653 : p | field; 50 : 2653 : p | varFnIdx; 51 : 2653 : } 52 : : //! Pack/Unpack serialize operator| 53 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference 54 : : //! \param[in,out] v OutVar object reference 55 [ + - ]: 2653 : friend void operator|( PUP::er& p, OutVar& v ) { v.pup(p); } 56 : : ///@} 57 : : 58 : : //! Query if outvar is a request for an analytic solution 59 : : //! \return True if outvar is a request for an analytic solution 60 : 56152 : bool analytic() const { return name.find("analytic") != std::string::npos; } 61 : : 62 : : //! Query if outvar is a request for a primitive variable 63 : : //! \param[in] iPDE PDE type 64 : : //! \return True if outvar should be extracted from primitive variable data 65 : : //! \details This function returns whether the requested variable is a part 66 : : //! of the vector of primitive variables. This changes according to which 67 : : //! system of PDEs is configured. 68 : 12769 : bool primitive( const PDEType& iPDE ) const { 69 : : bool is_prim(false); 70 : : 71 [ + + ]: 12769 : if (iPDE == PDEType::MULTISPECIES) { 72 [ - + ]: 1232 : if (varFnIdx.find("temperature") != std::string::npos) 73 : : { is_prim = true; } 74 : : } 75 : : else { 76 [ + + ]: 21217 : if (varFnIdx.find("pressure") != std::string::npos || 77 [ + + ][ + - ]: 15820 : varFnIdx.find("velocity") != std::string::npos || 78 : : varFnIdx.find("stress") != std::string::npos ) 79 : : { is_prim = true; } 80 [ + + ][ + - ]: 4907 : else if ( name.length() == 2 && 81 [ + - ]: 1248 : (name.find('u') != std::string::npos || 82 [ + - ]: 1248 : name.find('U') != std::string::npos || 83 [ - + ]: 1248 : name.find('p') != std::string::npos || 84 : 624 : name.find('P') != std::string::npos) ) 85 : : { is_prim = true; } 86 : : } 87 : : 88 : 12769 : return is_prim; 89 : : } 90 : : }; 91 : : 92 : : //! \brief Pack/Unpack: Namespace-scope serialize OutVar object for Charm++ 93 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference 94 : : //! \param[in,out] v OutVar object reference 95 : : inline void pup( PUP::er& p, OutVar& v ) { v.pup(p); } 96 : : 97 : : #if defined(__clang__) 98 : : #pragma clang diagnostic push 99 : : #pragma clang diagnostic ignored "-Wunused-function" 100 : : #endif 101 : : 102 : : //! Operator << for writing OutVar to output streams 103 : : //! \param[in,out] os Output stream to write to 104 : : //! \param[in] outvar OutVar to write 105 : : //! \return Updated output stream 106 [ - + ]: 596 : static std::ostream& operator<< ( std::ostream& os, const OutVar& outvar ) { 107 [ - + ]: 596 : if (outvar.name.empty()) 108 : 0 : os << outvar.field+1; 109 : : else 110 : : os << outvar.name; 111 : 596 : return os; 112 : : } 113 : : 114 : : #if defined(__clang__) 115 : : #pragma clang diagnostic pop 116 : : #endif 117 : : 118 : : } // ctr:: 119 : : } // inciter:: 120 : : 121 : : #endif // OutVar_h