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] = 1;
            }

            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       = .1;
            const double time           = 3;
            var          parentAnalyzer = new ConvectionDiffusionImplicitDynamicAnalyzerMultiModel(UpdateModels, models, solvers,
                                                                                                   providers, childAnalyzers, timestep, time, initialTemperature: initialValues);

            parentAnalyzer.Initialize();

            var structuralModel    = CreateStructuralModel(3e4, 0, new DynamicMaterial(.001, 0, 0, true), 0, new double[] { 1000, 0, 0 }, 1).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, .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());
        }
Пример #2
0
        private static IVectorView SolveModel(Model model, IModelReader modelReader)
        {
            var builder = new SkylineSolver.Builder();
            //builder.IsMatrixPositiveDefinite = false;
            var          solver   = builder.BuildSolver(model);
            const double timestep = 1;
            const double time     = 100;

            var provider             = new ProblemStructural(model, solver);
            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-6;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 50;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

            //var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, timestep, time);
            //parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();
            //NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();
            var parentAnalyzer = new NewmarkDynamicAnalyzer(UpdateNewmarkModel, model, solver,
                                                            provider, childAnalyzer, timestep, time, .25, .5);


            parentAnalyzer.Initialize();
            for (int i = 0; i < time / timestep; i++)
            {
                //lambdag = .01 * i + 1;
                parentAnalyzer.SolveTimestep(i);
            }

            return(solver.LinearSystems[subdomainID].Solution);
        }
        public void SolveNLBeam()
        {
            var m = new Model();

            m.NodesDictionary.Add(1, new Node(id: 1, x: 0, y:  0, z: 0));
            m.NodesDictionary.Add(2, new Node(id: 2, x: 5, y:  0, z: 0));
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationX
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationY
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.TranslationZ
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            m.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });
            m.ElementsDictionary.Add(1, new Element()
            {
                ID          = 1,
                ElementType = new Beam3DCorotationalQuaternion(m.Nodes, new ElasticMaterial3D()
                {
                    YoungModulus = 2.1e6, PoissonRatio = 0.2
                }, 1,
                                                               new BeamSection3D(0.06, 0.0002, 0.00045, 0.000818, 0.05, 0.05))
            });
            m.ElementsDictionary[1].AddNodes(m.Nodes);
            m.SubdomainsDictionary.Add(1, new Subdomain(1));
            m.SubdomainsDictionary[1].Elements.Add(m.ElementsDictionary[1]);
            m.Loads.Add(new Load()
            {
                Node = m.NodesDictionary[2], Amount = 100, DOF = StructuralDof.TranslationY
            });

            // Solver
            var     solverBuilder = new SkylineSolver.Builder();
            ISolver solver        = solverBuilder.BuildSolver(m);

            // Problem type
            var provider = new ProblemStructural(m, solver);

            // Analyzers
            int increments           = 10;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(m, solver, provider, increments);
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(m, solver, provider, childAnalyzer);

            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();
        }
        public static void EmbeddedEBEinMatrix_NewtonRaphson()
        {
            // 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 = 41;
            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: NewtonRaphsonNonLinearAnalyzer
            int increments           = 100;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                ResidualTolerance = 1E-03, MaxIterationsPerIncrement = 10
            };
            LoadControlAnalyzer 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();

            // Create Paraview File
            var paraview = new ParaviewEmbedded3D(model, solver.LinearSystems[0].Solution, "test");

            paraview.CreateParaviewFile();
        }
        private static double[] SolveModel()
        {
            var model = new Model();

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

            BuildCantileverModel(model, 850);

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);



            // initialize the anlaysis
            parentAnalyzer.Initialize();

            // Output
            int[] monitoredNodes = new int[] { 6, 8 };
            int[] monitoredDofs  = monitoredNodes.Select(x => model.GlobalDofOrdering.GlobalFreeDofs[model.NodesDictionary[x], StructuralDof.TranslationX]).ToArray();
            var   watchDofs      = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, monitoredDofs);
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

            //run the analysis and give output
            parentAnalyzer.Solve();



            var solutionOfIters5And12 = new double[] { log1.GetTotalDisplacement(5, 0, 3), log1.GetTotalDisplacement(12, 0, 3),
                                                       log1.GetTotalDisplacement(5, 0, 9), log1.GetTotalDisplacement(12, 0, 9) };

            return(solutionOfIters5And12);
        }
