Exemple #1
0
void
concater_rep::ghost (string s, path ip, color col) {
  if ((N(s)>2) && (s[0]=='<') && (s[N(s)-1]=='>')) {
    ghost ("<", ip, col);
    ghost (s (1,N(s)-1), ip, col);
    ghost (">", ip, col);
    return;
  }
  
  string fn_name= "cmr";
  if (N(s)==1) {
    if (s[0] == '<') { fn_name= "cmsy"; s= "h"; }
    else if (s[0] == '>') { fn_name= "cmsy"; s= "i"; }
    else if (s[0] == '|') { fn_name= "cmsy"; s= "j"; }
    else if (s[0] == '\\') { fn_name= "cmsy"; s= "n"; }
    else if (s[0] == '{') { fn_name= "cmsy"; s= "f"; }
    else if (s[0] == '}') { fn_name= "cmsy"; s= "g"; }
  }
  int sz= script (env->fn_size, env->index_level);
  font gfn (tex_font (fn_name, sz, (int) (env->magn*env->dpi)));
  box b= text_box (decorate (ip), 0, s, gfn, col);
  array<box> bs (1);
  bs[0]= b;
  a << line_item (STD_ITEM, OP_SKIP,
                  composite_box (decorate (ip), bs), HYPH_INVALID);
}
void BattleCommanderStateDirection::SetGuideArrowToGhost(void){
	if(_accessor == nullptr){return;}
	int arrow_index(0);
	for(int i=0; i<GUIDE_ARROW_MAX; i++){
		if(_guide_arrow[i] == nullptr){continue;}
		_guide_arrow[i]->SetVisible(false);
	}

	int player_count(_accessor->GetPlayerCount());
	for(int i=0; i<player_count; i++){
		BattleActor* player(_accessor->GetPlayer(i));
		BattleActorGhost* ghost(_accessor->GetPlayerGhost(player));
		ActorCursor* cursor(_accessor->GetPlayerCursor(i));
		if(player == nullptr || ghost == nullptr || cursor == nullptr){continue;}
		if(!cursor->IsActive()){continue;}

		while(arrow_index < GUIDE_ARROW_MAX && _guide_arrow[arrow_index] == nullptr){
			arrow_index++;
			continue;
		}
		if(arrow_index == GUIDE_ARROW_MAX){break;}
		GuideArrow* arrow(_guide_arrow[arrow_index]);

		D3DXVECTOR3 begin(player->GetPosition());
		D3DXVECTOR3 end(ghost->GetPosition());

		arrow->SetBeginPosition(begin);
		arrow->SetEndPosition(end);
		arrow->SetVisible(true);
		arrow->Update();
	}
}
double& unknown::operator ()(const unsigned int& ghost_i, const unsigned int& ghost_j, const unsigned int& adj_wet_i, const unsigned int& adj_wet_j)
{

	label ghost(ghost_i, ghost_j);
	label adj_wet(adj_wet_i, adj_wet_j);


	if (Gu.unknown_map.find(ghost) == Gu.unknown_map.end())
	{
		std::cout<< "ERRORE in unknown::operator(): la cella fornita non è ghost. Non è stato ritornato nessun valore.\n";
	}
	else
	{
		std::vector<ghost_value>& gv = Gu.unknown_map[ghost];
		for (std::vector<ghost_value>::iterator it = gv.begin(); it != gv.end(); it++)
		{
			if (it->ass_wet_cell == adj_wet)
			{
				return it->value;
			}
		}

		std::cout<<"ERRORE in unknown::operator(): la ghost cell ";
		ghost.print();
		std::cout<<"non ha la cella adiacente bagnata ";
		adj_wet.print();

	}
}
void scene_gestalt()
{
    float time = 0.0;
    float offset = 1.0;
    object p1 = GetObjectByTag("intro_p1_start");
    object p2 = GetObjectByTag("intro_p2_start");
    object p2e = GetObjectByTag("intro_p2_end");
    object p3 = GetObjectByTag("intro_p3");

    /* Initialize */
    GestaltStartCutscene(pc);
    GestaltCameraFade(time, pc, FADE_CROSS, FADE_SPEED_MEDIUM, fade_duration);
    ghost();

    /* Setup */
    time = 2*delay;
    GestaltInvisibility(time, pc);
    GestaltCameraFacing(time, 63.0, 10.0, 85.0, pc);
    play_audio(time);

    /* Pass 1 */
    GestaltJump(time, pc, p1);
    GestaltActionMove(time + offset, pc, p2, FALSE, 0.0, 5*delay);

    /* Pass 2 */
    time = 7*delay;
    GestaltCameraFade(time - offset, pc, FADE_CROSS, FADE_SPEED_MEDIUM, fade_duration);
    GestaltCameraFacing(time + offset, 293.0, 10.0, 85.0, pc);
    GestaltJump(time, pc, p2);
    GestaltActionMove(time + offset, pc, p2e, FALSE, 0.0, 5*delay);


    /* Pass 3 (zoom into shadow) */
    time = 12*delay;
    GestaltCameraFade(time - offset, pc, FADE_CROSS, FADE_SPEED_MEDIUM, fade_duration);
    GestaltJump(time + offset, pc, p3);
    GestaltCameraMove(time + offset, 260.0, 20.0, 85.0, 280.0, 10.0, 85.0, 5*delay, 60.0, pc);

    /* Clean up and end cutscene */
    time = 16 * delay;
    DelayCommand(time, FadeToBlack(pc));
    //GestaltCameraFade(time - offset, pc, FADE_CROSS, FADE_SPEED_MEDIUM, fade_duration);

    /* Trigger ScriptEase */
    time = 18 * delay;
    GestaltClearEffect(time, pc);
    GestaltStopCutscene(time, pc, "intro_end");

    time = time + offset;
    // GestaltCameraFacing(time, 270.0, 10.0, 75.0, pc);
    AssignCommand(pc, SetCameraFacing(270.0, 10.0));
    DelayCommand(time, AssignCommand(pc, SetFacing(270.0)));
    DelayCommand(time, SetLocked(GetObjectByTag("activate_easel_trigger"), FALSE));
    DelayCommand(time, FadeFromBlack(pc));
}
void BattleCommanderStateDirection::StateOut(void){
	_pointing_actor = nullptr;

	//make all ghost invisible
	int player_count(_accessor->GetPlayerCount());
	for (int i = 0; i<player_count; i++){
		BattleActorGhost* ghost(_accessor->GetPlayerGhost(i));
		if (ghost == nullptr){ continue; }
		ghost->SetVisible(false);
	}
}
Exemple #6
0
void Car::updateGhosts() {
    static sf::Clock clock = sf::Clock();
    
    sf::Time time = clock.getElapsedTime();
    
    sf::Vector2f lastLocation = this->mLastLocation;
    if (this->mCarGhostDrawables.size() > 0) {
        lastLocation = this->mCarGhostDrawables.back().ghost.getPosition();
    }
    
    // add new ghost
    float ghostDistance = length(this->mCurrentLocation - lastLocation);
    if (ghostDistance >= Car::MAX_GHOSTS_DISTANCE && this->mVelocity > 0.0f) {
        sf::RectangleShape ghost(sf::Vector2f(Car::CAR_WIDTH, Car::CAR_HEIGHT));
        ghost.setOrigin(Car::CAR_WIDTH / 2.0f, Car::CAR_HEIGHT / 2.0f);
        
        sf::Vector2f dir = normalize(this->mCurrentDirection);
        ghost.setPosition(this->mCurrentLocation); // - (dir * (Car::MAX_GHOSTS_DISTANCE + 20.0f)));
        ghost.setRotation(RAD_TO_DEG(heading(dir)));
        
        ghost.setFillColor(this->mCarDrawable.getFillColor());
        
        this->mCarGhostDrawables.push_back(Ghost(ghost, time.asMilliseconds()));
        
        if (this->mCarGhostDrawables.size() >= Car::MAX_GHOSTS) {
            this->mCarGhostDrawables.erase(this->mCarGhostDrawables.begin());
        }
    }
    
    // do we need to remove some ghosts?
    std::list<Ghost>::iterator it = this->mCarGhostDrawables.begin();
    while (it != this->mCarGhostDrawables.end()) {
        if ((time.asMilliseconds() - (*it).age) >= Car::MAX_GHOSTS_AGE) {
            it = this->mCarGhostDrawables.erase(it);
        } else {
            ++it;
        }
    }
       
    // adjust alphas
    int i = this->mCarGhostDrawables.size()+1;
    //float steps = (80.0f - (80.0f * (MAX_VELOCITY / this->mVelocity))) / static_cast<float>(i);
    float steps = 80.0f / static_cast<float>(i);
    sf::Color color = this->mCarDrawable.getFillColor();
    for (std::list<Ghost>::reverse_iterator it = this->mCarGhostDrawables.rbegin(); it != this->mCarGhostDrawables.rend(); ++it) {
        color.a = steps * i--;
        (*it).ghost.setFillColor(color);
    }

}
Exemple #7
0
    void copyAsGhost(const Particle& src, int extradata, const Real3D& shift) {

      src.r.copyShifted(r, shift);
      if (extradata & DATA_PROPERTIES) {
        p = src.p;
      }
      if (extradata & DATA_MOMENTUM) {
        m = src.m;
      }
      if (extradata & DATA_LOCAL) {
        l = src.l;
      }
      ghost() = 1;
    }
