コード例 #1
0
ファイル: model_data.cpp プロジェクト: francesco-romano/acado
returnValue ModelData::setIntegrationGrid(	const Grid& _ocpGrid, const uint _numSteps
										)
{
	uint i;
	N = _ocpGrid.getNumIntervals();
	BooleanType equidistantControl = _ocpGrid.isEquidistant();
	double T = _ocpGrid.getLastTime() - _ocpGrid.getFirstTime();
	double h = T/((double)_numSteps);
	Vector stepsVector( N );

	if (integrationGrid.isEmpty() == BT_TRUE)
	{
		for( i = 0; i < stepsVector.getDim(); i++ )
		{
			stepsVector(i) = (int) acadoRound((_ocpGrid.getTime(i+1)-_ocpGrid.getTime(i))/h);
		}

		if( equidistantControl )
		{
			// Setup fixed integrator grid for equidistant control grid
			integrationGrid = Grid( 0.0, ((double) T)/((double) N), (int) ceil((double)_numSteps/((double) N) - 10.0*EPS) + 1 );
		}
		else
		{
			// Setup for non equidistant control grid
			// NOTE: This grid defines only one integration step because the control
			// grid is non equidistant.
			integrationGrid = Grid( 0.0, h, 2 );
			numSteps = stepsVector;
		}
	}
	return SUCCESSFUL_RETURN;
}
コード例 #2
0
ファイル: Wall.cpp プロジェクト: wevet/Cocos2dxResources
Wall* Wall::create(Field* field, const Grid &pos)
{
    Wall* wall = new Wall();
    if (wall && wall->initWithGrid(field, "rWall_0003", pos))
    {
        wall->autorelease();
        wall->retain();
    }
    else
    {
        CC_SAFE_DELETE(wall);
        wall = nullptr;
    }
    
    wall->_is_top_wall_exist   = wall->_isWallExist(wall->m_grid_pos + Grid(0, -1));
    wall->_is_right_wall_exist = wall->_isWallExist(wall->m_grid_pos + Grid(1, 0));
    wall->_refreshWall();
    
    auto left_wall   = wall->_getWall(wall->m_grid_pos + Grid(-1, 0));

    if (left_wall)
    {
        left_wall->notifyRightWallExist();
    }
    
    auto bottom_wall = wall->_getWall(wall->m_grid_pos + Grid(0, 1));
    if (bottom_wall)
    {
        bottom_wall->notifyTopWallExist();
    }
    
    return wall;
}
コード例 #3
0
ファイル: test_grid.cpp プロジェクト: dhrupadb/C-doku-
int main(){
  Grid g = Grid();

  Grid g2 = Grid();

  assert(g == g2);

  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if ((i+j)%7 == 0) {
        g2.set(i,j,-1*(i+1)*(j+1));
      } else {
        g2.set(i,j,(i-1)*(j+1));
      }
    }
  }

  assert(g != g2);

  g = g2;

  assert (g == g2);

  g.set(8,8, -10);
  g.set(4,8, -10);
  g.set(3,8, -10);
  g.set(8,5, -10);
  g.set(1,3, -10);

  g.print();

  std::cout << "All tests passed!\n";

  return 0;
}
コード例 #4
0
ファイル: GameWorld.cpp プロジェクト: MagicBlocks/Pac-man
Grid GameWorld::GetGridPos(float x, float y)
{
	if (x < rect.left || x >= rect.right || y > rect.top || y <= rect.bottom) return Grid(-1, -1);

	int tx = int((x - rect.left) / gridWidth);
	int ty = int((rect.top - y) / gridHeight);

	return Grid(tx, ty);
}
コード例 #5
0
//#################### CONSTRUCTORS ####################
BroadPhaseCollisionDetector::BroadPhaseCollisionDetector(const BoundsManager_CPtr& boundsManager,
														 double minObjectSize, double maxObjectSize)
