Ejemplo n.º 1
0
 public ScalarFieldUnsteady(ScalarField[] fields, float timeStart, float timeStep = 1.0f) : base()
 {
     _slices    = fields;
     _sliceGrid = fields[0].Grid.GetAsTimeGrid(fields.Length, timeStart, timeStep);
     //for (int slice = 0; slice < _slices.Length; ++slice)
     //{
     //    _slices[slice].TimeOrigin = timeStart + timeStep * slice;
     //}
 }
Ejemplo n.º 2
0
 public ScalarFieldUnsteady(ScalarField[] fields, float timeStart, float timeStep = 1.0f)
     : base()
 {
     _slices = fields;
     _sliceGrid = fields[0].Grid.GetAsTimeGrid(fields.Length, timeStart, timeStep);
     //for (int slice = 0; slice < _slices.Length; ++slice)
     //{
     //    _slices[slice].TimeOrigin = timeStart + timeStep * slice;
     //}
 }
Ejemplo n.º 3
0
        public VectorFieldUnsteady(VectorFieldUnsteady field, VFJFunction function, int outputDim)
        {
            int       scalars  = outputDim;
            FieldGrid gridCopy = field._scalarsUnsteady[0].TimeSlices[0].Grid.Copy();

            _scalarsUnsteady = new ScalarFieldUnsteady[outputDim];

            // Reserve the space.
            for (int comp = 0; comp < outputDim; ++comp)
            {
                ScalarField[] fields = new ScalarField[field.Size.T]; //(field.Grid);

                for (int t = 0; t < field.Size.T; ++t)

                {
                    fields[t] = new ScalarField(gridCopy);
                }

                _scalarsUnsteady[comp]              = new ScalarFieldUnsteady(fields);
                _scalarsUnsteady[comp].TimeOrigin   = field[0].TimeOrigin ?? 0;
                _scalarsUnsteady[comp].InvalidValue = field.InvalidValue;
                _scalarsUnsteady[comp].DoNotScale();
            }

            this.InvalidValue = field.InvalidValue;
            this.TimeOrigin   = field.TimeOrigin;

            Grid = field.Grid.Copy();

            // Since the time component is in the grid size as well, we do not need to account for time specially.
            GridIndex indexIterator = new GridIndex(field.Size);

            foreach (GridIndex index in indexIterator)
            {
                Vector v = field.Sample((int)index);

                if (v[0] == InvalidValue)
                {
                    for (int dim = 0; dim < Scalars.Length; ++dim)
                    {
                        _scalarsUnsteady[dim][(int)index] = (float)InvalidValue;
                    }
                    continue;
                }

                SquareMatrix J         = field.SampleDerivative(index);
                Vector       funcValue = function(v, J);

                for (int dim = 0; dim < Scalars.Length; ++dim)
                {
                    Scalars[dim][(int)index] = funcValue[dim];
                }
            }
        }
Ejemplo n.º 4
0
        public VectorField(VectorField field, VFJFunction function, int outputDim, bool needJacobian = true)
        {
            int scalars = outputDim;/*function(field.Sample(0), field.SampleDerivative(new Vector(0, field.Size.Length))).Length;*/

            _scalars = new ScalarField[scalars];
            FieldGrid gridCopy = field.Grid.Copy();

            // In case the input field was time dependant, this one is not. Still, we keep the size and origin of the time as new dimension!
            gridCopy.TimeDependant = false;

            for (int dim = 0; dim < scalars; ++dim)
            {
                Scalars[dim] = new ScalarField(gridCopy);
            }
            this.InvalidValue = field.InvalidValue;

            GridIndex indexIterator = new GridIndex(field.Size);

            foreach (GridIndex index in indexIterator)
            {
                Vector v = field.Sample((int)index);

                if (v[0] == InvalidValue)
                {
                    for (int dim = 0; dim < Scalars.Length; ++dim)
                    {
                        Scalars[dim][(int)index] = (float)InvalidValue;
                    }
                    continue;
                }

                SquareMatrix J         = needJacobian? field.SampleDerivative(index) : null;
                Vector       funcValue = function(v, J);

                for (int dim = 0; dim < Scalars.Length; ++dim)
                {
                    var vec = Scalars[dim];
                    Scalars[dim][(int)index] = funcValue[dim];
                }
            }
        }
Ejemplo n.º 5
0
 //private float? _timeSlice = null;
 //public override float? TimeSlice
 //{
 //    get
 //    {
 //        return Grid.TimeOrigin;
 //    }
 //    set
 //    {
 //        Grid.TimeOrigin = value;
 //    }
 //}
 /// <summary>
 /// Instanciate a new field. The dimension is derived from the fields size.
 /// </summary>
 /// <param name="fieldSize">Number of grid edges in each dimension.</param>
 public ScalarField(FieldGrid grid)
 {
     Grid = grid;
     _data = new float[Size.Product()];
 }
Ejemplo n.º 6
0
        //private float? _timeSlice = null;
        //public override float? TimeSlice
        //{
        //    get
        //    {
        //        return Grid.TimeOrigin;
        //    }

        //    set
        //    {
        //        Grid.TimeOrigin = value;
        //    }
        //}

        /// <summary>
        /// Instanciate a new field. The dimension is derived from the fields size.
        /// </summary>
        /// <param name="fieldSize">Number of grid edges in each dimension.</param>
        public ScalarField(FieldGrid grid)
        {
            Grid  = grid;
            _data = new float[Size.Product()];
        }