/// <summary> /// Creates new <see cref="ABevolve"/> objects when a reclustering is performed /// </summary> protected virtual void CreateNewABevolver() { ABevolver = new ABevolve[CurrentClustering.NumberOfClusters]; for (int i = 0; i < ABevolver.Length; i++) { ABevolver[i] = new ABevolve(Operator, Mapping, ParameterMapping, order, adaptive: true, sgrd: CurrentClustering.Clusters[i]); ABevolver[i].ResetTime(m_Time, TimeInfo.TimeStepNumber); ABevolver[i].OnBeforeComputeChangeRate += (t1, t2) => this.RaiseOnBeforeComputechangeRate(t1, t2); } }
/// <summary> /// Resets the time for all individual time stepper within the LTS algorithm, /// i.e all ABevolve helper and Runge-Kutta time stepper. /// It is needed after a restart, such that all time stepper restart from the /// same common simulation time. /// </summary> /// <param name="NewTime">Time to be set</param> public override void ResetTime(double NewTime, int timestepNumber) { base.ResetTime(NewTime, timestepNumber); RungeKuttaScheme.ResetTime(NewTime, timestepNumber); foreach (var ABevolve in ABevolver) { ABevolve.ResetTime(NewTime, timestepNumber); } RungeKuttaScheme.ResetTime(NewTime, timestepNumber); }
//################# Hack for saving to database in every (A)LTS sub-step /// <summary> /// Standard constructor for the (adaptive) local time stepping algorithm /// </summary> /// <param name="spatialOp">Spatial operator</param> /// <param name="Fieldsmap">Coordinate mapping for the variable fields</param> /// <param name="Parameters">optional parameter fields, can be null if <paramref name="spatialOp"/> contains no parameters; must match the parameter field list of <paramref name="spatialOp"/>, see <see cref="BoSSS.Foundation.SpatialOperator.ParameterVar"/></param> /// <param name="order">LTS/AB order</param> /// <param name="numOfClusters">Amount of sub-grids/clusters to be used for LTS</param> /// <param name="timeStepConstraints">Time step constraints for later usage as metric</param> /// <param name="subGrid">Sub-grids, e.g., from previous time steps</param> /// <param name="fluxCorrection">Bool for triggering the fluss correction</param> /// <param name="reclusteringInterval">Interval for potential reclustering</param> /// <param name="saveToDBCallback">Hack for plotting all sub-steps</param> /// <remarks>Uses the k-Mean clustering, see <see cref="BoSSS.Solution.Utils.Kmeans"/>, to generate the element groups</remarks> public AdamsBashforthLTS(SpatialOperator spatialOp, CoordinateMapping Fieldsmap, CoordinateMapping Parameters, int order, int numOfClusters, IList <TimeStepConstraint> timeStepConstraints = null, SubGrid subGrid = null, bool fluxCorrection = true, int reclusteringInterval = 0, Action <TimestepNumber, double> saveToDBCallback = null, int initialTimestepNumber = 1) : base(spatialOp, Fieldsmap, Parameters, order, timeStepConstraints, subGrid) { if (reclusteringInterval != 0) { numberOfClustersInitial = numOfClusters; this.timestepNumber = initialTimestepNumber; this.adaptive = true; } // Add OnBeforeComputeChangeRate (AV) to start-up phase time stepper RungeKuttaScheme.OnBeforeComputeChangeRate += (t1, t2) => this.RaiseOnBeforeComputechangeRate(t1, t2); this.reclusteringInterval = reclusteringInterval; this.gridData = Fieldsmap.Fields.First().GridDat; this.fluxCorrection = fluxCorrection; NumberOfLocalTimeSteps = new List <int>(numOfClusters); clusterer = new Clusterer(this.gridData, this.TimeStepConstraints); CurrentClustering = clusterer.CreateClustering(numOfClusters, this.SubGrid); // Might remove clusters when their centres are too close CurrentClustering = CalculateNumberOfLocalTS(CurrentClustering); // Might remove clusters when time step sizes are too similar ABevolver = new ABevolve[CurrentClustering.NumberOfClusters]; for (int i = 0; i < ABevolver.Length; i++) { ABevolver[i] = new ABevolve(spatialOp, Fieldsmap, Parameters, order, adaptive: this.adaptive, sgrd: CurrentClustering.Clusters[i]); ABevolver[i].OnBeforeComputeChangeRate += (t1, t2) => this.RaiseOnBeforeComputechangeRate(t1, t2); } GetBoundaryTopology(); #if DEBUG for (int i = 0; i < CurrentClustering.NumberOfClusters; i++) { Console.WriteLine("AB LTS Ctor: id=" + i + " -> sub-steps=" + NumberOfLocalTimeSteps[i] + " and elements=" + CurrentClustering.Clusters[i].GlobalNoOfCells); } #endif // Saving time steps in subgrids //this.saveToDBCallback = saveToDBCallback; }
////################# Hack for saving to database in every (A)LTS sub-step //private Action<TimestepNumber, double> saveToDBCallback; ////################# Hack for saving to database in every (A)LTS sub-step /// <summary> /// Standard constructor for the (adaptive) local time stepping algorithm /// </summary> /// <param name="spatialOp">Spatial operator</param> /// <param name="Fieldsmap">Coordinate mapping for the variable fields</param> /// <param name="Parameters">optional parameter fields, can be null if <paramref name="spatialOp"/> contains no parameters; must match the parameter field list of <paramref name="spatialOp"/>, see <see cref="BoSSS.Foundation.SpatialOperator.ParameterVar"/></param> /// <param name="order">LTS/AB order</param> /// <param name="numOfClusters">Amount of sub-grids/clusters to be used for LTS</param> /// <param name="timeStepConstraints">Time step constraints for later usage as metric</param> /// <param name="subGrid">Sub-grids, e.g., from previous time steps</param> /// <param name="fluxCorrection">Bool for triggering the fluss correction</param> /// <param name="reclusteringInterval">Interval for potential reclustering</param> /// <param name="saveToDBCallback">Hack for plotting all sub-steps</param> /// <remarks>Uses the k-Mean clustering, see <see cref="BoSSS.Solution.Utils.Kmeans"/>, to generate the element groups</remarks> public AdamsBashforthLTS(SpatialOperator spatialOp, CoordinateMapping Fieldsmap, CoordinateMapping Parameters, int order, int numOfClusters, IList <TimeStepConstraint> timeStepConstraints = null, SubGrid subGrid = null, bool fluxCorrection = true, int reclusteringInterval = 0, Action <TimestepNumber, double> saveToDBCallback = null, int maxNumOfSubSteps = 0, bool forceReclustering = false, bool logging = false, bool consoleOutput = false) : base(spatialOp, Fieldsmap, Parameters, order, timeStepConstraints, subGrid) { this.forceReclustering = forceReclustering; this.Logging = logging; this.ConsoleOutput = consoleOutput; if (reclusteringInterval != 0) { NumberOfClustersInitial = numOfClusters; this.adaptive = true; } // Add OnBeforeComputeChangeRate (AV) to start-up phase time stepper RungeKuttaScheme.OnBeforeComputeChangeRate += (t1, t2) => this.RaiseOnBeforeComputechangeRate(t1, t2); this.reclusteringInterval = reclusteringInterval; this.gridData = Fieldsmap.Fields.First().GridDat; this.fluxCorrection = fluxCorrection; if (ConsoleOutput) { Console.WriteLine("### This is ABLTS ctor ###"); } clusterer = new Clusterer(this.gridData, maxNumOfSubSteps); CurrentClustering = clusterer.CreateClustering(numOfClusters, this.TimeStepConstraints, this.SubGrid); // Might remove clusters when their centres are too close CurrentClustering = clusterer.TuneClustering(CurrentClustering, Time, this.TimeStepConstraints); // Might remove clusters when their time step sizes are too similar ABevolver = new ABevolve[CurrentClustering.NumberOfClusters]; for (int i = 0; i < ABevolver.Length; i++) { ABevolver[i] = new ABevolve(spatialOp, Fieldsmap, Parameters, order, adaptive: this.adaptive, sgrd: CurrentClustering.Clusters[i]); ABevolver[i].OnBeforeComputeChangeRate += (t1, t2) => this.RaiseOnBeforeComputechangeRate(t1, t2); } GetBoundaryTopology(); // Saving time steps in subgrids //this.saveToDBCallback = saveToDBCallback; }