Пример #6
0
        //checked: apotelesmata C:\Users\turbo-x\Desktop\notes_elegxoi\MSOLVE_output_2\APOTELESMATA_MS_hexa8_cantilever_nea\IntegrationElasticCantileverBenchmark RunExample

        //Origin opou htan checked branch example/ms_development_nl_elements_merge
        //modifications: egine v2
        public static TotalDisplacementsPerIterationLog RunExample()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model model       = new Model();
            int   subdomainID = 1;  model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));

            HexaCantileverBuilder_copyMS_222(model, 0.00219881744271988174427);

            //model.ConnectDataStructures();

            //var linearSystems = new Dictionary<int, ILinearSystem>(); //I think this should be done automatically
            //linearSystems[subdomainID] = new SkylineLinearSystem(subdomainID, model.Subdomains[0].Forces);

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };

            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);
            var watchDofs      = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

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


            return(log1);
        }
        private static void SolveModel()
        {
            var model = new Model();

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

            var load = 850;

            BuildCantileverModel(model, load);

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 10;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-5;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Setup displacements log
            var watchDof = new Dictionary <int, int[]>();

            //watchDof.Add(subdomainID, new int[1] { 46 });
            watchDof.Add(subdomainID, new int[1] {
                94
            });
            var log1 = new IncrementalDisplacementsLog(watchDof);

            childAnalyzer.IncrementalDisplacementsLog = log1;

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

            // Write log data to file
            WriteDisplacementsToFile(log1, watchDof, load);
        }
        private static TotalDisplacementsPerIterationLog SolveModel()
        {
            var model = new Model();

            //model.dofOrderer = (subdomain) => (new SimpleDofOrderer()).OrderDofs(model);
            model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID));
            ShellAndCohesiveRAM_11tlkShellPaktwsh(model);

            // Solver
            var solverBuilder = new SkylineSolver.Builder();
            //var solverBuilder = new Solvers.Dense.DenseMatrixSolver.Builder();
            //solverBuilder.DofOrderer = new DofOrderer(new SimpleDofOrderingStrategy(), new NullReordering());
            var solver = solverBuilder.BuildSolver(model);

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();

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

            // Output
            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 39
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;

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

            return(log1);
        }
        private static IncrementalDisplacementsLog SolveModel()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model model = new Model();

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

            BuildCantileverModel(model, 850);

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            // Output
            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new IncrementalDisplacementsLog(watchDofs);

            childAnalyzer.IncrementalDisplacementsLog = log1;

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



            return(log1);
        }
Пример #10
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);
        }
