@@ -173,7 +173,7 @@ SteadystateProblem::SteadystateProblem(
173173}
174174
175175void SteadystateProblem::workSteadyStateProblem (
176- Solver const & solver, Model& model, int it, realtype t0
176+ Solver& solver, Model& model, int it, realtype t0
177177) {
178178 if (model.ne > 0 ) {
179179 solver.logger ->log (
@@ -280,7 +280,7 @@ void SteadystateProblem::workSteadyStateBackwardProblem(
280280}
281281
282282void SteadystateProblem::findSteadyState (
283- Solver const & solver, Model& model, int it, realtype t0
283+ Solver& solver, Model& model, int it, realtype t0
284284) {
285285 steady_state_status_.resize (3 , SteadyStateStatus::not_run);
286286 // Turn off Newton's method if 'integrationOnly' approach is chosen for
@@ -365,7 +365,7 @@ void SteadystateProblem::findSteadyStateByNewtonsMethod(
365365}
366366
367367SteadyStateStatus SteadystateProblem::findSteadyStateBySimulation (
368- Solver const & solver, Model& model, int const it, realtype const t0
368+ Solver& solver, Model& model, int const it, realtype const t0
369369) {
370370 try {
371371 if (it < 0 ) {
@@ -551,17 +551,6 @@ void SteadystateProblem::getQuadratureBySimulation(
551551 throw AmiException (errorString.c_str ());
552552}
553553
554- realtype SteadystateProblem::getWrmsState (Model& model) {
555- updateRightHandSide (model);
556-
557- if (newton_step_conv_) {
558- newtons_method_.compute_step (ws_->xdot , {ws_->t , ws_->x , ws_->dx });
559- return wrms_computer_x_.wrms (newtons_method_.get_delta (), ws_->x );
560- }
561-
562- return wrms_computer_x_.wrms (ws_->xdot , ws_->x );
563- }
564-
565554realtype
566555SteadystateProblem::getWrmsFSA (Model& model, WRMSComputer& wrms_computer_sx) {
567556 // Forward sensitivities: Compute weighted error norm for their RHS
@@ -601,7 +590,7 @@ bool SteadystateProblem::checkSteadyStateSuccess() const {
601590}
602591
603592void SteadystateProblem::runSteadystateSimulationFwd (
604- Solver const & solver, Model& model
593+ Solver& solver, Model& model
605594) {
606595 if (model.nx_solver == 0 )
607596 return ;
@@ -643,14 +632,25 @@ void SteadystateProblem::runSteadystateSimulationFwd(
643632 sensi_converged = []() { return true ; };
644633 }
645634
635+ // Returns the WRMS for the current state
636+ auto get_wrms_state = [&]() {
637+ updateRightHandSide (model);
638+ if (newton_step_conv_) {
639+ newtons_method_.compute_step (ws_->xdot , {ws_->t , ws_->x , ws_->dx });
640+ return wrms_computer_x_.wrms (newtons_method_.get_delta (), ws_->x );
641+ }
642+
643+ return wrms_computer_x_.wrms (ws_->xdot , ws_->x );
644+ };
645+
646646 int & sim_steps = numsteps_.at (1 );
647647 int convergence_check_frequency = newton_step_conv_ ? 25 : 1 ;
648648
649649 while (true ) {
650650 if (sim_steps % convergence_check_frequency == 0 ) {
651651 // Check for convergence (already before simulation, since we might
652652 // start in steady state)
653- wrms_ = getWrmsState (model );
653+ wrms_ = get_wrms_state ( );
654654 if (wrms_ < conv_thresh && sensi_converged ()) {
655655 break ;
656656 }
@@ -756,7 +756,7 @@ void SteadystateProblem::runSteadystateSimulationBwd(
756756 solver.step (std::max (final_state_.t , 1.0 ) * 10 );
757757
758758 solver.writeSolution (
759- & final_state_.t , xB_, final_state_.dx , final_state_.sx , xQ_
759+ final_state_.t , xB_, final_state_.dx , final_state_.sx , xQ_
760760 );
761761 }
762762}
0 commit comments