Beispiel #1
0
        public static void CheckElasticMultiscaleCantilever()
        {
            IReadOnlyList <Dictionary <int, double> > expectedDisplacements = GetExpectedDisplacements();
            TotalDisplacementsPerIterationLog         computedDisplacements = IntegrationElasticCantileverBenchmark.RunExample();

            Assert.True(AreDisplacementsSame(expectedDisplacements, computedDisplacements));
        }
Beispiel #2
0
        private static void RunTest()
        {
            IReadOnlyList <Dictionary <int, double> > expectedDisplacements = GetExpectedDisplacements();
            TotalDisplacementsPerIterationLog         computedDisplacements = SolveModel();

            Assert.True(AreDisplacementsSame(expectedDisplacements, computedDisplacements));
        }
        private static double[] SolveModel()
        {
            var model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            BuildCantileverModel(model, 850);

            // Solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);



            // initialize the anlaysis
            parentAnalyzer.Initialize();

            // Output
            int[] monitoredNodes = new int[] { 6, 8 };
            int[] monitoredDofs  = monitoredNodes.Select(x => model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[x], StructuralDof.TranslationX]).ToArray();
            var   watchDofs      = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, monitoredDofs);
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

            //run the analysis and give output
            parentAnalyzer.Solve();



            var solutionOfIters5And12 = new double[] { log1.GetTotalDisplacement(5, 0, 3), log1.GetTotalDisplacement(12, 0, 3),
                                                       log1.GetTotalDisplacement(5, 0, 9), log1.GetTotalDisplacement(12, 0, 9) };

            return(solutionOfIters5And12);
        }
