Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copyable state #673

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions include/micm/solver/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ namespace micm
std::size_t number_of_grid_cells_;
std::unique_ptr<TemporaryVariables> temporary_variables_;

/// @brief Default constructor
/// Only defined to be used to create default values in types, but a default constructed state is not useable
State();

/// @brief Constructor with parameters
/// @param parameters State dimension information
State(const StateParameters& parameters);

boulderdaze marked this conversation as resolved.
Show resolved Hide resolved
/// @brief Copy constructor
/// @param other The state object to be copied
State(const State& other)
Expand Down Expand Up @@ -102,12 +110,51 @@ namespace micm
return *this;
}

/// @brief
State();
/// @brief Move constructor
/// @param other The state object to be moved
State(State&& other) noexcept
: variables_(std::move(other.variables_)),
custom_rate_parameters_(std::move(other.custom_rate_parameters_)),
rate_constants_(std::move(other.rate_constants_)),
conditions_(std::move(other.conditions_)),
jacobian_(std::move(other.jacobian_)),
variable_map_(std::move(other.variable_map_)),
custom_rate_parameter_map_(std::move(other.custom_rate_parameter_map_)),
variable_names_(std::move(other.variable_names_)),
lower_matrix_(std::move(other.lower_matrix_)),
upper_matrix_(std::move(other.upper_matrix_)),
state_size_(other.state_size_),
number_of_grid_cells_(other.number_of_grid_cells_),
temporary_variables_(std::move(other.temporary_variables_))
{
}

/// @brief
/// @param parameters State dimension information
State(const StateParameters& parameters);
/// @brief Move assignment operator
/// @param other The state object to be moved
/// @return Reference to the moved state object
State& operator=(State&& other) noexcept
{
if (this != &other)
{
variables_ = std::move(other.variables_);
custom_rate_parameters_ = std::move(other.custom_rate_parameters_);
rate_constants_ = std::move(other.rate_constants_);
conditions_ = std::move(other.conditions_);
jacobian_ = std::move(other.jacobian_);
variable_map_ = std::move(other.variable_map_);
custom_rate_parameter_map_ = std::move(other.custom_rate_parameter_map_);
variable_names_ = std::move(other.variable_names_);
lower_matrix_ = std::move(other.lower_matrix_);
upper_matrix_ = std::move(other.upper_matrix_);
state_size_ = other.state_size_;
number_of_grid_cells_ = other.number_of_grid_cells_;
temporary_variables_ = std::move(other.temporary_variables_);

other.state_size_ = 0;
other.number_of_grid_cells_ = 0;
}
return *this;
}

/// @brief Set species' concentrations
/// @param species_to_concentration
Expand Down
Loading