Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsayad committed Jun 19, 2024
1 parent 8ca9600 commit 5ad0001
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
6 changes: 3 additions & 3 deletions framework/include/userobjects/TimedElementSubdomainModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class TimedElementSubdomainModifier : public ElementSubdomainModifier
virtual std::vector<Real> 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;
Expand All @@ -47,5 +47,5 @@ class TimedElementSubdomainModifier : public ElementSubdomainModifier
};

/// Times and subdomain changes to make
std::set<timeIndexPair> _times_and_indices;
std::set<TimeIndexPair> _times_and_indices;
};
13 changes: 3 additions & 10 deletions framework/src/userobjects/TimedElementSubdomainModifier.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
InputParameters
TimedElementSubdomainModifier::validParams()
{
InputParameters params = ElementSubdomainModifier::validParams();
params.addParam<std::vector<Real>>("times", "The times of the subdomain modifications.");
return params;
return ElementSubdomainModifier::validParams();
}

TimedElementSubdomainModifier::TimedElementSubdomainModifier(const InputParameters & parameters)
Expand All @@ -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});
}
34 changes: 16 additions & 18 deletions framework/src/userobjects/TimedSubdomainModifier.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ TimedSubdomainModifier::validParams()
{
InputParameters params = TimedElementSubdomainModifier::validParams();

// parameters for direct input (additionally to 'times')
// parameters for direct input
params.addParam<std::vector<Real>>("times", "The times of the subdomain modifications.");
params.addParam<std::vector<SubdomainName>>("blocks_from",
"Names or ids of the 'old' block(s), to be renamed.");
params.addParam<std::vector<SubdomainName>>("blocks_to", "Names or ids of the 'new' block.");
Expand All @@ -31,11 +32,11 @@ TimedSubdomainModifier::validParams()
"Indicates whether the file contains a header with the column names");
params.addParam<std::string>("delimiter", ",", "Delimiter used to parse the file");
params.addParam<std::string>("comment", ";", "Comment character used to parse the file");
params.addParam<size_t>(
params.addParam<std::size_t>(
"time_column_index", 0, "Zero-based index of the time column. Default is '0'.");
params.addParam<size_t>(
params.addParam<std::size_t>(
"blocks_from_column_index", 1, "Zero-based index of the blocks_from column. Default is '1'.");
params.addParam<size_t>(
params.addParam<std::size_t>(
"blocks_to_column_index", 2, "Zero-based index of the blocks_to column. Default is '2'.");
params.addParam<std::string>("time_column_text", "Header text of the time column.");
params.addParam<std::string>("blocks_from_column_text", "Header text of the blocks_from column.");
Expand Down Expand Up @@ -113,7 +114,6 @@ TimedSubdomainModifier::TimedSubdomainModifier(const InputParameters & parameter
void
TimedSubdomainModifier::buildFromParameters()
{

_times = getParam<std::vector<Real>>("times");
const auto n = _times.size();

Expand All @@ -129,11 +129,10 @@ TimedSubdomainModifier::buildFromParameters()
_blocks_from.resize(n);
_blocks_to.resize(n);

const std::shared_ptr<MooseMesh> _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]);
}
}

Expand Down Expand Up @@ -170,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<std::string>("time_column_text");
Expand All @@ -182,10 +181,10 @@ TimedSubdomainModifier::buildFromFile()
}
else if (isParamValid("time_column_index"))
{
_time_column = getParam<size_t>("time_column_index");
_time_column = getParam<std::size_t>("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<std::string>("blocks_from_column_text");
Expand All @@ -197,10 +196,10 @@ TimedSubdomainModifier::buildFromFile()
}
else if (isParamValid("blocks_from_column_index"))
{
_blocks_from_column = getParam<size_t>("blocks_from_column_index");
_blocks_from_column = getParam<std::size_t>("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<std::string>("blocks_to_column_text");
Expand All @@ -211,7 +210,7 @@ TimedSubdomainModifier::buildFromFile()
_blocks_to_column = std::distance(_names.begin(), it);
}
else if (isParamValid("blocks_to_column_index"))
_blocks_to_column = getParam<size_t>("blocks_to_column_index");
_blocks_to_column = getParam<std::size_t>("blocks_to_column_index");

const auto max_needed_column_index =
std::max({_time_column, _blocks_from_column, _blocks_to_column});
Expand Down Expand Up @@ -252,17 +251,16 @@ TimedSubdomainModifier::buildFromFile()
_blocks_to.resize(n_rows);

// fill the to and from blocks vectors
const std::shared_ptr<MooseMesh> _mesh = _app.actionWarehouse().mesh();
for (const auto & time_str : strTimes)
_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
Expand All @@ -273,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;
Expand Down

0 comments on commit 5ad0001

Please sign in to comment.