Пример #1
0
//------------------------------------------------------------------------------
// void DecrementMass()
//------------------------------------------------------------------------------
void ImpulsiveBurn::DecrementMass()
{
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      (wxT("ImpulsiveBurn::DecrementMass() <%p>'%s' entered. There are %d tank(s)\n"),
       this, instanceName.c_str(), tankMap.size());
   #endif
   totalTankMass = spacecraft->GetRealParameter(wxT("TotalMass"));
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      (wxT("   Now decrementing mass\n      before maneuver totalTankMass = %f\n"),
       totalTankMass);
   #endif
   
   Real dv = sqrt( deltaV[0]*deltaV[0] + deltaV[1]*deltaV[1] + deltaV[2]*deltaV[2]);
   deltaTankMass = totalTankMass * (exp(-dv * 1000/(isp * gravityAccel)) - 1.0);
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      (wxT("       after maneuver deltaTankMass = %f\n"), deltaTankMass);
   #endif
   
   totalTankMass = totalTankMass + deltaTankMass;
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      (wxT("       after maneuver totalTankMass = %f\n"), totalTankMass);
   #endif

   // Update tank mass
   if (!tankMap.empty())
   {
      for (ObjectMap::iterator tankPos = tankMap.begin();
           tankPos != tankMap.end(); ++tankPos)
      {
         GmatBase *currTank = tankPos->second;

         #ifdef DEBUG_IMPBURN_DECMASS
         MessageInterface::ShowMessage
            (wxT("       Decrementing tank mass for <%p>'%s'\n"), currTank,
             (tankPos->first).c_str());
         #endif
         Integer paramID = currTank->GetParameterID(wxT("FuelMass"));
         Real oldTankMass = currTank->GetRealParameter(paramID);
         Real currTankMass = oldTankMass + deltaTankMass;
         #ifdef DEBUG_IMPBURN_DECMASS
         MessageInterface::ShowMessage
            (wxT("       it was %f, it is now %f\n"), oldTankMass, currTankMass);
         #endif
         //@todo What should we do if decremented tank mass is below zero?
         currTank->SetRealParameter(paramID, currTankMass);
      }
   }
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      (wxT("ImpulsiveBurn::DecrementMass() <%p>'%s' returning\n"), this, GetName().c_str());
   #endif
}
Пример #2
0
//------------------------------------------------------------------------------
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;
}
Пример #3
0
//------------------------------------------------------------------------------
// void DecrementMass()
//------------------------------------------------------------------------------
void ImpulsiveBurn::DecrementMass(bool backwards)
{
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      ("ImpulsiveBurn::DecrementMass() <%p>'%s' entered. There are %d tank(s)\n",
       this, instanceName.c_str(), tankMap.size());
   #endif
   totalTankMass = spacecraft->GetRealParameter("TotalMass");
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      ("   Now decrementing mass\n      before maneuver totalTankMass = %f\n",
       totalTankMass);
   #endif
   
   Real dv = sqrt( deltaV[0]*deltaV[0] + deltaV[1]*deltaV[1] + deltaV[2]*deltaV[2]);
   if (!backwards)
      deltaTankMass = totalTankMass * (exp(-dv * 1000/(isp * gravityAccel)) - 1.0);
   else
      deltaTankMass = totalTankMass * (exp(dv * 1000/(isp * gravityAccel)) - 1.0);
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      ("       after maneuver deltaTankMass = %f\n", deltaTankMass);
   #endif
   
   totalTankMass = totalTankMass + deltaTankMass;
   
   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      ("       after maneuver totalTankMass = %f\n", totalTankMass);
   #endif

   // Update tank mass
   if (!tankMap.empty())
   {
      if (tankMap.size() > 1)
         throw BurnException("The ImpulsiveBorn object " + instanceName +
               " is configured to draw mass from multiple tanks, but only one "
               "tank is supported in the current implementation.");

      // This code is set up to draw from multiple tanks, but the amount drawn
      // is not calculated to draw proportionally.  Instead, it reduces each
      // tank by deltaTankMass.  We need to check this code before enabling
      // mass reduction from multiple tanks in a single impulsive burn.
      for (ObjectMap::iterator tankPos = tankMap.begin();
           tankPos != tankMap.end(); ++tankPos)
      {
         GmatBase *currTank = tankPos->second;

         #ifdef DEBUG_IMPBURN_DECMASS
         MessageInterface::ShowMessage
            ("       Decrementing tank mass for <%p>'%s'\n", currTank,
             (tankPos->first).c_str());
         #endif
         Integer paramID = currTank->GetParameterID("FuelMass");
         Real oldTankMass = currTank->GetRealParameter(paramID);
         Real currTankMass = oldTankMass + deltaTankMass;
         #ifdef DEBUG_IMPBURN_DECMASS
         MessageInterface::ShowMessage
            ("       it was %f, it is now %f\n", oldTankMass, currTankMass);
         #endif
         //@todo What should we do if decremented tank mass is below zero?
         currTank->SetRealParameter(paramID, currTankMass);
      }
   }
   else
      throw BurnException("Impulsive Burn " + instanceName +
            " is set to decrement mass from a tank named "  + tankNames[0] +
            ", but the Spacecraft " + spacecraft->GetName() +
            " does not have the selected fuel tank.");

   #ifdef DEBUG_IMPBURN_DECMASS
   MessageInterface::ShowMessage
      ("ImpulsiveBurn::DecrementMass() <%p>'%s' returning\n", this, GetName().c_str());
   #endif
}
Пример #4
0
//------------------------------------------------------------------------------
// void LoadData()
//------------------------------------------------------------------------------
void VaryPanel::LoadData()
{
   #ifdef DEBUG_VARYPANEL_LOAD
   MessageInterface::ShowMessage("VaryPanel::LoadData() entered\n");
   MessageInterface::ShowMessage
      ("   Command=<%p>'%s'\n", mVaryCommand, mVaryCommand ?
       mVaryCommand->GetTypeName().c_str() : "NULL");
   #endif
   
   mVarNameTextCtrl->Disable(); // we don't want user to edit this box
   mViewVarButton->Enable();
   
   if (mVaryCommand == NULL)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, "The Vary command is NULL\n");
      return;
   }
   
   try
   {
      // Set the pointer for the "Show Script" button
      mObject = mVaryCommand;
      
      solverName =
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("SolverName"));
      
      #ifdef DEBUG_VARYPANEL_LOAD
      MessageInterface::ShowMessage("   solverName=%s\n", solverName.c_str());
      #endif
      
      variableName =
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("Variable"));
      
      #ifdef DEBUG_VARYPANEL_LOAD
      MessageInterface::ShowMessage("   variableName=%s\n", variableName.c_str());
      #endif
      
      wxString initValStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("InitialValue")).c_str();
      wxString pertStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("Perturbation")).c_str();
      wxString lowerStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("Lower")).c_str();
      wxString upperStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("Upper")).c_str();      
      wxString maxStepStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("MaxStep")).c_str();
      wxString addSfStr = 
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("AdditiveScaleFactor")).c_str();
      wxString multCfStr =
         mVaryCommand->GetStringParameter(mVaryCommand->GetParameterID("MultiplicativeScaleFactor")).c_str();
      
      mSolverComboBox->SetStringSelection(solverName.c_str());
      mVarNameTextCtrl->SetValue(variableName.c_str());
      
      mInitialTextCtrl->SetValue(initValStr);
      mPertTextCtrl->SetValue(pertStr);
      mLowerValueTextCtrl->SetValue(lowerStr);
      mUpperValueTextCtrl->SetValue(upperStr);
      mMaxStepTextCtrl->SetValue(maxStepStr);
      mAdditiveTextCtrl->SetValue(addSfStr);
      mMultiplicativeTextCtrl->SetValue(multCfStr);
      
      //  Enalbe or disable fields depends on the solver type
      GmatBase *solver = theGuiInterpreter->GetConfiguredObject(solverName);
      if (solver != NULL)
      {
//         mVaryCommand->SetRefObject(solver, Gmat::SOLVER, solverName);
         solver->SetStringParameter
            (solver->GetParameterID("Variables"), variableName);
         SetControlEnabling(solver);
      }
   }
   catch (BaseException &e)
   {
      MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage());
   }
   
   #ifdef DEBUG_VARYPANEL_LOAD
   MessageInterface::ShowMessage("VaryPanel::LoadData() leaving\n");
   #endif
}