Example #1
0
        public void ContinuumElement3DNonLinearVonMisesMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

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

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

            // Create von Mises Plastic Material
            var solidMaterial = new VonMisesMaterial3D(youngModulus, poissonRatio, yieldStress, plasticModulus);

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DNonLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditionsNLM(model);

            // 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 -> Child: NewtonRaphson - LoadControl
            var subdomainUpdaters    = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) };
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                MaxIterationsPerIncrement     = 50,
                NumIterationsForMatrixRebuild = 1,
                ResidualTolerance             = 1E-06,
            };
            var childAnalyzer = childAnalyzerBuilder.Build();

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof });

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

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 1.93737;

            Assert.Equal(expectedValue, computedValue, 2);
        }
Example #2
0
        public void ContinuumElement3DElasticMaterialDynamicConsistent()
        {
            IList <Node> nodes = new List <Node>();

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

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

            // Create Elastic Material
            var solidMaterial = new ElasticMaterial3D()
            {
                YoungModulus = youngModulus,
                PoissonRatio = poissonRatio,
            };

            // Create Dynamic Material
            var dynamicMaterial = new DynamicMaterial(density, 0, 0, true);

            DefineContinuumElement3DLinear(model, solidMaterial, dynamicMaterial);

            BoundaryConditions(model);

            // 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 -> Linear
            var childAnalyzer = new LinearAnalyzer(model, solver, provider);

            // Choose parent analyzer -> Parent: Static
            var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 1.0, 100.0);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

            // Request output
            childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof });

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

            // Check output
            DOFSLog log           = (DOFSLog)childAnalyzer.Logs[subdomainID][0];
            double  computedValue = log.DOFValues[monitorDof];
            double  expectedValue = 0.531178; // consistent: 0.531178 // lumped: 0.894201

            Assert.Equal(expectedValue, computedValue, 3);
        }
        private static IVectorView SolveModel(Model model)
        {
            SkylineSolver solver   = (new SkylineSolver.Builder()).BuildSolver(model);
            var           provider = new ProblemThermal(model, solver);

            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            return(solver.LinearSystems[subdomainID].Solution);
        }
        private static IVectorView SolveModel(Model model)
        {
            double[]      temp0       = new double[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            Vector        initialTemp = Vector.CreateFromArray(temp0);
            SkylineSolver solver      = (new SkylineSolver.Builder()).BuildSolver(model);
            var           provider    = new ProblemConvectionDiffusion(model, solver);

            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new ConvectionDiffusionExplicitDynamicAnalyzer(model, solver, provider, childAnalyzer, 0.5, .5, initialTemp);

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

            return(solver.LinearSystems[subdomainID].Solution);
        }
        private static IVectorView SolveModelWithoutSubdomains(int numElementsX, int numElementsY)
        {
            Model model = CreateSingleSubdomainModel(numElementsX, numElementsY);

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

            // Linear static analysis
            var provider       = new ProblemStructural(model, solver);
            var childAnalyzer  = new LinearAnalyzer(model, solver, provider);
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            return(solver.LinearSystems[singleSubdomainID].Solution);
        }
Example #6
0
        public static void TestPropagation()
        {
            string meshPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName
                              + @"\MGroup.XFEM.Tests\Resources\holes_4442dofs.msh";
            //string propagationPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Propagation\crack_growth.txt";
            //string plotPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Plots";
            //string timingPath = @"C:\Users\Serafeim\Desktop\GRACM\Benchmark_Fillet\Timing";

            double growthLength = 1.0;             // mm. Must be sufficiently larger than the element size.
            var    builder      = new HolesBenchmark.Builder(meshPath, growthLength);

            builder.HeavisideEnrichmentTolerance = 0.12;

            // Usually should be in [1.5, 2.5). The J-integral radius must be large enough to at least include elements around
            // the element that contains the crack tip. However it must not be so large that an element intersected by the
            // J-integral contour is containes the previous crack tip. Thus the J-integral radius must be sufficiently smaller
            // than the crack growth length.
            builder.JintegralRadiusOverElementSize = 2.0;

            // If you modify the following two parameters significantly, then you will need to redefine which nodes are expected
            // to be enriched.
            builder.TipEnrichmentRadius = 0.5;
            builder.BC = HolesBenchmark.BoundaryConditions.BottomConstrainXDisplacementY_TopConstrainXDisplacementY;

            builder.MaxIterations = 12;
            //builder.LeftLsmPlotDirectory = plotLSM ? plotPathLeft : null;
            //builder.RightLsmPlotDirectory = plotLSM ? plotPathRight : null;

            // Run the benchmark
            HolesBenchmark benchmark = builder.BuildBenchmark();

            benchmark.InitializeModel();
            //SuiteSparseSolver solver = new SuiteSparseSolver.Builder().BuildSolver(benchmark.Model);
            var solverBuilder = new SkylineSolver.Builder();

            solverBuilder.DofOrderer = new DofOrderer(new NodeMajorDofOrderingStrategy(), AmdReordering.CreateWithCSparseAmd());
            SkylineSolver solver = solverBuilder.BuildSolver(benchmark.Model);

            benchmark.Analyze(solver);

            CheckCrackPropagationPath(benchmark);
        }
        private static IVectorView[] SolveModels(Model[] models)
        {
            SkylineSolver[] solvers = new SkylineSolver[models.Length];
            IImplicitIntegrationProvider[] providers = new IImplicitIntegrationProvider[models.Length];
            IChildAnalyzer[] childAnalyzers          = new IChildAnalyzer[models.Length];
            for (int i = 0; i < models.Length; i++)
            {
                //var builder = new DenseMatrixSolver.Builder();
                solvers[i]        = builder.BuildSolver(models[i]);
                providers[i]      = new ProblemStructural(models[i], solvers[i]);
                childAnalyzers[i] = new LinearAnalyzer(models[i], solvers[i], providers[i]);
            }

            var parentAnalyzer = new NewmarkDynamicAnalyzerMultiModel(UpdateModels, models, solvers, providers, childAnalyzers, 0.28, 3.36, .25, .5);

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

            return(solvers.Select(x => x.LinearSystems[subdomainID].Solution).ToArray());
        }
        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();
        }
