コード例 #1
0
        private static IVectorView SolveModel(Model model, IModelReader modelReader)
        {
            var builder = new SkylineSolver.Builder();
            //builder.IsMatrixPositiveDefinite = false;
            var          solver   = builder.BuildSolver(model);
            const double timestep = 1;
            const double time     = 100;

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

            childAnalyzerBuilder.ResidualTolerance             = 1E-6;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 50;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

            //var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, timestep, time);
            //parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            //NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();
            var parentAnalyzer = new NewmarkDynamicAnalyzer(UpdateNewmarkModel, model, solver,
                                                            provider, childAnalyzer, timestep, time, .25, .5);


            parentAnalyzer.Initialize();
            for (int i = 0; i < time / timestep; i++)
            {
                //lambdag = .01 * i + 1;
                parentAnalyzer.SolveTimestep(i);
            }

            return(solver.LinearSystems[subdomainID].Solution);
        }
コード例 #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();
        }
コード例 #3
0
        public static void TestPropagation(bool rigidBoundaryConditions)
        {
            string meshPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                              + @"\Resources\fillet_1272dofs.msh";
            //string propagationPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Propagation\crack_growth.txt";
            //string plotPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Plots";
            //string timingPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Timing";

            double growthLength = 5; // mm. Must be sufficiently larger than the element size.
            var    builder      = new FilletBenchmark.Builder(meshPath, growthLength);

            //builder.WritePropagation = writePropagationPath;
            builder.HeavisideEnrichmentTolerance = 0.01;
            builder.RigidBCs = rigidBoundaryConditions;

            //builder.LsmPlotDirectory = plotLSM ? plotPath : null;
            builder.MaxIterations = 13;

            // Usually should be in [1.5, 2.5). The J-integral radius must be large enough to at least include elements around
            // the element that contains the crack tip. However it must not be so large that an element intersected by the
            // J-integral contour is containes the previous crack tip. Thus the J-integral radius must be sufficiently smaller
            // than the crack growth length.
            builder.JintegralRadiusOverElementSize = 2.0;

            // Run the benchmark
            FilletBenchmark benchmark = builder.BuildBenchmark();

            benchmark.InitializeModel();
            //SuiteSparseSolver solver = new SuiteSparseSolver.Builder().BuildSolver(benchmark.Model);
            SkylineSolver solver = new SkylineSolver.Builder().BuildSolver(benchmark.Model);

            benchmark.Analyze(solver);

            CheckPropagationPath(benchmark.Crack.CrackPath, rigidBoundaryConditions);
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        public void ContinuumElement3DNonLinearVonMisesMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

            // Create Model
            var model = new Model();

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

            // Create von Mises Plastic Material
            var solidMaterial = new VonMisesMaterial3D(youngModulus, poissonRatio, yieldStress, plasticModulus);

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DNonLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditionsNLM(model);

            // 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 -> Child: NewtonRaphson - LoadControl
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) };
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                MaxIterationsPerIncrement     = 50,
                NumIterationsForMatrixRebuild = 1,
                ResidualTolerance             = 1E-06,
            };
            var childAnalyzer = childAnalyzerBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

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

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

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 1.93737;

            Assert.Equal(expectedValue, computedValue, 2);
        }
コード例 #6
0
        internal static void TestSkylineSolver()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new SkylineSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering()); // default
            ISolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
コード例 #7
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);
            }
        }
コード例 #8
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] });
        }
コード例 #9
0
        public void ContinuumElement3DElasticMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

            // Create Model
            var model = new Model();

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

            // Create Elastic Material
            var solidMaterial = new ElasticMaterial3D()
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditions(model);

            // 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 -> Linear
            var childAnalyzer = new LinearAnalyzer(model, solver, provider);

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

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

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

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 0.531178; // consistent: 0.531178 // lumped: 0.894201

            Assert.Equal(expectedValue, computedValue, 3);
        }
コード例 #10
0
        internal static void TestSkylineSolverWithAmdReordering()
        {
            CantileverBeam benchmark = BuildCantileverBenchmark();

            var solverBuilder = new SkylineSolver.Builder();

            solverBuilder.DofOrderer = new DofOrderer(
                new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd());
            ISolver solver = solverBuilder.BuildSolver(benchmark.Model);

            RunAnalysisAndCheck(benchmark, solver);
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
0
        /// <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] });
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
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();
            }
