LCOV - code coverage report
Current view: top level - src/io - NCWriteHelper.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 0 33 0.0 %
Date: 2020-12-16 07:07:30 Functions: 0 8 0.0 %
Branches: 0 46 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * NCWriteHelper.hpp
       3                 :            :  *
       4                 :            :  * Purpose       : Climate NC writer file helper; abstract, will be implemented for each type
       5                 :            :  *
       6                 :            :  *  Created on: Mar 28, 2014
       7                 :            :  */
       8                 :            : 
       9                 :            : #ifndef NCWRITEHELPER_HPP_
      10                 :            : #define NCWRITEHELPER_HPP_
      11                 :            : #include "WriteNC.hpp"
      12                 :            : 
      13                 :            : #ifdef WIN32
      14                 :            : #ifdef size_t
      15                 :            : #undef size_t
      16                 :            : #endif
      17                 :            : #endif
      18                 :            : 
      19                 :            : namespace moab
      20                 :            : {
      21                 :            : 
      22                 :            : class NCWriteHelper
      23                 :            : {
      24                 :            :   public:
      25                 :          0 :     NCWriteHelper( WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet )
      26                 :            :         : _writeNC( writeNC ), _fileId( fileId ), _opts( opts ), _fileSet( fileSet ), nTimeSteps( 0 ), nLevels( 1 ),
      27 [ #  # ][ #  # ]:          0 :           tDim( -1 ), levDim( -1 )
                 [ #  # ]
      28                 :            :     {
      29                 :          0 :     }
      30         [ #  # ]:          0 :     virtual ~NCWriteHelper(){};
      31                 :            : 
      32                 :            :     //! Get appropriate helper instance for WriteNC class based on some info in the file set
      33                 :            :     static NCWriteHelper* get_nc_helper( WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet );
      34                 :            : 
      35                 :            :     //! Collect necessary info about local mesh (implemented in child classes)
      36                 :            :     virtual ErrorCode collect_mesh_info() = 0;
      37                 :            : 
      38                 :            :     //! Collect data for specified variables (partially implemented in child classes)
      39                 :            :     virtual ErrorCode collect_variable_data( std::vector< std::string >& var_names, std::vector< int >& tstep_nums );
      40                 :            : 
      41                 :            :     //! Initialize file: this is where all defines are done
      42                 :            :     //! The VarData dimension ids are filled up after define
      43                 :            :     ErrorCode init_file( std::vector< std::string >& var_names, std::vector< std::string >& desired_names,
      44                 :            :                          bool _append );
      45                 :            : 
      46                 :            :     //! Take the info from VarData and write first non-set variables, then set variables
      47                 :            :     ErrorCode write_values( std::vector< std::string >& var_names, std::vector< int >& tstep_nums );
      48                 :            : 
      49                 :            :   private:
      50                 :            :     // Write set variables (common to scd mesh and ucd mesh)
      51                 :            :     ErrorCode write_set_variables( std::vector< WriteNC::VarData >& vsetdatas, std::vector< int >& tstep_nums );
      52                 :            : 
      53                 :            :   protected:
      54                 :            :     // Write non-set variables (implemented in child classes)
      55                 :            :     virtual ErrorCode write_nonset_variables( std::vector< WriteNC::VarData >& vdatas,
      56                 :            :                                               std::vector< int >& tstep_nums ) = 0;
      57                 :            : 
      58                 :            :     //! Allow NCWriteHelper to directly access members of WriteNC
      59                 :            :     WriteNC* _writeNC;
      60                 :            : 
      61                 :            :     //! Cache some information from WriteNC
      62                 :            :     int _fileId;
      63                 :            :     const FileOptions& _opts;
      64                 :            :     EntityHandle _fileSet;
      65                 :            : 
      66                 :            :     //! Dimensions of time and level
      67                 :            :     int nTimeSteps, nLevels;
      68                 :            : 
      69                 :            :     //! Dimension numbers for time and level
      70                 :            :     int tDim, levDim;
      71                 :            : 
      72                 :            :     //! Local owned cells, edges and vertices
      73                 :            :     Range localCellsOwned, localEdgesOwned, localVertsOwned;
      74                 :            : 
      75                 :            :     //! Time values of output timesteps
      76                 :            :     std::vector< double > timeStepVals;
      77                 :            : };
      78                 :            : 
      79                 :            : //! Child helper class for scd mesh, e.g. CAM_EL or CAM_FV
      80                 :            : class ScdNCWriteHelper : public NCWriteHelper
      81                 :            : {
      82                 :            :   public:
      83                 :          0 :     ScdNCWriteHelper( WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet )
      84                 :          0 :         : NCWriteHelper( writeNC, fileId, opts, fileSet )
      85                 :            :     {
      86         [ #  # ]:          0 :         for( unsigned int i = 0; i < 6; i++ )
      87                 :            :         {
      88                 :          0 :             lDims[i]  = -1;
      89                 :          0 :             lCDims[i] = -1;
      90                 :            :         }
      91                 :          0 :     }
      92         [ #  # ]:          0 :     virtual ~ScdNCWriteHelper() {}
      93                 :            : 
      94                 :            :   private:
      95                 :            :     //! Implementation of NCWriteHelper::collect_mesh_info()
      96                 :            :     virtual ErrorCode collect_mesh_info();
      97                 :            : 
      98                 :            :     //! Collect data for specified variables
      99                 :            :     virtual ErrorCode collect_variable_data( std::vector< std::string >& var_names, std::vector< int >& tstep_nums );
     100                 :            : 
     101                 :            :     //! Implementation of NCWriteHelper::write_nonset_variables()
     102                 :            :     virtual ErrorCode write_nonset_variables( std::vector< WriteNC::VarData >& vdatas, std::vector< int >& tstep_nums );
     103                 :            : 
     104                 :            :     template < typename T >
     105                 :          0 :     void jik_to_kji( size_t ni, size_t nj, size_t nk, T* dest, T* source )
     106                 :            :     {
     107                 :          0 :         size_t nik = ni * nk, nij = ni * nj;
     108         [ #  # ]:          0 :         for( std::size_t k = 0; k != nk; k++ )
     109         [ #  # ]:          0 :             for( std::size_t j = 0; j != nj; j++ )
     110         [ #  # ]:          0 :                 for( std::size_t i = 0; i != ni; i++ )
     111                 :          0 :                     dest[k * nij + j * ni + i] = source[j * nik + i * nk + k];
     112                 :          0 :     }
     113                 :            : 
     114                 :            :   protected:
     115                 :            :     //! Dimensions of my local part of grid
     116                 :            :     int lDims[6];
     117                 :            : 
     118                 :            :     //! Center dimensions of my local part of grid
     119                 :            :     int lCDims[6];
     120                 :            : };
     121                 :            : 
     122                 :            : //! Child helper class for ucd mesh, e.g. CAM_SE (HOMME) or MPAS
     123                 :            : class UcdNCWriteHelper : public NCWriteHelper
     124                 :            : {
     125                 :            :   public:
     126                 :          0 :     UcdNCWriteHelper( WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet )
     127 [ #  # ][ #  # ]:          0 :         : NCWriteHelper( writeNC, fileId, opts, fileSet ), cDim( -1 ), eDim( -1 ), vDim( -1 )
                 [ #  # ]
     128                 :            :     {
     129                 :          0 :     }
     130         [ #  # ]:          0 :     virtual ~UcdNCWriteHelper() {}
     131                 :            : 
     132                 :            :   protected:
     133                 :            :     //! This version takes as input the moab range, from which we actually need just the
     134                 :            :     //! size of each sequence, for a proper transpose of the data
     135                 :            :     template < typename T >
     136                 :          0 :     void jik_to_kji_stride( size_t, size_t nj, size_t nk, T* dest, T* source, Range& localGid )
     137                 :            :     {
     138                 :          0 :         std::size_t idxInSource = 0;  // Position of the start of the stride
     139                 :            :         // For each subrange, we will transpose a matrix of size
     140                 :            :         // subrange*nj*nk (subrange takes the role of ni)
     141 [ #  # ][ #  # ]:          0 :         for( Range::pair_iterator pair_iter = localGid.pair_begin(); pair_iter != localGid.pair_end(); ++pair_iter )
         [ #  # ][ #  # ]
                 [ #  # ]
     142                 :            :         {
     143 [ #  # ][ #  # ]:          0 :             std::size_t size_range = pair_iter->second - pair_iter->first + 1;
     144                 :          0 :             std::size_t nik = size_range * nk, nij = size_range * nj;
     145         [ #  # ]:          0 :             for( std::size_t k = 0; k != nk; k++ )
     146         [ #  # ]:          0 :                 for( std::size_t j = 0; j != nj; j++ )
     147         [ #  # ]:          0 :                     for( std::size_t i = 0; i != size_range; i++ )
     148                 :          0 :                         dest[idxInSource + k * nij + j * size_range + i] = source[idxInSource + j * nik + i * nk + k];
     149                 :          0 :             idxInSource += ( size_range * nj * nk );
     150                 :            :         }
     151                 :          0 :     }
     152                 :            : 
     153                 :            :     //! Dimension numbers for nCells, nEdges and nVertices
     154                 :            :     int cDim, eDim, vDim;
     155                 :            : 
     156                 :            :     //! Local global ID for owned cells, edges and vertices
     157                 :            :     Range localGidCellsOwned, localGidEdgesOwned, localGidVertsOwned;
     158                 :            : };
     159                 :            : 
     160                 :            : }  // namespace moab
     161                 :            : 
     162                 :            : #endif

Generated by: LCOV version 1.11