예제 #1
0
void FlameMapping::translate(V2f p, V2f df, bool editPreTrans)
{
    FlameMapping tmpMap = *this;
    AffineMap& aff = editPreTrans ? tmpMap.preMap : tmpMap.postMap;
    const float delta = 0.001;
    V2f r0 = tmpMap.map(p);
    aff.c.x += delta;
    V2f r1 = tmpMap.map(p);
    aff.c.x -= delta;
    aff.c.y += delta;
    V2f r2 = tmpMap.map(p);
    V2f drdx = (r1 - r0)/delta;
    V2f drdy = (r2 - r0)/delta;
    M22f dfdc(drdx.x, drdy.x,
                drdx.y, drdy.y);
    V2f dc = dfdc.inv()*df;
    const float maxLength = 2;
    if(dc.length() > maxLength)
        dc *= maxLength/dc.length();
    AffineMap& thisAff = editPreTrans ? preMap : postMap;
    thisAff.c += dc;
}
예제 #2
0
void update(MMSP::grid<dim,T>& grid, int steps)
{
	int rank=0;
	#ifdef MPI_VERSION
	rank = MPI::COMM_WORLD.Get_rank();
	#endif

	// Make sure the grid spacing is correct
	for (int d=0; d<dim; d++) {
		dx(grid,d) = deltaX;
		if (MMSP::x0(grid,d)==MMSP::g0(grid,d))
		    MMSP::b0(grid,d) = Neumann; // enumerated in MMSP.utility.hpp
		else if (MMSP::x1(grid,d)==MMSP::g1(grid,d))
		    MMSP::b1(grid,d) = Neumann; // enumerated in MMSP.utility.hpp
  }

  ghostswap(grid);

    // Let's be absolutely explicit about BCs here.
	MMSP::grid<dim,T> update(grid);
	for (int d=0; d<dim; d++) {
		dx(update,d) = deltaX;
		if (MMSP::x0(update,d)==MMSP::g0(update,d))
		    MMSP::b0(update,d) = Neumann; // enumerated in MMSP.utility.hpp
		else if (MMSP::x1(update,d)==MMSP::g1(update,d))
		    MMSP::b1(update,d) = Neumann; // enumerated in MMSP.utility.hpp
  }

	MMSP::grid<dim,T> temp(grid);
	for (int d=0; d<dim; d++) {
		dx(temp,d) = deltaX;
		if (MMSP::x0(temp,d)==MMSP::g0(temp,d))
		    MMSP::b0(temp,d) = Neumann; // enumerated in MMSP.utility.hpp
		else if (MMSP::x1(temp,d)==MMSP::g1(temp,d))
		    MMSP::b1(temp,d) = Neumann; // enumerated in MMSP.utility.hpp
  }


	for (int step=0; step<steps; step++) {
		for (int n=0; n<nodes(grid); n++) {
			MMSP::vector<int> x = position(grid,n);
			if (isOutside(x)) {
				temp(x) = 0.0;
			} else {
	    		double c = grid(x);
    			temp(x) = dfdc(c) - K*zfLaplacian(grid,x);
			}
		}
		#ifdef MPI_VERSION
		MPI::COMM_WORLD.Barrier();
		#endif
		ghostswap(temp);

		double energy = 0.0;
		double mass = 0.0;
		for (int n=0; n<nodes(grid); n++) {
			MMSP::vector<int> x = position(grid,n);
			if (isOutside(x)) {
				update(x) = 0.0;
			} else {
		    	update(x) = grid(x) + dt*D*zfLaplacian(temp,x);
	    		energy += dx(grid)*dy(grid)*energydensity(update(x));
    			mass += dx(grid)*dy(grid)*update(x);
		    }
		}
		#ifdef MPI_VERSION
		MPI::COMM_WORLD.Barrier();
		double myEnergy = energy;
		double myMass = mass;
		MPI::COMM_WORLD.Reduce(&myEnergy, &energy, 1, MPI_DOUBLE, MPI_SUM, 0);
        MPI::COMM_WORLD.Reduce(&myMass, &mass, 1, MPI_DOUBLE, MPI_SUM, 0);
        #endif
		if (rank==0)
		    std::cout<<energy<<'\t'<<mass<<'\n';

		swap(grid,update);
		ghostswap(grid);
	}
    #ifndef DEBUG
	if (rank==0)
	    std::cout<<std::flush;
	#endif
}