Example #1
0
int main(){
	Composite car("Car");
	Composite chassis("Chassis");
	Element weel1("weel1");
	Element weel2("weel2");
	Element weel3("weel3");
    Element weel4("weel4");
	Element sweel("Steering weel");
	chassis.add(weel1);
	chassis.add(weel2);
	chassis.add(weel3);
	chassis.add(weel4);
	chassis.add(sweel);
	Composite engine("Engine");
	Element splugs("spark plugs");
	Element pistons("Pistons");
	Element gbox("Gear Box");
	engine.add(splugs);
	engine.add(pistons);
	engine.add(gbox);
	car.add(engine);
	car.add(chassis);
	car.operation();
	std::cout<<std::endl<<"END OF ALL COMPOSITES"<<std::endl;
}
Example #2
0
static
void new_box(RECT *r, RECT *o)
{
	if (o)
		if (!rect_changed(r, o))
			return;

	hidem();

	if (o)
	{
		gbox(-1, o);
		gbox( 0, o);
		*o = *r;
	}

	gbox(-1, r);
	gbox( 0, r);

	showm();
}
Example #3
0
	const IBox View::computeCursor(const int2 &start, const int2 &end, const int3 &bbox, int height, int offset) const {
		float2 height_off = worldToScreen(float3(0, height, 0));
		int3 gbox(cellSize(), 1, cellSize());

		int3 start_pos = asXZ((int2)( screenToWorld(float2(start + pos()) - height_off) + float2(0.5f, 0.5f)));
		int3 end_pos   = asXZ((int2)( screenToWorld(float2(end   + pos()) - height_off) + float2(0.5f, 0.5f)));

		start_pos.y = end_pos.y = height + offset;
		
		{
			int apos1 = start_pos.x % gbox.x;
			int apos2 = apos1 - gbox.x + bbox.x;
			start_pos.x -= apos1 < gbox.x - apos1 || bbox.x >= gbox.x? apos1 : apos2;
		}
		{
			int apos1 = start_pos.z % gbox.z;
			int apos2 = apos1 - gbox.z + bbox.z;
			start_pos.z -= apos1 < gbox.z - apos1 || bbox.z >= gbox.z? apos1 : apos2;
		}
		if(end == start)
			end_pos = start_pos;
		
		int3 dir(end_pos.x >= start_pos.x? 1 : -1, 1, end_pos.z >= start_pos.z? 1 : -1);
		int3 size(::abs(end_pos.x - start_pos.x), 1, ::abs(end_pos.z - start_pos.z));
		size += bbox - int3(1, 1, 1);
		size.x -= size.x % bbox.x;
		size.z -= size.z % bbox.z;
		size = max(bbox, size);

		if(dir.x < 0)
			start_pos.x += bbox.x;
		if(dir.z < 0)
			start_pos.z += bbox.z;
		end_pos = start_pos + dir * size;

		if(start_pos.x > end_pos.x) swap(start_pos.x, end_pos.x);
		if(start_pos.z > end_pos.z) swap(start_pos.z, end_pos.z);
		
		int2 dims = m_tile_map.dimensions();
		start_pos = asXZY(clamp(start_pos.xz(), int2(0, 0), dims), start_pos.y);
		  end_pos = asXZY(clamp(  end_pos.xz(), int2(0, 0), dims),   end_pos.y);

		return IBox(start_pos, end_pos);

	}
