fix pressurecell OOB advect
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
c50e22cfd3
commit
982911cfb7
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -54,6 +54,7 @@
|
|||||||
"pressure.h": "c",
|
"pressure.h": "c",
|
||||||
"tracking.h": "c",
|
"tracking.h": "c",
|
||||||
"multigrid_navier_stokes.h": "c",
|
"multigrid_navier_stokes.h": "c",
|
||||||
"navier_stokes.h": "c"
|
"navier_stokes.h": "c",
|
||||||
|
"electrosphere_client_fluid_cache_fluidchunkdata.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,6 +65,10 @@ typedef struct {
|
|||||||
* The sum of density
|
* The sum of density
|
||||||
*/
|
*/
|
||||||
double densitySum;
|
double densitySum;
|
||||||
|
/**
|
||||||
|
* Ratio to normalize the density by
|
||||||
|
*/
|
||||||
|
double normalizationRatio;
|
||||||
} PressureCellData;
|
} PressureCellData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -21,5 +21,10 @@ LIBRARY_API void fluid_pressurecell_calculate_normalization_ratio(Environment *
|
|||||||
*/
|
*/
|
||||||
LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * chunk);
|
LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * chunk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recaptures density that has flowed into boundaries
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * chunk);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -25,12 +25,12 @@
|
|||||||
/**
|
/**
|
||||||
* Diffusion constant
|
* Diffusion constant
|
||||||
*/
|
*/
|
||||||
#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.00001f
|
#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.1f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Viscosity constant
|
* Viscosity constant
|
||||||
*/
|
*/
|
||||||
#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.00001f
|
#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.1f
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amount of the residual to add to the pressure field each frame
|
* Amount of the residual to add to the pressure field each frame
|
||||||
@ -62,5 +62,10 @@
|
|||||||
*/
|
*/
|
||||||
#define FLUID_PRESSURECELL_MAX_PRESSURE 10000.0f
|
#define FLUID_PRESSURECELL_MAX_PRESSURE 10000.0f
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Percentage of presure to keep from last frame
|
||||||
|
*/
|
||||||
|
#define FLUID_PRESSURECELL_PRESSURE_BACKDOWN_FACTOR 0.5f
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -76,6 +76,61 @@ void fluid_pressurecell_set_bounds_legacy(
|
|||||||
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bounds to 0
|
||||||
|
*/
|
||||||
|
void fluid_pressurecell_set_bounds_zero(
|
||||||
|
Environment * environment,
|
||||||
|
int vector_dir,
|
||||||
|
float * target
|
||||||
|
){
|
||||||
|
//set the boundary planes
|
||||||
|
for(int x = 1; x < DIM-1; x++){
|
||||||
|
for(int y = 1; y < DIM-1; y++){
|
||||||
|
//x-direction boundary planes
|
||||||
|
target[IX(0,x,y)] = 0;
|
||||||
|
target[IX(DIM-1,x,y)] = 0;
|
||||||
|
//y-direction boundary planes
|
||||||
|
target[IX(x,0,y)] = 0;
|
||||||
|
target[IX(x,DIM-1,y)] = 0;
|
||||||
|
//z-direction boundary planes
|
||||||
|
target[IX(x,y,0)] = 0;
|
||||||
|
target[IX(x,y,DIM-1)] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sets the edges of the chunk
|
||||||
|
//this should logically follow from how we're treating the boundary planes
|
||||||
|
for(int x = 1; x < DIM-1; x++){
|
||||||
|
target[IX(x,0,0)] = 0;
|
||||||
|
target[IX(x,DIM-1,0)] = 0;
|
||||||
|
target[IX(x,0,DIM-1)] = 0;
|
||||||
|
target[IX(x,DIM-1,DIM-1)] = 0;
|
||||||
|
|
||||||
|
target[IX(0,x,0)] = 0;
|
||||||
|
target[IX(DIM-1,x,0)] = 0;
|
||||||
|
target[IX(0,x,DIM-1)] = 0;
|
||||||
|
target[IX(DIM-1,x,DIM-1)] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
target[IX(0,0,x)] = 0;
|
||||||
|
target[IX(DIM-1,0,x)] = 0;
|
||||||
|
target[IX(0,DIM-1,x)] = 0;
|
||||||
|
target[IX(DIM-1,DIM-1,x)] = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
//sets the corners of the chunk
|
||||||
|
//this should logically follow from how we're treating the boundary planes
|
||||||
|
target[IX(0,0,0)] = 0;
|
||||||
|
target[IX(DIM-1,0,0)] = 0;
|
||||||
|
target[IX(0,DIM-1,0)] = 0;
|
||||||
|
target[IX(0,0,DIM-1)] = 0;
|
||||||
|
target[IX(DIM-1,DIM-1,0)] = 0;
|
||||||
|
target[IX(0,DIM-1,DIM-1)] = 0;
|
||||||
|
target[IX(DIM-1,0,DIM-1)] = 0;
|
||||||
|
target[IX(DIM-1,DIM-1,DIM-1)] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the bounds of the chunk based on its neighbors
|
* Updates the bounds of the chunk based on its neighbors
|
||||||
@ -87,6 +142,10 @@ LIBRARY_API void pressurecell_update_bounds(Environment * environment, Chunk * c
|
|||||||
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_U,chunk->u[CENTER_LOC]);
|
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_U,chunk->u[CENTER_LOC]);
|
||||||
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_V,chunk->v[CENTER_LOC]);
|
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_V,chunk->v[CENTER_LOC]);
|
||||||
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_W,chunk->w[CENTER_LOC]);
|
fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_W,chunk->w[CENTER_LOC]);
|
||||||
|
|
||||||
|
fluid_pressurecell_set_bounds_zero(environment,FLUID_PRESSURECELL_DIRECTION_U,chunk->u0[CENTER_LOC]);
|
||||||
|
fluid_pressurecell_set_bounds_zero(environment,FLUID_PRESSURECELL_DIRECTION_V,chunk->v0[CENTER_LOC]);
|
||||||
|
fluid_pressurecell_set_bounds_zero(environment,FLUID_PRESSURECELL_DIRECTION_W,chunk->w0[CENTER_LOC]);
|
||||||
|
|
||||||
// fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_U,chunk->u0[CENTER_LOC]);
|
// fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_U,chunk->u0[CENTER_LOC]);
|
||||||
// fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_V,chunk->v0[CENTER_LOC]);
|
// fluid_pressurecell_set_bounds_legacy(environment,FLUID_PRESSURECELL_DIRECTION_V,chunk->v0[CENTER_LOC]);
|
||||||
|
|||||||
@ -40,9 +40,12 @@ LIBRARY_API void fluid_pressurecell_calculate_normalization_ratio(Environment *
|
|||||||
env->state.existingDensity = env->state.existingDensity + expected;
|
env->state.existingDensity = env->state.existingDensity + expected;
|
||||||
if(sum > 0){
|
if(sum > 0){
|
||||||
double normalizationRatio = expected / sum;
|
double normalizationRatio = expected / sum;
|
||||||
chunk->pressureCellData.densitySum = normalizationRatio;
|
chunk->pressureCellData.normalizationRatio = normalizationRatio;
|
||||||
} else {
|
} else {
|
||||||
chunk->pressureCellData.densitySum = expected;
|
if(expected > 0.001f){
|
||||||
|
printf("We've managed to completely delete all density! (expected: %f) \n", expected);
|
||||||
|
}
|
||||||
|
chunk->pressureCellData.normalizationRatio = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ LIBRARY_API void fluid_pressurecell_calculate_normalization_ratio(Environment *
|
|||||||
*/
|
*/
|
||||||
LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * chunk){
|
LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * chunk){
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
double ratio = chunk->pressureCellData.densitySum;
|
double ratio = chunk->pressureCellData.normalizationRatio;
|
||||||
for(x = 1; x < DIM-1; x++){
|
for(x = 1; x < DIM-1; x++){
|
||||||
for(y = 1; y < DIM-1; y++){
|
for(y = 1; y < DIM-1; y++){
|
||||||
for(z = 1; z < DIM-1; z++){
|
for(z = 1; z < DIM-1; z++){
|
||||||
@ -62,3 +65,10 @@ LIBRARY_API void fluid_pressurecell_normalize_chunk(Environment * env, Chunk * c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recaptures density that has flowed into boundaries
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk * chunk){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Ch
|
|||||||
for(y = 0; y < DIM; y++){
|
for(y = 0; y < DIM; y++){
|
||||||
for(x = 0; x < DIM; x++){
|
for(x = 0; x < DIM; x++){
|
||||||
phi0[IX(x,y,z)] = divCache[IX(x,y,z)];
|
phi0[IX(x,y,z)] = divCache[IX(x,y,z)];
|
||||||
pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)];
|
pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)] * FLUID_PRESSURECELL_PRESSURE_BACKDOWN_FACTOR;
|
||||||
// pressureTemp[IX(x,y,z)] = 0;
|
// pressureTemp[IX(x,y,z)] = 0;
|
||||||
if(divCache[IX(x,y,z)] > 3){
|
if(divCache[IX(x,y,z)] > 3){
|
||||||
printf("invalid divergence!\n");
|
printf("invalid divergence!\n");
|
||||||
@ -198,6 +198,26 @@ LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Ch
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
double pressureMax = 0;
|
||||||
|
for(z = 1; z < DIM-1; z++){
|
||||||
|
for(y = 1; y < DIM-1; y++){
|
||||||
|
for(x = 1; x < DIM; x++){
|
||||||
|
if(pressureTemp[IX(x,y,z)] > pressureMax){
|
||||||
|
pressureMax = pressureTemp[IX(x,y,z)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(z = 1; z < DIM-1; z++){
|
||||||
|
for(y = 1; y < DIM-1; y++){
|
||||||
|
for(x = 1; x < DIM; x++){
|
||||||
|
if(pressureTemp[IX(x,y,z)] > pressureMax){
|
||||||
|
pressureTemp[IX(x,y,z)] = pressureTemp[IX(x,y,z)] / pressureMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//do NOT zero out pressure on edges
|
//do NOT zero out pressure on edges
|
||||||
//this will cause the fluid to advect into the walls
|
//this will cause the fluid to advect into the walls
|
||||||
// for(x = 0; x < DIM; x++){
|
// for(x = 0; x < DIM; x++){
|
||||||
@ -257,6 +277,7 @@ LIBRARY_API void pressurecell_approximate_divergence(Environment * environment,
|
|||||||
// }
|
// }
|
||||||
newDivergence = (du+dv+dw) * (-0.5f * FLUID_PRESSURECELL_SPACING);
|
newDivergence = (du+dv+dw) * (-0.5f * FLUID_PRESSURECELL_SPACING);
|
||||||
// divArr[IX(x,y,z)] = divArr[IX(x,y,z)] + newDivergence - FLUID_PRESSURECELL_RESIDUAL_MULTIPLIER * divArr[IX(x,y,z)] + outflowDiv;
|
// divArr[IX(x,y,z)] = divArr[IX(x,y,z)] + newDivergence - FLUID_PRESSURECELL_RESIDUAL_MULTIPLIER * divArr[IX(x,y,z)] + outflowDiv;
|
||||||
|
newDivergence = fmax(-3.0f,fmin(3.0f,newDivergence));
|
||||||
divArr[IX(x,y,z)] = newDivergence;
|
divArr[IX(x,y,z)] = newDivergence;
|
||||||
if(newDivergence > 3 || newDivergence < -3){
|
if(newDivergence > 3 || newDivergence < -3){
|
||||||
printf("Invalid divergence! \n");
|
printf("Invalid divergence! \n");
|
||||||
|
|||||||
@ -41,6 +41,11 @@ LIBRARY_API void fluid_pressurecell_simulate(
|
|||||||
|
|
||||||
for(int i = 0; i < numChunks; i++){
|
for(int i = 0; i < numChunks; i++){
|
||||||
Chunk * currentChunk = chunks[i];
|
Chunk * currentChunk = chunks[i];
|
||||||
|
fluid_pressurecell_clearArr(currentChunk->pressureTempCache);
|
||||||
|
fluid_pressurecell_clearArr(currentChunk->dTempCache);
|
||||||
|
fluid_pressurecell_clearArr(currentChunk->uTempCache);
|
||||||
|
fluid_pressurecell_clearArr(currentChunk->vTempCache);
|
||||||
|
fluid_pressurecell_clearArr(currentChunk->wTempCache);
|
||||||
fluid_pressurecell_calculate_expected_intake(environment,currentChunk);
|
fluid_pressurecell_calculate_expected_intake(environment,currentChunk);
|
||||||
pressurecell_update_bounds(environment,currentChunk);
|
pressurecell_update_bounds(environment,currentChunk);
|
||||||
// pressurecell_update_interest(environment,currentChunk);
|
// pressurecell_update_interest(environment,currentChunk);
|
||||||
|
|||||||
@ -16,7 +16,9 @@ LIBRARY_API void pressurecell_add_gravity(Environment * environment, Chunk * chu
|
|||||||
for(z = 1; z < DIM-1; z++){
|
for(z = 1; z < DIM-1; z++){
|
||||||
for(y = 1; y < DIM-1; y++){
|
for(y = 1; y < DIM-1; y++){
|
||||||
for(x = 1; x < DIM-1; x++){
|
for(x = 1; x < DIM-1; x++){
|
||||||
vSourceArr[IX(x,y,z)] = vSourceArr[IX(x,y,z)] + dArr[IX(x,y,z)] * environment->consts.gravity * environment->consts.dt;
|
float gravForce = dArr[IX(x,y,z)] * environment->consts.gravity * environment->consts.dt;
|
||||||
|
gravForce = fmax(fmin(1.0f, gravForce),-1.0f);
|
||||||
|
vSourceArr[IX(x,y,z)] = vSourceArr[IX(x,y,z)] + gravForce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,6 +45,14 @@ LIBRARY_API void pressurecell_add_velocity(Environment * environment, Chunk * ch
|
|||||||
uTemp[IX(x,y,z)] = uArr[IX(x,y,z)] + uSourceArr[IX(x,y,z)];
|
uTemp[IX(x,y,z)] = uArr[IX(x,y,z)] + uSourceArr[IX(x,y,z)];
|
||||||
vTemp[IX(x,y,z)] = vArr[IX(x,y,z)] + vSourceArr[IX(x,y,z)];
|
vTemp[IX(x,y,z)] = vArr[IX(x,y,z)] + vSourceArr[IX(x,y,z)];
|
||||||
wTemp[IX(x,y,z)] = wArr[IX(x,y,z)] + wSourceArr[IX(x,y,z)];
|
wTemp[IX(x,y,z)] = wArr[IX(x,y,z)] + wSourceArr[IX(x,y,z)];
|
||||||
|
if(vTemp[IX(x,y,z)] > 5){
|
||||||
|
printf("Invalid add velocity!\n");
|
||||||
|
printf("%f %f %f \n", vTemp[IX(x,y,z)], vArr[IX(x,y,z)], vSourceArr[IX(x,y,z)] );
|
||||||
|
printf("\n");
|
||||||
|
int a = 1;
|
||||||
|
int b = 0;
|
||||||
|
int c = a / b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +136,7 @@ LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk
|
|||||||
uTemp[IX(x,y,z-1)] +
|
uTemp[IX(x,y,z-1)] +
|
||||||
uTemp[IX(x,y,z+1)]
|
uTemp[IX(x,y,z+1)]
|
||||||
)
|
)
|
||||||
) * c
|
) * a
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,8 +156,21 @@ LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk
|
|||||||
vTemp[IX(x,y,z-1)] +
|
vTemp[IX(x,y,z-1)] +
|
||||||
vTemp[IX(x,y,z+1)]
|
vTemp[IX(x,y,z+1)]
|
||||||
)
|
)
|
||||||
) * c
|
) * a
|
||||||
;
|
;
|
||||||
|
if(vArr[IX(x,y,z)] > 5){
|
||||||
|
printf("Invalid diffuse!\n");
|
||||||
|
printf("%f \n", vArr[IX(x,y,z)]);
|
||||||
|
printf("%f\n", vTemp[IX(x,y,z)]);
|
||||||
|
printf("%f %f \n", vTemp[IX(x-1,y,z)], vTemp[IX(x+1,y,z)] );
|
||||||
|
printf("%f %f \n", vTemp[IX(x,y-1,z)], vTemp[IX(x,y+1,z)] );
|
||||||
|
printf("%f %f \n", vTemp[IX(x,y,z-1)], vTemp[IX(x,y,z+1)] );
|
||||||
|
printf("%f %f \n", a, c);
|
||||||
|
printf("\n");
|
||||||
|
int r = 1;
|
||||||
|
int s = 0;
|
||||||
|
int t = r / s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +189,7 @@ LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk
|
|||||||
wTemp[IX(x,y,z-1)] +
|
wTemp[IX(x,y,z-1)] +
|
||||||
wTemp[IX(x,y,z+1)]
|
wTemp[IX(x,y,z+1)]
|
||||||
)
|
)
|
||||||
) * c
|
) * a
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,8 +211,19 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
|
|||||||
float xp, yp, zp;
|
float xp, yp, zp;
|
||||||
float s0, s1, t0, t1, u0, u1;
|
float s0, s1, t0, t1, u0, u1;
|
||||||
float interpolatedU, interpolatedV, interpolatedW;
|
float interpolatedU, interpolatedV, interpolatedW;
|
||||||
float magnitude;
|
float magnitude, maxMagnitude;
|
||||||
float interpConst = environment->consts.dt / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING);
|
float interpConst = environment->consts.dt / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING);
|
||||||
|
for(y = 1; y < DIM-1; y++){
|
||||||
|
for(z = 1; z < DIM-1; z++){
|
||||||
|
for(x = 1; x < DIM-1; x++){
|
||||||
|
magnitude = sqrt(interpolatedU * interpolatedU + interpolatedV * interpolatedV + interpolatedW * interpolatedW);
|
||||||
|
if(maxMagnitude < magnitude){
|
||||||
|
maxMagnitude = magnitude;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
magnitude = 0;
|
||||||
for(y = 1; y < DIM-1; y++){
|
for(y = 1; y < DIM-1; y++){
|
||||||
for(z = 1; z < DIM-1; z++){
|
for(z = 1; z < DIM-1; z++){
|
||||||
for(x = 1; x < DIM-1; x++){
|
for(x = 1; x < DIM-1; x++){
|
||||||
@ -202,6 +236,24 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
|
|||||||
x0 = xp;
|
x0 = xp;
|
||||||
y0 = yp;
|
y0 = yp;
|
||||||
z0 = zp;
|
z0 = zp;
|
||||||
|
|
||||||
|
//make sure we're not grabbing from outside bounds
|
||||||
|
if(x0 < 0){
|
||||||
|
x0 = 0;
|
||||||
|
} else if(x0 > DIM-2){
|
||||||
|
x0 = DIM-2;
|
||||||
|
}
|
||||||
|
if(y0 < 0){
|
||||||
|
y0 = 0;
|
||||||
|
} else if(y0 > DIM-2){
|
||||||
|
y0 = DIM-2;
|
||||||
|
}
|
||||||
|
if(z0 < 0){
|
||||||
|
z0 = 0;
|
||||||
|
} else if(z0 > DIM-2){
|
||||||
|
z0 = DIM-2;
|
||||||
|
}
|
||||||
|
|
||||||
//find far border
|
//find far border
|
||||||
x1 = x0 + 1;
|
x1 = x0 + 1;
|
||||||
y1 = y0 + 1;
|
y1 = y0 + 1;
|
||||||
@ -258,11 +310,14 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
|
|||||||
t1*u1*wArr[IX(x1,y1,z1)]
|
t1*u1*wArr[IX(x1,y1,z1)]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
magnitude = sqrt(interpolatedU * interpolatedU + interpolatedV * interpolatedV + interpolatedW * interpolatedW);
|
||||||
|
|
||||||
if(
|
if(
|
||||||
x0 < 0 || y0 < 0 || z0 < 0 ||
|
x0 < 0 || y0 < 0 || z0 < 0 ||
|
||||||
x0 > DIM-1 || y0 > DIM-1 || z0 > DIM-1 ||
|
x0 > DIM-1 || y0 > DIM-1 || z0 > DIM-1 ||
|
||||||
x1 < 0 || y1 < 0 || z1 < 0 ||
|
x1 < 0 || y1 < 0 || z1 < 0 ||
|
||||||
x1 > DIM-1 || y1 > DIM-1 || z1 > DIM-1
|
x1 > DIM-1 || y1 > DIM-1 || z1 > DIM-1
|
||||||
|
// || magnitude > 1
|
||||||
){
|
){
|
||||||
printf("advect vel: out of bounds \n");
|
printf("advect vel: out of bounds \n");
|
||||||
printf("%d %d %d\n", x, y, z);
|
printf("%d %d %d\n", x, y, z);
|
||||||
@ -277,6 +332,10 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
|
|||||||
printf("%f %f %f\n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
printf("%f %f %f\n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
||||||
printf("%f %f %f\n", uTemp[IX(x,y,z)], vTemp[IX(x,y,z)], wTemp[IX(x,y,z)]);
|
printf("%f %f %f\n", uTemp[IX(x,y,z)], vTemp[IX(x,y,z)], wTemp[IX(x,y,z)]);
|
||||||
printf("%f\n", environment->consts.dt);
|
printf("%f\n", environment->consts.dt);
|
||||||
|
printf("%f\n", magnitude);
|
||||||
|
printf("values:\n");
|
||||||
|
printf("%f %f %f %f \n", vArr[IX(x0,y0,z0)], vArr[IX(x0,y1,z0)], vArr[IX(x1,y0,z0)], vArr[IX(x1,y1,z0)]);
|
||||||
|
printf("%f %f %f %f \n", vArr[IX(x0,y0,z1)], vArr[IX(x0,y1,z1)], vArr[IX(x1,y0,z1)], vArr[IX(x1,y1,z1)]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
@ -289,6 +348,20 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
|
|||||||
// interpolatedV = interpolatedV / magnitude;
|
// interpolatedV = interpolatedV / magnitude;
|
||||||
// interpolatedW = interpolatedW / magnitude;
|
// interpolatedW = interpolatedW / magnitude;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if(magnitude > 10){
|
||||||
|
printf("advect invalid set: %f %f %f \n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
||||||
|
int a = 1;
|
||||||
|
int b = 0;
|
||||||
|
int c = a / b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(maxMagnitude > 1){
|
||||||
|
// interpolatedU = interpolatedU / maxMagnitude;
|
||||||
|
// interpolatedV = interpolatedV / maxMagnitude;
|
||||||
|
// interpolatedW = interpolatedW / maxMagnitude;
|
||||||
|
// printf("maxMagnitude: %f \n", maxMagnitude);
|
||||||
|
// }
|
||||||
|
|
||||||
uTemp[IX(x,y,z)] = interpolatedU;
|
uTemp[IX(x,y,z)] = interpolatedU;
|
||||||
vTemp[IX(x,y,z)] = interpolatedV;
|
vTemp[IX(x,y,z)] = interpolatedV;
|
||||||
@ -312,7 +385,7 @@ LIBRARY_API double pressurecell_project_velocity(Environment * environment, Chun
|
|||||||
// float * wTemp = chunk->wTempCache;
|
// float * wTemp = chunk->wTempCache;
|
||||||
//temporary caches
|
//temporary caches
|
||||||
float pressureDivergence;
|
float pressureDivergence;
|
||||||
float magnitude;
|
float magnitude = 0;
|
||||||
float pressureDifferenceX, pressureDifferenceY, pressureDifferenceZ;
|
float pressureDifferenceX, pressureDifferenceY, pressureDifferenceZ;
|
||||||
double maxMagnitude = 0;
|
double maxMagnitude = 0;
|
||||||
//project
|
//project
|
||||||
@ -386,26 +459,30 @@ LIBRARY_API double pressurecell_project_velocity(Environment * environment, Chun
|
|||||||
pressureDifferenceZ = 0;
|
pressureDifferenceZ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//project the pressure gradient onto the velocity field
|
|
||||||
uArr[IX(x,y,z)] = uArr[IX(x,y,z)] - pressureDifferenceX;
|
|
||||||
vArr[IX(x,y,z)] = vArr[IX(x,y,z)] - pressureDifferenceY;
|
|
||||||
wArr[IX(x,y,z)] = wArr[IX(x,y,z)] - pressureDifferenceZ;
|
|
||||||
|
|
||||||
float magnitude = sqrt(uArr[IX(x,y,z)] * uArr[IX(x,y,z)] + vArr[IX(x,y,z)] * vArr[IX(x,y,z)] + wArr[IX(x,y,z)] * wArr[IX(x,y,z)]);
|
float magnitude = sqrt(uArr[IX(x,y,z)] * uArr[IX(x,y,z)] + vArr[IX(x,y,z)] * vArr[IX(x,y,z)] + wArr[IX(x,y,z)] * wArr[IX(x,y,z)]);
|
||||||
// if(maxMagnitude < magnitude){
|
if(maxMagnitude < magnitude){
|
||||||
// maxMagnitude = magnitude;
|
maxMagnitude = magnitude;
|
||||||
// }
|
}
|
||||||
|
|
||||||
if(magnitude != magnitude || magnitude > 1000000){
|
if(magnitude != magnitude || magnitude > 10){
|
||||||
printf("invalid magnitude! %f\n", magnitude);
|
printf("invalid magnitude! %f\n", magnitude);
|
||||||
printf("%f %f %f\n", pressureDifferenceX, pressureDifferenceY, pressureDifferenceZ);
|
printf("%f %f %f\n", pressureDifferenceX, pressureDifferenceY, pressureDifferenceZ);
|
||||||
|
printf("%f %f %f\n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
||||||
printf("%f %f \n",pressureTemp[IX(x+1,y,z)],pressureTemp[IX(x-1,y,z)]);
|
printf("%f %f \n",pressureTemp[IX(x+1,y,z)],pressureTemp[IX(x-1,y,z)]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
int a = 1;
|
||||||
|
int b = 0;
|
||||||
|
int c = a / b;
|
||||||
uArr[IX(x,y,z)] = 0;
|
uArr[IX(x,y,z)] = 0;
|
||||||
vArr[IX(x,y,z)] = 0;
|
vArr[IX(x,y,z)] = 0;
|
||||||
wArr[IX(x,y,z)] = 0;
|
wArr[IX(x,y,z)] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//project the pressure gradient onto the velocity field
|
||||||
|
uArr[IX(x,y,z)] = uArr[IX(x,y,z)] - pressureDifferenceX;
|
||||||
|
vArr[IX(x,y,z)] = vArr[IX(x,y,z)] - pressureDifferenceY;
|
||||||
|
wArr[IX(x,y,z)] = wArr[IX(x,y,z)] - pressureDifferenceZ;
|
||||||
|
|
||||||
//normalize if the projection has pushed us wayyy out of bounds
|
//normalize if the projection has pushed us wayyy out of bounds
|
||||||
//ie, large pressure differentials can create huge imbalances
|
//ie, large pressure differentials can create huge imbalances
|
||||||
// if(magnitude > 1.0f){
|
// if(magnitude > 1.0f){
|
||||||
@ -451,47 +528,47 @@ LIBRARY_API double pressurecell_project_velocity(Environment * environment, Chun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//normalize vector field
|
//normalize vector field
|
||||||
// if(maxMagnitude > 1){
|
if(maxMagnitude > 1){
|
||||||
// for(y = 1; y < DIM-1; y++){
|
for(y = 1; y < DIM-1; y++){
|
||||||
// for(z = 1; z < DIM-1; z++){
|
for(z = 1; z < DIM-1; z++){
|
||||||
// for(x = 1; x < DIM-1; x++){
|
for(x = 1; x < DIM-1; x++){
|
||||||
|
|
||||||
// //project the pressure gradient onto the velocity field
|
//project the pressure gradient onto the velocity field
|
||||||
// uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / maxMagnitude;
|
uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / maxMagnitude;
|
||||||
// vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / maxMagnitude;
|
vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / maxMagnitude;
|
||||||
// wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / maxMagnitude;
|
wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / maxMagnitude;
|
||||||
|
|
||||||
// //check for NaNs
|
//check for NaNs
|
||||||
// if(uArr[IX(x,y,z)] != uArr[IX(x,y,z)]){
|
if(uArr[IX(x,y,z)] != uArr[IX(x,y,z)]){
|
||||||
// uArr[IX(x,y,z)] = 0;
|
uArr[IX(x,y,z)] = 0;
|
||||||
// }
|
}
|
||||||
// if(vArr[IX(x,y,z)] != vArr[IX(x,y,z)]){
|
if(vArr[IX(x,y,z)] != vArr[IX(x,y,z)]){
|
||||||
// vArr[IX(x,y,z)] = 0;
|
vArr[IX(x,y,z)] = 0;
|
||||||
// }
|
}
|
||||||
// if(wArr[IX(x,y,z)] != wArr[IX(x,y,z)]){
|
if(wArr[IX(x,y,z)] != wArr[IX(x,y,z)]){
|
||||||
// wArr[IX(x,y,z)] = 0;
|
wArr[IX(x,y,z)] = 0;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if(
|
if(
|
||||||
// uArr[x,y,z] < -100.0f || uArr[x,y,z] > 100.0f ||
|
uArr[x,y,z] < -1.0f || uArr[x,y,z] > 1.0f ||
|
||||||
// vArr[x,y,z] < -100.0f || vArr[x,y,z] > 100.0f ||
|
vArr[x,y,z] < -1.0f || vArr[x,y,z] > 1.0f ||
|
||||||
// wArr[x,y,z] < -100.0f || wArr[x,y,z] > 100.0f
|
wArr[x,y,z] < -1.0f || wArr[x,y,z] > 1.0f
|
||||||
// // || magnitude < -1000 || magnitude > 1000
|
// || magnitude < -1000 || magnitude > 1000
|
||||||
// // pressureDivergence < -1000 || pressureDivergence > 1000
|
// pressureDivergence < -1000 || pressureDivergence > 1000
|
||||||
// ){
|
){
|
||||||
// printf("pressure divergence thing is off!!\n");
|
printf("pressure divergence thing is off!!\n");
|
||||||
// printf("%f \n", magnitude);
|
printf("%f \n", magnitude);
|
||||||
// printf("%f \n", pressureDivergence);
|
printf("%f \n", pressureDivergence);
|
||||||
// printf("%f %f %f \n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
printf("%f %f %f \n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
||||||
// printf("%f %f \n", pressureTemp[IX(x+1,y,z)], pressureTemp[IX(x-1,y,z)]);
|
printf("%f %f \n", pressureTemp[IX(x+1,y,z)], pressureTemp[IX(x-1,y,z)]);
|
||||||
// printf("%f %f \n", pressureTemp[IX(x,y+1,z)], pressureTemp[IX(x,y-1,z)]);
|
printf("%f %f \n", pressureTemp[IX(x,y+1,z)], pressureTemp[IX(x,y-1,z)]);
|
||||||
// printf("%f %f \n", pressureTemp[IX(x,y,z+1)], pressureTemp[IX(x,y,z-1)]);
|
printf("%f %f \n", pressureTemp[IX(x,y,z+1)], pressureTemp[IX(x,y,z-1)]);
|
||||||
// printf("\n");
|
printf("\n");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
return maxMagnitude;
|
return maxMagnitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,6 +590,9 @@ LIBRARY_API void pressurecell_copy_for_next_frame(Environment * environment, Chu
|
|||||||
uArr[IX(x,y,z)] = uTemp[IX(x,y,z)];
|
uArr[IX(x,y,z)] = uTemp[IX(x,y,z)];
|
||||||
vArr[IX(x,y,z)] = vTemp[IX(x,y,z)];
|
vArr[IX(x,y,z)] = vTemp[IX(x,y,z)];
|
||||||
wArr[IX(x,y,z)] = wTemp[IX(x,y,z)];
|
wArr[IX(x,y,z)] = wTemp[IX(x,y,z)];
|
||||||
|
// if(uArr[IX(x,y,z)] > 1000 || vArr[IX(x,y,z)] > 1000 || wArr[IX(x,y,z)] > 1000){
|
||||||
|
// printf("invalid set: %f %f %f \n", uArr[IX(x,y,z)], vArr[IX(x,y,z)], wArr[IX(x,y,z)]);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
#include "../../includes/native/electrosphere_server_fluid_manager_ServerFluidChunk.h"
|
#include "../../includes/native/electrosphere_server_fluid_manager_ServerFluidChunk.h"
|
||||||
#include "../../includes/native/electrosphere_client_fluid_cache_FluidChunkData.h"
|
#include "../../includes/native/electrosphere_client_fluid_cache_FluidChunkData.h"
|
||||||
|
|
||||||
|
#include "fluid/queue/chunk.h"
|
||||||
|
|
||||||
#include "../../includes/mem/pool.h"
|
#include "../../includes/mem/pool.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,6 +123,12 @@ void allocateCenterField(JNIEnv * env, jobject fluidObj, jfieldID arrFieldId){
|
|||||||
//assign to array
|
//assign to array
|
||||||
jobject jd = (*env)->GetObjectField(env,fluidObj,arrFieldId);
|
jobject jd = (*env)->GetObjectField(env,fluidObj,arrFieldId);
|
||||||
(*env)->SetObjectArrayElement(env,jd,CENTER_POS,byteBuffer);
|
(*env)->SetObjectArrayElement(env,jd,CENTER_POS,byteBuffer);
|
||||||
|
|
||||||
|
//zero out the data
|
||||||
|
float * floatView = (float *)buffer;
|
||||||
|
for(int x = 0; x < DIM * DIM * DIM; x++){
|
||||||
|
floatView[x] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user