Ejemplo n.º 1
0
        protected override void ComputeChangeRate(double[] k, double AbsTime, double RelTime, double[] edgeFluxes = null)
        {
            using (new ilPSP.Tracing.FuncTrace()) {
                RaiseOnBeforeComputechangeRate(AbsTime, RelTime);

                Evaluator.time = AbsTime;
                Evaluator.Evaluate(1.0, 0.0, k, outputBndEdge: edgeFluxes);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in standard terms");

                //k.SaveToTextFile("k-lts-bulk.txt");

                boundaryEvaluator.Value.time = AbsTime;
                boundaryEvaluator.Value.Evaluate(1.0, 1.0, k);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in boundary terms");

                // Agglomerate fluxes
                speciesMap.Agglomerator.ManipulateRHS(k, Mapping);

                // Apply inverse to all cells with non-identity mass matrix
                IBMMassMatrixFactory massMatrixFactory = speciesMap.GetMassMatrixFactory(Mapping);
                IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, k, 0.0, k, cutAndTargetCells);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Computes the change rates by sequentially evaluating the standard
        /// and immersed boundary operators. Afterwards, the change rate is
        /// agglomerated and multiplied by the inverse mass matrix (of the
        /// agglomerated basis)
        /// </summary>
        protected override void ComputeChangeRate(double[] k, double AbsTime, double RelTime, double[] edgeFluxes = null)
        {
            using (new ilPSP.Tracing.FuncTrace()) {
                RaiseOnBeforeComputechangeRate(AbsTime, RelTime);

                //var CV = new CoordinateVector(Evaluator.DomainFields);
                //double dist = Environment.CompareTo(CV);

                //(new CoordinateVector(Evaluator.DomainFields)).SaveToTextFile("inp-rk.txt");
                //(new CoordinateVector(Evaluator.Parameters.ToArray())).SaveToTextFile("para-rk.txt");

                Evaluator.time = AbsTime + RelTime;
                Evaluator.Evaluate(1.0, 0.0, k);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in standard terms");

                //k.SaveToTextFile("k-rk-bulk.txt");

                boundaryEvaluator.Value.time = AbsTime + RelTime;
                boundaryEvaluator.Value.Evaluate(1.0, 1.0, k);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in boundary terms");

                //k.SaveToTextFile("k-rk-bndy.txt");

                // Agglomerate fluxes
                speciesMap.Agglomerator.ManipulateRHS(k, Mapping);

                // Apply inverse to all cells with non-identity mass matrix
                IBMMassMatrixFactory massMatrixFactory = speciesMap.GetMassMatrixFactory(Mapping);
                IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, k, 0.0, k, cutAndTargetCells);
            }
        }
Ejemplo n.º 3
0
        public override double Perform(double dt)
        {
            if (agglomerationPatternHasChanged)
            {
                // TO DO: Agglomerate difference between old $cutAndTargetCells and new $cutAndTargetCells only
                BuildEvaluatorsAndMasks();

                // Required whenever agglomeration pattern changes
                SpeciesId            speciesId                 = speciesMap.Tracker.GetSpeciesId(speciesMap.Control.FluidSpeciesName);
                IBMMassMatrixFactory massMatrixFactory         = speciesMap.GetMassMatrixFactory(Mapping);
                BlockMsrMatrix       nonAgglomeratedMassMatrix = massMatrixFactory.BaseFactory.GetMassMatrix(
                    Mapping,
                    new Dictionary <SpeciesId, IEnumerable <double> >()
                {
                    { speciesId, Enumerable.Repeat(1.0, Mapping.NoOfVariables) }
                },
                    inverse: false);

                IBMUtility.SubMatrixSpMV(nonAgglomeratedMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutCells);
                speciesMap.Agglomerator.ManipulateRHS(CurrentState, Mapping);
                IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutAndTargetCells);
                speciesMap.Agglomerator.Extrapolate(CurrentState.Mapping);

                //Broadcast to RungeKutta ???
            }

            dt = base.Perform(dt);

            speciesMap.Agglomerator.Extrapolate(CurrentState.Mapping);
            return(dt);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates an instance of <see cref="IBMMassMatrixFactory"/> that is
 /// appropriate for the given <paramref name="mapping"/>
 /// </summary>
 /// <param name="mapping"></param>
 /// <returns></returns>
 public IBMMassMatrixFactory GetMassMatrixFactory(CoordinateMapping mapping)
 {
     if (MassMatrixFactory == null || !mapping.Equals(MassMatrixFactory.Mapping))
     {
         MassMatrixFactory = new IBMMassMatrixFactory(this, mapping, Control.FluidSpeciesName, Control.LevelSetQuadratureOrder);
     }
     return(MassMatrixFactory);
 }
Ejemplo n.º 5
0
        protected void AgglomerateAndExtrapolateDGCoordinates()
        {
            IBMMassMatrixFactory massMatrixFactory         = speciesMap.GetMassMatrixFactory(Mapping);
            BlockMsrMatrix       nonAgglomeratedMassMatrix = massMatrixFactory.NonAgglomeratedMassMatrix;

            IBMUtility.SubMatrixSpMV(nonAgglomeratedMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutCells);                    // eq. (39)
            speciesMap.Agglomerator.ManipulateRHS(CurrentState, Mapping);                                                           // eq. (39)
            IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, CurrentState, 0.0, CurrentState, cutAndTargetCells); // eq. (39)
            speciesMap.Agglomerator.Extrapolate(CurrentState.Mapping);                                                              // eq. (41)
        }
