23 params.
addParam<std::vector<Real>>(
"times",
"The times of the subdomain modifications.");
24 params.
addParam<std::vector<SubdomainName>>(
"blocks_from",
25 "Names or ids of the 'old' block(s), to be renamed.");
26 params.
addParam<std::vector<SubdomainName>>(
"blocks_to",
"Names or ids of the 'new' block.");
30 params.
addParam<FileName>(
"data_file",
"File holding CSV data");
32 "Indicates whether the file contains a header with the column names");
33 params.
addParam<std::string>(
"delimiter",
",",
"Delimiter used to parse the file");
34 params.
addParam<std::string>(
"comment",
";",
"Comment character used to parse the file");
36 "time_column_index", 0,
"Zero-based index of the time column. Default is '0'.");
38 "blocks_from_column_index", 1,
"Zero-based index of the blocks_from column. Default is '1'.");
40 "blocks_to_column_index", 2,
"Zero-based index of the blocks_to column. Default is '2'.");
41 params.
addParam<std::string>(
"time_column_text",
"Header text of the time column.");
42 params.
addParam<std::string>(
"blocks_from_column_text",
"Header text of the blocks_from column.");
43 params.
addParam<std::string>(
"blocks_to_column_text",
"Header text of the blocks_to column.");
45 "data_file header delimiter comment time_column_index blocks_from_column_index "
46 "blocks_to_column_index time_column_text blocks_from_column_text blocks_to_column_text",
47 "Subdomain change data from CSV file");
50 "Modify element subdomain ID of entire subdomains for given points "
51 "in time. This mesh modifier only runs on the undisplaced mesh, and it will "
52 "modify both the undisplaced and the displaced mesh.");
63 const auto from_data_file =
70 const auto from_data_File_needs_header =
isParamSetByUser(
"time_column_text") +
74 const auto from_parameters =
78 const auto from_source_count = ((from_data_file > 0) + (from_parameters > 0));
79 if (from_source_count != 1)
81 mooseError(
"Data on times and blocks must be provided either via a CSV file ('data_file' and "
82 "corresponding blocks), or via direct parameter input ('times', 'blocks_from', and "
86 if (from_parameters > 0)
88 if (from_parameters != 3)
89 mooseError(
"All parameters 'times', and 'blocks_from', and 'blocks_to' must be specified.");
92 else if (from_data_file > 0)
96 "The parameters 'time_column_index', and 'time_column_text' are mutual exclusive.");
99 mooseError(
"The parameters 'blocks_from_column_index', and 'blocks_from_column_text' are "
100 "mutual exclusive.");
103 mooseError(
"The parameters 'blocks_to_column_index', and 'blocks_to_column_text' are mutual "
106 mooseError(
"Header flag must be active if columns are to be found via header.");
111 mooseError(
"Unknown data source. Are you missing a parameter? Did you misspell one?");
117 _times = getParam<std::vector<Real>>(
"times");
118 const auto n =
_times.size();
120 const auto raw_from = getParam<std::vector<SubdomainName>>(
"blocks_from");
121 const auto raw_to = getParam<std::vector<SubdomainName>>(
"blocks_to");
123 if (raw_from.size() != n)
125 "Parameter 'blocks_from' must contain the same number of items as parameter 'times'.");
126 if (raw_to.size() != n)
127 mooseError(
"Parameter 'blocks_to' must contain the same number of items as parameter 'times'.");
132 for (
const auto i : index_range(raw_from))
142 const auto _file_name = getParam<FileName>(
"data_file");
148 _header_flag = getParam<bool>(
"header")
153 std::string _delimiter =
",";
156 _delimiter = getParam<std::string>(
"delimiter");
159 std::string _comment =
"#";
162 _comment = getParam<std::string>(
"comment");
172 std::size_t _time_column = 0;
175 const auto s = getParam<std::string>(
"time_column_text");
176 const auto _names = file.
getNames();
177 const auto it = find(_names.begin(), _names.end(), s);
178 if (it == _names.end())
179 mooseError(
"Could not find '", s,
"' in header of file ", _file_name,
".");
180 _time_column = std::distance(_names.begin(), it);
184 _time_column = getParam<std::size_t>(
"time_column_index");
187 std::size_t _blocks_from_column = 1;
190 const auto s = getParam<std::string>(
"blocks_from_column_text");
191 const auto _names = file.
getNames();
192 const auto it = find(_names.begin(), _names.end(), s);
193 if (it == _names.end())
194 mooseError(
"Could not find '", s,
"' in header of file ", _file_name,
".");
195 _blocks_from_column = std::distance(_names.begin(), it);
199 _blocks_from_column = getParam<std::size_t>(
"blocks_from_column_index");
202 std::size_t _blocks_to_column = 2;
205 const auto s = getParam<std::string>(
"blocks_to_column_text");
206 const auto _names = file.
getNames();
207 const auto it = find(_names.begin(), _names.end(), s);
208 if (it == _names.end())
209 mooseError(
"Could not find '", s,
"' in header of file ", _file_name,
".");
210 _blocks_to_column = std::distance(_names.begin(), it);
213 _blocks_to_column = getParam<std::size_t>(
"blocks_to_column_index");
215 const auto max_needed_column_index =
216 std::max({_time_column, _blocks_from_column, _blocks_to_column});
218 const auto data = file.
getData();
220 if (data.size() < max_needed_column_index)
221 mooseError(
"data must contain at least " + std::to_string(max_needed_column_index) +
225 const auto strTimes = data[_time_column];
226 const auto strBlockFrom = data[_blocks_from_column];
227 const auto strBlockTo = data[_blocks_to_column];
229 const auto n_rows = strTimes.size();
233 mooseError(
"empty sequence in file ", _file_name);
234 if (n_rows != strBlockFrom.size())
235 mooseError(
"Inconsistent source block data size in ",
240 strBlockFrom.size());
241 if (n_rows != strBlockTo.size())
242 mooseError(
"Inconsistent target block data size in ",
254 for (
const auto & time_str : strTimes)
255 _times.push_back(std::stod(time_str));
256 std::transform(strBlockFrom.begin(),
259 [
this](
const std::string & x) { return getSubdomainIDAndCheck(x); });
260 std::transform(strBlockTo.begin(),
263 [
this](
const std::string & x) { return getSubdomainIDAndCheck(x); });
272 mooseError(
"block",
"Subdomain \"" +
name +
"\" not found in mesh.");
287 const auto t = time_pair.time;
290 const auto j = time_pair.index;
300 return resulting_subdomain_id;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
registerMooseObject("MooseApp", TimedSubdomainModifier)
const Elem *const & _current_elem
The current element pointer (available during execute())
const std::string & name() const
Get the name of the class.
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
Utility class for reading delimited data (e.g., CSV data).
const std::vector< std::string > & getNames() const
Return the column/row names.
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
void setHeaderFlag(HeaderFlag value)
void setComment(const std::string &value)
void setDelimiter(const std::string &value)
void read()
Perform the actual data reading.
Modifies element subdomains only at a given list of times.
std::set< TimeIndexPair > _times_and_indices
Times and subdomain changes to make.
static InputParameters validParams()
Modifies elements from entire subdomains based on user input or file input.
TimedSubdomainModifier(const InputParameters ¶meters)
static InputParameters validParams()
virtual SubdomainID computeSubdomainID() override
Compute the subdomain ID of the current element.
std::vector< Real > _times
Times to change the subdomains on.
std::vector< SubdomainID > _blocks_to
Target subdomains to change the source subdomains to.
SubdomainID getSubdomainIDAndCheck(const std::string &subdomain_name)
void buildFromParameters()
std::vector< SubdomainID > _blocks_from
Source subdomains to change from.
const Real & _t_old
Old time.
std::string trim(const std::string &str, const std::string &white_space=" \t\n\v\f\r")
Standard scripting language trim function.
const SubdomainID INVALID_BLOCK_ID