public void UpdateModelAndAnalyze(IVectorView youngModuli)
        {
            for (int e = 0; e < NumElements; ++e)
            {
                penalizers[e].ScaleFactor = youngModuli[e];
            }

            // This is necessary in order to rebuild the stiffness matrix. However it also resets each element's state, which is
            // wasteful here.
            //TODO: If I mess with analyzer operations, I should implement a new analyzer instead of using StaticAnalyzer.
            //TODO: I could avoid this, if the analyzer decided when the matrix will be rebuilt, instead of the problem provider.
            problem.Reset();

            if (isFirstAnalysis)
            {
                staticAnalyzer.Initialize(true);
                isFirstAnalysis = false;
            }
            else
            {
                staticAnalyzer.Initialize(false);
            }
            staticAnalyzer.Solve();
            globalDisplacements = solver.LinearSystems[0].Solution;
        }
Exemplo n.º 2
0
        private static void SolveLinearStatic(Model model)
        {
            // Choose linear equation system solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            // Structural problem provider
            var provider = new ProblemStructural(model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            // Logging displacement, strain, and stress fields.
            string outputDirectory = workingDirectory + "\\Plots";

            childAnalyzer.LogFactories[0] = new VtkLogFactory(model, outputDirectory)
            {
                LogDisplacements         = true,
                LogStrains               = true,
                LogStresses              = true,
                VonMisesStressCalculator = new PlaneStressVonMises()
            };

            // Run the analysis
            parentAnalyzer.BuildMatrices();
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
Exemplo n.º 3
0
            //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);
            }
Exemplo n.º 4
0
        private static void SolveBuildingInNoSoilSmall()
        {
            VectorExtensions.AssignTotalAffinityCount();
            Model model = new Model();

            model.SubdomainsDictionary.Add(1, new Subdomain()
            {
                ID = 1
            });
            BeamBuildingBuilder.MakeBeamBuilding(model, 20, 20, 20, 5, 4, model.NodesDictionary.Count + 1,
                                                 model.ElementsDictionary.Count + 1, 1, 4, false, false);
            model.Loads.Add(new Load()
            {
                Amount = -100, Node = model.Nodes[21], DOF = DOFType.X
            });
            model.ConnectDataStructures();

            SolverSkyline     solver         = new SolverSkyline(model);
            ProblemStructural provider       = new ProblemStructural(model, solver.SubdomainsDictionary);
            LinearAnalyzer    analyzer       = new LinearAnalyzer(solver, solver.SubdomainsDictionary);
            StaticAnalyzer    parentAnalyzer = new StaticAnalyzer(provider, analyzer, solver.SubdomainsDictionary);

            analyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 420 });

            parentAnalyzer.BuildMatrices();
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
Exemplo n.º 5
0
        public static void SuiteSparseMemoryConsumptionDebugging()
        {
            for (int rep = 0; rep < 10; ++rep)
            {
                var benchmarkBuilder = new CantileverBeam.Builder();
                //benchmarkBuilder.Length = 5.0;
                CantileverBeam benchmark = benchmarkBuilder.BuildWithQuad4Elements(2000, 100);

                // Solver
                var solverBuilder = new SuiteSparseSolver.Builder();
                using (SuiteSparseSolver solver = solverBuilder.BuildSolver(benchmark.Model))
                {
                    // Structural problem provider
                    var provider = new ProblemStructural(benchmark.Model, solver);

                    // Linear static analysis
                    var childAnalyzer  = new LinearAnalyzer(benchmark.Model, solver, provider);
                    var parentAnalyzer = new StaticAnalyzer(benchmark.Model, solver, provider, childAnalyzer);

                    // Run the analysis
                    parentAnalyzer.Initialize();
                    parentAnalyzer.Solve();
                }
            }
        }
