コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        public static void Run()
        {
            double youngModulus = 200.0e06;
            double poissonRatio = 0.3;
            double nodalLoad    = 25.0;

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

            // Node creation
            IList <Node> nodes = CreateNodes();

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

            // Add a single subdomain to the model
            model.SubdomainsDictionary.Add(0, 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.RotationZ
            });

            model.NodesDictionary[2].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY, Amount = -4.16666666666667E-07
            });

            //Create a new Beam2D element
            var beam = new EulerBeam2D(youngModulus)
            {
                SectionArea     = 1,
                MomentOfInertia = .1
            };


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

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

            //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[subdomainID].Elements.Add(element);

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

            // 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);

            // Output requests
            var logFactory = new TotalDisplacementsLog.Factory(model.SubdomainsDictionary[subdomainID]);

            logFactory.WatchDof(model.NodesDictionary[2], StructuralDof.TranslationX);
            logFactory.WatchDof(model.NodesDictionary[2], StructuralDof.RotationZ);
            childAnalyzer.LogFactories[subdomainID] = logFactory;

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

            // Choose dof types X, Y, rotZ to log for node 5
            var logger = (TotalDisplacementsLog)(childAnalyzer.Logs[subdomainID][0]); //There is a list of logs for each subdomain and we want the first one

            double[] results =
            {
                logger.GetDisplacementAt(model.NodesDictionary[2], StructuralDof.TranslationX),
                logger.GetDisplacementAt(model.NodesDictionary[2], StructuralDof.RotationZ)
            };


            double[] expected = new double[] { 0, -4.16666666666667E-07, -6.25E-07 };

            for (int i = 0; i < expected.Length - 1; i++)
            {
                //if (Math.Abs(expected[i] - results[i]) > 1e-14)
                //{
                //    throw new SystemException("Failed beam2D test, results don't coincide for dof no: " + i + ", expected displacement: " + expected[i] + ", calculated displacement: " + results[i]);
                //}
                Console.WriteLine(results[i]);
            }
            Console.WriteLine("ran beam2d2 test");
        }
コード例 #5
0
        public void TestEulerBeam2DLinearBendingExample()
        {
            /// <summary>
            /// Define mechanical properties
            /// </summary>
            double youngModulus = 21000.0;
            double poissonRatio = 0.3;
            double nodalLoad    = 2000.0;
            int    nElems       = 2;
            int    monitorNode  = 3;

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

            /// <summary>
            /// Node creation. Define geometry.
            /// </summary>
            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);

            /// <summary>
            /// Model creation.
            /// </summary>
            Model model = new Model();

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

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

            /// <summary>
            /// Constrain bottom nodes of the model. Define Boundary Conditions.
            /// </summary>
            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
            });

            /// <summary>
            /// Generate elements of the structure.
            /// </summary>
            int iNode = 1;

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

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

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

                var a = beam.StiffnessMatrix(element);

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

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

            /// <summary>
            /// Defines Skyline Solver.
            /// </summary>
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(model);

            /// <summary>
            /// Defines Problem type as Structural.
            /// </summary>
            var provider = new ProblemStructural(model, solver);

            /// <summary>
            /// Defines Analyzers.
            /// Chlid Analyzer: Linear
            /// Parent Analyzer: Static
            /// </summary>
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            /// <summary>
            /// Run the anlaysis.
            /// </summary>
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();

            /// <summary>
            /// Solution and right-hand-side norms.
            /// </summary>
            double solutionNorm = solver.LinearSystems[1].Solution.Norm2();
            double rhsNorm      = solver.LinearSystems[1].RhsVector.Norm2();

            /// <summary>
            /// Check solution.
            /// </summary>
            Assert.Equal(31.388982074929341, solver.LinearSystems[1].Solution[4], 12);
        }
コード例 #6
0
        public void SolveCantileverBeam2D()
        {
            double youngModulus = 2.0e08;
            double poissonRatio = 0.3;
            double nodalLoad    = 10.0;

            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: 5.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)
            {
                SectionArea     = 1,
                MomentOfInertia = .1
            };

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

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

            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);

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

            // Solvers, providers, analyzers
            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);

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

            Assert.Equal(-2.08333333333333333e-5, solver.LinearSystems[1].Solution[1], 10);
        }
        private static Model CreateModel(double youngModulus, double area, double nodalLoad)
        {
            //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         node0 = new Node(id: 0, x: 0.0, y: 0.0, z: 0.0);
            Node         node1 = new Node(id: 1, x: 300.0, y: 0.0, z: 0.0);

            nodes.Add(node0);
            nodes.Add(node1);

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

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

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

            // Constrain bottom nodes of the model
            model.NodesDictionary[0].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[0].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[0].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          = 0,
                ElementType = beam
            };

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

            // 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[0].Elements.Add(element);

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

            return(model);
        }