Пример #11
0
        private static TotalDisplacementsPerIterationLog SolveModel()
        {
            //VectorExtensions.AssignTotalAffinityCount();
            Model model = new Model();

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

            BuildCantileverModel(model, 850);

            //model.ConnectDataStructures();

            //var linearSystems = new Dictionary<int, ILinearSystem>(); //I think this should be done automatically
            //linearSystems[subdomainID] = new SkylineLinearSystem(subdomainID, model.Subdomains[0].Forces);

            //ProblemStructural provider = new ProblemStructural(model, linearSystems);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };
            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            //var increments = 2;
            //var childAnalyzer = new NewtonRaphsonNonLinearAnalyzer(solver, linearSystemsArray, subdomainUpdaters, subdomainMappers, provider, increments, model.TotalDOFs);

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            //var solver = new SolverSkyline(linearSystems[subdomainID]);
            //var linearSystemsArray = new[] { linearSystems[subdomainID] };

            //var subdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.Subdomains[0]) };
            //var subdomainMappers = new[] { new SubdomainGlobalMapping(model.Subdomains[0]) };

            var increments           = 2;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance             = 1E-8;
            childAnalyzerBuilder.MaxIterationsPerIncrement     = 100;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 1;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

            var watchDofs = new Dictionary <int, int[]>();

            watchDofs.Add(subdomainID, new int[5] {
                0, 11, 23, 35, 47
            });
            var log1 = new TotalDisplacementsPerIterationLog(watchDofs);

            childAnalyzer.TotalDisplacementsPerIterationLog = log1;


            //childAnalyzer.SetMaxIterations = 100;
            //childAnalyzer.SetIterationsForMatrixRebuild = 1;

            //StaticAnalyzer parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystems);

            //parentAnalyzer.BuildMatrices();
            parentAnalyzer.Initialize();
            parentAnalyzer.Solve();


            return(log1);
        }
        private static void TestBeam3DElasticNonlinearNewmarkDynamicAnalysisExample()
        {
            double youngModulus     = 21000.0;
            double poissonRatio     = 0.3;
            double nodalLoad        = 20000.0;
            double area             = 91.04;
            double inertiaY         = 2843.0;
            double inertiaZ         = 8091.0;
            double torsionalInertia = 76.57;
            double effectiveAreaY   = 91.04;
            double effectiveAreaZ   = 91.04;
            double density          = 7.85;
            int    nNodes           = 3;
            int    nElems           = 2;
            int    monitorNode      = 3;

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

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x: 0.0, y: 0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 300.0, y: 0.0, z: 0.0);
            Node         node3 = new Node(id: 3, x: 600.0, y: 0.0, z: 0.0);

            nodes.Add(node1);
            nodes.Add(node2);
            nodes.Add(node3);

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

            // Add a single subdomain to the model
            int subdomainID = 0;

            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.TranslationZ
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });
            // 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 BeamSection3D(area, inertiaY, inertiaZ, torsionalInertia, effectiveAreaY, effectiveAreaZ);
                var beam        = new Beam3DCorotationalQuaternion(elementNodes, material, density, beamSection);

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = beam
                };

                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = beam.StiffnessMatrix(element);
                var b = beam.MassMatrix(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++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 10;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.MaxIterationsPerIncrement     = 120;
            childAnalyzerBuilder.NumIterationsForMatrixRebuild = 500;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzerBuilder         = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36);

            parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration();             // Not necessary. This is the default
            NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build();

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

            Assert.Equal(148.936792350562, solver.LinearSystems[subdomainID].Solution[7], 12);
        }
        private static void CantileverBeam2DCorotationalNonlinearTest()
        {
            double youngModulus = 21000.0;
            double poissonRatio = 0.3;
            double nodalLoad    = 20000.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
            var 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, Amount = 0.0
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = 0.0
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.RotationZ, Amount = 0.0
            });

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

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

            // 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
            int increments                    = 10;
            var childAnalyzerBuilder          = new LoadControlAnalyzer.Builder(model, solver, provider, increments);
            LoadControlAnalyzer 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[] { 4 });

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

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

            Assert.Equal(146.5587362562, log.DOFValues[4], 3);
        }