コード例 #18
0
ファイル: HolesTests.cs プロジェクト: mgroupntua/MSolve.XFEM
        public static void TestPropagation()
        {
            string meshPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                              + @"\MGroup.XFEM.Tests\Resources\holes_4442dofs.msh";
            //string propagationPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Propagation\crack_growth.txt";
            //string plotPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Plots";
            //string timingPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Timing";

            double growthLength = 1.0;             // mm. Must be sufficiently larger than the element size.
            var    builder      = new HolesBenchmark.Builder(meshPath, growthLength);

            builder.HeavisideEnrichmentTolerance = 0.12;

            // Usually should be in [1.5, 2.5). The J-integral radius must be large enough to at least include elements around
            // the element that contains the crack tip. However it must not be so large that an element intersected by the
            // J-integral contour is containes the previous crack tip. Thus the J-integral radius must be sufficiently smaller
            // than the crack growth length.
            builder.JintegralRadiusOverElementSize = 2.0;

            // If you modify the following two parameters significantly, then you will need to redefine which nodes are expected
            // to be enriched.
            builder.TipEnrichmentRadius = 0.5;
            builder.BC = HolesBenchmark.BoundaryConditions.BottomConstrainXDisplacementY_TopConstrainXDisplacementY;

            builder.MaxIterations = 12;
            //builder.LeftLsmPlotDirectory = plotLSM ? plotPathLeft : null;
            //builder.RightLsmPlotDirectory = plotLSM ? plotPathRight : null;

            // Run the benchmark
            HolesBenchmark benchmark = builder.BuildBenchmark();

            benchmark.InitializeModel();
            //SuiteSparseSolver solver = new SuiteSparseSolver.Builder().BuildSolver(benchmark.Model);
            var solverBuilder = new SkylineSolver.Builder();

            solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd());
            SkylineSolver solver = solverBuilder.BuildSolver(benchmark.Model);

            benchmark.Analyze(solver);

            CheckCrackPropagationPath(benchmark);
        }
コード例 #19
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);
        }
コード例 #20
0
        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();
        }
コード例 #21
0
        private static IVectorView SolveModel(Model model, ComsolMeshReader3 modelReader)
        {
            //var initialTemp = Vector.CreateZero(model.Nodes.Count);
            double[] value0      = new double[model.Nodes.Count];
            int[]    boundaryIDs = new int[] { 0 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        value0[node.ID] = 0;
                    }
                }
            }
            boundaryIDs = new int[] { 5 };
            foreach (int boundaryID in boundaryIDs)
            {
                foreach (IList <Node> nodes in modelReader.quadBoundaries[boundaryID])
                {
                    foreach (Node node in nodes)
                    {
                        value0[node.ID] = 0;
                    }
                }
            }
            Vector initialValue = Vector.CreateFromArray(value0);
            var    builder      = new SkylineSolver.Builder();
            //builder.IsMatrixPositiveDefinite = false;
            var solver   = builder.BuildSolver(model);
            var provider = new ProblemODE(model, solver);

            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new ODEDynamicAnalyzer(model, solver, provider, childAnalyzer, .5, .1, 3, initialValue);

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

            return(solver.LinearSystems[subdomainID].Solution);
        }
コード例 #22
0
        private static void SolveBuildingInNoSoilSmallDynamic()
        {
            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);

            // 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 parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.01, 0.1);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // 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]}");

            //TODO: No loads have been defined so the result is bound to be 0.
        }
コード例 #23
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]}");
        }
