www.mooseframework.org
CSVTimeSequenceStepper.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "CSVTimeSequenceStepper.h"
16 
17 template <>
20 {
22  params.addRequiredParam<FileName>("file_name",
23  "name of the file in which the time sequence is read");
24  params.addParam<bool>("header",
25  "indicates whether the file contains a header with the column names");
26  params.addParam<std::string>("delimiter", ",", "delimiter used to parse the file");
27  params.addParam<std::string>(
28  "column_name", "time", "name of the column which contains the time sequence");
29  params.addParam<unsigned int>("column_index",
30  "index of the column which contains the time sequence");
31  params.addClassDescription(
32  "Solves the Transient problem at a sequence of given time points read in a file.");
33  return params;
34 }
35 
37  : TimeSequenceStepperBase(parameters),
38  _file_name(getParam<FileName>("file_name")),
39  _header(isParamValid("header")
40  ? (getParam<bool>("header") ? MooseUtils::DelimitedFileReader::HeaderFlag::ON
41  : MooseUtils::DelimitedFileReader::HeaderFlag::OFF)
42  : MooseUtils::DelimitedFileReader::HeaderFlag::AUTO),
43  _delimiter(getParam<std::string>("delimiter")),
44  _column_name(getParam<std::string>("column_name")),
45  _search_by_index(isParamValid("column_index")),
46  _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0)
47 {
48 }
49 
50 void
52 {
54 
55  file.setHeaderFlag(_header);
57  file.read();
58 
59  std::vector<Real> instants;
60 
61  if (_search_by_index)
62  {
63  std::vector<std::vector<double>> data = file.getData();
64  if (_column_index >= data.size())
65  mooseError("cannot find column ", _column_index, " in file ", _file_name);
66  instants = data[_column_index];
67  }
68  else
69  instants = file.getData(_column_name);
70 
71  if (instants.size() == 0)
72  mooseError("empty sequence in file ", _file_name);
73 
74  setupSequence(instants);
75 }
void setHeaderFlag(HeaderFlag value)
void read()
Perform the actual data reading.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< std::vector< double > > & getData() const
Return the rows/columns of 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)
InputParameters validParams< TimeSequenceStepperBase >()
void setDelimiter(const std::string &value)
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
const unsigned int _column_index
index of the column containing the time data
const std::string _delimiter
string used as a delimiter