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 "CSVTimeSequenceStepper.h" 11 : 12 : registerMooseObject("MooseApp", CSVTimeSequenceStepper); 13 : 14 : InputParameters 15 14313 : CSVTimeSequenceStepper::validParams() 16 : { 17 14313 : InputParameters params = TimeSequenceStepperBase::validParams(); 18 14313 : params.addRequiredParam<FileName>("file_name", 19 : "name of the file in which the time sequence is read"); 20 14313 : params.addParam<bool>("header", 21 : "indicates whether the file contains a header with the column names"); 22 14313 : params.addParam<std::string>("delimiter", ",", "delimiter used to parse the file"); 23 14313 : params.addParam<std::string>( 24 : "column_name", "time", "name of the column which contains the time sequence"); 25 14313 : params.addParam<unsigned int>("column_index", 26 : "index of the column which contains the time sequence"); 27 14313 : params.addClassDescription( 28 : "Solves the Transient problem at a sequence of given time points read in a file."); 29 14313 : return params; 30 0 : } 31 : 32 24 : CSVTimeSequenceStepper::CSVTimeSequenceStepper(const InputParameters & parameters) 33 : : TimeSequenceStepperBase(parameters), 34 24 : _file_name(getParam<FileName>("file_name")), 35 48 : _header(isParamValid("header") 36 24 : ? (getParam<bool>("header") ? MooseUtils::DelimitedFileReader::HeaderFlag::ON 37 : : MooseUtils::DelimitedFileReader::HeaderFlag::OFF) 38 : : MooseUtils::DelimitedFileReader::HeaderFlag::AUTO), 39 24 : _delimiter(getParam<std::string>("delimiter")), 40 24 : _column_name(getParam<std::string>("column_name")), 41 24 : _search_by_index(isParamValid("column_index")), 42 48 : _column_index(_search_by_index ? getParam<unsigned int>("column_index") : 0) 43 : { 44 24 : } 45 : 46 : void 47 24 : CSVTimeSequenceStepper::init() 48 : { 49 24 : MooseUtils::DelimitedFileReader file(_file_name); 50 : 51 24 : file.setHeaderFlag(_header); 52 24 : file.setDelimiter(_delimiter); 53 24 : file.read(); 54 : 55 24 : std::vector<Real> instants; 56 : 57 24 : if (_search_by_index) 58 : { 59 0 : std::vector<std::vector<double>> data = file.getData(); 60 0 : if (_column_index >= data.size()) 61 0 : mooseError("cannot find column ", _column_index, " in file ", _file_name); 62 0 : instants = data[_column_index]; 63 0 : } 64 : else 65 24 : instants = file.getData(_column_name); 66 : 67 24 : if (instants.size() == 0) 68 0 : mooseError("empty sequence in file ", _file_name); 69 : 70 24 : setupSequence(instants); 71 24 : }