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>
   ::std::cerr << CMI_COMPONENT_NAME ": Status is "
   this->log.info ("Updating.");
              << this->CMI_get_status () << ::std::endl;
  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;


  fprintf (stderr, "%s: Updating until %f.
", CMI_COMPONENT_NAME, time_interval);
   {
   {
     double print_time = this->print_q.next_print_time ();
     double print_time = this->print_q.next_print_time ();
    fprintf (stderr, "%s: Next print time is %f.
", CMI_COMPONENT_NAME, 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;
       fprintf (stderr, "%s: Running until print time %f.
 
", CMI_COMPONENT_NAME, print_time);
       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 ();
      fprintf (stderr, "%s: Print time is now %f.
", CMI_COMPONENT_NAME, print_time);
     }
     }
   }
   }
/*
  if (time_interval > this->state.get_end_time ())
    time_interval = this->state.get_end_time ();
*/


  fprintf (stderr, "%s: Updating (0) ports until %f.
", CMI_COMPONENT_NAME, time_interval);
   { // 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)
     {
     {
      //this->print_q.print_all (now);
#if CMI_TURN_OFF_PORTS
#if CMI_TURN_OFF_PORTS
       fprintf (stderr, "%s: Forgetting ports for now.
       this->log.warning ("Forgetting ports for now.");
", CMI_COMPONENT_NAME);
#else
#else
       fprintf (stderr, "%s: Updating (1) ports until %f.
       this->log.info ("Updating ports.");
", CMI_COMPONENT_NAME, now);
      fflush (stderr);
       this->ports.run_ports (now);
       this->ports.run_ports (now);
#endif
#endif


#if CMI_TURN_OFF_MAPPING
#if CMI_TURN_OFF_MAPPING
       fprintf (stderr, "%s: Not mapping values (0).
       this->log.warning ("Not mapping values.");
", CMI_COMPONENT_NAME);
#else
#else
       fprintf (stderr, "%s: Map values.
       this->log.info ("Mapping values.");
", CMI_COMPONENT_NAME);
      fflush (stderr);
 
       this->ports.run_mappers ();
       this->ports.run_mappers ();
#endif
#endif


       fprintf (stderr, "%s: Updating myself until %f.
       this->log.info ("Updating myself.");
", CMI_COMPONENT_NAME, t);
      fflush (stderr);
       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).
      //this->print_q.print_all (time_interval);
#if CMI_TURN_OFF_PORTS
#if CMI_TURN_OFF_PORTS
       fprintf (stderr, "%s: Forgetting ports for now.
       this->log.warning ("Forgetting ports for now.");
", CMI_COMPONENT_NAME);
#else
#else
       fprintf (stderr, "%s: Updating (2) ports until %f.
       this->log.info ("Updating ports.");
", CMI_COMPONENT_NAME, now);
      fflush (stderr);
       this->ports.run_ports (now);
       this->ports.run_ports (now);
#endif
#endif


#if CMI_TURN_OFF_MAPPING
#if CMI_TURN_OFF_MAPPING
       fprintf (stderr, "%s: Not mapping values (1).
       this->log.warning ("Not mapping values.");
", CMI_COMPONENT_NAME);
#else
#else
       fprintf (stderr, "%s: Map values.
       this->log.info ("Mapping values.");
", CMI_COMPONENT_NAME);
      fflush (stderr);
       this->ports.run_mappers ();
       this->ports.run_mappers ();
#endif
#endif


       fprintf (stderr, "%s: Updating myself until %f.
       this->log.info ("Updating myself.");
", CMI_COMPONENT_NAME, time_interval);
      fflush (stderr);
      // NOTE: Child.run may accept a dt not a time.
       this->state.update_until (time_interval);
       this->state.update_until (time_interval);
     }
     }
   }
   }
  // NOTE: We may need to mask nodes below sea level.
  // this->state.MaskNodesBelowElevation (0);


   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;