LCOV - code coverage report
Current view: top level - src/BC - Constant.cpp (source / functions) Coverage Total Hit
Test: coverage_merged.info Lines: 47.4 % 116 55
Test Date: 2025-02-27 04:17:48 Functions: 45.5 % 11 5

            Line data    Source code
       1              : #include "Constant.H"
       2              : 
       3              : namespace BC
       4              : {
       5              : 
       6              : 
       7            0 : Constant::Constant (int a_ncomp,
       8              :             amrex::Vector<std::string> bc_hi_str,
       9              :             amrex::Vector<std::string> bc_lo_str,
      10              :             AMREX_D_DECL(amrex::Vector<amrex::Real> _bc_lo_1,
      11              :                         amrex::Vector<amrex::Real> _bc_lo_2,
      12              :                         amrex::Vector<amrex::Real> _bc_lo_3),
      13              :             AMREX_D_DECL(amrex::Vector<amrex::Real> _bc_hi_1,
      14              :                         amrex::Vector<amrex::Real> _bc_hi_2,
      15            0 :                         amrex::Vector<amrex::Real> _bc_hi_3))
      16              :     //: 
      17              :     //AMREX_D_DECL(bc_lo_1(_bc_lo_1),bc_lo_2(_bc_lo_2),bc_lo_3(_bc_lo_3)),
      18              :     //AMREX_D_DECL(bc_hi_1(_bc_hi_1),bc_hi_2(_bc_hi_2),bc_hi_3(_bc_hi_3))
      19              : {
      20            0 :     Util::Warning(INFO,"This method is going away. Please use pp.queryclass() instead.");
      21              : 
      22            0 :     m_ncomp = a_ncomp;
      23              : 
      24            0 :     m_bc_type[Face::XLO].resize(m_ncomp,BCUtil::ReadString(bc_lo_str[0]));
      25            0 :     m_bc_type[Face::XHI].resize(m_ncomp,BCUtil::ReadString(bc_hi_str[0]));
      26            0 :     m_bc_type[Face::YLO].resize(m_ncomp,BCUtil::ReadString(bc_lo_str[1]));
      27            0 :     m_bc_type[Face::YHI].resize(m_ncomp,BCUtil::ReadString(bc_hi_str[1]));
      28              :     #if AMREX_SPACEDIM == 3
      29            0 :     m_bc_type[Face::ZLO].resize(m_ncomp,BCUtil::ReadString(bc_lo_str[2]));
      30            0 :     m_bc_type[Face::ZHI].resize(m_ncomp,BCUtil::ReadString(bc_hi_str[2]));
      31              :     #endif
      32              : 
      33              : 
      34            0 :     m_bc_val[Face::XLO].resize(m_ncomp,NAN);
      35            0 :     m_bc_val[Face::XHI].resize(m_ncomp,NAN);
      36            0 :     m_bc_val[Face::YLO].resize(m_ncomp,NAN);
      37            0 :     m_bc_val[Face::YHI].resize(m_ncomp,NAN);
      38              :     #if AMREX_SPACEDIM == 3
      39            0 :     m_bc_val[Face::ZLO].resize(m_ncomp,NAN);
      40            0 :     m_bc_val[Face::ZHI].resize(m_ncomp,NAN);
      41              :     #endif
      42              : 
      43            0 :     for (unsigned int i=0;i<m_ncomp;i++)
      44              :     {
      45            0 :         if (_bc_lo_1.size() > 0) m_bc_val[Face::XLO][i] = _bc_lo_1[i];
      46            0 :         if (_bc_hi_1.size() > 0) m_bc_val[Face::XHI][i] = _bc_hi_1[i];
      47            0 :         if (_bc_lo_2.size() > 0) m_bc_val[Face::YLO][i] = _bc_lo_2[i];
      48            0 :         if (_bc_hi_2.size() > 0) m_bc_val[Face::YHI][i] = _bc_hi_2[i];
      49              :         #if AMREX_SPACEDIM == 3
      50            0 :         if (_bc_lo_3.size() > 0) m_bc_val[Face::ZLO][i] = _bc_lo_3[i];
      51            0 :         if (_bc_hi_3.size() > 0) m_bc_val[Face::ZHI][i] = _bc_hi_3[i];
      52              :         #endif
      53              :     }
      54            0 : }
      55              : 
      56              : 
      57              : //amrex::Mask& m
      58              : void
      59      8246820 : Constant::FillBoundary (amrex::BaseFab<Set::Scalar> &a_in,
      60              :             const amrex::Box &a_box,
      61              :             int ngrow, int /*dcomp*/, int /*ncomp*/, amrex::Real time,
      62              :             Orientation face, const amrex::Mask * /*mask*/)
      63              : {
      64      8246820 :     const amrex::Real* DX = m_geom.CellSize();
      65              : 
      66     57727740 :     Util::Assert(INFO,TEST(a_in.nComp() == (int)m_ncomp));
      67              : 
      68      8246820 :     amrex::Box box = a_box;
      69      8246820 :     box.grow(ngrow);
      70     24740460 :     const amrex::Dim3 lo= amrex::lbound(m_geom.Domain()), hi = amrex::ubound(m_geom.Domain());
      71              : 
      72      8246820 :     amrex::Array4<amrex::Real> const& in = a_in.array();
      73              : 
      74     18241651 :     for (int n = 0; n < a_in.nComp(); n++)
      75      9994832 :     amrex::ParallelFor (box,[=] AMREX_GPU_DEVICE(int i, int j, int k)
      76              :     {
      77   3141873303 :         amrex::IntVect glevel;
      78   9434093380 :         AMREX_D_TERM(glevel[0] = std::max(std::min(0,i-lo.x),i-hi.x); ,
      79              :                     glevel[1] = std::max(std::min(0,j-lo.y),j-hi.y); ,
      80              :                     glevel[2] = std::max(std::min(0,k-lo.z),k-hi.z); );
      81              :         
      82   3141873302 :         if (glevel[0]<0 && (face == Orientation::xlo || face == Orientation::All)) // Left boundary
      83              :         {
      84    171558803 :             if (BCUtil::IsDirichlet(m_bc_type[Face::XLO][n]))
      85    162575512 :                 in(i,j,k,n) = m_bc_val[Face::XLO][n](time);
      86     90271047 :             else if(BCUtil::IsNeumann(m_bc_type[Face::XLO][n]))
      87    359888348 :                 in(i,j,k,n) = in(i-glevel[0],j,k,n) - (m_bc_val[Face::XLO].size() > 0 ? m_bc_val[Face::XLO][n](time)*DX[0] : 0);
      88       298960 :             else if(BCUtil::IsReflectEven(m_bc_type[Face::XLO][n]))
      89            0 :                 in(i,j,k,n) = in(1-glevel[0],j,k,n);
      90       298960 :             else if(BCUtil::IsReflectOdd(m_bc_type[Face::XLO][n]))
      91            0 :                 in(i,j,k,n) = -in(1-glevel[0],j,k,n);
      92       298960 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::XLO][n])) {}
      93              :             else
      94            0 :                 Util::Abort(INFO, "Incorrect boundary conditions");
      95              :         }
      96   2970314499 :         else if (glevel[0]>0 && (face == Orientation::xhi || face == Orientation::All)) // Right boundary
      97              :         {
      98     11902190 :             if (BCUtil::IsDirichlet(m_bc_type[Face::XHI][n]))
      99      3647144 :                 in(i,j,k,n) = m_bc_val[Face::XHI][n](time);
     100     10078618 :             else if(BCUtil::IsNeumann(m_bc_type[Face::XHI][n]))
     101     39843912 :                 in(i,j,k,n) = in(i-glevel[0],j,k,n) - (m_bc_val[Face::XHI].size() > 0 ? m_bc_val[Face::XHI][n](time)*DX[0] : 0);
     102       117640 :             else if(BCUtil::IsReflectEven(m_bc_type[Face::XHI][n]))
     103            0 :                 in(i,j,k,n) = in(hi.x-glevel[0],j,k,n);
     104       117640 :             else if(BCUtil::IsReflectOdd(m_bc_type[Face::XHI][n]))
     105            0 :                 in(i,j,k,n) = -in(hi.x-glevel[0],j,k,n);
     106       117640 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::XHI][n])) {}
     107              :             else
     108            0 :                 Util::Abort(INFO, "Incorrect boundary conditions");
     109              :         }
     110              :         
     111   2958412309 :         else if (glevel[1]<0 && (face == Orientation::ylo || face == Orientation::All)) // Bottom boundary
     112              :         {
     113     36737242 :             if (BCUtil::IsDirichlet(m_bc_type[Face::YLO][n]))
     114     15018348 :                 in(i,j,k,n) = m_bc_val[Face::YLO][n](time);
     115     29228068 :             else if (BCUtil::IsNeumann(m_bc_type[Face::YLO][n]))
     116    107011056 :                 in(i,j,k,n) = in(i,j-glevel[1],k,n) - (m_bc_val[Face::YLO].size() > 0 ? m_bc_val[Face::YLO][n](time)*DX[1] : 0);
     117      2475304 :             else if (BCUtil::IsReflectEven(m_bc_type[Face::YLO][n]))
     118            0 :                 in(i,j,k,n) = in(i,j-glevel[1],k,n);
     119      2475304 :             else if (BCUtil::IsReflectOdd(m_bc_type[Face::YLO][n]))
     120            0 :                 in(i,j,k,n) = -in(i,j-glevel[1],k,n);
     121      2475304 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::YLO][n])) {}
     122              :             else
     123            0 :                 Util::Abort(INFO, "Incorrect boundary conditions");
     124              :         }
     125   2921675067 :         else if (glevel[1]>0 && (face == Orientation::yhi || face == Orientation::All)) // Top boundary
     126              :         {
     127     22586978 :             if (BCUtil::IsDirichlet(m_bc_type[Face::YHI][n]))
     128      3428036 :                 in(i,j,k,n) = m_bc_val[Face::YHI][n](time);
     129     20872960 :             else if (BCUtil::IsNeumann(m_bc_type[Face::YHI][n]))
     130     78311864 :                 in(i,j,k,n) = in(i,j-glevel[1],k,n) - (m_bc_val[Face::YHI].size() > 0 ? m_bc_val[Face::YHI][n](time)*DX[1] : 0);
     131      1294994 :             else if (BCUtil::IsReflectEven(m_bc_type[Face::YHI][n]))
     132            0 :                 in(i,j,k,n) = in(i,hi.y-glevel[1],k,n);
     133      1294994 :             else if (BCUtil::IsReflectOdd(m_bc_type[Face::YHI][n]))
     134            0 :                 in(i,j,k,n) = -in(i,hi.y-glevel[1],k,n);
     135      1294994 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::YHI][n])) {}
     136              :             else
     137            0 :                 Util::Abort(INFO, "Incorrect boundary conditions");
     138              :         }
     139              : 
     140              : #if AMREX_SPACEDIM>2
     141      6658048 :         else if (glevel[2]<0 && (face == Orientation::zlo || face == Orientation::All))
     142              :         {
     143       600256 :             if (BCUtil::IsDirichlet(m_bc_type[Face::ZLO][n]))
     144      1200512 :                 in(i,j,k,n) = m_bc_val[Face::ZLO][n](time);
     145            0 :             else if (BCUtil::IsNeumann(m_bc_type[Face::ZLO][n]))
     146            0 :                 in(i,j,k,n) = in(i,j,k-glevel[2],n) - (m_bc_val[Face::ZLO].size() > 0 ? m_bc_val[Face::ZLO][n](time)*DX[2] : 0);
     147            0 :             else if (BCUtil::IsReflectEven(m_bc_type[Face::ZLO][n]))
     148            0 :                 in(i,j,k,n) = in(i,j,1-glevel[2],n);
     149            0 :             else if (BCUtil::IsReflectOdd(m_bc_type[Face::ZLO][n]))
     150            0 :                 in(i,j,k,n) = -in(i,j,1-glevel[2],n);
     151            0 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::ZLO][n])) {}
     152            0 :             else Util::Abort(INFO, "Incorrect boundary conditions");
     153              :         }
     154      6057792 :         else if (glevel[2]>0 && (face == Orientation::zhi || face == Orientation::All))
     155              :         {
     156       102144 :             if (BCUtil::IsDirichlet(m_bc_type[Face::ZHI][n]))
     157       204288 :                 in(i,j,k,n) = m_bc_val[Face::ZHI][n](time);
     158            0 :             else if(BCUtil::IsNeumann(m_bc_type[Face::ZHI][n]))
     159            0 :                 in(i,j,k,n) = in(i,j,k-glevel[2],n) - (m_bc_val[Face::ZHI].size() > 0 ? m_bc_val[Face::ZHI][n](time)*DX[2] : 0);
     160            0 :             else if(BCUtil::IsReflectEven(m_bc_type[Face::ZHI][n]))
     161            0 :                 in(i,j,k,n) = in(i,j,hi.z-glevel[2],n);
     162            0 :             else if(BCUtil::IsReflectOdd(m_bc_type[Face::ZHI][n]))
     163            0 :                 in(i,j,k,n) = -in(i,j,hi.z-glevel[2],n);
     164            0 :             else if(BCUtil::IsPeriodic(m_bc_type[Face::ZHI][n])) {}
     165            0 :             else Util::Abort(INFO, "Incorrect boundary conditions");
     166              :         }
     167              : #endif
     168              : 
     169              : 
     170   3141873302 :     });
     171      8246819 : }
     172              : 
     173              : amrex::BCRec
     174       449711 : Constant::GetBCRec() 
     175              : {
     176       449711 :     int bc_lo[BL_SPACEDIM] = {AMREX_D_DECL(m_bc_type[Face::XLO][0],m_bc_type[Face::YLO][0],m_bc_type[Face::XLO][0])};
     177       449711 :     int bc_hi[BL_SPACEDIM] = {AMREX_D_DECL(m_bc_type[Face::XHI][0],m_bc_type[Face::YHI][0],m_bc_type[Face::XHI][0])};
     178              : 
     179       449711 :     return amrex::BCRec(bc_lo,bc_hi);
     180              : }
     181              : 
     182              : amrex::Array<int,AMREX_SPACEDIM>
     183            0 : Constant::IsPeriodic()
     184              : {
     185            0 :     return {AMREX_D_DECL(BCUtil::IsPeriodic(m_bc_type[Face::XLO][0]),
     186              :                 BCUtil::IsPeriodic(m_bc_type[Face::YLO][0]),
     187            0 :                 BCUtil::IsPeriodic(m_bc_type[Face::ZLO][0]))};
     188              : }
     189            0 : amrex::Periodicity Constant::Periodicity () const
     190              : {
     191            0 :     return amrex::Periodicity(amrex::IntVect(AMREX_D_DECL(m_geom.Domain().length(0) * BCUtil::IsPeriodic(m_bc_type[Face::XLO][0]),
     192              :                                                             m_geom.Domain().length(1) * BCUtil::IsPeriodic(m_bc_type[Face::YLO][0]),
     193            0 :                                                             m_geom.Domain().length(2) * BCUtil::IsPeriodic(m_bc_type[Face::ZLO][0]))));
     194              : }
     195            0 : amrex::Periodicity Constant::Periodicity (const amrex::Box& b) {
     196            0 :     return amrex::Periodicity(amrex::IntVect(AMREX_D_DECL(b.length(0) * BCUtil::IsPeriodic(m_bc_type[Face::XLO][0]),
     197              :                                                         b.length(1) * BCUtil::IsPeriodic(m_bc_type[Face::YLO][0]),
     198            0 :                                                         b.length(2) * BCUtil::IsPeriodic(m_bc_type[Face::ZLO][0]))));
     199              : 
     200              : }
     201              : 
     202              : 
     203              : }
        

Generated by: LCOV version 2.0-1