Example #1
0
void VCAMRPoissonOp2::reflux(const LevelData<FArrayBox>&        a_phiFine,
                            const LevelData<FArrayBox>&        a_phi,
                            LevelData<FArrayBox>&              a_residual,
                            AMRLevelOp<LevelData<FArrayBox> >* a_finerOp)
{
  CH_TIME("VCAMRPoissonOp2::reflux");

  int ncomp = 1;
  ProblemDomain fineDomain = refine(m_domain, m_refToFiner);
  LevelFluxRegister levfluxreg(a_phiFine.disjointBoxLayout(),
                               a_phi.disjointBoxLayout(),
                               fineDomain,
                               m_refToFiner,
                               ncomp);

  levfluxreg.setToZero();
  Interval interv(0,a_phi.nComp()-1);

  DataIterator dit = a_phi.dataIterator();
  for (dit.reset(); dit.ok(); ++dit)
    {
      const FArrayBox& coarfab = a_phi[dit];
      const FluxBox& coarBCoef  = (*m_bCoef)[dit];
      const Box& gridBox = a_phi.getBoxes()[dit];

      for (int idir = 0; idir < SpaceDim; idir++)
        {
          FArrayBox coarflux;
          Box faceBox = surroundingNodes(gridBox, idir);
          getFlux(coarflux, coarfab, coarBCoef , faceBox, idir);

          Real scale = 1.0;
          levfluxreg.incrementCoarse(coarflux, scale,dit(),
                                     interv,interv,idir);
        }
    }
  LevelData<FArrayBox>& p = ( LevelData<FArrayBox>&)a_phiFine;

  // has to be its own object because the finer operator
  // owns an interpolator and we have no way of getting to it
  VCAMRPoissonOp2* finerAMRPOp = (VCAMRPoissonOp2*) a_finerOp;
  QuadCFInterp& quadCFI = finerAMRPOp->m_interpWithCoarser;

  quadCFI.coarseFineInterp(p, a_phi);
  // p.exchange(a_phiFine.interval()); // BVS is pretty sure this is not necesary.
  IntVect phiGhost = p.ghostVect();

  DataIterator ditf = a_phiFine.dataIterator();
  const  DisjointBoxLayout& dblFine = a_phiFine.disjointBoxLayout();
  for (ditf.reset(); ditf.ok(); ++ditf)
    {
      const FArrayBox& phifFab = a_phiFine[ditf];
      const FluxBox& fineBCoef  = (*(finerAMRPOp->m_bCoef))[ditf];
      const Box& gridbox = dblFine.get(ditf());
      for (int idir = 0; idir < SpaceDim; idir++)
        {
          int normalGhost = phiGhost[idir];
          SideIterator sit;
          for (sit.begin(); sit.ok(); sit.next())
            {
              Side::LoHiSide hiorlo = sit();
              Box fabbox;
              Box facebox;

              // assumption here that the stencil required
              // to compute the flux in the normal direction
              // is 2* the number of ghost cells for phi
              // (which is a reasonable assumption, and probably
              // better than just assuming you need one cell on
              // either side of the interface
              // (dfm 8-4-06)
              if (sit() == Side::Lo)
                {
                  fabbox = adjCellLo(gridbox,idir, 2*normalGhost);
                  fabbox.shift(idir, 1);
                  facebox = bdryLo(gridbox, idir,1);
                }
              else
                {
                  fabbox = adjCellHi(gridbox,idir, 2*normalGhost);
                  fabbox.shift(idir, -1);
                  facebox = bdryHi(gridbox, idir, 1);
                }

              // just in case we need ghost cells in the transverse direction
              // (dfm 8-4-06)
              for (int otherDir=0; otherDir<SpaceDim; ++otherDir)
                {
                  if (otherDir != idir)
                    {
                      fabbox.grow(otherDir, phiGhost[otherDir]);
                    }
                }
              CH_assert(!fabbox.isEmpty());

              FArrayBox phifab(fabbox, a_phi.nComp());
              phifab.copy(phifFab);

              FArrayBox fineflux;
              getFlux(fineflux, phifab, fineBCoef, facebox, idir,
                      m_refToFiner);

              Real scale = 1.0;
              levfluxreg.incrementFine(fineflux, scale, ditf(),
                                       interv, interv, idir, hiorlo);
            }
        }
    }

  Real scale =  1.0/m_dx;
  levfluxreg.reflux(a_residual, scale);
}
void CollisionTest::display()
{
	const static GLfloat lightPosition[] = {1, -1, 0, 0};
	const static GLfloat lightPositionMirror[] = { 1, 1, 0, 0 };

	// Update the transform matrices of each box in turn.
	for (Box *box = boxData; box < boxData + boxes; box++)
	{
		box->calculateInternals();
		box->isOverlapping = false;
	}

	// Update the transform matrices of each ball in turn.
	for (Ball *ball = ballData; ball < ballData + balls; ball++)
	{
		// Run the physics.
		ball->calculateInternals();
	}

	// Clear the viewport and set the camera direction.
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(18.0f, 0, 0, 0, 0, 0, 0, 1.0f, 0);
	glRotatef(-phi, 0, 0, 1);
	glRotatef(theta, 0, 1, 0);
	glTranslatef(0, -5.0f, 0);

	// Render each element in turn as a shadow.
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
	glEnable(GL_LIGHT0);
	glPushMatrix();
	glMultMatrixf(floorMirror);
	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
	for (Box *box = boxData; box < boxData + boxes; box++)
	{
		box->render();
	}
	for (Ball *ball = ballData; ball < ballData + balls; ball++)
	{
		ball->render();
	}
	glPopMatrix();
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);

	DrawGrid(Vector3(35, 0, 30), 60);

	// Render each shadow in turn
	glEnable(GL_BLEND);
	glColor4f(0, 0, 0, 0.1f);
	glDisable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	for (Box *box = boxData; box < boxData + boxes; box++)
	{
		box->renderShadow();
	}
	for (Ball *ball = ballData; ball < ballData + balls; ball++)
	{
		ball->renderShadow();
	}
	glDisable(GL_BLEND);
	
	// Render the boxes themselves
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPositionMirror);
	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	for (Box *box = boxData; box < boxData + boxes; box++)
	{
		box->render();
	}
	for (Ball *ball = ballData; ball < ballData + balls; ball++)
	{
		ball->render();
	}
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);
	
	drawDebug();
}
void
LevelFluxRegisterEdge::refluxCurl(LevelData<FluxBox>& a_uCoarse,
                                  Real a_scale)
{
  CH_assert(isDefined());
  CH_assert(a_uCoarse.nComp() == m_nComp);

  SideIterator side;
  // idir is the normal direction to the coarse-fine interface
  for (int idir=0 ; idir<SpaceDim; ++idir)
  {
    for (side.begin(); side.ok(); ++side)
    {
      LevelData<FluxBox>& fineReg = m_fabFine[index(idir, side())];

      // first, create temp LevelData<FluxBox> to hold "coarse flux"
      const DisjointBoxLayout coarseBoxes = m_regCoarse.getBoxes();

      // this fills the place of what used to be m_fabCoarse in the old
      // implementation
      LevelData<FluxBox> coarReg(coarseBoxes, m_nComp, IntVect::Unit);


      // now fill the coarReg with the curl of the stored coarse-level
      // edge-centered flux
      DataIterator crseDit = coarseBoxes.dataIterator();
      for (crseDit.begin(); crseDit.ok(); ++crseDit)
        {
          FluxBox& thisCoarReg = coarReg[crseDit];
          thisCoarReg.setVal(0.0);

          EdgeDataBox& thisEdgeData = m_regCoarse[crseDit];

          for (int edgeDir=0; edgeDir<SpaceDim; edgeDir++)
            {
              if (idir != edgeDir)
                {
                  FArrayBox& crseEdgeDataDir = thisEdgeData[edgeDir];
                  for (int faceDir = 0; faceDir<SpaceDim; faceDir++)
                    {
                      if (faceDir != edgeDir)
                        {
                          FArrayBox& faceData = thisCoarReg[faceDir];
                          int shiftDir = -1;
                          for (int i=0; i<SpaceDim; i++)
                            {
                              if ((i != faceDir) && (i != edgeDir) )
                                {
                                  shiftDir = i;
                                }
                            }
                          CH_assert(shiftDir >= 0);
                          crseEdgeDataDir.shiftHalf(shiftDir, sign(side()));
                          // scaling already taken care of in incrementCrse
                          Real scale = 1.0;
                          faceData.plus(crseEdgeDataDir, scale, 0, 0, faceData.nComp());
                          crseEdgeDataDir.shiftHalf(shiftDir, -sign(side()));
                        } // end if not normal direction
                    } // end loop over face directions
                } // end if edgeDir != idir
            } // end loop over edge directions
        } // end loop over crse boxes


      // first, we need to create a temp LevelData<FluxBox>
      // to make a local copy in the coarse layout space of
      // the fine register increments

      LevelData<FluxBox> fineRegLocal(coarReg.getBoxes(), m_nComp, IntVect::Unit);

      fineReg.copyTo(fineReg.interval(), fineRegLocal,
                     fineRegLocal.interval(),
                     m_crseCopiers[index(idir,side())]);

      for (DataIterator it = a_uCoarse.dataIterator(); it.ok(); ++it)
        {
          // loop over flux components here
          for (int fluxComp=0; fluxComp < SpaceDim; fluxComp++)
            {
              // we don't do anything in the normal direction
              if (fluxComp != idir)
                {
                  // fluxDir is the direction of the face-centered flux
                  FArrayBox& U = a_uCoarse[it()][fluxComp];
                  // set up IntVectSet to avoid double counting of updates
                  Box coarseGridBox = U.box();
                  // transfer to Cell-centered, then create IVS
                  coarseGridBox.shiftHalf(fluxComp,1);
                  IntVectSet nonUpdatedEdges(coarseGridBox);

                  // remember, we want to take the curl here
                  // also recall that fluxComp is the component
                  // of the face-centered curl (not the edge-centered
                  // vector field that we're refluxing, which is why
                  // the sign may seem like it's the opposite of what
                  // you might expect!
                  Real local_scale = -sign(side())*a_scale;
                  //int testDir = (fluxComp+1)%(SpaceDim);
                  if (((fluxComp+1)%(SpaceDim)) == idir)  local_scale *= -1;
                  Vector<IntVectSet>& ivsV =
                    m_refluxLocations[index(idir, side())][it()][fluxComp];
                  Vector<DataIndex>&  indexV =
                    m_coarToCoarMap[index(idir, side())][it()];
                  IVSIterator iv;

                  for (int i=0; i<ivsV.size(); ++i)
                    {
                      iv.define(ivsV[i]);
                      const FArrayBox& coar = coarReg[indexV[i]][fluxComp];
                      const FArrayBox& fine = fineRegLocal[indexV[i]][fluxComp];
                      for (iv.begin(); iv.ok(); ++iv)
                        {
                          IntVect thisIV = iv();
                          if (nonUpdatedEdges.contains(thisIV))
                          {
                            for (int comp=0; comp <m_nComp; ++comp)
                              {
                                //Real coarVal = coar(thisIV, comp);
                                //Real fineVal = fine(thisIV, comp);
                                U(thisIV, comp) -=
                                local_scale*(coar(thisIV, comp)
                                             +fine(thisIV, comp));
                              }
                            nonUpdatedEdges -= thisIV;
                          }
                        }

                    }
                } // end if not normal face
            } // end loop over fluxbox directions
        } // end loop over coarse boxes
    } // end loop over sides
  } // end loop over directions
}
Example #4
0
  // Computes   omega = A*psi
  void execute( const vector<complex>& psi, vector<complex>& omega )
  {
#if STAGE_TIMES
    StopWatch timer;
    timer.start();
#endif

    int nLevels = tree.numLevels();

    // Compute lowest level multipole
    Level<DIM>& leafLevel = getLevel(nLevels);
    leafLevel.zeroFields();
    for( BoxIter bi = leafLevel.boxbegin(); bi != leafLevel.boxend(); ++bi ) {
      Box* b = *bi;

      const Vec3& center = b->center;

      const Box::pointIter piEnd = b->pointIndex.end();
      for( Box::pointIter pi = b->pointIndex.begin(); pi != piEnd; ++pi ) {
        int index = *pi;
        const Vec3 r = center - sourcefield[index];
        cout << "Accumulating " << index << " into Box " << b->n << endl;
        Translation_Function::add( r, psi[index], b->getMultipole() );
      }
    }

#if STAGE_TIMES
    cout << "Lowest Level Multipoles Done " << timer.stop() << endl;
#endif

    // Upward Pass - Compute the multipoles
    for( int L = nLevels; L >= 3; --L ) {

      Level<DIM>& level = getLevel(L);
      Level<DIM>& pLevel = getLevel(L-1);
      pLevel.zeroFields();
      NFunction& Ms = pLevel.getScratch();

      // For all boxes at level L
      for( BoxIter bi = level.boxbegin(); bi != level.boxend(); ++bi ) {
        Box* b = *bi;

        // Interpolate to the parent level L-1
        level.getInterp().apply( b->getMultipole(), Ms );

        // Multiply by the transfer function and accumulate into parent
        b->parent->getMultipole().addProduct( Ms, pLevel.getTranslationUp(b) );
      }
    }

#if STAGE_TIMES
    cout << "Upward Pass Done " << timer.stop() << endl;
#endif

    // Do the Transfers
    for( int L = nLevels; L >= 2; --L ) {
      getLevel(L).applyTransferFunctions();
    }

#if STAGE_TIMES
    cout << "Transfer List Applied " << timer.stop() << endl;
#endif

    for( int L = 3; L <= nLevels; ++L ) {

      Level<DIM>& level = getLevel(L);
      Level<DIM>& pLevel = getLevel(L-1);
      NFunction& Lb = level.getScratch();
      NFunction& LB = pLevel.getScratch();

      // For all boxes at level L
      for( BoxIter bi = level.boxbegin(); bi != level.boxend(); ++bi ) {
        Box* b = *bi;

        // Multiply parent's local expansion by translation function
        LB.setProduct( b->parent->getLocal(), pLevel.getTranslationDown(b) );

        // Anterpolate
        pLevel.getAnterp().apply( LB, Lb );

        // Accumulate into the box's local expansion
        b->getLocal().add( Lb );
      }
    }

#if STAGE_TIMES
    cout << "Downward Pass Done " << timer.stop() << endl;
#endif

    // Zero omega
    omega.assign( omega.size(), 0 );

    // Integrate and add close interactions

    // For all the boxes at the lowest level, integrate local
    NFunction& LE = leafLevel.getScratch();           // Scratch space
    for( BoxIter bi = leafLevel.boxbegin(); bi != leafLevel.boxend(); ++bi ) {
      Box* b = *bi;
      Vec3& center = b->center;
      // for all interior points
      const Box::pointIter nEnd = b->pointIndex.end();
      for( Box::pointIter ni = b->pointIndex.begin(); ni != nEnd; ++ni ) {
        int n = *ni;
        const Vec3& pn = sourcefield[n];
        Vec3 r = pn - center;
        //cout << "Integrating for " << n << " from box " << b->n << endl;
        Translation_Function::times( b->getLocal(), r, LE );
        omega[n] += LE.integrate();

        // Add contributions from other points inside this box
        for( Box::pointIter mi = b->pointIndex.begin(); mi != ni; ++mi ) {
          int m = *mi;
          double r = pn.dist(sourcefield[m]);
          complex E = K(r);
          omega[m] += psi[n] * E;
          omega[n] += psi[m] * E;
        }
      }
    }

#if STAGE_TIMES
    cout << "Local Integration Done " << timer.stop() << endl;
#endif

    leafLevel.applyClose(K, psi, sourcefield, omega);

#if STAGE_TIMES
    cout << "Close List Applied " << timer.stop() << endl;
#endif
  }
