Template:CMI Example CMI run CXX: Difference between revisions
From CSDMS
Automated import of articles |
Automated import of articles *** existing text overwritten *** |
||
Line 1: | Line 1: | ||
<syntaxhighlight lang=cpp> | <syntaxhighlight lang=cpp> | ||
this->log.info ("Updating."); | |||
this->log.info (this->CMI_get_status ()); | |||
if (this->status == CMI_STATUS_UPDATING) | if (this->status == CMI_STATUS_UPDATING) | ||
Line 8: | Line 8: | ||
this->status = CMI_STATUS_UPDATING; | this->status = CMI_STATUS_UPDATING; | ||
{ | { | ||
double print_time = this->print_q.next_print_time (); | double print_time = this->print_q.next_print_time (); | ||
while (print_time>0 && print_time<time_interval) | while (print_time>0 && print_time<time_interval) | ||
{ | { | ||
this->status = CMI_STATUS_UPDATED; | this->status = CMI_STATUS_UPDATED; | ||
" | this->log.info ("Running until next print time."); | ||
this->CMI_run (print_time); | this->CMI_run (print_time); | ||
this->print_q.print_all (print_time); | this->print_q.print_all (print_time); | ||
print_time = this->print_q.next_print_time (); | print_time = this->print_q.next_print_time (); | ||
} | } | ||
} | } | ||
{ // Run model until the stop time | { // Run model until the stop time | ||
double now = this->state.get_current_time (); | double now = this->state.get_current_time (); | ||
Line 39: | Line 28: | ||
for (; t<time_interval; t+=port_queue_dt) | for (; t<time_interval; t+=port_queue_dt) | ||
{ | { | ||
#if CMI_TURN_OFF_PORTS | #if CMI_TURN_OFF_PORTS | ||
this->log.warning ("Forgetting ports for now."); | |||
" | |||
#else | #else | ||
this->log.info ("Updating ports."); | |||
" | |||
this->ports.run_ports (now); | this->ports.run_ports (now); | ||
#endif | #endif | ||
#if CMI_TURN_OFF_MAPPING | #if CMI_TURN_OFF_MAPPING | ||
this->log.warning ("Not mapping values."); | |||
" | |||
#else | #else | ||
this->log.info ("Mapping values."); | |||
" | |||
this->ports.run_mappers (); | this->ports.run_mappers (); | ||
#endif | #endif | ||
this->log.info ("Updating myself."); | |||
" | |||
this->state.update_until (t); | this->state.update_until (t); | ||
now = this->state.get_current_time (); | now = this->state.get_current_time (); | ||
} | } | ||
Line 71: | Line 50: | ||
if (t>time_interval) | if (t>time_interval) | ||
{ // The last partial time step (if necessary). | { // The last partial time step (if necessary). | ||
#if CMI_TURN_OFF_PORTS | #if CMI_TURN_OFF_PORTS | ||
this->log.warning ("Forgetting ports for now."); | |||
" | |||
#else | #else | ||
this->log.info ("Updating ports."); | |||
" | |||
this->ports.run_ports (now); | this->ports.run_ports (now); | ||
#endif | #endif | ||
#if CMI_TURN_OFF_MAPPING | #if CMI_TURN_OFF_MAPPING | ||
this->log.warning ("Not mapping values."); | |||
" | |||
#else | #else | ||
this->log.info ("Mapping values."); | |||
" | |||
this->ports.run_mappers (); | this->ports.run_mappers (); | ||
#endif | #endif | ||
this->log.info ("Updating myself."); | |||
" | |||
this->state.update_until (time_interval); | this->state.update_until (time_interval); | ||
} | } | ||
} | } | ||
this->status = CMI_STATUS_UPDATED; | this->status = CMI_STATUS_UPDATED; | ||
Line 107: | Line 73: | ||
<< this->CMI_get_status () << ::std::endl; | << this->CMI_get_status () << ::std::endl; | ||
this->log.info ("Updated."); | |||
this->log.info (this->CMI_get_status ()); | |||
return TRUE; | return TRUE; | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 11:53, 6 February 2012
this->log.info ("Updating.");
this->log.info (this->CMI_get_status ());
if (this->status == CMI_STATUS_UPDATING)
return TRUE;
else
this->status = CMI_STATUS_UPDATING;
{
double print_time = this->print_q.next_print_time ();
while (print_time>0 && print_time<time_interval)
{
this->status = CMI_STATUS_UPDATED;
this->log.info ("Running until next print time.");
this->CMI_run (print_time);
this->print_q.print_all (print_time);
print_time = this->print_q.next_print_time ();
}
}
{ // Run model until the stop time
double now = this->state.get_current_time ();
double port_queue_dt = CMI_PORT_QUEUE_DT;
double t = now + port_queue_dt;
for (; t<time_interval; t+=port_queue_dt)
{
#if CMI_TURN_OFF_PORTS
this->log.warning ("Forgetting ports for now.");
#else
this->log.info ("Updating ports.");
this->ports.run_ports (now);
#endif
#if CMI_TURN_OFF_MAPPING
this->log.warning ("Not mapping values.");
#else
this->log.info ("Mapping values.");
this->ports.run_mappers ();
#endif
this->log.info ("Updating myself.");
this->state.update_until (t);
now = this->state.get_current_time ();
}
if (t>time_interval)
{ // The last partial time step (if necessary).
#if CMI_TURN_OFF_PORTS
this->log.warning ("Forgetting ports for now.");
#else
this->log.info ("Updating ports.");
this->ports.run_ports (now);
#endif
#if CMI_TURN_OFF_MAPPING
this->log.warning ("Not mapping values.");
#else
this->log.info ("Mapping values.");
this->ports.run_mappers ();
#endif
this->log.info ("Updating myself.");
this->state.update_until (time_interval);
}
}
this->status = CMI_STATUS_UPDATED;
::std::cerr << CMI_COMPONENT_NAME ": Status is "
<< this->CMI_get_status () << ::std::endl;
this->log.info ("Updated.");
this->log.info (this->CMI_get_status ());
return TRUE;