private static void BuildCantileverModel(Model model, double load_value) { //xrhsimopoiithike to Hexa8NonLinearCantileverDefGrad // allagh tou material IContinuumMaterial3DDefGrad material1 = new HyperElasticMaterial3DDefGrad() { C1 = 0.035, C2 = 0.057, k_cons = 1 }; double[,] nodeData = new double[, ] { { 1, -1, -1 }, { 1, 1, -1 }, { 1, -1, 1 }, { 1, 1, 1 }, { -1, -1, -1 }, { -1, 1, -1 }, { -1, -1, 1 }, { -1, 1, 1 } }; int[,] elementData = new int[, ] { { 1, 4, 8, 7, 3, 2, 6, 5, 1 }, { 2, 12, 11, 9, 10, 8, 7, 5, 6 } }; // the last line will not be used. We assign only one element // orismos shmeiwn for (int nNode = 0; nNode < nodeData.GetLength(0); nNode++) { model.NodesDictionary.Add(nNode + 1, new Node(id: nNode + 1, x: nodeData[nNode, 0], y: nodeData[nNode, 1], z: nodeData[nNode, 2])); } // orismos elements Element e1; int subdomainID = 1; for (int nElement = 0; nElement < elementData.GetLength(0) - 1; nElement++) { e1 = new Element() { ID = nElement + 1, ElementType = new Hexa8NonLinearDefGrad(material1, GaussLegendre3D.GetQuadratureWithOrder(3, 3, 3)) // dixws to e. exoume sfalma enw sto beambuilding oxi//edw kaleitai me ena orisma to Hexa8 }; for (int j = 0; j < 8; j++) { e1.NodesDictionary.Add(elementData[nElement, j + 1], model.NodesDictionary[elementData[nElement, j + 1]]); } model.ElementsDictionary.Add(e1.ID, e1); model.SubdomainsDictionary[subdomainID].Elements.Add(e1); } // constraint to to deftero miso apo th list twn nodes foreach (int k in new int[] { 5, 6, 7, 8 }) { model.NodesDictionary[k].Constraints.Add(new Constraint() { Amount = 0, DOF = StructuralDof.TranslationX }); model.NodesDictionary[k].Constraints.Add(new Constraint() { Amount = 0, DOF = StructuralDof.TranslationY }); model.NodesDictionary[k].Constraints.Add(new Constraint() { Amount = 0, DOF = StructuralDof.TranslationZ }); } // fortish korufhs Load load1; for (int k = 4; k < 5; k++) { load1 = new Load() { Node = model.NodesDictionary[k], DOF = StructuralDof.TranslationZ, Amount = 1 * load_value }; model.Loads.Add(load1); } }
public Model CreateModelFromFile() { var model = new Model(); model.SubdomainsDictionary[0] = new Subdomain(0); // Material char[] delimeters = { ' ', '=', '\t' }; Attributes?name = null; String[] text = System.IO.File.ReadAllLines(Filename); elementBoundaries = new List <IList <Element> >(); elementDomains = new List <IList <Element> >(); nodeDomains = new List <IList <Node> >(); nodeBoundaries = new List <IList <Node> >(); quadBoundaries = new List <IList <IList <Node> > >(); triBoundaries = new List <IList <IList <Node> > >(); for (int i = 0; i < 10; i++) { elementBoundaries.Add(new List <Element>()); nodeBoundaries.Add(new List <Node>()); quadBoundaries.Add(new List <IList <Node> >()); triBoundaries.Add(new List <IList <Node> >()); } for (int i = 0; i < 2; i++) { elementDomains.Add(new List <Element>()); nodeDomains.Add(new List <Node>()); } for (int i = 0; i < text.Length; i++) { String[] line = text[i].Split(delimeters, StringSplitOptions.RemoveEmptyEntries); StringBuilder comparisonString = new StringBuilder(null, 50); if (line.Length == 0) { continue; } if ((line[0] == "3" || line[0] == "4") && line.Length > 1) { try { name = (Attributes)Enum.Parse(typeof(Attributes), line[1]); } catch (Exception exception) { name = null; } } else { for (int linePosition = 0; linePosition < line.Length; linePosition++) { if (line[linePosition] == "#") { for (int ij = linePosition + 1; ij < line.Length; ij++) { comparisonString.Append(line[ij]); } try { name = (Attributes)Enum.Parse(typeof(Attributes), comparisonString.ToString()); } catch (Exception exception) { name = null; } } } } switch (name) { case Attributes.sdim: int NumberOfDimensions = Int32.Parse(line[0]); break; case Attributes.numberofmeshpoints: NumberOfNodes = Int32.Parse(line[0]); break; case Attributes.Meshpointcoordinates: IList <Node> nodelist = new List <Node> { null }; for (int j = 0; j < NumberOfNodes; j++) { i++; line = text[i].Split(delimeters); int nodeGlobalID = j; double x = Double.Parse(line[0], CultureInfo.InvariantCulture); double y = Double.Parse(line[1], CultureInfo.InvariantCulture); double z = Double.Parse(line[2], CultureInfo.InvariantCulture); Node node = new Node(nodeGlobalID, x, y, z); model.NodesDictionary.Add(nodeGlobalID, node); nodelist.Add(node); } break; case Attributes.tri: do { i++; line = text[i].Split(delimeters); } while (line[0] == ""); i++; line = text[i].Split(delimeters); NumberOfTriElements = Int32.Parse(line[0]); i++; IList <IList <Node> > triNodesCollection = new List <IList <Node> >(); for (int TriID = 0; TriID < NumberOfTriElements; TriID++) { i++; line = text[i].Split(delimeters); triNodesCollection.Add(new List <Node> { model.NodesDictionary[Int32.Parse(line[2])], model.NodesDictionary[Int32.Parse(line[1])], model.NodesDictionary[Int32.Parse(line[0])] }); } i = i + 3; for (int TriID = 0; TriID < NumberOfTriElements; TriID++) { i++; line = text[i].Split(delimeters); int boundaryID = Int32.Parse(line[0]); triBoundaries[boundaryID].Add(triNodesCollection[TriID]); foreach (Node node in triNodesCollection[TriID]) { nodeBoundaries[boundaryID].Add(node); } //int elementBoundaryID = Int32.Parse(line[0]); //elementBoundaries[elementBoundaryID].Add(model.ElementsDictionary[QuadID]); } for (int boundaryID = 0; boundaryID < nodeBoundaries.Count; boundaryID++) { nodeBoundaries[boundaryID] = nodeBoundaries[boundaryID].Distinct().ToList(); } break; case Attributes.quad: do { i++; line = text[i].Split(delimeters); } while (line[0] == ""); i++; line = text[i].Split(delimeters); NumberOfQuadElements = Int32.Parse(line[0]); i++; IList <IList <Node> > quadNodesCollection = new List <IList <Node> >(); for (int QuadID = 0; QuadID < NumberOfQuadElements; QuadID++) { i++; line = text[i].Split(delimeters); //IReadOnlyList<Node> nodes = new List<Node> //{ // model.NodesDictionary[Int32.Parse(line[1])], //0 // model.NodesDictionary[Int32.Parse(line[3])], //1 // model.NodesDictionary[Int32.Parse(line[2])], //2 // model.NodesDictionary[Int32.Parse(line[0])] //3 //}; quadNodesCollection.Add(new List <Node> { model.NodesDictionary[Int32.Parse(line[1])], //0 model.NodesDictionary[Int32.Parse(line[3])], //1 model.NodesDictionary[Int32.Parse(line[2])], //2 model.NodesDictionary[Int32.Parse(line[0])] //3 }); //var Quad4 = boundaryFactory3D.CreateElement(CellType.Quad4, nodes); //var element = new Element(); //element.ID = QuadID; //element.ElementType = Quad4; //model.SubdomainsDictionary[0].Elements.Add(element); //model.ElementsDictionary.Add(QuadID, element); //foreach (Node node in nodes) //{ // element.AddNode(node); //} } i = i + 3; for (int QuadID = 0; QuadID < NumberOfQuadElements; QuadID++) { i++; line = text[i].Split(delimeters); int boundaryID = Int32.Parse(line[0]); quadBoundaries[boundaryID].Add(quadNodesCollection[QuadID]); foreach (Node node in quadNodesCollection[QuadID]) { nodeBoundaries[boundaryID].Add(node); } //int elementBoundaryID = Int32.Parse(line[0]); //elementBoundaries[elementBoundaryID].Add(model.ElementsDictionary[QuadID]); } for (int boundaryID = 0; boundaryID < nodeBoundaries.Count; boundaryID++) { nodeBoundaries[boundaryID] = nodeBoundaries[boundaryID].Distinct().ToList(); } break; case Attributes.tet: do { i++; line = text[i].Split(delimeters); } while (line[0] == ""); i++; line = text[i].Split(delimeters); NumberOfTetElements = Int32.Parse(line[0]); i++; List <IReadOnlyList <Node> > TetraNodes = new List <IReadOnlyList <Node> >(); for (int TetID = 0; TetID < NumberOfTetElements; TetID++) { i++; line = text[i].Split(delimeters); TetraNodes.Add(new List <Node> { model.NodesDictionary[Int32.Parse(line[3])], model.NodesDictionary[Int32.Parse(line[2])], model.NodesDictionary[Int32.Parse(line[1])], model.NodesDictionary[Int32.Parse(line[0])] }); } i = i + 3; for (int TetID = 0; TetID < NumberOfTetElements; TetID++) { i++; line = text[i].Split(delimeters); int elementDomainID = Int32.Parse(line[0]); HyperElasticMaterial3DDefGrad hyperElasticMaterial = new HyperElasticMaterial3DDefGrad() { C1 = C1[elementDomainID - 1], C2 = C2[elementDomainID - 1], k_cons = k_cons[elementDomainID - 1] }; ContinuumElement3DNonLinearDefGradFactory elementFactory; if (lambdag == null) { elementFactory = new ContinuumElement3DNonLinearDefGradFactory(hyperElasticMaterial, CommonDynamicProperties[elementDomainID - 1]); } else { elementFactory = new ContinuumElement3DNonLinearDefGradFactory(hyperElasticMaterial, CommonDynamicProperties[elementDomainID - 1], lambdag[TetID]); } IReadOnlyList <Node> nodesTet = TetraNodes[TetID]; var Tet4 = elementFactory.CreateElement(CellType.Tet4, nodesTet); var element = new Element(); element.ID = TetID; element.ElementType = Tet4; foreach (Node node in nodesTet) { element.AddNode(node); nodeDomains[elementDomainID - 1].Add(node); } model.SubdomainsDictionary[0].Elements.Add(element); model.ElementsDictionary.Add(TetID, element); elementDomains[elementDomainID - 1].Add(model.ElementsDictionary[TetID]); //int elementBoundaryID = Int32.Parse(line[0]); //elementBoundaries[elementBoundaryID].Add(model.ElementsDictionary[QuadID]); } for (int elementDomainID = 0; elementDomainID < elementDomains.Count; elementDomainID++) { nodeDomains[elementDomainID] = nodeDomains[elementDomainID].Distinct().ToList(); } break; case Attributes.hex: do { i++; line = text[i].Split(delimeters); } while (line[0] == ""); i++; line = text[i].Split(delimeters); NumberOfHexElements = Int32.Parse(line[0]); i++; List <IReadOnlyList <Node> > HexaNodes = new List <IReadOnlyList <Node> >(); for (int HexID = 0; HexID < NumberOfHexElements; HexID++) { i++; line = text[i].Split(delimeters); HexaNodes.Add(new List <Node> { model.NodesDictionary[Int32.Parse(line[4])], model.NodesDictionary[Int32.Parse(line[6])], model.NodesDictionary[Int32.Parse(line[7])], model.NodesDictionary[Int32.Parse(line[5])], model.NodesDictionary[Int32.Parse(line[0])], model.NodesDictionary[Int32.Parse(line[2])], model.NodesDictionary[Int32.Parse(line[3])], model.NodesDictionary[Int32.Parse(line[1])], }); } i = i + 3; for (int HexID = 0; HexID < NumberOfHexElements; HexID++) { i++; line = text[i].Split(delimeters); int elementDomainID = Int32.Parse(line[0]); HyperElasticMaterial3DDefGrad hyperElasticMaterial = new HyperElasticMaterial3DDefGrad() { C1 = C1[elementDomainID - 1], C2 = C2[elementDomainID - 1], k_cons = k_cons[elementDomainID - 1] }; ContinuumElement3DNonLinearDefGradFactory elementFactory; if (lambdag == null) { elementFactory = new ContinuumElement3DNonLinearDefGradFactory(hyperElasticMaterial, CommonDynamicProperties[elementDomainID - 1]); } else { elementFactory = new ContinuumElement3DNonLinearDefGradFactory(hyperElasticMaterial, CommonDynamicProperties[elementDomainID - 1], lambdag[HexID]); } IReadOnlyList <Node> nodesHex = HexaNodes[HexID]; var Hexa8 = elementFactory.CreateElement(CellType.Hexa8, nodesHex); var element = new Element(); element.ID = HexID; element.ElementType = Hexa8; foreach (Node node in nodesHex) { element.AddNode(node); nodeDomains[elementDomainID - 1].Add(node); } model.SubdomainsDictionary[0].Elements.Add(element); model.ElementsDictionary.Add(HexID, element); elementDomains[elementDomainID - 1].Add(model.ElementsDictionary[HexID]); } for (int elementDomainID = 0; elementDomainID < elementDomains.Count; elementDomainID++) { nodeDomains[elementDomainID] = nodeDomains[elementDomainID].Distinct().ToList(); } break; } } return(model); }
public void ContinuumElement3DNonLinearDefGradDynamicConsistent() { 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); var solidMaterial = new HyperElasticMaterial3DDefGrad() { C1 = 1, C2 = 1, k_cons = 1 }; // Create Dynamic Material var dynamicMaterial = new DynamicMaterial(density, 0, 0, true); //DefineContinuumElement3DNonLinear(model, solidMaterial, dynamicMaterial); DefineContinuumElement3DNonLinearDefGrad(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, 2) { 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 = 2.32803; Assert.Equal(expectedValue, computedValue, 2); }