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); }
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); }
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 SolveBuildingInNoSoilSmall() { 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); model.Loads.Add(new Load() { Amount = -100, Node = model.Nodes[21], DOF = StructuralDof.TranslationX }); // 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 parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); // 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]}"); }
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); }
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 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); }
public static void CNT_4_4_DisplacementControl() { double youngModulus = 16710.0; double poissonRatio = 0.034; double nodalDisplacement = 23.73; 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 = 20; 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 }); } // Applied displacement model.NodesDictionary[monitorNode_2].Constraints.Add(new Constraint { DOF = StructuralDof.TranslationY, Amount = nodalDisplacement }); // 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); } } // 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 DisplacementControlAnalyzer.Builder(model, solver, provider, increments); var 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(-21.2328445476855, log.DOFValues[monDOF], 8); }
private static void TestQuad4LinearCantileverExample() { // Model & subdomains var model = new Model(); int subdomainID = 0; model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); // Materials double youngModulus = 3.76; double poissonRatio = 0.3779; double thickness = 1.0; double nodalLoad = 500.0; var material = new ElasticMaterial2D(StressState2D.PlaneStress) { YoungModulus = youngModulus, PoissonRatio = poissonRatio }; // Nodes var nodes = new Node[] { new Node(id: 1, x: 0.0, y: 0.0, z: 0.0), new Node(id: 2, x: 10.0, y: 0.0, z: 0.0), new Node(id: 3, x: 10.0, y: 10.0, z: 0.0), new Node(id: 4, x: 0.0, y: 10.0, z: 0.0) }; for (int i = 0; i < nodes.Length; ++i) { model.NodesDictionary.Add(i, nodes[i]); } // Elements var factory = new ContinuumElement2DFactory(thickness, material, null); var elementWrapper = new Element() { ID = 0, ElementType = factory.CreateElement(CellType.Quad4, nodes) }; elementWrapper.AddNodes(nodes); model.ElementsDictionary.Add(elementWrapper.ID, elementWrapper); model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper); //var a = quad.StiffnessMatrix(element); // Prescribed displacements model.NodesDictionary[0].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationX, Amount = 0.0 }); model.NodesDictionary[0].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationY, Amount = 0.0 }); model.NodesDictionary[3].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationX, Amount = 0.0 }); model.NodesDictionary[3].Constraints.Add(new Constraint() { DOF = StructuralDof.TranslationY, Amount = 0.0 }); // Nodal loads model.Loads.Add(new Load() { Amount = nodalLoad, Node = model.NodesDictionary[1], DOF = StructuralDof.TranslationX }); model.Loads.Add(new Load() { Amount = nodalLoad, Node = model.NodesDictionary[2], DOF = StructuralDof.TranslationX }); // Solver var pcgBuilder = new PcgAlgorithm.Builder(); pcgBuilder.ResidualTolerance = 1E-6; pcgBuilder.MaxIterationsProvider = new PercentageMaxIterationsProvider(0.5); var solverBuilder = new PcgSolver.Builder(); solverBuilder.PcgAlgorithm = pcgBuilder.Build(); PcgSolver solver = solverBuilder.BuildSolver(model); // Problem type var provider = new ProblemStructural(model, solver); // Analyzers var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); //NewmarkDynamicAnalyzer parentAnalyzer = new NewmarkDynamicAnalyzer(provider, childAnalyzer, linearSystems, 0.25, 0.5, 0.28, 3.36); // Request output childAnalyzer.LogFactories[subdomainID] = new LinearAnalyzerLogFactory(new int[] { 0 }); // Run the anlaysis 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(253.132375961535, log.DOFValues[0], 8); }