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 
14 template <>
17 {
19  params.addRequiredParam<FileName>("file_name",
20  "name of the file in which the time sequence is read");
21  params.addParam<bool>("header",
22  "indicates whether the file contains a header with the column names");
23  params.addParam<std::string>("delimiter", ",", "delimiter used to parse the file");
24  params.addParam<std::string>(
25  "column_name", "time", "name of the column which contains the time sequence");
26  params.addParam<unsigned int>("column_index",
27  "index of the column which contains the time sequence");
28  params.addClassDescription(
29  "Solves the Transient problem at a sequence of given time points read in a file.");
30  return params;
31 }
32 
34  : TimeSequenceStepperBase(parameters),
35  _file_name(getParam<FileName>("file_name")),
36  _header(isParamValid("header")
37  ? (getParam<bool>("header") ? MooseUtils::DelimitedFileReader::HeaderFlag::ON
38  : MooseUtils::DelimitedFileReader::HeaderFlag::OFF)
39  : MooseUtils::DelimitedFileReader::HeaderFlag::AUTO),
40  _delimiter(getParam<std::string>("delimiter")),
41  _column_name(getParam<std::string>("column_name")),
42  _search_by_index(isParamValid("column_index")),
43  _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0)
44 {
45 }
46 
47 void
49 {
51 
52  file.setHeaderFlag(_header);
54  file.read();
55 
56  std::vector<Real> instants;
57 
58  if (_search_by_index)
59  {
60  std::vector<std::vector<double>> data = file.getData();
61  if (_column_index >= data.size())
62  mooseError("cannot find column ", _column_index, " in file ", _file_name);
63  instants = data[_column_index];
64  }
65  else
66  instants = file.getData(_column_name);
67 
68  if (instants.size() == 0)
69  mooseError("empty sequence in file ", _file_name);
70 
71  setupSequence(instants);
72 }
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)
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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)
InputParameters validParams< TimeSequenceStepperBase >()
void setDelimiter(const std::string &value)
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.
InputParameters validParams< CSVTimeSequenceStepper >()
Solves the PDEs at a sequence of given time points.
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
const std::string _delimiter
string used as a delimiter