main()
	{
	page pg;
	FeynDiagram fd(pg);

	vertex_dot vtx(fd,0,0);
	line_spring gluon(fd,xy(-5,0),vtx);
	gluon.arrowon.settrue();
	line_plain ghost(fd,vtx,vtx);
	ghost.arcthru(3,0,1);
	ghost.dashon.settrue();
	ghost.dsratio.set(0);
	ghost.thickness.scale(1.8);
	pg.output();
	return 0;
	}
Exemple #9
0
void Ghost::initializeGL(QGLWidget& target) {
    QImage ghost("../gfx/ghost.png");
    _ghostTexture = target.bindTexture(ghost);

    _sphereList = glGenLists(1);
    _sphereQuadric = gluNewQuadric();
    gluQuadricTexture(_sphereQuadric, true);

    glNewList(_sphereList, GL_COMPILE);
    {
        glBindTexture(GL_TEXTURE_2D, _ghostTexture);
        _material.updateGlState(Material::Front);
        glRotatef(180, 1.0f, 0.0f, 0.0f);
        gluSphere(_sphereQuadric, _radius, 360/5, 180/5);
    }
    glEndList();
}
Exemple #10
0
void test_adp_boundary() {
	std::cout << "test adapt initial vof  ================\n";
	Grid_<Float, Float, 2> g(4, -2.0, 1, //
			4, -2.0, 1);
	g.connect_root();
	std::cout << "num root : " << g.get_num_root() << std::endl;
	Adaptive_<Float, Float, 2> adp(&g, 2, 5);
	//adp.adapt_full();
    //g.show_info();
	// shape
	Shape2D cir;
	CreatCircle(cir, 0.0, 0.0, 1.0, 359);
	adp.adapt_inner_solid(cir);
	// ==============================
	// shape for vof
	Shape2D cir2;
	CreatCircle(cir2, 0.0, 0.0, 1.5, 359);
	adp.adapt_vof(cir2);
	g.new_data_on_leaf(1, 0, 0, 1);
	Vof_<Float, Float, 2> vof(&g, 0, 0);
	vof.set_color(cir2);
	g.connect_nodes();
	// boundary ====
	Ghost_<Float, Float, 2> ghost(&g);

	// show ================================
	std::list<Gnuplot_actor> lga;
	Gnuplot_actor ga;
	//GnuplotActor_LeafNodesContours(ga, g, 0);
	//lga.push_back(ga);
	GnuplotActor_LeafNodes(ga, g);
	lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir);
	//lga.push_back(ga);
	//GnuplotActor_Shape2D(ga, cir2);
	//lga.push_back(ga);
	//GnuplotActor_Vof2D(ga, vof);
	//lga.push_back(ga);
	Gnuplot gp;
	gp.set_equal_ratio();
	//gp.set_xrange(-1.5, 0);
	//gp.set_yrange(0, 1.5);
	gp.plot(lga);
}
void BattleCommanderStateDirection::SetGhostAsMovement(void){
	int player_count(_accessor->GetPlayerCount());
	for(int i=0; i<player_count; i++){
		ActorCursor* cursor(_accessor->GetPlayerCursor(i));
		BattleActorGhost* ghost(_accessor->GetPlayerGhost(i));
		BattleActor* player(_accessor->GetPlayer(i));
		if(ghost == nullptr || player == nullptr){continue;}
		if(cursor == nullptr || !cursor->IsActive()){
			ghost->SetVisible(false);
			continue;
		}

		//update position
		D3DXVECTOR3 position(0.0f, 0.0f, 0.0f);
		Cursor3D* cursor3d(_accessor->GetCursor3D());
		if(cursor3d != nullptr){
			position = cursor3d->GetPosition();
		}
		ghost->SetPosition(position);

		//update rotation
		D3DXVECTOR3 player_position(0.0f, 0.0f, 0.0f);
		if(player != nullptr){
			player_position = player->GetPosition();
		}
		D3DXVECTOR3 direction(position - player_position);
		if(D3DXVec3Dot(&direction, &direction) > 0.0f){
			D3DXVec3Normalize(&direction, &direction);
		}
		D3DXVECTOR3 rotation(0.0f, 0.0f, 0.0f);
		rotation.y = atan2(direction.x, direction.z);
		ghost->SetRotation(rotation);

		//play animation

		ghost->SetVisible(true);
	}
}
Exemple #12
0
int main(int argc, char* argv[])
{
	/*!
	 * \page Vector_5_md_vl_sym_crs Vector 5 molecular dynamic with symmetric Verlet list crossing scheme
	 *
	 * ## Simulation ## {#md_e5_sym_sim_crs}
	 *
	 * The simulation is equal to the simulation explained in the example molecular dynamic
	 *
	 * \see \ref md_e5_sym
	 *
	 * The difference is that we create a symmetric Verlet-list for crossing scheme instead of a normal one
	 * \snippet Vector/5_molecular_dynamic_sym_crs/main.cpp sim verlet
	 *
	 * The rest of the code remain unchanged
	 *
	 * \snippet Vector/5_molecular_dynamic_sym_crs/main.cpp simulation
	 *
	 */

	//! \cond [simulation] \endcond

	double dt = 0.00025;
	double sigma = 0.1;
	double r_cut = 3.0*sigma;
	double r_gskin = 1.3*r_cut;
	double sigma12 = pow(sigma,12);
	double sigma6 = pow(sigma,6);

	openfpm::vector<double> x;
	openfpm::vector<openfpm::vector<double>> y;

	openfpm_init(&argc,&argv);
	Vcluster & v_cl = create_vcluster();

	// we will use it do place particles on a 10x10x10 Grid like
	size_t sz[3] = {10,10,10};

	// domain
	Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});

	// Boundary conditions
	size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};

	// ghost, big enough to contain the interaction radius
	Ghost<3,float> ghost(r_gskin);
	ghost.setLow(0,0.0);
	ghost.setLow(1,0.0);
	ghost.setLow(2,0.0);

	vector_dist<3,double, aggregate<double[3],double[3]> > vd(0,box,bc,ghost,BIND_DEC_TO_GHOST);

	size_t k = 0;
	size_t start = vd.accum();

	auto it = vd.getGridIterator(sz);

	while (it.isNext())
	{
		vd.add();

		auto key = it.get();

		vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
		vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
		vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);

		vd.template getLastProp<velocity>()[0] = 0.0;
		vd.template getLastProp<velocity>()[1] = 0.0;
		vd.template getLastProp<velocity>()[2] = 0.0;

		vd.template getLastProp<force>()[0] = 0.0;
		vd.template getLastProp<force>()[1] = 0.0;
		vd.template getLastProp<force>()[2] = 0.0;

		k++;
		++it;
	}

	vd.map();
	vd.ghost_get<>();

	timer tsim;
	tsim.start();

	//! \cond [sim verlet] \endcond

	// Get the Cell list structure
	auto NN = vd.getVerletCrs(r_gskin);;

	//! \cond [sim verlet] \endcond

	// calculate forces
	calc_forces(vd,NN,sigma12,sigma6,r_cut);
	unsigned long int f = 0;

	int cnt = 0;
	double max_disp = 0.0;

	// MD time stepping
	for (size_t i = 0; i < 10000 ; i++)
	{
		// Get the iterator
		auto it3 = vd.getDomainIterator();

		double max_displ = 0.0;

		// integrate velicity and space based on the calculated forces (Step1)
		while (it3.isNext())
		{
			auto p = it3.get();

			// here we calculate v(tn + 0.5)
			vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
			vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
			vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];

			Point<3,double> disp({vd.template getProp<velocity>(p)[0]*dt,vd.template getProp<velocity>(p)[1]*dt,vd.template getProp<velocity>(p)[2]*dt});

			// here we calculate x(tn + 1)
			vd.getPos(p)[0] += disp.get(0);
			vd.getPos(p)[1] += disp.get(1);
			vd.getPos(p)[2] += disp.get(2);

			if (disp.norm() > max_displ)
				max_displ = disp.norm();

			++it3;
		}

		if (max_disp < max_displ)
			max_disp = max_displ;

		// Because we moved the particles in space we have to map them and re-sync the ghost
		if (cnt % 10 == 0)
		{
			vd.map();
			vd.template ghost_get<>();
			// Get the Cell list structure
			vd.updateVerlet(NN,r_gskin,VL_CRS_SYMMETRIC);
		}
		else
		{
			vd.template ghost_get<>(SKIP_LABELLING);
		}

		cnt++;

		// calculate forces or a(tn + 1) Step 2
		calc_forces(vd,NN,sigma12,sigma6,r_cut);

		// Integrate the velocity Step 3
		auto it4 = vd.getDomainIterator();

		while (it4.isNext())
		{
			auto p = it4.get();

			// here we calculate v(tn + 1)
			vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
			vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
			vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];

			++it4;
		}

		// After every iteration collect some statistic about the confoguration
		if (i % 100 == 0)
		{
			// We write the particle position for visualization (Without ghost)
			vd.deleteGhost();
			vd.write("particles_",f);

			// we resync the ghost
			vd.ghost_get<>();


			// We calculate the energy
			double energy = calc_energy(vd,NN,sigma12,sigma6,r_cut);
			auto & vcl = create_vcluster();
			vcl.sum(energy);
			vcl.max(max_disp);
			vcl.execute();

			// we save the energy calculated at time step i c contain the time-step y contain the energy
			x.add(i);
			y.add({energy});

			// We also print on terminal the value of the energy
			// only one processor (master) write on terminal
			if (vcl.getProcessUnitID() == 0)
				std::cout << "Energy: " << energy << "   " << max_disp << "   " << std::endl;

			max_disp = 0.0;

			f++;
		}
	}

	tsim.stop();
	std::cout << "Time: " << tsim.getwct()  << std::endl;

	//! \cond [simulation] \endcond

	// Google charts options, it store the options to draw the X Y graph
	GCoptions options;

	// Title of the graph
	options.title = std::string("Energy with time");

	// Y axis name
	options.yAxis = std::string("Energy");

	// X axis name
	options.xAxis = std::string("iteration");

	// width of the line
	options.lineWidth = 1.0;

	// Object that draw the X Y graph
	GoogleChart cg;

	// Add the graph
	// The graph that it produce is in svg format that can be opened on browser
	cg.AddLinesGraph(x,y,options);

	// Write into html format
	cg.write("gc_plot2_out.html");

	//! \cond [google chart] \endcond

	/*!
	 * \page Vector_5_md_vl_sym_crs Vector 5 molecular dynamic with symmetric Verlet list crossing scheme
	 *
	 * ## Finalize ## {#finalize_v_e5_md_sym_crs}
	 *
	 *  At the very end of the program we have always to de-initialize the library
	 *
	 * \snippet Vector/5_molecular_dynamic_sym_crs/main.cpp finalize
	 *
	 */

	//! \cond [finalize] \endcond

	openfpm_finalize();

	//! \cond [finalize] \endcond

	/*!
	 * \page Vector_5_md_vl_sym_crs Vector 5 molecular dynamic with symmetric Verlet list crossing scheme
	 *
	 * ## Full code ## {#full_code_v_e5_md_sym_crs}
	 *
	 * \include Vector/5_molecular_dynamic_sym_crs/main.cpp
	 *
	 */
}
Exemple #13
0
void
concater_rep::ghost (string s, path ip) {
  ghost (s, ip, blue);
}
int main(int argc, char* argv[])
{
    /*!
     *
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * ## Initialization ##
     *
     * The initialization is the same as the molecular dynamic example. The differences are in the
     * parameters. We will use a bigger system, with more particles. The delta time for integration
     * is chosen in order to keep the system stable.
     *
     * \see \ref e3_md_init
     *
     * \snippet Vector/4_reorder/main_comp_ord.cpp vect create
     *
     */

    //! \cond [vect create] \endcond

    double dt = 0.0001;
    float r_cut = 0.03;
    double sigma = r_cut/3.0;
    double sigma12 = pow(sigma,12);
    double sigma6 = pow(sigma,6);

    openfpm::vector<double> x;
    openfpm::vector<openfpm::vector<double>> y;

    openfpm_init(&argc,&argv);
    Vcluster & v_cl = create_vcluster();

    // we will use it do place particles on a 40x40x40 Grid like
    size_t sz[3] = {40,40,40};

    // domain
    Box<3,float> box({0.0,0.0,0.0}, {1.0,1.0,1.0});

    // Boundary conditions
    size_t bc[3]= {PERIODIC,PERIODIC,PERIODIC};

    // ghost, big enough to contain the interaction radius
    Ghost<3,float> ghost(r_cut);

    vector_dist<3,double, aggregate<double[3],double[3]> > vd(0,box,bc,ghost);

    //! \cond [vect create] \endcond

    /*!
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * ## Particles on a grid like position ##
     *
     * Here we place the particles on a grid like manner
     *
     * \see \ref e3_md_gl
     *
     * \snippet Vector/4_reorder/main_comp_ord.cpp vect grid
     *
     */

    //! \cond [vect grid] \endcond

    auto it = vd.getGridIterator(sz);

    while (it.isNext())
    {
        vd.add();

        auto key = it.get();

        vd.getLastPos()[0] = key.get(0) * it.getSpacing(0);
        vd.getLastPos()[1] = key.get(1) * it.getSpacing(1);
        vd.getLastPos()[2] = key.get(2) * it.getSpacing(2);

        vd.template getLastProp<velocity>()[0] = 0.0;
        vd.template getLastProp<velocity>()[1] = 0.0;
        vd.template getLastProp<velocity>()[2] = 0.0;

        vd.template getLastProp<force>()[0] = 0.0;
        vd.template getLastProp<force>()[1] = 0.0;
        vd.template getLastProp<force>()[2] = 0.0;

        ++it;
    }

    //! \cond [vect grid] \endcond

    /*!
     *
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * ## Molecular dynamic steps ##
     *
     * Here we do 30000 MD steps using verlet integrator the cycle is the same as the
     * molecular dynamic example. with the following changes.
     *
     * ### Cell lists ###
     *
     * Instead of getting the normal cell list we get an hilbert curve cell-list. Such cell list has a
     * function called **getIterator** used inside the function **calc_forces** and **calc_energy**
     * that iterate across all the particles but in a smart-way. In practice
     * given an r-cut a cell-list is constructed with the provided spacing. Suppose to have a cell-list
     * \f$ m \times n \f$, an hilbert curve \f$ 2^k \times 2^k \f$ is contructed with \f$ k = ceil(log_2(max(m,n))) \f$.
     * Cell-lists are explored according to this Hilbert curve, If a cell does not exist is simply skipped.
     *
     *
     * \verbatim
    +------+------+------+------+     Example of Hilbert curve running on a 3 x 3 Cell
    |      |      |      |      |     An hilbert curve of k = ceil(log_2(3)) = 4
    |  X+---->X   |  X +---> X  |
    |  ^   |  +   |  ^   |   +  |
    ***|******|******|****---|--+      *******
    *  +   |  v   |  +   *   v  |      *     *
    *  7   |  8+---->9   *   X  |      *     *  = Domain
    *  ^   |      |      *   +  |      *     *
    *--|-----------------*---|--+      *******
    *  +   |      |      *   v  |
    *  4<----+5   |   6<---+ X  |
    *      |  ^   |   +  *      |
    *---------|-------|--*------+
    *      |  +   |   v  *      |
    *  1+---->2   |   3+---> X  |
    *      |      |      *      |
    **********************------+

     this mean that we will iterate the following cells

     1,2,5,4,7,8,9,6,3

     Suppose now that the particles are ordered like described




    Particles   id      Cell
                 0         1
                 1         7
                 2         8
    			 3		   1
    			 4		   9
    			 5		   9
    			 6		   6
    			 7		   7
    			 8		   3
    			 9		   2
    			10		   4
    			11		   3


    The iterator of the cell-list will explore the particles in the following way

    Cell     1  2 5 4  7  8  9  6 3
       	   |   | | | |   | |   | | |
        	0,3,9,,10,1,7,2,4,5,6,8


     * \endverbatim
     *
     * We cannot explain here what is a cache, but in practice is a fast memory in the CPU able
     * to store chunks of memory. The cache in general is much smaller than RAM, but the big advantage
     * is its speed. Retrieve data from the cache is much faster than RAM. Unfortunately the factors
     *  that determine what is on cache and what is not are multiples: Type of cache, algorithm ... .
     * Qualitatively all caches will tend to load chunks of data that you read multiple-time, or chunks
     *  of data that probably you will read based on pattern analysis. A small example is a linear memory copy where
     * you read consecutively memory and you write on consecutive memory.
     * Modern CPU recognize such pattern and decide to load on cache the consecutive memory before
     *  you actually require it.
     *
     *
     * Iterating the vector in the way described above has the advantage that when we do computation on particles
     * and its neighborhood with the sequence described above it will happen that:
     *
     * * If to process a particle A we read some neighborhood particles to process the next particle A+1
     *   we will probably read most of the previous particles.
     *
     *
     * In order to show in practice what happen we first show the graph when we do not reorder
     *
     * \htmlinclude Vector/4_reorder/no_reorder.html
     *
     * The measure has oscillation but we see an asymptotic behavior from 0.04 in the initial condition to
     * 0.124 . Below we show what happen when we use iterator from the Cell list hilbert
     *
     * \htmlinclude Vector/4_reorder/comp_reord.html
     *
     * In cases where particles does not move or move very slowly consider to use data-reordering, because it can
     * give **8-10% speedup**
     *
     * \see \ref e4_reo
     *
     *  ## Timers ##
     *
     *  In order to collect the time of the force calculation we insert two timers around the function
     *  calc_force. The overall performance is instead calculated with another timer around the time stepping
     *
     * \snippet Vector/4_reorder/main_data_ord.cpp timer start
     * \snippet Vector/4_reorder/main_data_ord.cpp timer stop
     *
     * \see \ref e3_md_vi
     *
     *
     */

    //! \cond [md steps] \endcond

    // Get the Cell list structure
    auto NN = vd.getCellList_hilb(r_cut);

    // calculate forces
    calc_forces(vd,NN,sigma12,sigma6);
    unsigned long int f = 0;

    timer time2;
    time2.start();

#ifndef TEST_RUN
    size_t Nstep = 30000;
#else
    size_t Nstep = 300;
#endif

    // MD time stepping
    for (size_t i = 0; i < Nstep ; i++)
    {
        // Get the iterator
        auto it3 = vd.getDomainIterator();

        // integrate velicity and space based on the calculated forces (Step1)
        while (it3.isNext())
        {
            auto p = it3.get();

            // here we calculate v(tn + 0.5)
            vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
            vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
            vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];

            // here we calculate x(tn + 1)
            vd.getPos(p)[0] += vd.template getProp<velocity>(p)[0]*dt;
            vd.getPos(p)[1] += vd.template getProp<velocity>(p)[1]*dt;
            vd.getPos(p)[2] += vd.template getProp<velocity>(p)[2]*dt;

            ++it3;
        }

        // Because we mooved the particles in space we have to map them and re-sync the ghost
        vd.map();
        vd.template ghost_get<>();

        timer time;
        if (i % 10 == 0)
            time.start();

        // calculate forces or a(tn + 1) Step 2
        calc_forces(vd,NN,sigma12,sigma6);

        if (i % 10 == 0)
        {
            time.stop();
            x.add(i);
            y.add({time.getwct()});
        }

        // Integrate the velocity Step 3
        auto it4 = vd.getDomainIterator();

        while (it4.isNext())
        {
            auto p = it4.get();

            // here we calculate v(tn + 1)
            vd.template getProp<velocity>(p)[0] += 0.5*dt*vd.template getProp<force>(p)[0];
            vd.template getProp<velocity>(p)[1] += 0.5*dt*vd.template getProp<force>(p)[1];
            vd.template getProp<velocity>(p)[2] += 0.5*dt*vd.template getProp<force>(p)[2];

            ++it4;
        }

        // After every iteration collect some statistic about the confoguration
        if (i % 100 == 0)
        {
            // We write the particle position for visualization (Without ghost)
            vd.deleteGhost();
            vd.write("particles_",f);

            // we resync the ghost
            vd.ghost_get<>();

            // We calculate the energy
            double energy = calc_energy(vd,NN,sigma12,sigma6);
            auto & vcl = create_vcluster();
            vcl.sum(energy);
            vcl.execute();

            // We also print on terminal the value of the energy
            // only one processor (master) write on terminal
            if (vcl.getProcessUnitID() == 0)
                std::cout << std::endl << "Energy: " << energy << std::endl;

            f++;
        }
    }

    time2.stop();
    std::cout << "Performance: " << time2.getwct() << std::endl;

    //! \cond [md steps] \endcond

    /*!
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * ## Plotting graphs ##
     *
     * After we terminate the MD steps our vector x contains at which iteration we benchmark the force
     * calculation time, while y contains the measured time at that time-step. We can produce a graph X Y
     *
     * \note The graph produced is an svg graph that can be view with a browser. From the browser we can
     *       also easily save the graph into pure svg format
     *
     * \snippet Vector/4_reorder/main_comp_ord.cpp google chart
     *
     */

    //! \cond [google chart] \endcond

    // Google charts options, it store the options to draw the X Y graph
    GCoptions options;

    // Title of the graph
    options.title = std::string("Force calculation time");

    // Y axis name
    options.yAxis = std::string("Time");

    // X axis name
    options.xAxis = std::string("iteration");

    // width of the line
    options.lineWidth = 1.0;

    // Object that draw the X Y graph
    GoogleChart cg;

    // Add the graph
    // The graph that it produce is in svg format that can be opened on browser
    cg.AddLinesGraph(x,y,options);

    // Write into html format
    cg.write("gc_plot2_out.html");

    //! \cond [google chart] \endcond

    /*!
     *
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * ## Finalize ##
     *
     *  At the very end of the program we have always to de-initialize the library
     *
     * \snippet Vector/4_reorder/main_comp_ord.cpp finalize
     *
     */

    //! \cond [finalize] \endcond

    openfpm_finalize();

    //! \cond [finalize] \endcond

    /*!
     *
     * \page Vector_4_comp_reo Vector 4 computational reordering and cache friendliness
     *
     * # Full code #
     *
     * \include Vector/4_reorder/main_comp_ord.cpp
     *
     */
}
double& unknown::operator ()(const label& ghost, const label& adj_wet)
{
	return operator ()(ghost(0), ghost(1), adj_wet(0), adj_wet(1));
}
Exemple #16
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Orthogonal - set world orientation
   //glTranslated(pos[0],0,pos[1]);
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);
    
    //  Flat or smooth shading
    glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);
    
    // Add light to the scene
    if (light)
    {
        //  Translate intensity to color vectors
        float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
        float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
        float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
        //  Light position
        float Position[]  = {distance*Cos(zh),ylight,distance*Sin(zh),1.0};
        //  Draw light position as ball (still no lighting here)
        glColor3f(1,1,1);
        lightSource(Position[0],Position[1],Position[2] , 0.1);
        //  OpenGL should normalize normal vectors
        glEnable(GL_NORMALIZE);
        //  Enable lighting
        glEnable(GL_LIGHTING);
        //  Location of viewer for specular calculations
        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
        //  glColor sets ambient and diffuse color materials
        glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
        glEnable(GL_COLOR_MATERIAL);
        //  Enable light 0
        glEnable(GL_LIGHT0);
        //  Set ambient, diffuse, specular components and position of light 0
        glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
        glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
        glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
        glLightfv(GL_LIGHT0,GL_POSITION,Position);
    }
    else
        glDisable(GL_LIGHTING);
    // Draw Bell towers
    bell(8,2,-6,.25);
    bell(-8,2,-6,.25);
    
    for (int i = -9; i <= 9; i+=2){
        for (int j = -5; j <= 5; j +=4){
            floorTiles(i,-.5,j,1.2,0);
        }
    }
    for (int i = -8; i <= 8; i+=2){
        for (int j = -3; j <= 5; j +=4){
            floorTiles(i,-.5,j,1.2,.5);
        }
    }
   
    
   // Draw Game grid
     for (int k = -4; k <= -1; k++){
        cube(k,0,-4, .5,.5,.5 , 0);
        cube(k,0,4, .5,.5,.5 , 0);
        cube(-4,0,k, .5,.5,.5 , 0);
        cube(4,0,k, .5,.5,.5 , 0);
    }
    for (int k = 1; k <= 4; k++){
        cube(k,0,-4, .5,.5,.5 , 0);
        cube(k,0,4, .5,.5,.5 , 0);
        cube(-4,0,k, .5,.5,.5 , 0);
        cube(4,0,k, .5,.5,.5 , 0);
    }
    for (int k = -10; k <= 10; k++){
        cube(k,0,-6, .5,.5,.5 , 0);
        cube(k,0,6, .5,.5,.5 , 0);
    }
    for (int k = -6; k <= 6; k++){
        cube(-10,0,k, .5,.5,.5 , 0);
        cube(10,0,k, .5,.5,.5 , 0);
    }
    for (int k = -4; k <= 4; k++){
        cube(-8,0,k, .5,.5,.5 , 0);
        cube(8,0,k, .5,.5,.5 , 0);
    }
    for (int k = -6; k <= -5; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int k = -3; k <= 3; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int k = 5; k <= 6; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int j = -2; j <= -1; j++){
        cube(j,0,-2, .5,.5,.5 , 0);
        cube(j,0,2, .5,.5,.5 , 0);
        cube(-2,0,j, .5,.5,.5 , 0);
        cube(2,0,j, .5,.5,.5 , 0);
    }
    for (int l = 1; l <= 2; l++){
        cube(l,0,-2, .5,.5,.5 , 0);
        cube(l,0,2, .5,.5,.5 , 0);
        cube(-2,0,l, .5,.5,.5 , 0);
        cube(2,0,l, .5,.5,.5 , 0);
    }
    for (int i = -6; i <= 6; i++){
        for (int j = -10; j <= 10; j++){
            if (balls[i+6][j+10] == 1){
                ball(j,0,i, 0.1,4);
            }
        }
    }
    
   // Draw ghosts and animate movement
    //Red Ghost Movement
    if (redTrack == 0){
        posx1 += dx;
        ghost(posx1,0,-5 , 0.4, 0, 0);
        if (posx1 >= -7){
            redTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 1){
        posz1 += dx;
        ghost(-7,0,posz1 , 0.4, 0, 0);
        if (posz1 >= 5){
            redTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 2){
        posx1 -= dx;
        ghost(posx1,0,5 , 0.4, 0, 0);
        if (posx1 <= -9){
            redTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 3){
        posz1 -= dx;
        ghost(-9,0,posz1 , 0.4, 0, 0);
        if (posz1 <= -5){
            redTrack = 0;
        }
        glutIdleFunc(idle);
    }
   
    //Blue Ghost Movement
    if (blueTrack == 0){
        posx2 += dx;
        ghost(posx2,0,-5 , 0.4, 0, 1);
        if (posx2 >= 5){
            blueTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 1){
        posz2 += dx;
        ghost(5,0,posz2 , 0.4, 0, 1);
        if (posz2 >= 5){
            blueTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 2){
        posx2 -= dx;
        ghost(posx2,0,5 , 0.4, 0, 1);
        if (posx2 <= -5){
            blueTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 3){
        posz2 -= dx;
        ghost(-5,0,posz2 , 0.4, 0, 1);
        if (posz2 <= -5){
            blueTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    //Pink Ghost Movement
    if (pinkTrack == 0){
        posx3 += dx;
        ghost(posx3,0,-5 , 0.4, 0, 2);
        if (posx3 >= 9){
            pinkTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 1){
        posz3 += dx;
        ghost(9,0,posz3 , 0.4, 0, 2);
        if (posz3 >= 5){
            pinkTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 2){
        posx3 -= dx;
        ghost(posx3,0,5 , 0.4, 0, 2);
        if (posx3 <= 7){
            pinkTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 3){
        posz3 -= dx;
        ghost(7,0,posz3 , 0.4, 0, 2);
        if (posz1 <= -5){
            pinkTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    //Orange Ghost Movement
    if (orangeTrack == 0){
        posx4 += dx;
        ghost(posx4,0,-3 , 0.4, 0, 3);
        if (posx4 >= 3){
            orangeTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 1){
        posz4 += dx;
        ghost(3,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 0){
            orangeTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 2){
        posx4 += dx;
        ghost(posx4,0,0 , 0.4, 0, 3);
        if (posx4 >= 5){
            orangeTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 3){
        posz4 -= dx;
        ghost(5,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -4){
            orangeTrack = 4;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 4){
        posx4 += dx;
        ghost(posx4,0,-4 , 0.4, 0, 3);
        if (posx4 >= 7){
            orangeTrack = 5;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 5){
        posz4 += dx;
        ghost(7,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 4){
            orangeTrack = 6;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 6){
        posx4 -= dx;
        ghost(posx4,0,4 , 0.4, 0, 3);
        if (posx4 <= 5){
            orangeTrack = 7;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 7){
        posz4 += dx;
        ghost(5,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 5){
            orangeTrack = 8;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 8){
        posx4 -= dx;
        ghost(posx4,0,5 , 0.4, 0, 3);
        if (posx4 <= -5){
            orangeTrack = 9;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 9){
        posz4 -= dx;
        ghost(-5,0,posz4 , 0.4, 0, 3);
        if (posz4 <= 4){
            orangeTrack = 10;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 10){
        posx4 -= dx;
        ghost(posx4,0,4 , 0.4, 0, 3);
        if (posx4 <= -7){
            orangeTrack = 11;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 11){
        posz4 -= dx;
        ghost(-7,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -4){
            orangeTrack = 12;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 12){
        posx4 += dx;
        ghost(posx4,0,-4 , 0.4, 0, 3);
        if (posx4 >= -5){
            orangeTrack = 13;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 13){
        posz4 += dx;
        ghost(-5,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 0){
            orangeTrack = 14;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 14){
        posx4 += dx;
        ghost(posx4,0,0 , 0.4, 0, 3);
        if (posx4 >= -3){
            orangeTrack = 15;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 15){
        posz4 -= dx;
        ghost(-3,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -3){
            orangeTrack = 16;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 16){
        posx4 += dx;
        ghost(posx4,0,-3 , 0.4, 0, 3);
        if (posx4 >= 0){
            orangeTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    // Win condition
    if (score == 132){
        glPopMatrix();
        glDisable(GL_LIGHTING);
        //  Display parameters
        glColor3f(1,1,1);
        glWindowPos2i(400,400);
        Print("Congratulations: You Win");
        pos[0] = 0;
        pos[1] = 0;
    }
    
   // Detect ghost collision
   if ((pos[0] == posx1 && pos[1] == posz1) ||
        (pos[0] == posx2 && pos[1] == posz2) ||
        (pos[0] == posx3 && pos[1] == posz3) ||
        (pos[0] == posx4 && pos[1] == posz4)){
        lives--;
        dead = 1;
        if (lives == 0){
            done = 1;
        }
    }
    // Draw Pacman
    if (dead == 0){
        pacman(pos[0],0,pos[1], .4,0,press);
    }
    else if (done == 1){
        glPopMatrix();
        glDisable(GL_LIGHTING);
        //  Display parameters
        glColor3f(1,1,1);
        glWindowPos2i(400,400);
        Print("Game Over");
        pos[0] = 0;
        pos[1] = 0;
    }
    else{
        pos[0] = 0;
        pos[1] = 0;
        dead = 0;
        pacman(pos[0],0,pos[1], .4,0,press);
        glutPostRedisplay();
    }

   glPopMatrix();
   glDisable(GL_LIGHTING);
   //  Display parameters
   glColor3f(1,1,1);
   glWindowPos2i(5,5);
   Print("Lives:%i Score=%i",lives,score);
   //  Render the scene and make it visible
   glFlush();
   glutSwapBuffers();
}