Line data Source code
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 : 13 : registerMooseObject("MooseApp", CSVFileTimes); 14 : 15 : InputParameters 16 14289 : CSVFileTimes::validParams() 17 : { 18 14289 : InputParameters params = Times::validParams(); 19 14289 : params.addClassDescription("Import times from one or more files."); 20 14289 : params.addRequiredParam<std::vector<FileName>>("files", 21 : "Text file(s) with the times, one per line"); 22 14289 : params.addParam<unsigned int>("time_column_index", 0, "Index for the column with the time"); 23 : // File is loaded on all processes 24 14289 : params.set<bool>("auto_broadcast") = false; 25 : 26 14289 : return params; 27 0 : } 28 : 29 12 : CSVFileTimes::CSVFileTimes(const InputParameters & parameters) 30 12 : : Times(parameters), _time_column_index(getParam<unsigned int>("time_column_index")) 31 : { 32 12 : const auto & times_files = getParam<std::vector<FileName>>("files"); 33 : 34 : // Copied from MultiApp.C 35 24 : for (const auto p_file_it : index_range(times_files)) 36 : { 37 12 : const std::string times_file = times_files[p_file_it]; 38 12 : MooseUtils::DelimitedFileReader file(times_file, &_communicator); 39 12 : file.setFormatFlag(MooseUtils::DelimitedFileReader::FormatFlag::COLUMNS); 40 12 : file.read(); 41 : 42 12 : const auto & data = file.getData(); 43 264 : for (const auto & d : data[_time_column_index]) 44 252 : _times.push_back(d); 45 12 : } 46 12 : }