void
Stokes::V_Coarsen_Patch_Strategy::postprocessCoarsen_2D
(SAMRAI::hier::Patch& coarse,
 const SAMRAI::hier::Patch& fine,
 const SAMRAI::hier::Box& ,
 const SAMRAI::hier::IntVector& )
{
  /* Fix up the boundary elements by iterating through the boundary
     boxes */

  /* We only care about edges, not corners, so we only iterate over
     edge boundary boxes. */
  const std::vector<SAMRAI::hier::BoundaryBox>
    &boundaries=coarse_fine[fine.getPatchLevelNumber()]->getEdgeBoundaries(coarse.getGlobalId());
     
  boost::shared_ptr<SAMRAI::pdat::SideData<double> > v_fine =
    boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
    (fine.getPatchData(v_id));
  boost::shared_ptr<SAMRAI::pdat::SideData<double> > v =
    boost::dynamic_pointer_cast<SAMRAI::pdat::SideData<double> >
    (coarse.getPatchData(v_id));

  TBOX_ASSERT(v);
  TBOX_ASSERT(v_fine);
  TBOX_ASSERT(v_fine->getDepth() == v->getDepth());
  TBOX_ASSERT(v->getDepth() == 1);

  SAMRAI::hier::Box gbox(v_fine->getGhostBox());
  SAMRAI::hier::Index ip(1,0), jp(0,1);
  for(size_t mm=0; mm<boundaries.size(); ++mm)
    {
      SAMRAI::hier::Box bbox=boundaries[mm].getBox();
      int location_index=boundaries[mm].getLocationIndex();

      SAMRAI::hier::Index
        lower=SAMRAI::hier::Index::coarsen(bbox.lower(),
                                           SAMRAI::hier::Index(2,2)),
        upper=SAMRAI::hier::Index::coarsen(bbox.upper(),
                                           SAMRAI::hier::Index(2,2));

      for(int j=lower(1); j<=upper(1); ++j)
        for(int i=lower(0); i<=upper(0); ++i)
          {
            /* Fix vx */
            if(location_index==0)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0,
                                               SAMRAI::pdat::SideIndex::Upper);
                SAMRAI::pdat::SideIndex center(coarse*2);
                if(center[1]>=gbox.lower(1) && center[1]<gbox.upper(1))
                  {
                    (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+jp))/2;
                  }
              }
            else if(location_index==1)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0,
                                               SAMRAI::pdat::SideIndex::Lower);
                SAMRAI::pdat::SideIndex center(coarse*2);
                if(center[1]>=gbox.lower(1) && center[1]<gbox.upper(1))
                  {
                    (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+jp))/2;
                  }
              }
            /* Fix vy */
            else if(location_index==2)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1,
                                               SAMRAI::pdat::SideIndex::Upper);
                SAMRAI::pdat::SideIndex center(coarse*2);
                if(center[0]>=gbox.lower(0) && center[0]<gbox.upper(0))
                  {
                    (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+ip))/2;
                  }
              }
            else if(location_index==3)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1,
                                               SAMRAI::pdat::SideIndex::Lower);
                SAMRAI::pdat::SideIndex center(coarse*2);
                if(center[0]>=gbox.lower(0) && center[0]<gbox.upper(0))
                  {
                    (*v)(coarse)=((*v_fine)(center) + (*v_fine)(center+ip))/2;
                  }
              }
            else
              {
                abort();
              }
          }
    }
}
Example #5
0
global
void d3_pushbutton(int d, RECT *r, OBJC_COLOURS *col, int state, int thick, int mode)
{
	G_u selected = state&SELECTED;
	int t, j, outline;

	thick = -thick;		/* make thick same direction as d (positive value --> LARGER!) */

	if (thick > 0)		/* outside thickness */
		d += thick;
	d += 2;
	
	if (mode&1)			/* fill ? */
	{
		if (col == nil)
			f_color(screen.dial_colours.bg_col);
		/* otherwise set by set_colours() */
		gbar(d, r);						/* inside bar */
	}

	j = d;
	t = abs(thick);
	outline = j;

#if NAES3D
	if (default_options.naes and !(mode&2))
	{	
		l_color(screen.dial_colours.fg_col);
		
		while (t > 0)
		{
			gbox(j, r);					/* outside box */
			t--, j--;
		}
	
		br_hook(j, r, selected ? screen.dial_colours.lit_col : screen.dial_colours.shadow_col);
		tl_hook(j, r, selected ? screen.dial_colours.shadow_col : screen.dial_colours.lit_col);
	}
	else
#endif
	{
		do
		{
			br_hook(j, r, selected ? screen.dial_colours.lit_col : screen.dial_colours.shadow_col);
			tl_hook(j, r, selected ? screen.dial_colours.shadow_col : screen.dial_colours.lit_col);
			t--, j--;
		} while (t >= 0);
	
	    if (    thick
	        and !(mode&2)		/* full outline ? */
	       )
		{
			l_color(screen.dial_colours.fg_col);
			gbox(outline, r);					/* outside box */
		}
	}

	shadow_object(outline, state, r, screen.dial_colours.border_col, thick);

	l_color(screen.dial_colours.border_col);
}
Example #6
0
// clean out BC from stencil of cell a_iv
void 
PetscCompGridVTO::applyBCs( IntVect a_iv, int a_ilev, const DataIndex &di_dummy, Box a_dombox, 
                            StencilTensor &a_sten )
{
  CH_TIME("PetscCompGridVTO::applyBCs");
  Vector<Vector<StencilNode> > new_vals; // StencilTensorValue
  
  RefCountedPtr<BCFunction> bc = m_bc.getBCFunction();
  CompGridVTOBC *mybc = dynamic_cast<CompGridVTOBC*>(&(*bc));
  
  // count degrees, add to 'corners'
  Vector<IntVectSet> corners(CH_SPACEDIM);
  StencilTensor::const_iterator end2 = a_sten.end(); 
  for (StencilTensor::const_iterator it = a_sten.begin(); it != end2; ++it) 
    {
      const IntVect &jiv = it->first.iv();
      if (!a_dombox.contains(jiv) && it->first.level()==a_ilev) // a BC
        {
          int degree = CH_SPACEDIM-1;
          for (int dir=0;dir<CH_SPACEDIM;++dir)
            {
              if (jiv[dir] >= a_dombox.smallEnd(dir) && jiv[dir] <= a_dombox.bigEnd(dir)) degree--;
            }
          CH_assert(degree>=0);
          corners[degree] |= jiv;
        }
    }
  // move ghosts starting at with high degree corners and cascade to lower degree
  for (int ideg=CH_SPACEDIM-1;ideg>=0;ideg--)
    {
      // iterate through list
      for (IVSIterator ivit(corners[ideg]); ivit.ok(); ++ivit)
        {
          const IntVect &jiv = ivit(); // get rid of this bc ghost
          // get layer of ghost
          Box gbox(IntVect::Zero,IntVect::Zero); gbox.shift(jiv);
          Box inter = a_dombox & gbox;    CH_assert(inter.numPts()==0);
          int igid = -1; // find which layer of ghost I am
          do{
            igid++;
            gbox.grow(1);
            inter = a_dombox & gbox;
          }while (inter.numPts()==0);
	  if (igid!=0) MayDay::Error("PetscCompGridVTO::applyBCs layer???");
          for (int dir=0;dir<CH_SPACEDIM;++dir)
            {
              if (jiv[dir] < a_dombox.smallEnd(dir) || jiv[dir] > a_dombox.bigEnd(dir))
		{ // have a BC, get coefs on demand
		  int iside = 1; // hi
		  int isign = 1;
                  if (jiv[dir] < a_dombox.smallEnd(dir)) isign = -1;
		  if (jiv[dir] < a_dombox.smallEnd(dir)) iside = 0; // lo
		  if (!mybc) MayDay::Error("PetscCompGridVTO::applyBCs: wrong BC!!!!");
		  new_vals.resize(1);
		  new_vals[0].resize(1); 
		  //new_vals[i][j].second.setValue(mybc->getCoef(j,i));
                  for (int comp=0; comp<SpaceDim; comp++)
                    {
		      new_vals[0][0].second.define(1);
                      if (mybc->m_bcDiri[dir][iside][comp]) new_vals[0][0].second.setValue(comp,comp,-1.); // simple diagonal 
                      else new_vals[0][0].second.setValue(comp,comp,1.);
                    } // end loop over components
                  new_vals[0][0].first.setLevel(a_ilev);
		  
		  IndexML kill(jiv,a_ilev);
		  IntVect biv = jiv;
		  biv.shift(dir,-isign*(igid+1));                 
		  new_vals[igid][0].first.setIV(biv);
		  if (ideg>0 && !a_dombox.contains(biv)) // this could be a new stencil value for high order BCs
		    {
		      corners[ideg-1] |= biv; // send down to lower list for later removal
		    }
		  else CH_assert(a_dombox.contains(biv));
		
		  StencilProject(kill,new_vals[igid],a_sten);
		  int nrm = a_sten.erase(kill); CH_assert(nrm==1);
		  break;
		} // BC
	    } // spacedim
	} // ghosts
    } // degree
}
void
Elastic::V_Coarsen_Patch_Strategy::fix_boundary_elements_2D
(SAMRAI::pdat::SideData<double>& v,
 const SAMRAI::pdat::SideData<double>& v_fine,
 const boost::shared_ptr<SAMRAI::pdat::SideData<double> > dv_mixed,
 const std::vector<SAMRAI::hier::BoundaryBox> &boundaries) const
{
  /* FIXME: Why is this required?  Shouldn't the boundary points be
     ok?  They are partially interpolated from the coarse level, but
     that should not be a problem.  Unfortunately, it is a problem,
     because removing this routine generates nan's. */

  /* Fix up the boundary elements by iterating through the boundary
     boxes */

  /* We only care about edges, not corners, so we only iterate over
     edge boundary boxes. */

  SAMRAI::hier::Box gbox(v_fine.getGhostBox());
  SAMRAI::hier::Index ip(1,0), jp(0,1);
  for(size_t mm=0; mm<boundaries.size(); ++mm)
    {
      SAMRAI::hier::Box bbox=boundaries[mm].getBox();
      int location_index=boundaries[mm].getLocationIndex();

      SAMRAI::hier::Index
        lower=SAMRAI::hier::Index::coarsen(bbox.lower(),
                                           SAMRAI::hier::Index(2,2)),
        upper=SAMRAI::hier::Index::coarsen(bbox.upper(),
                                           SAMRAI::hier::Index(2,2));

      for(int j=lower(1); j<=upper(1); ++j)
        for(int i=lower(0); i<=upper(0); ++i)
          {
            /* Fix vx */
            if(location_index==0)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0,
                                               SAMRAI::pdat::SideIndex::Upper);
                SAMRAI::pdat::SideIndex x(coarse*2);
                if(x[1]>=gbox.lower(1) && x[1]<gbox.upper(1))
                  {
                    v(coarse)=(v_fine(x) + v_fine(x+jp))/2;
                    if(have_faults() && !is_residual)
                      v(coarse)+=((*dv_mixed)(x,0) + (*dv_mixed)(x+jp,1))/2;
                  }
              }
            else if(location_index==1)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),0,
                                               SAMRAI::pdat::SideIndex::Lower);
                SAMRAI::pdat::SideIndex x(coarse*2);
                if(x[1]>=gbox.lower(1) && x[1]<gbox.upper(1))
                  {
                    v(coarse)=(v_fine(x) + v_fine(x+jp))/2;
                    if(have_faults() && !is_residual)
                      v(coarse)+=((*dv_mixed)(x,0) + (*dv_mixed)(x+jp,1))/2;
                  }
              }
            /* Fix vy */
            else if(location_index==2)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1,
                                               SAMRAI::pdat::SideIndex::Upper);
                SAMRAI::pdat::SideIndex y(coarse*2);
                if(y[0]>=gbox.lower(0) && y[0]<gbox.upper(0))
                  {
                    v(coarse)=(v_fine(y) + v_fine(y+ip))/2;
                    if(have_faults() && !is_residual)
                      v(coarse)+=((*dv_mixed)(y,0) + (*dv_mixed)(y+ip,1))/2;
                  }
              }
            else if(location_index==3)
              {
                SAMRAI::pdat::SideIndex coarse(SAMRAI::hier::Index(i,j),1,
                                               SAMRAI::pdat::SideIndex::Lower);
                SAMRAI::pdat::SideIndex y(coarse*2);
                if(y[0]>=gbox.lower(0) && y[0]<gbox.upper(0))
                  {
                    v(coarse)=(v_fine(y) + v_fine(y+ip))/2;
                    if(have_faults() && !is_residual)
                      v(coarse)+=((*dv_mixed)(y,0) + (*dv_mixed)(y+ip,1))/2;
                  }
              }
            else
              {
                abort();
              }
          }
    }
}