LCOV - code coverage report
Current view: top level - src/Meshes - UniformCartesian.hpp (source / functions) Coverage Total Hit
Test: report.info Lines: 74.3 % 35 26
Test Date: 2025-05-12 09:25:18 Functions: 95.5 % 88 84
Branches: 57.1 % 14 8

             Branch data     Line data    Source code
       1                 :             : //
       2                 :             : // Class UniformCartesian
       3                 :             : //   UniformCartesian class - represents uniform-spacing cartesian meshes.
       4                 :             : //
       5                 :             : #include "Utility/IpplInfo.h"
       6                 :             : #include "Utility/PAssert.h"
       7                 :             : 
       8                 :             : #include "Field/BareField.h"
       9                 :             : #include "Field/Field.h"
      10                 :             : 
      11                 :             : namespace ippl {
      12                 :             : 
      13                 :             :     template <typename T, unsigned Dim>
      14                 :         196 :     UniformCartesian<T, Dim>::UniformCartesian()
      15                 :             :         : Mesh<T, Dim>()
      16         [ +  - ]:         196 :         , volume_m(0.0) {}
      17                 :             : 
      18                 :             :     template <typename T, unsigned Dim>
      19                 :         368 :     UniformCartesian<T, Dim>::UniformCartesian(const NDIndex<Dim>& ndi, const vector_type& hx,
      20         [ +  - ]:         368 :                                                const vector_type& origin) {
      21         [ +  - ]:         368 :         this->initialize(ndi, hx, origin);
      22                 :         368 :     }
      23                 :             : 
      24                 :             :     template <typename T, unsigned Dim>
      25                 :         380 :     void UniformCartesian<T, Dim>::initialize(const NDIndex<Dim>& ndi, const vector_type& hx,
      26                 :             :                                               const vector_type& origin) {
      27                 :         380 :         meshSpacing_m = hx;
      28                 :             : 
      29                 :         380 :         volume_m = 1.0;
      30         [ +  + ]:        1690 :         for (unsigned d = 0; d < Dim; ++d) {
      31                 :        1310 :             this->gridSizes_m[d] = ndi[d].length();
      32                 :        1310 :             volume_m *= meshSpacing_m[d];
      33                 :             :         }
      34                 :             : 
      35                 :         380 :         this->setOrigin(origin);
      36                 :         380 :     }
      37                 :             : 
      38                 :             :     template <typename T, unsigned Dim>
      39                 :           0 :     void UniformCartesian<T, Dim>::setMeshSpacing(const vector_type& meshSpacing) {
      40                 :           0 :         meshSpacing_m = meshSpacing;
      41                 :           0 :         this->updateCellVolume_m();
      42                 :           0 :     }
      43                 :             : 
      44                 :             :     template <typename T, unsigned Dim>
      45                 :         462 :     T UniformCartesian<T, Dim>::getMeshSpacing(unsigned dim) const {
      46         [ -  + ]:         462 :         PAssert_LT(dim, Dim);
      47                 :         462 :         return meshSpacing_m[dim];
      48                 :             :     }
      49                 :             : 
      50                 :             :     template <typename T, unsigned Dim>
      51                 :         128 :     const typename UniformCartesian<T, Dim>::vector_type& UniformCartesian<T, Dim>::getMeshSpacing()
      52                 :             :         const {
      53                 :         128 :         return meshSpacing_m;
      54                 :             :     }
      55                 :             : 
      56                 :             :     template <typename T, unsigned Dim>
      57                 :          48 :     T UniformCartesian<T, Dim>::getCellVolume() const {
      58                 :          48 :         return volume_m;
      59                 :             :     }
      60                 :             : 
      61                 :             :     template <typename T, unsigned Dim>
      62                 :          36 :     T UniformCartesian<T, Dim>::getMeshVolume() const {
      63                 :          36 :         T ret = 1;
      64         [ +  + ]:         162 :         for (unsigned int d = 0; d < Dim; ++d) {
      65                 :         126 :             ret *= this->getGridsize(d) * this->getMeshSpacing(d);
      66                 :             :         }
      67                 :          36 :         return ret;
      68                 :             :     }
      69                 :             : 
      70                 :             :     template <typename T, unsigned Dim>
      71                 :           0 :     void UniformCartesian<T, Dim>::updateCellVolume_m() {
      72                 :             :         // update cell volume
      73                 :           0 :         volume_m = 1.0;
      74         [ #  # ]:           0 :         for (unsigned i = 0; i < Dim; ++i) {
      75                 :           0 :             volume_m *= meshSpacing_m[i];
      76                 :             :         }
      77                 :           0 :     }
      78                 :             : 
      79                 :             : }  // namespace ippl
        

Generated by: LCOV version 2.0-1