:	m_boundsManager(boundsManager)
{
	for(double gridSize=minObjectSize; gridSize<maxObjectSize*2; gridSize*=2)
	{
		m_hgrid.insert(std::make_pair(gridSize, Grid()));
	}

	m_hgrid.insert(std::make_pair(std::numeric_limits<double>::max(), Grid()));
}
コード例 #6
0
ファイル: Board.cpp プロジェクト: ZwodahS/DestroyTheBrick
void Board::addDestroyedBricks(Brick* brick, std::vector<Brick*> &destroyedBricks)
{
    Grid location = brick->_currentLocation;
    Brick* north = getBrickAt(location + Grid(-1,0));
    Brick* south = getBrickAt(location + Grid(1,0));
    Brick* east = getBrickAt(location + Grid(0,1));
    Brick* west = getBrickAt(location + Grid(0,-1));
    
    if(north != 0 ) // not sure why some times short circuit works sometime it doesn't.
    {
        if(!north->tmp_moves)
        {
            if(brick->getType() == north->getType())
            {
                north->tmp_moves = true;    
                destroyedBricks.push_back(north);
            }
        }
    }
    if(south != 0 )
    {
        if(!south->tmp_moves)
        {
            if(brick->getType() == south->getType())
            {
                south->tmp_moves = true;    
                destroyedBricks.push_back(south);
            }
        }
    }
    if(east != 0)
    {
        if(!east->tmp_moves)
        {
            if(brick->getType() == east->getType() )
            {
                east->tmp_moves = true;    
                destroyedBricks.push_back(east);
            }
        }
    }
    if(west != 0 )
    {
        if(!west->tmp_moves)
        {
            if(brick->getType() == west->getType() )
            {
                west->tmp_moves = true;    
                destroyedBricks.push_back(west);
            }
        }
    }
}
コード例 #7
0
ファイル: Board.cpp プロジェクト: ZwodahS/DestroyTheBrick
bool Board::fireBrick(Grid location, Brick* nextBrick, zf::Direction direction)
{
    if(isMoving())
    {
        return false;
    }
    Grid directionGrid = Grid(0,0);
    switch(direction)
    {
        case zf::North:
            directionGrid = Grid(-1,0);
            break;
        case zf::South:
            directionGrid = Grid(1,0);
            break;
        case zf::East:
            directionGrid = Grid(0,1);
            break;
        case zf::West:
            directionGrid = Grid(0,-1);
            break;
    }
    Grid nextGrid = location + directionGrid;
    Brick* brick = getBrickAt(nextGrid.row , nextGrid.col);
    if(brick != 0)
    {
        return false; // if there is a brick blocking directly, don't allow it to shoot.
    }
    //find the first block that it will hit
    // move nextGrid back first
    nextGrid -= directionGrid;
    while(brick == 0)
    {
        nextGrid += directionGrid;
        Grid temp = nextGrid + directionGrid;
        if(!inShootableRange(temp.row,temp.col)) // if the next is not in shootable range , break
        {
            // prevent out of bound
            break;
        }
        brick = getBrickAt(temp.row, temp.col);
    }

    _knock = -1;
    putBrickInto(location.row,location.col,nextBrick);
    nextBrick->moveToLocation(nextGrid.row, nextGrid.col);
    _currentMovingDirection = directionGrid; 
    _movingBricks.push_back(nextBrick);
    return true;
}
コード例 #8
0
ファイル: World.cpp プロジェクト: ZwodahS/LD26
bool World::hasBot(int row, int col)
{
    for(int i = 0 ; i < _enemyBots.size() ; i++)
    {
        if(_enemyBots[i]->getLocation() == Grid(row,col))
        {
            return true;
        }
    }
    if(_player->getLocation() == Grid(row, col))
    {
        return true;
    }
    return false;
}
コード例 #9
0
ファイル: SlotArea.cpp プロジェクト: l0ud/MCServer
void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player)
{
	const cItem * ResultSlot = GetSlot(0, a_Player);
	cItem & DraggingItem = a_Player.GetDraggingItem();

	// Get the current recipe:
	cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player);

	cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1;
	cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize);

	// If possible, craft:
	if (DraggingItem.IsEmpty())
	{
		DraggingItem = Recipe.GetResult();
		Recipe.ConsumeIngredients(Grid);
		Grid.CopyToItems(PlayerSlots);
	}
	else if (DraggingItem.IsEqual(Recipe.GetResult()))
	{
		cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType);
		if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize())
		{
			DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount;
			Recipe.ConsumeIngredients(Grid);
			Grid.CopyToItems(PlayerSlots);
		}
	}

	// Get the new recipe and update the result slot:
	UpdateRecipe(a_Player);
	
	// We're done. Send all changes to the client and bail out:
	m_ParentWindow.BroadcastWholeWindow();
}
コード例 #10
0
ファイル: radial-wca.cpp プロジェクト: droundy/deft
double run_soft_sphere(double reduced_density, double temp) {
  Functional f = SoftFluid(sigma, 1, 0);
  const double mu = find_chemical_potential(OfEffectivePotential(f), temp, reduced_density*pow(2,-5.0/2.0));
  printf("mu is %g for reduced_density = %g at temperature %g\n", mu, reduced_density, temp);

  //printf("Filling fraction is %g with functional %s at temperature %g\n", reduced_density, teff);
  //fflush(stdout);
  temperature = temp;
  //if (kT == 0) kT = ;1

  Lattice lat(Cartesian(xmax,0,0), Cartesian(0,ymax,0), Cartesian(0,0,zmax));
  GridDescription gd(lat, dx);

  Grid softspherepotential(gd);
  softspherepotential.Set(soft_sphere_potential);

  f = SoftFluid(sigma, 1, mu); // compute approximate energy with chemical potential mu
  const double approx_energy = f(temperature, reduced_density*pow(2,-5.0/2.0))*xmax*ymax*zmax;
  const double precision = fabs(approx_energy*1e-9);

  f = OfEffectivePotential(SoftFluid(sigma, 1, mu) + ExternalPotential(softspherepotential));

  static Grid *potential = 0;
  potential = new Grid(gd);
  *potential = softspherepotential - temperature*log(reduced_density*pow(2,-5.0/2.0)/(1.0*radius*radius*radius))*VectorXd::Ones(gd.NxNyNz); // Bad starting guess
  printf("\tMinimizing to %g absolute precision from %g from %g...\n", precision, approx_energy, temperature);
  fflush(stdout);

  Minimizer min = Precision(precision,
                            PreconditionedConjugateGradient(f, gd, temperature,
                                potential,
                                QuadraticLineMinimizer));
  took("Setting up the variables");
  for (int i=0; min.improve_energy(true) && i<100; i++) {
  }

  took("Doing the minimization");
  min.print_info();

  Grid density(gd, EffectivePotentialToDensity()(temperature, gd, *potential));
  //printf("# per area is %g at filling fraction %g\n", density.sum()*gd.dvolume/dw/dw, reduced_density);

  char *plotname = (char *)malloc(1024);

  sprintf(plotname, "papers/fuzzy-fmt/figs/radial-wca-%06.4f-%04.2f.dat", temp, reduced_density);
  z_plot(plotname, Grid(gd, pow(2,5.0/2.0)*density));
  free(plotname);

  {
    //double peak = peak_memory()/1024.0/1024;
    //double current = current_memory()/1024.0/1024;
    //printf("Peak memory use is %g M (current is %g M)\n", peak, current);

  }

  took("Plotting stuff");
  printf("density %g gives ff %g for reduced_density = %g and T = %g\n", density(0,0,gd.Nz/2),
         density(0,0,gd.Nz/2)*4*M_PI/3, reduced_density, temp);
  return density(0, 0, gd.Nz/2)*4*M_PI/3; // return bulk filling fraction
}
コード例 #11
0
ファイル: abstract_impl.hpp プロジェクト: jimgoo/Elemental
inline void
AbstractDistMatrix<T,Int>::Write
( const std::string filename, const std::string msg ) const
{
#ifndef RELEASE
    PushCallStack("AbstractDistMatrix::Write");
#endif
    const elem::Grid& g = Grid();
    const int commRank = mpi::CommRank( g.VCComm() ); 

    if( commRank == 0 )
    {
        std::ofstream file( filename.c_str() );
        file.setf( std::ios::scientific );
        PrintBase( file, msg );
        file.close();
    }
    else
    {
        NullStream nullStream;
        PrintBase( nullStream, msg );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
コード例 #12
0
ファイル: abstract_impl.hpp プロジェクト: jimgoo/Elemental
inline void
AbstractDistMatrix<T,Int>::AssertSameGrid
( const AbstractDistMatrix<U,Int>& A ) const
{
    if( Grid() != A.Grid() )
        throw std::logic_error("Assertion that grids match failed");
}
コード例 #13
0
FixPaintSelection::GridMap::iterator
FixPaintSelection::addGrid(const Point& pt)
{
    std::pair<GridMap::iterator, bool> inserted =
        mGrids.insert(GridMap::value_type(pt, Grid()));
    return inserted.first;
}
コード例 #14
0
ファイル: Grid.cpp プロジェクト: liviniuk/MIPT_base
Grid Grid::exact_solution(int time_steps) {
	std::vector<double> sol(size, 0);
	int shift = (int) (dt * xi / dh * time_steps / dh);
	for (int i = 0; i < size - shift; i++)
		sol[i + shift] = data[i];
	return Grid(sol, dh, dt, xi);
};
コード例 #15
0
ファイル: GamePlay.cpp プロジェクト: appsromch/CPlusPlus
		 : Game(rm, dbGraphics, screenBounds, gameFont, fontBrush, sound)
{
	// Create random instance
	rGen = gcnew Random();
	
	// Load background image
	//background = Image::FromFile("background.jpg");

	// Create gamegrid and preview
	grid = gcnew GameGrid(rm, Point(302,-30), graphics, sound, GAMEGRID_COLS, GAMEGRID_ROWS);
	preview = gcnew Grid(rm, Point(757,480), graphics, PREVIEW_COLS, PREVIEW_ROWS); 

	// Create arrays for tracking block stats
	tetriminoStats = gcnew array<int>(7);
	tetriminoTypes = gcnew array<ETetriminoType>
	{
		I_TETRIMINO,
		J_TETRIMINO, 
		L_TETRIMINO, 
		O_TETRIMINO, 
		S_TETRIMINO, 
		T_TETRIMINO,
		Z_TETRIMINO
	};

	// Create first two tetriminos
	tetriminoInPlay = generateTetrimino();
	nextTetrimino = generateTetrimino();

	// Initialize game update time
	waitTime = 50;
}
コード例 #16
0
//Constructs the grid based on the polygon's bounding box and generates a random point if inside polygon
Points PathPlanner::getRandGridPoints(){
	//Grid
	CGAL::Bbox_2 box = this->BPpoly.bbox();
	long double xmini = box.xmin();
	long double ymini = box.ymin();
	long double xmaxi = box.xmax();
	long double ymaxi = box.ymax();
	cout<<xmini<<" "<<xmaxi<<" "<<ymini<<" "<<ymaxi<<'\n';
	Point_2 iterator;
	vector<Grid> grids;
	Points randGridPoints;
	for(long double i =ymini; i<ymaxi; i += this->gridSideLen ){
		for(long double j = xmini; j<xmaxi; j+= this->gridSideLen ){
			grids.push_back( Grid( Point_2(j,i) , this->gridSideLen) );
			cout<<"row: "<<i<<" column: "<<j<<'\n';
		}
	}
	for (int i =0 ; i <grids.size();i++){
		if(grids[i].is_bounded(BPpoly)){
			randGridPoints.push_back(grids[i].genRandPoint());
			grids[i].printGrid();
		}
	}
	return randGridPoints;

}
コード例 #17
0
//---------------------------------------------------------
bool CFilter_Resample::On_Execute(void)
{
	double		Cellsize;
	CSG_Grid	*pGrid, *pLoPass, *pHiPass;

	//-----------------------------------------------------
	pGrid		= Parameters("GRID"  )->asGrid();
	pLoPass		= Parameters("LOPASS")->asGrid();
	pHiPass		= Parameters("HIPASS")->asGrid();
	Cellsize	= Parameters("SCALE" )->asDouble() * Get_Cellsize();

	//-----------------------------------------------------
	if( Cellsize > 0.5 * SG_Get_Length(Get_System()->Get_XRange(), Get_System()->Get_YRange()) )
	{
		Error_Set(_TL("resampling cell size is too large"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	Grid(CSG_Grid_System(Cellsize, Get_XMin(), Get_YMin(), Get_XMax(), Get_YMax()), SG_DATATYPE_Float);

	Grid.Assign(pGrid, GRID_RESAMPLING_Mean_Cells);

	//-----------------------------------------------------
	pLoPass->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("Low Pass")));
	pHiPass->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pGrid->Get_Name(), _TL("High Pass")));

	CSG_Colors	Colors;

	DataObject_Get_Colors(pGrid  , Colors);
	DataObject_Set_Colors(pLoPass, Colors);
	DataObject_Set_Colors(pHiPass, 11, SG_COLORS_RED_GREY_BLUE);

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		double	py	= Get_YMin() + y * Get_Cellsize();

		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			double	z, px	= Get_XMin() + x * Get_Cellsize();

			if( !pGrid->is_NoData(x, y) && Grid.Get_Value(px, py, z) )
			{
				pLoPass->Set_Value(x, y, z);
				pHiPass->Set_Value(x, y, pGrid->asDouble(x, y) - z);
			}
			else
			{
				pLoPass->Set_NoData(x, y);
				pHiPass->Set_NoData(x, y);
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #18
0
ファイル: SlotArea.cpp プロジェクト: RedEnraged96/MCServer-1
void cSlotAreaCrafting::UpdateRecipe(cPlayer & a_Player)
{
	cCraftingGrid   Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize);
	cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player);
	cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
	SetSlot(0, a_Player, Recipe.GetResult());
	m_ParentWindow.SendSlot(a_Player, this, 0);
}
コード例 #19
0
ファイル: Wall.cpp プロジェクト: wevet/Cocos2dxResources
void Wall::_destroy()
{
    Building::_destroy();
    m_field->notifyWallWatchers();
    
    auto left_wall   = _getWall(m_grid_pos + Grid(-1, 0));
    if (left_wall)
    {
        left_wall->notifyRightWallBroken();
    }
    
    auto bottom_wall = _getWall(m_grid_pos + Grid(0, 1));
    if (bottom_wall)
    {
        bottom_wall->notifyTopWallBroken();
    }
}
コード例 #20
0
ファイル: grid.cpp プロジェクト: Mr-Kumar-Abhishek/qt
bool Grid::fromVariantMap(const QVariantMap& vm)
{
    *this = Grid();
    valueFromVariantMap(vm, QLatin1String(KEY_VISIBLE), m_visible);
    valueFromVariantMap(vm, QLatin1String(KEY_SNAPX), m_snapX);
    valueFromVariantMap(vm, QLatin1String(KEY_SNAPY), m_snapY);
    valueFromVariantMap(vm, QLatin1String(KEY_DELTAX), m_deltaX);
    return valueFromVariantMap(vm, QLatin1String(KEY_DELTAY), m_deltaY);
}
コード例 #21
0
ファイル: World.cpp プロジェクト: ZwodahS/LD26
Grid World::gridAt(Grid g, direction::Direction d)
{
    if(d == direction::North)
    {
        return Grid(g.row-1,g.col);
    }
    else if(d == direction::South)
    {
        return Grid(g.row+1,g.col);
    }
    else if(d == direction::East)
    {
        return Grid(g.row,g.col+1);
    }
    else
    {
        return Grid(g.row,g.col-1);
    }
}
コード例 #22
0
bool
GridSelection::add(int x, int z)
{
    if (!getTerrainData()->isValidGrid(x, z))
        return false;

    size_t index = getTerrainData()->_getGridIndex(x, z);
    std::pair<GridMap::iterator, bool> inserted =
        mGrids.insert(GridMap::value_type(index, Grid(x, z, getTerrainData()->mGridInfos[index])));
    return inserted.second;
}
コード例 #23
0
ファイル: Grid.cpp プロジェクト: liviniuk/MIPT_base
Grid Grid::solve(int time_steps) {
	std::vector< double > data(this->data);	
	std::vector< double > auxiliary;
	int steps = time_steps / dh;
	for (int i = 0; i < steps; i++) {
		vector_copy(auxiliary, data);
		for (int j = 1; j < size; j++) {
			data[j] = auxiliary[j] - xi * dt * (auxiliary[j] - auxiliary[j - 1]) / dh;
		}
	}
	return Grid(data, dh, dt, xi);
}
コード例 #24
0
ファイル: binvox.cpp プロジェクト: shivamvats/leatherman
bool leatherman::ReadBinvox(const std::string& filename)
{
    ROS_INFO("Reading binvox file: %s", filename.c_str());
    std::ifstream* input = new std::ifstream(
            filename.c_str(), std::ios::in | std::ios::binary);

    // read header
    std::string line;
    *input >> line;  // #binvox
    if (line.compare("#binvox") != 0) {
        ROS_INFO_STREAM("Error: first line reads [" << line << "] instead of [#binvox]");
        delete input;
        return false;
    }
    *input >> Grid().version;
    ROS_INFO_STREAM("reading binvox version " << Grid().version);

    Grid().depth = -1;
    int done = 0;
    while (input->good() && !done) {
        *input >> line;
        if (line.compare("data") == 0) {
            done = 1;
        }
        else if (line.compare("dim") == 0) {
            *input >> Grid().depth >> Grid().height >> Grid().width;
        }
        else if (line.compare("translate") == 0) {
コード例 #25
0
ファイル: HSolveUtils.cpp プロジェクト: Vivek-sagar/moose-1
void HSolveUtils::rates(
	Id gateId,
	HSolveUtils::Grid grid,
	vector< double >& A,
	vector< double >& B )
{
	double min = HSolveUtils::get< HHGate, double >( gateId, "min" );
	double max = HSolveUtils::get< HHGate, double >( gateId, "max" );
	unsigned int divs = HSolveUtils::get< HHGate, unsigned int >(
		gateId, "divs" );
	
	if ( grid == Grid( min, max, divs ) ) {
		A = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableA" );
		B = HSolveUtils::get< HHGate, vector< double > >( gateId, "tableB" );
		
		return;
	}
	
	A.resize( grid.size() );
	B.resize( grid.size() );
	
	/*
	 * Getting Id of original (prototype) gate, so that we can set fields on
	 * it. Copied gates are read-only.
	 */
	HHGate* gate = reinterpret_cast< HHGate* >( gateId.eref().data() );
	gateId = gate->originalGateId();
	
	/*
	 * Setting interpolation flag on. Will set back to its original value once
	 * we're done.
	 */
	bool useInterpolation = HSolveUtils::get< HHGate, bool >
		( gateId, "useInterpolation" );
	//~ HSolveUtils::set< HHGate, bool >( gateId, "useInterpolation", true );
	Qinfo* qDummy = NULL;
	gate->setUseInterpolation( gateId.eref(), qDummy, true );
	
	unsigned int igrid;
	double* ia = &A[ 0 ];
	double* ib = &B[ 0 ];
	for ( igrid = 0; igrid < grid.size(); ++igrid ) {
		gate->lookupBoth( grid.entry( igrid ), ia, ib );
		
		++ia, ++ib;
	}
	
	// Setting interpolation flag back to its original value.
	//~ HSolveUtils::set< HHGate, bool >
		//~ ( gateId, "useInterpolation", useInterpolation );
	gate->setUseInterpolation( gateId.eref(), qDummy, useInterpolation );
}
コード例 #26
0
ファイル: walls.cpp プロジェクト: rscheirer/deft
double run_walls(double reduced_density, const char *name, Functional fhs, double teff) {
  double kT = teff;
  if (kT == 0) kT = 1;

  Functional f = OfEffectivePotential(fhs);

  const double zmax = width + 2*spacing;
  Lattice lat(Cartesian(dw,0,0), Cartesian(0,dw,0), Cartesian(0,0,zmax));
  GridDescription gd(lat, dx);

  Grid constraint(gd);
  constraint.Set(notinwall);
  f = constrain(constraint, f);

  Grid potential(gd);
  potential = pow(2,-5.0/2.0)*(reduced_density*constraint + 1e-4*reduced_density*VectorXd::Ones(gd.NxNyNz));
  potential = -kT*potential.cwise().log();

  const double approx_energy = fhs(kT, reduced_density*pow(2,-5.0/2.0))*dw*dw*width;
  const double precision = fabs(approx_energy*1e-11);
  printf("\tMinimizing to %g absolute precision from %g from %g...\n", precision, approx_energy, kT);
  fflush(stdout);

  Minimizer min = Precision(precision,
                            PreconditionedConjugateGradient(f, gd, kT,
                                                            &potential,
                                                            QuadraticLineMinimizer));
  took("Setting up the variables");
  if (strcmp(name, "hard") != 0 && false) {
    printf("For now, SoftFluid doesn't work properly, so we're skipping the\n");
    printf("minimization at temperature %g.\n", teff);
  } else {
    for (int i=0;min.improve_energy(false) && i<100;i++) {
    }
  }
  took("Doing the minimization");
  min.print_info();

  Grid density(gd, EffectivePotentialToDensity()(kT, gd, potential));
  //printf("# per area is %g at filling fraction %g\n", density.sum()*gd.dvolume/dw/dw, eta);

  char *plotname = (char *)malloc(1024);

  sprintf(plotname, "papers/fuzzy-fmt/figs/walls%s-%06.4f-%04.2f.dat", name, teff, reduced_density);
  z_plot(plotname, Grid(gd, density*pow(2,5.0/2.0)));
  free(plotname);

  took("Plotting stuff");
  printf("density %g gives ff %g for reduced density = %g and T = %g\n", density(0,0,gd.Nz/2),
         density(0,0,gd.Nz/2)*4*M_PI/3, reduced_density, teff);
  return density(0, 0, gd.Nz/2)*4*M_PI/3; // return bulk filling fraction
}
コード例 #27
0
wxButton* grid_toggle_button(wxWindow* parent,
  wxSizer* sizer,
  const Art& art)
{
  // Create the button that enables/disables the grid
  wxButton* button = noiseless_button(parent,
    "",
    Tooltip(""),
    IntSize(60,50));
  update_grid_toggle_button(Grid(), button, art);
  sizer->Add(button, 0, wxEXPAND);
  return button;
}
コード例 #28
0
ファイル: World.cpp プロジェクト: ZwodahS/LD26
void World::initWorld(std::vector<std::vector<Tile*> > tiles)
{
    this->_tiles = std::vector<std::vector<Tile*> >(tiles.size(),std::vector<Tile*>(tiles[0].size(),NULL));
    for(int r = 0 ; r < _tiles.size() ; r++)
    {
        for(int c = 0 ; c < _tiles[r].size() ; c++)
        {
            _tiles[r][c] = tiles[r][c];
            _tiles[r][c]->setGrid(r,c);
            if(_tiles[r][c]->type == Type_ComputerTile)
            {
                computerGrid = Grid(r,c);
                computerTile = (ComputerTile*)_tiles[r][c];
            }
            else if(_tiles[r][c]->type == Type_ExitTile)
            {
                exitGrid = Grid(r,c);
                exitTile = (ExitTile*)_tiles[r][c];
            }
        }
    }
}
コード例 #29
0
/* method: "set_grid((x,y), dashed, enabled, spacing)\n
Specify the grid." */
static void frameprops_set_grid(ImageProps& self,
  const Point& anchor,
  bool dashed,
  bool enabled,
  int spacing)
{

  self.SetGrid(Grid(enabled_t(enabled),
    dashed_t(dashed),
    spacing,
    default_grid_color(),
    anchor));
}
コード例 #30
0
ファイル: funky_env.c プロジェクト: gregghz/funky
int establish_root_environment(void) {
    spawn_env(NULL, Primordial_Grid(GC_SKIPREG));
    rootEnvironment=Car(env);
    rootBacros=Grid();
    unknownSymbolError=Err(Cons(String("Unknown symbol"), NULL));
    Set(rootEnvironment, "nil", NULL);
    Set(rootEnvironment, "true", Atom("true"));
    Set(rootEnvironment, "add", Routine(&dirty_sum));
    Set(rootEnvironment, "+", Get(rootEnvironment, "add"));
    Set(rootEnvironment, "subtract", Routine(&dirty_sub));
    Set(rootEnvironment, "-", Get(rootEnvironment, "subtract"));
    Set(rootEnvironment, "if", Method(&funky_if));
    Set(rootEnvironment, "&ver", String("Funky Lisp Draft 3"));
    Set(rootEnvironment, "set!", Routine(&funky_set));
    Set(rootEnvironment, "print_", Routine(&funky_print));
    Set(rootEnvironment, "list", Routine(&funky_list));
    Set(rootEnvironment, "pair", Routine(&funky_pair));
    Set(rootEnvironment, "grid", Routine(&funky_grid));
    Set(rootEnvironment, "get", Routine(&funky_grid_get));
    Set(rootEnvironment, "quote", Method(&funky_quote));
    Set(rootEnvironment, "apply", Routine(&apply));
    Set(rootEnvironment, "mac", Method(&funky_macro));
    Set(rootEnvironment, "def", Method(&funky_def));
    Set(rootEnvironment, "head", Routine(&funky_head));
    Set(rootEnvironment, "rest_", Routine(&funky_rest));
    Set(rootEnvironment, "last", Routine(&funky_last));
    Set(rootEnvironment, "err", Routine(&funky_err));
    Set(rootEnvironment, "dump", Routine(&funky_dump));
    Set(rootEnvironment, "&bacros", rootBacros);
    Set(rootEnvironment, ">", Routine(&funky_greater_than));
    Set(rootEnvironment, "<", Routine(&funky_less_than));
    Set(rootEnvironment, "=", Routine(&funky_equivalent));
    Set(rootEnvironment, "not", Routine(&funky_not_operator));
    Set(rootEnvironment, "eval", Method(&funky_evaluator));
    Set(rootEnvironment, "true?", Routine(&funky_truthy));
    Set(rootEnvironment, "false?", Routine(&funky_nilly));
    Set(rootEnvironment, "lambda?", Routine(&funky_callable));
    Set(rootEnvironment, "atom?", Routine(&funky_is_atom));
    Set(rootEnvironment, "gen?", Routine(&funky_is_gen));
    Set(rootEnvironment, "len", Routine(&funky_length));
    Set(rootEnvironment, "gen", Routine(&funky_gen));
    Set(rootEnvironment, "cons", Routine(&funky_cons));
    Set(rootEnvironment, "append", Routine(&funky_append));
    Set(rootEnvironment, "error?", Routine(&funky_is_error));
    Set(rootEnvironment, "grid?", Routine(&funky_is_grid));
    Set(rootEnvironment, "txt-concatenate_", Routine(&funky_make_txt));
    Set(rootEnvironment, "type", Routine(&funky_type_symbol));
    Set(rootEnvironment, UNKNOWN_HANDLER, Atom(UNKNOWN_LIT));
    establish_bacros(rootBacros);
    return new_env();
}