From 9bb8c2f3602681bfac7c2eac80321e7e46903744 Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 12 Dec 2024 14:48:13 -0500 Subject: [PATCH] neighbor sourcing bounds function --- src/main/c/src/fluid/sim/grid2/grid2.c | 6 +- src/main/c/src/fluid/sim/grid2/utilities.c | 131 ++++++++++++++++++++- 2 files changed, 129 insertions(+), 8 deletions(-) diff --git a/src/main/c/src/fluid/sim/grid2/grid2.c b/src/main/c/src/fluid/sim/grid2/grid2.c index d8bb3a96..7f8b6d79 100644 --- a/src/main/c/src/fluid/sim/grid2/grid2.c +++ b/src/main/c/src/fluid/sim/grid2/grid2.c @@ -341,7 +341,7 @@ static inline void fluid_grid2_apply_bounds_mask(Environment * environment, floa invertedMask = _mm256_loadu_ps(&environment->state.grid2.fluid_grid2_border_mask_inverted[IX(x,y,z)]); realPart = _mm256_mul_ps(realVal,invertedMask); finalVec = _mm256_add_ps(realPart,maskedBounds); - _mm256_storeu_ps(&realArr[IX(x,y,z)],finalVec); + _mm256_storeu_ps(&boundsArr[IX(x,y,z)],finalVec); //middle part @@ -353,7 +353,7 @@ static inline void fluid_grid2_apply_bounds_mask(Environment * environment, floa invertedMask = _mm256_loadu_ps(&environment->state.grid2.fluid_grid2_border_mask_inverted[IX(x,y,z)]); realPart = _mm256_mul_ps(realVal,invertedMask); finalVec = _mm256_add_ps(realPart,maskedBounds); - _mm256_storeu_ps(&realArr[IX(x,y,z)],finalVec); + _mm256_storeu_ps(&boundsArr[IX(x,y,z)],finalVec); //upper part x = 10; @@ -364,7 +364,7 @@ static inline void fluid_grid2_apply_bounds_mask(Environment * environment, floa invertedMask = _mm256_loadu_ps(&environment->state.grid2.fluid_grid2_border_mask_inverted[IX(x,y,z)]); realPart = _mm256_mul_ps(realVal,invertedMask); finalVec = _mm256_add_ps(realPart,maskedBounds); - _mm256_storeu_ps(&realArr[IX(x,y,z)],finalVec); + _mm256_storeu_ps(&boundsArr[IX(x,y,z)],finalVec); } } diff --git a/src/main/c/src/fluid/sim/grid2/utilities.c b/src/main/c/src/fluid/sim/grid2/utilities.c index 7b63fb7c..fb972097 100644 --- a/src/main/c/src/fluid/sim/grid2/utilities.c +++ b/src/main/c/src/fluid/sim/grid2/utilities.c @@ -193,6 +193,125 @@ void fluid_grid2_set_bounds_continuity( 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 the neighbor's value + */ +void fluid_grid2_set_bounds_neighbor( + Environment * environment, + int sourceType, + float * target +){ + float * neighborArr; + switch(sourceType){ + case BOUND_SET_DENSITY: { + neighborArr = environment->state.grid2.fluid_grid2_neighborArr_d; + } break; + case BOUND_SET_VECTOR_U: { + neighborArr = environment->state.grid2.fluid_grid2_neighborArr_u; + } break; + case BOUND_SET_VECTOR_V: { + neighborArr = environment->state.grid2.fluid_grid2_neighborArr_v; + } break; + case BOUND_SET_VECTOR_W: { + neighborArr = environment->state.grid2.fluid_grid2_neighborArr_w; + } break; + } + //set the boundary planes + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(0,x,y)] = neighborArr[IX(0,x,y)]; + target[IX(DIM-1,x,y)] = neighborArr[IX(DIM-1,x,y)]; + target[IX(x,0,y)] = neighborArr[IX(x,0,y)]; + target[IX(x,DIM-1,y)] = neighborArr[IX(x,DIM-1,y)]; + target[IX(x,y,0)] = neighborArr[IX(x,y,0)]; + target[IX(x,y,DIM-1)] = neighborArr[IX(x,y,DIM-1)]; + } + } + + //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)] = neighborArr[IX(x,0,0)]; + target[IX(x,DIM-1,0)] = neighborArr[IX(x,DIM-1,0)]; + target[IX(x,0,DIM-1)] = neighborArr[IX(x,0,DIM-1)]; + target[IX(x,DIM-1,DIM-1)] = neighborArr[IX(x,DIM-1,DIM-1)]; + + target[IX(0,x,0)] = neighborArr[IX(0,x,0)]; + target[IX(DIM-1,x,0)] = neighborArr[IX(DIM-1,x,0)]; + target[IX(0,x,DIM-1)] = neighborArr[IX(0,x,DIM-1)]; + target[IX(DIM-1,x,DIM-1)] = neighborArr[IX(DIM-1,x,DIM-1)]; + + + target[IX(0,0,x)] = neighborArr[IX(0,0,x)]; + target[IX(DIM-1,0,x)] = neighborArr[IX(DIM-1,0,x)]; + target[IX(0,DIM-1,x)] = neighborArr[IX(0,DIM-1,x)]; + target[IX(DIM-1,DIM-1,x)] = neighborArr[IX(DIM-1,DIM-1,x)]; + + } + //sets the corners of the chunk + //this should logically follow from how we're treating the boundary planes + target[IX(0,0,0)] = neighborArr[IX(0,0,0)]; + target[IX(DIM-1,0,0)] = neighborArr[IX(DIM-1,0,0)]; + target[IX(0,DIM-1,0)] = neighborArr[IX(0,DIM-1,0)]; + target[IX(0,0,DIM-1)] = neighborArr[IX(0,0,DIM-1)]; + target[IX(DIM-1,DIM-1,0)] = neighborArr[IX(DIM-1,DIM-1,0)]; + target[IX(0,DIM-1,DIM-1)] = neighborArr[IX(0,DIM-1,DIM-1)]; + target[IX(DIM-1,0,DIM-1)] = neighborArr[IX(DIM-1,0,DIM-1)]; + target[IX(DIM-1,DIM-1,DIM-1)] = neighborArr[IX(DIM-1,DIM-1,DIM-1)]; +} + +/** + * Sets the bounds to 0 + */ +void fluid_grid2_set_bounds_zero( + Environment * environment, + float * target +){ + float * boundsArr = environment->state.grid2.fluid_grid2_neighborArr_d; + //set the boundary planes + for(int x=1; x < DIM-1; x++){ + for(int y = 1; y < DIM-1; y++){ + target[IX(0,x,y)] = 0; + target[IX(DIM-1,x,y)] = 0; + target[IX(x,0,y)] = 0; + target[IX(x,DIM-1,y)] = 0; + 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; +} + /** * Sets the bounds of this cube to those of its neighbor */ @@ -204,18 +323,20 @@ LIBRARY_API void fluid_grid2_set_bounds( switch(vector_dir){ case BOUND_SET_VECTOR_DIFFUSE_PHI_U: case BOUND_SET_VECTOR_DIFFUSE_PHI_V: - case BOUND_SET_VECTOR_DIFFUSE_PHI_W: - case BOUND_SET_VECTOR_U: - case BOUND_SET_VECTOR_V: - case BOUND_SET_VECTOR_W: { + case BOUND_SET_VECTOR_DIFFUSE_PHI_W: { fluid_grid2_set_bounds_reflection(environment,vector_dir,target); } break; case BOUND_SET_DENSITY_PHI: - case BOUND_SET_DENSITY: case BOUND_SET_PROJECTION_PHI: case BOUND_SET_PROJECTION_PHI_0: { fluid_grid2_set_bounds_continuity(environment,target); } break; + case BOUND_SET_VECTOR_U: + case BOUND_SET_VECTOR_V: + case BOUND_SET_VECTOR_W: + case BOUND_SET_DENSITY: { + fluid_grid2_set_bounds_neighbor(environment,vector_dir,target); + } break; } }