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); }
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; }