diff --git a/framework/include/userobjects/TimedElementSubdomainModifier.h b/framework/include/userobjects/TimedElementSubdomainModifier.h index 47e6f5a62f9a..c6f0ac917be6 100644 --- a/framework/include/userobjects/TimedElementSubdomainModifier.h +++ b/framework/include/userobjects/TimedElementSubdomainModifier.h @@ -26,18 +26,18 @@ class TimedElementSubdomainModifier : public ElementSubdomainModifier protected: /** * Requests a vector of all times from the inheriting class - * (these do not have to be sorted). + * (these do not have to be sorted and may have duplicates). * @returns Unsorted vector of times. */ - virtual std::set getTimes() = 0; + virtual std::vector getTimes() = 0; /// storage for the times including their original index. - struct timeIndexPair + struct TimeIndexPair { Real time; std::size_t index; - bool operator<(const timeIndexPair & a) const + bool operator<(const TimeIndexPair & a) const { if (time == a.time) return index < a.index; @@ -47,5 +47,5 @@ class TimedElementSubdomainModifier : public ElementSubdomainModifier }; /// Times and subdomain changes to make - std::set _times_and_indices; + std::set _times_and_indices; }; diff --git a/framework/include/userobjects/TimedSubdomainModifier.h b/framework/include/userobjects/TimedSubdomainModifier.h index efc1e4549540..d543edbd0247 100644 --- a/framework/include/userobjects/TimedSubdomainModifier.h +++ b/framework/include/userobjects/TimedSubdomainModifier.h @@ -24,7 +24,7 @@ class TimedSubdomainModifier : public TimedElementSubdomainModifier TimedSubdomainModifier(const InputParameters & parameters); protected: - virtual std::set getTimes() override { return _times; } + virtual std::vector getTimes() override { return _times; } virtual SubdomainID computeSubdomainID() override; @@ -33,8 +33,9 @@ class TimedSubdomainModifier : public TimedElementSubdomainModifier void buildFromFile(); /// Times to change the subdomains on. If the time steps do not align with the times, - /// the subdomain changes will happen at the end of the time step - std::set _times; + /// the subdomain changes will happen at the end of the time step. + /// The sort order of this vector must match _blocks_from and _blocks_to. + std::vector _times; /// Source subdomains to change from std::vector _blocks_from; diff --git a/framework/src/userobjects/TimedElementSubdomainModifier.C b/framework/src/userobjects/TimedElementSubdomainModifier.C index a49f45033dac..d2bda8b74401 100644 --- a/framework/src/userobjects/TimedElementSubdomainModifier.C +++ b/framework/src/userobjects/TimedElementSubdomainModifier.C @@ -14,9 +14,7 @@ InputParameters TimedElementSubdomainModifier::validParams() { - InputParameters params = ElementSubdomainModifier::validParams(); - params.addParam>("times", "The times of the subdomain modifications."); - return params; + return ElementSubdomainModifier::validParams(); } TimedElementSubdomainModifier::TimedElementSubdomainModifier(const InputParameters & parameters) @@ -31,12 +29,7 @@ TimedElementSubdomainModifier::initialize() const auto times = getTimes(); // copy data to local storage - unsigned int i = 0; + std::size_t i = 0; for (const auto time : times) - { - timeIndexPair pair; - pair.time = time; - pair.index = i++; - _times_and_indices.insert(pair); - } + _times_and_indices.insert(TimeIndexPair{time, i++}); } diff --git a/framework/src/userobjects/TimedSubdomainModifier.C b/framework/src/userobjects/TimedSubdomainModifier.C index fc207fc296b0..e2904a265d9c 100644 --- a/framework/src/userobjects/TimedSubdomainModifier.C +++ b/framework/src/userobjects/TimedSubdomainModifier.C @@ -19,7 +19,8 @@ TimedSubdomainModifier::validParams() { InputParameters params = TimedElementSubdomainModifier::validParams(); - // parameters for direct input (additionally to 'times') + // parameters for direct input + params.addParam>("times", "The times of the subdomain modifications."); params.addParam>("blocks_from", "Names or ids of the 'old' block(s), to be renamed."); params.addParam>("blocks_to", "Names or ids of the 'new' block."); @@ -31,11 +32,11 @@ TimedSubdomainModifier::validParams() "Indicates whether the file contains a header with the column names"); params.addParam("delimiter", ",", "Delimiter used to parse the file"); params.addParam("comment", ";", "Comment character used to parse the file"); - params.addParam( + params.addParam( "time_column_index", 0, "Zero-based index of the time column. Default is '0'."); - params.addParam( + params.addParam( "blocks_from_column_index", 1, "Zero-based index of the blocks_from column. Default is '1'."); - params.addParam( + params.addParam( "blocks_to_column_index", 2, "Zero-based index of the blocks_to column. Default is '2'."); params.addParam("time_column_text", "Header text of the time column."); params.addParam("blocks_from_column_text", "Header text of the blocks_from column."); @@ -113,9 +114,7 @@ TimedSubdomainModifier::TimedSubdomainModifier(const InputParameters & parameter void TimedSubdomainModifier::buildFromParameters() { - - const auto times = getParam>("times"); - _times = std::set(times.begin(), times.end()); + _times = getParam>("times"); const auto n = _times.size(); const auto raw_from = getParam>("blocks_from"); @@ -130,11 +129,10 @@ TimedSubdomainModifier::buildFromParameters() _blocks_from.resize(n); _blocks_to.resize(n); - const std::shared_ptr _mesh = _app.actionWarehouse().mesh(); for (const auto i : index_range(raw_from)) { - _blocks_from[i] = _mesh->getSubdomainID(raw_from[i]); - _blocks_to[i] = _mesh->getSubdomainID(raw_to[i]); + _blocks_from[i] = _mesh.getSubdomainID(raw_from[i]); + _blocks_to[i] = _mesh.getSubdomainID(raw_to[i]); } } @@ -171,7 +169,7 @@ TimedSubdomainModifier::buildFromFile() file.setComment(_comment); file.read(); - size_t _time_column = 0; + std::size_t _time_column = 0; if (isParamValid("time_column_text")) { const auto s = getParam("time_column_text"); @@ -183,10 +181,10 @@ TimedSubdomainModifier::buildFromFile() } else if (isParamValid("time_column_index")) { - _time_column = getParam("time_column_index"); + _time_column = getParam("time_column_index"); } - size_t _blocks_from_column = 1; + std::size_t _blocks_from_column = 1; if (isParamValid("blocks_from_column_text")) { const auto s = getParam("blocks_from_column_text"); @@ -198,10 +196,10 @@ TimedSubdomainModifier::buildFromFile() } else if (isParamValid("blocks_from_column_index")) { - _blocks_from_column = getParam("blocks_from_column_index"); + _blocks_from_column = getParam("blocks_from_column_index"); } - size_t _blocks_to_column = 2; + std::size_t _blocks_to_column = 2; if (isParamValid("blocks_to_column_text")) { const auto s = getParam("blocks_to_column_text"); @@ -212,7 +210,7 @@ TimedSubdomainModifier::buildFromFile() _blocks_to_column = std::distance(_names.begin(), it); } else if (isParamValid("blocks_to_column_index")) - _blocks_to_column = getParam("blocks_to_column_index"); + _blocks_to_column = getParam("blocks_to_column_index"); const auto max_needed_column_index = std::max({_time_column, _blocks_from_column, _blocks_to_column}); @@ -253,17 +251,16 @@ TimedSubdomainModifier::buildFromFile() _blocks_to.resize(n_rows); // fill the to and from blocks vectors - const std::shared_ptr _mesh = _app.actionWarehouse().mesh(); for (const auto & time_str : strTimes) - _times.insert(std::stod(time_str)); + _times.push_back(std::stod(time_str)); std::transform(strBlockFrom.begin(), strBlockFrom.end(), _blocks_from.begin(), - [_mesh](std::string x) { return _mesh->getSubdomainID(x); }); + [this](const std::string & x) { return _mesh.getSubdomainID(x); }); std::transform(strBlockTo.begin(), strBlockTo.end(), _blocks_to.begin(), - [_mesh](std::string x) { return _mesh->getSubdomainID(x); }); + [this](const std::string & x) { return _mesh.getSubdomainID(x); }); } SubdomainID @@ -274,7 +271,7 @@ TimedSubdomainModifier::computeSubdomainID() // check for all the subdomain changes that can have been requested between the previous and the // current time - for (const auto time_pair : _times_and_indices) + for (const auto & time_pair : _times_and_indices) { // time of the data point const auto t = time_pair.time; diff --git a/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s004 b/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s004 new file mode 100644 index 000000000000..1e82519cf10d Binary files /dev/null and b/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s004 differ diff --git a/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s006 b/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s006 index 3561897e6969..18b6a653e0b1 100644 Binary files a/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s006 and b/test/tests/userobjects/element_subdomain_modifier/gold/tsm_direct_out.e-s006 differ diff --git a/test/tests/userobjects/element_subdomain_modifier/tests b/test/tests/userobjects/element_subdomain_modifier/tests index 1a1c841d34a2..042cf2d624c5 100644 --- a/test/tests/userobjects/element_subdomain_modifier/tests +++ b/test/tests/userobjects/element_subdomain_modifier/tests @@ -144,7 +144,7 @@ [direct] type = 'Exodiff' input = 'tsm_direct.i' - exodiff = 'tsm_direct_out.e-s006' + exodiff = 'tsm_direct_out.e-s004 tsm_direct_out.e-s006' detail = 'listed in the input file,' exodiff_opts = '-pedantic' [] diff --git a/test/tests/userobjects/element_subdomain_modifier/tsm_direct.i b/test/tests/userobjects/element_subdomain_modifier/tsm_direct.i index a27fbf1b94b0..09fd38700d0e 100644 --- a/test/tests/userobjects/element_subdomain_modifier/tsm_direct.i +++ b/test/tests/userobjects/element_subdomain_modifier/tsm_direct.i @@ -6,17 +6,19 @@ material_coverage_check = false [] -Box2_inactive_id = '3' +Box2_inactive_id = '4' +Box3_inactive_id = '5' Box2_inactive_name = 'Box2_inactive' -inactive_domain_block_ids = ${Box2_inactive_id} -inactive_domain_block_names = ${Box2_inactive_name} +Box3_inactive_name = 'Box3_inactive' +inactive_domain_block_ids = '${Box2_inactive_id} ${Box3_inactive_id}' +inactive_domain_block_names = '${Box2_inactive_name} ${Box3_inactive_name}' [Mesh] [BaseMesh] type = GeneratedMeshGenerator elem_type = TET4 dim = 3 - nx = 5 + nx = 4 ny = 3 nz = 2 xmin = -10 @@ -41,8 +43,17 @@ inactive_domain_block_names = ${Box2_inactive_name} input = "Box1" block_id = 2 location = "INSIDE" - bottom_left = "-2 -2 +2" - top_right = "+2 +2 0" + bottom_left = "-4 -3 +3" + top_right = "0 +3 0" + [] + + [Box3] + type = SubdomainBoundingBoxGenerator + input = "Box2" + block_id = 3 + location = "INSIDE" + bottom_left = "0 -3 +2" + top_right = "+4 +3 0" [] add_subdomain_ids = ${inactive_domain_block_ids} @@ -59,9 +70,9 @@ inactive_domain_block_names = ${Box2_inactive_name} [UserObjects] [GlobalSubdomainModifier] type = TimedSubdomainModifier - times = '0.4 0.6' - blocks_from = '2 3' - blocks_to = 'Box2_inactive 2' # Subdomain names are permitted ('Box2_inactive' = 3) + times = ' 0.4 0.6 0.4' + blocks_from = '2 4 3' + blocks_to = ' Box2_inactive 2 Box3_inactive' # Subdomain names are permitted ('Box2_inactive' = 4, etc) execute_on = 'INITIAL TIMESTEP_BEGIN' [] []