コード例 #24
0
        public void LinearElasticBeam2DNewmarkDynamicAnalysisTest()
        {
            double youngModulus = 21000;
            double poissonRatio = 0.3;
            double area         = 91.04;
            double inertiaY     = 2843.0;
            double inertiaZ     = 8091.0;
            double density      = 7.85;
            double nodalLoad    = 1000.0;
            int    totalNodes   = 2;

            var material = new ElasticMaterial()
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x: 0.0, y: 0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 300.0, y: 0.0, z: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);

            // Model creation
            Model model = new Model();

            // Add a single subdomain to the model
            model.SubdomainsDictionary.Add(1, new Subdomain(1));

            // Add nodes to the nodes dictonary of the model
            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(i + 1, nodes[i]);
            }

            // Constrain bottom nodes of the model
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });

            // Create a new Beam2D element
            var beam = new EulerBeam2D(youngModulus)
            {
                Density         = density,
                SectionArea     = area,
                MomentOfInertia = inertiaZ
            };

            var element = new Element()
            {
                ID          = 1,
                ElementType = beam
            };

            // Add nodes to the created element
            element.AddNode(model.NodesDictionary[1]);
            element.AddNode(model.NodesDictionary[2]);

            // Element Stiffness Matrix
            var a = beam.StiffnessMatrix(element);
            var b = beam.MassMatrix(element);

            // Add Hexa element to the element and subdomains dictionary of the model
            model.ElementsDictionary.Add(element.ID, element);
            model.SubdomainsDictionary[1].Elements.Add(element);

            // define loads
            model.Loads.Add(new Load {
                Amount = nodalLoad, Node = model.NodesDictionary[totalNodes], DOF = StructuralDof.TranslationY
            });

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

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

            // Analyzers
            var childAnalyzer         = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

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

            Assert.Equal(2.2840249264795207, solver.LinearSystems[1].Solution[1], 8);
        }
コード例 #25
0
        public void TestEulerBeam2DLinearBendingExample()
        {
            double youngModulus = 21000.0;
            double poissonRatio = 0.3;
            double nodalLoad    = 2000.0;
            int    nElems       = 2;
            int    monitorNode  = 3;

            // Create new material
            var material = new ElasticMaterial()
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x:   0.0, y:  0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 100.0, y:  0.0, z: 0.0);
            Node         node3 = new Node(id: 3, x: 200.0, y:  0.0, z: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);
            nodes.Add(node3);

            // Model creation
            Model model = new Model();

            // Add a single subdomain to the model
            model.SubdomainsDictionary.Add(1, new Subdomain(1));

            // Add nodes to the nodes dictonary of the model
            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(i + 1, nodes[i]);
            }

            // Constrain bottom nodes of the model
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationZ
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });
            // Generate elements of the structure
            int iNode = 1;

            for (int iElem = 0; iElem < nElems; iElem++)
            {
                // Create new Beam2D section and element
                var beam = new EulerBeam2D(youngModulus)
                {
                    Density         = 7.85,
                    SectionArea     = 91.04,
                    MomentOfInertia = 8091.00,
                };

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = beam
                };
                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = beam.StiffnessMatrix(element);

                // Add Hexa element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
                model.SubdomainsDictionary[1].Elements.Add(element);
                iNode++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

            // Solver
            //var solverBuilder = new MSolve.Solvers.Iterative.PcgSolver.Builder(
            //    (new LinearAlgebra.Iterative.ConjugateGradient.PcgAlgorithm.Builder()).Build());
            //var solver = solverBuilder.BuildSolver(model);
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver 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);

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

            double solutionNorm = solver.LinearSystems[1].Solution.Norm2();
            double rhsNorm      = solver.LinearSystems[1].RhsVector.Norm2();

            Assert.Equal(31.388982074929341, solver.LinearSystems[1].Solution[4], 12);
        }
コード例 #26
0
        public void CantileverYBeam3DQuaternionNonlinearTest()
        {
            double youngModulus     = 21000.0;
            double poissonRatio     = 0.3;
            double nodalLoad        = 20000.0;
            double area             = 91.04;
            double inertiaY         = 2843.0;
            double inertiaZ         = 8091.0;
            double torsionalInertia = 76.57;
            double effectiveAreaY   = 91.04;
            double effectiveAreaZ   = 91.04;
            int    nNodes           = 3;
            int    nElems           = 2;
            int    monitorNode      = 3;

            // Create new 3D material
            var material = new ElasticMaterial3D
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x:   0.0, y:  0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 100.0, y:  0.0, z: 0.0);
            Node         node3 = new Node(id: 3, x: 200.0, y:  0.0, z: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);
            nodes.Add(node3);

            // Model creation
            Model model = new Model();

            // Add a single subdomain to the model
            model.SubdomainsDictionary.Add(1, new Subdomain(1));

            // Add nodes to the nodes dictonary of the model
            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(i + 1, nodes[i]);
            }

            // Constrain bottom nodes of the model
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationZ
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });

            // Generate elements of the structure
            int iNode = 1;

            for (int iElem = 0; iElem < nElems; iElem++)
            {
                // element nodes
                IList <Node> elementNodes = new List <Node>();
                elementNodes.Add(model.NodesDictionary[iNode]);
                elementNodes.Add(model.NodesDictionary[iNode + 1]);

                // Create new Beam3D section and element
                var beamSection = new BeamSection3D(area, inertiaY, inertiaZ, torsionalInertia, effectiveAreaY, effectiveAreaZ);
                var beam        = new Beam3DCorotationalQuaternion(elementNodes, material, 7.85, beamSection);

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = beam
                };

                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = beam.StiffnessMatrix(element);
                //var writer = new FullMatrixWriter();
                //writer.WriteToFile(a, output);


                // Add beam element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
                model.SubdomainsDictionary[1].Elements.Add(element);
                iNode++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

            // 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-3;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            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

            Assert.Equal(148.936792350562, log.DOFValues[7], 2);
        }
