public static void TestNonLinearSolverConfigurations() { //Arrange --- set configs var ACS = new AppControlSolver(); NonLinearSolverConfig nlconfig = ACS.NonLinearSolver; LinearSolverConfig lconfig = ACS.LinearSolver; lconfig.verbose = true; lconfig.NoOfMultigridLevels = 3; lconfig.TargetBlockSize = 10; nlconfig.verbose = true; var SF = new SolverFactory(nlconfig, lconfig); //Arrange --- get test multigrid operator stuff AggregationGridData[] seq; var MGO = Utils.CreateTestMGOperator(out seq, Resolution: 10); var map = MGO.Mapping; var changeofbasisis = Utils.GetAllMGConfig(MGO); var agggridbasisis = Utils.GetAllAggGridBasis(MGO); //Arrange --- get nonlinear codes available var nonlincodes = (NonLinearSolverCode[])Enum.GetValues(typeof(NonLinearSolverCode)); NonlinearSolver NLsolver = null; //Arrange --- get test linear Solver to set in NLsolver ISolverSmootherTemplate LinSolver = null; LinearSolverCode[] LinTestcandidates = { LinearSolverCode.classic_pardiso, LinearSolverCode.exp_gmres_levelpmg }; // in order to test the GMRES variants of the NL solver //Act and Assert foreach (var lincode in LinTestcandidates) { lconfig.SolverCode = lincode; TestDelegate nldlg = () => SF.GenerateNonLin(out NLsolver, out LinSolver, null, agggridbasisis, changeofbasisis, seq); SF.Clear(); foreach (NonLinearSolverCode nlcode in nonlincodes) { nlconfig.SolverCode = nlcode; if (nlconfig.SolverCode == NonLinearSolverCode.selfmade) { SF.Selfmade_nonlinsolver = new Newton(null, agggridbasisis, changeofbasisis); } Assert.DoesNotThrow(nldlg, "", null); Assert.IsNotNull(NLsolver); } Console.WriteLine("===="); } }
/// <summary> /// Returns either a solver for the Navier-Stokes or the Stokes system. /// E.g. for testing purposes, one might also use a nonlinear solver on a Stokes system. /// </summary> protected virtual string GetSolver(out NonlinearSolver nonlinSolver, out ISolverSmootherTemplate linearSolver) { nonlinSolver = null; linearSolver = null; if (Config_SpatialOperatorType != SpatialOperatorType.Nonlinear) { m_nonlinconfig.SolverCode = BoSSS.Solution.Control.NonLinearSolverCode.Picard; } XdgSolverFactory.GenerateNonLin(out nonlinSolver, out linearSolver, this.AssembleMatrixCallback, this.MultigridBasis, Config_MultigridOperator, MultigridSequence); string ls_strg = String.Format("{0}", m_linearconfig.SolverCode); string nls_strg = String.Format("{0}", m_nonlinconfig.SolverCode); if ((this.Config_LevelSetHandling == LevelSetHandling.Coupled_Iterative) && (nonlinSolver.Equals(typeof(FixpointIterator)))) { ((FixpointIterator)nonlinSolver).CoupledIteration_Converged = LevelSetConvergenceReached; } // set callback for diagnostic output // ---------------------------------- if (nonlinSolver != null) { nonlinSolver.IterationCallback += this.LogResis; if (linearSolver != null && linearSolver is ISolverWithCallback) { //((ISolverWithCallback)linearSolver).IterationCallback = this.MiniLogResi; } } else { if (linearSolver != null && linearSolver is ISolverWithCallback) { ((ISolverWithCallback)linearSolver).IterationCallback = this.LogResis; } } return(String.Format("nonlinear Solver: {0}, linear Solver: {1}", nls_strg, ls_strg)); }