LCOV - code coverage report
Current view: top level - src/timesteppers - CSVTimeSequenceStepper.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 29 36 80.6 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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             : #include "CSVTimeSequenceStepper.h"
      11             : 
      12             : registerMooseObject("MooseApp", CSVTimeSequenceStepper);
      13             : 
      14             : InputParameters
      15       14309 : CSVTimeSequenceStepper::validParams()
      16             : {
      17       14309 :   InputParameters params = TimeSequenceStepperBase::validParams();
      18       14309 :   params.addRequiredParam<FileName>("file_name",
      19             :                                     "name of the file in which the time sequence is read");
      20       14309 :   params.addParam<bool>("header",
      21             :                         "indicates whether the file contains a header with the column names");
      22       14309 :   params.addParam<std::string>("delimiter", ",", "delimiter used to parse the file");
      23       14309 :   params.addParam<std::string>(
      24             :       "column_name", "time", "name of the column which contains the time sequence");
      25       14309 :   params.addParam<unsigned int>("column_index",
      26             :                                 "index of the column which contains the time sequence");
      27       14309 :   params.addClassDescription(
      28             :       "Solves the Transient problem at a sequence of given time points read in a file.");
      29       14309 :   return params;
      30           0 : }
      31             : 
      32          22 : CSVTimeSequenceStepper::CSVTimeSequenceStepper(const InputParameters & parameters)
      33             :   : TimeSequenceStepperBase(parameters),
      34          22 :     _file_name(getParam<FileName>("file_name")),
      35          44 :     _header(isParamValid("header")
      36          22 :                 ? (getParam<bool>("header") ? MooseUtils::DelimitedFileReader::HeaderFlag::ON
      37             :                                             : MooseUtils::DelimitedFileReader::HeaderFlag::OFF)
      38             :                 : MooseUtils::DelimitedFileReader::HeaderFlag::AUTO),
      39          22 :     _delimiter(getParam<std::string>("delimiter")),
      40          22 :     _column_name(getParam<std::string>("column_name")),
      41          22 :     _search_by_index(isParamValid("column_index")),
      42          44 :     _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0)
      43             : {
      44          22 : }
      45             : 
      46             : void
      47          22 : CSVTimeSequenceStepper::init()
      48             : {
      49          22 :   MooseUtils::DelimitedFileReader file(_file_name);
      50             : 
      51          22 :   file.setHeaderFlag(_header);
      52          22 :   file.setDelimiter(_delimiter);
      53          22 :   file.read();
      54             : 
      55          22 :   std::vector<Real> instants;
      56             : 
      57          22 :   if (_search_by_index)
      58             :   {
      59           0 :     std::vector<std::vector<double>> data = file.getData();
      60           0 :     if (_column_index >= data.size())
      61           0 :       mooseError("cannot find column ", _column_index, " in file ", _file_name);
      62           0 :     instants = data[_column_index];
      63           0 :   }
      64             :   else
      65          22 :     instants = file.getData(_column_name);
      66             : 
      67          22 :   if (instants.size() == 0)
      68           0 :     mooseError("empty sequence in file ", _file_name);
      69             : 
      70          22 :   setupSequence(instants);
      71          22 : }

Generated by: LCOV version 1.14