Exemplo n.º 6
0
        public static void TestSolver()
        {
            // Setup the model and solver
            Model model = Quads4x4MappingMatricesTests.CreateModel();
            Dictionary <int, HashSet <INode> > cornerNodes = Quads4x4MappingMatricesTests.DefineCornerNodes(model);
            var fetiMatrices        = new DenseFetiDPSubdomainMatrixManager.Factory();
            var cornerNodeSelection = new UsedDefinedCornerNodes(cornerNodes);
            var solver         = new FetiDPSolver.Builder(cornerNodeSelection, fetiMatrices).BuildSolver(model);
            var problem        = new ProblemStructural(model, solver);
            var linearAnalyzer = new LinearAnalyzer(model, solver, problem);
            var staticAnalyzer = new StaticAnalyzer(model, solver, problem, linearAnalyzer);

            // Run the analysis
            staticAnalyzer.Initialize();
            staticAnalyzer.Solve();

            // Gather the global displacements
            var sudomainDisplacements = new Dictionary <int, IVectorView>();

            foreach (var ls in solver.LinearSystems)
            {
                sudomainDisplacements[ls.Key] = ls.Value.Solution;
            }
            Vector globalU = solver.GatherGlobalDisplacements(sudomainDisplacements);

            // Check against expected solution
            double tol = 1E-7;

            Assert.True(SolutionGlobalDisplacements.Equals(globalU, tol));
        }
Exemplo n.º 7
0
        public void TestEulerBeam2DLinearBendingExample()
        {
            // Model and node creation
            var model = new Model();

            model.NodesDictionary.Add(1, new Node {
                ID = 1, X = 0.0, Y = 0.0, Z = 0.0
            });
            model.NodesDictionary.Add(2, new Node {
                ID = 2, X = 100.0, Y = 0.0, Z = 0.0
            });
            model.NodesDictionary.Add(3, new Node {
                ID = 3, X = 200.0, Y = 0.0, Z = 0.0
            });
            // Constrain bottom node and add nodal load value
            model.NodesDictionary[1].Constraints.AddRange(new[] { DOFType.X, DOFType.Y, DOFType.Z, DOFType.RotZ });
            model.Loads.Add(new Load()
            {
                Amount = 2000, Node = model.NodesDictionary[3], DOF = DOFType.Y
            });

            // Generate elements of the structure
            for (int iElem = 0; iElem < 2; iElem++)
            {
                // Create new Beam2D section and element
                var element = new EulerBeam2D(2.1e4)
                {
                    ID = iElem + 1, Density = 7.85, SectionArea = 91.04, MomentOfInertia = 8091.00
                };
                element.ElementType = element;
                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iElem + 1]);
                element.AddNode(model.NodesDictionary[iElem + 2]);
                // Add Hexa element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
            }
            // Needed in order to make all the required data structures
            model.ConnectDataStructures();

            // Setup
            var linearSystem   = new SkylineLinearSystem(model.Forces);
            var solver         = new SolverSkyline(linearSystem);
            var provider       = new ProblemStructural(model);
            var childAnalyzer  = new LinearAnalyzer(solver);
            var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem);

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

            // Tests if calculated solution meets expected
            var expectedSolution = new double[] { 0, 9.80905689841542, 0.17656302417147754, 0, 31.388982074929341, 0.23541736556197002 };

            for (int i = 0; i < expectedSolution.Length; i++)
            {
                Assert.Equal(expectedSolution[i], linearSystem.Solution[i], 12);
            }
        }
        public void SolveNLBeam()
        {
            var m = new Model();

            m.NodesDictionary.Add(1, new Node(id: 1, x: 0, y:  0, z: 0));
            m.NodesDictionary.Add(2, new Node(id: 2, x: 5, y:  0, z: 0));
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationZ
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });
            m.ElementsDictionary.Add(1, new Element()
            {
                ID          = 1,
                ElementType = new Beam3DCorotationalQuaternion(m.Nodes, new ElasticMaterial3D()
                {
                    YoungModulus = 2.1e6, PoissonRatio = 0.2
                }, 1,
                                                               new BeamSection3D(0.06, 0.0002, 0.00045, 0.000818, 0.05, 0.05))
            });
            m.ElementsDictionary[1].AddNodes(m.Nodes);
            m.SubdomainsDictionary.Add(1, new Subdomain(1));
            m.SubdomainsDictionary[1].Elements.Add(m.ElementsDictionary[1]);
            m.Loads.Add(new Load()
            {
                Node = m.NodesDictionary[2], Amount = 100, DOF = StructuralDof.TranslationY
            });

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

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

            // Analyzers
            int increments           = 10;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(m, solver, provider, increments);
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(m, solver, provider, childAnalyzer);

            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