コード例 #27
0
        private static void CantileverBeam2DCorotationalNonlinearTest()
        {
            double youngModulus = 21000.0;
            double poissonRatio = 0.3;
            double nodalLoad    = 20000.0;
            double area         = 91.04;
            double inertia      = 8091.0;
            int    nNodes       = 3;
            int    nElems       = 2;
            int    monitorNode  = 3;

            // Create new 2D material
            var material = new ElasticMaterial
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x: 0.0, y: 0.0);
            Node         node2 = new Node(id: 2, x: 100.0, y: 0.0);
            Node         node3 = new Node(id: 3, x: 200.0, y: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);
            nodes.Add(node3);

            // Model creation
            var model = new Model();

            // Add a single subdomain to the model
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            // Add nodes to the nodes dictonary of the model
            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(i + 1, nodes[i]);
            }

            // Constrain bottom nodes of the model
            model.NodesDictionary[1].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationX, Amount = 0.0
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = 0.0
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.RotationZ, Amount = 0.0
            });

            // Generate elements of the structure
            int iNode = 1;

            for (int iElem = 0; iElem < nElems; iElem++)
            {
                // element nodes
                IList <Node> elementNodes = new List <Node>();
                elementNodes.Add(model.NodesDictionary[iNode]);
                elementNodes.Add(model.NodesDictionary[iNode + 1]);

                // Create new Beam3D section and element
                var beamSection = new BeamSection2D(area, inertia);

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = new Beam2DCorotational(elementNodes, material, 7.85, beamSection)
                };

                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = element.ElementType.StiffnessMatrix(element);

                // Add beam element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
                model.SubdomainsDictionary[subdomainID].Elements.Add(element);
                iNode++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

            // Choose linear equation system solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver 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                    = 10;
            var childAnalyzerBuilder          = new LoadControlAnalyzer.Builder(model, solver, provider, increments);
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

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

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { 4 });

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

            // Check output
            DOFSLog log = (DOFSLog)childAnalyzer.Logs[subdomainID][0];

            Assert.Equal(146.5587362562, log.DOFValues[4], 3);
        }
        private static void TestBeam3DElasticNonlinearNewmarkDynamicAnalysisExample()
        {
            double youngModulus     = 21000.0;
            double poissonRatio     = 0.3;
            double nodalLoad        = 20000.0;
            double area             = 91.04;
            double inertiaY         = 2843.0;
            double inertiaZ         = 8091.0;
            double torsionalInertia = 76.57;
            double effectiveAreaY   = 91.04;
            double effectiveAreaZ   = 91.04;
            double density          = 7.85;
            int    nNodes           = 3;
            int    nElems           = 2;
            int    monitorNode      = 3;

            // Create new 3D material
            var material = new ElasticMaterial3D
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x: 0.0, y: 0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 300.0, y: 0.0, z: 0.0);
            Node         node3 = new Node(id: 3, x: 600.0, y: 0.0, z: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);
            nodes.Add(node3);

            // Model creation
            Model model = new Model();

            // Add a single subdomain to the model
            int subdomainID = 0;

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

            // Add nodes to the nodes dictonary of the model
            for (int i = 0; i < nodes.Count; ++i)
            {
                model.NodesDictionary.Add(i + 1, nodes[i]);
            }

            // Constrain bottom nodes of the model
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationZ
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });
            // Generate elements of the structure
            int iNode = 1;

            for (int iElem = 0; iElem < nElems; iElem++)
            {
                // element nodes
                IList <Node> elementNodes = new List <Node>();
                elementNodes.Add(model.NodesDictionary[iNode]);
                elementNodes.Add(model.NodesDictionary[iNode + 1]);

                // Create new Beam3D section and element
                var beamSection = new BeamSection3D(area, inertiaY, inertiaZ, torsionalInertia, effectiveAreaY, effectiveAreaZ);
                var beam        = new Beam3DCorotationalQuaternion(elementNodes, material, density, beamSection);

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = beam
                };

                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = beam.StiffnessMatrix(element);
                var b = beam.MassMatrix(element);

                // Add beam element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
                model.SubdomainsDictionary[subdomainID].Elements.Add(element);
                iNode++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

            // 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.MaxIterationsPerIncrement     = 120;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 500;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzerBuilder         = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();             // Not necessary. This is the default
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

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

            Assert.Equal(148.936792350562, solver.LinearSystems[subdomainID].Solution[7], 12);
        }