Example #5
0
void drawScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity(); 
	//brown color of the board
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, -8.0f);
	glBegin(GL_QUADS);
	glColor3f(0.0f, 0.0f, 0.0f);
	glVertex2f(-3.0f  , -3.0f);
	glVertex2f(-3.0f , 3.0f);
	glVertex2f(3.0f , 3.0f);
	glVertex2f(3.0f , -3.0f);
	glEnd();
	glPopMatrix();
	//cream color of the board
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, -8.0f);
	glBegin(GL_QUADS);
	glColor3f(1.0f, 0.8f, 0.45f);
	glVertex2f(-2.75f , -2.75f);
	glVertex2f(-2.75f , 2.75f);
	glVertex2f(2.75f , 2.75f);
	glVertex2f(2.75f , -2.75f);
	glEnd();
	glPopMatrix();
	//holes
	glTranslatef(0.0f, 0.0f, -8.0f);
	glPushMatrix();
	hol[0].drawhole(hol[0].a,hol[0].c,-8.0f,0.0f,0.0f,0.0f,hol[0].rad);
	glPopMatrix();
	glPushMatrix();
	hol[0].drawhole(hol[1].a,hol[1].c,-8.0f,0.0f,0.0f,0.0f,hol[1].rad);
	glPopMatrix();
	glPushMatrix();
	hol[0].drawhole(hol[2].a,hol[2].c,-8.0f,0.0f,0.0f,0.0f,hol[2].rad);
	glPopMatrix();
	glPushMatrix();
	hol[0].drawhole(hol[3].a,hol[3].c,-8.0f,0.0f,0.0f,0.0f,hol[3].rad);
	glPopMatrix();
	//circle at centre
	glPushMatrix();
	c.drawCircle(0.0f,0.0f,-8.0f,0.0f,0.0f,0.0f,1.50f);
	glPopMatrix();
	//striker box
	glPushMatrix();
	u.drawstrikerbox(7.0f,0.58f,0.0f,4.0f,-8.0f,0.0f,0.0f,0.0f);
	glPopMatrix();
	glPushMatrix();
	u1.drawstrikerbox(7.0f,0.58f,0.0f,-4.0f,-8.0f,0.0f,0.0f,0.0f);
	glPopMatrix();
	glPushMatrix();
	u2.drawstrikerbox(0.58f,7.0f,4.0f,0.0f,-8.0f,0.0f,0.0f,0.0f);
	glPopMatrix();
	glPushMatrix();
	u3.drawstrikerbox(0.58f,7.0f,-4.0f,0.0f,-8.0f,0.0f,0.0f,0.0f);
	glPopMatrix();
	//stricker box holes
	glPushMatrix();
	hole[0].drawhole(3.5f,4.0f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[1].drawhole(-4.0f,3.5f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[2].drawhole(-3.5f,-4.0f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[3].drawhole(4.0f,-3.5f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[4].drawhole(3.5f,-4.0f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[5].drawhole(4.0f,3.5f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[6].drawhole(-3.5f,4.0f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	glPushMatrix();
	hole[7].drawhole(-4.0f,-3.5f,-8.0f,1.0f,0.0f,0.0f,0.3f);
	glPopMatrix();
	//coins
	glPushMatrix();
	coin[0].drawcoin(coin[0].a,coin[0].c,-8.0f,0.0f,0.0f,0.0f,coin[0].rad);
	glPopMatrix();
	glPushMatrix();
	coin[1].drawcoin(coin[1].a,coin[1].c,-8.0f,0.0f,0.0f,0.0f,coin[1].rad);
	glPopMatrix();
	glPushMatrix();
	coin[2].drawcoin(coin[2].a,coin[2].c,-8.0f,0.0f,0.0f,0.0f,coin[2].rad);
	glPopMatrix();
	glPushMatrix();
	coin[3].drawcoin(coin[3].a,coin[3].c,-8.0f,0.0f,0.0f,0.0f,coin[3].rad);
	glPopMatrix();
	glPushMatrix();
	coin[4].drawcoin(coin[4].a,coin[4].c,-8.0f,0.8f,0.4f,0.0f,coin[4].rad);
	glPopMatrix();
	glPushMatrix();
	coin[5].drawcoin(coin[5].a,coin[5].c,-8.0f,0.8f,0.4f,0.0f,coin[5].rad);
	glPopMatrix();
	glPushMatrix();
	coin[6].drawcoin(coin[6].a,coin[6].c,-8.0f,0.8f,0.4f,0.0f,coin[6].rad);
	glPopMatrix();
	glPushMatrix();
	coin[7].drawcoin(coin[7].a,coin[7].c,-8.0f,0.8f,0.4f,0.0f,coin[7].rad);
	glPopMatrix();
	glPushMatrix();
	coin[8].drawcoin(coin[8].a,coin[8].c,-8.0f,1.0f,0.0f,0.0f,coin[8].rad);
	glPopMatrix();
	// striker
	glPushMatrix();
	s[0].drawstriker(s[0].a,s[0].c,-8.0f,0.0f,1.0f,0.0f,s[0].rad);
	glPopMatrix();
	//striker pointer
	glPushMatrix();
	glTranslatef(s[0].a,s[0].c,-8.0f);
	glColor3f(0.0f,0.0f,0.0f);
	glRotatef(theta,0.0f,0.0f,-1.0f);
	glBegin(GL_LINES);
	glVertex2f(0.0f,0.0f);
	glVertex2f(lx,ly);
	glEnd();
	glPopMatrix();
	// speedometer
	glPushMatrix();
	glBegin(GL_QUADS);
	glColor3f(0.0,1.0,0.0);
	glVertex2f(3.8,-3.0);
	glVertex2f(4.0,-3.0);
	glVertex2f(4.0,pointer);
	glVertex2f(3.8,pointer);
	glColor3f(1.0,0.0,0.1);
	glVertex2f(4.0,2.0);
	glVertex2f(3.8,2.0);
	glVertex2f(3.8,pointer);
	glVertex2f(4.0,pointer);
	glEnd();
	glColor3f(0.4,0.3,0.1);
	glVertex2f(0.48,pointer);
	glVertex2f(0.55,pointer);
	glPopMatrix();
	//score-board
	scoreBoard.drawBox();
	glColor3f(0.0f,0.0f,1.0f);
	char string[] = "Score";
	scoreBoard.drawText(string,strlen(string),-0.7f,0.2f);
	ostringstream sc;
	sc<<scoreBoard.score1;
	score1 = sc.str();
	scoreBoard.drawText(score1.data(),score1.size(),-0.2f,-0.4f); 
	glutSwapBuffers();
}
KOKKOS_INLINE_FUNCTION
bool isValid( Box const &b )
{
    return isValid( b.minCorner() ) && isValid( b.maxCorner() );
}
Example #7
0
		Mesh* Sphere::GenerateMesh()
		{
			Box box;
			return box.GenerateMesh();
		}
Example #8
0
  void MeshFromSpline2D (SplineGeometry2d & geometry,
			 Mesh *& mesh, 
			 MeshingParameters & mp)
  {
    PrintMessage (1, "Generate Mesh from spline geometry");

    double h = mp.maxh;

    Box<2> bbox = geometry.GetBoundingBox ();

    if (bbox.Diam() < h) 
      {
	h = bbox.Diam();
	mp.maxh = h;
      }

    mesh = new Mesh;
    mesh->SetDimension (2);

    geometry.PartitionBoundary (h, *mesh);

    // marks mesh points for hp-refinement
    for (int i = 0; i < geometry.GetNP(); i++)
      if (geometry.GetPoint(i).hpref)
	{
	  double mindist = 1e99;
	  PointIndex mpi(0);
	  Point<2> gp = geometry.GetPoint(i);
	  Point<3> gp3(gp(0), gp(1), 0);
	  for (PointIndex pi = PointIndex::BASE; 
	       pi < mesh->GetNP()+PointIndex::BASE; pi++)
	    if (Dist2(gp3, (*mesh)[pi]) < mindist)
	      {
		mpi = pi;
		mindist = Dist2(gp3, (*mesh)[pi]);
	      }
	  (*mesh)[mpi].Singularity(1.);
	}


    int maxdomnr = 0;
    for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
      {
	if ( (*mesh)[si].domin > maxdomnr) maxdomnr = (*mesh)[si].domin;
	if ( (*mesh)[si].domout > maxdomnr) maxdomnr = (*mesh)[si].domout;
      }

    mesh->ClearFaceDescriptors();
    for (int i = 1; i <= maxdomnr; i++)
      mesh->AddFaceDescriptor (FaceDescriptor (i, 0, 0, i));

    // set Array<string*> bcnames... 
    // number of bcnames
    int maxsegmentindex = 0;
    for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
      {
	if ( (*mesh)[si].si > maxsegmentindex) maxsegmentindex = (*mesh)[si].si;
      }

    mesh->SetNBCNames(maxsegmentindex);

    for ( int sindex = 0; sindex < maxsegmentindex; sindex++ )
      mesh->SetBCName ( sindex, geometry.GetBCName( sindex+1 ) );

    for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
      (*mesh)[si].SetBCName ( (*mesh).GetBCNamePtr( (*mesh)[si].si-1 ) );

    Point3d pmin(bbox.PMin()(0), bbox.PMin()(1), -bbox.Diam());
    Point3d pmax(bbox.PMax()(0), bbox.PMax()(1), bbox.Diam());

    mesh->SetLocalH (pmin, pmax, mparam.grading);
    mesh->SetGlobalH (h);
  
    mesh->CalcLocalH();

    int bnp = mesh->GetNP(); // boundary points

    int hquad = mparam.quad;


    for (int domnr = 1; domnr <= maxdomnr; domnr++)
      if (geometry.GetDomainTensorMeshing (domnr))
        { // tensor product mesh
          
          Array<PointIndex, PointIndex::BASE> nextpi(bnp);
          Array<int, PointIndex::BASE> si1(bnp), si2(bnp);
          PointIndex firstpi;
          
          nextpi = -1;
          si1 = -1;
          si2 = -1;
          for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
            {
              int p1 = -1, p2 = -2;

              if ( (*mesh)[si].domin == domnr)
                { p1 = (*mesh)[si][0]; p2 = (*mesh)[si][1]; }
              if ( (*mesh)[si].domout == domnr)
                { p1 = (*mesh)[si][1]; p2 = (*mesh)[si][0]; }
              
              if (p1 == -1) continue;

              nextpi[p1] = p2;       // counter-clockwise
              
              int index = (*mesh)[si].si;
              if (si1[p1] != index && si2[p1] != index)
                { si2[p1] = si1[p1]; si1[p1] = index; }
              if (si1[p2] != index && si2[p2] != index)
                { si2[p2] = si1[p2]; si1[p2] = index; }
            }

          PointIndex c1(0), c2, c3, c4;  // 4 corner points
          int nex = 1, ney = 1;

          for (PointIndex pi = 1; pi <= si2.Size(); pi++)
            if (si2[pi] != -1)
              { c1 = pi; break; }      

          for (c2 = nextpi[c1]; si2[c2] == -1; c2 = nextpi[c2], nex++);
          for (c3 = nextpi[c2]; si2[c3] == -1; c3 = nextpi[c3], ney++);
          for (c4 = nextpi[c3]; si2[c4] == -1; c4 = nextpi[c4]);



          Array<PointIndex> pts ( (nex+1) * (ney+1) );   // x ... inner loop
          pts = -1;

          for (PointIndex pi = c1, i = 0; pi != c2; pi = nextpi[pi], i++)
            pts[i] = pi;
          for (PointIndex pi = c2, i = 0; pi != c3; pi = nextpi[pi], i++)
            pts[(nex+1)*i+nex] = pi;
          for (PointIndex pi = c3, i = 0; pi != c4; pi = nextpi[pi], i++)
            pts[(nex+1)*(ney+1)-i-1] = pi;
          for (PointIndex pi = c4, i = 0; pi != c1; pi = nextpi[pi], i++)
            pts[(nex+1)*(ney-i)] = pi;


          for (PointIndex pix = nextpi[c1], ix = 0; pix != c2; pix = nextpi[pix], ix++)
            for (PointIndex piy = nextpi[c2], iy = 0; piy != c3; piy = nextpi[piy], iy++)
              {
                Point<3> p = (*mesh)[pix] + ( (*mesh)[piy] - (*mesh)[c2] );
                pts[(nex+1)*(iy+1) + ix+1] = mesh -> AddPoint (p , 1, FIXEDPOINT);
              }

          for (int i = 0; i < ney; i++)
            for (int j = 0; j < nex; j++)
              {
                Element2d el(QUAD);
                el[0] = pts[i*(nex+1)+j];
                el[1] = pts[i*(nex+1)+j+1];
                el[2] = pts[(i+1)*(nex+1)+j+1];
                el[3] = pts[(i+1)*(nex+1)+j];
                el.SetIndex (domnr);

                mesh -> AddSurfaceElement (el);
              }
        }




    for (int domnr = 1; domnr <= maxdomnr; domnr++)
      {
        if (geometry.GetDomainTensorMeshing (domnr)) continue;

	if ( geometry.GetDomainMaxh ( domnr ) > 0 )
	  h = geometry.GetDomainMaxh(domnr);


	PrintMessage (3, "Meshing domain ", domnr, " / ", maxdomnr);

	int oldnf = mesh->GetNSE();

        mparam.quad = hquad || geometry.GetDomainQuadMeshing (domnr);

	Meshing2 meshing (Box<3> (pmin, pmax));

	for (PointIndex pi = PointIndex::BASE; pi < bnp+PointIndex::BASE; pi++)
	  meshing.AddPoint ( (*mesh)[pi], pi);
      

	PointGeomInfo gi;
	gi.trignum = 1;
	for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
	  {
	    if ( (*mesh)[si].domin == domnr)
	      meshing.AddBoundaryElement ( (*mesh)[si][0] + 1 - PointIndex::BASE, 
					   (*mesh)[si][1] + 1 - PointIndex::BASE, gi, gi);
	    if ( (*mesh)[si].domout == domnr)
	      meshing.AddBoundaryElement ( (*mesh)[si][1] + 1 - PointIndex::BASE, 
					   (*mesh)[si][0] + 1 - PointIndex::BASE, gi, gi);
	  }


	mparam.checkoverlap = 0;

	meshing.GenerateMesh (*mesh, h, domnr);

	for (SurfaceElementIndex sei = oldnf; sei < mesh->GetNSE(); sei++)
	  (*mesh)[sei].SetIndex (domnr);


	// astrid
	char * material;
	geometry.GetMaterial( domnr, material );
	if ( material )
	  {
	    (*mesh).SetMaterial ( domnr,  material );
	  }

      }

    mparam.quad = hquad;



    int hsteps = mp.optsteps2d;

    mp.optimize2d = "smcm"; 
    mp.optsteps2d = hsteps/2;
    Optimize2d (*mesh, mp);

    mp.optimize2d = "Smcm"; 
    mp.optsteps2d = (hsteps+1)/2;
    Optimize2d (*mesh, mp);

    mp.optsteps2d = hsteps;

    mesh->Compress();
    mesh -> SetNextMajorTimeStamp();


    extern void Render();
    Render();
  }
Example #9
0
void
Moof::ParseTraf(Box& aBox, Trex& aTrex, Mvhd& aMvhd, Mdhd& aMdhd, Edts& aEdts, Sinf& aSinf, uint64_t* aDecodeTime, bool aIsAudio)
{
  MOZ_ASSERT(aDecodeTime);
  Tfhd tfhd(aTrex);
  Tfdt tfdt;
  for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
    if (box.IsType("tfhd")) {
      tfhd = Tfhd(box, aTrex);
    } else if (!aTrex.mTrackId || tfhd.mTrackId == aTrex.mTrackId) {
      if (box.IsType("tfdt")) {
        tfdt = Tfdt(box);
      } else if (box.IsType("saiz")) {
        mSaizs.AppendElement(Saiz(box, aSinf.mDefaultEncryptionType));
      } else if (box.IsType("saio")) {
        mSaios.AppendElement(Saio(box, aSinf.mDefaultEncryptionType));
      }
    }
  }
  if (aTrex.mTrackId && tfhd.mTrackId != aTrex.mTrackId) {
    return;
  }
  // Now search for TRUN boxes.
  uint64_t decodeTime =
    tfdt.IsValid() ? tfdt.mBaseMediaDecodeTime : *aDecodeTime;
  for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
    if (box.IsType("trun")) {
      if (ParseTrun(box, tfhd, aMvhd, aMdhd, aEdts, &decodeTime, aIsAudio)) {
        mValid = true;
      } else {
        mValid = false;
        break;
      }
    }
  }
  *aDecodeTime = decodeTime;
}
Example #10
0
int main(int argc, char* argv[])
{
#ifdef CH_MPI
  MPI_Init(&argc, &argv);
  // setChomboMPIErrorHandler();
  MPI_Barrier(Chombo_MPI::comm);  // Barrier #1
#endif

  // ------------------------------------------------
  // parse command line and input file
  // ------------------------------------------------
  // infile must be first
  if (argc < 2)
  {
    cerr << "  need inputs file" << endl;
    abort();
  }

  char* in_file = argv[1];
  ParmParse pp(argc-2, argv+2, NULL, in_file);

#ifdef CH_MPI
  MPI_Barrier(Chombo_MPI::comm);
#endif

  pout().setf(ios::scientific);
  pout().precision(4);

  // set defaults
  bool isSameSize = false;
  bool doGhostCells = false;
  bool doPlots = true;
  bool isTimeDep = false;
  bool verbose = false;
  bool computeRelativeError = false;
  bool removeMean = false;
  bool useUnitDomain = false;
  bool HOaverage = false;

  // this is the initial value for the error
  Real bogusValue = 0.0;

  string exactRoot, computedRoot, errorRoot;

  Vector<string> errorVars;

  int numCrseFinish, numCrseStart, crseStep, crseMult, intFieldSize;

  init(exactRoot, computedRoot, errorRoot, intFieldSize,
       numCrseStart, errorVars, numCrseFinish, crseStep,
       crseMult, doPlots, isTimeDep, isSameSize, bogusValue,
       computeRelativeError, removeMean, doGhostCells, useUnitDomain,
       HOaverage,verbose);


  int nStep, exactStep;

  if (!isTimeDep)
  {
    crseStep = 1;
    numCrseFinish = numCrseStart;
  }

  for (nStep = numCrseStart; nStep <= numCrseFinish; nStep += crseStep)
  {
    if (verbose)
    {
      pout() << "starting step " << nStep << endl;
    }

    exactStep = nStep*crseMult;

    ostrstream exactFile;
    ostrstream computedFile;
    ostrstream errorFile;

    exactFile.fill('0');
    computedFile.fill('0');
    errorFile.fill('0');

    if (isTimeDep)
    {
      constructPlotFileName(exactFile, exactRoot, intFieldSize, exactStep);
      constructPlotFileName(computedFile, computedRoot, intFieldSize, nStep);
      constructPlotFileName(errorFile, errorRoot, intFieldSize, nStep);

    }
    else
    {
      // if not time dependent, file roots are really filenames
      exactFile << exactRoot << ends;
      computedFile << computedRoot << ends;
      errorFile << errorRoot << ends;
    }

    pout() << "exact Filename = " << exactFile.str() << endl;
    pout() << "computed Filename = " << computedFile.str() << endl;
    if (doPlots)
    {
      pout() << "error Filename = " << errorFile.str() << endl;
    }

    // declare memory
    Vector<LevelData<FArrayBox>* > exactSoln;
    Vector<string> exactVars; // exact solution variable names
    Vector<DisjointBoxLayout> exactGrids;
    Box exactDomain;
    Real exactDx, exactDt, exactTime;
    Vector<int> exactRefRatio;
    int exactNumLevels;
    IntVect ghostVect = IntVect::Unit;
    string exactFileName(exactFile.str());

    // get exact solution
    if (verbose)
    {
      pout() << "read exact solution..." << endl;
    }

    ReadAMRHierarchyHDF5(exactFileName,
                         exactGrids,
                         exactSoln,
                         exactVars,
                         exactDomain,
                         exactDx,
                         exactDt,
                         exactTime,
                         exactRefRatio,
                         exactNumLevels);

    if (verbose)
    {
      pout () << "done reading exact soln" << endl;
    }

    // we assume that exact soln is single-grid if we're doing averaging
    if (!isSameSize)
    {
      CH_assert(exactNumLevels == 1);
    }

    Vector<LevelData<FArrayBox>* > computedSoln;
    Vector<string> computedVars; // computed soln variable names
    Vector<DisjointBoxLayout> computedGrids;
    Box computedDomain;
    Real computedDx, computedDt, computedTime;
    Vector<int> computedRefRatio;
    int computedNumLevels;
    string computedFileName(computedFile.str());

    //ghostVect = IntVect::Zero;
    // now read in computed solution
    if (verbose)
    {
      pout() << "read computed solution..." << endl;
    }

    ReadAMRHierarchyHDF5(computedFileName,
                         computedGrids,
                         computedSoln,
                         computedVars,
                         computedDomain,
                         computedDx,
                         computedDt,
                         computedTime,
                         computedRefRatio,
                         computedNumLevels);

    if (verbose)
    {
      pout() << "done reading computed solution" << endl;
    }

    // reality check
    if ((computedDomain != exactDomain) && isSameSize)
    {
      MayDay::Error("Incompatible exact and computed domains for sameSize comparison");
    }

    int numExact    = exactVars.size();
    int numComputed = computedVars.size();

    int numError = errorVars.size();
    // If no errorVars were specified
    if (numError == 0)
    {
      // Set errorVars to the intersection of exactVars and computedVars
      // This numVars^2 method should be changed to something more efficient
      for (int iExact = 0; iExact < numExact; iExact++)
      {
        for (int iComp = 0; iComp < numComputed; iComp++)
        {
          if (exactVars[iExact] == computedVars[iComp])
          {
            errorVars.push_back(exactVars[iExact]);
            break;
          }
        }
      }

      numError = errorVars.size();
    }
    else
    {
      // if errorVars were specified, then do a quick check that
      // they're present in both exactVars and computedVars
      for (int errVarNo = 0; errVarNo<errorVars.size(); ++errVarNo)
        {
          bool foundComputed = false;
          for (int i=0; i<numComputed; i++)
            {
              if (errorVars[errVarNo] == computedVars[i])
                {
                  foundComputed = true;
                }
            } // end loop over exact variables
          if (!foundComputed)
            {
              pout() << "errorVar " << errorVars[errVarNo]
                     << " not found in computed solution!"
                     << endl;
              MayDay::Error();
            }

          bool foundExact = false;
          for (int i=0; i<numExact; i++)
            {
              if (errorVars[errVarNo] == exactVars[i])
                {
                  foundExact = true;
                }
            } // end loop over exact variables
          if (!foundExact)
            {
              pout() << "errorVar " << errorVars[errVarNo]
                     << " not found in exact solution!"
                     << endl;
              MayDay::Error();
            }

        } // end loop over errorVars
    } // end if errorVars was specified in the inputs file


    Vector<string> errorNames;
    errorNames.resize(numError);

    constructErrorNames(errorNames, errorVars);

    Vector<LevelData<FArrayBox>* > error(computedNumLevels);

    // allocate error -- same domain as computed solution
    for (int level = 0; level < computedNumLevels; level++)
    {
      error[level] = new LevelData<FArrayBox>(computedGrids[level],
                                              numError, ghostVect);
    }

    if (!isSameSize)
    {
      if (verbose)
      {
        pout () << "compute AMR error..." << endl;
      }

      computeAMRError(error,
                      errorVars,
                      computedSoln,
                      computedVars,
                      computedGrids,
                      computedDx,
                      computedRefRatio,
                      exactSoln,
                      exactVars,
                      exactDx,
                      bogusValue,
                      HOaverage,
                      computeRelativeError);

      if (verbose)
      {
        pout() << "done computing AMR error" << endl;
      }
    }
    else
    {
      // first make sure refRatios are the same
      for (int lev = 0; lev < computedRefRatio.size() - 1; lev++)
      {
        CH_assert(computedRefRatio[lev] == exactRefRatio[lev]);
      }

      CH_assert(exactDx == computedDx);

      if (verbose)
      {
        pout () << "compute sameSize error..." << endl;
      }

      computeSameSizeError(error,
                           errorVars,
                           computedSoln,
                           computedVars,
                           computedGrids,
                           computedDx,
                           computedRefRatio,
                           exactSoln,
                           exactVars,
                           bogusValue,
                           computeRelativeError,
                           doGhostCells);

      if (verbose)
      {
        pout() << "done computing sameSize error" << endl;
      }
    }

    Vector<Real> mean(numError);

    // remove mean
    if (removeMean)
    {
      int lBase = 0;
      int numLevels = error.size();

      for (int err = 0; err < numError; err++)
      {
        Interval errComps(err, err);

        if (verbose)
        {
          pout() << "compute mean for component " << err << endl;
        }

        Real volume;
        mean[err] = computeSum(volume,
                               error,
                               computedRefRatio,
                               computedDx,
                               errComps,
                               lBase);

        mean[err] /= volume;

        if (verbose)
        {
          pout() << "comp = "   << err
                 << ", mean = " << mean
                 << ", vol = "  << volume
                 << endl;
        }

        for (int level = 0; level < numLevels; level++)
        {
          LevelData<FArrayBox>& thisLevelError = *error[level];

          const DisjointBoxLayout levelGrids = error[level]->getBoxes();

          DataIterator dit = levelGrids.dataIterator();
          for (dit.reset(); dit.ok(); ++dit)
          {
            const Box thisBox = levelGrids[dit()];
            FArrayBox& thisFabError = thisLevelError[dit()];

            thisFabError.plus(-mean[err],err);
          } // end loop over errors

          thisLevelError.exchange();
        } // end loop over levels
      } // end loop over errors
    }

    // now compute norms

    pout() << "error, step " << nStep << ": L1, L2, Max, sum" << endl;
    for (int err = 0; err < numError; err++)
    {
      Interval errComps(err, err);
      Real L0, L1, L2, sum;

      if (verbose)
      {
        pout() << "compute error for component " << err << endl;
      }

      int lBase = 0;
      int normType = 0;
      Real normDx = computedDx;
      if (useUnitDomain)
        {
          normDx = 1.0/computedDomain.size(0);
        }
      L0 = computeNorm(error,
                       computedRefRatio,
                       normDx,
                       errComps,
                       normType,
                       lBase);

      normType = 1;
      L1 = computeNorm(error,
                       computedRefRatio,
                       normDx,
                       errComps,
                       normType,
                       lBase);

      normType = 2;
      L2 = computeNorm(error,
                       computedRefRatio,
                       normDx,
                       errComps,
                       normType,
                       lBase);
      
      sum = computeSum(error,
                       computedRefRatio,
                       normDx,
                       errComps,
                       lBase);


      pout() << errorNames[err] << ": "
             << L1 << ", "
             << L2 << ", "
             << L0 << ", "
             << sum;

      if (removeMean)
      {
        pout() << " (" << mean[err] << ")";
      }

      pout() << endl;
    } // end loop over errors

    if (doPlots)
    {
      if (verbose)
      {
        pout() << "begin writing hdf5 file..." << endl;
      }

      WriteAMRHierarchyHDF5(errorFile.str(),
                            computedGrids,
                            error,
                            errorNames,
                            computedDomain,
                            computedDx,
                            computedDt,
                            computedTime,
                            computedRefRatio,
                            computedNumLevels);

      if (verbose)
      {
        pout() << "done writing hdf5 file" << endl;
      }
    }

    // clean up memory
    for (int level = 0; level < exactNumLevels; level++)
    {
      if (exactSoln[level] != NULL)
      {
        delete exactSoln[level];
        exactSoln[level] = NULL;
      }
    }

    for (int level = 0; level < computedNumLevels; level++)
    {
      if (computedSoln[level] != NULL)
      {
        delete computedSoln[level];
        computedSoln[level] = NULL;
      }

      if (error[level] != NULL)
      {
        delete error[level];
        error[level] = NULL;
      }
    }
  } // end loop over timesteps

#ifdef CH_MPI
  dumpmemoryatexit();
  MPI_Finalize();
#endif
} // end main
Example #11
0
// this function averages down the fine solution to the valid
// regions of the computed solution, then subtracts ir from
// the computed solution.  (error is exact-computed)
void computeAMRError(Vector<LevelData<FArrayBox>* >&       a_error,
                     const Vector<string>&                 a_errorVars,
                     const Vector<LevelData<FArrayBox>* >& a_computedSoln,
                     const Vector<string>&                 a_computedVars,
                     const Vector<DisjointBoxLayout>&      a_computedGrids,
                     const Real                            a_computedDx,
                     const Vector<int>&                    a_computedRefRatio,
                     const Vector<LevelData<FArrayBox>* >& a_exactSoln,
                     const Vector<string>&                 a_exactVars,
                     const Real                            a_exactDx,
                     Real                                  a_bogus_value,
                     bool                                  a_HOaverage,
                     bool                                  a_computeRelativeError)
{
  int numLevels = a_computedSoln.size();

  CH_assert(a_exactSoln.size() == 1);
  CH_assert(a_error.size() == numLevels);
  CH_assert(a_exactDx <= a_computedDx);
  CH_assert(a_computedRefRatio.size() >= numLevels - 1);

  if (a_exactDx == a_computedDx)
  {
    cerr << "Exact dx and computed dx are equal." << endl;
  }

  // check whether input file selects "sum all variables"
  bool sumAll = false;
  ParmParse pp;
  pp.query("sumAll",sumAll);
  
  // const DisjointBoxLayout& exactGrids = a_exactSoln[0]->getBoxes();

  Real dxLevel = a_computedDx;

  // do a bit of sleight-of-hand in the case where there are no
  // ghost cells in the exact solution -- allocate a temporary which
  // _has_ ghost cells, and do a copyTo
  LevelData<FArrayBox>* exactSolnPtr = NULL;
  bool allocatedMemory = false;
  if (a_exactSoln[0]->ghostVect() == IntVect::Zero)
    {
      exactSolnPtr = new LevelData<FArrayBox>(a_exactSoln[0]->getBoxes(),
                                              a_exactSoln[0]->nComp(),
                                              IntVect::Unit);
      a_exactSoln[0]->copyTo(*exactSolnPtr);

      allocatedMemory = true;
     }
   else
     {
       // if there are ghost cells, we can use the exactSoln as-is
       exactSolnPtr = a_exactSoln[0];
     }
   LevelData<FArrayBox>& exactSolnRef = *exactSolnPtr;

   // first need to set boundary conditions on exactsoln
   // this is for the Laplacian which is needed in AverageHO
   DataIterator ditFine = exactSolnRef.dataIterator();
   DomainGhostBC exactBC;
   Interval exactComps(0, a_exactVars.size() - 1);
   for (int dir = 0; dir < SpaceDim; dir++)
   {
     SideIterator sit;
     for (sit.reset(); sit.ok(); ++sit)
     {
       // use HO extrapolation at physical boundaries
       HOExtrapBC thisBC(dir, sit(), exactComps);
       exactBC.setBoxGhostBC(thisBC);
     }
   }

   for (ditFine.begin(); ditFine.ok(); ++ditFine)
   {
     FArrayBox& thisFineSoln = exactSolnRef[ditFine()];
     const Box& fineBox = exactSolnRef.getBoxes()[ditFine()];
     exactBC.applyInhomogeneousBCs(thisFineSoln, fineBox, a_exactDx);
   }
   exactSolnRef.exchange(exactComps);

   // outer loop is over levels
   for (int level = 0; level < numLevels; level++)
   {
     LevelData<FArrayBox>& thisLevelError = *a_error[level];
     LevelData<FArrayBox>& thisLevelComputed = *a_computedSoln[level];

     // compute refinement ratio between solution at this level
     // and exact solution
     Real nRefTemp = (dxLevel / a_exactDx);
     int nRefExact = (int) nRefTemp;

     // this is to do rounding properly if necessary
     if (nRefTemp - nRefExact > 0.5) nRefExact += 1;

     // make sure it's not zero
     if (nRefExact == 0) nRefExact =1;

     const DisjointBoxLayout levelGrids = a_error[level]->getBoxes();
     const DisjointBoxLayout fineGrids = a_exactSoln[0]->getBoxes();
     DisjointBoxLayout coarsenedFineGrids;

     // petermc, 14 Jan 2014: Replace this because fineGrids might
     // not be coarsenable by nRefExact.
     // coarsen(coarsenedFineGrids, fineGrids, nRefExact);
     int nCoarsenExact = nRefExact;
     while ( !fineGrids.coarsenable(nCoarsenExact) && (nCoarsenExact > 0) )
       {
         // Divide nCoarsenExact by 2 until fineGrids is coarsenable by it.
         nCoarsenExact /= 2;
       }
     if (nCoarsenExact == 0)
       {
         nCoarsenExact = 1;
       }
     coarsen(coarsenedFineGrids, fineGrids, nCoarsenExact);

     int numExact = a_exactVars.size();
     LevelData<FArrayBox> averagedExact(coarsenedFineGrids, numExact);

     Box fineRefBox(IntVect::Zero, (nCoarsenExact-1)*IntVect::Unit);

     // average fine solution down to coarsened-fine level
     // loop over grids and do HO averaging down
     //DataIterator crseExactDit = coarsenedFineGrids.dataIterator();
     for (ditFine.reset(); ditFine.ok(); ++ditFine)
       {
         const Box fineBox = exactSolnRef.getBoxes()[ditFine()];
         FArrayBox fineTemp(fineBox, 1);
         Box coarsenedFineBox(fineBox);
         coarsenedFineBox.coarsen(nCoarsenExact);
         if (a_exactDx < a_computedDx)
           {
             // loop over components
             for (int comp = 0; comp < numExact; comp++)
               {
                 Box coarseBox(coarsenedFineGrids.get(ditFine()));
                 coarseBox &= coarsenedFineBox;
                 
                 if (!coarseBox.isEmpty())
                   {
                     // for now, this is a quick and dirty way to avoid
                     // stepping out of bounds if there are no ghost cells.
                     // LapBox will be the box over which we are
                     // able to compute the Laplacian.
                     Box LapBox = exactSolnRef[ditFine()].box();
                     LapBox.grow(-1);
                     LapBox &= fineBox;
                     fineTemp.setVal(0.0);
                     int doHO = 0;
                     if (a_HOaverage)
                       { 
                         doHO = 1;
                       }
                     
                     // average by default
                     int doAverage = 1;
                     
                     if (sumAll || sumVar(a_exactVars[comp]))
                       {
                         doAverage = 0;
                       }
                     
                     // average or sum, based on booleans
                     FORT_AVERAGEHO(CHF_FRA1(averagedExact[ditFine], comp),
                                    CHF_CONST_FRA1(exactSolnRef[ditFine], comp),
                                    CHF_FRA1(fineTemp, 0),
                                    CHF_BOX(coarseBox),
                                    CHF_BOX(LapBox),
                                    CHF_CONST_INT(nCoarsenExact),
                                    CHF_BOX(fineRefBox),
                                    CHF_INT(doHO),
                                    CHF_INT(doAverage));
                   } // end if crseBox not empty
               } // end loop over comps
           }
         else
           {
             // if cell sizes are the same, then copy
             averagedExact[ditFine].copy(exactSolnRef[ditFine]);
           }
         
       } // end loop over exact solution boxes
     
     int nRefineComputed = nRefExact / nCoarsenExact;
     LevelData<FArrayBox>* thisLevelComputedRefinedPtr = &thisLevelComputed;
     LevelData<FArrayBox>* thisLevelErrorRefinedPtr = &thisLevelError;
     if (nRefineComputed > 1)
       {
         // Do piecewise constant interpolation (replication) by nRefineComputed
         // on thisLevelComputed.
         DisjointBoxLayout levelRefinedGrids;
         refine(levelRefinedGrids, levelGrids, nRefineComputed);
         int nCompComputed = thisLevelComputed.nComp();
         IntVect ghostVectComputed = nRefineComputed * thisLevelComputed.ghostVect();
         thisLevelComputedRefinedPtr =
           new LevelData<FArrayBox>(levelRefinedGrids, nCompComputed, ghostVectComputed);
         ProblemDomain levelDomain = levelRefinedGrids.physDomain();
         FineInterp interpolator(levelRefinedGrids, nCompComputed, nRefineComputed,
                                 levelDomain);
         interpolator.pwcinterpToFine(*thisLevelComputedRefinedPtr, thisLevelComputed);

         int nCompErr = thisLevelError.nComp();
         IntVect ghostVectErr = nRefineComputed * thisLevelError.ghostVect();
         thisLevelErrorRefinedPtr =
           new LevelData<FArrayBox>(levelRefinedGrids, nCompErr, ghostVectErr);
       }

     // initialize error to 0
     // also initialize error to a bogus value
     DataIterator levelDit = thisLevelError.dataIterator();
     for (levelDit.begin(); levelDit.ok(); ++levelDit)
       {
         (*thisLevelErrorRefinedPtr)[levelDit].setVal(a_bogus_value);
       }

     Box refComputedBox(IntVect::Zero, (nRefineComputed-1)*IntVect::Unit);
     // loop over variables
     for (int nErr = 0; nErr < a_errorVars.size(); nErr++)
       {
         string thisErrVar = a_errorVars[nErr];
         bool done = false;

         // first loop over exact variables
         for (int exactComp = 0; exactComp < a_exactVars.size(); exactComp++)
           {
             string thisExactVar = a_exactVars[exactComp];
             // check if this exact variable is "the one"
             if ((thisExactVar == thisErrVar) || nonAverageVar(thisErrVar))
               {
                 int computedComp = 0;
                 // now loop over computed variables
                 while (!done && (computedComp < a_computedVars.size()))
                   {
                     if (a_computedVars[computedComp] == thisErrVar)
                       {
                         if (!nonAverageVar(thisErrVar))
                           {
                             // copy averaged exact solution -> error
                             // and then subtract computed solution
                             Interval exactInterval(exactComp, exactComp);
                             Interval errorInterval(nErr, nErr);
                             averagedExact.copyTo(exactInterval, *thisLevelErrorRefinedPtr,
                                                  errorInterval);
                           }
                         
                         DataIterator levelDit = thisLevelError.dataIterator();
                         for (levelDit.reset(); levelDit.ok(); ++levelDit)
                           {
                             FArrayBox& thisComputedRefined = (*thisLevelComputedRefinedPtr)[levelDit];
                             FArrayBox& thisErrorRefined = (*thisLevelErrorRefinedPtr)[levelDit];
                             if (a_computeRelativeError)
                               {
                                 // do this a little strangely -- relative
                                 // error is one - computed/exact.
                                 thisErrorRefined.divide(thisComputedRefined, computedComp, nErr, 1);
                                 thisErrorRefined.invert(-1.0, nErr, 1);
                                 thisErrorRefined.plus(1.0, nErr, 1);
                               }
                             else
                               {
                                 thisErrorRefined.minus(thisComputedRefined, computedComp, nErr, 1);
                               }
                             if (nRefineComputed > 1)
                               {
                                 FArrayBox& thisError = thisLevelError[levelDit];
                                 Box coarseBox = thisError.box();
                                 // Average thisErrorRefined to thisError.
                                 int doHO = 0;
                                 if (a_HOaverage)
                                   { 
                                     doHO = 1;
                                   }
                                 CH_assert(doHO == 0);

                                 // for now, this is a quick and dirty way to avoid
                                 // stepping out of bounds if there are no ghost cells.
                                 // LapBox will be the box over which we are
                                 // able to compute the Laplacian.
                                 Box LapBox = thisErrorRefined.box();
                                 LapBox.grow(-1);
                                 // LapBox &= fineBox;
                                 FArrayBox fineTemp(thisErrorRefined.box(), 1);
                                 fineTemp.setVal(0.0);
                                 
                                 // average by default
                                 int doAverage = 1;
                                 // average or sum, based on booleans
                                 FORT_AVERAGEHO(CHF_FRA1(thisError, nErr),
                                                CHF_CONST_FRA1(thisErrorRefined, nErr),
                                                CHF_FRA1(fineTemp, 0),
                                                CHF_BOX(coarseBox),
                                                CHF_BOX(LapBox),
                                                CHF_CONST_INT(nRefineComputed),
                                                CHF_BOX(refComputedBox),
                                                CHF_INT(doHO),
                                                CHF_INT(doAverage));
                                 
                               }
                           } // end loop over coarse grids
                         
                         done = true;
                       } // if computedVar is a_errorVar
                     
                     computedComp += 1;
                   } // end loop over a_computedVars
                 
                 if (!done)
                   {
                     pout() << "Variable " << thisErrVar  << " not found!!!" << endl;
                     MayDay::Error();
                   }
               } // end if this exactVar is correct
           } // end loop over exact variables
       } // end loop over errors
     
     if (nRefineComputed > 1)
       {
         delete thisLevelComputedRefinedPtr;
         delete thisLevelErrorRefinedPtr;
       }
     
     // now need to set covered regions to 0
     if (level < numLevels - 1)
       {
         // will need to loop over all boxes in finer level, not just
         // those on this processor...
         const BoxLayout& finerGrids = a_computedSoln[level + 1]->boxLayout();
         LayoutIterator fineLit = finerGrids.layoutIterator();
         
         // outer loop over this level's grids, since there are fewer of them
         DataIterator levelDit = thisLevelError.dataIterator();
         for (levelDit.reset(); levelDit.ok(); ++levelDit)
           {
             const Box& coarseBox = levelGrids[levelDit()];
             FArrayBox& thisError = thisLevelError[levelDit()];
             int numError = thisError.nComp();
             
             for (fineLit.reset(); fineLit.ok(); ++fineLit)
               {
                 Box fineBox(finerGrids[fineLit()]);
                 // now coarsen box down to this level
                 fineBox.coarsen(a_computedRefRatio[level]);
                 // if coarsened fine box intersects error's box, set
                 // overlap to 0
                 fineBox &= coarseBox;
                 if (!fineBox.isEmpty())
                   {
                     thisError.setVal(0.0, fineBox, 0, numError);
                   }
               } // end loop over finer-level grids
           } // end loop over this-level grids
         
         // this is a good place to update dx as well
         dxLevel = dxLevel / a_computedRefRatio[level];
       } // end if there is a finer level
     
     thisLevelError.exchange();
   } // end loop over levels
   
   // clean up if we need to
   if (allocatedMemory)
     {
       delete exactSolnPtr;
       exactSolnPtr = NULL;
     }
}
void
CartCellDoubleBoundsPreservingConservativeLinearRefine::refine(Patch<NDIM>& fine,
                                                               const Patch<NDIM>& coarse,
                                                               const int dst_component,
                                                               const int src_component,
                                                               const Box<NDIM>& fine_box,
                                                               const IntVector<NDIM>& ratio)
    const
{
    // Determine the box over which we can apply the bounds-preserving
    // correction, and construct a list of boxes that will not be corrected.
    bool empty_correction_box = false;
    Box<NDIM> correction_box = Box<NDIM>::refine(Box<NDIM>::coarsen(fine_box, ratio), ratio);
    for (unsigned int axis = 0; axis < NDIM; ++axis)
    {
        int& lower = correction_box.lower()(axis);
        while (lower < fine_box.lower()(axis))
        {
            lower += ratio(axis);
        }

        int& upper = correction_box.upper()(axis);
        while (upper > fine_box.upper()(axis))
        {
            upper -= ratio(axis);
        }

        if (lower >= upper)
        {
            empty_correction_box = true;
        }
    }
    const Box<NDIM> coarse_correction_box = Box<NDIM>::coarsen(correction_box, ratio);

    BoxList<NDIM> uncorrected_boxes(fine_box);
    if (!empty_correction_box)
    {
        uncorrected_boxes.removeIntersections(correction_box);
    }

    // Employ limited conservative interpolation to prolong data on the
    // correction box.
    d_conservative_linear_refine_op.refine(
        fine, coarse, dst_component, src_component, correction_box, ratio);

    // Employ constant interpolation to prolong data on the rest of the fine
    // box.
    for (BoxList<NDIM>::Iterator b(uncorrected_boxes); b; b++)
    {
        d_constant_refine_op.refine(fine, coarse, dst_component, src_component, b(), ratio);
    }

    // There is nothing left to do if the correction box is empty.
    if (empty_correction_box) return;

    // Correct the data within the correction box.
    Pointer<CellData<NDIM, double> > fdata = fine.getPatchData(dst_component);
    Pointer<CellData<NDIM, double> > cdata = coarse.getPatchData(src_component);
#if !defined(NDEBUG)
    TBOX_ASSERT(fdata);
    TBOX_ASSERT(cdata);
    TBOX_ASSERT(fdata->getDepth() == cdata->getDepth());
#endif
    const int data_depth = fdata->getDepth();
    const Box<NDIM>& patch_box_crse = coarse.getBox();
    const Index<NDIM>& patch_lower_crse = patch_box_crse.lower();
    const Index<NDIM>& patch_upper_crse = patch_box_crse.upper();
    Pointer<CartesianPatchGeometry<NDIM> > pgeom_crse = coarse.getPatchGeometry();
    for (int depth = 0; depth < data_depth; ++depth)
    {
        for (Box<NDIM>::Iterator b(coarse_correction_box); b; b++)
        {
            const Index<NDIM>& i_crse = b();
            const Index<NDIM> i_fine = i_crse * ratio;

            // Determine the lower/upper bounds.
            Box<NDIM> stencil_box_crse(i_crse, i_crse);
            for (unsigned int axis = 0; axis < NDIM; ++axis)
            {
                if (i_crse(axis) > patch_lower_crse(axis) ||
                    !pgeom_crse->getTouchesRegularBoundary(axis, 0))
                {
                    stencil_box_crse.growLower(axis, 1);
                }
                if (i_crse(axis) < patch_upper_crse(axis) ||
                    !pgeom_crse->getTouchesRegularBoundary(axis, 1))
                {
                    stencil_box_crse.growUpper(axis, 1);
                }
            }

            double l = std::numeric_limits<double>::max();
            double u = -(l - std::numeric_limits<double>::epsilon());
            for (Box<NDIM>::Iterator b(stencil_box_crse); b; b++)
            {
                const double& m = (*cdata)(b(), depth);
                l = std::min(l, m);
                u = std::max(u, m);
            }

            // Force all refined data to lie within the bounds, accumulating the
            // discrepancy.
            Box<NDIM> stencil_box_fine(i_fine, i_fine);
            stencil_box_fine.growUpper(ratio - IntVector<NDIM>(1));
            double Delta = 0.0;
            for (Box<NDIM>::Iterator b(stencil_box_fine); b; b++)
            {
                double& m = (*fdata)(b(), depth);
                Delta += std::max(0.0, m - u) - std::max(0.0, l - m);
                m = std::max(std::min(m, u), l);
            }

            // Distribute the discrepancy to maintain conservation.
            if (Delta >= std::numeric_limits<double>::epsilon())
            {
                double K = 0.0;
                for (Box<NDIM>::Iterator b(stencil_box_fine); b; b++)
                {
                    const double& m = (*fdata)(b(), depth);
                    double k = u - m;
                    K += k;
                }
                for (Box<NDIM>::Iterator b(stencil_box_fine); b; b++)
                {
                    double& m = (*fdata)(b(), depth);
                    double k = u - m;
                    m += Delta * k / K;
                }
            }
            else if (Delta <= -std::numeric_limits<double>::epsilon())
            {
                double K = 0.0;
                for (Box<NDIM>::Iterator b(stencil_box_fine); b; b++)
                {
                    const double& m = (*fdata)(b(), depth);
                    double k = m - l;
                    K += k;
                }
                for (Box<NDIM>::Iterator b(stencil_box_fine); b; b++)
                {
                    double& m = (*fdata)(b(), depth);
                    double k = m - l;
                    m += Delta * k / K;
                }
            }
        }
    }
    return;
} // refine
Example #13
0
DTboolean     PrimitiveCollisions::ray_intersect_box (  const Vector3 &from, const Vector3 &direction,
                                                        const Box &b, DTfloat &t)
{
    DTfloat tmin = -std::numeric_limits<DTfloat>::infinity();
    DTfloat tmax = std::numeric_limits<DTfloat>::infinity();
    
    DTfloat t1,t2;
    
    // X axis
    if (direction.x > EPSILON || direction.x < -EPSILON) {
        DTfloat direction_inverse = 1.0F / direction.x;
        t1 = (b.minus_x() - from.x) * direction_inverse;
        t2 = (b.plus_x() - from.x) * direction_inverse;
        
        tmin = MoreMath::min(tmin,t1,t2);
        tmax = MoreMath::max(tmin,t1,t2);
        
        if (tmin > tmax)    return false;
        if (tmax < 0.0F)    return false;
    } else if (from.x < b.minus_x() || from.x > b.plus_x()) {
        return false;
    }   
    
    // Y axis
    if (direction.y > EPSILON || direction.y < -EPSILON) {
        DTfloat direction_inverse = 1.0F / direction.y;
        t1 = (b.minus_y() - from.y) * direction_inverse;
        t2 = (b.plus_y() - from.y) * direction_inverse;
        
        tmin = MoreMath::min(tmin,t1,t2);
        tmax = MoreMath::max(tmin,t1,t2);
        
        if (tmin > tmax)    return false;
        if (tmax < 0.0F)    return false;
    } else if (from.y < b.minus_y() || from.y > b.plus_y()) {
        return false;
    }
    
    // Z axis
    if (direction.z > EPSILON || direction.z < -EPSILON) {
        DTfloat direction_inverse = 1.0F / direction.z;
        t1 = (b.minus_z() - from.z) * direction_inverse;
        t2 = (b.plus_z() - from.z) * direction_inverse;
        
        tmin = MoreMath::min(tmin,t1,t2);
        tmax = MoreMath::max(tmin,t1,t2);
        
        if (tmin > tmax)    return false;
        if (tmax < 0.0F)    return false;
    } else if (from.z < b.minus_z() || from.z > b.plus_z()) {
        return false;
    }
    
    if (tmin <= tmax) {
        t = tmin;
        return true;
    }

    return false;
}
Example #14
0
// Set boundary fluxes
void VelIBC::primBC(FArrayBox&            a_WGdnv,
                    const FArrayBox&      a_Wextrap,
                    const FArrayBox&      a_W,
                    const int&            a_dir,
                    const Side::LoHiSide& a_side,
                    const Real&           a_time)
{
  CH_assert(m_isDefined == true);

  // In periodic case, this doesn't do anything
  if (!m_domain.isPeriodic(a_dir))
    {
      // This needs to be fixed
      // CH_assert(m_isBCvalSet);

      int lohisign;
      Box tmp = a_WGdnv.box() & m_domain;
      Real bcVal;

      // Determine which side and thus shifting directions
      if (a_side == Side::Lo)
        {
          lohisign = -1;
          bcVal = m_bcVal[a_dir][0];
        }
      else
        {
          lohisign = 1;
          bcVal = m_bcVal[a_dir][1];
        }

      tmp.shiftHalf(a_dir,lohisign);

      // Is there a domain boundary next to this grid
      if (!m_domain.contains(tmp))
        {
          tmp &= m_domain;

          Box boundaryBox;

          // Find the strip of cells next to the domain boundary
          if (a_side == Side::Lo)
            {
              boundaryBox = bdryLo(tmp,a_dir);
            }
          else
            {
              boundaryBox = bdryHi(tmp,a_dir);
            }

          // Set the boundary fluxes
          FORT_SOLIDVELBCF(CHF_FRA(a_WGdnv),
                           CHF_CONST_FRA(a_Wextrap),
                           CHF_CONST_REAL(bcVal),
                           CHF_CONST_INT(lohisign),
                           CHF_CONST_REAL(m_dx),
                           CHF_CONST_INT(a_dir),
                           CHF_BOX(boundaryBox));
        }
    }
}
// calculate the centroid of a box
KOKKOS_INLINE_FUNCTION
void centroid( Box const &box, Point &c )
{
    for ( int d = 0; d < 3; ++d )
        c[d] = 0.5 * ( box.minCorner()[d] + box.maxCorner()[d] );
}
Example #16
0
bool can_stack(const Box& b, const Tower& t){
  return b.compare(*(t.begin())) == '>';
}
KOKKOS_INLINE_FUNCTION
bool equals( Box const &l, Box const &r )
{
    return equals( l.minCorner(), r.minCorner() ) &&
           equals( l.maxCorner(), r.maxCorner() );
}
Example #18
0
Box::Box( Box const& rhs ) : Primitive( rhs ), min( rhs.getMin() ), max( rhs.getMax() ) {}
Example #19
0
    Box operator()(Box data)
    {
        typedef typename Box::ValueType ValueType;

        Box dstBox = Box(PitchedBox<ValueType, DIM2 > (
                                                       (ValueType*) filteredData,
                                                       Space(),
                                                       header.simSize,
                                                       header.simSize.x() * sizeof (ValueType)
                                                       ));
        MessageHeader mHeader;
        MessageHeader* fakeHeader = &mHeader;
        memcpy(fakeHeader, &header, MessageHeader::bytes);

        char* recvHeader = new char[ MessageHeader::bytes * numRanks];

        if (fullData == NULL && mpiRank == 0)
            fullData = (char*) new ValueType[header.nodeSize.productOfComponents() * numRanks];


        MPI_CHECK(MPI_Gather(fakeHeader, MessageHeader::bytes, MPI_CHAR, recvHeader, MessageHeader::bytes,
                             MPI_CHAR, 0, comm));

        const size_t elementsCount = header.nodeSize.productOfComponents() * sizeof (ValueType);

        MPI_CHECK(MPI_Gather(
                             (char*) (data.getPointer()), elementsCount, MPI_CHAR,
                             fullData, elementsCount, MPI_CHAR,
                             0, comm));



        if (mpiRank == 0)
        {
            if (filteredData == NULL)
                filteredData = (char*) new ValueType[header.simSize.productOfComponents()];

            /*create box with valid memory*/
            dstBox = Box(PitchedBox<ValueType, DIM2 > (
                                                       (ValueType*) filteredData,
                                                       Space(),
                                                       header.simSize,
                                                       header.simSize.x() * sizeof (ValueType)
                                                       ));


            for (int i = 0; i < numRanks; ++i)
            {
                MessageHeader* head = (MessageHeader*) (recvHeader + MessageHeader::bytes * i);
                Box srcBox = Box(PitchedBox<ValueType, DIM2 > (
                                                               (ValueType*) fullData,
                                                               Space(0, head->nodeSize.y() * i),
                                                               head->nodeSize,
                                                               head->nodeSize.x() * sizeof (ValueType)
                                                               ));

                insertData(dstBox, srcBox, head->nodeOffset, head->nodePictureSize, head->nodeGuardCells);
            }

        }

        delete[] recvHeader;

        return dstBox;
    }
Example #20
0
__host__ void parseShape(const std::smatch& matches, Box& shape)
{
	shape.setPosition(ParseUtils::parseVec3(matches[3].str()));
	shape.setRotation(glm::quat(ParseUtils::parseVec3(matches[4].str())));
	shape.setSize(ParseUtils::parseVec3(matches[5].str()));
}
Example #21
0
  Meshing2OCCSurfaces :: Meshing2OCCSurfaces (const TopoDS_Shape & asurf,
					      const Box<3> & abb, int aprojecttype)
    : Meshing2(Box<3>(abb.PMin(), abb.PMax())), surface(TopoDS::Face(asurf), aprojecttype)
  {
    ;
  }
Example #22
0
void
sphereGeometry(Box& a_coarsestDomain,
               Real& a_dx)
{
    ParmParse ppgodunov;
    //parse input file
    int max_level = 0;
    ppgodunov.get("max_level",max_level);

    int num_read_levels = Max(max_level,1);
    std::vector<int> refRatios; // (num_read_levels,1);
    // note this requires a refRatio to be defined for the
    // finest level (even though it will never be used)

    ppgodunov.getarr("ref_ratio",refRatios,0,num_read_levels+1);
    ParmParse pp;
    RealVect origin = RealVect::Zero;
    Vector<int> n_cell(SpaceDim);
    pp.getarr("n_cell",n_cell,0,SpaceDim);

    CH_assert(n_cell.size() == SpaceDim);
    IntVect lo = IntVect::Zero;
    IntVect hi;
    for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
        if (n_cell[ivec] <= 0)
        {
            pout() << " bogus number of cells input = " << n_cell[ivec];
            MayDay::Error();
        }
        hi[ivec] = n_cell[ivec] - 1;
    }

    a_coarsestDomain = Box(lo, hi);
    Box finestDomain = a_coarsestDomain;
    for (int ilev = 0; ilev < max_level; ilev++)
    {
        finestDomain.refine(refRatios[ilev]);
    }

    Real prob_hi;
    int numOpen = n_cell[0];
    pp.get("domain_length",prob_hi);
    a_dx = prob_hi/numOpen;
    Real fineDx = a_dx;
    int ebMaxCoarsen = 2;
    for (int ilev = 0; ilev < max_level; ilev++)
    {
        fineDx /= refRatios[ilev];
        ebMaxCoarsen += refRatios[ilev]/2;
    }
    int ebMaxSize;
    ppgodunov.get("max_grid_size", ebMaxSize);
    EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
    pout() << "sphere geometry" << endl;
    vector<Real> sphere_center(SpaceDim);
    pp.getarr("sphere_center",sphere_center, 0, SpaceDim);
    RealVect sphereCenter;
    for (int idir = 0; idir < SpaceDim; idir++)
    {
        sphereCenter[idir] = sphere_center[idir];
    }
    Real sphereRadius;
    pp.get("sphere_radius", sphereRadius);
    int inside_fluid;
    pp.get("sphere_fluid_inside", inside_fluid);
    bool insideFluid = (inside_fluid==1);
    SphereIF sphereIF(sphereRadius, sphereCenter, insideFluid);
    RealVect vectFineDx(D_DECL(fineDx,fineDx,fineDx));
    GeometryShop workshop(sphereIF,0,vectFineDx);
    //this generates the new EBIS
    ebisPtr->define(finestDomain, origin, fineDx, workshop, ebMaxSize, ebMaxCoarsen);
}
// 	Shape* s2 = new Sphere(position, 1.2, "sphere1", red);

// 	s1->print(std::cout);
// 	std::cout << "\n";
// 	s2->print(std::cout);

// 	delete s1;
// 	delete s2;
// }


//7
TEST_CASE("box_intersect", "[intersect_box]"){
	glm::vec3 vec1{0.0f,0.0f,0.0f};
	glm::vec3 vec2{1.0f,1.0f,1.0f};
	Box b1{vec1, vec2};

	glm::vec3 origin(-1.0,0.0,0.0);
	glm::vec3 direction(1.0,0.5,0.0);
	Ray r{origin, direction};
	float distance(0.0);
	REQUIRE(b1.intersect(r, distance));
	std::cout <<"\n" << distance << std::endl;
}
TEST_CASE("box_intersect2", "[intersect_box2]"){
	glm::vec3 vec1{0.0f,0.0f,0.0f};
	glm::vec3 vec2{1.0f,1.0f,1.0f};
	Box b1{vec1, vec2};

	glm::vec3 origin(12.0,0.5,0.5);
	glm::vec3 direction(1.0,0.0,0.0);
Example #24
0
 void set_box(const Box& b)
 {
   set_min_corner(b.min_corner());
   set_max_corner(b.max_corner());
 }
Example #25
0
void draw()
{
	// Rotate box and position (and the spheres will orbitate around it)
	box.rotateY( angle );
}
Example #26
0
void GameplayScreen::onEntry() {

    b2Vec2 gravity(0.0f, -25.0);
    m_world = std::make_unique<b2World>(gravity);

    m_debugRenderer.init();

    // Make the ground
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0.0f, -20.0f);
    b2Body* groundBody = m_world->CreateBody(&groundBodyDef);
    // Make the ground fixture
    b2PolygonShape groundBox;
    groundBox.SetAsBox(50.0f, 10.0f);
    groundBody->CreateFixture(&groundBox, 0.0f);

    // Load the texture
    m_texture = Bengine::ResourceManager::getTexture("Assets/bricks_top.png");

    // Make a bunch of boxes
    std::mt19937 randGenerator;
    std::uniform_real_distribution<float> xPos(-10.0, 10.0f);
    std::uniform_real_distribution<float> yPos(-10.0, 25.0f);
    std::uniform_real_distribution<float> size(0.5, 2.5f);
    std::uniform_int_distribution<int> color(50, 255);
    const int NUM_BOXES = 10;

    for (int i = 0; i < NUM_BOXES; i++) {
        Bengine::ColorRGBA8 randColor;
        randColor.r = color(randGenerator);
        randColor.g = color(randGenerator);
        randColor.b = color(randGenerator);
        randColor.a = 255;
        Box newBox;
        newBox.init(m_world.get(), glm::vec2(xPos(randGenerator), yPos(randGenerator)), glm::vec2(size(randGenerator), size(randGenerator)), m_texture, randColor, false);
        m_boxes.push_back(newBox);
    }

    // Initialize spritebatch
    m_spriteBatch.init();

    // Shader init
    // Compile our texture
    m_textureProgram.compileShaders("Shaders/textureShading.vert", "Shaders/textureShading.frag");
    m_textureProgram.addAttribute("vertexPosition");
    m_textureProgram.addAttribute("vertexColor");
    m_textureProgram.addAttribute("vertexUV");
    m_textureProgram.linkShaders();
    // Compile our light shader
    m_lightProgram.compileShaders("Shaders/lightShading.vert", "Shaders/lightShading.frag");
    m_lightProgram.addAttribute("vertexPosition");
    m_lightProgram.addAttribute("vertexColor");
    m_lightProgram.addAttribute("vertexUV");
    m_lightProgram.linkShaders();

    // Init camera
    m_camera.init(m_window->getScreenWidth(), m_window->getScreenHeight());
    m_camera.setScale(32.0f);

    // Init player
    m_player.init(m_world.get(), glm::vec2(0.0f, 30.0f), glm::vec2(2.0f), glm::vec2(1.0f, 1.8f), Bengine::ColorRGBA8(255, 255, 255, 255));

    // Init the UI
    m_gui.init("GUI");
    m_gui.loadScheme("TaharezLook.scheme");
    m_gui.setFont("DejaVuSans-10");
    CEGUI::PushButton* testButton = static_cast<CEGUI::PushButton*>(m_gui.createWidget("TaharezLook/Button", glm::vec4(0.5f, 0.5f, 0.1f, 0.05f), glm::vec4(0.0f), "TestButton"));
    testButton->setText("Hello World!");

    CEGUI::Combobox* TestCombobox = static_cast<CEGUI::Combobox*>(m_gui.createWidget("TaharezLook/Combobox", glm::vec4(0.2f, 0.2f, 0.1f, 0.05f), glm::vec4(0.0f), "TestCombobox"));

    m_gui.setMouseCursor("TaharezLook/MouseArrow");
    m_gui.showMouseCursor();
    SDL_ShowCursor(0);
}
void
LevelFluxRegisterEdge::incrementFine(
                                     FArrayBox& a_fineFlux,
                                     Real a_scale,
                                     const DataIndex& a_fineDataIndex,
                                     const Interval& a_srcInterval,
                                     const Interval& a_dstInterval,
                                     int a_dir,
                                     Side::LoHiSide a_sd)
{
  CH_assert(isDefined());
  CH_assert(!a_fineFlux.box().isEmpty());
  CH_assert(a_srcInterval.size() == a_dstInterval.size());
  CH_assert(a_srcInterval.begin() >= 0);
  CH_assert(a_srcInterval.end() < a_fineFlux.nComp());
  CH_assert(a_dstInterval.begin() >= 0);
  CH_assert(a_dstInterval.end() < m_nComp);

  CH_assert(a_dir >= 0);
  CH_assert(a_dir < SpaceDim);
  CH_assert((a_sd == Side::Lo)||(a_sd == Side::Hi));
  //
  //
  //denom is the number of fine faces per coarse face
  //this is intrinsically dimension-dependent
#if (CH_SPACEDIM == 2)
  Real denom = 1;
#elif (CH_SPACEDIM == 3)
  Real denom = m_nRefine;
#else
  // This code doesn't make any sense in 1D, and hasn't been implemented
  // for DIM > 3
  Real denom = -1.0;
  MayDay::Error("LevelFluxRegisterEdge -- bad SpaceDim");
#endif

  Real scale = a_scale/denom;

  // need which fluxbox face we're doing this for
  Box thisBox = a_fineFlux.box();
  int fluxComp = -1;
  for (int sideDir=0; sideDir<SpaceDim; sideDir++)
  {
    // we do nothing in the direction normal to face
    if (sideDir != a_dir)
    {
      if (thisBox.type(sideDir) == IndexType::CELL)
      {
        fluxComp = sideDir;
      }
    }
  }
  CH_assert (fluxComp >= 0);
  int regcomp = getRegComp(a_dir, fluxComp);

  FluxBox& thisReg = m_fabFine[index(a_dir, a_sd)][a_fineDataIndex];
  FArrayBox& reg = thisReg[regcomp];

  a_fineFlux.shiftHalf(a_dir, sign(a_sd));

  // this is a way of geting a face-centered domain
  // box which we can then use to intersect with things
  // to screen out cells outside the physical domain
  // (nothing is screened out in periodic case)
  Box shiftedValidDomain = m_domainCoarse.domainBox();
  shiftedValidDomain.grow(2);
  shiftedValidDomain &= m_domainCoarse;
  shiftedValidDomain.surroundingNodes(regcomp);

  BoxIterator regIt(reg.box() & shiftedValidDomain);
  for (regIt.begin(); regIt.ok(); ++regIt)
    {
      const IntVect& coarseIndex = regIt();
      // create a cell-centered box, then shift back to face-centered
      Box box(coarseIndex, coarseIndex);
      box.shiftHalf(regcomp,-1);
      // to avoid adding in edges which do not overlie coarse-grid
      // edges, will refine only in non-fluxComp directions to
      // determine box from which to grab fluxes.
      IntVect refineVect(m_nRefine*IntVect::Unit);
      //refineVect.setVal(fluxComp,1);
      box.refine(refineVect);
      if (a_sd == Side::Lo) box.growLo(a_dir,-(m_nRefine-1));
      else                 box.growHi(a_dir,-(m_nRefine-1));
      BoxIterator fluxIt(box);
      for (fluxIt.begin(); fluxIt.ok(); ++fluxIt)
        {
          int src = a_srcInterval.begin();
          int dest =  a_dstInterval.begin();
          for ( ; src <=a_srcInterval.end(); ++src,++dest)
            reg(coarseIndex, dest) += scale*a_fineFlux(fluxIt(), src);
        }
    }
  a_fineFlux.shiftHalf(a_dir, -sign(a_sd));
}
Example #28
0
template <class T> void
_fillHullT(T *_m, const XYPoint &srcsize) {
  int nobj = 0, i, x, y;
  XYPoint size = srcsize;

  // computes maximum number of different objects
  for (i=0; i < srcsize.x*srcsize.y; i++)
    if ((int)_m[i] > nobj) nobj = (int)_m[i];

  // nothing to do if no objects
  if (nobj < 1) return;

  // extend m by 2 pixels, copy content of _m inside, the frame - 0;
  // initialize temporary canvas with 0 
  size.x += 2;
  size.y += 2;

  typedef T* pT;
  T ** m = new pT[size.x];
  T ** canvas = new pT[size.x];
  for (x=0; x < size.x; x++) {
    m[x] = new T[size.y];
    canvas[x] = new T[size.y];
    for (y=0; y < size.y; y++) {
      canvas[x][y] = (T)0;
      if (x==0 || x==size.x-1 || y==0 || y==size.y-1) m[x][y] = (T)0;
      else m[x][y] = _m[x-1 + (y-1)*srcsize.x];
    }
  }

  // allocate and compute bounding boxes for all objects (the one for 0 never used)
  Box * bbox = new Box[nobj+1];

  for (i=1; i <= nobj; i++) {
    bbox[i].l = size.x-2;
    bbox[i].t = size.y-2;
  }

  for (x=1; x < size.x-1; x++)
    for (y=1; y < size.y-1; y++) {
      if ( (i=(int)m[x][y]) == 0) continue;
      if (x < bbox[i].l) bbox[i].l = x;
      else if (bbox[i].r < x) bbox[i].r = x;
      if (y < bbox[i].t) bbox[i].t = y;
      else if (bbox[i].b < y) bbox[i].b = y;
    }

  // reverse filling
  for (i=1; i <= nobj; i++) {
    Box box = bbox[i];
    box.expand(1);
    _fillAroundObjectHullT<T>(m, canvas, box, i);
    // fill back the original matrix!
  	for (x=box.l+1; x <= box.r-1; x++)
      for (y=box.t+1; y <= box.b-1; y++) {
	      // if ((int)_m[x-1+(y-1)*srcsize.x] > 0) continue;
	      if ((int)m[x][y] != 0 || (int)canvas[x][y]==i) continue;
        // this should never happen, but just in case
	      if (x-1<0 || x-1>=srcsize.x || y-1<0 || y-1>=srcsize.y) continue;
 	      _m[x-1+(y-1)*srcsize.x] = (T)i;
	    }
  }
  // cleanup
  for (x=0; x < size.x; x++) {
    delete[] m[x];
    delete[] canvas[x];
  }
  delete[] m;
  delete[] canvas;
  delete[] bbox;
}
Example #29
0
// confine the view to keep as much of the image onscreen as possible.
void EditView::ConfineView()
{
    Box const& p = Proj().ImgConst(Frame()).Bounds();
    Box v = ViewToProj( m_ViewBox );
#if 0
    if( p.W() < v.W() )
        m_Offset.x = -(v.W()-p.W())/2;   // center
    else if( v.XMin() < 0 )
        m_Offset.x = 0;
    else if( v.XMax() > p.XMax() )
        m_Offset.x = (p.x + p.W()) - v.W();

    if( p.H() < v.H() )
        m_Offset.y = -(v.H()-p.H())/2;   // center
    else if( v.YMin() < 0 )
        m_Offset.y = 0;
    else if( v.YMax() > p.YMax() )
        m_Offset.y = (p.y+p.H()) - v.H();
#endif

    if( p.W() < v.W() )
    {
        // view is wider than proj
        if( v.XMin() > p.XMin() )
            m_Offset.x = p.XMin();
        if( v.XMax() < p.XMax() )
            m_Offset.x = (p.x + p.W())-v.W();
    }
    else
    {
        // proj is wider than view
        if( v.XMin() < 0 )
            m_Offset.x = 0;
        else if( v.XMax() > p.XMax() )
            m_Offset.x = (p.x + p.W()) - v.W();
    }

    if( p.H() < v.H() )
    {
        // view is taller than proj
        if( v.YMin() > p.YMin() )
            m_Offset.y = p.YMin();
        if( v.YMax() < p.YMax() )
            m_Offset.y = (p.y + p.H())-v.H();
    }
    else
    {
        // proj is taller than view
        if( v.YMin() < 0 )
            m_Offset.y = 0;
        else if( v.YMax() > p.YMax() )
            m_Offset.y = (p.y+p.H()) - v.H();
    }

}
Example #30
0
void VCAMRPoissonOp2::restrictResidual(LevelData<FArrayBox>&       a_resCoarse,
                                      LevelData<FArrayBox>&       a_phiFine,
                                      const LevelData<FArrayBox>& a_rhsFine)
{
  CH_TIME("VCAMRPoissonOp2::restrictResidual");

  homogeneousCFInterp(a_phiFine);
  const DisjointBoxLayout& dblFine = a_phiFine.disjointBoxLayout();
  for (DataIterator dit = a_phiFine.dataIterator(); dit.ok(); ++dit)
    {
      FArrayBox& phi = a_phiFine[dit];
      m_bc(phi, dblFine[dit()], m_domain, m_dx, true);
    }

  a_phiFine.exchange(a_phiFine.interval(), m_exchangeCopier);

  for (DataIterator dit = a_phiFine.dataIterator(); dit.ok(); ++dit)
    {
      FArrayBox&       phi = a_phiFine[dit];
      const FArrayBox& rhs = a_rhsFine[dit];
      FArrayBox&       res = a_resCoarse[dit];

      const FArrayBox& thisACoef = (*m_aCoef)[dit];
      const FluxBox&   thisBCoef = (*m_bCoef)[dit];

      Box region = dblFine.get(dit());
      const IntVect& iv = region.smallEnd();
      IntVect civ = coarsen(iv, 2);

      res.setVal(0.0);

#if CH_SPACEDIM == 1
      FORT_RESTRICTRESVC1D
#elif CH_SPACEDIM == 2
      FORT_RESTRICTRESVC2D
#elif CH_SPACEDIM == 3
      FORT_RESTRICTRESVC3D
#else
      This_will_not_compile!
#endif
                          (CHF_FRA_SHIFT(res, civ),
                           CHF_CONST_FRA_SHIFT(phi, iv),
                           CHF_CONST_FRA_SHIFT(rhs, iv),
                           CHF_CONST_REAL(m_alpha),
                           CHF_CONST_FRA_SHIFT(thisACoef, iv),
                           CHF_CONST_REAL(m_beta),
#if CH_SPACEDIM >= 1
                           CHF_CONST_FRA_SHIFT(thisBCoef[0], iv),
#endif
#if CH_SPACEDIM >= 2
                           CHF_CONST_FRA_SHIFT(thisBCoef[1], iv),
#endif
#if CH_SPACEDIM >= 3
                           CHF_CONST_FRA_SHIFT(thisBCoef[2], iv),
#endif
#if CH_SPACEDIM >= 4
                           This_will_not_compile!
#endif
                           CHF_BOX_SHIFT(region, iv),
                           CHF_CONST_REAL(m_dx));
    }
}