public static void EmbeddedEBEinMatrix_DisplacementControl()
        {
            // Model creation
            var model = new Model();

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

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

            // Choose model
            EmbeddedEBEModelBuilder.EmbeddedExampleBuilder(model);

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

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

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

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

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

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

            childAnalyzer.IncrementalLogs.Add(subdomainID, logger);

            // Run the analysis
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
        private static void 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();
        }
        public void CantileverBeam2DCorotationalDisplacementControlTest()
        {
            double youngModulus      = 21000.0;
            double poissonRatio      = 0.3;
            double nodalDisplacement = 146.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
            Model 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
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });

            // Applied displacement
            model.NodesDictionary[3].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY, Amount = nodalDisplacement
            });

            // 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++;
            }

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

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

            // Choose child analyzer -> Child: DisplacementControlAnalyzer
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) };
            int numIncrements        = 10;
            var childAnalyzerBuilder = new DisplacementControlAnalyzer.Builder(model, solver, provider, numIncrements);
            var 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[] { 3 });

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

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

            Assert.Equal(-72.090605787610343, log.DOFValues[3], 7);
        }
Exemplo n.º 4
0
        public static void CNT_4_4_DisplacementControl()
        {
            double youngModulus      = 16710.0;
            double poissonRatio      = 0.034;
            double nodalDisplacement = 23.73;
            double area             = 5.594673861218848e-003;
            double inertiaY         = 2.490804749753243e-006;
            double inertiaZ         = 2.490804749753243e-006;
            double torsionalInertia = inertiaY / 2.0;
            double effectiveAreaY   = area;
            double effectiveAreaZ   = area;

            string workingDirectory     = @"..\..\..\Resources\Beam3DInputFiles";
            string geometryFileName     = "CNT-4-4-L=25-Geometry.inp";
            string connectivityFileName = "CNT-4-4-L=25-ConnMatr.inp";
            int    increments           = 20;

            int nNodes        = File.ReadLines(workingDirectory + '\\' + geometryFileName).Count();
            int nElems        = File.ReadLines(workingDirectory + '\\' + connectivityFileName).Count();
            int monitorNode_1 = nNodes - 1;
            int monitorNode_2 = nNodes;

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

            var material_2 = new ElasticMaterial3D
            {
                YoungModulus = 100.0 * youngModulus,
                PoissonRatio = poissonRatio,
            };

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

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

            // Node creation
            IList <Node> nodes = new List <Node>();

            using (TextReader reader = File.OpenText(workingDirectory + '\\' + geometryFileName))
            {
                for (int i = 0; i < nNodes; i++)
                {
                    string   text   = reader.ReadLine();
                    string[] bits   = text.Split(',');
                    int      nodeID = int.Parse(bits[0]);
                    double   nodeX  = double.Parse(bits[1]);
                    double   nodeY  = double.Parse(bits[2]);
                    double   nodeZ  = double.Parse(bits[3]);
                    nodes.Add(new Node(id: nodeID, x: nodeX, y:  nodeY, z: nodeZ));
                    model.NodesDictionary.Add(nodeID, nodes[i]);
                }
            }

            // Constraints
            IList <Node> constraintsNodes = new List <Node>();

            constraintsNodes.Add(nodes[1 - 1]);
            constraintsNodes.Add(nodes[2 - 1]);
            constraintsNodes.Add(nodes[617 - 1]);
            constraintsNodes.Add(nodes[618 - 1]);
            constraintsNodes.Add(nodes[1029 - 1]);
            constraintsNodes.Add(nodes[1030 - 1]);
            constraintsNodes.Add(nodes[1441 - 1]);
            constraintsNodes.Add(nodes[1442 - 1]);
            constraintsNodes.Add(nodes[1649 - 1]);

            for (int i = 0; i < 9; i++)
            {
                int iNode = constraintsNodes[i].ID;
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationY
                });
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.RotationX
                });
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.RotationY
                });
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.RotationZ
                });
            }

            // Applied displacement
            model.NodesDictionary[monitorNode_2].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY, Amount = nodalDisplacement
            });

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

            // Generate elements
            using (TextReader reader = File.OpenText(workingDirectory + '\\' + connectivityFileName))
            {
                for (int i = 0; i < (nElems - 16); i++)
                {
                    string   text      = reader.ReadLine();
                    string[] bits      = text.Split(',');
                    int      elementID = int.Parse(bits[0]);
                    int      node1     = int.Parse(bits[1]);
                    int      node2     = int.Parse(bits[2]);
                    // element nodes
                    IList <Node> elementNodes = new List <Node>();
                    elementNodes.Add(model.NodesDictionary[node1]);
                    elementNodes.Add(model.NodesDictionary[node2]);
                    // create element
                    var beam_1  = new Beam3DCorotationalQuaternion(elementNodes, material_1, 7.85, beamSection);
                    var element = new Element {
                        ID = elementID, ElementType = beam_1
                    };
                    // Add nodes to the created element
                    element.AddNode(model.NodesDictionary[node1]);
                    element.AddNode(model.NodesDictionary[node2]);
                    // beam stiffness matrix
                    var a = beam_1.StiffnessMatrix(element);
                    // Add beam element to the element and subdomains dictionary of the model
                    model.ElementsDictionary.Add(element.ID, element);
                    model.SubdomainsDictionary[1].Elements.Add(element);
                }
                for (int i = (nElems - 16); i < nElems; i++)
                {
                    string   text      = reader.ReadLine();
                    string[] bits      = text.Split(',');
                    int      elementID = int.Parse(bits[0]);
                    int      node1     = int.Parse(bits[1]);
                    int      node2     = int.Parse(bits[2]);
                    // element nodes
                    IList <Node> elementNodes = new List <Node>();
                    elementNodes.Add(model.NodesDictionary[node1]);
                    elementNodes.Add(model.NodesDictionary[node2]);
                    // create element
                    var beam_2  = new Beam3DCorotationalQuaternion(elementNodes, material_2, 7.85, beamSection);
                    var element = new Element {
                        ID = elementID, ElementType = beam_2
                    };
                    // Add nodes to the created element
                    element.AddNode(model.NodesDictionary[node1]);
                    element.AddNode(model.NodesDictionary[node2]);
                    // beam stiffness matrix
                    var a = beam_2.StiffnessMatrix(element);
                    // Add beam element to the element and subdomains dictionary of the model
                    model.ElementsDictionary.Add(element.ID, element);
                    model.SubdomainsDictionary[1].Elements.Add(element);
                }
            }

            // 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
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[1]) };
            var childAnalyzerBuilder = new DisplacementControlAnalyzer.Builder(model, solver, provider, increments);
            var childAnalyzer        = childAnalyzerBuilder.Build();

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

            // Request output
            //int monDOF = linearSystems[1].Solution.Length - 5;  //(6 * monitorNode_2 - 4);
            int monDOF = 9841;

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

            // Run the analysis
            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

            Console.WriteLine($"dof = {monDOF}, u = {log.DOFValues[monDOF]}");
            //Assert.Equal(-21.2328445476855, log.DOFValues[monDOF], 8);
        }
        public static void EmbeddedCNTinMatrix_DisplacementControl()
        {
            // No. of increments
            int increments = 10;

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

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

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

            // Choose model
            EmbeddedModelBuilder.EmbeddedExample(model);

            // Boundary Conditions - Left End [End-1]
            for (int iNode = 1; iNode <= 100; iNode++)
            {
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ
                });
            }

            // Boundary Conditions - Bottom End [End-3]
            for (int iNode = 1; iNode <= 10001; iNode += 100)
            {
                for (int j = 0; j < 10; j++)
                {
                    model.NodesDictionary[iNode + j].Constraints.Add(new Constraint {
                        DOF = StructuralDof.TranslationY
                    });
                }
            }

            // Applied Displacements [End-4]
            double nodalDisplacement = -2.0;

            for (int iNode = 10001; iNode <= 10100; iNode++)
            {
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationZ, Amount = nodalDisplacement
                });
            }

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

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

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

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

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

            childAnalyzer.IncrementalLogs.Add(subdomainID, logger);

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