private static void SolveBuildingInNoSoilSmall() { 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.Loads.Add(new Load() { Amount = -100, Node = model.Nodes[21], DOF = DOFType.X }); model.ConnectDataStructures(); SolverSkyline solver = new SolverSkyline(model); ProblemStructural provider = new ProblemStructural(model, solver.SubdomainsDictionary); LinearAnalyzer analyzer = new LinearAnalyzer(solver, solver.SubdomainsDictionary); StaticAnalyzer parentAnalyzer = new StaticAnalyzer(provider, analyzer, solver.SubdomainsDictionary); analyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { 420 }); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); }
private static void SolveLinearStatic(Model model) { // Choose linear equation system 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); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Logging displacement, strain, and stress fields. string outputDirectory = workingDirectory + "\\Plots"; childAnalyzer.LogFactories[0] = new VtkLogFactory(model, outputDirectory) { LogDisplacements = true, LogStrains = true, LogStresses = true, VonMisesStressCalculator = new PlaneStressVonMises() }; // Run the analysis parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); }
public void TestEulerBeam2DLinearBendingExample() { // Model and node creation var model = new Model(); model.NodesDictionary.Add(1, new Node { ID = 1, X = 0.0, Y = 0.0, Z = 0.0 }); model.NodesDictionary.Add(2, new Node { ID = 2, X = 100.0, Y = 0.0, Z = 0.0 }); model.NodesDictionary.Add(3, new Node { ID = 3, X = 200.0, Y = 0.0, Z = 0.0 }); // Constrain bottom node and add nodal load value model.NodesDictionary[1].Constraints.AddRange(new[] { DOFType.X, DOFType.Y, DOFType.Z, DOFType.RotZ }); model.Loads.Add(new Load() { Amount = 2000, Node = model.NodesDictionary[3], DOF = DOFType.Y }); // Generate elements of the structure for (int iElem = 0; iElem < 2; iElem++) { // Create new Beam2D section and element var element = new EulerBeam2D(2.1e4) { ID = iElem + 1, Density = 7.85, SectionArea = 91.04, MomentOfInertia = 8091.00 }; element.ElementType = element; // Add nodes to the created element element.AddNode(model.NodesDictionary[iElem + 1]); element.AddNode(model.NodesDictionary[iElem + 2]); // Add Hexa element to the element and subdomains dictionary of the model model.ElementsDictionary.Add(element.ID, element); } // Needed in order to make all the required data structures model.ConnectDataStructures(); // Setup var linearSystem = new SkylineLinearSystem(model.Forces); var solver = new SolverSkyline(linearSystem); var provider = new ProblemStructural(model); var childAnalyzer = new LinearAnalyzer(solver); var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Tests if calculated solution meets expected var expectedSolution = new double[] { 0, 9.80905689841542, 0.17656302417147754, 0, 31.388982074929341, 0.23541736556197002 }; for (int i = 0; i < expectedSolution.Length; i++) { Assert.Equal(expectedSolution[i], linearSystem.Solution[i], 12); } }
private static Vector RunAnalysis(Model model) { // Setup analysis var linearSystem = new SkylineLinearSystem(model.Forces); var solver = new SolverSkyline(linearSystem); var provider = new ProblemStructural(model); var childAnalyzer = new LinearAnalyzer(solver); var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); return(linearSystem.Solution); }
private void TestCollocationPointCreation() { var model = new CollocationModel(); ModelCreator modelCreator = new ModelCreator(model); string filename = "..\\..\\..\\InputFiles\\PlateWithHole.txt"; IsogeometricReader modelReader = new IsogeometricReader(modelCreator, filename); modelReader.CreateCollocationModelFromFile(); //var solverBuilder = new SuiteSparseSolver.Builder(); //solverBuilder.DofOrderer = new DofOrderer( // new NodeMajorDofOrderingStrategy(), new NullReordering()); var solverBuilder = new GmresSolver.Builder(); ISolver solver = new GmresSolver(model, new AsymmetricDofOrderer(new RowDofOrderingStrategy()), new DofOrderer(new NodeMajorDofOrderingStrategy(), new NullReordering())); // Structural problem provider var provider = new ProblemStructural(model, solver); // Linear static analysis var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.BuildMatrices(); var k = solver.LinearSystems[0].Matrix; Matrix <double> kmatlab = MathNet.Numerics.LinearAlgebra.CreateMatrix.Dense <double>(k.NumRows, k.NumColumns); for (int i = 0; i < k.NumRows; i++) { for (int j = 0; j < k.NumColumns; j++) { kmatlab[i, j] = k[i, j]; } } MatlabWriter.Write("..\\..\\..\\InputFiles\\KcolMsolve.mat", kmatlab, "Ktotal"); }
public void CollocationPoint3DMatrix() { var model = new CollocationModel(); ModelCreator modelCreator = new ModelCreator(model); string filename = "..\\..\\..\\InputFiles\\Collocation 3D.txt"; IsogeometricReader modelReader = new IsogeometricReader(modelCreator, filename); modelReader.CreateCollocationModelFromFile(); var gmresBuilder = new GmresSolver.Builder(); ISolver solver = gmresBuilder.BuildSolver(model); // Structural problem provider var provider = new ProblemStructural(model, solver); // Linear static analysis var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); // Run the analysis parentAnalyzer.Initialize(); parentAnalyzer.BuildMatrices(); var k = solver.LinearSystems[0].Matrix; Matrix <double> stiffnessMatrixExpected = MatlabReader.Read <double>("..\\..\\..\\InputFiles\\Kcol3D.mat", "Ktotal"); for (int i = 0; i < k.NumRows; i++) { for (int j = 0; j < k.NumColumns; j++) { Utilities.AreValuesEqual(stiffnessMatrixExpected[i, j], k[i, j], 10e-9); } } }
public void TestQuad4LinearCantileverExample() { // Model and node creation var model = new Model(); model.NodesDictionary.Add(1, new Node { ID = 1, X = 0.0, Y = 0.0, Z = 0.0 }); model.NodesDictionary.Add(2, new Node { ID = 2, X = 10.0, Y = 0.0, Z = 0.0 }); model.NodesDictionary.Add(3, new Node { ID = 3, X = 10.0, Y = 10.0, Z = 0.0 }); model.NodesDictionary.Add(4, new Node { ID = 4, X = 0.0, Y = 10.0, Z = 0.0 }); // Constrain bottom nodes of the model and add loads model.NodesDictionary[1].Constraints.AddRange(new[] { DOFType.X, DOFType.Y }); model.NodesDictionary[4].Constraints.AddRange(new[] { DOFType.X, DOFType.Y }); model.Loads.Add(new Load() { Amount = 500, Node = model.NodesDictionary[2], DOF = DOFType.X }); model.Loads.Add(new Load() { Amount = 500, Node = model.NodesDictionary[3], DOF = DOFType.X }); // Create Quad4 element and its material var material = new ElasticMaterial2D(StressState2D.PlaneStress) { YoungModulus = 3.76, PoissonRatio = 0.3779 }; var quad = new Quad4(material) { Thickness = 1 }; // Create the element connectivity var element = new Element() { ID = 1, ElementType = quad }; element.AddNode(model.NodesDictionary[1]); element.AddNode(model.NodesDictionary[2]); element.AddNode(model.NodesDictionary[3]); element.AddNode(model.NodesDictionary[4]); // Add quad element to the element and subdomains dictionary of the model model.ElementsDictionary.Add(element.ID, element); model.ConnectDataStructures(); // Setup var linearSystem = new SkylineLinearSystem(model.Forces); var solver = new SolverSkyline(linearSystem); var provider = new ProblemStructural(model); var childAnalyzer = new LinearAnalyzer(solver); var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); var expectedSolution = new double[] { 253.13237596153559, 66.567582057178811, 253.13237596153553, -66.567582057178811 }; for (int i = 0; i < expectedSolution.Length; i++) { Assert.Equal(expectedSolution[i], linearSystem.Solution[i], 12); } }
public static void WriteStiffnessOfContinuum3DStructure() { // _____ ____ // / / /| // /____/____/ | // | | | | // |____|____|/| // | | | / // |____|____|/ // // Model with 1 subdomain var model = new Model(); model.SubdomainsDictionary.Add(subdomainID, new Subdomain(subdomainID)); // Material var material = new ElasticMaterial3D() { YoungModulus = 2.1E7, PoissonRatio = 0.3 }; var dynamicProperties = new DynamicMaterial(1.0, 0.0, 0.0, true); // Generate mesh double lengthX = 2.0; double lengthY = 2.4; double lengthZ = 2.2; var meshGenerator = new UniformMeshGenerator3D <Node>(0.0, 0.0, 0.0, lengthX, lengthY, lengthZ, 10, 10, 10); (IReadOnlyList <Node> vertices, IReadOnlyList <CellConnectivity <Node> > cells) = meshGenerator.CreateMesh((id, x, y, z) => new Node(id: id, x: x, y: y, z: z)); // Add nodes to the model for (int n = 0; n < vertices.Count; ++n) { model.NodesDictionary.Add(n, vertices[n]); } // Add Quad4 elements to the model var factory = new ContinuumElement3DFactory(material, dynamicProperties); for (int e = 0; e < cells.Count; ++e) { ContinuumElement3D element = factory.CreateElement(cells[e].CellType, cells[e].Vertices); var elementWrapper = new Element() { ID = e, ElementType = element }; foreach (Node node in element.Nodes) { elementWrapper.AddNode(node); } model.ElementsDictionary.Add(e, elementWrapper); model.SubdomainsDictionary[subdomainID].Elements.Add(elementWrapper); } // Solver var solverBuilder = new SkylineSolver.Builder(); SkylineSolver solver = solverBuilder.BuildSolver(model); // Structural problem provider var provider = new ProblemStructural(model, solver); // Linear static analysis var childAnalyzer = new LinearAnalyzer(model, solver, provider); var parentAnalyzer = new StaticAnalyzer(model, solver, provider, childAnalyzer); // Run the analysis to build the stiffness matrix parentAnalyzer.Initialize(); parentAnalyzer.BuildMatrices(); // Print the stiffness matrix //var writer = new MatlabWriter(); var writer = new RawArraysWriter(); writer.WriteToMultipleFiles((SkylineMatrix)solver.LinearSystems[subdomainID].Matrix, outputDirectory + @"\hexa8_10x10x10_stiffness.txt"); }
private static void TestLinearTrussExample() { // Model and node creation Model model = new Model(); model.NodesDictionary.Add(1, new Node { ID = 1, X = 0, Y = 0 }); model.NodesDictionary.Add(2, new Node { ID = 2, X = 0, Y = 40 }); model.NodesDictionary.Add(3, new Node { ID = 3, X = 40, Y = 40 }); // Constrain bottom nodes of the model and add loads model.NodesDictionary[1].Constraints.AddRange(new[] { DOFType.X, DOFType.Y }); model.NodesDictionary[2].Constraints.AddRange(new[] { DOFType.X, DOFType.Y }); model.Loads.Add(new Load() { Amount = 500, Node = model.NodesDictionary[3], DOF = DOFType.X }); model.Loads.Add(new Load() { Amount = 300, Node = model.NodesDictionary[3], DOF = DOFType.Y }); var element1 = new Truss2D(1e7) { ID = 1, Density = 1, SectionArea = 1.5 }; element1.ElementType = element1; var element2 = new Truss2D(1e7) { ID = 2, Density = 1, SectionArea = 1.5 }; element2.ElementType = element2; element1.AddNode(model.NodesDictionary[1]); element1.AddNode(model.NodesDictionary[3]); element2.AddNode(model.NodesDictionary[2]); element2.AddNode(model.NodesDictionary[3]); model.ElementsDictionary.Add(element1.ID, element1); model.ElementsDictionary.Add(element2.ID, element2); model.ConnectDataStructures(); // Setup var linearSystem = new SkylineLinearSystem(model.Forces); var solver = new SolverSkyline(linearSystem); var provider = new ProblemStructural(model); var childAnalyzer = new LinearAnalyzer(solver); var parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, linearSystem); parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); Assert.Equal(0.00053333333333333336, linearSystem.Solution[0], 10); Assert.Equal(0.0017294083664636196, linearSystem.Solution[1], 10); }
static void Main(string[] args) { VectorExtensions.AssignTotalAffinityCount(); double youngModulus = 200.0e06; double poissonRatio = 0.3; double nodalLoad = 25.0; // Create a new elastic 3D material ElasticMaterial3D material = new ElasticMaterial3D() { 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(1, new Subdomain() { ID = 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]); } // Constraint bottom nodes of the model model.NodesDictionary[1].Constraints.Add(DOFType.X); model.NodesDictionary[1].Constraints.Add(DOFType.Y); model.NodesDictionary[1].Constraints.Add(DOFType.Z); model.NodesDictionary[2].Constraints.Add(DOFType.X); model.NodesDictionary[2].Constraints.Add(DOFType.Y); model.NodesDictionary[2].Constraints.Add(DOFType.Z); model.NodesDictionary[3].Constraints.Add(DOFType.X); model.NodesDictionary[3].Constraints.Add(DOFType.Y); model.NodesDictionary[3].Constraints.Add(DOFType.Z); model.NodesDictionary[4].Constraints.Add(DOFType.X); model.NodesDictionary[4].Constraints.Add(DOFType.Y); model.NodesDictionary[4].Constraints.Add(DOFType.Z); // Create a new Hexa8 element var element = new Element() { ID = 1, ElementType = new Hexa8(material) }; // Add nodes to the created element element.AddNode(model.NodesDictionary[1]); element.AddNode(model.NodesDictionary[2]); element.AddNode(model.NodesDictionary[3]); element.AddNode(model.NodesDictionary[4]); element.AddNode(model.NodesDictionary[5]); element.AddNode(model.NodesDictionary[6]); element.AddNode(model.NodesDictionary[7]); element.AddNode(model.NodesDictionary[8]); // Add Hexa element to the element and subdomains dictionary of the model model.ElementsDictionary.Add(element.ID, element); model.SubdomainsDictionary[1].ElementsDictionary.Add(element.ID, element); // Add nodal load values at the top nodes of the model model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[5], DOF = DOFType.Z }); model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[6], DOF = DOFType.Z }); model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[7], DOF = DOFType.Z }); model.Loads.Add(new Load() { Amount = -nodalLoad, Node = model.NodesDictionary[8], DOF = DOFType.Z }); // Needed in order to make all the required data structures model.ConnectDataStructures(); // Choose linear equation system solver SolverSkyline solver = new SolverSkyline(model); // Choose the provider of the problem -> here a structural problem ProblemStructural provider = new ProblemStructural(model, solver.SubdomainsDictionary); // Choose parent and child analyzers -> Parent: Static, Child: Linear Analyzers.LinearAnalyzer childAnalyzer = new LinearAnalyzer(solver, solver.SubdomainsDictionary); StaticAnalyzer parentAnalyzer = new StaticAnalyzer(provider, childAnalyzer, solver.SubdomainsDictionary); // Choose dof types X, Y, Z to log for node 5 childAnalyzer.LogFactories[1] = new LinearAnalyzerLogFactory(new int[] { model.NodalDOFsDictionary[5][DOFType.X], model.NodalDOFsDictionary[5][DOFType.Y], model.NodalDOFsDictionary[5][DOFType.Z] }); // Analyze the problem parentAnalyzer.BuildMatrices(); parentAnalyzer.Initialize(); parentAnalyzer.Solve(); // Write results to console Console.WriteLine("Writing results for node 5"); Console.WriteLine("Dof and Values for Displacement X, Y, Z"); Console.WriteLine(childAnalyzer.Logs[1][0]); }