Exemplo n.º 9
0
        public void TestSolveHexaCantileverBeam()
        {
            var model = new Model();

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

            HexaSimpleCantileverBeam.MakeCantileverBeam(model, 0, 0, 0, model.NodesDictionary.Count + 1, model.ElementsDictionary.Count + 1, 1);

            model.Loads.Add(new Load()
            {
                Amount = -0.25, Node = model.Nodes[16], DOF = StructuralDof.TranslationZ
            });
            model.Loads.Add(new Load()
            {
                Amount = -0.25, Node = model.Nodes[17], DOF = StructuralDof.TranslationZ
            });
            model.Loads.Add(new Load()
            {
                Amount = -0.25, Node = model.Nodes[18], DOF = StructuralDof.TranslationZ
            });
            model.Loads.Add(new Load()
            {
                Amount = -0.25, Node = model.Nodes[19], DOF = StructuralDof.TranslationZ
            });

            var     solverBuilder  = new SkylineSolver.Builder();
            ISolver solver         = solverBuilder.BuildSolver(model);
            var     provider       = new ProblemStructural(model, solver);
            var     childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var     parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            //childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 47 });

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

            double[] expectedDisplacements = new double[]
            {
                -0.0000025899520106, -0.0000004898560318, -0.0000031099520106, -0.0000025899520106, 0.0000004898560318,
                -0.0000031099520106, 0.0000025899520106, 0.0000004898560318, -0.0000031099520106, 0.0000025899520106,
                -0.0000004898560318, -0.0000031099520106, -0.0000045673419128, -0.0000002423136749, -0.0000107872459340,
                -0.0000045673419128, 0.0000002423136749, -0.0000107872459340, 0.0000045673419128, 0.0000002423136749,
                -0.0000107872459340, 0.0000045673419128, -0.0000002423136749, -0.0000107872459340, -0.0000057299058132,
                -0.0000001253780263, -0.0000216044936601, -0.0000057299058132, 0.0000001253780263, -0.0000216044936601,
                0.0000057299058132, 0.0000001253780263, -0.0000216044936601, 0.0000057299058132, -0.0000001253780263,
                -0.0000216044936601, -0.0000061325564473, -0.0000000425738760, -0.0000339869559207, -0.0000061325564473,
                0.0000000425738760, -0.0000339869559207, 0.0000061325564473, 0.0000000425738760, -0.0000339869559207,
                0.0000061325564473, -0.0000000425738760, -0.0000339869559207
            };

            for (int i = 0; i < expectedDisplacements.Length; i++)
            {
                Assert.Equal(expectedDisplacements[i], solver.LinearSystems[1].Solution[i], 10);
            }
        }
        public static void EmbeddedEBEinMatrix_NewtonRaphson()
        {
            // Model creation
            var model = new Model();

            // Subdomains
            //model.SubdomainsDictionary.Add(subdomainID, new Subdomain() { ID = 1 });
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Variables
            int      monitorNode = 41;
            IDofType monitorDof  = StructuralDof.TranslationZ;

            // Choose model
            EmbeddedEBEModelBuilder.EmbeddedExampleBuilder(model);

            //-----------------------------------------------------------------------------------------------------------
            // Model

            // Choose linear equation system solver
            //var solverBuilder = new SkylineSolver.Builder();
            //SkylineSolver solver = solverBuilder.BuildSolver(model);
            var solverBuilder        = new SuiteSparseSolver.Builder();
            SuiteSparseSolver solver = solverBuilder.BuildSolver(model);

            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer -> Child: NewtonRaphsonNonLinearAnalyzer
            int increments           = 100;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                ResidualTolerance = 1E-03, MaxIterationsPerIncrement = 10
            };
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Request output
            string outputFile = outputDirectory + "\\CNT-Embedded-3D_Results.txt";
            var    logger     = new TotalLoadsDisplacementsPerIncrementLog(model.SubdomainsDictionary[subdomainID], increments,
                                                                           model.NodesDictionary[monitorNode], monitorDof, outputFile);

            childAnalyzer.IncrementalLogs.Add(subdomainID, logger);

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

            // Create Paraview File
            var paraview = new ParaviewEmbedded3D(model, solver.LinearSystems[0].Solution, "test");

            paraview.CreateParaviewFile();
        }
