Exemplo n.º 1
0
        /// <summary>
        /// Initialize the solver with parameters
        /// </summary>
        /// <param name="param"></param>
        public void Init(SolverParams param)
        {
            NX         = param.Width;
            NY         = param.Height;
            NZ         = param.Depth;
            dims       = new IntPos(NX, NY, NZ);
            array_size = NX * NY * NZ;

            dt     = param.Dt;
            dt_inv = -dt * NX;

            force       = param.Force;
            source      = param.Source;
            tAmb        = param.Tamb;
            temperature = param.Temperature;
            vorticity   = param.Vorticity;

            vel_x           = new float[array_size];
            vel_y           = new float[array_size];
            vel_z           = new float[array_size];
            vel_x_prev      = new float[array_size];
            vel_y_prev      = new float[array_size];
            vel_z_prev      = new float[array_size];
            density         = new float[array_size];
            density_prev    = new float[array_size];
            heat            = new float[array_size];
            heat_prev       = new float[array_size];
            pressure        = new float[array_size];
            pressure_prev   = new float[array_size];
            curl            = new float[array_size];
            compressibility = new float[array_size];
            divergence      = new float[array_size];
            obstacles       = new int[array_size];
        }
Exemplo n.º 2
0
        private float get_interpolated_val_with_obs(float[] x, int[] obs, Vector3 pos, float h, IntPos n)
        {
            //The grid world pos is 0-1.
            int i0 = (int)(pos.X / h);
            int j0 = (int)(pos.Y / h);
            int k0 = (int)(pos.Z / h);
            int i1 = Clamp(i0 + 1, 0, n.X - 1); // returns 1??
            int j1 = Clamp(j0 + 1, 0, n.Y - 1);
            int k1 = Clamp(k0 + 1, 0, n.Z - 1);

            //Calculate t per component
            float it = (pos.X - i0 * h);
            float jt = (pos.Y - j0 * h);
            float kt = (pos.Z - k0 * h);

            // Assume a cube with 8 points
            //Front face
            //Top Front MIX
            float xFrontLeftTop   = x[IX(i0, j1, k0)] * (1 - obs[IX(i0, j1, k0)]);
            float xFrontRightTop  = x[IX(i1, j1, k0)] * (1 - obs[IX(i1, j1, k0)]);
            float xFrontTopInterp = MIX(xFrontLeftTop, xFrontRightTop, it);
            //Bottom Front MIX
            float xFrontLeftBottom   = x[IX(i0, j0, k0)] * (1 - obs[IX(i0, j0, k0)]);
            float xFrontRightBottom  = x[IX(i1, j0, k0)] * (1 - obs[IX(i1, j0, k0)]);
            float xFrontBottomInterp = MIX(xFrontLeftBottom, xFrontRightBottom, it);

            //Back face
            //Top Back MIX
            float xBackLeftTop   = x[IX(i0, j1, k1)] * (1 - obs[IX(i0, j1, k1)]);
            float xBackRightTop  = x[IX(i1, j1, k1)] * (1 - obs[IX(i1, j1, k1)]);
            float xBackTopInterp = MIX(xBackLeftTop, xBackRightTop, it);
            //Bottom Back MIX
            float xBackLeftBottom   = x[IX(i0, j0, k1)] * (1 - obs[IX(i0, j0, k1)]);
            float xBackRightBottom  = x[IX(i1, j0, k1)] * (1 - obs[IX(i1, j0, k1)]);
            float xBackBottomInterp = MIX(xBackLeftBottom, xBackRightBottom, it);


            //Now get middle of front -The bilinear interp of the front face
            float xBiLerpFront = MIX(xFrontBottomInterp, xFrontTopInterp, jt);

            //Now get middle of back -The bilinear interp of the back face
            float xBiLerpBack = MIX(xBackBottomInterp, xBackTopInterp, jt);

            //Now get the interpolated point between the points calculated in the front and back faces - The trilinear interp part
            float xTriLerp = MIX(xBiLerpFront, xBiLerpBack, kt);

            return(xTriLerp);
        }