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

Refactor: move Model::state_ initalization to ModelState ctor #2533

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
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
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
Loading