Exemplo n.º 11
0
        public static void TestSolver()
        {
            // Setup the model
            double stiffnessRatio = 1E-2; // Do not change this! The expected solution is taken for this value
            Model  model          = CreateModel(stiffnessRatio);
            Dictionary <int, HashSet <INode> > cornerNodes = Quads4x4MappingMatricesTests.DefineCornerNodes(model);

            // Setup solver
            var interfaceSolverBuilder = new FetiDPInterfaceProblemSolver.Builder();

            interfaceSolverBuilder.PcgConvergenceTolerance = 1E-7;
            //var fetiMatrices = new SkylineFetiDPSubdomainMatrixManager.Factory();
            var fetiMatrices        = new DenseFetiDPSubdomainMatrixManager.Factory();
            var cornerNodeSelection = new UsedDefinedCornerNodes(cornerNodes);
            var fetiSolverBuilder   = new FetiDPSolver.Builder(cornerNodeSelection, fetiMatrices);

            fetiSolverBuilder.InterfaceProblemSolver = interfaceSolverBuilder.Build();
            fetiSolverBuilder.ProblemIsHomogeneous   = false;
            fetiSolverBuilder.PreconditionerFactory  = new DirichletPreconditioner.Factory();
            FetiDPSolver fetiSolver = fetiSolverBuilder.BuildSolver(model);

            // Run the analysis
            var problem        = new ProblemStructural(model, fetiSolver);
            var linearAnalyzer = new LinearAnalyzer(model, fetiSolver, problem);
            var staticAnalyzer = new StaticAnalyzer(model, fetiSolver, problem, linearAnalyzer);

            staticAnalyzer.Initialize();
            staticAnalyzer.Solve();

            // Gather the global displacements
            var sudomainDisplacements = new Dictionary <int, IVectorView>();

            foreach (var ls in fetiSolver.LinearSystems)
            {
                sudomainDisplacements[ls.Key] = ls.Value.Solution;
            }
            Vector globalU = fetiSolver.GatherGlobalDisplacements(sudomainDisplacements);

            // Check against expected solution
            double tol             = 1E-7;
            var    globalUExpected = Vector.CreateFromArray(new double[]
            {
                17.623494584618864, 12.564560593215612, 31.832863897135404, 34.496634608059082, 40.255481382985629,
                66.49190654178912, 42.572002358887204, 99.798764204232072, 4.267568672307144, 9.00506902466324,
                9.100928263505315, 31.107370029452451, 12.1615036308774, 66.065492717632239, 11.510673148931499,
                102.06649895017948, -3.0529124682202156, 9.24107474483673, -7.8531777412741217, 26.728892403726846,
                -16.890006178831449, 70.602493468916791, -21.80233265288679, 109.39882637058051, -4.7311061272016808,
                10.030926199331375, -5.6722429958962142, 18.837815470700932, 146.94209278892487, 392.04674590737193,
                -35.619167413693908, 1407.200332011206, -9.9609496807814057, 10.46574373452243, -17.603838651152756,
                20.760800663270086, -843.13592713307355, 371.10700308359418, -1666.2547486301742, 3714.1637893447919
            });

            Assert.True(globalUExpected.Equals(globalU, tol));
        }
