//------------------------------------------------------------------------------ void EstimationStateManager::BufferObjects(ObjectArray *buffer) { #ifdef DEBUG_CLONING MessageInterface::ShowMessage("EstimationStateManager::BufferObjects(%p) " "called\n", buffer); #endif GmatBase *clone; for (UnsignedInt i = 0; i < estimationObjectClones.size(); ++i) delete estimationObjectClones[i]; estimationObjectClones.clear(); if (buffer != NULL) { for (UnsignedInt i = 0; i < buffer->size(); ++i) delete (*buffer)[i]; buffer->clear(); } for (UnsignedInt i = 0; i < objects.size(); ++i) { clone = objects[i]->Clone(); estimationObjectClones.push_back(clone); if (buffer != NULL) buffer->push_back(clone->Clone()); } }
//------------------------------------------------------------------------------ bool Target::Initialize() { GmatBase *mapObj = NULL; cloneCount = 0; if ((mapObj = FindObject(solverName)) == NULL) { wxString errorString = wxT("Target command cannot find targeter \""); errorString += solverName; errorString += wxT("\""); throw CommandException(errorString, Gmat::ERROR_); } // Clone the targeter for local use #ifdef DEBUG_TARGET_INIT MessageInterface::ShowMessage (wxT("Target::Initialize() cloning mapObj <%p>'%s'\n"), mapObj, mapObj->GetName().c_str()); MessageInterface::ShowMessage (wxT("mapObj maxIter=%d\n"), mapObj->GetIntegerParameter(mapObj->GetParameterID(wxT("MaximumIterations")))); #endif // Delete the old cloned solver if (theSolver) { #ifdef DEBUG_MEMORY MemoryTracker::Instance()->Remove (theSolver, wxT("local solver", "Target::Initialize()"), wxT("deleting local cloned solver")); #endif delete theSolver; } theSolver = (Solver *)(mapObj->Clone()); if (theSolver != NULL) ++cloneCount; #ifdef DEBUG_MEMORY MemoryTracker::Instance()->Add (theSolver, theSolver->GetName(), wxT("Target::Initialize()"), wxT("theSolver = (Solver *)(mapObj->Clone())")); #endif theSolver->TakeAction(wxT("ResetInstanceCount")); mapObj->TakeAction(wxT("ResetInstanceCount")); theSolver->TakeAction(wxT("IncrementInstanceCount")); mapObj->TakeAction(wxT("IncrementInstanceCount")); if (theSolver->GetStringParameter(wxT("ReportStyle")) == wxT("Debug")) targeterInDebugMode = true; theSolver->SetStringParameter(wxT("SolverMode"), GetStringParameter(SOLVER_SOLVE_MODE)); theSolver->SetStringParameter(wxT("ExitMode"), GetStringParameter(SOLVER_EXIT_MODE)); // Set the local copy of the targeter on each node std::vector<GmatCommand*>::iterator node; GmatCommand *current; specialState = Solver::INITIALIZING; for (node = branch.begin(); node != branch.end(); ++node) { current = *node; #ifdef DEBUG_TARGET_COMMANDS Integer nodeNum = 0; #endif while ((current != NULL) && (current != this)) { #ifdef DEBUG_TARGET_COMMANDS MessageInterface::ShowMessage( wxT(" Target Command %d: %s\n"), ++nodeNum, current->GetTypeName().c_str()); #endif if ((current->GetTypeName() == wxT("Vary")) || (current->GetTypeName() == wxT("Achieve"))) current->SetRefObject(theSolver, Gmat::SOLVER, solverName); current = current->GetNext(); } } bool retval = SolverBranchCommand::Initialize(); if (retval == true) { // Targeter specific initialization goes here: if (FindObject(solverName) == NULL) { wxString errorString = wxT("Target command cannot find targeter \""); errorString += solverName; errorString += wxT("\""); throw CommandException(errorString); } retval = theSolver->Initialize(); } targeterInFunctionInitialized = false; return retval; }
//------------------------------------------------------------------------------ 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; }
//------------------------------------------------------------------------------ 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; }