Skip to content

Commit

Permalink
Copyable state (#673)
Browse files Browse the repository at this point in the history
* defining move assignment and copy for state

* default constructor

* fixing default constructor

* pr comments
  • Loading branch information
K20shores authored Oct 2, 2024
1 parent 023c83d commit b3c462a
Showing 1 changed file with 52 additions and 5 deletions.
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);

/// @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

0 comments on commit b3c462a

Please sign in to comment.