LCOV - code coverage report
Current view: top level - src/massDistribution - ConstantDensity.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 74 89 83.1 %
Date: 2024-04-29 14:43:01 Functions: 18 19 94.7 %

          Line data    Source code
       1             : #include "crpropa/massDistribution/ConstantDensity.h"
       2             : 
       3             : #include "kiss/logger.h"
       4             : 
       5             : #include <sstream>
       6             : 
       7             : namespace crpropa{
       8             : 
       9           3 : ConstantDensity::ConstantDensity(double HI, double HII, double H2) {
      10             :         // set all types active which are not equal 0 and change number density
      11           3 :         if(HI!=0)
      12           3 :                 setHI(true, HI);
      13           3 :         if(HII!=0)
      14           3 :                 setHII(true, HII);
      15           3 :         if(H2!=0)
      16           3 :                 setH2(true, H2);
      17           3 : }
      18             : 
      19           4 : double ConstantDensity::getDensity(const Vector3d &position) const {
      20             :         double n = 0;
      21             : 
      22           4 :         if(isHI)
      23           3 :                 n += HIdensitynumber;
      24           4 :         if(isHII)
      25           3 :                 n += HIIdensitynumber;
      26           4 :         if(isH2)
      27           3 :                 n += H2densitynumber;
      28             : 
      29             :         // check if all densities are deactivated and raise warning if so
      30           4 :         if((isHI || isHII || isH2) == false){
      31           2 :                 KISS_LOG_WARNING
      32           1 :                         << "\nCalled getNucleonDensity on fully deactivated ConstantDensity "
      33           1 :                         << "gas density model. In this case the density is allways set to 0. \n";
      34             :         }
      35             : 
      36           4 :         return n;
      37             : }
      38             : 
      39           4 : double ConstantDensity::getNucleonDensity(const Vector3d &position) const {
      40             :         double n = 0;
      41             : 
      42           4 :         if(isHI)
      43           3 :                 n += HIdensitynumber;
      44           4 :         if(isHII)
      45           3 :                 n += HIIdensitynumber;
      46           4 :         if(isH2)
      47           3 :                 n += 2*H2densitynumber;
      48             : 
      49             :         // check if all densities are deactivated and raise warning if so
      50           4 :         if((isHI || isHII || isH2) == false){
      51           2 :                 KISS_LOG_WARNING
      52           1 :                         << "\nCalled getNucleonDensity on fully deactivated ConstantDensity "
      53           1 :                         << "gas density model. In this case the density is allways set to 0. \n";
      54             :         }
      55           4 :         return n;
      56             : }
      57             : 
      58           4 : double ConstantDensity::getHIDensity(const Vector3d &position) const {
      59           4 :         return HIdensitynumber;
      60             : }
      61             : 
      62           4 : double ConstantDensity::getHIIDensity(const Vector3d &position) const{
      63           4 :         return HIIdensitynumber;
      64             : }
      65             : 
      66           4 : double ConstantDensity::getH2Density(const Vector3d &position) const{
      67           4 :         return H2densitynumber;
      68             : }
      69             : 
      70           2 : bool ConstantDensity::getIsForHI() {
      71           2 :         return isHI;
      72             : }
      73             : 
      74           2 : bool ConstantDensity::getIsForHII() {
      75           2 :         return isHII;
      76             : }
      77             : 
      78           2 : bool ConstantDensity::getIsForH2() {
      79           2 :         return isH2;
      80             : }
      81             : 
      82           5 : void ConstantDensity::setHI(bool activate, double densitynumber) {
      83           5 :         isHI = activate;
      84           5 :         HIdensitynumber = densitynumber;
      85           5 : }
      86             : 
      87           1 : void ConstantDensity::setHI(bool activate) {
      88           1 :         setHI(activate, HIdensitynumber);
      89           1 : }
      90             : 
      91           1 : void ConstantDensity::setHI(double densitynumber) {
      92           1 :         setHI(isHI, densitynumber);
      93           1 : }
      94             : 
      95           5 : void ConstantDensity::setHII(bool activate, double densitynumber) {
      96           5 :         isHII = activate;
      97           5 :         HIIdensitynumber = densitynumber;
      98           5 : }
      99             : 
     100           1 : void ConstantDensity::setHII(bool activate) {
     101           1 :         setHII(activate, HIIdensitynumber);
     102           1 : }
     103             : 
     104           1 : void ConstantDensity::setHII(double densitynumber) {
     105           1 :         setHII(isHII, densitynumber);
     106           1 : }
     107             : 
     108           5 : void ConstantDensity::setH2(bool activate, double densitynumber) {
     109           5 :         isH2 = activate;
     110           5 :         H2densitynumber = densitynumber;
     111           5 : }
     112             : 
     113           1 : void ConstantDensity::setH2(bool activate) {
     114           1 :         setH2(activate, H2densitynumber);
     115           1 : }
     116             : 
     117           1 : void ConstantDensity::setH2(double densitynumber) {
     118           1 :         setH2(isH2, densitynumber);
     119           1 : }
     120             : 
     121           0 : std::string ConstantDensity::getDescription() {
     122           0 :         std::stringstream s;
     123           0 :         s << "ConstantDensity:\n";
     124           0 :         s<< "HI component is ";
     125           0 :         if(!isHI)
     126           0 :                 s<< "not ";
     127           0 :         s<< "active and has a density of " << HIdensitynumber/ccm << " cm^-3" << "\nHII component is ";
     128           0 :         if(!isHII)
     129           0 :                 s<< "not ";
     130           0 :         s<<"active and has a density of " << HIIdensitynumber/ccm<<" cm^-3" <<  "\nH2 component is ";
     131           0 :         if(!isH2)
     132           0 :                 s<<"not ";
     133           0 :         s<<"active and has a density of " << H2densitynumber/ccm << " cm^-3";
     134           0 :         return s.str();
     135           0 : }
     136             : 
     137             : }  // namespace crpropa

Generated by: LCOV version 1.14