Exemplo n.º 1
0
//------------------------------------------------------------------------------
bool PropagationStateManager::SetProperty(std::string propName,
      GmatBase *forObject)
{
   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage("Entered SetProperty(%s, %s)\n",
            propName.c_str(), forObject->GetName().c_str());
   #endif

   if (find(objects.begin(), objects.end(), forObject) == objects.end())
      throw PropagatorException("Prop object " + forObject->GetName() +
            " not found in a propagation state manager\n");

   if (forObject)
   {
      // Validate that the property can be propagated
      if (forObject->SetPropItem(propName) == Gmat::UNKNOWN_STATE)
         throw PropagatorException(propName
               + " is not a known propagation parameter on "
               + forObject->GetName());
      if (find(elements[forObject]->begin(), elements[forObject]->end(),
            propName) == elements[forObject]->end())
         elements[forObject]->push_back(propName);

      #ifdef DEBUG_STATE_CONSTRUCTION
         MessageInterface::ShowMessage("Current property List:\n");
            for (StringArray::iterator i = elements[forObject]->begin();
                  i != elements[forObject]->end(); ++i)
               MessageInterface::ShowMessage("   %s\n", i->c_str());
      #endif

      return true;
   }

   return false;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
bool PropagationStateManager::SetProperty(std::string propName)
{
   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage("Entered SetProperty(%s); current = %ld\n",
            propName.c_str(), current);
   #endif
   if (current) 
   {
      // Validate that the property can be propagated
      if (current->SetPropItem(propName) == Gmat::UNKNOWN_STATE)
         throw PropagatorException(propName 
               + " is not a known propagation parameter on " 
               + current->GetName());
      
      // Only add it if it is not yet there
      if (find(elements[current]->begin(), elements[current]->end(),
            propName) == elements[current]->end())
         elements[current]->push_back(propName);

      #ifdef DEBUG_STATE_CONSTRUCTION
         MessageInterface::ShowMessage("Current property List:\n");
            for (StringArray::iterator i = elements[current]->begin(); 
                  i != elements[current]->end(); ++i)
               MessageInterface::ShowMessage("   %s\n", i->c_str());
      #endif
            
      return true;
   }
   
   return false;   
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
bool Propagator::Initialize()
{
   if (UsesODEModel())
   {
      if (physicalModel != NULL)
      {
         #ifdef DEBUG_INITIALIZATION
            MessageInterface::ShowMessage(wxT("Propagator::Initialize() calling ")
                  wxT("physicalModel->Initialize() \n"));
         #endif

         if ( physicalModel->Initialize() )
            initialized = true;

         #ifdef DEBUG_INITIALIZATION
            MessageInterface::ShowMessage(
               wxT("Propagator::Initialize() initialized = %d\n"), initialized);
         #endif

         inState  = physicalModel->GetState();
         outState = physicalModel->GetState();

         if ((resetInitialData) || (alwaysUpdateStepsize))
         {
            stepSize = stepSizeBuffer;
            resetInitialData = false;
         }
      }
      else
         throw PropagatorException(wxT("Propagator::Initialize -- Force model is ")
               wxT("not defined"));
   }
   else
      initialized = true;

    
    if (!initialized)
       throw PropagatorException(wxT("Propagator failed to initialize"));

    return true;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
bool PropagationStateManager::SetProperty(std::string propName, Integer index)
{
   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage("Entered SetProperty(%s, %d)\n",
            propName.c_str(), index);
   #endif

   if ((index < 0) || (index >= (Integer)objects.size()))
      throw PropagatorException("Index out of bounds specifying a prop object "
            "in a propagation state manager\n");

   GmatBase *obj = objects[index];

   if (obj)
   {
      // Validate that the property can be propagated
      if (obj->SetPropItem(propName) == Gmat::UNKNOWN_STATE)
         throw PropagatorException(propName
               + " is not a known propagation parameter on "
               + obj->GetName());
      if (find(elements[obj]->begin(), elements[obj]->end(), propName) ==
            elements[obj]->end())
         elements[obj]->push_back(propName);

      #ifdef DEBUG_STATE_CONSTRUCTION
         MessageInterface::ShowMessage("Current property List:\n");
            for (StringArray::iterator i = elements[obj]->begin();
                  i != elements[obj]->end(); ++i)
               MessageInterface::ShowMessage("   %s\n", i->c_str());
      #endif

      return true;
   }

   return false;
}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
Real Propagator::SetRealParameter(const Integer id, const Real value)
{
   if (id == INITIAL_STEP_SIZE)
   {
      if (GmatMathUtil::IsEqual(value, 0.0, STEP_SIZE_TOLERANCE))
      {
         wxString ss;
         ss << wxT("Initial Step Size must not be zero (tolerance = ") << STEP_SIZE_TOLERANCE << wxT(" seconds).");
         throw PropagatorException(ss);
      }
      stepSizeBuffer = value;
      return stepSizeBuffer;
   }
   return GmatBase::SetRealParameter(id, value);
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
bool BulirschStoer::AdaptStep(Real maxerror)
{
    Real factor = 1.0, errkm;

    if (maxerror > tolerance)
    {
       if (GmatMathUtil::Abs(stepSize) == minimumStep)
       {
          if (stopIfAccuracyViolated)
          {
             throw PropagatorException(
                   "BulirschStoer: Accuracy settings will be violated with current step size values.\n");
          }
          else
          {
             if (!accuracyWarningTriggered) // so only write the warning once per propagation command
             {
                accuracyWarningTriggered = true;
                MessageInterface::PopupMessage(Gmat::WARNING_,
                   "BulirschStoer: Accuracy settings will be violated with current step size values.\n");
             }
             return false;
          }
       }
        // Step is too large: reduce it 
        errkm = pow(maxerror/(bs_safety1 * tolerance), 1.0 / (2*kused+1));

        if ((kused == kmax) || (kused == kopt+1)) 
            factor = bs_safety2 / errkm;
        else if ((kused == kopt) && (alpha[kopt-1][kopt] < errkm))
            factor = 1.0 / errkm;
        else if ((kopt == kmax) && (alpha[kused][kmax-1] < errkm))
            factor = alpha[kused][kmax-1] * bs_safety2 / errkm;
        else if (alpha[kused][kopt-1] < errkm)
            factor = alpha[kused][kopt-1] / errkm;

        factor = (factor > minimumReduction ? minimumReduction : factor);
        factor = (factor < maximumReduction ? maximumReduction : factor);

        stepSize *= factor;
        ++stepAttempts;
    }
    else
    {
        // The step succeeded; step or depth can be increased
        first = false;
        stepTaken = stepSize;
        Real workingMin = 1.0e35, work, scale = 1.0, errorRatio;
        for (Integer i = 0; i <= kused; i++)
        {
            errorRatio = levelError[i] / tolerance;
            factor = (errorRatio > scale_dt ? errorRatio : scale_dt);
            work = factor * ai[i+2];
            if (work < workingMin)
            {
                scale = factor;
                workingMin = work;
                kopt = (i+1 > kmax ? kmax : i+1);
            }
        }

        // Set stepSize to new value
        stepSize /= scale;

        if ((kopt >= kused) && (kopt < kmax))
        {
            work = scale / alpha[kopt-1][kopt];
            factor = (scale < scale_dt ? scale : scale_dt);
            if (ai[kopt+1] * factor < workingMin)
            {
                ++kopt;
                stepSize = stepTaken / factor;
            }
        }

        // Adapt to the range constraints on the step
        Real sign = (stepSize >= 0.0 ? 1.0 : -1.0);
        stepSize = (fabs(stepSize) > minimumStep ? stepSize : minimumStep*sign);
        stepSize = (fabs(stepSize) < maximumStep ? stepSize : maximumStep*sign);

        // Handle the fixed step mode case
        if (fixedStep) 
            stepSize = (fabs(stepSize) < fabs(fixedStepsize) ? 
                        stepSize : fixedStepsize);

        stepAttempts = 0;
    }

    return true;
}
Exemplo n.º 7
0
//------------------------------------------------------------------------------
Integer PropagationStateManager::SortVector()
{
   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage(
            "Entered PropagationStateManager::SortVector()\n");
   #endif

   StringArray *propList;
   std::vector<Integer> order;
   std::vector<Gmat::StateElementId> idList;
   ObjectArray owners;
   StringArray property;
   std::vector<Integer>::iterator oLoc;

   Gmat::StateElementId id;
   Integer size, loc = 0, val;
   stateSize = 0;
   // Initially assume there is no post superposition member
   hasPostSuperpositionMember = false;


   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage("Element list:\n");
      Integer k = 0;
      for (std::map<GmatBase*, StringArray*>::iterator i = elements.begin();
            i != elements.end(); ++i)
      {
         current  = i->first;
         propList = i->second;
         MessageInterface::ShowMessage("   %d: %s ->\n", ++k,
               current->GetName().c_str());
         for (UnsignedInt j = 0; j < propList->size(); ++j)
         {
            MessageInterface::ShowMessage("      %s\n", (*propList)[j].c_str());
         }
      }
   #endif

   // First build a list of the property IDs and objects, measuring state size 
   // at the same time
   for (UnsignedInt q = 0; q < objects.size(); ++q)
   {
      current  = objects[q];
      propList = elements[current];
      
      for (StringArray::iterator j = propList->begin(); 
            j != propList->end(); ++j)
      {
         id = (Gmat::StateElementId)current->SetPropItem(*j);
         if (id == Gmat::UNKNOWN_STATE)
            throw PropagatorException("Unknown state element: " + (*j) +
                  " on object " + current->GetName() + ", a " +
                  current->GetTypeName());
         size = current->GetPropItemSize(id);
         if (size <= 0)
            throw PropagatorException("State element " + (*j) +
                  " has size set less than or equal to 0; unable to continue.");
         stateSize += size;
         for (Integer k = 0; k < size; ++k)
         {
            idList.push_back(id);
            if (current->PropItemNeedsFinalUpdate(id))
               hasPostSuperpositionMember = true;
            owners.push_back(current);
            property.push_back(*j);

            // Put this item in the ordering list
            oLoc = order.begin();
            while (oLoc != order.end())
            {
               val = idList[*oLoc];
               if (id < val)
               {
                  #ifdef DEBUG_STATE_CONSTRUCTION
                     MessageInterface::ShowMessage("Inserting; id = %d, z = %d,"
                           "  loc = %d\n", id, (*oLoc), loc);
                  #endif
                     
                  order.insert(oLoc, loc);
                  break;
               }
               ++oLoc;
            }
            if (oLoc == order.end())
               order.push_back(loc);
            
            ++loc;
         }
      }
   }
   
   ListItem *newItem;
   val = 0;
   completionIndexList.clear();
   completionSizeList.clear();

   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage(
            "State size is %d()\n", stateSize);
   #endif
   
   for (Integer i = 0; i < stateSize; ++i)
   {
      #ifdef DEBUG_STATE_CONSTRUCTION
         MessageInterface::ShowMessage("%d <- %d: %d %s.%s gives ", i, order[i], 
               idList[order[i]], owners[order[i]]->GetName().c_str(), 
               property[order[i]].c_str());
      #endif

      newItem = new ListItem;
      newItem->objectName  = owners[order[i]]->GetName();
      newItem->elementName = property[order[i]];
      if (owners[order[i]]->HasAssociatedStateObjects())
         newItem->associateName = owners[order[i]]->GetAssociateName(val);
      else
         newItem->associateName = owners[order[i]]->GetName();
      newItem->object      = owners[order[i]];
      newItem->elementID   = idList[order[i]];
      newItem->subelement  = ++val;
      newItem->parameterID = 
            owners[order[i]]->GetParameterID(property[order[i]]);
      newItem->parameterType = 
            owners[order[i]]->GetParameterType(newItem->parameterID);
      
      newItem->dynamicObjectProperty =
            newItem->object->ParameterAffectsDynamics(newItem->parameterID);

      if (newItem->parameterType == Gmat::REAL_TYPE)
         newItem->parameterID += val - 1;

      #ifdef DEBUG_STATE_CONSTRUCTION
         MessageInterface::ShowMessage("[%s, %s, %s, %d, %d, %d, %d, %s]\n",
               newItem->objectName.c_str(),
               newItem->elementName.c_str(),
               newItem->associateName.c_str(),
               newItem->elementID,
               newItem->subelement,
               newItem->parameterID,
               newItem->parameterType,
               (newItem->dynamicObjectProperty ? "dynamic" : "static"));
      #endif

      if (newItem->parameterType == Gmat::RVECTOR_TYPE)
      {
         const Rvector vec =
            owners[order[i]]->GetRvectorParameter(property[order[i]]);
         newItem->rowLength = vec.GetSize();
         newItem->rowIndex = val - 1;
      }

      if (newItem->parameterType == Gmat::RMATRIX_TYPE)
      {
         const Rmatrix mat = 
            owners[order[i]]->GetRmatrixParameter(property[order[i]]);
         newItem->rowLength = mat.GetNumColumns();
         newItem->colIndex = (val-1) % newItem->rowLength;
         newItem->rowIndex = (Integer)((val - 1) / newItem->rowLength);
         
         #ifdef DEBUG_STATE_CONSTRUCTION
            MessageInterface::ShowMessage(
                  "RowLen = %d, %d -> row %2d  col %2d\n", newItem->rowLength, 
                  val, newItem->rowIndex, newItem->colIndex); 
         #endif
      }
      
      newItem->nonzeroInit = owners[order[i]]->
            ParameterDvInitializesNonzero(newItem->parameterID,
                  newItem->rowIndex, newItem->colIndex);
      if (newItem->nonzeroInit)
      {
         newItem->initialValue = owners[order[i]]->
                ParameterDvInitialValue(newItem->parameterID,
                      newItem->rowIndex, newItem->colIndex);
      }
      if (newItem->object->PropItemNeedsFinalUpdate(newItem->elementID))
      {
         completionIndexList.push_back(newItem->elementID);
         completionSizeList.push_back(1);       // Or count sizes?
//         newItem->nonzeroInit = true;
//         newItem->initialValue = 1.0;
      }

      newItem->postDerivativeUpdate = owners[order[i]]->
            ParameterUpdatesAfterSuperposition(newItem->parameterID);


      newItem->length      = owners[order[i]]->GetPropItemSize(idList[order[i]]);
      
      if (val == newItem->length)
         val = 0;
      
      stateMap.push_back(newItem);
   }

   #ifdef DEBUG_STATE_CONSTRUCTION
      MessageInterface::ShowMessage("State map contents:\n");
      for (std::vector<ListItem*>::iterator i = stateMap.begin(); 
            i != stateMap.end(); ++i)
         MessageInterface::ShowMessage("   %s %s %d %d of %d, id = %d\n", 
               (*i)->objectName.c_str(), (*i)->elementName.c_str(),
               (*i)->elementID, (*i)->subelement, (*i)->length, 
               (*i)->parameterID); 
      MessageInterface::ShowMessage(
            "Finished PropagationStateManager::SortVector()\n");
   #endif
   
   return stateSize;
}
Exemplo n.º 8
0
//------------------------------------------------------------------------------
bool PropagationStateManager::MapObjectsToVector()
{
   #ifdef DEBUG_OBJECT_UPDATES
      MessageInterface::ShowMessage("Mapping objects to vector\n");

      // Look at state data before
      MessageInterface::ShowMessage("O -> V: Real object data before: [");
      for (Integer index = 0; index < stateSize; ++index)
         if (stateMap[index]->parameterType ==  Gmat::REAL_TYPE)
            MessageInterface::ShowMessage(" %lf ",
                  (stateMap[index]->object)->GetRealParameter(
                        stateMap[index]->parameterID));
      MessageInterface::ShowMessage("]\n");
   #endif

   Real value;

   for (Integer index = 0; index < stateSize; ++index)
   {
      switch (stateMap[index]->parameterType)
      {
         case Gmat::REAL_TYPE:
            value = stateMap[index]->object->GetRealParameter(
                          stateMap[index]->parameterID);

            if (GmatMathUtil::IsNaN(value))
               throw PropagatorException("Value for parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is not a number");

            if (GmatMathUtil::IsInf(value))
               throw PropagatorException("Value for parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is infinite");

            state[index] = value;
            break;
            
         case Gmat::RVECTOR_TYPE:
            value = stateMap[index]->object->GetRealParameter(
                  stateMap[index]->parameterID, stateMap[index]->rowIndex);

            if (GmatMathUtil::IsNaN(value))
               throw PropagatorException("Value for array parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is not a number");

            if (GmatMathUtil::IsInf(value))
               throw PropagatorException("Value for array parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is infinite");

            state[index] = value;
            break;

         case Gmat::RMATRIX_TYPE:
            value = stateMap[index]->object->GetRealParameter(
                  stateMap[index]->parameterID, stateMap[index]->rowIndex,
                  stateMap[index]->colIndex);

            if (GmatMathUtil::IsNaN(value))
               throw PropagatorException("Value for array parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is not a number");

            if (GmatMathUtil::IsInf(value))
               throw PropagatorException("Value for array parameter " +
                     stateMap[index]->object->GetParameterText(
                     stateMap[index]->parameterID) + " on object " +
                     stateMap[index]->object->GetName() +
                     " is infinite");

            state[index] = value;
            break;

         default:
            std::stringstream sel("");
            sel << stateMap[index]->subelement;
            std::string label = stateMap[index]->objectName + "." + 
                  stateMap[index]->elementName + "." + sel.str();
            MessageInterface::ShowMessage(
                  "%s not set; Element type not handled\n",label.c_str());
      }
   }
   
   // Manage epoch
   if (ObjectEpochsMatch() == false)
      MessageInterface::ShowMessage("Epochs do not match\n");

   if (objects.size() > 0)
      state.SetEpoch(objects[0]->GetRealParameter(epochIDs[0]));
   
   #ifdef DEBUG_OBJECT_UPDATES
      MessageInterface::ShowMessage(
            "After mapping %d objects to vector, contents are\n"
            "   Epoch = %.12lf\n", objects.size(), state.GetEpoch());
      for (Integer index = 0; index < stateSize; ++index)
      {
         std::stringstream msg("");
         msg << stateMap[index]->subelement;
         std::string lbl = stateMap[index]->objectName + "." + 
            stateMap[index]->elementName + "." + msg.str() + " = ";
         MessageInterface::ShowMessage("   %d: %s%.12lf\n", index, lbl.c_str(), 
               state[index]);
      }

      // Look at state data after
      MessageInterface::ShowMessage("Real object data after: [");
      for (Integer index = 0; index < stateSize; ++index)
         if (stateMap[index]->parameterType ==  Gmat::REAL_TYPE)
            MessageInterface::ShowMessage(" %lf ",
                  (stateMap[index]->object)->GetRealParameter(
                        stateMap[index]->parameterID));
      MessageInterface::ShowMessage("]\n");
   #endif

   return true;
}
Exemplo n.º 9
0
//------------------------------------------------------------------------------
bool PredictorCorrector::AdaptStep(Real maxError)
{
   Real newStep = stepSize * pow(targetError / maxError, invOrder);

   // The following code is in place to omit error control for steps
   // at the minimum stepsize.  See the note above for more
   // information.  Remove this block if the issue gets resolved.
   if (GmatMathUtil::Abs(stepSize) == minimumStep)
   {
      if (stopIfAccuracyViolated)
      {
         throw PropagatorException(typeSource + ": Accuracy settings will be "
               "violated with current step size values.\n");
      }
      else
      {
         if (!accuracyWarningTriggered)
         {
            accuracyWarningTriggered = true;
            MessageInterface::ShowMessage("**** Warning **** %s: Accuracy "
                  "settings will be violated with current step size values.\n",
                  typeSource.c_str());
         }
         return true;
      }
   }

   // Make sure new step is in the accepted range
   if (fabs(newStep) < minimumStep)
      newStep = minimumStep * stepSign;
   if (fabs(newStep) > maximumStep)
      newStep = maximumStep * stepSign;

   if (!fixedStep)
   {
      // Variable step mode
      if (maxError > tolerance)
      {
         // Tried and failed at the minimum stepsize
         if (GmatMathUtil::IsEqual(GmatMathUtil::Abs(stepSize),minimumStep))
         {
            if (stopIfAccuracyViolated)
            {
               throw PropagatorException(
                     "PredictorCorrector: Accuracy settings will be violated "
                     "with current step size values.\n");
            }
            else
            {
               // Only write the warning once per propagation command
               if (!accuracyWarningTriggered)
               {
                  accuracyWarningTriggered = true;
                  MessageInterface::PopupMessage(Gmat::WARNING_,
                     "PredictorCorrector: Accuracy settings will be violated "
                     "with current step size values.\n");
               }
               return false;
            }
         }
         stepSize = newStep;
         ++stepAttempts;
      }
      else
      {
         // Step can be "safely" increased -- but only up to twice old value
         if (newStep >= 2.0 * stepSize)
            stepSize *= 2.0;
         else
            stepSize = newStep;

         stepAttempts = 0;
      }
   }
   else
   {
      // Fixed step mode: Adjust newStep to be a power of 2 different from
      // the current step
      Real twoStep = stepSize;
      if (fabs(newStep) < fabs(stepSize))
      {
         do
         {
            twoStep /= 2.0;
         } while (fabs(twoStep) > fabs(newStep));
         stepSize = twoStep;
      }
      else if (fabs(newStep) >= fabs(2.0 * stepSize))
      {
         // Check to see if the step can safely be Reald, given the
         // remaining interval
         Real stepsToGo = timeleft / (2.0 * stepSize);
         if (stepsToGo == int(stepsToGo))
            stepSize *= 2.0;
         else
            return true;
      }
      else        // Cannot increase this stepsize in fixed step mode
         return true;
   while (fabs(stepSize) < minimumStep)
      stepSize *= 2.0;
   }

   return Reset();
}
Exemplo n.º 10
0
//------------------------------------------------------------------------------
bool PredictorCorrector::Initialize()
{
//    Propagator::Initialize();

   #ifdef DEBUG_PROPAGATION
      MessageInterface::ShowMessage("Initializing %s\n", typeName.c_str());
   #endif

   isInitialized = false;
   if (stepCount <= 0)
      return isInitialized;

   // Check the P-C error control tolerances
   if ((lowerError >= targetError) || (targetError >= tolerance))
      throw PropagatorException("Setup error in the " + typeName +
             " Propagator; Predictor-Corrector integrators require that the "
             "error control settings satisfy the relationship\n\n"
             "   LowerError < TargetError < Accuracy\n\n"
             "and work best if the settings differ from one another by at "
             "least a factor of 10", Gmat::ERROR_);

   if (physicalModel)
   {
      dimension = physicalModel->GetDimension();

      if (history)
      {
         for (int i = 0; i < stepCount; i++)
            if (history[i])
               delete [] history[i];
         delete [] history;
         history = NULL;
      }

      if (pweights)
      {
         delete [] pweights;
         pweights = NULL;
      }

      if (cweights)
      {
         delete [] cweights;
         cweights = NULL;
      }

      if (predictorState)
      {
         delete [] predictorState;
         predictorState = NULL;
      }

      if (correctorState)
      {
         delete [] correctorState;
         correctorState = NULL;
      }

      if (errorEstimates)
      {
         delete [] errorEstimates;
         errorEstimates = NULL;
      }

      predictorState = new Real[dimension];
      if (!predictorState)
      {
         return isInitialized;
      }

      correctorState = new Real[dimension];
      if (!correctorState)
      {
         delete [] predictorState;
         predictorState = NULL;
         return isInitialized;
      }

      errorEstimates = new Real[dimension];
      if (!errorEstimates)
      {
         delete [] predictorState;
         predictorState = NULL;
         delete [] correctorState;
         correctorState = NULL;
         return isInitialized;
      }

      pweights = new Real[stepCount];
      if (!pweights)
      {
         delete [] predictorState;
         predictorState = NULL;
         delete [] correctorState;
         correctorState = NULL;
         delete [] errorEstimates;
         errorEstimates = NULL;
         return isInitialized;
      }

      cweights = new Real[stepCount];
      if (!cweights)
      {
         delete [] pweights;
         pweights = NULL;
         delete [] predictorState;
         predictorState = NULL;
         delete [] correctorState;
         correctorState = NULL;
         delete [] errorEstimates;
         errorEstimates = NULL;
         return isInitialized;
      }

      history = new Real*[stepCount];
      if (history)
      {
         for (int i = 0; i < stepCount; i++)
         {
            history[i] = new Real[dimension];
            if (!history[i])
            {
               for (int j = 0; j < i; j++)
               {
                  delete [] history[j];
               }
               delete [] history;
               history = NULL;
               delete [] pweights;
               pweights = NULL;
               delete [] cweights;
               cweights = NULL;
               delete [] predictorState;
               predictorState = NULL;
               delete [] correctorState;
               correctorState = NULL;
               delete [] errorEstimates;
               errorEstimates = NULL;
               return isInitialized;
            }
            if (SetWeights())
            {
               isInitialized = true;
            }
         }
      }
      else
      {
         delete [] pweights;
         pweights = NULL;
         delete [] cweights;
         cweights = NULL;
         delete [] predictorState;
         predictorState = NULL;
         delete [] correctorState;
         correctorState = NULL;
         delete [] errorEstimates;
         errorEstimates = NULL;
      }

      // Setup the starter
      if (starter == NULL)
         starter = new RungeKutta89;

      starter->SetPhysicalModel(physicalModel);

      if (fabs(stepSizeBuffer) < minimumStep)
         stepSizeBuffer = minimumStep * stepSign;
      if (fabs(stepSizeBuffer) > maximumStep)
         stepSizeBuffer = maximumStep * stepSign;

      starter->SetRealParameter("InitialStepSize", stepSize);
      starter->SetBooleanParameter(STOP_IF_ACCURACY_VIOLATED,
               stopIfAccuracyViolated);
      starter->SetRealParameter(ACCURACY, tolerance);
      starter->SetRealParameter(MIN_STEP, minimumStep);
      starter->SetRealParameter(MAX_STEP, maximumStep);
      starter->TakeAction("ChangeTypeSourceString",
            "Starter for Predictor-Corrector");
      starter->Initialize();

      inState  = physicalModel->GetState();
      outState = physicalModel->GetState();
   }
    
   accuracyWarningTriggered = false;

   Reset();

   return isInitialized;
}