Esempio n. 1
0
//------------------------------------------------------------------------------
bool RunSimulator::Initialize()
{
   bool retval = false;

   // First set the simulator object
   if (solverName == wxT(""))
      throw CommandException(wxT("Cannot initialize RunSimulator command -- the ")
            wxT("simulator name is not specified."));

   // Clear the old clone if it was set
   if (theSimulator != NULL)
      delete theSimulator;

   GmatBase *simObj = FindObject(solverName);
   if (simObj == NULL)
      throw CommandException(wxT("Cannot initialize RunSimulator command -- the ")
            wxT("simulator named ") + solverName + wxT(" cannot be found."));

   if (!simObj->IsOfType(wxT("Simulator")))
      throw CommandException(wxT("Cannot initialize RunSimulator command -- the ")
            wxT("object named ") + solverName + wxT(" is not a simulator."));

   theSimulator = (Simulator*)(simObj->Clone());

   // Set the streams for the measurement manager
   MeasurementManager *measman = theSimulator->GetMeasurementManager();
   StringArray streamList = measman->GetStreamList();
   for (UnsignedInt ms = 0; ms < streamList.size(); ++ms)
   {
      GmatBase *obj = FindObject(streamList[ms]);
      if (obj != NULL)
      {
         if (obj->IsOfType(Gmat::DATASTREAM))
         {
            Datafile *df = (Datafile*)obj;
            measman->SetStreamObject(df);
         }
      }
      else
         throw CommandException(wxT("Did not find the object named ") +
               streamList[ms]);
   }

   // Next comes the propagator
   PropSetup *obj = theSimulator->GetPropagator();

   #ifdef DEBUG_INITIALIZATION
      MessageInterface::ShowMessage(wxT("Propagator at address %p "), obj);
      if (obj != NULL)
         MessageInterface::ShowMessage(wxT("is named %s\n"),
               obj->GetName().c_str());
      else
         MessageInterface::ShowMessage(wxT("is not yet set\n"));
   #endif

   if (obj != NULL)
   {
      if (obj->IsOfType(Gmat::PROP_SETUP))
      {
         PropSetup *ps = (PropSetup*)obj->Clone();

         // RunSimulator only manages one PropSetup.  If that changes, so
         // does this code
         if (propagators.size() > 0)
         {
            for (std::vector<PropSetup*>::iterator pp = propagators.begin();
                  pp != propagators.end(); ++pp)
            {
               delete (*pp);
            }
            propagators.clear();
            p.clear();
            fm.clear();
         }
         propagators.push_back(ps);
         p.push_back(ps->GetPropagator());
         fm.push_back(ps->GetODEModel());
         retval = true;
      }
   }
   else
      throw CommandException(wxT("Cannot initialize RunSimulator command; the ")
            wxT("propagator pointer in the Simulator ") +
            theSimulator->GetName() + wxT(" is NULL."));

   // Now set the participant list
   MeasurementManager *mm = theSimulator->GetMeasurementManager();
   StringArray participants = mm->GetParticipantList();

   #ifdef DEBUG_INITIALIZATION
      MessageInterface::ShowMessage(wxT("RunSimulator command found %d ")
            wxT("participants\n"), participants.size());
   #endif

   propObjectNames.clear();
   propObjectNames.push_back(participants);

   // Now we can initialize the propagation subsystem by calling up the
   // inheritance tree.
   retval = RunSolver::Initialize();

   #ifdef DEBUG_INITIALIZATION
      if (retval == false)
         MessageInterface::ShowMessage(wxT("RunSimulator command failed to ")
               wxT("initialize; RunSolver::Initialize() call failed.\n"));
   #endif

   return retval;
}
Esempio n. 2
0
//------------------------------------------------------------------------------
bool RunSimulator::Initialize()
{
   bool retval = false;

   // First set the simulator object
   if (solverName == "")
      throw CommandException("Cannot initialize RunSimulator command -- the "
            "simulator name is not specified.");

   // Clear the old clone if it was set
   if (theSimulator != NULL)
      delete theSimulator;

   GmatBase *simObj = FindObject(solverName);
   if (simObj == NULL)
      throw CommandException("Cannot initialize RunSimulator command -- the "
            "simulator named " + solverName + " cannot be found.");

   if (!simObj->IsOfType("Simulator"))
      throw CommandException("Cannot initialize RunSimulator command -- the "
            "object named " + solverName + " is not a simulator.");

   theSimulator = (Simulator*)(simObj->Clone());

   // Set the streams for the measurement manager
   MeasurementManager *measman = theSimulator->GetMeasurementManager();
   StringArray streamList = measman->GetStreamList();
   for (UnsignedInt ms = 0; ms < streamList.size(); ++ms)
   {
      GmatBase *obj = FindObject(streamList[ms]);
      if (obj != NULL)
      {
         if (obj->IsOfType(Gmat::DATASTREAM))
         {
            DataFile *df = (DataFile*)obj;
            measman->SetStreamObject(df);
         }
      }
      else
         throw CommandException("Did not find the object named " +
               streamList[ms]);
   }

   // Find the event manager and store its pointer
   if (triggerManagers == NULL)
      throw CommandException("The Event Manager pointer was not set on the "
            "RunSimulator command");

   for (UnsignedInt i = 0; i < triggerManagers->size(); ++i)
   {
      #ifdef DEBUG_INITIALIZATION
         MessageInterface::ShowMessage("RunSimulator has an TriggerManager of "
               "type %s, id %d\n",
               (*triggerManagers)[i]->GetTriggerTypeString().c_str(),
               (*triggerManagers)[i]->GetTriggerType());
      #endif
      if ((*triggerManagers)[i]->GetTriggerType() == Gmat::EVENT)
      {
         eventMan = (EventManager*)(*triggerManagers)[i];
         #ifdef DEBUG_INITIALIZATION
            MessageInterface::ShowMessage("RunSimulator has an EventManager of "
                  "type %s\n", eventMan->GetTriggerTypeString().c_str());
         #endif
      }
   }
   if (eventMan == NULL)
      throw CommandException("The EventManager pointer was not set on the "
            "RunSimulator command");

   // Next comes the propagator
   PropSetup *obj = theSimulator->GetPropagator();

   #ifdef DEBUG_INITIALIZATION
      MessageInterface::ShowMessage("Propagator at address %p ", obj);
      if (obj != NULL)
         MessageInterface::ShowMessage("is named %s\n",
               obj->GetName().c_str());
      else
         MessageInterface::ShowMessage("is not yet set\n");
   #endif

   if (obj != NULL)
   {
      if (obj->IsOfType(Gmat::PROP_SETUP))
      {
         PropSetup *ps = (PropSetup*)obj->Clone();

         // RunSimulator only manages one PropSetup.  If that changes, so
         // does this code
         if (propagators.size() > 0)
         {
            for (std::vector<PropSetup*>::iterator pp = propagators.begin();
                  pp != propagators.end(); ++pp)
            {
               delete (*pp);
            }
            propagators.clear();
            p.clear();
            fm.clear();
         }
         propagators.push_back(ps);
         p.push_back(ps->GetPropagator());
         fm.push_back(ps->GetODEModel());
         eventMan->SetObject(ps);  // todo <-- Check this -- added 6/28

//         PropagationStateManager *psm = ps->GetPropStateManager();
//         StringArray propObjects = ps->GetStringArrayParameter("");

         retval = true;
      }
   }
   else
      throw CommandException("Cannot initialize RunSimulator command; the "
            "propagator pointer in the Simulator " +
            theSimulator->GetName() + " is NULL.");

   // Now set the participant list
   MeasurementManager *mm = theSimulator->GetMeasurementManager();
   StringArray participants = mm->GetParticipantList();

   #ifdef DEBUG_INITIALIZATION
      MessageInterface::ShowMessage("RunSimulator command found %d "
            "participants\n", participants.size());
   #endif

   propObjectNames.clear();
   propObjectNames.push_back(participants);

   // Now we can initialize the propagation subsystem by calling up the
   // inheritance tree.
   if (retval)
      retval = RunSolver::Initialize();

   #ifdef DEBUG_INITIALIZATION
      if (retval == false)
         MessageInterface::ShowMessage("RunSimulator command failed to "
               "initialize; RunSolver::Initialize() call failed.\n");
   #endif

   return retval;
}