Пример #1
0
void TimeStepping::initializeNewtonLoop()
{
  DEBUG_BEGIN("TimeStepping::initializeNewtonLoop()\n");
  double tkp1 = getTkp1();
  assert(!isnan(tkp1));

  for (OSIIterator it = _allOSI->begin(); it != _allOSI->end() ; ++it)
  {
    (*it)->computeInitialNewtonState();
    (*it)->computeResidu();
  }

  // Predictive contact -- update initial contacts after updating DS positions
  updateWorldFromDS();
  updateInteractions();

  // Changes in updateInteractions may require initialization
  initializeNSDSChangelog();

  SP::InteractionsGraph indexSet0 = _nsds->topology()->indexSet0();
  if (indexSet0->size()>0)
  {
    for (OSIIterator itOSI = _allOSI->begin(); itOSI != _allOSI->end() ; ++itOSI)
    {
      (*itOSI)->updateOutput(nextTime());
      (*itOSI)->updateInput(nextTime());
    }
  }

  SP::DynamicalSystemsGraph dsGraph = _nsds->dynamicalSystems();
  for (DynamicalSystemsGraph::VIterator vi = dsGraph->begin(); vi != dsGraph->end(); ++vi)
  {
    dsGraph->bundle(*vi)->updatePlugins(tkp1);
  }

  for (OSIIterator it = _allOSI->begin(); it != _allOSI->end() ; ++it)
    (*it)->computeResidu();

  if (_computeResiduY)
  {
    for (OSIIterator itOSI = _allOSI->begin(); itOSI != _allOSI->end() ; ++itOSI)
    {
      (*itOSI)->computeResiduOutput(tkp1, indexSet0);
    }
  }
  DEBUG_END("TimeStepping::initializeNewtonLoop()\n");
}
Пример #2
0
void Simulation::processEvents()
{
  _eventsManager->processEvents(*this);

  if (_eventsManager->hasNextEvent())
  {
    // For TimeStepping Scheme, need to update IndexSets, but not for EventDriven scheme
    if (Type::value(*this) != Type::EventDriven)
    {
      updateIndexSets();
    }
  }

  /* should be evaluated only if needed */
  SP::DynamicalSystemsGraph dsGraph = _nsds->dynamicalSystems();
  for (DynamicalSystemsGraph::VIterator vi = dsGraph->begin(); vi != dsGraph->end(); ++vi)
  {
    dsGraph->bundle(*vi)->endStep();
  }

}
Пример #3
0
void Hem5OSI::fprob(integer* IFCN,
                 integer* NQ,
                 integer* NV,
                 integer* NU,
                 integer* NL,
                 integer* LDG, integer* LDF, integer* LDA,
                 integer* NBLK, integer* NMRC,
                 integer* NPGP, integer* NPFL,
                 integer* INDGR, integer* INDGC, integer * INDFLR, integer * INDFLC,
                 doublereal* time,
                 doublereal* q, doublereal* v, doublereal* u,  doublereal* xl,
                 doublereal* G, doublereal* GQ, doublereal * F,
                 doublereal* GQQ, doublereal* GT, doublereal * FL,
                 doublereal* QDOT, doublereal* UDOT, doublereal * AM)
{
  DEBUG_PRINTF("Hem5OSI::fprob(integer* IFCN,...) with IFCN = %i \n", (int)*IFCN);
  DEBUG_PRINTF("NQ = %i\t NV = %i \t NU = %i, NL = %i \n", (int)*NQ, (int)*NV, (int)*NU, (int)*NL);
  DEBUG_PRINTF("LDG = %i\t LDF = %i \t LDA = %i \n", (int)*LDG, (int)*LDF, (int)*LDA);

  // fill in xWork vector (ie all the x of the ds of this osi) with x
  fillqWork(NQ, q);
  fillvWork(NV, v);

  double t = *time;
  simulationLink->model()->setCurrentTime(t);

  SP::DynamicalSystemsGraph dsGraph = simulationLink->model()->nonSmoothDynamicalSystem()->dynamicalSystems();



  int ifcn = (int)(*IFCN);

  if ((ifcn == 1) || (ifcn >= 7)) // compute Mass AM
  {
    unsigned int pos=0;
    for (DynamicalSystemsGraph::VIterator vi = dsGraph->begin(); vi != dsGraph->end(); ++vi)
    {
      SP::DynamicalSystem ds = dsGraph->bundle(*vi);
      if (Type::value(*ds) == Type::LagrangianDS ||
          Type::value(*ds) == Type::LagrangianLinearTIDS)
      {
        LagrangianDS& lds = *std11::static_pointer_cast<LagrangianDS>(ds);
        lds.computeMass();
        for (unsigned int ii =pos ; ii < ((unsigned int)(*NV)+pos); ii ++)
        {
          for (unsigned int jj =pos ; jj < ((unsigned int)(*NV)+pos); jj ++)
          {
            AM[ii + jj*(int)(*NV)] = lds.mass()->getValue(ii,jj) ;
          }
        }
        pos += lds.getDim();
      }
      else
      {
        RuntimeException::selfThrow("Hem5OSI::fprob(), Only integration of Lagrangian DS is allowed");
      }
      DEBUG_EXPR(
        for (int kk =0 ; kk < (int)(*NV)* (int)(*NV); kk ++)
    {
      std::cout << AM[kk] << std::endl;
      }
      );
    }
Пример #4
0
void KernelTest::t6()
{
  SP::Model bouncingBall = Siconos::load("BouncingBall1.xml");

  try
  {
    double T = bouncingBall->finalT();
    double t0 = bouncingBall->t0();
    double h = bouncingBall->simulation()->timeStep();
    int N = (int)((T - t0) / h); // Number of time steps

    SP::DynamicalSystemsGraph dsg = 
      bouncingBall->nonSmoothDynamicalSystem()->topology()->dSG(0);

    SP::LagrangianDS ball = std11::static_pointer_cast<LagrangianDS>
      (dsg->bundle(*(dsg->begin())));

    SP::TimeStepping s = std11::static_pointer_cast<TimeStepping>(bouncingBall->simulation());
    SP::Interaction inter;
    InteractionsGraph::VIterator ui, uiend;
    SP::InteractionsGraph indexSet0 = bouncingBall->nonSmoothDynamicalSystem()->topology()->indexSet(0);
    for (std11::tie(ui, uiend) = indexSet0->vertices(); ui != uiend; ++ui)
      inter = indexSet0->bundle(*ui);


    // --- Get the values to be plotted ---
    // -> saved in a matrix dataPlot
    unsigned int outputSize = 5;
    SimpleMatrix dataPlot(N + 1, outputSize);



    SP::SiconosVector q = ball->q();
    SP::SiconosVector v = ball->velocity();
    SP::SiconosVector p = ball->p(1);
    SP::SiconosVector lambda = inter->lambda(1);

    dataPlot(0, 0) = bouncingBall->t0();
    dataPlot(0, 1) = (*q)(0);
    dataPlot(0, 2) = (*v)(0);
    dataPlot(0, 3) = (*p)(0);
    dataPlot(0, 4) = (*lambda)(0);
    // --- Time loop ---
    cout << "====> Start computation ... " << endl << endl;
    // ==== Simulation loop - Writing without explicit event handling =====
    int k = 1;
    boost::progress_display show_progress(N);

    boost::timer time;
    time.restart();

    while (s->hasNextEvent())
    {
      s->computeOneStep();

      // --- Get values to be plotted ---
      dataPlot(k, 0) =  s->nextTime();
      dataPlot(k, 1) = (*q)(0);
      dataPlot(k, 2) = (*v)(0);
      dataPlot(k, 3) = (*p)(0);
      dataPlot(k, 4) = (*lambda)(0);
      s->nextStep();
      ++show_progress;
      k++;
    }
    cout << endl << "End of computation - Number of iterations done: " << k - 1 << endl;
    cout << "Computation Time " << time.elapsed()  << endl;

    // --- Output files ---
    cout << "====> Output file writing ..." << endl;
    dataPlot.resize(k, outputSize);
    ioMatrix::write("result.dat", "ascii", dataPlot, "noDim");
    // Comparison with a reference file
    SimpleMatrix dataPlotRef(dataPlot);
    dataPlotRef.zero();
    ioMatrix::read("result.ref", "ascii", dataPlotRef);

    if ((dataPlot - dataPlotRef).normInf() > 1e-12)
    {
      std::cout << 
        "Warning. The results is rather different from the reference file :" 
                << 
        (dataPlot - dataPlotRef).normInf()
                <<
        std::endl;
      CPPUNIT_ASSERT(false);
    }

  }

  catch (SiconosException e)
  {
    cout << e.report() << endl;
    CPPUNIT_ASSERT(false);
  }
  catch (...)
  {
    cout << "Exception caught in BouncingBallTS.cpp" << endl;
    CPPUNIT_ASSERT(false);

  }


}