TPZGeoMesh *MalhaCubo() { int numnodes=-1; int numelements=-1; string FileName, dirname = PZSOURCEDIR; FileName = dirname + "/Projects/Substruct_Viscoelastic/"; FileName += "cube1.txt"; { bool countnodes = false; bool countelements = false; ifstream read (FileName.c_str()); while(read) { char buf[1024]; read.getline(buf, 1024); std::string str(buf); if(str == "Coordinates") countnodes = true; if(str == "end coordinates") countnodes = false; if(countnodes) numnodes++; if(str == "Elements") countelements = true; if(str == "end elements") countelements = false; if(countelements) numelements++; } } TPZGeoMesh * gMesh = new TPZGeoMesh; gMesh -> NodeVec().Resize(numnodes); TPZManVector <int> TopolTetra(4); const int Qnodes = numnodes; TPZVec <TPZGeoNode> Node(Qnodes); //setting nodes coords int nodeId = 0, elementId = 0, matElId = 1; ifstream read; read.open(FileName.c_str()); double nodecoordX , nodecoordY , nodecoordZ ; char buf[1024]; read.getline(buf, 1024); read.getline(buf, 1024); std::string str(buf); int in; for(in=0; in<numnodes; in++) { read >> nodeId; read >> nodecoordX; read >> nodecoordY; read >> nodecoordZ; Node[nodeId-1].SetNodeId(nodeId); Node[nodeId-1].SetCoord(0,nodecoordX); Node[nodeId-1].SetCoord(1,nodecoordY); Node[nodeId-1].SetCoord(2,nodecoordZ); gMesh->NodeVec()[nodeId-1] = Node[nodeId-1]; } { read.close(); read.open(FileName.c_str()); int l , m = numnodes+5; for(l=0; l<m; l++) { read.getline(buf, 1024); } int el; int neumann1 = -4, neumann2 = -5; //std::set<int> ncoordz; //jeitoCaju for(el=0; el<numelements; el++) { read >> elementId; read >> TopolTetra[0]; //node 1 read >> TopolTetra[1]; //node 2 read >> TopolTetra[2]; //node 3 read >> TopolTetra[3]; //node 4 // O GID comeca com 1 na contagem dos nodes, e nao zero como no PZ, assim o node 1 na verdade é o node 0 TopolTetra[0]--; TopolTetra[1]--; TopolTetra[2]--; TopolTetra[3]--; int index = el; TPZGeoEl * tetra = new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (index, TopolTetra, matElId, *gMesh); } gMesh->BuildConnectivity(); // Colocando as condicoes de contorno for(el=0; el<numelements; el++) { TPZManVector <TPZGeoNode,4> Nodefinder(4); TPZManVector <REAL,3> nodecoord(3); TPZGeoEl *tetra = gMesh->ElementVec()[el]; // na face x = 1 TPZVec<int> ncoordzVec(0); int sizeOfVec = 0; for (int i = 0; i < 4; i++) { int pos = tetra->NodeIndex(i); Nodefinder[i] = gMesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (nodecoord[0] == 1.) { sizeOfVec++; ncoordzVec.Resize(sizeOfVec); ncoordzVec[sizeOfVec-1] = pos; } } if(ncoordzVec.NElements() == 3) { int lado = tetra->WhichSide(ncoordzVec); TPZGeoElSide tetraSide(tetra, lado); TPZGeoElBC(tetraSide,neumann1); } // Na face x = -1 ncoordzVec.Resize(0); sizeOfVec = 0; for (int i = 0; i < 4; i++) { int pos = tetra->NodeIndex(i); Nodefinder[i] = gMesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (nodecoord[0] == -1.) { sizeOfVec++; ncoordzVec.Resize(sizeOfVec); ncoordzVec[sizeOfVec-1] = pos; } } if(ncoordzVec.NElements() == 3) { int lado = tetra->WhichSide(ncoordzVec); TPZGeoElSide tetraSide(tetra, lado); TPZGeoElBC(tetraSide,neumann2); } } TPZVec <REAL> xyz(3,-1.), yz(3,-1.), z(3,1.); yz[0] = 1.; z[2] = -1; int bcidxyz = -1, bcidyz = -2, bcidz = -3; SetPointBC(gMesh, xyz, bcidxyz); SetPointBC(gMesh, yz, bcidyz); SetPointBC(gMesh, z, bcidz); } ofstream arg("malhaPZ1BC.txt"); gMesh->Print(arg); std::ofstream out("Cube.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gMesh, out, true); return gMesh; }
TPZGeoMesh *PyramidalMesh::CreateGMeshCubeWithPyramids(int64_t nelem, int MaterialId) { TPZGeoMesh *gmesh = new TPZGeoMesh; GenerateNodesforPyramidalMesh(gmesh,nelem); int posicao = 0; for (int64_t i=0; i<=nelem; i++) { for (int64_t j=0; j<=nelem; j++) { for (int64_t k=0; k<=nelem; k++) { posicao = i*(nelem+1)*(nelem+1)+j*(nelem+1)+k; } } } for (int64_t i=0; i<nelem; i++) { for (int64_t j=0; j<nelem; j++) { for (int64_t k=0; k<nelem; k++) { TPZManVector<int64_t,9> nodes(9,0); nodes[0] = k*(nelem+1)*(nelem+1)+j*(nelem+1)+i; nodes[1] = k*(nelem+1)*(nelem+1)+j*(nelem+1)+i+1; nodes[2] = k*(nelem+1)*(nelem+1)+(j+1)*(nelem+1)+i+1; nodes[3] = k*(nelem+1)*(nelem+1)+(j+1)*(nelem+1)+i; nodes[4] = (k+1)*(nelem+1)*(nelem+1)+j*(nelem+1)+i; nodes[5] = (k+1)*(nelem+1)*(nelem+1)+j*(nelem+1)+i+1; nodes[6] = (k+1)*(nelem+1)*(nelem+1)+(j+1)*(nelem+1)+i+1; nodes[7] = (k+1)*(nelem+1)*(nelem+1)+(j+1)*(nelem+1)+i; nodes[8] = posicao + (k)*(nelem)*(nelem)+(j)*(nelem)+i+1; for (int el=0; el<6; el++) { TPZManVector<int64_t,5> elnodes(5); int64_t index; for (int il=0; il<5; il++) { elnodes[il] = nodes[piramide_2[el][il]]; } gmesh->CreateGeoElement(EPiramide, elnodes, MaterialId, index); } } } } gmesh->BuildConnectivity(); // Boundary Conditions const int numelements = gmesh->NElements(); // const int bczMinus = -3, bczplus = -2, bcids = -1; // const int bczMinus = -1, bczplus = -1, bcids = -1; for(int el=0; el<numelements; el++) { TPZManVector <TPZGeoNode,5> Nodefinder(5); TPZManVector <REAL,3> nodecoord(3); TPZGeoEl *piramide = gmesh->ElementVec()[el]; TPZVec<int64_t> ncoordVec(0); int64_t sizeOfVec = 0; // na face z = 0 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[2],0.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc0); } ncoordVec.clear(); sizeOfVec = 0; // na face y = 0 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[1],0.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc1); } ncoordVec.clear(); sizeOfVec = 0; // na face x = 1 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[0],1.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc2); } ncoordVec.clear(); sizeOfVec = 0; // na face y = 1 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[1],1.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc3); } ncoordVec.clear(); sizeOfVec = 0; // na face x = 0 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[0],0.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc4); } ncoordVec.clear(); sizeOfVec = 0; // na face z = 1 for (int i = 0; i < 5; i++) { int64_t pos = piramide->NodeIndex(i); Nodefinder[i] = gmesh->NodeVec()[pos]; Nodefinder[i].GetCoordinates(nodecoord); if (DoubleComparer(nodecoord[2],1.)) { sizeOfVec++; ncoordVec.Resize(sizeOfVec); ncoordVec[sizeOfVec-1] = pos; } } if(ncoordVec.NElements() == 4) { int lado = piramide->WhichSide(ncoordVec); TPZGeoElSide piramideSide(piramide, lado); TPZGeoElBC(piramideSide,bc5); } } std::ofstream out("CubeWithPyramidswithBcs.vtk"); TPZVTKGeoMesh::PrintGMeshVTK(gmesh, out, true); return gmesh; }