Exemple #1
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");
        }
        public static void Run()
        {
            double youngMod = 10e6;
            //double poisson = 0.3;
            double loadX       = 500;
            double loadY       = 300;
            double sectionArea = 1.5;

            IList <Node> nodes = TrussExample.CreateNodes();

            var model = new Model();

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

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

            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            model.NodesDictionary[2].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            model.NodesDictionary[2].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });


            var element1 = new Element()
            {
                ID          = 1,
                ElementType = new Rod2D(youngMod)
                {
                    Density = 1, SectionArea = sectionArea
                }
            };

            var element2 = new Element()
            {
                ID          = 2,
                ElementType = new Rod2D(youngMod)
                {
                    Density = 1, SectionArea = sectionArea
                }
            };

            element1.AddNode(model.NodesDictionary[1]);
            element1.AddNode(model.NodesDictionary[3]);

            element2.AddNode(model.NodesDictionary[2]);
            element2.AddNode(model.NodesDictionary[3]);

            model.ElementsDictionary.Add(element1.ID, element1);
            model.ElementsDictionary.Add(element2.ID, element2);

            model.SubdomainsDictionary[subdomainID].Elements.Add(element1);
            model.SubdomainsDictionary[subdomainID].Elements.Add(element2);

            model.Loads.Add(new Load()
            {
                Amount = loadX, Node = model.NodesDictionary[3], DOF = StructuralDof.TranslationX
            });
            model.Loads.Add(new Load()
            {
                Amount = loadY, Node = model.NodesDictionary[3], DOF = StructuralDof.TranslationY
            });

            // 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[3], StructuralDof.TranslationX);
            logFactory.WatchDof(model.NodesDictionary[3], StructuralDof.TranslationY);
            childAnalyzer.LogFactories[subdomainID] = logFactory;

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

            // Print output
            var    logger = (TotalDisplacementsLog)(childAnalyzer.Logs[subdomainID][0]); //There is a list of logs for each subdomain and we want the first one
            double ux     = logger.GetDisplacementAt(model.NodesDictionary[3], StructuralDof.TranslationX);
            double uy     = logger.GetDisplacementAt(model.NodesDictionary[3], StructuralDof.TranslationY);

            Console.WriteLine($"Displacements of Node 3: Ux = {ux}, Uy = {uy}");
        }