Example #9
0
        public void EmbeddedElementTechniqueExample()
        {
            var model = new Model();

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

            // Choose model
            EmbeddedExamplesBuilder.ExampleWithEmbedded(model);

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

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

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

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

            // Request output
            childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 11 });
            //childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] {
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.X],
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.Y],
            //    model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[5], DOFType.Z]});

            // Run
            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 (index = 0) from subdomain id = 1
            var     computedValue = log.DOFValues[11];

            Assert.Equal(11.584726466617692, computedValue, 3);
        }
        public static void ThermalEmbeddedElementExample()
        {
            Model model = new Model();

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

            // Choose model
            ThermalExampleWithEmbedded(model);

            SkylineSolver solver   = (new SkylineSolver.Builder()).BuildSolver(model);
            var           provider = new ProblemThermal(model, solver);
            var           rve      = new ThermalSquareRve(model, Vector2.Create(minX, minY), Vector2.Create(maxX, maxY), thickness,
                                                          temperatureGradient);
            var homogenization = new HomogenizationAnalyzer(model, solver, provider, rve);

            homogenization.Initialize();
            homogenization.Solve();

            IMatrix conductivity = homogenization.EffectiveConstitutiveTensors[subdomainID];

            Debug.WriteLine($"C = [ {conductivity[0, 0]} {conductivity[0, 1]}; {conductivity[1, 0]} {conductivity[1, 1]}");
        }
        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");
        }
Example #12
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);
        }
        private static IVectorView[] SolveModelsWithNewmark(Model[] models, IModelReader[] modelReaders)
        {
            Vector[] initialValues = new Vector[models.Length];
            var      value0        = new Dictionary <int, double[]>();

            for (int i = 0; i < models.Length; i++)
            {
                double[] v0 = new double[models[i].Nodes.Count];
                value0.Add(i, v0);
            }
            foreach (Node node in models[0].Nodes)
            {
                value0[0][node.ID] = 0; /* 0.96733;*/
            }
            foreach (Node node in models[1].Nodes)
            {
                value0[1][node.ID] = 0.96;
            }

            foreach (Node node in models[1].Nodes)
            {
                value0[2][node.ID] = 1;
            }

            SkylineSolver[] solvers = new SkylineSolver[models.Length];
            //DenseMatrixSolver[] solvers = new DenseMatrixSolver[models.Length];
            IConvectionDiffusionIntegrationProvider[] providers = new IConvectionDiffusionIntegrationProvider[models.Length];
            IChildAnalyzer[] childAnalyzers = new IChildAnalyzer[models.Length];
            for (int i = 0; i < models.Length; i++)
            {
                initialValues[i] = Vector.CreateFromArray(value0[i]);
                //var builder = new DenseMatrixSolver.Builder();
                //builder.IsMatrixPositiveDefinite = false;
                solvers[i]        = builder.BuildSolver(models[i]);
                providers[i]      = new ProblemConvectionDiffusion2(models[i], solvers[i]);
                childAnalyzers[i] = new LinearAnalyzer(models[i], solvers[i], providers[i]);
            }

            const double timestep       = .005;
            const double time           = 30;
            var          parentAnalyzer = new ConvectionDiffusionImplicitDynamicAnalyzerMultiModel(UpdateModels, models, solvers,
                                                                                                   providers, childAnalyzers, timestep, time, initialTemperature: initialValues);

            parentAnalyzer.Initialize();
            double[]           muLame           = new double[] { 6e4, 2.1e4 };
            double[]           poissonV         = new double[] { .45, .2 };
            IDynamicMaterial[] dynamicMaterials = new DynamicMaterial[] { new DynamicMaterial(.001, 0, 0, true), new DynamicMaterial(.001, 0, 0, true) };
            var structuralModel    = CreateStructuralModel(muLame, poissonV, dynamicMaterials, 0, new double[] { 0, 0, 0 }, lgElement).Item1; // new Model();
            var structuralSolver   = structuralBuilder.BuildSolver(structuralModel);
            var structuralProvider = new ProblemStructural(structuralModel, structuralSolver);
            //var structuralChildAnalyzer = new LinearAnalyzer(structuralModel, structuralSolver, structuralProvider);
            var increments = 2;
            var structuralChildAnalyzerBuilder = new LoadControlAnalyzer.Builder(structuralModel, structuralSolver, structuralProvider, increments);

            structuralChildAnalyzerBuilder.ResidualTolerance             = 1E-6;
            structuralChildAnalyzerBuilder.MaxIterationsPerIncrement     = 50;
            structuralChildAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer structuralChildAnalyzer = structuralChildAnalyzerBuilder.Build();
            var structuralParentAnalyzer = new NewmarkDynamicAnalyzer(UpdateNewmarkModel, structuralModel, structuralSolver,
                                                                      structuralProvider, structuralChildAnalyzer, timestep, time, 0.25, 0.5);

            structuralParentAnalyzer.Initialize();

            for (int i = 0; i < time / timestep; i++)
            {
                parentAnalyzer.SolveTimestep(i);
                structuralParentAnalyzer.SolveTimestep(i);
            }

            return(solvers.Select(x => x.LinearSystems[subdomainID].Solution).ToArray());
        }