Exemplo n.º 1
0
        private static Model CreateModel(int numElementsX, int numElementsY)
        {
            // Create mesh
            var meshGenerator = new UniformMeshGenerator2D(0, 0, length, height, numElementsX, numElementsY);

            (Node[] nodes, Element[] elements) = meshGenerator.CreateMesh();

            // Create model and add the nodes
            var model = new Model();

            foreach (Node node in nodes)
            {
                model.NodesDictionary.Add(node.ID, node);
            }

            // Find nodes on the left side and constrain their displacement
            var leftNodes = model.FindNodesWithX(0);

            foreach (Node node in leftNodes)
            {
                node.Constraints.AddRange(new[] { DOFType.X, DOFType.Y });
            }

            // Find nodes on the right side and apply load
            var    rightNodes  = model.FindNodesWithX(length);
            double loadPerNode = totalLoad / rightNodes.Count;

            foreach (Node node in rightNodes)
            {
                model.Loads.Add(new Load()
                {
                    Amount = loadPerNode, Node = node, DOF = DOFType.Y
                });
            }

            // Create Quad4 elements and their material
            var material = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio
            };

            foreach (Element element in elements)
            {
                element.ElementType = new Quad4(material)
                {
                    Thickness = thickness
                };
                model.ElementsDictionary.Add(element.ID, element);
            }

            // Finalize model creation
            model.ConnectDataStructures();
            return(model);
        }
Exemplo n.º 2
0
        private static Model CreateModel(int numElementsX, int numElementsY)
        {
            // Create mesh
            var meshGenerator = new UniformMeshGenerator2D(0, 0, length, height, numElementsX, numElementsY);

            (Node[] nodes, Element[] elements) = meshGenerator.CreateMesh();

            // Create model and add the nodes
            var model = new Model();

            foreach (Node node in nodes)
            {
                model.NodesDictionary.Add(node.ID, node);
            }

            // Create Quad4 elements and their material
            var material = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio
            };

            foreach (Element element in elements)
            {
                element.ElementType = new Quad4(material)
                {
                    Thickness = thickness
                };
                model.ElementsDictionary.Add(element.ID, element);
            }

            // Boundary conditions:
            // *******************************************************************************************
            // *******************************************************************************************
            // Excercise: Write your own boundary conditions for simply supported beam
            // *******************************************************************************************
            // *******************************************************************************************
            ApplyCantileverBoundaryConditions(model);



            // Finalize model creation
            model.ConnectDataStructures();
            return(model);
        }
        private static void AddHostElements(Model model)
        {
            // Material
            double density = 1.0;
            double c       = 1.0;
            double h       = 0;

            // Generate mesh
            var meshGenerator = new UniformMeshGenerator2D <Node>(minX, minY, maxX, maxY, numElementsX, numElementsY);

            (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) =
                meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

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

            // Add the elements to the model
            var elementFactory = new ThermalElement2DFactory(1.0, new ThermalMaterial(density, c, conductivityMatrix, h));

            for (int e = 0; e < cells.Count; ++e)
            {
                ThermalElement2D element = elementFactory.CreateElement(cells[e].CellType, cells[e].Vertices);
                var elementWrapper       = new Element()
                {
                    ID = e + hostElementsIDStart, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(elementWrapper.ID, elementWrapper);
                model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
            }
        }
        private static (IReadOnlyList <Node> nodes, IReadOnlyList <CellConnectivity <Node> > elements) GenerateUniformMesh()
        {
            var meshGen = new UniformMeshGenerator2D <Node>(0.0, 0.0, length, height, 4, 20);

            return(meshGen.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z)));
        }
