https://mooseframework.inl.gov
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 
26  return params;
27 }
28 
30  : Times(parameters), _time_column_index(getParam<unsigned int>("time_column_index"))
31 {
32  const auto & times_files = getParam<std::vector<FileName>>("files");
33 
34  // Copied from MultiApp.C
35  for (const auto p_file_it : index_range(times_files))
36  {
37  const std::string times_file = times_files[p_file_it];
40  file.read();
41 
42  const auto & data = file.getData();
43  for (const auto & d : data[_time_column_index])
44  _times.push_back(d);
45  }
46 }
const unsigned int _time_column_index
Column in (all) the CSV file(s) where the time is.
Definition: CSVFileTimes.h:29
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
CSVFileTimes(const InputParameters &parameters)
Definition: CSVFileTimes.C:29
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition: Times.h:18
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & _communicator
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...
registerMooseObject("MooseApp", CSVFileTimes)
static InputParameters validParams()
Definition: Times.C:14
static InputParameters validParams()
Definition: CSVFileTimes.C:16
void read()
Perform the actual data reading.
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
Utility class for reading delimited data (e.g., CSV data).
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 optional parameter and a documentation string to the InputParameters object...
void ErrorVector unsigned int
auto index_range(const T &sizable)
std::vector< Real > & _times
The vector holding the times.
Definition: Times.h:72
Times from a file.
Definition: CSVFileTimes.h:18