Exemplo n.º 1
0
  int check_burning_wind(int** forest, int row_index, int col_index, int neighbourhood_type, int wind_speed, int wind_direction, long double pImmune,int rows, int cols)
  {
    int i=row_index;
    int j=col_index;
    int neighbour_status = -5;
    switch(wind_speed)
      {
      case 0:
	return TREE;
	break;
      case 2:
			
	switch(wind_direction)
	  {
	  case SOUTH:
	    neighbour_status = forest[Nr(Nr(i))%rows][Nc(Nc(j))%cols];
	    break;
	  case NORTH:
	    neighbour_status = forest[Sr(Sr(i))%rows][Sc(Sc(j))%cols];
	    break;
	  case EAST:
	    neighbour_status = forest[Wr(Wr(i))%rows][Wc(Wc(j))%cols];
	    break;
	  case WEST:
	    neighbour_status = forest[Er(Er(i))%rows][Ec(Ec(j))%cols];
	    break;
	  }
	if (pImmune<U && neighbour_status == BURNING)
	  return BURNING;
      case 1:
	neighbour_status = -5;
	switch(wind_direction)
	  {
	  case SOUTH:
	    neighbour_status = forest[Nr(i)][Nc(j)];
	    break;
	  case NORTH:
	    neighbour_status = forest[Sr(i)][Sc(j)];
	    break;
	  case EAST:
	    neighbour_status = forest[Wr(i)][Wc(j)];
	    break;
	  case WEST:
	    neighbour_status = forest[Er(i)][Ec(j)];
	    break;
	  }
	if (pImmune<U && neighbour_status == BURNING)
	  return BURNING;
	else
	  return TREE;	
      }
	
  }
