From b3c462a9658e443e95ee9daf354036f7dda866aa Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Wed, 2 Oct 2024 11:23:02 -0500 Subject: [PATCH] Copyable state (#673) * defining move assignment and copy for state * default constructor * fixing default constructor * pr comments --- include/micm/solver/state.hpp | 57 ++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/include/micm/solver/state.hpp b/include/micm/solver/state.hpp index 29bd50d37..ff8f23817 100644 --- a/include/micm/solver/state.hpp +++ b/include/micm/solver/state.hpp @@ -59,6 +59,14 @@ namespace micm std::size_t number_of_grid_cells_; std::unique_ptr 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) @@ -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