private static void GenerateElements(double width, double height, double stepX, double stepY) { ElasticMaterial elasticMaterial = new ElasticMaterial(); elasticMaterial.YoungModulus = young; elasticMaterial.PoissonRatio = poisson; Beam2D beam = new Beam2D(elasticMaterial); beam.Density = density; beam.MomentOfInertia = inertia; beam.SectionArea = section; int nX = (int)(width / stepX) + 1; int nY = (int)(height / stepY) + 1; int eX = 2 * nX - 1; int eY = nY - 1; for (int i = 1; i <= eY; i++) { for (int j = 1; j <= nX; j++) { Element element = new Element(); element.ElementType = beam; //element.MaterialType = elasticMaterial; element.ID = (i - 1) * eX + (j - 1) * 2 + 1; element.AddNode(model.NodesDictionary[(i - 1) * nX + j]); element.AddNode(model.NodesDictionary[i * nX + j]); model.ElementsDictionary.Add(element.ID, element); } for (int j = 1; j <= nX - 1; j++) { Element element = new Element(); element.ElementType = beam; //element.MaterialType = elasticMaterial; element.ID = (i - 1) * eX + (j - 1) * 2 + 2; element.AddNode(model.NodesDictionary[i * nX + j]); element.AddNode(model.NodesDictionary[i * nX + j + 1]); model.ElementsDictionary.Add(element.ID, element); } } }
public void TestEulerBeam2DLinearBendingExample() { double youngModulus = 21000.0; double poissonRatio = 0.3; double nodalLoad = 2000.0; int nElems = 2; int monitorNode = 3; // Create new 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, 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++) { // Create new Beam2D section and element var beam = new EulerBeam2D(youngModulus) { Density = 7.85, SectionArea = 91.04, MomentOfInertia = 8091.00, }; // 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); // Add Hexa 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 MSolve.Solvers.Iterative.PcgSolver.Builder( // (new LinearAlgebra.Iterative.ConjugateGradient.PcgAlgorithm.Builder()).Build()); //var solver = solverBuilder.BuildSolver(model); 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 parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); // Run the anlaysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); double solutionNorm = solver.LinearSystems[1].Solution.Norm2(); double rhsNorm = solver.LinearSystems[1].RhsVector.Norm2(); Assert.Equal(31.388982074929341, solver.LinearSystems[1].Solution[4], 12); }
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 Model CreateModelWithoutLoads() { double youngModulus = 21000.0; double poissonRatio = 0.3; double area = 91.04; double inertia = 8091.0; int nElems = 2; // 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++; } return(model); }
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 Run() { double youngModulus = 200.0e06; double poissonRatio = 0.3; double nodalLoad = 25.0; // Create a new elastic 3D material var material = new ElasticMaterial() { YoungModulus = youngModulus, PoissonRatio = poissonRatio, }; // Node creation IList <Node> nodes = CreateNodes(); // Model creation Model model = new Model(); // Add a single subdomain to the model model.SubdomainsDictionary.Add(0, 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.RotationZ }); model.NodesDictionary[2].Constraints.Add(new Constraint { DOF = StructuralDof.TranslationY, Amount = -4.16666666666667E-07 }); //Create a new Beam2D element var beam = new EulerBeam2D(youngModulus) { SectionArea = 1, MomentOfInertia = .1 }; var element = new Element() { ID = 1, ElementType = beam }; //// Add nodes to the created element element.AddNode(model.NodesDictionary[1]); element.AddNode(model.NodesDictionary[2]); //var a = beam.StiffnessMatrix(element); // Add Hexa element to the element and subdomains dictionary of the model model.ElementsDictionary.Add(element.ID, element); model.SubdomainsDictionary[subdomainID].Elements.Add(element); // Add nodal load values at the top nodes of the model //model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[2], DOF = DOFType.Y }); // 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); // Output requests var logFactory = new TotalDisplacementsLog.Factory(model.SubdomainsDictionary[subdomainID]); logFactory.WatchDof(model.NodesDictionary[2], StructuralDof.TranslationX); logFactory.WatchDof(model.NodesDictionary[2], StructuralDof.RotationZ); childAnalyzer.LogFactories[subdomainID] = logFactory; // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Choose dof types X, Y, rotZ to log for node 5 var logger = (TotalDisplacementsLog)(childAnalyzer.Logs[subdomainID][0]); //There is a list of logs for each subdomain and we want the first one double[] results = { logger.GetDisplacementAt(model.NodesDictionary[2], StructuralDof.TranslationX), logger.GetDisplacementAt(model.NodesDictionary[2], StructuralDof.RotationZ) }; double[] expected = new double[] { 0, -4.16666666666667E-07, -6.25E-07 }; for (int i = 0; i < expected.Length - 1; i++) { //if (Math.Abs(expected[i] - results[i]) > 1e-14) //{ // throw new SystemException("Failed beam2D test, results don't coincide for dof no: " + i + ", expected displacement: " + expected[i] + ", calculated displacement: " + results[i]); //} Console.WriteLine(results[i]); } Console.WriteLine("ran beam2d2 test"); }
public void TestEulerBeam2DLinearBendingExample() { /// <summary> /// Define mechanical properties /// </summary> double youngModulus = 21000.0; double poissonRatio = 0.3; double nodalLoad = 2000.0; int nElems = 2; int monitorNode = 3; /// <summary> /// Create new material /// </summary> var material = new ElasticMaterial() { YoungModulus = youngModulus, PoissonRatio = poissonRatio, }; /// <summary> /// Node creation. Define geometry. /// </summary> 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); /// <summary> /// Model creation. /// </summary> Model model = new Model(); /// <summary> /// Add a single subdomain to the model. /// </summary> model.SubdomainsDictionary.Add(1, new Subdomain(1)); /// <summary> /// Add nodes to the nodes dictonary of the model. /// </summary> for (int i = 0; i < nodes.Count; ++i) { model.NodesDictionary.Add(i + 1, nodes[i]); } /// <summary> /// Constrain bottom nodes of the model. Define Boundary Conditions. /// </summary> 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 }); /// <summary> /// Generate elements of the structure. /// </summary> int iNode = 1; for (int iElem = 0; iElem < nElems; iElem++) { /// <summary> /// Create new Beam2D section and element. /// </summary> var beam = new EulerBeam2D(youngModulus) { Density = 7.85, SectionArea = 91.04, MomentOfInertia = 8091.00, }; /// <summary> /// Create elements. /// </summary> var element = new Element() { ID = iElem + 1, ElementType = beam }; /// <summary> /// Add nodes to the created element. /// </summary> element.AddNode(model.NodesDictionary[iNode]); element.AddNode(model.NodesDictionary[iNode + 1]); var a = beam.StiffnessMatrix(element); /// <summary> /// Adds Beam2D element to the element and subdomains dictionary of the model. /// </summary> model.ElementsDictionary.Add(element.ID, element); model.SubdomainsDictionary[1].Elements.Add(element); iNode++; } /// <summary> /// Add nodal load values at the top nodes of the model. /// </summary> model.Loads.Add(new Load() { Amount = nodalLoad, Node = model.NodesDictionary[monitorNode], DOF = StructuralDof.TranslationY }); /// <summary> /// Defines Skyline Solver. /// </summary> var solverBuilder = new SkylineSolver.Builder(); ISolver solver = solverBuilder.BuildSolver(model); /// <summary> /// Defines Problem type as Structural. /// </summary> var provider = new ProblemStructural(model, solver); /// <summary> /// Defines Analyzers. /// Chlid Analyzer: Linear /// Parent Analyzer: Static /// </summary> var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); /// <summary> /// Run the anlaysis. /// </summary> parentAnalyzer.Initialize(); parentAnalyzer.Solve(); /// <summary> /// Solution and right-hand-side norms. /// </summary> double solutionNorm = solver.LinearSystems[1].Solution.Norm2(); double rhsNorm = solver.LinearSystems[1].RhsVector.Norm2(); /// <summary> /// Check solution. /// </summary> Assert.Equal(31.388982074929341, solver.LinearSystems[1].Solution[4], 12); }
public void SolveCantileverBeam2D() { double youngModulus = 2.0e08; double poissonRatio = 0.3; double nodalLoad = 10.0; 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: 5.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) { SectionArea = 1, MomentOfInertia = .1 }; var element = new Element() { ID = 1, ElementType = beam }; // Add nodes to the created element element.AddNode(model.NodesDictionary[1]); element.AddNode(model.NodesDictionary[2]); var a = beam.StiffnessMatrix(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); // Add nodal load values at the top nodes of the model model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[2], DOF = StructuralDof.TranslationY }); // Solvers, providers, analyzers var solverBuilder = new SkylineSolver.Builder(); ISolver solver = solverBuilder.BuildSolver(model); var provider = new ProblemStructural(model, solver); var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); Assert.Equal(-2.08333333333333333e-5, solver.LinearSystems[1].Solution[1], 10); }
/// <summary> /// Saves the current structure to an .xml file /// </summary> /// <param name="pathToSave">The path to save the file</param> public static void SaveStructure(string pathToSave, List <Material> materialsList, List <Node> nodesList, List <ShellElement> shellList, List <Spring3D> spring3DList, List <Load> loadsList, List <Mass> massesList, List <Support> supportsList, List <SeismicLoad> seismicList, List <ImpulseLoad> impulseList, List <Analyses> analysesList) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineChars = "\r\n"; XmlWriter writer = XmlWriter.Create(pathToSave, settings); writer.WriteStartDocument(true); writer.WriteStartElement("structure"); //write the analysis type writer.WriteStartElement("analyses"); int count = 1; foreach (Analyses analysis in analysesList) { writer.WriteStartElement("analysis"); writer.WriteAttributeString("type", analysis.AnalysisType()); if (analysis.AnalysisType() == "Elastic") { ElasticAnalysis mElas = analysis as ElasticAnalysis; writer.WriteAttributeString("load-steps", mElas.Steps.ToString()); } else if (analysis.AnalysisType() == "Pushover") { PushoverAnalysis push = analysis as PushoverAnalysis; writer.WriteAttributeString("load-steps", push.Steps.ToString()); writer.WriteAttributeString("iterations", push.Iters.ToString()); } else if (analysis.AnalysisType() == "Cyclic") { CyclicAnalysis cyclic = analysis as CyclicAnalysis; writer.WriteAttributeString("load-steps", cyclic.Steps.ToString()); writer.WriteAttributeString("iterations", cyclic.Iters.ToString()); writer.WriteAttributeString("initial-peak", cyclic.InitialPeak.ToString()); writer.WriteAttributeString("cycles-per-peak", cyclic.CyclesPerPeak.ToString()); writer.WriteAttributeString("peak-increment", cyclic.PeakIncrement.ToString()); writer.WriteAttributeString("steps-per-peak", cyclic.StepsPerPeak.ToString()); writer.WriteAttributeString("type", cyclic.Type.ToString()); } else { DynamicAnalysis dyn = analysis as DynamicAnalysis; writer.WriteAttributeString("deltaT", dyn.DeltaT.ToString()); writer.WriteAttributeString("additional-time", dyn.AdditionalTime.ToString()); writer.WriteAttributeString("iterations", dyn.Iters.ToString()); writer.WriteAttributeString("itegration-method", dyn.IntegrationMethod.ToString()); writer.WriteAttributeString("type", dyn.Type.ToString()); } writer.WriteString(count.ToString()); count++; writer.WriteEndElement(); } writer.WriteEndElement(); //write the materials writer.WriteStartElement("materials"); writer.WriteAttributeString("total", materialsList.Count.ToString()); foreach (Material m in materialsList) { writer.WriteStartElement("material"); writer.WriteAttributeString("type", m.Type); if (m.Type == "Elastic") { ElasticMaterial mElas = m as ElasticMaterial; writer.WriteAttributeString("elasticity", mElas.E.ToString()); writer.WriteAttributeString("poisson", mElas.V.ToString()); } else if (m.Type == "OrthoElastic") { OrthotropicElasticMaterial mElas = m as OrthotropicElasticMaterial; writer.WriteAttributeString("ex", mElas.Ex.ToString()); writer.WriteAttributeString("ey", mElas.Ey.ToString()); writer.WriteAttributeString("vxy", mElas.Vxy.ToString()); writer.WriteAttributeString("gxy", mElas.Gxy.ToString()); writer.WriteAttributeString("gyz", mElas.Gyz.ToString()); writer.WriteAttributeString("gxz", mElas.Gxz.ToString()); } else if (m.Type == "Spring-Axial") { SpringAxialModel springAxial = m as SpringAxialModel; writer.WriteAttributeString("initialStiffness", springAxial._iniStiff.ToString()); writer.WriteAttributeString("peakForce", springAxial._fMax.ToString()); writer.WriteAttributeString("peakDisplacement", springAxial._dMax.ToString()); writer.WriteAttributeString("degradingStiffness", springAxial._degStiff.ToString()); writer.WriteAttributeString("residualForce", springAxial._fRes.ToString()); writer.WriteAttributeString("ultimateDisplacement", springAxial._dUlt.ToString()); writer.WriteAttributeString("compressiveStiffness", springAxial._compStiff.ToString()); writer.WriteAttributeString("unloadStiffness", springAxial._unlStiff.ToString()); writer.WriteAttributeString("unloadForce", springAxial._fUnl.ToString()); writer.WriteAttributeString("connectStiffness", springAxial._conStiff.ToString()); writer.WriteAttributeString("reloadStiffness", springAxial._relStiff.ToString()); } else { SpringGeneralModel springGeneral = m as SpringGeneralModel; writer.WriteAttributeString("initialStiffness", springGeneral._iniStiff.ToString()); writer.WriteAttributeString("peakForce", springGeneral._fMax.ToString()); writer.WriteAttributeString("peakDisplacement", springGeneral._dMax.ToString()); writer.WriteAttributeString("degradingStiffness", springGeneral._degStiff.ToString()); writer.WriteAttributeString("residualForce", springGeneral._fRes.ToString()); writer.WriteAttributeString("ultimateDisplacement", springGeneral._dUlt.ToString()); writer.WriteAttributeString("unloadStiffness", springGeneral._unlStiff.ToString()); writer.WriteAttributeString("unloadForce", springGeneral._fUnl.ToString()); writer.WriteAttributeString("connectStiffness", springGeneral._conStiff.ToString()); writer.WriteAttributeString("reloadStiffness", springGeneral._relStiff.ToString()); } writer.WriteString(m.ID.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); //write the loads writer.WriteStartElement("loads"); writer.WriteAttributeString("total", loadsList.Count.ToString()); foreach (Load l in loadsList) { writer.WriteStartElement("load"); writer.WriteAttributeString("ID", l.ID.ToString()); writer.WriteAttributeString("nodeID", l.NodeID.ToString()); writer.WriteAttributeString("status", l.Status); writer.WriteAttributeString("values", l.GetLoadList.Count.ToString()); //for each pair of dir-val in the load element foreach (PairValue pv in l.GetLoadList) { writer.WriteStartElement("value"); writer.WriteAttributeString("direction", pv.ID.ToString()); writer.WriteString(pv.GetVal.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); //write the masses writer.WriteStartElement("masses"); writer.WriteAttributeString("total", massesList.Count.ToString()); foreach (Mass m in massesList) { writer.WriteStartElement("mass"); writer.WriteAttributeString("ID", m.ID.ToString()); writer.WriteAttributeString("nodeID", m.NodeID.ToString()); writer.WriteAttributeString("values", m.GetMassList.Count.ToString()); //for each pair of dir-val in the mass element foreach (PairValue pv in m.GetMassList) { writer.WriteStartElement("value"); writer.WriteAttributeString("direction", pv.ID.ToString()); writer.WriteString(pv.GetVal.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); //write the boundaries writer.WriteStartElement("boundaries"); writer.WriteAttributeString("total", supportsList.Count.ToString()); foreach (Support s in supportsList) // for each support condition applied to a node { writer.WriteStartElement("boundary"); writer.WriteAttributeString("ID", s.ID.ToString()); writer.WriteAttributeString("nodeID", s.NodeID.ToString()); writer.WriteAttributeString("values", s.GetSupportList.Count.ToString()); foreach (PairValue pv in s.GetSupportList) // for each pair of dir-val in the support element { writer.WriteStartElement("value"); writer.WriteAttributeString("direction", pv.ID.ToString()); writer.WriteString(pv.GetVal.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); //write the nodes writer.WriteStartElement("nodes"); writer.WriteAttributeString("total", nodesList.Count.ToString()); foreach (Node n in nodesList) { writer.WriteStartElement("node"); writer.WriteAttributeString("X", n.Point.X.ToString()); writer.WriteAttributeString("Y", n.Point.Y.ToString()); writer.WriteAttributeString("Z", n.Point.Z.ToString()); writer.WriteString(n.ID.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); //write the spring3D elements writer.WriteStartElement("spring3D"); writer.WriteAttributeString("total", spring3DList.Count.ToString()); foreach (Spring3D e in spring3DList) { writer.WriteStartElement("element"); writer.WriteAttributeString("N1", e.N1.ID.ToString()); writer.WriteAttributeString("N2", e.N2.ID.ToString()); writer.WriteAttributeString("materialX", e.MaterialList[0].ToString()); writer.WriteAttributeString("materialY", e.MaterialList[1].ToString()); writer.WriteAttributeString("materialZ", e.MaterialList[2].ToString()); writer.WriteAttributeString("axial-vec", e.VectorX.ToString()); writer.WriteAttributeString("shear-vec", e.VectorY.ToString()); writer.WriteString(e.ID.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); //write the shell elements writer.WriteStartElement("shell"); writer.WriteAttributeString("total", shellList.Count.ToString()); foreach (ShellElement e in shellList) { writer.WriteStartElement("element"); writer.WriteAttributeString("thickness", e.thickness.ToString()); writer.WriteAttributeString("layers", e.layers.ToString()); writer.WriteAttributeString("material", e.material.ID.ToString()); writer.WriteAttributeString("N1", e.nodeList[0].ID.ToString()); writer.WriteAttributeString("N2", e.nodeList[1].ID.ToString()); writer.WriteAttributeString("N3", e.nodeList[2].ID.ToString()); writer.WriteAttributeString("N4", e.nodeList[3].ID.ToString()); writer.WriteAttributeString("N5", e.nodeList[4].ID.ToString()); writer.WriteAttributeString("N6", e.nodeList[5].ID.ToString()); writer.WriteAttributeString("N7", e.nodeList[6].ID.ToString()); writer.WriteAttributeString("N8", e.nodeList[7].ID.ToString()); writer.WriteAttributeString("N9", e.nodeList[8].ID.ToString()); writer.WriteString(e.ID.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); if (seismicList.Count != 0) { //write the seismic load writer.WriteStartElement("seismic"); writer.WriteAttributeString("total", seismicList[0].Records[0].Count.ToString()); for (int i = 0; i < seismicList[0].Records[0].Count; i++) { writer.WriteStartElement("data-point"); writer.WriteAttributeString("time", (seismicList[0].DeltaT * (i + 1)).ToString()); for (int j = 0; j < seismicList[0].Directions.Count; j++) { if (seismicList[0].Directions[j] == 'x') { writer.WriteAttributeString("x", (seismicList[0].Records[j][i] * seismicList[0].Scales[j]).ToString()); } else if (seismicList[0].Directions[j] == 'y') { writer.WriteAttributeString("y", (seismicList[0].Records[j][i] * seismicList[0].Scales[j]).ToString()); } else { writer.WriteAttributeString("z", (seismicList[0].Records[j][i] * seismicList[0].Scales[j]).ToString()); } } writer.WriteString((i + 1).ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } if (impulseList.Count != 0) { //write the seismic load writer.WriteStartElement("impulse"); writer.WriteAttributeString("total", impulseList[0].Points.GetLength(0).ToString()); for (int i = 0; i < impulseList[0].Points.GetLength(0); i++) { writer.WriteStartElement("data-point"); writer.WriteAttributeString("time", (impulseList[0].Points[i, 0]).ToString()); writer.WriteAttributeString("force", (impulseList[0].Points[i, 1]).ToString()); writer.WriteString((i + 1).ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndDocument(); writer.Close(); }
private static Model CreateModel(double youngModulus, double area, double nodalLoad) { //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 node0 = new Node(id: 0, x: 0.0, y: 0.0, z: 0.0); Node node1 = new Node(id: 1, x: 300.0, y: 0.0, z: 0.0); nodes.Add(node0); nodes.Add(node1); // Model creation Model model = new Model(); // Add a single subdomain to the model model.SubdomainsDictionary.Add(0, new Subdomain(0)); // Add nodes to the nodes dictonary of the model for (int i = 0; i < nodes.Count; ++i) { model.NodesDictionary.Add(i, nodes[i]); } // Constrain bottom nodes of the model model.NodesDictionary[0].Constraints.Add(new Constraint { DOF = StructuralDof.TranslationX }); model.NodesDictionary[0].Constraints.Add(new Constraint { DOF = StructuralDof.TranslationY }); model.NodesDictionary[0].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 = 0, ElementType = beam }; // Add nodes to the created element element.AddNode(model.NodesDictionary[0]); element.AddNode(model.NodesDictionary[1]); // 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[0].Elements.Add(element); // define loads model.Loads.Add(new Load { Amount = nodalLoad, Node = model.NodesDictionary[totalNodes - 1], DOF = StructuralDof.TranslationY }); return(model); }