https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSVFileTimes.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
10#include "CSVFileTimes.h"
11#include "DelimitedFileReader.h"
12
14
17{
19 params.addClassDescription("Import times from one or more files.");
20 params.addRequiredParam<std::vector<FileName>>("files",
21 "Text file(s) with the times, one per line");
22 params.addParam<unsigned int>("time_column_index", 0, "Index for the column with the time");
23 // File is loaded on all processes
24 params.set<bool>("auto_broadcast") = false;
25 // CSV file set the time sequence during initialization stage
26 params.set<bool>("dynamic_time_sequence") = false;
27
28 return params;
29}
30
32 : Times(parameters), _time_column_index(getParam<unsigned int>("time_column_index"))
33{
34 const auto & times_files = getParam<std::vector<FileName>>("files");
35
36 // Copied from MultiApp.C
37 for (const auto p_file_it : index_range(times_files))
38 {
39 const std::string times_file = times_files[p_file_it];
42 file.read();
43
44 const auto & data = file.getData();
45 for (const auto & d : data[_time_column_index])
46 _times.push_back(d);
47 }
48}
registerMooseObject("MooseApp", CSVFileTimes)
void ErrorVector unsigned int
Times from a file.
CSVFileTimes(const InputParameters &parameters)
const unsigned int _time_column_index
Column in (all) the CSV file(s) where the time is.
static InputParameters validParams()
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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 read()
Perform the actual data reading.
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition Times.h:19
static InputParameters validParams()
Definition Times.C:14
std::vector< Real > & _times
The vector holding the times.
Definition Times.h:74
const Parallel::Communicator & _communicator