void TPZQuadraticQuad::InsertExampleElement(TPZGeoMesh &gmesh, int matid, TPZVec<REAL> &lowercorner, TPZVec<REAL> &size) { TPZManVector<REAL,3> co(3),shift(3),scale(3); TPZManVector<int64_t,4> nodeindexes(NCornerNodes); for (int i=0; i<3; i++) { scale[i] = size[i]/3.; shift[i] = size[i]/2.+lowercorner[i]; } for (int i=0; i<NCornerNodes; i++) { ParametricDomainNodeCoord(i, co); co.Resize(3,0.); for (int j=0; j<3; j++) { co[j] = shift[j]+scale[j]*co[j]+(rand()*0.2/RAND_MAX)-0.1; } nodeindexes[i] = gmesh.NodeVec().AllocateNewElement(); gmesh.NodeVec()[nodeindexes[i]].Initialize(co, gmesh); } int64_t index; CreateGeoElement(gmesh, EQuadrilateral, nodeindexes, matid, index); TPZGeoEl *gel = gmesh.Element(index); int nsides = gel->NSides(); for (int is=0; is<nsides; is++) { gel->SetSideDefined(is); } gel = TPZChangeEl::ChangeToQuadratic(&gmesh, index); for (int node = gel->NCornerNodes(); node < gel->NNodes(); node++) { TPZManVector<REAL,3> co(3); gel->NodePtr(node)->GetCoordinates(co); for (int i=0; i<3; i++) { co[i] += (0.2*rand())/RAND_MAX - 0.1; } gel->NodePtr(node)->SetCoord(co); } }
REAL TPZAnalysisError::h_Parameter(TPZCompEl *cel) { REAL h = 0.,cicjdist; TPZGeoEl *gel = cel->Reference(); int nconn = gel->NCornerNodes(); for(int conni=0;conni<nconn;conni++) { for(int connj=conni;connj<nconn;connj++) { cicjdist = 0.; for(int coordi=0;coordi<3;coordi++) { REAL coor1 = gel->NodePtr(conni)->Coord(coordi); REAL coor2 = gel->NodePtr(connj)->Coord(coordi); cicjdist += pow( coor1 - coor2, (REAL)2.0); } cicjdist = sqrt(cicjdist); if(h < cicjdist) h = cicjdist; } } return h; }
/// Generate a boundary geometric element at the indicated node void SetPointBC(TPZGeoMesh *gr, TPZVec<REAL> &x, int bc) { // look for an element/corner node whose distance is close to start TPZGeoNode *gn1 = gr->FindNode(x); int iel; int nelem = gr->ElementVec().NElements(); TPZGeoEl *gel; for (iel = 0; iel<nelem; iel++) { gel = gr->ElementVec()[iel]; if(!gel) continue; int nc = gel->NCornerNodes(); int c; for (c=0; c<nc; c++) { TPZGeoNode *gn = gel->NodePtr(c); if (gn == gn1) { break; } } if (c<nc) { TPZGeoElBC(gel, c, bc); return; } } }
void TPZAnalysisError::MathematicaPlot() { TPZGeoMesh *gmesh = fCompMesh->Reference(); TPZAdmChunkVector<TPZGeoNode> &listnodes = gmesh->NodeVec(); int64_t nnodes = gmesh->NNodes(); TPZAdmChunkVector<TPZGeoNode> nodes(listnodes); TPZVec<int64_t> nodeindex(0); int64_t keepindex; int64_t in; TPZGeoNode *nodei = 0; /// jorge 2017 - I think it's unnecessary, because if node is created its exists always for(in=0;in<nnodes;in++) { nodei = &nodes[in]; REAL xi; if(nodei) xi = nodei->Coord(0); else continue; keepindex = in; for(int64_t jn=in;jn<nnodes;jn++) { TPZGeoNode *nodej = &nodes[jn]; REAL xj; if(nodej) xj = nodej->Coord(0); else continue; if(xj < xi) { keepindex = jn; xi = xj; } } if(keepindex!=in) { TPZGeoNode commut = nodes[in]; nodes[in] = nodes[keepindex]; nodes[keepindex] = commut; } } ofstream mesh("Malha.dat"); ofstream graph("Graphic.nb"); mesh << "\nDistribuicao de nos\n\n"; int64_t i; for(i=0;i<nnodes;i++) { nodei = &nodes[i]; if(nodei) mesh << nodei->Coord(0) << endl; } //2a parte TPZVec<int64_t> locnodid(nnodes,0); TPZVec<TPZGeoEl *> gelptr(nnodes); int64_t nel = gmesh->NElements(); int64_t count = 0; for(in=0;in<nnodes;in++) { nodei = &nodes[in]; if(!nodei) continue; for(int64_t iel=0;iel<nel;iel++) { TPZGeoEl *gel = gmesh->ElementVec()[iel]; if(!gel || !gel->Reference() || gel->MaterialId() < 0) continue; //int numnodes = gel->NNodes(); int ic=0;//for(int ic=0;ic<numnodes;ic++) if(in==nnodes-1) ic = 1; if(nodei->Id() == gel->NodePtr(ic)->Id()) { gelptr[count] = gel; locnodid[count++] = ic; break; } } } TPZVec<int64_t> connects(nnodes); int64_t iel; for(iel=0;iel<nnodes;iel++) { //if(!gelptr[iel] || !(gelptr[iel]->Reference())) continue; connects[iel] = gelptr[iel]->Reference()->ConnectIndex(locnodid[iel]); } TPZVec<STATE> sol(nnodes); for(i=0; i<nnodes; i++) { TPZConnect *df = &fCompMesh->ConnectVec()[connects[i]]; if(!df) { cout << "\nError in structure of dates\n"; mesh << "\nError in structure of dates\n"; return;//exit(-1); } int64_t seqnum = df->SequenceNumber(); int64_t pos = fCompMesh->Block().Position(seqnum); sol[i] = fCompMesh->Solution()(pos,0); } mesh << "\nSolucao nodal\n\n"; for(i=0;i<nnodes;i++) { mesh << sol[i] << endl; } // expanding solution int64_t numsols = 5*(nnodes-1)+1; // 5 values by element: 3 interpolated (interior) + 2 over corners TPZVec<STATE> expand_sol(numsols); TPZVec<REAL> expand_nodes(numsols); TPZVec<REAL> qsi(1); int64_t exp_iel = -1; for(iel=0;iel<nnodes-1;iel++) { TPZManVector<STATE> locsol(1); exp_iel++; expand_sol[exp_iel] = sol[iel]; qsi[0] = -1.; expand_nodes[exp_iel] = nodes[iel].Coord(0); REAL h = h_Parameter(gelptr[iel]->Reference()); for(int i=1;i<5;i++) { exp_iel++; expand_nodes[exp_iel] = i*h/5. + nodes[iel].Coord(0); qsi[0] += .4; gelptr[iel]->Reference()->Solution(qsi,0,locsol); expand_sol[exp_iel] = locsol[0]; } } expand_nodes[numsols-1] = nodes[nnodes-1].Coord(0); expand_sol[numsols-1] = sol[nnodes-1]; // Mathematica output format graph << "list = {" << endl; for(int64_t isol=0;isol<numsols;isol++) { if(isol > 0) graph << ","; STATE expandsol = expand_sol[isol]; if(fabs(expandsol) < 1.e-10) expandsol = 0.; graph << "{" << expand_nodes[isol] << "," << expandsol << "}"; if( !((isol+1)%5) ) graph << endl; } graph << "\n};\n"; graph << "ListPlot[list, PlotJoined->True, PlotRange->All];" << endl; }