Exemplo n.º 2
0
void Foam::tetrahedron<Point, PointRef>::gradNiDotGradNj
(
    scalarField& buffer
) const
{
    // Warning. Ordering of edges needs to be the same for a tetrahedron
    // class, a tetrahedron cell shape model and a tetCell

    // Warning: Added a mag to produce positive coefficients even if
    // the tetrahedron is twisted inside out.  This is pretty
    // dangerous, but essential for mesh motion.

    // Double change of sign between face area vector and gradient

    scalar magVol = Foam::mag(mag());
    vector sa = Sa();
    vector sb = Sb();
    vector sc = Sc();
    vector sd = Sd();

    buffer[0] = (1.0/9.0)*(sa & sb)/magVol;
    buffer[1] = (1.0/9.0)*(sa & sc)/magVol;
    buffer[2] = (1.0/9.0)*(sa & sd)/magVol;
    buffer[3] = (1.0/9.0)*(sd & sb)/magVol;
    buffer[4] = (1.0/9.0)*(sb & sc)/magVol;
    buffer[5] = (1.0/9.0)*(sd & sc)/magVol;
}
Exemplo n.º 3
0
int do_neighbours_burn(int** forest,int row_index,int col_index)
{
	return (forest[Nr(row_index)][Nc(col_index)]==BURNING ||
	    forest[Er(row_index)][Ec(col_index)]==BURNING ||
	    forest[Wr(row_index)][Wc(col_index)]==BURNING ||
	    forest[Sr(row_index)][Sc(col_index)]==BURNING
	    );
}
Exemplo n.º 4
0
  /* This counts the number of burning neighbours */
  int count_burning_neighbours(int** forest, int row_index, int col_index, int neighbourhood_type){
    int neighbors_on_fire=0;
    int i=row_index;
    int j=col_index;

    switch(neighbourhood_type){
    case VON_NEUMANN:
      if(forest[Nr(i)][Nc(j)]>=BURNING && forest[Nr(i)][Nc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Er(i)][Ec(j)]>=BURNING && forest[Er(i)][Ec(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Wr(i)][Wc(j)]>=BURNING && forest[Wr(i)][Wc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Sr(i)][Sc(j)]>=BURNING && forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      break;
    case MOORE:
      if(forest[Nr(i)][Nc(j)]>=BURNING && forest[Nr(i)][Nc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Er(i)][Ec(j)]>=BURNING && forest[Er(i)][Ec(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Wr(i)][Wc(j)]>=BURNING && forest[Wr(i)][Wc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Sr(i)][Sc(j)]>=BURNING && forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      /* Diagonals */
      if(forest[NEr(i)][NEc(j)]>=BURNING && forest[NEr(i)][NEc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[SEr(i)][SEc(j)]>=BURNING && forest[SEr(i)][SEc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[NWr(i)][NWc(j)]>=BURNING && forest[NWr(i)][NWc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[SWr(i)][SWc(j)]>=BURNING && forest[SWr(i)][SWc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      break;
    default:
      break;
    }
    return neighbors_on_fire;
  }
Exemplo n.º 5
0
  /* This returns 1 if any neighbours burn, 0 otherwise */
  int do_neighbours_burn(int** forest, int row_index, int col_index, int neighbourhood_type){

    int i=row_index;
    int j=col_index;
  
    switch(neighbourhood_type){
    case VON_NEUMANN:
      return ((forest[Nr(i)][Nc(j)]>=BURNING &&
	       forest[Nr(i)][Nc(j)]<=OLD_BURNING) ||
	      (forest[Er(i)][Ec(j)]>=BURNING &&
	       forest[Er(i)][Ec(j)]<=OLD_BURNING) ||
	      (forest[Wr(i)][Wc(j)]>=BURNING &&
	       forest[Wr(i)][Wc(j)]<=OLD_BURNING) ||
	      (forest[Sr(i)][Sc(j)]>=BURNING &&
	       forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	      );
    case MOORE:
      return ((forest[Nr(i)][Nc(j)]>=BURNING &&
	       forest[Nr(i)][Nc(j)]<=OLD_BURNING) ||
	      (forest[Er(i)][Ec(j)]>=BURNING &&
	       forest[Er(i)][Ec(j)]<=OLD_BURNING) ||
	      (forest[Wr(i)][Wc(j)]>=BURNING &&
	       forest[Wr(i)][Wc(j)]<=OLD_BURNING) ||
	      (forest[Sr(i)][Sc(j)]>=BURNING &&
	       forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	      ||
	      //Diagonals
	      (forest[NEr(i)][NEc(j)]>=BURNING &&
	       forest[NEr(i)][NEc(j)]<=OLD_BURNING) ||
	      (forest[SEr(i)][SEc(j)]>=BURNING &&
	       forest[SEr(i)][SEc(j)]<=OLD_BURNING) ||
	      (forest[NWr(i)][NWc(j)]>=BURNING &&
	       forest[NWr(i)][NWc(j)]<=OLD_BURNING) ||
	      (forest[SWr(i)][SWc(j)]>=BURNING &&
	       forest[SWr(i)][SWc(j)]<=OLD_BURNING)
	      );
    default:
      return 0;
    }
  }
Exemplo n.º 6
0
void Foam::tetrahedron<Point, PointRef>::gradNiGradNi
(
    tensorField& buffer
) const
{
    // Change of sign between face area vector and gradient
    // does not matter because of square

    scalar magVol = Foam::mag(mag());

    buffer[0] = (1.0/9.0)*sqr(Sa())/magVol;
    buffer[1] = (1.0/9.0)*sqr(Sb())/magVol;
    buffer[2] = (1.0/9.0)*sqr(Sc())/magVol;
    buffer[3] = (1.0/9.0)*sqr(Sd())/magVol;
}
Exemplo n.º 7
0
void Foam::tetrahedron<Point, PointRef>::gradNiSquared
(
    scalarField& buffer
) const
{
    // Change of sign between face area vector and gradient
    // does not matter because of square

    // Warning: Added a mag to produce positive coefficients even if
    // the tetrahedron is twisted inside out.  This is pretty
    // dangerous, but essential for mesh motion.
    scalar magVol = Foam::mag(mag());

    buffer[0] = (1.0/9.0)*magSqr(Sa())/magVol;
    buffer[1] = (1.0/9.0)*magSqr(Sb())/magVol;
    buffer[2] = (1.0/9.0)*magSqr(Sc())/magVol;
    buffer[3] = (1.0/9.0)*magSqr(Sd())/magVol;
}
Exemplo n.º 8
0
void Foam::tetrahedron<Point, PointRef>::gradNiGradNj
(
    tensorField& buffer
) const
{
    // Warning. Ordering of edges needs to be the same for a tetrahedron
    // class, a tetrahedron cell shape model and a tetCell

    // Double change of sign between face area vector and gradient

    scalar magVol = Foam::mag(mag());
    vector sa = Sa();
    vector sb = Sb();
    vector sc = Sc();
    vector sd = Sd();

    buffer[0] = (1.0/9.0)*(sa * sb)/magVol;
    buffer[1] = (1.0/9.0)*(sa * sc)/magVol;
    buffer[2] = (1.0/9.0)*(sa * sd)/magVol;
    buffer[3] = (1.0/9.0)*(sd * sb)/magVol;
    buffer[4] = (1.0/9.0)*(sb * sc)/magVol;
    buffer[5] = (1.0/9.0)*(sd * sc)/magVol;
}
Exemplo n.º 9
0
void parcel::setRelaxationTimes
(
    label celli,
    scalar& tauMomentum,
    scalarField& tauEvaporation,
    scalar& tauHeatTransfer,
    scalarField& tauBoiling,
    const spray& sDB,
    const scalar rho,
    const vector& Up,
    const scalar temperature,
    const scalar pressure,
    const scalarField& Yfg,
    const scalarField& m0,
    const scalar dt
)
{

    const liquidMixture& fuels = sDB.fuels();

    scalar mCell = rho*sDB.mesh().V()[cell()];
    scalarField mfg(Yfg*mCell);

    label Ns = sDB.composition().Y().size();
    label Nf = fuels.components().size();

    // Tf is based on the 1/3 rule
    scalar Tf  = T() + (temperature - T())/3.0;

    // calculate mixture properties
    scalar W = 0.0;
    scalar kMixture = 0.0;
    scalar cpMixture = 0.0;
    scalar muf = 0.0;

    for(label i=0; i<Ns; i++)
    {
        scalar Y = sDB.composition().Y()[i][celli];
        W += Y/sDB.gasProperties()[i].W();
        // Using mass-fractions to average...
        kMixture += Y*sDB.gasProperties()[i].kappa(Tf);
        cpMixture += Y*sDB.gasProperties()[i].Cp(Tf);
        muf += Y*sDB.gasProperties()[i].mu(Tf);
    }
    W = 1.0/W;

    scalarField Xf(Nf, 0.0);
    scalarField Yf(Nf, 0.0);
    scalarField psat(Nf, 0.0);
    scalarField msat(Nf, 0.0);

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Y = sDB.composition().Y()[j][celli];
        scalar Wi = sDB.gasProperties()[j].W();
        Yf[i] = Y;
        Xf[i] = Y*W/Wi;
        psat[i] = fuels.properties()[i].pv(pressure, temperature);
        msat[i] = min(1.0, psat[i]/pressure)*Wi/W;
    }

    scalar nuf = muf/rho;

    scalar liquidDensity = fuels.rho(pressure, T(), X());
    scalar liquidcL = fuels.cp(pressure, T(), X());
    scalar heatOfVapour = fuels.hl(pressure, T(), X());

    // calculate the partial rho of the fuel vapour
    // alternative is to use the mass fraction
    // however, if rhoFuelVap is small (zero)
    // d(mass)/dt = 0 => no evaporation... hmmm... is that good? NO!

    // Assume equilibrium at drop-surface => pressure @ surface
    // = vapour pressure to calculate fuel-vapour density @ surface
    scalar pressureAtSurface = fuels.pv(pressure, T(), X());
    scalar rhoFuelVap = pressureAtSurface*fuels.W(X())/(specie::RR*Tf);

    scalarField Xs(sDB.fuels().Xs(pressure, temperature, T(), Xf, X()));
    scalarField Ys(Nf, 0.0);
    scalar Wliq = 0.0;

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Wi = sDB.gasProperties()[j].W();
        Wliq += Xs[i]*Wi;
    }

    for(label i=0; i<Nf; i++)
    {
        label j = sDB.liquidToGasIndex()[i];
        scalar Wi = sDB.gasProperties()[j].W();
        Ys[i] = Xs[i]*Wi/Wliq;
    }

    scalar Reynolds = Re(Up, nuf);
    scalar Prandtl = Pr(cpMixture, muf, kMixture);

    // calculate the characteritic times

    if(liquidCore_> 0.5)
    {
//      no drag for parcels in the liquid core..
        tauMomentum = GREAT;
    }
    else
    {
        tauMomentum = sDB.drag().relaxationTime
        (
            Urel(Up),
            d(),
            rho,
            liquidDensity,
            nuf,
            dev()
        );
    }

    // store the relaxationTime since it is needed in some breakup models.
    tMom_ = tauMomentum;

    tauHeatTransfer = sDB.heatTransfer().relaxationTime
    (
        liquidDensity,
        d(),
        liquidcL,
        kMixture,
        Reynolds,
        Prandtl
    );

    // evaporation-properties are evaluated at averaged temperature
    // set the boiling conditions true if pressure @ surface is 99.9%
    // of the pressure
    // this is mainly to put a limit on the evaporation time,
    // since tauEvaporation is very very small close to the boiling point.

    for(label i=0; i<Nf; i++)
    {
        scalar Td = min(T(), 0.999*fuels.properties()[i].Tc());
        bool boiling = fuels.properties()[i].pv(pressure, Td) >= 0.999*pressure;
        scalar Di = fuels.properties()[i].D(pressure, Td);
        scalar Schmidt = Sc(nuf, Di);

        scalar partialPressure = Xf[i]*pressure;

//      saturated vapour
        if(partialPressure > psat[i])
        {
            tauEvaporation[i] = GREAT;
        }
//      not saturated vapour
        else
        {
            if (!boiling)
            {
                // for saturation evaporation, only use 99.99% for numerical robustness
                scalar dm = max(SMALL, 0.9999*msat[i] - mfg[i]);

                tauEvaporation[i] = sDB.evaporation().relaxationTime
                (
                    d(),
                    fuels.properties()[i].rho(pressure, Td),
                    rhoFuelVap,
                    Di,
                    Reynolds,
                    Schmidt,
                    Xs[i],
                    Xf[i],
                    m0[i],
                    dm,
                    dt
                );
            }
            else
            {
                scalar Nusselt =
                    sDB.heatTransfer().Nu(Reynolds, Prandtl);

//              calculating the boiling temperature of the liquid at ambient pressure
                scalar tBoilingSurface = Td;

                label Niter = 0;
                scalar deltaT = 10.0;
                scalar dp0 = fuels.properties()[i].pv(pressure, tBoilingSurface) - pressure;
                while ((Niter < 200) && (mag(deltaT) > 1.0e-3))
                {
                    Niter++;
                    scalar pBoil = fuels.properties()[i].pv(pressure, tBoilingSurface);
                    scalar dp = pBoil - pressure;
                    if ( (dp > 0.0) && (dp0 > 0.0) )
                    {
                        tBoilingSurface -= deltaT;
                    }
                    else
                    {
                        if ( (dp < 0.0) && (dp0 < 0.0) )
                        {
                            tBoilingSurface += deltaT;
                        }
                        else
                        {
                            deltaT *= 0.5;
                            if ( (dp > 0.0) && (dp0 < 0.0) )
                            {
                                tBoilingSurface -= deltaT;
                            }
                            else
                            {
                                tBoilingSurface += deltaT;
                            }
                        }
                    }
                    dp0 = dp;
                }

                scalar vapourSurfaceEnthalpy = 0.0;
                scalar vapourFarEnthalpy = 0.0;

                for(label k = 0; k < sDB.gasProperties().size(); k++)
                {
                    vapourSurfaceEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(tBoilingSurface);
                    vapourFarEnthalpy += sDB.composition().Y()[k][celli]*sDB.gasProperties()[k].H(temperature);
                }

                scalar kLiquid = fuels.properties()[i].K(pressure, 0.5*(tBoilingSurface+T()));

                tauBoiling[i] = sDB.evaporation().boilingTime
                (
                    fuels.properties()[i].rho(pressure, Td),
                    fuels.properties()[i].cp(pressure, Td),
                    heatOfVapour,
                    kMixture,
                    Nusselt,
                    temperature - T(),
                    d(),
                    liquidCore(),
                    sDB.runTime().value() - ct(),
                    Td,
                    tBoilingSurface,
                    vapourSurfaceEnthalpy,
                    vapourFarEnthalpy,
                    cpMixture,
                    temperature,
                    kLiquid
                );
            }

        }
    }
}
Exemplo n.º 10
0
void MyWidget::MarchingCubes() {

    Vector **triangles = new Vector*[5];
    for (int i = 0; i < 5; i++) {
        triangles[i] = new Vector[3];
    }

    Matrix T(4, 4);
    T.Diag(1);
    T(0, 3) = Tx + 200;
    T(1, 3) = Ty + 150;
    T(2, 3) = Tz;

    Matrix Sc(4, 4);
    Sc(0, 0) = ScX;
    Sc(1, 1) = ScY;
    Sc(2, 2) = ScZ;
    Sc(3, 3) = 1;

    Matrix RX(4, 4);
    RX.Diag(1);
    RX(1, 1) = cos(AlfaX);
    RX(1, 2) = sin(AlfaX);
    RX(2, 1) = -sin(AlfaX);
    RX(2, 2) = cos(AlfaX);

    Matrix RY(4, 4);
    RY.Diag(1);
    RY(0, 0) = cos(AlfaY);
    RY(0, 2) = -sin(AlfaY);
    RY(2, 0) = sin(AlfaY);
    RY(2, 2) = cos(AlfaY);

    Matrix RZ(4, 4);
    RZ.Diag(1);
    RZ(0, 0) = cos(AlfaZ);
    RZ(0, 1) = sin(AlfaZ);
    RZ(1, 0) = -sin(AlfaZ);
    RZ(1, 1) = cos(AlfaZ);

    Matrix m = T.multi(Sc.multi(RX.multi(RY.multi(RZ))));

    T.free();
    Sc.free();
    RX.free();
    RY.free();
    RZ.free();

    Matrix p;

    for (int x = _S; x < fR2; x += _S) {
        for (int y = _S; y < fR2; y += _S) {
            for (int z = _S; z < fR2; z += _S) {
                int n = Polygonise(x, y, z, 1, triangles);
                for (int i = 0; i < n; i++) {
                    Vector tab[3];
                    for (int j = 0; j < 3; j++) {
                        p = m.multi(triangles[i][j]);
                        tab[j] = Vector(p(X, 0), p(Y, 0), p(Z, 0));
                    }
                    Triangle(_bitsDest, tab[0], tab[1], tab[2]);

                    tab[0].free();
                    tab[1].free();
                    tab[2].free();
                }
            }
        }
    }

    m.free();
    p.free();

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 3; j++) {
            triangles[i][j].free();
        }
    }
}
Exemplo n.º 11
0
		bool TLDDetector::detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
		{
			patches.clear();
			Mat_<uchar> standardPatch(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
			Mat tmp;
			int dx = initSize.width / 10, dy = initSize.height / 10;
			Size2d size = img.size();
			double scale = 1.0;
			int npos = 0, nneg = 0;
			double maxSc = -5.0;
			Rect2d maxScRect;
			int scaleID;
			std::vector <Mat> resized_imgs, blurred_imgs;
			std::vector <Point> varBuffer, ensBuffer;
			std::vector <int> varScaleIDs, ensScaleIDs;

			//Detection part
			//Generate windows and filter by variance
			scaleID = 0;
			resized_imgs.push_back(img);
			blurred_imgs.push_back(imgBlurred);
			do
			{
				Mat_<double> intImgP, intImgP2;
				computeIntegralImages(resized_imgs[scaleID], intImgP, intImgP2);
				for (int i = 0, imax = cvFloor((0.0 + resized_imgs[scaleID].cols - initSize.width) / dx); i < imax; i++)
				{
					for (int j = 0, jmax = cvFloor((0.0 + resized_imgs[scaleID].rows - initSize.height) / dy); j < jmax; j++)
					{
						if (!patchVariance(intImgP, intImgP2, originalVariancePtr, Point(dx * i, dy * j), initSize))
							continue;
						varBuffer.push_back(Point(dx * i, dy * j));
						varScaleIDs.push_back(scaleID);
					}
				}
				scaleID++;
				size.width /= SCALE_STEP;
				size.height /= SCALE_STEP;
				scale *= SCALE_STEP;
				resize(img, tmp, size, 0, 0, DOWNSCALE_MODE);
				resized_imgs.push_back(tmp);
				GaussianBlur(resized_imgs[scaleID], tmp, GaussBlurKernelSize, 0.0f);
				blurred_imgs.push_back(tmp);
			} while (size.width >= initSize.width && size.height >= initSize.height);

			//Encsemble classification
			for (int i = 0; i < (int)varBuffer.size(); i++)
			{
				prepareClassifiers(static_cast<int> (blurred_imgs[varScaleIDs[i]].step[0]));
				if (ensembleClassifierNum(&blurred_imgs[varScaleIDs[i]].at<uchar>(varBuffer[i].y, varBuffer[i].x)) <= ENSEMBLE_THRESHOLD)
					continue;
				ensBuffer.push_back(varBuffer[i]);
				ensScaleIDs.push_back(varScaleIDs[i]);
			}

			//NN classification
			for (int i = 0; i < (int)ensBuffer.size(); i++)
			{
				LabeledPatch labPatch;
				double curScale = pow(SCALE_STEP, ensScaleIDs[i]);
				labPatch.rect = Rect2d(ensBuffer[i].x*curScale, ensBuffer[i].y*curScale, initSize.width * curScale, initSize.height * curScale);
				resample(resized_imgs[ensScaleIDs[i]], Rect2d(ensBuffer[i], initSize), standardPatch);

				double srValue, scValue;
				srValue = Sr(standardPatch);

				////To fix: Check the paper, probably this cause wrong learning
				//
				labPatch.isObject = srValue > THETA_NN;
				labPatch.shouldBeIntegrated = abs(srValue - THETA_NN) < 0.1;
				patches.push_back(labPatch);
				//

				if (!labPatch.isObject)
				{
					nneg++;
					continue;
				}
				else
				{
					npos++;
				}
				scValue = Sc(standardPatch);
				if (scValue > maxSc)
				{
					maxSc = scValue;
					maxScRect = labPatch.rect;
				}
			}

			if (maxSc < 0)
				return false;
			else
			{
				res = maxScRect;
				return true;
			}
		}