Exemplo n.º 12
0
        /// <summary>Evaluates the specified iteration.</summary>
        /// <param name="iteration">The iteration.</param>
        /// <returns></returns>
        public double[] Evaluate(int iteration)
        {
            var solver         = new SkylineSolver.Builder().BuildSolver(currentModel);
            var provider       = new ProblemStructural(currentModel, solver);
            var childAnalyzer  = new LinearAnalyzer(currentModel, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(currentModel, solver, provider, childAnalyzer);

            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
            return(new[] { solver.LinearSystems[0].Solution[56], solver.LinearSystems[0].Solution[58] });
        }
        private static IVectorView SolveModel(Model model)
        {
            SkylineSolver solver   = (new SkylineSolver.Builder()).BuildSolver(model);
            var           provider = new ProblemThermal(model, solver);

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

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

            return(solver.LinearSystems[subdomainID].Solution);
        }
        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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        private static Vector RunAnalysis(Model model)
        {
            // Setup analysis
            var linearSystem   = new SkylineLinearSystem(model.Forces);
            var solver         = new SolverSkyline(linearSystem);
            var provider       = new ProblemStructural(model);
            var childAnalyzer  = new LinearAnalyzer(solver);
            var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem);

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

            return(linearSystem.Solution);
        }
        /// <summary>Evaluates the specified iteration.</summary>
        /// <param name="iteration">The iteration.</param>
        /// <returns></returns>
        public double[] Evaluate(int iteration)
        {
            //TODO: Perhaps the analyzer, solver, etc should be reused throughout the MonteCarlo, to avoid recalculating
            //      connectivity and indexing structures.

            var solver         = new SkylineSolver.Builder().BuildSolver(currentModel);
            var provider       = new ProblemStructural(currentModel, solver);
            var childAnalyzer  = new LinearAnalyzer(currentModel, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(currentModel, solver, provider, childAnalyzer);

            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
            //return new[] { linearSystems[0].RHS[0] };
            return(new[] { solver.LinearSystems[0].Solution[56], solver.LinearSystems[0].Solution[58] });
        }
        public static void EmbeddedEBEinMatrix_DisplacementControl()
        {
            // Model creation
            var model = new Model();

            // Subdomains
            //model.SubdomainsDictionary.Add(subdomainID, new Subdomain() { ID = 1 });
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Variables
            int      monitorNode = 161;
            IDofType monitorDof  = StructuralDof.TranslationZ;

            // Choose model
            EmbeddedEBEModelBuilder.EmbeddedExampleBuilder(model);

            //-----------------------------------------------------------------------------------------------------------
            // Model

            // Choose linear equation system solver
            //var solverBuilder = new SkylineSolver.Builder();
            //SkylineSolver solver = solverBuilder.BuildSolver(model);
            var solverBuilder        = new SuiteSparseSolver.Builder();
            SuiteSparseSolver solver = solverBuilder.BuildSolver(model);

            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer -> Child: DisplacementControl
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) };
            int increments           = 100;
            var childAnalyzerBuilder = new DisplacementControlAnalyzer.Builder(model, solver, provider, increments);
            DisplacementControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Request output
            string outputFile = outputDirectory + "\\CNT-Embedded-3D_Results.txt";
            var    logger     = new TotalLoadsDisplacementsPerIncrementLog(model.SubdomainsDictionary[subdomainID], increments,
                                                                           model.NodesDictionary[monitorNode], monitorDof, outputFile);

            childAnalyzer.IncrementalLogs.Add(subdomainID, logger);

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
        private static void SolveModel()
        {
            var model = new Model();

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

            var load = 850;

            BuildCantileverModel(model, load);

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

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

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

            childAnalyzerBuilder.ResidualTolerance             = 1E-5;
            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);

            // Setup displacements log
            var watchDof = new Dictionary <int, int[]>();

            //watchDof.Add(subdomainID, new int[1] { 46 });
            watchDof.Add(subdomainID, new int[1] {
                94
            });
            var log1 = new IncrementalDisplacementsLog(watchDof);

            childAnalyzer.IncrementalDisplacementsLog = log1;

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

            // Write log data to file
            WriteDisplacementsToFile(log1, watchDof, load);
        }
        private static IncrementalDisplacementsLog SolveModel()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model 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 IncrementalDisplacementsLog(watchDofs);

            childAnalyzer.IncrementalDisplacementsLog = log1;

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



            return(log1);
        }
        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);
        }