Beispiel #4
0
        //checked: apotelesmata C:\Users\turbo-x\Desktop\notes_elegxoi\MSOLVE_output_2\APOTELESMATA_MS_hexa8_cantilever_nea\IntegrationElasticCantileverBenchmark RunExample

        //Origin opou htan checked branch example/ms_development_nl_elements_merge
        //modifications: egine v2
        public static TotalDisplacementsPerIterationLog RunExample()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model model       = new Model();
            int   subdomainID = 1;  model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            HexaCantileverBuilder_copyMS_222(model, 0.00219881744271988174427);

            //model.ConnectDataStructures();

            //var linearSystems = new Dictionary<int, ILinearSystem>(); //I think this should be done automatically
            //linearSystems[subdomainID] = new SkylineLinearSystem(subdomainID, model.Subdomains[0].Forces);

            // Solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };

            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);
            var watchDofs      = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();


            return(log1);
        }
        private static bool AreDisplacementsSame(IReadOnlyList <Dictionary <int, double> > expectedDisplacements,
                                                 TotalDisplacementsPerIterationLog computedDisplacements)
        {
            var comparer = new ValueComparer(1E-13);

            for (int iter = 0; iter < expectedDisplacements.Count; ++iter)
            {
                foreach (int dof in expectedDisplacements[iter].Keys)
                {
                    if (!comparer.AreEqual(expectedDisplacements[iter][dof], computedDisplacements.GetTotalDisplacement(iter, subdomainID, dof)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        private static TotalDisplacementsPerIterationLog SolveModel()
        {
            var model = new Model();

            //model.dofOrderer = (subdomain) => (new SimpleDofOrderer()).OrderDofs(model);
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));
            ShellAndCohesiveRAM_11tlkShellPaktwsh(model);

            // Solver
            var solverBuilder = new SkylineSolver.Builder();
            //var solverBuilder = new Solvers.Dense.DenseMatrixSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(new SimpleDofOrderingStrategy(), new NullReordering());
            var solver = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Output
            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 39
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

            // Run the anlaysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            return(log1);
        }
        private static bool AreDisplacementsSame(IReadOnlyList <Dictionary <int, double> > expectedDisplacements,
                                                 TotalDisplacementsPerIterationLog computedDisplacements)
        {
            var comparer = new ValueComparer(1E-10);             // for node major dof order and skyline solver

            //var comparer = new ValueComparer(1E-3); // for other solvers. It may require adjusting after visual inspection
            for (int iter = 0; iter < expectedDisplacements.Count; ++iter)
            {
                foreach (int dof in expectedDisplacements[iter].Keys)
                {
                    if (!comparer.AreEqual(expectedDisplacements[iter][dof], computedDisplacements.GetTotalDisplacement(iter, subdomainID, dof)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        private static TotalDisplacementsPerIterationLog SolveModel()
        {
            var model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            BuildCantileverModel(model, 850);

            // Solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Output
            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

            // Run the anlaysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            return(log1);
        }
Beispiel #9
0
        private static TotalDisplacementsPerIterationLog SolveModel()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            BuildCantileverModel(model, 850);

            //model.ConnectDataStructures();

            //var linearSystems = new Dictionary<int, ILinearSystem>(); //I think this should be done automatically
            //linearSystems[subdomainID] = new SkylineLinearSystem(subdomainID, model.Subdomains[0].Forces);

            //ProblemStructural provider = new ProblemStructural(model, linearSystems);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };
            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            //var increments = 2;
            //var childAnalyzer = new NewtonRaphsonNonLinearAnalyzer(solver, linearSystemsArray, subdomainUpdaters, subdomainMappers, provider, increments, model.TotalDOFs);

            // Solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };

            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;


            //childAnalyzer.SetMaxIterations = 100;
            //childAnalyzer.SetIterationsForMatrixRebuild = 1;

            //StaticAnalyzer parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystems);

            //parentAnalyzer.BuildMatrices();
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();


            return(log1);
        }
Beispiel #10
0
        public override void Solve()
        {
            InitializeLogs();

            DateTime start = DateTime.Now;

            UpdateInternalVectors();//TODOMaria this divides the externally applied load by the number of increments and scatters it to all subdomains and stores it in the class subdomain dictionary and total external load vector
            for (int increment = 0; increment < numIncrements; increment++)
            {
                double errorNorm = 0;
                ClearIncrementalSolutionVector(); //TODOMaria this sets du to 0
                UpdateRhs(increment);             //TODOMaria this copies the residuals stored in the class dictionary to the subdomains

                double firstError = 0;
                int    iteration  = 0;
                for (iteration = 0; iteration < maxIterationsPerIncrement; iteration++)
                {
                    if (iteration == 0)
                    {
                        var vecs = CalculateInternalRhs(increment, iteration);
                        UpdateResidualForcesAndNorm(increment, vecs);
                    }
                    if (iteration == maxIterationsPerIncrement - 1)
                    {
                        return;
                    }
                    if (Double.IsNaN(errorNorm))
                    {
                        return;
                    }
                    solver.Solve();
                    //double rhsNormIt = solver.LinearSystems.First().Value.RhsVector.Norm2();
                    //double xNormIt = solver.LinearSystems.First().Value.Solution.Norm2();
                    Dictionary <int, IVector> internalRhsVectors = CalculateInternalRhs(increment, iteration);
                    Console.WriteLine($"incre:{increment}, iter:{iteration}, total Solution Norm{uPlusdu[0].Norm2()}");
                    Debug.WriteLine($"incre:{increment}, iter:{iteration}, total Solution Norm{uPlusdu[0].Norm2()}");
                    double residualNormCurrent = UpdateResidualForcesAndNorm(increment, internalRhsVectors); // This also sets the rhs vectors in linear systems.
                    errorNorm = globalRhsNormInitial != 0 ? residualNormCurrent / globalRhsNormInitial : 0;  // (rhsNorm*increment/increments) : 0;//TODOMaria this calculates the internal force vector and subtracts it from the external one (calculates the residual)
                    //Console.WriteLine($"Increment {increment}, iteration {iteration}: norm2(error) = {errorNorm}");

                    if (iteration == 0)
                    {
                        firstError = errorNorm;
                    }

                    if (TotalDisplacementsPerIterationLog != null)
                    {
                        TotalDisplacementsPerIterationLog.StoreDisplacements(uPlusdu);
                    }

                    if (errorNorm < residualTolerance)
                    {
                        previousConvergedUplusdUSolution = uPlusdu[0];
                        foreach (var subdomainLogPair in IncrementalLogs)
                        {
                            int subdomainID = subdomainLogPair.Key;
                            TotalLoadsDisplacementsPerIncrementLog log = subdomainLogPair.Value;
                            log.LogTotalDataForIncrement(increment, iteration, errorNorm,
                                                         uPlusdu[subdomainID], internalRhsVectors[subdomainID]);
                        }
                        break;
                    }
                    SplitResidualForcesToSubdomains();                        //TODOMaria scatter residuals to subdomains
                    if ((iteration + 1) % numIterationsForMatrixRebuild == 0) // Matrix rebuilding should be handled in another way. E.g. in modified NR, it must be done at each increment.
                    {
                        provider.Reset();
                        BuildMatrices();
                    }
                }
                //double rhsNormInc = solver.LinearSystems.First().Value.RhsVector.Norm2();
                //double xNormInc = solver.LinearSystems.First().Value.Solution.Norm2();
                Debug.WriteLine("NR {0}, first error: {1}, exit error: {2}", iteration, firstError, errorNorm);
                SaveMaterialStateAndUpdateSolution();
            }
            //            ClearMaterialStresses();

            // TODO: Logging should be done at each iteration. And it should be done using pull observers
            DateTime end = DateTime.Now;

            StoreLogResults(start, end);
        }
        public override void Solve()
        {
            InitializeLogs();

            DateTime start = DateTime.Now;

            UpdateInternalVectors();
            for (int increment = 0; increment < numIncrements; increment++)
            {
                double errorNorm = 0;
                ClearIncrementalSolutionVector();
                UpdateRhs(increment);
                ScaleSubdomainConstraints(increment);

                double firstError = 0;
                int    iteration  = 0;
                for (iteration = 0; iteration < maxIterationsPerIncrement; iteration++)
                {
                    AddEquivalentNodalLoadsToRHS(increment, iteration);
                    solver.Solve();

                    Dictionary <int, IVector> internalRhsVectors = CalculateInternalRhs(increment, iteration);
                    errorNorm = UpdateResidualForcesAndNorm(increment, internalRhsVectors); // This also sets the rhs vectors in linear systems.
                    //Console.WriteLine($"Increment {increment}, iteration {iteration}: norm2(error) = {errorNorm}");

                    if (iteration == 0)
                    {
                        firstError = errorNorm;
                    }

                    if (TotalDisplacementsPerIterationLog != null)
                    {
                        TotalDisplacementsPerIterationLog.StoreDisplacements(uPlusdu);
                    }

                    if (errorNorm < residualTolerance)
                    {
                        foreach (var subdomainLogPair in IncrementalLogs)
                        {
                            int subdomainID = subdomainLogPair.Key;
                            TotalLoadsDisplacementsPerIncrementLog log = subdomainLogPair.Value;
                            log.LogTotalDataForIncrement(increment, iteration, errorNorm,
                                                         uPlusdu[subdomainID], internalRhsVectors[subdomainID]);
                        }
                        break;
                    }

                    SplitResidualForcesToSubdomains();
                    if ((iteration + 1) % numIterationsForMatrixRebuild == 0)
                    {
                        provider.Reset();
                        BuildMatrices();
                    }
                }
                Debug.WriteLine("NR {0}, first error: {1}, exit error: {2}", iteration, firstError, errorNorm);
                SaveMaterialStateAndUpdateSolution();
            }

            // TODO: Logging should be done at each iteration. And it should be done using pull observers
            DateTime end = DateTime.Now;

            StoreLogResults(start, end);
        }
Beispiel #12
0
        /// <summary>
        /// Solves the nonlinear equations and calculates the displacements vector.
        /// </summary>
        public override void Solve()
        {
            InitializeLogs();

            DateTime start = DateTime.Now;

            UpdateInternalVectors();
            for (int increment = 0; increment < numIncrements; increment++)
            {
                double errorNorm = 0;
                ClearIncrementalSolutionVector();
                UpdateRhs(increment);

                double firstError = 0;
                int    iteration  = 0;
                for (iteration = 0; iteration < maxIterationsPerIncrement; iteration++)
                {
                    if (iteration == maxIterationsPerIncrement - 1)
                    {
                        return;
                    }

                    if (Double.IsNaN(errorNorm))
                    {
                        return;
                    }

                    solver.Solve();
                    Dictionary <int, IVector> internalRhsVectors = CalculateInternalRhs(increment, iteration);
                    double residualNormCurrent = UpdateResidualForcesAndNorm(increment, internalRhsVectors);
                    errorNorm = globalRhsNormInitial != 0 ? residualNormCurrent / globalRhsNormInitial : 0;

                    if (iteration == 0)
                    {
                        firstError = errorNorm;
                    }

                    if (TotalDisplacementsPerIterationLog != null)
                    {
                        TotalDisplacementsPerIterationLog.StoreDisplacements(uPlusdu);
                    }

                    if (errorNorm < residualTolerance)
                    {
                        foreach (var subdomainLogPair in IncrementalLogs)
                        {
                            int subdomainID = subdomainLogPair.Key;
                            TotalLoadsDisplacementsPerIncrementLog log = subdomainLogPair.Value;
                            log.LogTotalDataForIncrement(increment, iteration, errorNorm,
                                                         uPlusdu[subdomainID], internalRhsVectors[subdomainID]);
                        }
                        break;
                    }

                    SplitResidualForcesToSubdomains();
                    if ((iteration + 1) % numIterationsForMatrixRebuild == 0)
                    {
                        provider.Reset();
                        BuildMatrices();
                    }
                }
                Debug.WriteLine("NR {0}, first error: {1}, exit error: {2}", iteration, firstError, errorNorm);
                SaveMaterialStateAndUpdateSolution();
            }
            DateTime end = DateTime.Now;

            StoreLogResults(start, end);
        }