// ___________________________________________________

      //

      void ValidateAlgo::calculate( Sfx::PhySystem* aPhySys)

      {

        // Courant-Friedrich-Levy number for this simulation

        const float64 w_CFL=SimulationMgr::getSingleton().getCFL();

 

        // compute the time stepping according to CFL criteria

        const float64 w_timeStep =

            w_CFL*Sfx::TimeStepCriteria::adjustTimeStep( m_U1, m_U2);

           

        // time attribute of the simulation

        SimulationMgr::getSingleton().setTimeStep(w_timeStep);

 

        m_bndCnd.applyBC( m_U1, m_U2);

        // compute right-hand-side terms according to spatial discretization

        m_bndCnd.setBC(m_U1->values(),m_U2->values());

           

        // compute friction and bed slope term (S_f and S_b)

        m_Hop.computeSourceTerms(*m_setofSectFlow);

 

        // compute the RHS according to spatial discretization

        // we have change the implementation of the flux algorithm,

        m_rhs = (Swe::LDeltaOperator::SWE_RHS*)m_Hop.applyTo(m_U1,m_U2);

 

        // predictor step (n+1/2)

        m_Rk2Integrator->setStepType( Sfx::TwoStepIntegrator::predictorStep);

        m_Rk2Integrator->setStep( w_timeStep);

        m_Rk2Integrator->step( m_rhs);

 

        // retrieve physical intermediate state

        Sfx::TwoStepIntegrator::pair_vecarr w_AQpairnp12 =

                  m_Rk2Integrator->currentState();

 

        // set field values

        m_U1np12->values(w_AQpairnp12.first);

        m_U2np12->values(w_AQpairnp12.second);

        m_bndCnd.setBC(m_U1np12->values(),m_U2np12->values());

       

        //??

        try

        {

            DamBreakSys* w_dbSys =

                        boost::polymorphic_downcast<DamBreakSys*>(aPhySys);

            w_dbSys->setState(w_AQpairnp12);

        }

        catch( std::bad_cast& bc)

        {

        std::cerr << "Bad cast caught physical system: "<< bc.what()<< "\n";

        }

        aPhySys->notify();

        m_Hop.computeSourceTerms(*m_setofSectFlow);

        m_rhs = (Swe::LDeltaOperator::SWE_RHS*)m_Hop.applyTo(m_U1np12,m_U2np12);

 

        // corrector step

        m_Rk2Integrator->setStepType(Sfx::TwoStepIntegrator::correctorStep);

        m_Rk2Integrator->setStep( w_timeStep);

        m_Rk2Integrator->step(m_rhs);

 

        Sfx::TwoStepIntegrator::pair_vecarr w_AQpairnp1 =

        m_Rk2Integrator->currentState();

        // set field values (use the stl vector)

        m_U1->values(w_AQpairnp1.first);

        m_U2->values(w_AQpairnp1.second);

 

        try

        {

          DamBreakSys* w_dbPhys =

                  boost::polymorphic_downcast<DamBreakSys*>(aPhySys);

          w_dbPhys->setState(w_AQpairnp1); // set the new physical state

          w_dbPhys->setH();                // set the new water level

        }

        catch( std::bad_cast& bc)

        {

            throw "Bad cast with Physical System";

        }

            aPhySys->notify();

      }