/// <summary> /// <see cref="ResidualLogger"/> /// </summary> /// <param name="program"></param> /// <param name="residualInterval"> /// <see cref="ResidualLogger"/> /// </param> /// <param name="differentialOperator"> /// The spatial differential operator defining (the spatial part of) /// the system of equations that are solved. /// </param> public RigorousResidualLogger(Application <T> program, DGField[] consVars, CoordinateMapping paramMap, int residualInterval, SpatialOperator differentialOperator) : base(program.ResLogger, program.CurrentSessionInfo, consVars, residualInterval) { CoordinateMapping domainMapping = new CoordinateMapping(consVars); UnsetteledCoordinateMapping codomainMapping = new UnsetteledCoordinateMapping( consVars.Select((field) => field.Basis).ToArray()); evaluator = differentialOperator.GetEvaluatorEx( domainMapping, paramMap, codomainMapping); }
/// <summary> /// <see cref="ResidualLogger"/> /// </summary> /// <param name="program"></param> /// <param name="residualInterval"> /// <see cref="ResidualLogger"/> /// </param> /// <param name="differentialOperator"> /// The spatial differential operator defining (the spatial part of) /// the system of equations that are solved. /// </param> public RigorousResidualLogger(Program <T> program, int residualInterval, SpatialOperator differentialOperator) : base(program.ResLogger, program.CurrentSessionInfo, program.WorkingSet, residualInterval) { DGField[] primalFields = program.WorkingSet.ConservativeVariables; CoordinateMapping domainMapping = new CoordinateMapping(primalFields); UnsetteledCoordinateMapping codomainMapping = new UnsetteledCoordinateMapping( primalFields.Select((field) => field.Basis).ToArray()); evaluator = differentialOperator.GetEvaluatorEx( domainMapping, program.ParameterMapping, codomainMapping); }
void PerformRKstep(double dt, int jCell, BitArray AcceptedMask, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi, IEvaluatorNonLin Evaluator) { int N = this.LevelSetBasis.GetLength(jCell); int i0G = this.LevelSetMapping.GlobalUniqueCoordinateIndex(0, jCell, 0); int i0L = this.LevelSetMapping.LocalUniqueCoordinateIndex(0, jCell, 0); double[][] k = new double[RKsch.Stages][]; for (int i = 0; i < RKsch.Stages; i++) { k[i] = new double[N]; } double[] y0 = Phi.Coordinates.GetRow(jCell); Debug.Assert(y0.Length == N); ComputeChangeRate(k[0], jCell, AcceptedMask, Phi, gradPhi, Evaluator); for (int s = 1; s < RKsch.Stages; s++) { Phi.Coordinates.SetRow(jCell, y0); for (int r = 0; r < s; r++) { if (RKsch.a[s, r] != 0.0) { Phi.Coordinates.AccRow(jCell, -dt * RKsch.a[s, r], k[r]); } } ComputeChangeRate(k[s], jCell, AcceptedMask, Phi, gradPhi, Evaluator); } // next timestep for (int s = 0; s < RKsch.Stages; s++) { if (RKsch.b[s] != 0.0) { y0.AccV(-RKsch.b[s] * dt, k[s]); } } Phi.Coordinates.SetRow(jCell, y0); }
void ComputeChangeRate(double[] k, int jCell, BitArray AcceptedMask, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi, IEvaluatorNonLin Evaluator) { int N = this.LevelSetBasis.GetLength(jCell); int i0L = this.LevelSetMapping.LocalUniqueCoordinateIndex(0, jCell, 0); Debug.Assert(k.Length == N); if (temp == null) { temp = new double[this.LevelSetMapping.LocalLength]; } gm.GradientUpdate(jCell, AcceptedMask, Phi, gradPhi); for (int n = 0; n < N; n++) { temp[n + i0L] = 0; } #if DEBUG double[] oldtemp = temp.CloneAs(); #endif Evaluator.time = 0.0; Evaluator.MPITtransceive = false; Evaluator.Evaluate <double[]>(1.0, 1.0, temp); #if DEBUG for (int i = 0; i < oldtemp.Length; i++) { if (i < i0L && i >= (i0L + N)) { Debug.Assert(oldtemp[i] == temp[i]); // check that the locality of the operator is implemented correctly } } #endif for (int n = 0; n < N; n++) { k[n] = temp[n + i0L]; } }