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