Пример #14
0
        public static void CNT_4_4_NewtonRaphson()
        {
            double youngModulus         = 16710.0;
            double poissonRatio         = 0.034;
            double nodalLoad            = 1.2;
            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           = 100;

            //Read number of nodes and number of elements from input files
            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
                });
            }

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

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode_2], DOF = StructuralDof.TranslationY
            });

            // 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 LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance = 1E-3;
            LoadControlAnalyzer 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(23.7373042863345, log.DOFValues[monDOF], 8);
        }
        public static void EmbeddedCNTinMatrix_NewtonRaphson()
        {
            // No. of increments
            int increments = 1000;

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

            // Boundary Conditions - Right End [End-5]
            for (int iNode = 1; iNode <= 10091; iNode += 10)
            {
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
            }

            //// Boundary Conditions - Left End [End-6]
            //for (int iNode = 10; iNode <= 10100; iNode += 10)
            //{
            //    model.NodesDictionary[iNode].Constraints.Add(new Constraint { DOF = DOFType.X });
            //}

            //Compression Loading
            double nodalLoad = -1.0;                         //0.40;

            for (int iNode = 10001; iNode <= 10100; iNode++) //[End-4]
            {
                model.Loads.Add(new Load()
                {
                    Amount = nodalLoad, Node = model.NodesDictionary[iNode], DOF = StructuralDof.TranslationZ
                });
            }

            // 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 LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                ResidualTolerance = 1E-03
            };
            LoadControlAnalyzer 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();
        }
        public void CantileverYBeam3DQuaternionNonlinearTest()
        {
            double youngModulus     = 21000.0;
            double poissonRatio     = 0.3;
            double nodalLoad        = 20000.0;
            double area             = 91.04;
            double inertiaY         = 2843.0;
            double inertiaZ         = 8091.0;
            double torsionalInertia = 76.57;
            double effectiveAreaY   = 91.04;
            double effectiveAreaZ   = 91.04;
            int    nNodes           = 3;
            int    nElems           = 2;
            int    monitorNode      = 3;

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

            // Node creation
            IList <Node> nodes = new List <Node>();
            Node         node1 = new Node(id: 1, x:   0.0, y:  0.0, z: 0.0);
            Node         node2 = new Node(id: 2, x: 100.0, y:  0.0, z: 0.0);
            Node         node3 = new Node(id: 3, x: 200.0, y:  0.0, z: 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(1, new Subdomain(1));

            // 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.TranslationZ
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationX
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationY
            });
            model.NodesDictionary[1].Constraints.Add(new Constraint {
                DOF = StructuralDof.RotationZ
            });

            // 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 BeamSection3D(area, inertiaY, inertiaZ, torsionalInertia, effectiveAreaY, effectiveAreaZ);
                var beam        = new Beam3DCorotationalQuaternion(elementNodes, material, 7.85, beamSection);

                // Create elements
                var element = new Element()
                {
                    ID          = iElem + 1,
                    ElementType = beam
                };

                // Add nodes to the created element
                element.AddNode(model.NodesDictionary[iNode]);
                element.AddNode(model.NodesDictionary[iNode + 1]);

                var a = beam.StiffnessMatrix(element);
                //var writer = new FullMatrixWriter();
                //writer.WriteToFile(a, output);


                // Add beam element to the element and subdomains dictionary of the model
                model.ElementsDictionary.Add(element.ID, element);
                model.SubdomainsDictionary[1].Elements.Add(element);
                iNode++;
            }

            // Add nodal load values at the top nodes of the model
            model.Loads.Add(new Load()
            {
                Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY
            });

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

            // Problem type
            var provider = new ProblemStructural(model, solver);

            // Analyzers
            int increments           = 10;
            var childAnalyzerBuilder = new LoadControlAnalyzer.Builder(model, solver, provider, increments);

            childAnalyzerBuilder.ResidualTolerance = 1E-3;
            //childAnalyzerBuilder.SubdomainUpdaters = new[] { new NonLinearSubdomainUpdater(model.SubdomainsDictionary[subdomainID]) }; // This is the default
            LoadControlAnalyzer childAnalyzer = childAnalyzerBuilder.Build();
            var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer);

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

            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

            Assert.Equal(148.936792350562, log.DOFValues[7], 2);
        }
        public static void EmbeddedCNT_20_20_inMatrix_NewtonRaphson()
        {
            // No. of increments
            int increments = 100;

            // 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 = 1800;
            IDofType monitorDof  = StructuralDof.TranslationZ;

            // Choose model
            EmbeddedModelBuilder.EmbeddedExample(model);

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

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

            // Boundary Conditions - Bottom End [End-5] (x = -10)
            for (int iNode = 1; iNode <= 17981; iNode = iNode + 20)
            {
                model.NodesDictionary[iNode].Constraints.Add(new Constraint {
                    DOF = StructuralDof.TranslationX
                });
            }

            // Compressive Loading - [End-4]
            double nodalLoad = -0.5; //-2.0; //

            for (int iNode = 17601; iNode <= 18000; iNode++)
            {
                model.Loads.Add(new Load()
                {
                    Amount = nodalLoad, Node = model.NodesDictionary[iNode], DOF = StructuralDof.TranslationZ
                });
            }

            // 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 LoadControlAnalyzer.Builder(model, solver, provider, increments)
            {
                MaxIterationsPerIncrement     = 100,
                NumIterationsForMatrixRebuild = 1,
                ResidualTolerance             = 5E-3
            };
            LoadControlAnalyzer 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_NewtonRaphson.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();

            // Create Paraview File
            var paraview = new ParaviewEmbedded3D(model, solver.LinearSystems[0].Solution, "test");

            paraview.CreateParaviewFile();
        }