コード例 #29
0
        private static void TestBatheImplicitAnalysisExample()
        {
            var model       = new Model();
            int subdomainID = 0;

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

            var n = new Node(id: 0, x: double.NaN);
            var e = new Element()
            {
                ID = 0
            };

            e.NodesDictionary.Add(0, n);
            var m = new Mock <IFiniteElement>();

            m.Setup(x => x.StiffnessMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] {
                { 6, -2, }, { -2, 4 }
            }));
            m.Setup(x => x.MassMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] {
                { 2, 0, }, { 0, 1 }
            }));
            m.Setup(x => x.DampingMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] {
                { 0, 0, }, { 0, 0 }
            }));
            //m.Setup(x => x.StiffnessMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 6, -2, 4 }));
            //m.Setup(x => x.MassMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 2, 0, 1 }));
            //m.Setup(x => x.DampingMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 0, 0, 0 }));
            m.Setup(x => x.GetElementDofTypes(e)).Returns(new[] { new[] { StructuralDof.TranslationX, StructuralDof.TranslationY } });
            m.SetupGet(x => x.DofEnumerator).Returns(new GenericDofEnumerator());
            e.ElementType = m.Object;
            model.NodesDictionary.Add(0, n);
            model.ElementsDictionary.Add(0, e);
            model.SubdomainsDictionary[subdomainID].Elements.Add(e);
            model.Loads.Add(new Load()
            {
                Amount = 10, Node = n, DOF = StructuralDof.TranslationY
            });
            var lX = new Mock <IMassAccelerationHistoryLoad>();

            lX.SetupGet(x => x.DOF).Returns(StructuralDof.TranslationX);
            lX.SetupGet(x => x[It.IsAny <int>()]).Returns(0);
            var lY = new Mock <IMassAccelerationHistoryLoad>();

            lY.SetupGet(x => x.DOF).Returns(StructuralDof.TranslationY);
            lY.SetupGet(x => x[0]).Returns(10);
            lY.SetupGet(x => x[It.IsInRange(1, 100, Range.Inclusive)]).Returns(0);
            model.MassAccelerationHistoryLoads.Add(lX.Object);
            model.MassAccelerationHistoryLoads.Add(lY.Object);
            m.Setup(x => x.CalculateAccelerationForces(It.IsAny <Element>(), It.IsAny <IList <MassAccelerationLoad> >()))
            .Returns <Element, IList <MassAccelerationLoad> >((element, loads) =>
            {
                double[] accelerations = { loads[0].Amount, loads[1].Amount };
                var massMatrix         = Matrix.CreateFromArray(new double[, ] {
                    { 2, 0, }, { 0, 1 }
                });
                //var massMatrix = new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 2, 0, 1 });
                return(massMatrix.Multiply(accelerations));
            }
                                                              );

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

            //TODO: These overwrite the corresponding data extracted by the Model. Either set up these or the Model.
            //solver.LinearSystems[subdomainID].SetMatrix(
            //    SkylineMatrix.CreateFromArrays(2, new double[] { 6, 4, -2 }, new int[] { 0, 1, 3 }, true)); // K = [6 -2; -2 4]
            //solver.LinearSystems[subdomainID].RhsVector = Vector.CreateFromArray(new double[] { 0, 10 });

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

            // Analyzers
            var childAnalyzer         = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default
            //parentAnalyzerBuilder.SetNewmarkParameters(0.25, 0.5); // Not necessary. This is the default
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { 0, 1 });

            // Run the analysis
            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(2.2840249264795207, log.DOFValues[0], 8);
            Assert.Equal(2.4351921891904156, log.DOFValues[1], 8);
        }
コード例 #30
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);
        }