Exemplo n.º 22
0
            private void Solve(double[] x, out Model model, out LinearAnalyzer childAnalyzer,
                               out Rod2DResults rodResults)
            {
                model = BuildModel(x);


                SkylineSolver solver   = new SkylineSolver.Builder().BuildSolver(model);
                var           provider = new ProblemStructural(model, solver);

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

                CreateLogs(model, childAnalyzer);
                rodResults = new Rod2DResults(model.SubdomainsDictionary[subdomainID], solver.LinearSystems[subdomainID]); // Let's hope this is the one!

                parentAnalyzer.Initialize();
                parentAnalyzer.Solve();
            }
        private static IVectorView SolveModelWithoutSubdomains(int numElementsX, int numElementsY)
        {
            Model model = CreateSingleSubdomainModel(numElementsX, numElementsY);

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

            // Linear static analysis
            var provider       = new ProblemStructural(model, solver);
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            return(solver.LinearSystems[singleSubdomainID].Solution);
        }
Exemplo n.º 24
0
        public (IVectorView globalU, IMatrixView globalK) SolveModel()
        {
            // Solver
            SkylineSolver solver = new SkylineSolver.Builder().BuildSolver(Model);

            solver.PreventFromOverwrittingSystemMatrices(); // Necessary to extract the stiffness matrix.

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

            // Analyzers
            var childAnalyzer  = new LinearAnalyzer(Model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(Model, solver, provider, childAnalyzer);

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

            return(solver.LinearSystems[0].Solution, solver.LinearSystems[0].Matrix);
        }
Exemplo n.º 25
0
        private void TestCollocationPointCreation()
        {
            var                model        = new CollocationModel();
            ModelCreator       modelCreator = new ModelCreator(model);
            string             filename     = "..\\..\\..\\InputFiles\\PlateWithHole.txt";
            IsogeometricReader modelReader  = new IsogeometricReader(modelCreator, filename);

            modelReader.CreateCollocationModelFromFile();

            //var solverBuilder = new SuiteSparseSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(
            //    new NodeMajorDofOrderingStrategy(), new NullReordering());
            var     solverBuilder = new GmresSolver.Builder();
            ISolver solver        = new GmresSolver(model,
                                                    new AsymmetricDofOrderer(new RowDofOrderingStrategy()),
                                                    new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()));

            // Structural problem provider
            var provider = new ProblemStructural(model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.BuildMatrices();

            var k = solver.LinearSystems[0].Matrix;

            Matrix <double> kmatlab = MathNet.Numerics.LinearAlgebra.CreateMatrix.Dense <double>(k.NumRows, k.NumColumns);

            for (int i = 0; i < k.NumRows; i++)
            {
                for (int j = 0; j < k.NumColumns; j++)
                {
                    kmatlab[i, j] = k[i, j];
                }
            }
            MatlabWriter.Write("..\\..\\..\\InputFiles\\KcolMsolve.mat", kmatlab, "Ktotal");
        }
        private static void Analyze(Model model, bool loadControl)
        {
            // Choose linear equation system solver
            var           solverBuilder = new SkylineSolver.Builder();
            SkylineSolver solver        = solverBuilder.BuildSolver(model);


            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer
            NonLinearAnalyzerBase childAnalyzer;
            int increments = 10;

            if (loadControl)
            {
                var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);
                childAnalyzerBuilder.ResidualTolerance = 1E-3;
                childAnalyzer = childAnalyzerBuilder.Build();
            }
            else
            {
                var childAnalyzerBuilder = new DisplacementControlAnalyzer.Builder(model, solver, provider, increments);
                childAnalyzer = childAnalyzerBuilder.Build();
            }


            // Choose parent analyzer -> Parent: Static
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Request output
            string outputFile = outputDirectory + "\\load_control_beam2D_corrotational.txt";
            var    logger     = new TotalLoadsDisplacementsPerIncrementLog(model.SubdomainsDictionary[subdomainID], increments,
                                                                           model.NodesDictionary[monitorNode], monitorDof, outputFile);

            childAnalyzer.IncrementalLogs.Add(subdomainID, logger);

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
        private static void RunAnalysisAndCheck(CantileverBeam benchmark, ISolver solver)
        {
            // Structural problem provider
            var provider = new ProblemStructural(benchmark.Model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(benchmark.Model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(benchmark.Model, solver, provider, childAnalyzer);

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

            // Check output
            double endDeflectionExpected = benchmark.CalculateEndDeflectionWithEulerBeamTheory();
            double endDeflectionComputed =
                benchmark.CalculateAverageEndDeflectionFromSolution(solver.LinearSystems.First().Value.Solution);
            var comparer = new ValueComparer(1E-2);

            Assert.True(comparer.AreEqual(endDeflectionExpected, endDeflectionComputed));
        }
Exemplo n.º 28
0
        public void EmbeddedElementTechniqueExample()
        {
            var model = new Model();

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

            // Choose model
            EmbeddedExamplesBuilder.ExampleWithEmbedded(model);

            // Choose linear equation system solver
            SkylineSolver solver = (new SkylineSolver.Builder()).BuildSolver(model);

            // Choose the provider of the problem -> here a structural problem
            var provider = new ProblemStructural(model, solver);

            // Choose child analyzer -> Child: NewtonRaphsonNonLinearAnalyzer
            int increments                    = 10;
            var loadControlBuilder            = new LoadControlAnalyzer.Builder(model, solver, provider, increments);
            LoadControlAnalyzer childAnalyzer = loadControlBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Request output
            childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 11 });
            //childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] {
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.X],
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.Y],
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.Z]});

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

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[1][0];   //There is a list of logs for each subdomain and we want the first one (index = 0) from subdomain id = 1
            var     computedValue = log.DOFValues[11];

            Assert.Equal(11.584726466617692, computedValue, 3);
        }
        private static (IVectorView U, SolverLogger logger) SolveModelWithSubdomains(int numElementsX, int numElementsY,
                                                                                     double factorizationTolerance)
        {
            Model multiSubdomainModel = CreateModel(numElementsX, numElementsY);

            // Solver
            var factorizationTolerances = new Dictionary <int, double>();

            foreach (Subdomain s in multiSubdomainModel.Subdomains)
            {
                factorizationTolerances[s.ID] = factorizationTolerance;
            }
            //var fetiMatrices = new DenseFeti1SubdomainMatrixManager.Factory();
            //var fetiMatrices = new SkylineFeti1SubdomainMatrixManager.Factory();
            var fetiMatrices  = new SkylineFeti1SubdomainMatrixManager.Factory(new OrderingAmdCSparseNet());
            var solverBuilder = new Feti1Solver.Builder(fetiMatrices, factorizationTolerances);

            //solverBuilder.PreconditionerFactory = new LumpedPreconditioner.Factory();
            solverBuilder.PreconditionerFactory = new DirichletPreconditioner.Factory();
            solverBuilder.ProblemIsHomogeneous  = true;
            Feti1Solver fetiSolver = solverBuilder.BuildSolver(multiSubdomainModel);

            // Linear static analysis
            var provider       = new ProblemStructural(multiSubdomainModel, fetiSolver);
            var childAnalyzer  = new LinearAnalyzer(multiSubdomainModel, fetiSolver, provider);
            var parentAnalyzer = new StaticAnalyzer(multiSubdomainModel, fetiSolver, provider, childAnalyzer);

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

            // Gather the global displacements
            var sudomainDisplacements = new Dictionary <int, IVectorView>();

            foreach (var ls in fetiSolver.LinearSystems)
            {
                sudomainDisplacements[ls.Key] = ls.Value.Solution;
            }
            return(fetiSolver.GatherGlobalDisplacements(sudomainDisplacements), fetiSolver.Logger);
        }
Exemplo n.º 30
0
        private static void SolveBuildingInNoSoilSmall()
        {
            var model = new Model();

            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));
            BeamBuildingBuilder.MakeBeamBuilding(model, 20, 20, 20, 5, 4, model.NodesDictionary.Count + 1,
                                                 model.ElementsDictionary.Count + 1, subdomainID, 4, false, false);
            model.Loads.Add(new Load()
            {
                Amount = -100, Node = model.Nodes[21], DOF = StructuralDof.TranslationX
            });

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

            // Structural problem provider
            var provider = new ProblemStructural(model, solver);

            // Linear static analysis
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Request output
            int monitorDof = 420;

            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof });

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

            // Write output
            DOFSLog log = (DOFSLog)childAnalyzer.Logs[subdomainID][0]; //There is a list of logs for each subdomain and we want the first one

            Console.WriteLine($"dof = {monitorDof}, u = {log.DOFValues[monitorDof]}");
        }