LCOV - code coverage report
Current view: top level - include/utils - GriddedData.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MooseTypes.h"
      13             : #include "MooseError.h"
      14             : #include "MooseUtils.h"
      15             : 
      16             : #include <iosfwd>
      17             : #include <string>
      18             : #include <vector>
      19             : 
      20             : /**
      21             :  * Container for holding a function defined on a grid of arbitrary dimension.
      22             :  *
      23             :  * Information is read from a file.  The file contains the grid, which
      24             :  * has dimension _dim, and consists of _dim vectors of Reals.  The
      25             :  * file also contains the function values at each grid point.  The
      26             :  * file also contains information on how to embed the grid into a
      27             :  * MOOSE simulation.  This is achieved through specifying the MOOSE
      28             :  * direction that each grid axis corresponds to.  For instance, the
      29             :  * first grid axis might correspond to the MOOSE "y" direction, the
      30             :  * second grid axis might correspond to the MOOSE "t" direction, etc.
      31             :  */
      32             : class GriddedData
      33             : {
      34             : public:
      35             :   /**
      36             :    * Construct with a file name
      37             :    */
      38             :   GriddedData(std::string file_name);
      39             : 
      40         444 :   virtual ~GriddedData() = default;
      41             : 
      42             :   typedef MooseUtils::SemidynamicVector<Real, 4> GridPoint;
      43             :   typedef MooseUtils::SemidynamicVector<ADReal, 4> ADGridPoint;
      44             :   typedef MooseUtils::SemidynamicVector<unsigned int, 4> GridIndex;
      45             : 
      46             :   /**
      47             :    * Returns the dimensionality of the grid.
      48             :    *
      49             :    * This may have nothing to do with the dimensionality of the
      50             :    * simulation.  Eg, a 2D grid with axes (Y,Z) (so dim=2) be used in
      51             :    * a 3D simulation.
      52             :    */
      53             :   unsigned int getDim();
      54             : 
      55             :   /**
      56             :    * Yields axes information.
      57             :    * If axes[i] == 0 then the i_th axis in the grid data corresponds to the x axis in the simulation
      58             :    * If axes[i] == 1 then the i_th axis in the grid data corresponds to the y axis in the simulation
      59             :    * If axes[i] == 2 then the i_th axis in the grid data corresponds to the z axis in the simulation
      60             :    * If axes[i] == 3 then the i_th axis in the grid data corresponds to the time in the simulation
      61             :    */
      62             :   void getAxes(std::vector<int> & axes);
      63             : 
      64             :   /**
      65             :    * Yields the grid.
      66             :    * grid[i] = a vector of Reals that define the i_th axis of the grid.
      67             :    */
      68             :   void getGrid(std::vector<std::vector<Real>> & grid);
      69             : 
      70             :   /**
      71             :    * Yields the values defined at the grid points.
      72             :    */
      73             :   void getFcn(std::vector<Real> & fcn);
      74             : 
      75             :   /**
      76             :    * Evaluates the function at a given grid point.
      77             :    * For instance, evaluateFcn({n,m}) = value at (grid[0][n], grid[1][m]), for a function defined on
      78             :    * a 2D grid
      79             :    */
      80             :   Real evaluateFcn(const GridIndex & ijk);
      81             : 
      82             :   /**
      83             :    * parse the file_name extracting information.
      84             :    * Here is an example file:
      85             :    * # this is a comment line at start of file
      86             :    * AXIS Y
      87             :    * -1.5 0
      88             :    * # there is no reason why the x axis can't be second
      89             :    * AXIS X
      90             :    * 1 2 3
      91             :    * # This example has a 3D grid, but the 3rd direction is time
      92             :    * AXIS T
      93             :    * 0 199
      94             :    * # now some data
      95             :    * DATA
      96             :    * # following for x=1, t=0
      97             :    * 1 2
      98             :    * # following for x=2, t=0
      99             :    * 2 3
     100             :    * # following for x=3, t=0
     101             :    * 2 3
     102             :    * # following for x=1, t=199
     103             :    * 89 900
     104             :    * # following for x=2, t=199, and x=3, t=199
     105             :    * 1 -3 -5 -6.898
     106             :    * # end of file
     107             :    */
     108             :   static void parse(unsigned int & dim,
     109             :                     std::vector<int> & axes,
     110             :                     std::vector<std::vector<Real>> & grid,
     111             :                     std::vector<Real> & f,
     112             :                     std::vector<unsigned int> & step,
     113             :                     std::string file_name);
     114             : 
     115             : private:
     116             :   unsigned int _dim;
     117             :   std::vector<int> _axes;
     118             :   std::vector<std::vector<Real>> _grid;
     119             :   std::vector<Real> _fcn;
     120             :   std::vector<unsigned int> _step;
     121             :   /**
     122             :    * Extracts the next line from file_stream that is:
     123             :    *  - not empty
     124             :    *  - does not start with #
     125             :    * Returns true if such a line was found,
     126             :    * otherwise returns false
     127             :    */
     128             :   static bool getSignificantLine(std::ifstream & file_stream, std::string & line);
     129             : 
     130             :   /**
     131             :    * Splits an input_string using space as the separator
     132             :    * Converts the resulting items to Real, and adds these
     133             :    * to the end of output_vec
     134             :    */
     135             :   static void splitToRealVec(const std::string & input_string, std::vector<Real> & output_vec);
     136             : 
     137             :   void updateGrid(unsigned int & dim, const std::vector<Real> & axis_i, const int axis_index);
     138             : };

Generated by: LCOV version 1.14