Skip to content

Commit

Permalink
Refactor: move Model::state_ initalization to ModelState ctor (AMICI-…
Browse files Browse the repository at this point in the history
…dev#2533)

Move `Model::state_` initalization to `ModelState` ctor where it belongs.

Closes AMICI-dev#2531.
  • Loading branch information
dweindl authored Oct 10, 2024
1 parent b7a3e91 commit f5533ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 13 additions & 0 deletions include/amici/model_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ namespace amici {
* number of attributes that need to be transferred.
*/
struct ModelState {
ModelState() = default;
/**
* @brief Constructor from model dimensions.
* @param dim Model dimensions
*/
explicit ModelState(ModelDimensions const& dim) {
h.resize(dim.ne, 0.0);
total_cl.resize(dim.nx_rdata - dim.nx_solver, 0.0);
stotal_cl.resize((dim.nx_rdata - dim.nx_solver) * dim.np, 0.0);
unscaledParameters.resize(dim.np);
fixedParameters.resize(dim.nk);
}

/**
* Flag indicating whether a certain Heaviside function should be active or
* not (dimension: `ne`)
Expand Down
7 changes: 2 additions & 5 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ Model::Model(
, o2mode(o2mode)
, idlist(std::move(idlist))
, state_independent_events_(std::move(state_independent_events))
, derived_state_(model_dimensions)
, state_(*this)
, derived_state_(*this)
, z2event_(std::move(z2event))
, state_is_non_negative_(nx_solver, false)
, simulation_parameters_(std::move(simulation_parameters)) {
Expand All @@ -200,10 +201,6 @@ Model::Model(
model_dimensions.np, ParameterScaling::none
);

state_.h.resize(ne, 0.0);
state_.total_cl.resize(nx_rdata - nx_solver, 0.0);
state_.stotal_cl.resize((nx_rdata - nx_solver) * np(), 0.0);
state_.unscaledParameters.resize(np());
unscaleParameters(
simulation_parameters_.parameters, simulation_parameters_.pscale,
state_.unscaledParameters
Expand Down

0 comments on commit f5533ba

Please sign in to comment.