Beispiel #1
0
        public static ScalarField FromAnalyticalField(AnalyticalField func, Index size, Vector origin, Vector cellSize)
        {
            Debug.Assert(size.Length == origin.Length && size.Length == cellSize.Length);

            RectlinearGrid grid  = new RectlinearGrid(size);
            ScalarField    field = new ScalarField(grid);

            for (int idx = 0; idx < size.Product(); ++idx)
            {
                // Compute the n-dimensional position.
                int   index = idx;
                Index pos   = new Index(0, size.Length);
                pos[0] = index % size[0];

                for (int dim = 1; dim < size.Length; ++dim)
                {
                    index   -= pos[dim - 1];
                    index   /= size[dim - 1];
                    pos[dim] = index % size[dim];
                }

                Vector posV = origin + pos * cellSize;
                field[idx] = func(posV);
            }

            return(field);
        }
Beispiel #2
0
        public virtual VectorField GetSlicePlanarVelocity(int posInLastDimension)
        {
            ScalarField[] slices = new ScalarField[Size.Length - 1];

            // Copy the grid - one dimension smaller!
            RectlinearGrid grid    = Grid as RectlinearGrid;
            Index          newSize = new Index(Size.Length - 1);

            Array.Copy(Size.Data, newSize.Data, newSize.Length);

            FieldGrid sliceGrid = new RectlinearGrid(newSize);

            for (int i = 0; i < Size.Length - 1; ++i)
            {
                slices[i] = new ScalarField(sliceGrid);
                Array.Copy(((ScalarField)this.Scalars[i]).Data, newSize.Product() * posInLastDimension, slices[i].Data, 0, newSize.Product());
                slices[i].TimeOrigin = posInLastDimension;
            }
            return(new VectorField(slices));
        }