Пример #1
0
ECode RatingBar::Init(
    /* [in] */ IContext* context,
    /* [in] */ IAttributeSet* attrs,
    /* [in] */ Int32 defStyle)
{
    FAIL_RETURN(AbsSeekBar::Init(context, attrs, defStyle));
    AutoPtr<ArrayOf<Int32> > attrIds = ArrayOf<Int32>::Alloc(
        const_cast<Int32 *>(R::styleable::RatingBar),
        ARRAY_SIZE(R::styleable::RatingBar));

    AutoPtr<ITypedArray> a;
    FAIL_RETURN(context->ObtainStyledAttributes(attrs, attrIds, defStyle, 0, (ITypedArray**)&a));
    Int32 numStars = 0;
    a->GetInt32(R::styleable::RatingBar_numStars, mNumStars, &numStars);
    Boolean res = FALSE;
    a->GetBoolean(R::styleable::RatingBar_isIndicator, !mIsUserSeekable, &res);
    SetIsIndicator(res);
    Float rating = 0, stepSize = 0;
    a->GetFloat(R::styleable::RatingBar_rating, -1, &rating);
    a->GetFloat(R::styleable::RatingBar_stepSize, -1, &stepSize);
    a->Recycle();

    if(numStars > 0 && numStars != mNumStars) {
        SetNumStars(numStars);
    }

    if(stepSize > 0) {
        SetStepSize(stepSize);
    } else {
        SetStepSize(0.5f);
    }

    if(rating > 0) {
        SetRating(rating);
    }

    // A touch inside a star fill up to that fractional area (slightly more
    // than 1 so boundaries round up).
    mTouchProgressOffset = 1.1f;

    return NOERROR;
}
Пример #2
0
//---------------------------------------------------------
void MaxwellCurved2D::InitRun()
//---------------------------------------------------------
{
  StartUp2D();        // construct grid and metric

#if (0)
  umLOG(1, "before refine : K = %5d\n", K);
  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  DMat Q2(Np*K, 1);  IMat refineflag;
  refineflag = Ones(K,Nfaces); Q2 = ConformingHrefine2D(refineflag, Q2);
  umLOG(1, "after refine 1: K = %5d\n", K);
  //refineflag = Ones(K,Nfaces); Q2 = ConformingHrefine2D(refineflag, Q2);
  //umLOG(1, "after refine 1: K = %5d\n", K);
  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#endif


  BuildBCMaps2D();    // build boundary condition maps
//OutputNodes(true);  // face nodes
  AdjustCylBC(1., 0.,0., BC_All); // Push all boundary faces to unit cylinder
//OutputNodes(true);  // face nodes
  Resize();           // allocate work arrays
  SetIC();            // set initial conditions
  SetStepSize();      // calculate step size (dt)

  BuildCurvedOPS2D(3*N);

  //---------------------------------------------
  // base class version sets counters and flags
  //---------------------------------------------
  NDG2D::InitRun();   

  //---------------------------------------------
  // Adjust reporting and render frequencies
  //---------------------------------------------
  Nreport =  Nsteps/20;
//Nreport =  2;         // set frequency of reporting (param)
//Nreport = 10;         // set frequency of reporting (param)
//Nreport = 50;        // set frequency of reporting (param)
  Nrender = Nreport;    // output frequency           (param)
//Nrender = 10;         // output frequency           (param)
//Nrender = 100000;     // output frequency           (param)
  
  NvtkInterp = 12;      // set output resolution
//NvtkInterp =  6;      // set output resolution

  Summary();          // Show simulation details
}
ForwardEulerSolver::ForwardEulerSolver(int N, double startTime, double endTime, double initialValue){
    if (endTime > startTime){
        if (N > 1){
            SetIterationNumber(N);
            SetInitialValue(initialValue);
            SetTimeInterval(startTime, endTime);
            SetStepSize((endTime - startTime)/(N - 1));
            double* output = SolveEquation();
            for (int i = 0; i < GetIterationNumber(); ++i) {
                std::cout << output[i] << " " << GetInitialTime() + i*GetStepSize() << " " << test(GetInitialTime() + i*GetStepSize())<< "\n";
            }
        }
        else{
            std::cerr << "The number of iterations needs to be > 1!!\n";
        }
    }
    else{
        std::cerr << "Final time needs to be after initial!!\n";
    }
}
Пример #4
0
//---------------------------------------------------------
void Maxwell2D::InitRun()
//---------------------------------------------------------
{
  StartUp2D();          // construct grid and metric

  Resize();             // allocate work arrays
  SetIC();              // set initial conditions
  SetStepSize();        // calculate step size (dt)

  // just call base class version 
  NDG2D::InitRun();

  //---------------------------------------------
  // Adjust reporting and render frequencies
  //---------------------------------------------
  Nreport =  Nsteps/20;
  Nrender = Nreport;    // output frequency           (param)

  NvtkInterp = 12;      // set output resolution

  Summary();            // show simulation details
}
Пример #5
0
//---------------------------------------------------------
void EulerShock2D::Run()
//---------------------------------------------------------
{
  // function Q = EulerShock2D(Q,FinalTime, ExactSolution, ExactSolutionBC, fluxtype)
  // Purpose  : Integrate 2D Euler equations using a 2nd order SSP Runge-Kutta time integrator

  InitRun();

  // choose order to integrate exactly
  CubatureOrder = (int)floor(2.0*(N+1)*3.0/2.0);
  NGauss        = (int)floor(2.0*(N+1));

  // build cubature node data for all elements
  CubatureVolumeMesh2D(CubatureOrder);

  // build Gauss node data for all element faces
  GaussFaceMesh2D(NGauss);

  Resize_cub();         // resize cubature arrays
//MapGaussFaceData();   // {nx = gauss.nx}, etc.
  ti0=timer.read();     // time simulation loop

#if (0)
  //-------------------------------------
  // check all node sets
  //-------------------------------------
  OutputNodes(false);   // volume nodes
  OutputNodes(true);    // face nodes
  OutputNodes_cub();    // cubature
  OutputNodes_gauss();  // quadrature
  Report(true);         // show initial conditions
  umLOG(1, "\n*** Exiting after Cub, Gauss\n\n");
  return;
#endif


  // limit initial condition
  Q = EulerLimiter2D(Q, time);

  // outer time step loop 
  while (time<FinalTime) {

    if (time+dt > FinalTime) {dt=FinalTime-time;}
    tw1=timer.read();   // time NDG work
    oldQ = Q;           // store solutuion from previous step

    // 2nd order SSP Runge-Kutta
    this->RHS(Q,  time, BCSolution); Q1 =  Q +      dt*rhsQ;      Q1 = EulerLimiter2D(Q1, time);
    this->RHS(Q1, time, BCSolution); Q  = (Q + Q1 + dt*rhsQ)/2.0; Q  = EulerLimiter2D(Q,  time);
    
    time += dt;         // increment time 
    SetStepSize();      // compute new timestep
    time_work += timer.read() - tw1;  // accumulate cost of NDG work
    Report();           // optional reporting
    ++tstep;            // increment timestep

    // if (tstep>=10) break;      // testing
  }

  time_total = timer.read()-ti0;  // stop timing
  FinalReport();                  // final report
}
Пример #6
0
//---------------------------------------------------------
void CurvedINS2D::InitRun()
//---------------------------------------------------------
{
  // construct grid and metric
  StartUp2D();

  // Optional mesh refinement: split each parent 
  // element into 4 conforming "child" elements

  if (Nrefine>0) {
    umLOG(1, "before refine : K = %5d\n", K);
    DMat Q2(Np*K, 1);  IMat refineflag;
    refineflag = Ones(K,Nfaces);
    for (int i=1; i<=Nrefine; ++i) {
      Q2 = ConformingHrefine2D(refineflag, Q2);
      umLOG(1, "after refine %d: K = %5d\n", i, K);
    }
  }

  // Adjust faces on circular boundaries,
  // and perform any sim-specific setup:

  switch (sim_type) {

  case eVolkerCylinder:
    // move Cylinder bdry faces to radius 0.05
    AdjustCylBC(0.05, 0.,0., BC_Cyl);
    break;

  default:
    // set default maps for {straight,curved} elements
    straight.range(1,K); curved.resize(0);
    break;
  }

  Resize();             // allocate arrays
  BuildBCMaps2D();      // build boundary condition maps
  SetIC();              // set initial conditions
  SetStepSize();        // calculate step size (dt)

  // reset various work timers
  time_setup = time_advection = 0.0;
  time_viscous = time_viscous_sol = 0.0;
  time_pressure = time_pressure_sol = 0.0;

  //---------------------------------------------
  // base class version sets counters and flags
  //---------------------------------------------
  NDG2D::InitRun();   

  //---------------------------------------------
  // set frequency of reporting
  //---------------------------------------------
//Nreport =  Nsteps/150;
//Nreport =  10;
//Nreport =  2;

  Nreport = 10;
//Nreport = 250;

//Nreport = 1000;
//Nreport = 10000;

  //---------------------------------------------
  // set frequency of rendering
  //---------------------------------------------
  Nrender = Nreport;
//Nrender = 250;
//Nrender = 1000;

//NvtkInterp = 12;        // set output resolution
//NvtkInterp =  5;        // set output resolution
  NvtkInterp = this->N;   // use original nodes

  Summary();  // show simulation details
}
Пример #7
0
//---------------------------------------------------------
void EulerShock2D::InitRun()
//---------------------------------------------------------
{
  // base class performs usual startup sequence
  // CurvedEuler2D::InitRun();

  //-------------------------------------
  // construct grid and metric
  //-------------------------------------
  StartUp2D();

  //-------------------------------------
  // refine default mesh
  //-------------------------------------
  if (Nrefine>=1) {
    umLOG(1, "before refinement K = %6d\n", K);
    for (int i=1; i<=Nrefine; ++i) {
      DMat Qtmp(Np*K, 1);  IMat refineflag;
      refineflag = Ones(K,Nfaces); Qtmp = ConformingHrefine2D(refineflag, Qtmp);
      umLOG(1, "after h-refine %d: K = %6d\n", i,K);
    }
  }

  // store original BC types before adjusting, 
  // (e.g. BC_Cyl faces may be set to BC_Wall)
  saveBCType = BCType;

  //-------------------------------------
  // Adjust faces on circular boundaries
  //-------------------------------------
  switch (sim_type) {

  case eForwardStep:
    // no cylinder faces
    straight.range(1,K); curved.resize(0);
    break;

  case eScramInlet:
    // no cylinder faces
    straight.range(1,K); curved.resize(0);
    break;
  
  default:
    // set default maps for {straight,curved} elements
    straight.range(1,K); curved.resize(0);
    break;
  }

  BuildBCMaps2D();  // map faces subject to boundary conditions
  Resize();         // allocate arrays
  SetIC();          // set initial conditions

#if (1)
  OutputNodes(false); // volume nodes
#endif


#if (0)
  tstep = -1;
  Report(true);
#endif

  SetStepSize();    // compute initial timestep (using IC's)

  // storage for residual at each time-step,
  // allowing for variable step size
  resid.resize(2*Nsteps);

  // base class version sets counters and flags
  NDG2D::InitRun();   

  // pre-calculate constant data for limiter routine
  precalc_limiter_data();

  //---------------------------------------------
  // Adjust reporting and render frequencies
  //---------------------------------------------

  switch (sim_type) {

  case eForwardStep:
    Nreport     = 100;    // frequency of reporting
    Nrender     = 300;    // frequency of rendering
    NvtkInterp  = 3;      // resolution of vtk output
    break;

  case eScramInlet:
    NvtkInterp = 2;
    switch (mesh_level) {
    case 1:   Nreport =  100;  Nrender =  100;   break;
    case 2:   Nreport =  250;  Nrender =  250;   break;
    case 3:   Nreport =  500;  Nrender =  500;   break;
    case 4:   Nreport = 1000;  Nrender = 1000;   break;
    default:  Nreport = 1000;  Nrender = 1000;   break;
    }
    break;
  }

  // Show simulation details
  Summary();
}