コード例 #1
0
ファイル: RunSimulator.cpp プロジェクト: ddj116/gmat
//------------------------------------------------------------------------------
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;
}
コード例 #2
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;
}
コード例 #3
0
//------------------------------------------------------------------------------
int GetODEModel(GmatCommand **cmd, const char *modelName)
{
   Integer retval = -1;

   ODEModel* model = NULL;
   ode = NULL;
   pSetup = NULL;

   char extraMsg[256] = "";

//   // First see if it has been located before
//   if (odeNameTable.find(modelName) != odeNameTable.end())
//   {
//      ode = odeTable[odeNameTable[modelName]];
//      sprintf(extraMsg, "%s", ode->GetName().c_str());
//      return odeNameTable[modelName];
//   }
//   else if ((odeTable.size() > 0) && (strcmp(modelName, "") == 0))
//   {
//      // If no name specified, return first one in table if there is an entry
//      ode = odeTable.begin()->second;
//      sprintf(extraMsg, "%s", ode->GetName().c_str());
//      return 0;
//   }

   if (strcmp(modelName, "") == 0)
   {
      PropSetup *prop = GetFirstPropagator(*cmd);
      if (prop != NULL)
      {
         model = prop->GetODEModel();
         lastMsg = "In GetODEModel; found prop";
         if (model != NULL)
         {
            #ifdef DEBUG_ODE_SEARCH
               lastMsg += ", model != NULL\n";
               lastMsg += ::extraMsg;
            #else
               lastMsg += " ";
            #endif
            lastMsg += model->GetName();
            lastMsg += "\n";
            pSetup = prop;
            ode = model;

            if (ode != NULL)
            {
               sprintf(extraMsg, "%s", ode->GetName().c_str());
               odeNameTable[ode->GetName()] = nextOdeIndex++;
               odeTable[odeNameTable[ode->GetName()]] = model;
               setupTable[odeNameTable[ode->GetName()]] = pSetup;
               retval = 0;
            }
         }
         else
            lastMsg += ", model == NULL\n";
      }
      else
      {
         lastMsg = "In GetODEModel; did not find prop\n";
         lastMsg += ::extraMsg;
      }
   }
   else // Find a named ODEModel
   {
      while ((*cmd) != NULL)
      {
         #ifdef DEBUG_INTERFACE_FROM_MATLAB
            fprintf(fp, "Command: '%s', <%p>\n",
                  (*cmd)->GetGeneratingString(Gmat::NO_COMMENTS).c_str(), (*cmd));
         #endif
         PropSetup *setup = GetPropagator(cmd);
         #ifdef DEBUG_INTERFACE_FROM_MATLAB
            fprintf(fp, "   setup <%p>: %s\n", setup,
                  (setup != NULL ? setup->GetName().c_str() : "<undefined>"));
         #endif
         if (setup != NULL)
         {
            model = setup->GetODEModel();
            #ifdef DEBUG_INTERFACE_FROM_MATLAB
               fprintf(fp, "   model <%p>: %s\n", model,
                     (model != NULL ? model->GetName().c_str() : "<undefined>"));
            #endif
            if (model != NULL)
            {
               if (strcmp(modelName, model->GetName().c_str()) == 0)
               {
                  ode = model;
                  retval = nextOdeIndex++;
                  odeNameTable[modelName] = retval;
                  odeTable[retval] = model;
                  setupTable[retval] = setup;
                  pSetup = setup;
                  break;
               }
            }
         }
         #ifdef DEBUG_INTERFACE_FROM_MATLAB
            fprintf(fp, "On return, cmd is <%p>\n", (*cmd));
         #endif
      }
   }

   if (ode != NULL)
   {
      lastMsg = "ODE model is set to ";
      lastMsg += ode->GetName();
   }
   else
   {
      if (strcmp(modelName, "") == 0)
         lastMsg += "No ODE model found\n";
      else
      {
         std::string notFoundName = modelName;
         lastMsg += "The ODE model named \"" + notFoundName + "\" was not found\n";
      }
   }

   return retval;
}