www.mooseframework.org
CSVTimeSequenceStepper.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
13 
16 {
18  params.addRequiredParam<FileName>("file_name",
19  "name of the file in which the time sequence is read");
20  params.addParam<bool>("header",
21  "indicates whether the file contains a header with the column names");
22  params.addParam<std::string>("delimiter", ",", "delimiter used to parse the file");
23  params.addParam<std::string>(
24  "column_name", "time", "name of the column which contains the time sequence");
25  params.addParam<unsigned int>("column_index",
26  "index of the column which contains the time sequence");
27  params.addClassDescription(
28  "Solves the Transient problem at a sequence of given time points read in a file.");
29  return params;
30 }
31 
33  : TimeSequenceStepperBase(parameters),
34  _file_name(getParam<FileName>("file_name")),
35  _header(isParamValid("header")
36  ? (getParam<bool>("header") ? MooseUtils::DelimitedFileReader::HeaderFlag::ON
37  : MooseUtils::DelimitedFileReader::HeaderFlag::OFF)
38  : MooseUtils::DelimitedFileReader::HeaderFlag::AUTO),
39  _delimiter(getParam<std::string>("delimiter")),
40  _column_name(getParam<std::string>("column_name")),
41  _search_by_index(isParamValid("column_index")),
42  _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0)
43 {
44 }
45 
46 void
48 {
50 
51  file.setHeaderFlag(_header);
53  file.read();
54 
55  std::vector<Real> instants;
56 
57  if (_search_by_index)
58  {
59  std::vector<std::vector<double>> data = file.getData();
60  if (_column_index >= data.size())
61  mooseError("cannot find column ", _column_index, " in file ", _file_name);
62  instants = data[_column_index];
63  }
64  else
65  instants = file.getData(_column_name);
66 
67  if (instants.size() == 0)
68  mooseError("empty sequence in file ", _file_name);
69 
70  setupSequence(instants);
71 }
void setHeaderFlag(HeaderFlag value)
void read()
Perform the actual data reading.
Solves the PDEs at a sequence of time points given as a column in a text table file (such as a *...
const std::vector< std::vector< double > > & getData() const
Return the rows/columns of data.
Utility class for reading delimited data (e.g., CSV data).
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const bool _search_by_index
indicates whether to access a column using its index or its name
void setupSequence(const std::vector< Real > &times)
const MooseUtils::DelimitedFileReader::HeaderFlag _header
whether the file contains a header with the column names
const std::string _column_name
name of the column containing the time data
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
CSVTimeSequenceStepper(const InputParameters &parameters)
void setDelimiter(const std::string &value)
static InputParameters validParams()
registerMooseObject("MooseApp", CSVTimeSequenceStepper)
const std::string _file_name
name of the file where the data is read
virtual void init() override
Initialize the time stepper.
Solves the PDEs at a sequence of given time points.
static InputParameters validParams()
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const unsigned int _column_index
index of the column containing the time data
void ErrorVector unsigned int
const std::string _delimiter
string used as a delimiter