Ejemplo n.º 6
0
        //int count = 0;

        /// <summary>
        /// Computes the change rates by sequentially evaluating the standard
        /// and immersed boundary operators. Afterwards, the change rate is
        /// agglomerated and multiplied by the inverse mass matrix (of the
        /// agglomerated basis)
        /// </summary>
        protected override void ComputeChangeRate(double[] k, double AbsTime, double RelTime, double[] edgeFluxes = null)
        {
            using (new ilPSP.Tracing.FuncTrace()) {
                RaiseOnBeforeComputechangeRate(AbsTime, RelTime);

                //var CV = new CoordinateVector(Evaluator.DomainFields);
                //double dist = Environment.CompareTo(CV);

                //(new CoordinateVector(Evaluator.DomainFields)).SaveToTextFile("inp-rk.txt");
                //(new CoordinateVector(Evaluator.Parameters.ToArray())).SaveToTextFile("para-rk.txt");

                Debug.Assert(Evaluator.DomainFields.Fields.ListEquals(boundaryEvaluator.Value.DomainFields.Fields, (a, b) => object.ReferenceEquals(b, a)));

                //var cv = new CoordinateVector(Evaluator.DomainFields);
                //Random r = new Random(666);
                //for(int ir = 0; ir < cv.Length; ir++) {
                //    cv[ir] = r.NextDouble();
                //}


                Evaluator.time = AbsTime + RelTime;
                Evaluator.Evaluate(1.0, 0.0, k);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in standard terms");

                //Console.WriteLine(String.Format("\nBULK: L2-Norm of change rate = {0}", k.L2Norm()));
                //k.SaveToTextFile(String.Format("k_BULK_{0}.txt", count));

                boundaryEvaluator.Value.time = AbsTime + RelTime;
                boundaryEvaluator.Value.Evaluate(1.0, 1.0, k);
                Debug.Assert(
                    !k.Any(f => double.IsNaN(f)),
                    "Unphysical flux in boundary terms");

                //Console.WriteLine(String.Format("BOUNDARY: L2-Norm of change rate = {0}", k.L2Norm()));
                //k.SaveToTextFile(String.Format("k_BOUND_{0}.txt", count));

                // Agglomerate fluxes
                speciesMap.Agglomerator.ManipulateRHS(k, Mapping);

                // Apply inverse to all cells with non-identity mass matrix
                IBMMassMatrixFactory massMatrixFactory = speciesMap.GetMassMatrixFactory(Mapping);
                IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, k, 0.0, k, cutAndTargetCells);

                //massMatrixFactory.MassMatrix.SaveToTextFileSparse("massMatrix.txt");

                //Console.WriteLine($"AGGLOMERATOR: L2-Norm of change rate = {k.L2Norm()}");
                //k.SaveToTextFile($"k_CUT_{count}.txt");
                //k.SaveToTextFile($"c:\\tmp\\cns_k_CUT_{count}.txt");

                //count++;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates an instance of <see cref="IBMMassMatrixFactory"/> that is
        /// appropriate for the given <paramref name="mapping"/>
        /// </summary>
        /// <param name="mapping"></param>
        /// <returns></returns>
        public IBMMassMatrixFactory GetMassMatrixFactory(CoordinateMapping mapping)
        {
            if (MaMaFactCache_TrackerVersion != Tracker.VersionCnt)
            {
                MaMaFactCache.Clear();
                MaMaFactCache_TrackerVersion = Tracker.VersionCnt;
            }

            int[] degCodes = mapping.BasisS.Select(bs => bs.Degree).ToArray();
            if (!MaMaFactCache.ContainsKey(degCodes))
            {
                var mmf = new IBMMassMatrixFactory(this, mapping, Control.FluidSpeciesName, Control.LevelSetQuadratureOrder);
                MaMaFactCache.Add(degCodes, mmf);
            }

            return(MaMaFactCache[degCodes]);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Computes the change rates by sequentially evaluating the standard
        /// and immersed boundary operators. Afterwards, the change rate is
        /// agglomerated and multiplied by the inverse mass matrix (of the
        /// agglomerated basis)
        /// </summary>
        /// <param name="k"></param>
        /// <param name="AbsTime"></param>
        /// <param name="RelTime"></param>
        protected override void ComputeChangeRate(double[] k, double AbsTime, double RelTime, double[] edgeFluxes = null)
        {
            Evaluator.Evaluate(1.0, 0.0, k, AbsTime + RelTime);
            Debug.Assert(
                !k.Any(f => double.IsNaN(f)),
                "Unphysical flux in standard terms");

            boundaryEvaluator.Value.Evaluate(1.0, 1.0, k, AbsTime + RelTime);
            Debug.Assert(
                !k.Any(f => double.IsNaN(f)),
                "Unphysical flux in boundary terms");

            // Agglomerate fluxes
            speciesMap.Agglomerator.ManipulateRHS(k, Mapping);

            // Apply inverse to all cells with non-identity mass matrix
            IBMMassMatrixFactory massMatrixFactory = speciesMap.GetMassMatrixFactory(Mapping);

            IBMUtility.SubMatrixSpMV(massMatrixFactory.InverseMassMatrix, 1.0, k, 0.0, k, cutAndTargetCells);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Discards old quadrature information
 /// </summary>
 /// <param name="value"></param>
 public void OnNext(LevelSetTracker.LevelSetRegions value)
 {
     this.MassMatrixFactory = null;
     this.cellAgglomeration = null;
 }