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
12
14
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");
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")
38 ? MooseUtils::DelimitedFileOfStringReader::HeaderFlag::ON
39 : MooseUtils::DelimitedFileOfStringReader::HeaderFlag::OFF)
40 : MooseUtils::DelimitedFileOfStringReader::HeaderFlag::AUTO),
41 _delimiter(getParam<std::string>("delimiter")),
42 _column_name(getParam<std::string>("column_name")),
43 _search_by_index(isParamValid("column_index")),
44 _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0)
45{
46}
47
48void
50{
52
55 file.read();
56
57 std::vector<Real> instants;
58
60 {
61 instants = file.getData<Real>(_column_index);
62 }
63 else
64 instants = file.getData<Real>(_column_name);
65
66 if (instants.size() == 0)
67 mooseError("empty sequence in file ", _file_name);
68
69 setupSequence(instants);
70}
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 MooseUtils::DelimitedFileOfStringReader::HeaderFlag _header
whether the file contains a header with the column names
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 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.
void setDelimiter(const std::string &value)
void read()
Perform the actual data reading.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< T > getData(const std::string &name) const
Converts a specific named column in the data set to a vector of a specified type.
Solves the PDEs at a sequence of given time points.
void setupSequence(const std::vector< Real > &times)
static InputParameters validParams()