void Cabin::randomEvent() { int random = ofRandom(0,8); switch(random) { case 0: turbulence(); break; case 1: cabinCrew(); break; case 2: garbledAnnouncement(); break; case 3: inappropriateComment(); break; case 4: landingGear(); break; case 5: fallingTraytable(); break; case 6: weirdSmell(); break; case 7: babyCrying(); break; } }
Color3f PerlinTexture::sample(Point2f &uv) const { float result = 0.0f; float x = clamp(uv(0), 0.0f, 1.0f) * m_width; float y = clamp(uv(1), 0.0f, 1.0f) * m_height; result = turbulence(x, y); return Color3f(result, result, result); }
void LICE_TexGen_CircNoise(LICE_IBitmap *dest, RECT *rect, float rv, float gv, float bv, float nrings, float power, int size) { initNoise(); int span=dest->getRowSpan(); int w = dest->getWidth(); int h = dest->getHeight(); int x = 0; int y = 0; if(rect) { x = rect->left; y = rect->top; w = rect->right - rect->left; h = rect->bottom - rect->top; } if (x<0) { w+=x; x=0; } if (y<0) { h+=y; y=0; } if (x+w > dest->getWidth()) w=dest->getWidth()-x; if (y+h > dest->getHeight()) h=dest->getHeight()-y; if (w<1 || h<1) return; LICE_pixel *startp = dest->getBits(); if (dest->isFlipped()) { startp += x + (dest->getHeight()-1-y)*span; span=-span; } else startp += x + y*span; float xyPeriod = nrings; float turbPower = power; const float iturbSize = 1.0f/(float)size; const float turbSize = (float)size; { LICE_pixel *p = startp; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { float xValue = ((float)j - w / 2) / w; float yValue = ((float)i - h / 2) / h; float distValue = sqrt(xValue * xValue + yValue * yValue) + turbPower * turbulence(j, i, turbSize, iturbSize) / 256.0f; float col = (float)fabs(256.0 * sin(2 * xyPeriod * distValue * 3.14159)); p[j] = LICE_RGBA((int)(col*rv),(int)(col*bv),(int)(col*gv),255); } p+=span; } } }
void marble::apply( Vector& p, surface_data& t ) { double x = p.x * scale.x + offs.x; double s = pow( saw_wave( x + turb * turbulence(p,octaves) ), squeeze ); // if(!Tbl.IsEmpty()) // { t.color = tbl.find_color(s); // return; // } }
double apply_marble_noise(int x, int y, double res, double **tab_noise) { double x_period; double y_period; double turb_power; double xy_val; double sin_val; x_period = 1.0; y_period = 30.0; turb_power = 10.0; xy_val = x * x_period / WIDTH; xy_val += y * y_period / HEIGHT; xy_val += turb_power * turbulence(x, y, res, tab_noise) / 256.0; sin_val = 256 * fabs(sin(xy_val * M_PI)); return (sin_val); }
rgb Ray_Trace(int obj_num,float dx, float dy,float dz, points from, int depth) { int shadow_flag; int texture, buf_ptr = 0; int num_image = 1; float nx, ny, nz; float t_min, t1, t2, ipx = 0, ipy = 0, ipz = 0; float rlx, rly, rlz, rfx,rfy,rfz; rgb rgb_color; /* Check if the current ray intercepts spheres */ t_min = 999.0; //obj_num = 0; texture = 0; for(int i = 1; i <= NUM_SPHERES; i++) { Check_Sphere(from.x, from.y, from.z, dx, dy, dz, c[i-1][0], c[i-1][1], c[i-1][2], c[i-1][3], &t1, &t2); if (t1>=0.00001) { t_min = t1; obj_num = i; Compute_Intersection(from.x, from.y, from.z, dx, dy, dz, t1, &ipx, &ipy, &ipz); } if (t2>=0.00001 && t2<t_min) { t_min = t2; obj_num = i; Compute_Intersection(from.x, from.y, from.z, dx, dy, dz, t2, &ipx, &ipy, &ipz); } } /* Check if the current ray intercepts planes. */ for(int i = 1; i <= NUM_PLANES; i++) { Check_Plane(from.x, from.y, from.z, dx, dy, dz, p[i-1][0], p[i-1][1], p[i-1][2], p[i-1][3], &t1); if (t1 >= 0.00001 && t1<t_min) { /* Check if the intersection point is inside the min/max values. */ Compute_Intersection(from.x, from.y, from.z, dx, dy, dz, t1, &ipx, &ipy, &ipz); if (ipx >= pminmax[i-1][0][0] && ipx <= pminmax[i-1][0][1] && ipy >= pminmax[i-1][1][0] && ipy <= pminmax[i-1][1][1] && ipz >= pminmax[i-1][2][0] && ipz <= pminmax[i-1][2][1] ) { t_min = t1; obj_num = i+NUM_SPHERES; } } } int grain; float u,v,w,t,value,x; /* Compute the intensity to use at the current pixel. */ switch (obj_num) { /* The current ray does not intersect any of the objects. */ case 0 :rgb_color.r = 0.1; rgb_color.g = 0.1; rgb_color.b = 0.1; break; /* The current ray intercept sphere #1. */ case 1 : nx = ipx - c[0][0]; ny = ipy - c[0][1]; nz = ipz - c[0][2]; Normalize(&nx, &ny, &nz); shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz, obj_num); texture = 0; rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_S[0], kd_S[0], ks_S[0], ns_S[0], krg_S[0], ktg_S[0], 1); break; /* The current ray intercepts sphere #2. */ case 2 : nx = ipx - c[1][0]; ny = ipy - c[1][1]; nz = ipz - c[1][2]; Normalize(&nx, &ny, &nz); shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz, obj_num); texture = rand() % 2; if(texture == 1) { Bump_map(ipx,ipy,ipz,dx,dy,dz,1,&nx,&ny,&nz,2); rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_S[1], kd_S[1], ks_S[1], ns_S[1], krg_S[1], ktg_S[1], 1); } else rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_S[1], kd_S[1], ks_S[1], ns_S[1], krg_S[1], ktg_S[1], 1); break; /* The current ray intercepts sphere #3. */ case 3 : nx = ipx - c[2][0]; ny = ipy - c[2][1]; nz = ipz - c[2][2]; Normalize(&nx, &ny, &nz); shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz, obj_num); texture = rand() % 2; if (texture==1) // Compute texture. */ { Bump_map(ipx,ipy,ipz,dx,dy,dz,1,&nx,&ny,&nz,1); rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, tka3, tkd3, ks_S[2], ns_S[2], krg_S[2], ktg_S[2], 1); } else rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_S[2], kd_S[2], ks_S[2], ns_S[2], krg_S[2], ktg_S[2], 1); break; case 4 : /* The current ray intercepts plane #1. */ nx = p[0][0]; ny = p[0][1]; nz = p[0][2]; shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz,obj_num); grain = wood_grain(ipx,ipy,ipz); if(grain < 3) rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, tka4 ,tkd4 , ks_P[0], ns_P[0] ,krg_P[0], ktg_P[0], 1); else rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_P[0], kd_P[0], ks_P[0], ns_P[0], krg_P[0], ktg_P[0], 1); break; case 5 : /* The current ray intercepts plane #2. */ nx = p[1][0]; ny = p[1][1]; nz = p[1][2]; shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz,obj_num); if (ipz < 2.0 || (ipz>=4.0 && ipz<6.0)) { if ((ipy>=2.0 && ipy<4.0) || (ipy>=6.0)) texture = 1; else texture = 0; } else { if ((ipy<2.0) || (ipy>=4.0 && ipy<6.0)) texture = 1; else texture = 0; } if (texture == 1) rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, tka5, tkd5, ks_P[1], ns_P[1], krg_P[1], ktg_P[1], 1); else rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_P[1], kd_P[1], ks_P[1], ns_P[1], krg_P[1], ktg_P[1], 1); break; case 6 : /* The current ray intercepts plane #3. */ nx = p[2][0]; ny = p[2][1]; nz = p[2][2]; shadow_flag = 0; shadow_flag = Check_Shadow(ipx, ipy, ipz,obj_num); if (ipx < 2.0 || (ipx >= 4.0 && ipx < 6.0)) { if ((ipz >= 2.0 && ipz < 4.0) || (ipz >=6.0)) texture = 1; else texture = 0; } else { if ((ipz<2.0) || (ipz>=4.0 && ipz<6.0)) texture = 1; else texture = 0; } t = turbulence(ipx,ipy,ipz,0.5); value = ipx+t; x = sqrt( value + 1.0)*0.7071; get_marble_color( (float)sin(value*3.1415926), &rgb_color); get_marble_color( (float)sin(value*3.1415926), &rgb_color); get_marble_color( (float)sin(value*3.1415926), &rgb_color); /*if (texture == 1) rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, tka6, tkd6, ks_P[2], ns_P[2], krg_P[2], ktg_P[2], 1); else rgb_color = Compute_Color(shadow_flag, ipx, ipy, ipz, nx, ny, nz, ia, ka_P[2], kd_P[2], ks_P[2], ns_P[2], krg_P[2], ktg_P[2], 1); */ break; default: break; } if(depth < MAX_DEPTH) { if(obj_num > 0 && obj_num !=4 && nx >= 0 && ny >= 0 && nz >= 0) { compute_reflected_ray(dx, dy, dz, nx, ny, nz, &rlx, &rly, &rlz); points newFrom; newFrom.x = ipx; newFrom.y = ipy; newFrom.z = ipz; rgb rcolor = Ray_Trace(obj_num,rlx,rly,rlz,newFrom,depth+1); switch(obj_num) { case 1: rgb_color.r += krg_S[0]*rcolor.r; rgb_color.g += krg_S[0]*rcolor.g; rgb_color.b += krg_S[0]*rcolor.b; break; case 2: rgb_color.r += krg_S[1]*rcolor.r; rgb_color.g += krg_S[1]*rcolor.g; rgb_color.b += krg_S[1]*rcolor.b; break; case 3: rgb_color.r += krg_S[2]*rcolor.r; rgb_color.g += krg_S[2]*rcolor.g; rgb_color.b += krg_S[2]*rcolor.b; break; case 4: rgb_color.r += krg_P[0]*rcolor.r; rgb_color.g += krg_P[0]*rcolor.g; rgb_color.b += krg_P[0]*rcolor.b; break; case 5: rgb_color.r += krg_P[1]*rcolor.r; rgb_color.g += krg_P[1]*rcolor.g; rgb_color.b += krg_P[1]*rcolor.b; break; case 6: rgb_color.r += krg_P[2]*rcolor.r; rgb_color.g += krg_P[2]*rcolor.g; rgb_color.b += krg_P[2]*rcolor.b; break; default: break; } } float n1 = 1.0003; /*refractive index air*/ /*nt - refractive index material*/ float thetha = 1000; if(obj_num > 0 && obj_num < 7) { if(obj_num < 4) { thetha = asin((float)n1/(float)nt_S[obj_num-1]); if(thetha < 41.2) /* Check if object is semi transparent */ { points newFrom; newFrom.x = ipx; newFrom.y = ipy; newFrom.z = ipz; compute_refracted_ray(dx,dy,dz,nx,ny,nz,&rfx,&rfy,&rfz,nt_S[obj_num-1]); /*Compute refracted ray*/ rgb rcolor = Ray_Trace(obj_num,rfx,rfy,rfz,newFrom,depth+1); rgb_color.r += ktg_P[0]*rcolor.r; rgb_color.g += ktg_P[0]*rcolor.g; rgb_color.b += ktg_P[0]*rcolor.b; } } else { int i = obj_num-NUM_SPHERES-1; thetha = asin((float)n1/(float)nt_P[i]); if(thetha < 41.2) /* Check if object is semi transparent */ { points newFrom; newFrom.x = ipx; newFrom.y = ipy; newFrom.z = ipz; compute_refracted_ray(dx,dy,dz,nx,ny,nz,&rfx,&rfy,&rfz,nt_P[i]); /*Compute refracted ray*/ rgb rcolor = Ray_Trace(obj_num,rfx,rfy,rfz,newFrom,depth+1); rgb_color.r += ktg_P[0]*rcolor.r; rgb_color.g += ktg_P[0]*rcolor.g; rgb_color.b += ktg_P[0]*rcolor.b; } } } } return rgb_color; }
void stochasticDispersionRAS::disperseParcels() const { const scalar cps = 0.16432; scalar dt = spray_.runTime().deltaT().value(); const volScalarField& k = turbulence().k(); //volVectorField gradk = fvc::grad(k); const volScalarField& epsilon = turbulence().epsilon(); const volVectorField& U = spray_.U(); for ( spray::iterator elmnt = spray_.begin(); elmnt != spray_.end(); ++elmnt ) { label celli = elmnt().cell(); scalar UrelMag = mag(elmnt().U() - U[celli] - elmnt().Uturb()); scalar Tturb = min ( k[celli]/epsilon[celli], cps*pow(k[celli], 1.5)/epsilon[celli]/(UrelMag + SMALL) ); // parcel is perturbed by the turbulence if (dt < Tturb) { elmnt().tTurb() += dt; if (elmnt().tTurb() > Tturb) { elmnt().tTurb() = 0.0; scalar sigma = sqrt(2.0*k[celli]/3.0); vector dir = 2.0*spray_.rndGen().vector01() - vector::one; dir /= mag(dir) + SMALL; // numerical recipes... Ch. 7. Random Numbers... scalar x1,x2; scalar rsq = 10.0; while((rsq > 1.0) || (rsq == 0.0)) { x1 = 2.0*spray_.rndGen().scalar01() - 1.0; x2 = 2.0*spray_.rndGen().scalar01() - 1.0; rsq = x1*x1 + x2*x2; } scalar fac = sqrt(-2.0*log(rsq)/rsq); fac *= mag(x1); elmnt().Uturb() = sigma*fac*dir; } } else { elmnt().tTurb() = GREAT; elmnt().Uturb() = vector::zero; } } }
int main(int argc, char *argv[]) { argList::addNote ( "apply a simplified boundary-layer model to the velocity and\n" "turbulence fields based on the 1/7th power-law." ); argList::addOption ( "ybl", "scalar", "specify the boundary-layer thickness" ); argList::addOption ( "Cbl", "scalar", "boundary-layer thickness as Cbl * mean distance to wall" ); argList::addBoolOption ( "writenut", "write nut field" ); #include "setRootCase.H" if (!args.optionFound("ybl") && !args.optionFound("Cbl")) { FatalErrorIn(args.executable()) << "Neither option 'ybl' or 'Cbl' have been provided to calculate " << "the boundary-layer thickness.\n" << "Please choose either 'ybl' OR 'Cbl'." << exit(FatalError); } else if (args.optionFound("ybl") && args.optionFound("Cbl")) { FatalErrorIn(args.executable()) << "Both 'ybl' and 'Cbl' have been provided to calculate " << "the boundary-layer thickness.\n" << "Please choose either 'ybl' OR 'Cbl'." << exit(FatalError); } #include "createTime.H" #include "createMesh.H" #include "createFields.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Modify velocity by applying a 1/7th power law boundary-layer // u/U0 = (y/ybl)^(1/7) // assumes U0 is the same as the current cell velocity Info<< "Setting boundary layer velocity" << nl << endl; scalar yblv = ybl.value(); forAll(U, cellI) { if (y[cellI] <= yblv) { mask[cellI] = 1; U[cellI] *= ::pow(y[cellI]/yblv, (1.0/7.0)); } } mask.correctBoundaryConditions(); Info<< "Writing U\n" << endl; U.write(); // Update/re-write phi #include "createPhi.H" phi.write(); singlePhaseTransportModel laminarTransport(U, phi); autoPtr<incompressible::turbulenceModel> turbulence ( incompressible::turbulenceModel::New(U, phi, laminarTransport) ); if (isA<incompressible::RASModel>(turbulence())) { // Calculate nut - reference nut is calculated by the turbulence model // on its construction tmp<volScalarField> tnut = turbulence->nut(); volScalarField& nut = tnut(); volScalarField S(mag(dev(symm(fvc::grad(U))))); nut = (1 - mask)*nut + mask*sqr(kappa*min(y, ybl))*::sqrt(2)*S; // do not correct BC - wall functions will 'undo' manipulation above // by using nut from turbulence model if (args.optionFound("writenut")) { Info<< "Writing nut" << endl; nut.write(); } //--- Read and modify turbulence fields // Turbulence k tmp<volScalarField> tk = turbulence->k(); volScalarField& k = tk(); scalar ck0 = pow025(Cmu)*kappa; k = (1 - mask)*k + mask*sqr(nut/(ck0*min(y, ybl))); // do not correct BC - operation may use inconsistent fields wrt these // local manipulations // k.correctBoundaryConditions(); Info<< "Writing k\n" << endl; k.write(); // Turbulence epsilon tmp<volScalarField> tepsilon = turbulence->epsilon(); volScalarField& epsilon = tepsilon(); scalar ce0 = ::pow(Cmu, 0.75)/kappa; epsilon = (1 - mask)*epsilon + mask*ce0*k*sqrt(k)/min(y, ybl); // do not correct BC - wall functions will use non-updated k from // turbulence model // epsilon.correctBoundaryConditions(); Info<< "Writing epsilon\n" << endl; epsilon.write(); // Turbulence omega IOobject omegaHeader ( "omega", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false ); if (omegaHeader.headerOk()) { volScalarField omega(omegaHeader, mesh); dimensionedScalar k0("VSMALL", k.dimensions(), VSMALL); omega = (1 - mask)*omega + mask*epsilon/(Cmu*k + k0); // do not correct BC - wall functions will use non-updated k from // turbulence model // omega.correctBoundaryConditions(); Info<< "Writing omega\n" << endl; omega.write(); } // Turbulence nuTilda IOobject nuTildaHeader ( "nuTilda", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false ); if (nuTildaHeader.headerOk()) { volScalarField nuTilda(nuTildaHeader, mesh); nuTilda = nut; // do not correct BC // nuTilda.correctBoundaryConditions(); Info<< "Writing nuTilda\n" << endl; nuTilda.write(); } } Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; Info<< "End\n" << endl; return 0; }
void Foam::stochasticDispersionRAS::disperseParcels() const { const scalar cps = 0.16432; const vector one(1.0, 1.0, 1.0); scalar dt = spray_.runTime().deltaTValue(); const volScalarField& k = turbulence().k(); // volVectorField gradk(fvc::grad(k)); const volScalarField& epsilon = turbulence().epsilon(); const volVectorField& U = spray_.U(); forAllIter(spray, spray_, elmnt) { const label cellI = elmnt().cell(); scalar UrelMag = mag(elmnt().U() - U[cellI] - elmnt().Uturb()); scalar Tturb = min ( k[cellI]/epsilon[cellI], cps*pow(k[cellI], 1.5)/epsilon[cellI]/(UrelMag + SMALL) ); // parcel is perturbed by the turbulence if (dt < Tturb) { elmnt().tTurb() += dt; if (elmnt().tTurb() > Tturb) { elmnt().tTurb() = 0.0; scalar sigma = sqrt(2.0*k[cellI]/3.0); vector dir = 2.0*spray_.rndGen().sample01<vector>() - one; dir /= mag(dir) + SMALL; // numerical recipes... Ch. 7. Random Numbers... scalar x1,x2; scalar rsq = 10.0; while (rsq > 1.0 || rsq == 0.0) { x1 = 2.0*spray_.rndGen().sample01<scalar>() - 1.0; x2 = 2.0*spray_.rndGen().sample01<scalar>() - 1.0; rsq = x1*x1 + x2*x2; } scalar fac = sqrt(-2.0*log(rsq)/rsq); fac *= mag(x1); elmnt().Uturb() = sigma*fac*dir; } } else { elmnt().tTurb() = GREAT; elmnt().Uturb() = vector::zero; } } }
void gradientDispersionRAS::disperseParcels() const { const scalar cps = 0.16432; scalar dt = spray_.runTime().deltaT().value(); const volScalarField& k = turbulence().k(); volVectorField gradk = fvc::grad(k); const volScalarField& epsilon = turbulence().epsilon(); const volVectorField& U = spray_.U(); for ( spray::iterator elmnt = spray_.begin(); elmnt != spray_.end(); ++elmnt ) { label celli = elmnt().cell(); scalar UrelMag = mag(elmnt().U() - U[celli] - elmnt().Uturb()); scalar Tturb = min ( k[celli]/epsilon[celli], cps*pow(k[celli], 1.5)/epsilon[celli]/(UrelMag + SMALL) ); // parcel is perturbed by the turbulence if (dt < Tturb) { elmnt().tTurb() += dt; if (elmnt().tTurb() > Tturb) { elmnt().tTurb() = 0.0; scalar sigma = sqrt(2.0*k[celli]/3.0); vector dir = -gradk[celli]/(mag(gradk[celli]) + SMALL); // numerical recipes... Ch. 7. Random Numbers... scalar x1 = 0.0; scalar x2 = 0.0; scalar rsq = 10.0; while((rsq > 1.0) || (rsq == 0.0)) { x1 = 2.0*spray_.rndGen().scalar01() - 1.0; x2 = 2.0*spray_.rndGen().scalar01() - 1.0; rsq = x1*x1 + x2*x2; } scalar fac = sqrt(-2.0*log(rsq)/rsq); // in 2D calculations the -grad(k) is always // away from the axis of symmetry // This creates a 'hole' in the spray and to // prevent this we let x1 be both negative/positive if (spray_.twoD()) { fac *= x1; } else { fac *= mag(x1); } elmnt().Uturb() = sigma*fac*dir; } } else { elmnt().tTurb() = GREAT; elmnt().Uturb() = vector::zero; } } }
RealT PerlinNoise::marble (const RealT &strength, const Vec3 &v) const { RealT t = turbulence(v); return t; }