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