コード例 #1
0
        public static void Generate3DMesh()
        {
            double minX = 0.0, minY = 0.0, minZ = 0.0;
            double maxX = 100.0, maxY = 100.0, maxZ = 100.0;
            int    cellsPerX = 4, cellsPerY = 4, cellsPerZ = 4;

            var generator = new UniformMeshGenerator3D <Node>(minX, minY, minZ, maxX, maxY, maxZ, cellsPerX, cellsPerY, cellsPerZ);

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

            Console.WriteLine($"{vertices.Count} vertices:");
            foreach (var vertex in vertices)
            {
                Console.WriteLine($"{vertex.ID} {vertex.X} {vertex.Y} {vertex.Z}");
            }

            Console.WriteLine();
            Console.WriteLine($"{cells.Count} cells:");
            int    cellID       = 1;
            string gmshHexa8Tag = "5 2 1 1";

            foreach (var cell in cells)
            {
                Console.Write($"{cellID++} {gmshHexa8Tag} ");
                foreach (var vertex in cell.Vertices)
                {
                    Console.Write($"{vertex.ID} ");
                }
                Console.WriteLine();
            }
        }
コード例 #2
0
        public static void WriteStiffnessOfContinuum3DStructure()
        {
            //    _____ ____
            //   /    /    /|
            //  /____/____/ |
            //  |    |    | |
            //  |____|____|/|
            //  |    |    | /
            //  |____|____|/
            //

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

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

            // Material
            var material = new ElasticMaterial3D()
            {
                YoungModulus = 2.1E7,
                PoissonRatio = 0.3
            };
            var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true);

            // Generate mesh
            double lengthX       = 2.0;
            double lengthY       = 2.4;
            double lengthZ       = 2.2;
            var    meshGenerator = new UniformMeshGenerator3D <Node>(0.0, 0.0, 0.0, lengthX, lengthY, lengthZ, 10, 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 ContinuumElement3DFactory(material, dynamicProperties);

            for (int e = 0; e < cells.Count; ++e)
            {
                ContinuumElement3D 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 + @"\hexa8_10x10x10_stiffness.txt");
        }