Exemplo n.º 5
0
            public CantileverBeam BuildWithQuad4Elements(int numElementsAlongLength, int numElementsAlongHeight)
            {
                // Material and section properties
                double thickness = Width;
                var    material  = new ElasticMaterial2D(StressState2D.PlaneStress)
                {
                    YoungModulus = this.YoungModulus,
                    PoissonRatio = this.PoissonRatio
                };
                var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0);

                // Model with 1 subdomain
                var model = new Model();

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

                // Generate mesh
                var meshGenerator = new UniformMeshGenerator2D <Node>(0.0, 0.0, Length, Height,
                                                                      numElementsAlongLength, numElementsAlongHeight);

                (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) =
                    meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

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

                // Add Quad4 elements to the model
                var factory = new ContinuumElement2DFactory(thickness, material, dynamicProperties);

                for (int e = 0; e < cells.Count; ++e)
                {
                    ContinuumElement2D element = factory.CreateElement(cells[e].CellType, cells[e].Vertices);
                    var elementWrapper         = new Element()
                    {
                        ID = e, ElementType = element
                    };
                    foreach (Node node in element.Nodes)
                    {
                        elementWrapper.AddNode(node);
                    }
                    model.ElementsDictionary.Add(e, elementWrapper);
                    model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
                }

                // Clamp boundary condition at one end
                double tol = 1E-10; //TODO: this should be chosen w.r.t. the element size along X

                foreach (var node in model.Nodes.Where(node => Math.Abs(node.X) <= tol))
                {
                    node.Constraints.Add(new Constraint()
                    {
                        DOF = StructuralDof.TranslationX, Amount = 0.0
                    });
                    node.Constraints.Add(new Constraint()
                    {
                        DOF = StructuralDof.TranslationY, Amount = 0.0
                    });
                }

                // Apply concentrated load at the other end
                Node[] loadedNodes = model.Nodes.Where(node => Math.Abs(node.X - Length) <= tol).ToArray();
                foreach (var node in loadedNodes)
                {
                    model.Loads.Add(new Load()
                    {
                        Amount = EndPointLoad / loadedNodes.Length, Node = node, DOF = StructuralDof.TranslationY
                    });
                }

                return(new CantileverBeam(Length, Height, Width, EndPointLoad, YoungModulus, model, loadedNodes));
            }
        public static void WriteStiffnessOfContinuum2DStructure()
        {
            //   ____ ____
            //  |    |    |
            //  |____|____|
            //  |    |    |
            //  |____|____|

            // Model with 1 subdomain
            var model = new Model();

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

            // Material
            double thickness = 1.0;
            var    material  = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = 2.1E7,
                PoissonRatio = 0.3
            };
            var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true);

            // Generate mesh
            double domainLength  = 2.0;
            double domainHeight  = 2.4;
            var    meshGenerator = new UniformMeshGenerator2D <Node>(0.0, 0.0, domainLength, domainHeight, 10, 10);

            (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) =
                meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

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

            // Add Quad4 elements to the model
            var factory = new ContinuumElement2DFactory(thickness, material, dynamicProperties);

            for (int e = 0; e < cells.Count; ++e)
            {
                ContinuumElement2D element = factory.CreateElement(cells[e].CellType, cells[e].Vertices);
                var elementWrapper         = new Element()
                {
                    ID = e, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(e, elementWrapper);
                model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
            }

            // Solver
            var           solverBuilder = new SkylineSolver.Builder();
            SkylineSolver 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 to build the stiffness matrix
            parentAnalyzer.Initialize();
            parentAnalyzer.BuildMatrices();

            // Print the stiffness matrix
            //var writer = new MatlabWriter();
            var writer = new RawArraysWriter();

            writer.WriteToMultipleFiles((SkylineMatrix)solver.LinearSystems[subdomainID].Matrix,
                                        outputDirectory + @"\quad4_20x20_stiffness.txt");
        }
