//TODO: perhaps this should be done in Initialize(). Nope, Initialize is not called when using PCPG. private (IMatrixView globalStiffness, IVectorView globalForces) BuildGlobalLinearSystem() { // PcgSolver uses CSR matrices which are efficient for calculating f-K*u var pcgBuilder = new PcgAlgorithm.Builder(); pcgBuilder.MaxIterationsProvider = new FixedMaxIterationsProvider(1); // No need to solve though. var solverBuilder = new PcgSolver.Builder(); solverBuilder.DofOrderer = originalDofOrderer; solverBuilder.PcgAlgorithm = pcgBuilder.Build(); PcgSolver solver = solverBuilder.BuildSolver(singleSubdomainModel); // Let MSolve follow the usual analysis routine, to create all necessary data structures. IStaticProvider problemProvider = createProblemProvider(singleSubdomainModel, solver); var linearAnalyzer = new LinearAnalyzer(singleSubdomainModel, solver, problemProvider); var staticAnalyzer = new StaticAnalyzer(singleSubdomainModel, solver, problemProvider, linearAnalyzer); staticAnalyzer.Initialize(); try { staticAnalyzer.Solve(); } catch (IterativeSolverNotConvergedException) { } // Extract the global matrix and rhs ILinearSystem linearSystem = solver.LinearSystems.First().Value; return(linearSystem.Matrix, linearSystem.RhsVector); }
internal static void TestPcgJacobiSolver() { CantileverBeam benchmark = BuildCantileverBenchmark(); //LibrarySettings.LinearAlgebraProviders = LinearAlgebraProviderChoice.MKL; var solverBuilder = new PcgSolver.Builder(); //var pcgBuilder = new PcgAlgorithm.Builder(); //solverBuilder.PcgAlgorithm = pcgBuilder.Build(); // default //solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()); // default PcgSolver solver = solverBuilder.BuildSolver(benchmark.Model); RunAnalysisAndCheck(benchmark, solver); }
internal static void TestPcgJacobiSolverWithAmdReordering() { CantileverBeam benchmark = BuildCantileverBenchmark(); var solverBuilder = new PcgSolver.Builder(); //var pcgBuilder = new PcgAlgorithm.Builder(); //solverBuilder.PcgAlgorithm = pcgBuilder.Build(); solverBuilder.DofOrderer = new DofOrderer( new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd()); PcgSolver solver = solverBuilder.BuildSolver(benchmark.Model); RunAnalysisAndCheck(benchmark, solver); }
private static void TestQuad4LinearCantileverExample() { // Model & subdomains var model = new Model(); int subdomainID = 0; model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); // Materials double youngModulus = 3.76; double poissonRatio = 0.3779; double thickness = 1.0; double nodalLoad = 500.0; var material = new ElasticMaterial2D(StressState2D.PlaneStress) { YoungModulus = youngModulus, PoissonRatio = poissonRatio }; // Nodes var nodes = new Node[] { new Node(id: 1, x: 0.0, y: 0.0, z: 0.0), new Node(id: 2, x: 10.0, y: 0.0, z: 0.0), new Node(id: 3, x: 10.0, y: 10.0, z: 0.0), new Node(id: 4, x: 0.0, y: 10.0, z: 0.0) }; for (int i = 0; i < nodes.Length; ++i) { model.NodesDictionary.Add(i, nodes[i]); } // Elements var factory = new ContinuumElement2DFactory(thickness, material, null); var elementWrapper = new Element() { ID = 0, ElementType = factory.CreateElement(CellType.Quad4, nodes) }; elementWrapper.AddNodes(nodes); model.ElementsDictionary.Add(elementWrapper.ID, elementWrapper); model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper); //var a = quad.StiffnessMatrix(element); // Prescribed displacements model.NodesDictionary[0].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationX, Amount = 0.0 }); model.NodesDictionary[0].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationY, Amount = 0.0 }); model.NodesDictionary[3].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationX, Amount = 0.0 }); model.NodesDictionary[3].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationY, Amount = 0.0 }); // Nodal loads model.Loads.Add(new Load() { Amount = nodalLoad, Node = model.NodesDictionary[1], DOF = StructuralDof.TranslationX }); model.Loads.Add(new Load() { Amount = nodalLoad, Node = model.NodesDictionary[2], DOF = StructuralDof.TranslationX }); // Solver var pcgBuilder = new PcgAlgorithm.Builder(); pcgBuilder.ResidualTolerance = 1E-6; pcgBuilder.MaxIterationsProvider = new PercentageMaxIterationsProvider(0.5); var solverBuilder = new PcgSolver.Builder(); solverBuilder.PcgAlgorithm = pcgBuilder.Build(); PcgSolver solver = solverBuilder.BuildSolver(model); // Problem type var provider = new ProblemStructural(model, solver); // Analyzers var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); //NewmarkDynamicAnalyzer parentAnalyzer = new NewmarkDynamicAnalyzer(provider, childAnalyzer, linearSystems, 0.25, 0.5, 0.28, 3.36); // Request output childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { 0 }); // Run the anlaysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Check output DOFSLog log = (DOFSLog)childAnalyzer.Logs[subdomainID][0]; //There is a list of logs for each subdomain and we want the first one Assert.Equal(253.132375961535, log.DOFValues[0], 8); }
/// <summary> /// Sets up the necessary MSolve objects, checks user input and finally runs the simulation. /// </summary> public void Submit() { // Linear system solver ISolver solver; if (Solver == SolverOptions.DirectSkyline) { var solverBuilder = new SkylineSolver.Builder(); solver = solverBuilder.BuildSolver(model.CoreModel); } else if (Solver == SolverOptions.IterativePcg) { var solverBuilder = new PcgSolver.Builder(); solver = solverBuilder.BuildSolver(model.CoreModel); } else { throw new NotImplementedException(); } // Provider of the problem var provider = new ProblemStructural(model.CoreModel, solver); //TODO: extend this // (Non) linear analyzer IChildAnalyzer childAnalyzer; if (Integrator == IntegratorOptions.Linear) { var linearAnalyzer = new LinearAnalyzer(model.CoreModel, solver, provider); // Field output requests //TODO: this should work for all analyzers if (FieldOutputRequests != null) { linearAnalyzer.LogFactories[0] = FieldOutputRequests.CreateLogFactory(model); } childAnalyzer = linearAnalyzer; } else if (Integrator == IntegratorOptions.LoadControl) { throw new NotImplementedException("The next code doesn't compile since the classes NonLinearSubdomainUpdater" + " and SubdomainGlobalMapping do not exist"); //INonLinearSubdomainUpdater[] subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) }; //ISubdomainGlobalMapping[] subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) }; //int increments = 1; //int maxIterations = 100; //int iterationsForMatrixRebuild = 1; //var nonLinearAnalyzer = new NewtonRaphsonNonLinearAnalyzer(solver, linearSystems.Values.ToArray(), // subdomainUpdaters, subdomainMappers, provider, increments, model.TotalDOFs, maxIterations, // iterationsForMatrixRebuild); //childAnalyzer = nonLinearAnalyzer; } else { throw new NotImplementedException(); } // Parent analyzer IAnalyzer parentAnalyzer; if (Procedure == ProcedureOptions.Static) { parentAnalyzer = new StaticAnalyzer(model.CoreModel, solver, provider, childAnalyzer); } else if (Procedure == ProcedureOptions.DynamicImplicit) { var analyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model.CoreModel, solver, provider, childAnalyzer, model.TimeStep, model.TotalDuration); analyzerBuilder.SetNewmarkParameters(0.6, 1); //TODO: Use the defaults. parentAnalyzer = analyzerBuilder.Build(); } else { throw new NotImplementedException(); } // Run the analysis parentAnalyzer.Initialize(true); parentAnalyzer.Solve(); }