Esempio n. 1
0
void Water3D::drawCellTypes(){
    
    double dx = cellTypes.dx();
    double dy = cellTypes.dy();
    double dz = cellTypes.dz();
    //double dz = cellTypes.mapping.dx();
    for (GridFieldIterator<int> iter = cellTypes.iterator(); !iter.done(); iter.next()) {
        double x,y,z;
        int i,j,k;
        iter.index(i, j, k);
        
        cellTypes.indexToWorld(i, j, k, x, y, z);
        CellType val = static_cast<CellType>(iter.value());
        
        if (val == SOLID){
            glColor3d(1.0, 1.0, 1.0);
            drawVoxel(x, y, z, dx, dy, dz);
        }/*else if (val == BURNT){
            glColor3d(0.0, 0.0, 0.0);
            glVertex3d(x-dx*0.5, y-dy*0.5, z-dz*0.5);
            glVertex3d(x+dx*0.5, y-dy*0.5, z-dz*0.5);
            glVertex3d(x+dx*0.5, y+dy*0.5, z-dz*0.5);
            glVertex3d(x-dx*0.5, y+dy*0.5, z-dz*0.5);
        }else if (val == AIR){
            glColor3d(0.0, 0.0, 0.0);
            glVertex3d(x-dx*0.5, y-dy*0.5, z-dz*0.5);
            glVertex3d(x+dx*0.5, y-dy*0.5, z-dz*0.5);
            glVertex3d(x+dx*0.5, y+dy*0.5, z-dz*0.5);
            glVertex3d(x-dx*0.5, y+dy*0.5, z-dz*0.5);
        }*/
        //glEnd();
        
        if (val == SOLID){
            /*glColor3d(0.0, 0.0, 1.0);
            glBegin(GL_POINTS);
            glVertex3d(x, y, z);
            glVertex3d(x, y, z);
            glEnd();
            */
        }else if (val == AIR){
            glColor3d(1.0, 0.0, 0.0);
            drawVoxel(x, y, z, dx, dy, dz);
        }else if (val == BURNT){
            glColor3d(1.0, 1.0, 0.0);
            drawVoxel(x, y, z, dx, dy, dz);
        }
        

        
    }
}
Esempio n. 2
0
GridField<T>::GridField(const GridField<T> &g):GridMapping(g),_extrapolation(nullptr),_interpolation(nullptr),_extrapolate(true){
	int count = g.cellCount();
	_data = new T[count];

	//Iterera över g
	for (GridFieldIterator<T> iter = g.iterator(); !iter.done(); iter.next()) {
		setValueAtIndex(iter.value(), iter.index());
	}

	//Interpolation
	//Extra/Interpolation
	setInterpolation(g._interpolation);
	setExtrapolation(g._extrapolation);
}
Esempio n. 3
0
void Water3D::recomputeCellTypes(){
    
    
    //Set all to AIR
    for (GridFieldIterator<int> it = cellTypes.iterator(); !it.done(); it.next()) {
        int i,j,k;
        it.index(i, j, k);
        if (cellTypes.valueAtIndex(i, j, k) != SOLID) {
            cellTypes.setValueAtIndex(AIR, it.index());
        }
    }
    
    //Set BURNT if inhabited with marker partile
    #pragma omp parallel for
    for (int index = 0; index < particles.size(); index++) {
        int i,j,k;
        cellTypes.worldToIndex(i, j, k, particles[index].x, particles[index].y, particles[index].z);
        CellType type = static_cast<CellType>(cellTypes.valueAtIndex(i, j, k));
        if (type == AIR) {
            cellTypes.setValueAtIndex(BURNT, i, j, k);
        }
    }
}
Esempio n. 4
0
T GridField<T>::getMax() const
{
	T max;
	GridFieldIterator<T> it = iterator();
	if(!it.done())
		max = valueAtIndex(it.index());
	else
	{
		std::cout << "GridField<T>::getMax() failed!" << std::endl;
		throw;
	}

	for(; !it.done(); it.next())
	{
		T v = valueAtIndex(it.index());
		if(v > max)
			max = v;
	}

	return max;
}
Esempio n. 5
0
void GhostMAC::makeRandom(){
    
    double randMax = 0.0;
    //Fill U
    for (GridFieldIterator<double> iterator = _u->iterator(); !iterator.done(); iterator.next()) {
        int i,j,k;
        double x,y,z;
        iterator.index(i, j, k);
        _u->indexToWorld(i, j, k, x, y, z);
        double v1 = ((double)(rand() % RAND_MAX))/((double)RAND_MAX)*randMax-randMax*0.5;
        double vel = v1;
        _u->setValueAtIndex(vel, iterator.index());
        buffer()->_u->setValueAtIndex(vel, iterator.index());
    }
    
    //Fill V
    for (GridFieldIterator<double> iterator = _v->iterator(); !iterator.done(); iterator.next()) {
        int i,j,k;
        //double x,y,z;
        iterator.index(i, j, k);
        //_v->indexToWorld(i, j, k, x, y, z);
        double v1 =  ((double)(rand() % RAND_MAX))/((double)RAND_MAX)*randMax-randMax*0.5;
        double vel = v1;
        _v->setValueAtIndex(vel, iterator.index());
        buffer()->_v->setValueAtIndex(vel, iterator.index());
    }
    
    //Fill W
    for (GridFieldIterator<double> iterator = _w->iterator(); !iterator.done(); iterator.next()) {
        int i,j,k;
        //double x,y,z;
        iterator.index(i, j, k);
        double v1  = ((double)(rand() % RAND_MAX))/((double)RAND_MAX)*randMax-randMax*0.5;
        double vel = v1;
        _w->setValueAtIndex(vel, iterator.index());
        buffer()->_w->setValueAtIndex(vel, iterator.index());
    }
}
Esempio n. 6
0
Water3D::Water3D(int dim):u(dim,dim,dim,2600),cellTypes(dim,dim,dim,2600, new ClosestValueExtrapolation<int>()){ //TODO KORREKT EXTRAPOLERING?
    
    //Default variables
    g = Vector3(0.0,-3.0,0.0);
    rho = 1.0;
    
    //
    _advect = new MACAdvectRK2<double>();
    
    //Translate dude
    u.multTransformation(glm::translate(-1300.0, -600.0, -800.0));
    //cellTypes.multTransformation(glm::translate(-0.5, -0.2, -0.4));
    cellTypes.setTransformation(u.getTrans());

    //Init environment
    //GridFieldFileManager::readFromFile<int>(cellTypes,"circle");
    
    for (GridFieldIterator<int> iter = cellTypes.iterator(); !iter.done(); iter.next()) {
        int i,j,k;
        iter.index(i, j, k);
        if (i  < 1 || (i >= cellTypes.xdim()-1) || j  < 1 || (j >= cellTypes.ydim()-1) || k  < 1 || (k >= cellTypes.zdim()-1)) {
            cellTypes.setValueAtIndex(SOLID, iter.index());
        }else{
            cellTypes.setValueAtIndex(AIR, iter.index());
        }
    }
    
    //GridFieldFileManager::writeToFile(cellTypes, "circle");
    
    
    //Init marker-particles
    for (GridFieldIterator<int> iter = cellTypes.iterator(); !iter.done(); iter.next()) {
        int i,j,k;
        iter.index(i, j, k);
        double l_x,l_y,l_z;
        cellTypes.indexToLocal(i, j, k, l_x, l_y, l_z);
        double r = 0.25;
        double c_x = 0.5;
        double c_y = 0.6;
        double c_z = 0.5;

        if (r*r > (l_x-c_x)*(l_x-c_x)+(l_y-c_y)*(l_y-c_y)+(l_z-c_z)*(l_z-c_z) && iter.value() != SOLID) {
            double x,y,z;
            cellTypes.indexToWorld(i, j, k, x, y, z);
            
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
        }
        
        if (l_y < 0.25 && iter.value() != SOLID) {
            double x,y,z;
            cellTypes.indexToWorld(i, j, k, x, y, z);
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z-cellTypes.dz()*0.25));
            
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x-cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y-cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
            particles.push_back(Vector3(x+cellTypes.dx()*0.25,y+cellTypes.dy()*0.25,z+cellTypes.dz()*0.25));
        }
    }
    
    
    _projection = new PCGProjection3D(&u,&cellTypes);
}
Esempio n. 7
0
void Water3D::drawFaceVelocities(){
    glColor3f(0,1,0);
    for (GridFieldIterator<double> iter = u._u->iterator(); !iter.done(); iter.next()) {
        int i,j,k;
        iter.index(i, j, k);
        double x,y,z;
        u._u->indexToWorld(i, j, k, x, y, z);
        double val = iter.value();
        glBegin(GL_LINE_STRIP);
        glVertex3d(x, y, z);
        glVertex3d(x+val, y, z);
        glEnd();
    }
    
    glColor3f(1,0,0);
    for (GridFieldIterator<double> iter = u._v->iterator(); !iter.done(); iter.next()) {
        int i,j,k;
        iter.index(i, j, k);
        double x,y,z;
        u._v->indexToWorld(i, j, k, x, y, z);
        double val = iter.value();
        glBegin(GL_LINE_STRIP);
        glVertex3d(x, y, z);
        glVertex3d(x, y+val, z);
        glEnd();
    }
    
    glColor3f(0,0,1);
    for (GridFieldIterator<double> iter = u._w->iterator(); !iter.done(); iter.next()) {
        int i,j,k;
        iter.index(i, j, k);
        double x,y,z;
        u._w->indexToWorld(i, j, k, x, y, z);
        double val = iter.value();
        glBegin(GL_LINE_STRIP);
        glVertex3d(x, y, z);
        glVertex3d(x, y, z+val);
        glEnd();
    }
    
}