https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSVTimeSequenceStepper.C
Go to the documentation of this file.
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
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");
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
46void
48{
50
53 file.read();
54
55 std::vector<Real> instants;
56
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}
registerMooseObject("MooseApp", CSVTimeSequenceStepper)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void ErrorVector unsigned int
Solves the PDEs at a sequence of time points given as a column in a text table file (such as a *....
const std::string _delimiter
string used as a delimiter
const bool _search_by_index
indicates whether to access a column using its index or its name
CSVTimeSequenceStepper(const InputParameters &parameters)
const std::string _file_name
name of the file where the data is read
static InputParameters validParams()
const unsigned int _column_index
index of the column containing the time data
virtual void init() override
Initialize the time stepper.
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
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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...
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.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
void setDelimiter(const std::string &value)
void read()
Perform the actual data reading.
Solves the PDEs at a sequence of given time points.
void setupSequence(const std::vector< Real > &times)
static InputParameters validParams()