Exemplo n.º 7
0
        public void CreateModel(int numElementsX, int numElementsY, double jIntegralRadiusRatio)
        {
            var model = new XModel();

            model.Subdomains[subdomainID] = new XSubdomain(subdomainID);
            this.Model = model;

            // Mesh generation
            var meshGenerator = new UniformMeshGenerator2D <XNode>(0.0, 0.0, beamLength, beamHeight, numElementsX, numElementsY);

            (IReadOnlyList <XNode> nodes, IReadOnlyList <CellConnectivity <XNode> > elementConnectivities) =
                meshGenerator.CreateMesh((id, x, y, z) => new XNode(id, x, y, z));

            // Nodes
            foreach (XNode node in nodes)
            {
                model.Nodes.Add(node);
            }

            // Elements
            var factory = new XContinuumElement2DFactory(integration, jIntegration, material);
            var cells   = new XContinuumElement2D[elementConnectivities.Count];

            for (int e = 0; e < elementConnectivities.Count; ++e)
            {
                XContinuumElement2D element = factory.CreateElement(e, CellType.Quad4, elementConnectivities[e].Vertices);
                cells[e] = element;
                model.Elements.Add(element);
                model.Subdomains[subdomainID].Elements.Add(model.Elements[e]);
            }

            // Mesh
            var mesh = new BidirectionalMesh2D <XNode, XContinuumElement2D>(model.Nodes,
                                                                            model.Elements.Select(e => (XContinuumElement2D)e).ToArray(), beamBoundary);

            // Boundary conditions
            double tol         = 1E-6;
            double L           = DoubleCantileverBeam.beamLength;
            double H           = DoubleCantileverBeam.beamHeight;
            XNode  topRight    = model.Nodes.Where(n => Math.Abs(n.X - L) <= tol && Math.Abs(n.Y - H) <= tol).First();
            XNode  bottomRight = model.Nodes.Where(n => Math.Abs(n.X - L) <= tol && Math.Abs(n.Y) <= tol).First();

            topRight.Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = +0.05
            });
            bottomRight.Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = -0.05
            });
            foreach (XNode node in model.Nodes.Where(n => Math.Abs(n.X) <= tol))
            {
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationX, Amount = 0.0
                });
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationY, Amount = 0.0
                });
            }

            // Create crack
            double elementSizeX = beamLength / numElementsX;
            double elementSizeY = beamHeight / numElementsY;

            CreateCrack(Math.Max(elementSizeX, elementSizeY), model, mesh, jIntegralRadiusRatio);
        }
Exemplo n.º 8
0
        private static void TestCantileverBeamGeneral()
        {
            // Define the materials
            double thickness = 1.0;
            var    material  = new ElasticMaterial2D(StressState2D.PlaneStress)
            {
                YoungModulus = youngModulus, PoissonRatio = 0.3
            };
            var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true);

            // Model with 1 subdomain
            var model = new Model();

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

            // Generate mesh
            int    numElementsX = 32, numElementsY = 20;
            double lengthX = numElementsX;
            double depthY  = numElementsY;
            var    mesher  = new UniformMeshGenerator2D <Node>(0, 0, lengthX, depthY, numElementsX, numElementsY);

            (IReadOnlyList <Node> nodes, IReadOnlyList <CellConnectivity <Node> > connectivity) =
                mesher.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y:  y, z: z));

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

            // Add Quad4 elements to the model
            var factory = new ContinuumElement2DFactory(thickness, material, dynamicProperties);

            for (int e = 0; e < connectivity.Count; ++e)
            {
                ContinuumElement2D element = factory.CreateElement(connectivity[e].CellType, connectivity[e].Vertices);
                var elementWrapper         = new Element()
                {
                    ID = e, ElementType = element
                };
                foreach (Node node in element.Nodes)
                {
                    elementWrapper.AddNode(node);
                }
                model.ElementsDictionary.Add(e, elementWrapper);
                model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper);
            }

            // Clamp boundary condition at left edge
            double tol = 1E-10; //TODO: this should be chosen w.r.t. the element size along X

            foreach (var node in model.Nodes.Where(node => Math.Abs(node.X) <= tol))
            {
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationX, Amount = 0.0
                });
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationY, Amount = 0.0
                });
            }

            // Apply concentrated load at the bottom right corner
            double load       = 1.0;
            var    cornerNode = model.Nodes.Where(
                node => (Math.Abs(node.X - lengthX) <= tol) && (Math.Abs(node.Y - depthY) <= tol));

            Assert.True(cornerNode.Count() == 1);
            model.Loads.Add(new Load()
            {
                Amount = load, Node = cornerNode.First(), DOF = StructuralDof.TranslationY
            });

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

            // Define the fem analysis and the filter
            double filterAreaRadius = 1.2;
            var    fem    = new LinearFemAnalysis2DGeneral(model, solver);
            var    filter = new ProximityDensityFilter2D(model, filterAreaRadius);

            // Run the test
            TestCantileverBeam(fem, filter);
        }