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); }
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 void SolveBuildingInNoSoilSmallDynamic() { var model = new Model(); model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); BeamBuildingBuilder.MakeBeamBuilding(model, 20, 20, 20, 5, 4, model.NodesDictionary.Count + 1, model.ElementsDictionary.Count + 1, subdomainID, 4, false, false); // Solver var solverBuilder = new SkylineSolver.Builder(); ISolver solver = solverBuilder.BuildSolver(model); // Structural problem provider var provider = new ProblemStructural(model, solver); // Linear static analysis var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.01, 0.1); parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build(); // Request output int monitorDof = 420; childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { monitorDof }); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Write output DOFSLog log = (DOFSLog)childAnalyzer.Logs[subdomainID][0]; //There is a list of logs for each subdomain and we want the first one Console.WriteLine($"dof = {monitorDof}, u = {log.DOFValues[monitorDof]}"); //TODO: No loads have been defined so the result is bound to be 0. }
private static void SolveBuildingInNoSoilSmallDynamic() { VectorExtensions.AssignTotalAffinityCount(); Model model = new Model(); model.SubdomainsDictionary.Add(1, new Subdomain() { ID = 1 }); BeamBuildingBuilder.MakeBeamBuilding(model, 20, 20, 20, 5, 4, model.NodesDictionary.Count + 1, model.ElementsDictionary.Count + 1, 1, 4, false, false); model.ConnectDataStructures(); SolverSkyline solver = new SolverSkyline(model); ProblemStructural provider = new ProblemStructural(model, solver.SubdomainsDictionary); LinearAnalyzer analyzer = new LinearAnalyzer(solver, solver.SubdomainsDictionary); NewmarkDynamicAnalyzer parentAnalyzer = new NewmarkDynamicAnalyzer(provider, analyzer, solver.SubdomainsDictionary, 0.5, 0.25, 0.01, 0.1); analyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 420 }); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); }
public void LinearElasticBeam2DNewmarkDynamicAnalysisTest() { double youngModulus = 21000; double poissonRatio = 0.3; double area = 91.04; double inertiaY = 2843.0; double inertiaZ = 8091.0; double density = 7.85; double nodalLoad = 1000.0; int totalNodes = 2; 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, z: 0.0); Node node2 = new Node(id: 2, x: 300.0, y: 0.0, z: 0.0); nodes.Add(node1); nodes.Add(node2); // 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.RotationZ }); // Create a new Beam2D element var beam = new EulerBeam2D(youngModulus) { Density = density, SectionArea = area, MomentOfInertia = inertiaZ }; var element = new Element() { ID = 1, ElementType = beam }; // Add nodes to the created element element.AddNode(model.NodesDictionary[1]); element.AddNode(model.NodesDictionary[2]); // Element Stiffness Matrix var a = beam.StiffnessMatrix(element); var b = beam.MassMatrix(element); // Add Hexa element to the element and subdomains dictionary of the model model.ElementsDictionary.Add(element.ID, element); model.SubdomainsDictionary[1].Elements.Add(element); // define loads model.Loads.Add(new Load { Amount = nodalLoad, Node = model.NodesDictionary[totalNodes], DOF = StructuralDof.TranslationY }); // Solver var solverBuilder = new SkylineSolver.Builder(); ISolver solver = solverBuilder.BuildSolver(model); // Problem type var provider = new ProblemStructural(model, solver); // Analyzers var childAnalyzer = new LinearAnalyzer(model, solver, provider); 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(2.2840249264795207, solver.LinearSystems[1].Solution[1], 8); }
private static void TestBatheImplicitAnalysisExample() { var model = new Model(); int subdomainID = 0; model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); var n = new Node(id: 0, x: double.NaN); var e = new Element() { ID = 0 }; e.NodesDictionary.Add(0, n); var m = new Mock <IFiniteElement>(); m.Setup(x => x.StiffnessMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] { { 6, -2, }, { -2, 4 } })); m.Setup(x => x.MassMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] { { 2, 0, }, { 0, 1 } })); m.Setup(x => x.DampingMatrix(e)).Returns(Matrix.CreateFromArray(new double[, ] { { 0, 0, }, { 0, 0 } })); //m.Setup(x => x.StiffnessMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 6, -2, 4 })); //m.Setup(x => x.MassMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 2, 0, 1 })); //m.Setup(x => x.DampingMatrix(e)).Returns(new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 0, 0, 0 })); m.Setup(x => x.GetElementDofTypes(e)).Returns(new[] { new[] { StructuralDof.TranslationX, StructuralDof.TranslationY } }); m.SetupGet(x => x.DofEnumerator).Returns(new GenericDofEnumerator()); e.ElementType = m.Object; model.NodesDictionary.Add(0, n); model.ElementsDictionary.Add(0, e); model.SubdomainsDictionary[subdomainID].Elements.Add(e); model.Loads.Add(new Load() { Amount = 10, Node = n, DOF = StructuralDof.TranslationY }); var lX = new Mock <IMassAccelerationHistoryLoad>(); lX.SetupGet(x => x.DOF).Returns(StructuralDof.TranslationX); lX.SetupGet(x => x[It.IsAny <int>()]).Returns(0); var lY = new Mock <IMassAccelerationHistoryLoad>(); lY.SetupGet(x => x.DOF).Returns(StructuralDof.TranslationY); lY.SetupGet(x => x[0]).Returns(10); lY.SetupGet(x => x[It.IsInRange(1, 100, Range.Inclusive)]).Returns(0); model.MassAccelerationHistoryLoads.Add(lX.Object); model.MassAccelerationHistoryLoads.Add(lY.Object); m.Setup(x => x.CalculateAccelerationForces(It.IsAny <Element>(), It.IsAny <IList <MassAccelerationLoad> >())) .Returns <Element, IList <MassAccelerationLoad> >((element, loads) => { double[] accelerations = { loads[0].Amount, loads[1].Amount }; var massMatrix = Matrix.CreateFromArray(new double[, ] { { 2, 0, }, { 0, 1 } }); //var massMatrix = new Numerical.LinearAlgebra.SymmetricMatrix2D(new double[] { 2, 0, 1 }); return(massMatrix.Multiply(accelerations)); } ); // Solver var solverBuilder = new SkylineSolver.Builder(); ISolver solver = solverBuilder.BuildSolver(model); //TODO: These overwrite the corresponding data extracted by the Model. Either set up these or the Model. //solver.LinearSystems[subdomainID].SetMatrix( // SkylineMatrix.CreateFromArrays(2, new double[] { 6, 4, -2 }, new int[] { 0, 1, 3 }, true)); // K = [6 -2; -2 4] //solver.LinearSystems[subdomainID].RhsVector = Vector.CreateFromArray(new double[] { 0, 10 }); // Problem type var provider = new ProblemStructural(model, solver); // Analyzers var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36); parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default //parentAnalyzerBuilder.SetNewmarkParameters(0.25, 0.5); // Not necessary. This is the default NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build(); // Request output childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { 0, 1 }); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); //Check output DOFSLog log = (DOFSLog)childAnalyzer.Logs[subdomainID][0]; //There is a list of logs for each subdomain and we want the first one Assert.Equal(2.2840249264795207, log.DOFValues[0], 8); Assert.Equal(2.4351921891904156, log.DOFValues[1], 8); }
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 TotalDisplacementsPerIterationLog SolveModel() { //VectorExtensions.AssignTotalAffinityCount(); Model model = new Model(); model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); BuildCantileverModel(model, -(0.15 * 2) / 20); //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 parentAnalyzerBuilder = new NewmarkDynamicAnalyzer.Builder(model, solver, provider, childAnalyzer, 0.28, 3.36); parentAnalyzerBuilder.SetNewmarkParametersForConstantAcceleration(); // Not necessary. This is the default NewmarkDynamicAnalyzer parentAnalyzer = parentAnalyzerBuilder.Build(); //var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); var watchDofs = new Dictionary <int, int[]>(); watchDofs.Add(subdomainID, new int[2] { 0, 5 }); //[12] { 0, 1,2,3,4,5,6,7,8,9,10,11}); 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); }