Example #1
0
void TPZGeoCloneMesh::SetElements(TPZStack <TPZGeoEl *> &patch, TPZGeoEl *ref){
    
    int64_t i;
    if (!ref){
        cout << "TPZGeoCloneMesh::Error\n Reference element must not be null\n";
        DebugStop();
    }
    //fGeoRoot = ref;
    CloneElement(ref);
    fGeoRoot = fMapElements[ref];
    
    //  cout << "\n\n\nTeste\n\n\n";
    //  Print(cout);
    
    int64_t nel = patch.NElements();
    //  fReferenceElement.Resize(nel);
    for (i=0; i<nel; i++){
        if(patch[i]) {
            TPZGeoEl *gel = patch[i];
            TPZGeoEl *father = gel->Father();
            while(father) {
                gel = father;
                father = gel->Father();
            }
            //      cout << "\nElemento a ser clonado:\n";
            //      gel->Print(cout);
            CloneElement(gel);
            // verificar se neighbour.Element ja esta no map --->>>> j� � feito no CloneElement
            TPZGeoEl *localpatch = fMapElements[patch[i]];
#ifdef PZDEBUG 
			if (localpatch == 0) {
				DebugStop();
			}
#endif
            fPatchElements.insert(localpatch);
            AddBoundaryConditionElements(patch[i]);

//			cout << "Printing fPatchElements("<< i << "_NEl_" << fPatchElements.size() << ") : " << endl;
//			std::set<TPZGeoEl *>::iterator it;
//			for(it=fPatchElements.begin();it!=fPatchElements.end();it++) {
//				(*it)->Print(cout);
//			}
		}
    }
}
Example #2
0
// IT IS BAD !!!! IMPROVE IT !!!
void TPZGeoCloneMesh::AddBoundaryConditionElements(TPZGeoEl *eltoadd) {
    int nsides = eltoadd->NSides();
    int is;
    for(is=0; is<nsides; is++) {
        TPZGeoElSide elside(eltoadd,is);
        TPZGeoElSide neighbour = elside.Neighbour();
#ifdef PZDEBUG
        if (!neighbour.Element()) DebugStop();
#endif
        while(neighbour != elside) {
            if(neighbour.Element()->Dimension() < eltoadd->Dimension() &&
               neighbour.Side() == neighbour.Element()->NSides() - 1
               // && neighbour.Element()->Reference()
			   ) {
			   
                TPZGeoEl *gel = neighbour.Element();
                if (HasElement(gel)) {
                    neighbour = neighbour.Neighbour();
                    continue;
                }
                TPZGeoEl *father = gel->Father();
                while(father) {
                    gel = father;
                    father = gel->Father();
                }
                CloneElement(gel);
                // verificar se neighbour.Element ja esta no map
          //      TPZGeoEl *localpatch = fMapElements[neighbour.Element()];
				TPZGeoEl *localpatch = fMapElements[gel];							// Jorge 2013/03/28
                fPatchElements.insert(localpatch);
            }
            neighbour = neighbour.Neighbour();
#ifdef PZDEBUG
            if (!neighbour.Exists()) {
                DebugStop();
            }
#endif
        }
    }
}
Example #3
0
int main()
{
    TPZManVector<REAL,3> x0(3,0.),x1(3,1.);
    x1[2] = 0.;
    TPZManVector<int,2> nelx(2,4);
    nelx[0] = 8;
    TPZGenGrid gengrid(nelx,x0,x1);
    gengrid.SetElementType(ETriangle);
    TPZGeoMesh *gmesh = new TPZGeoMesh;
    gmesh->SetDimension(2);
    gengrid.Read(gmesh);
    {
        std::ofstream out("gmesh.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh, out, true);
    }
    TPZExtendGridDimension extend(gmesh,0.5);
    extend.SetElType(1);
    TPZGeoMesh *gmesh3d = extend.ExtendedMesh(4);
    {
        std::ofstream out("gmesh3d.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }
    {
        int numel = nelx[1];
        for(int el=0; el<numel; el++)
        {
            TPZManVector<int64_t, 3> nodes(2);
            nodes[0] = 2+(nelx[0]+1)*el+el;
            nodes[1] = 2+(nelx[0]+1)*(el+1)+1+el;
            int matid = 2;
            int64_t index;
            gmesh3d->CreateGeoElement(EOned, nodes, matid, index);

        }
        {
            std::ofstream out("gmesh3dbis.vtk");
            TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
        }
    }
    gmesh3d->BuildConnectivity();
    gRefDBase.InitializeRefPatterns();
    std::set<int> matids;
    matids.insert(2);
    TPZRefPatternTools::RefineDirectional(gmesh3d, matids);
    {
        std::ofstream out("gmesh3dtris.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }
    {
        int64_t nel = gmesh3d->NElements();
        for (int64_t el = 0; el<nel; el++) {
            TPZGeoEl *gel = gmesh3d->Element(el);
            if(gel->Father()) gel->SetMaterialId(3);
        }
        for (int64_t el = 0; el<nel; el++) {
            TPZGeoEl *gel = gmesh3d->Element(el);
            if(gel->Dimension() == 1)
            {
                for(int side=0; side < gel->NSides(); side++)
                {
                    TPZGeoElSide gelside(gel,side);
                    TPZGeoElSide neighbour(gelside.Neighbour());
                    while (neighbour != gelside) {
                        if(neighbour.Element()->Father())
                        {
                            neighbour.Element()->SetMaterialId(4);
                        }
                        neighbour = neighbour.Neighbour();
                    }
                }
            }
        }

    }
    {
        std::ofstream out("gmesh3dtris.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }

    return 0;
}
Example #4
0
int TPZGeoCloneMesh::main(){
	cout << "**************************************" << endl;
  	cout << "****** Getting Patchs!************" << endl;
	cout << "**************************************" << endl;
    
    /*******************************************************
     * Constru��o da malha
     * *****************************************************/
  	//malha quadrada de nr x nc
	const int numrel = 3;
  	const int numcel = 3;
//  	int numel = numrel*numcel;
  	TPZVec<REAL> coord(2,0.);
    
  	// criar um objeto tipo malha geometrica
  	TPZGeoMesh geomesh;
    
  	// criar nos
  	int i,j;
  	for(i=0; i<(numrel+1); i++) {
        for (j=0; j<(numcel+1); j++) {
            int64_t nodind = geomesh.NodeVec().AllocateNewElement();
            TPZVec<REAL> coord(2);
            coord[0] = j;//co[nod][0];
            coord[1] = i;//co[nod][1];
            geomesh.NodeVec()[nodind] = TPZGeoNode(i*(numrel+1)+j,coord,geomesh);
        }
  	}
  	// cria��o dos elementos
  	int elc, elr;
  	TPZGeoEl *gel[numrel*numcel];
  	TPZVec<int64_t> indices(4);
  	for(elr=0; elr<numrel; elr++) {  
        for(elc=0; elc<numcel; elc++) {
            indices[0] = (numrel+1)*elr+elc;
            indices[1] = indices[0]+1;
            indices[3] = indices[0]+numrel+1;
            indices[2] = indices[1]+numrel+1;
            // O proprio construtor vai inserir o elemento na malha
			int64_t index;
			gel[elr*numrel+elc] = geomesh.CreateGeoElement(EQuadrilateral,indices,1,index);
            //gel[elr*numrel+elc] = new TPZGeoElQ2d(elr*numrel+elc,indices,1,geomesh);
        }
  	}
	//Divis�o dos elementos
  	TPZVec<TPZGeoEl *> sub;
  	gel[0]->Divide(sub);
    //  	gel[1]->Divide(sub);
    //  	gel[3]->Divide(sub); 
  	ofstream output("patches.dat");
  	geomesh.Print(output);
    //  	TPZGeoElBC t3(gel[0],4,-1,geomesh); 
    //  	TPZGeoElBC t4(gel[numel-1],6,-2,geomesh); 
  	geomesh.Print(output);
	geomesh.BuildConnectivity();
    std::set <TPZGeoEl *> patch;
    
	
  	TPZCompMesh *comp = new TPZCompMesh(&geomesh);
 	// inserir os materiais
  	TPZMaterial *meumat = new TPZElasticityMaterial(1,1.e5,0.2,0,0);
  	comp->InsertMaterialObject(meumat);
  	// inserir a condicao de contorno
    //  	TPZFMatrix val1(3,3,0.),val2(3,1,0.);
    //  	TPZMaterial *bnd = meumat->CreateBC (-1,0,val1,val2);
    //  	comp->InsertMaterialObject(bnd);
    //  	TPZFMatrix val3(3,3,1);
    // 	bnd = meumat->CreateBC (-2,1,val3,val2);
    //  	comp->InsertMaterialObject(bnd);
	comp->AutoBuild();
	comp->Print(output);
  	output.flush();
    
    /**********************************************************************
     * Cria��o de uma malha computacional clone
     * ********************************************************************/
 	comp->GetRefPatches(patch);
	
	geomesh.ResetReference();
	TPZStack <int64_t> patchel;
	TPZStack <TPZGeoEl *> toclonegel;
	TPZStack <int64_t> patchindex;
	TPZVec<int64_t> n2elgraph;
	TPZVec<int64_t> n2elgraphid;
	TPZStack<int64_t> elgraph;
	TPZVec<int64_t> elgraphindex;
	int64_t k;
	TPZCompMesh *clonecmesh = new TPZCompMesh(&geomesh);
	cout << "Check 1: number of reference elements for patch before createcompel: " << patch.size() << endl;
    std::set<TPZGeoEl *>::iterator it;
    for (it=patch.begin(); it!=patch.end(); it++)
    {
		//patch[i]->Print(cout);
        int64_t index;
        TPZGeoEl *gel = *it;
        clonecmesh->CreateCompEl(gel, index);
        //		patch[i]->CreateCompEl(*clonecmesh,i);
	}
    //	cout << "Check 2: number of reference elements for patch after createcompel: " << patch.NElements() << endl;
	clonecmesh->CleanUpUnconnectedNodes();
    //	clonecmesh->Print(cout);
	clonecmesh->GetNodeToElGraph(n2elgraph,n2elgraphid,elgraph,elgraphindex);
	int64_t clnel = clonecmesh->NElements();
    //	cout << "Number of elements in clonemessh: " << clnel << endl;
	//o primeiro patch come�a em zero
	patchindex.Push(0);
	for (i=0; i<clnel; i++){
		//cout << endl << endl << "Evaluating patch for element: " << i << endl;
		clonecmesh->GetElementPatch(n2elgraph,n2elgraphid,elgraph,elgraphindex,i,patchel);
		cout << "Patch elements: " << patchel.NElements() << endl;
		/*for (k=0;k<patchel.NElements();k++){
         clonecmesh->ElementVec()[patchel[k]]->Reference()->Print();
         cout << endl;
         }*/
		for (j=0; j<patchel.NElements(); j++){
			//obten��o do elemento geom�trico do patch
			//cout << "Creating geometric clone elements for computational element :" << j << endl;
			TPZGeoEl *gel = clonecmesh->ElementVec()[patchel[j]]->Reference();
			//gel->Print(cout);
			//inserir todos os pais do elemento geom�trico do patch
			int64_t count = 0;
			//cout << "Inserting father element:" << "\t"; 
			while(gel){	
				TPZGeoEl *father = gel->Father();
				if (father){
					//father->Print(cout);
					gel = father;
					continue;
				}
				else toclonegel.Push(gel);
				gel = father;
				//cout <<  count << "\t";
				count ++;
			}
			//cout << endl;
		}
		int64_t sum = toclonegel.NElements()-1;
		//cout << endl << sum << endl;
		patchindex.Push(sum);
        
		/*for (k=patchindex[i];k<patchindex[i+1];k++){
         toclonegel[k]->Print();
         }*/
	}
    
    
	cout <<endl;
	cout << endl;
	
	TPZGeoCloneMesh geoclone(&geomesh);
	TPZStack<TPZGeoEl*> testpatch;
	for (j=0; j<1/*patchindex.NElements()-1*/;j++){
		cout << "\n\n\nClone do Patch do elemento: " << j <<endl;
		k=0;
		cout << patchindex[j] << "\t" << patchindex[j+1] <<endl;
		for (i=patchindex[j];i<=patchindex[j+1];i++){
			testpatch.Push(toclonegel[i]);
			toclonegel[i]->Print();
			cout << k << endl;
			k++;
		}
		geoclone.SetElements(testpatch,testpatch[patchindex[j]]);
		geoclone.Print(cout);
        
	}
	//geoclone.SetElements(testpatch);
	//geoclone.Print(cout);
	
    
    /**************************************************************************
     * Fim da cria��o do clone
     **************************************************************************/
    
    
	
    /*	output <<"Impress�o dos Pathces\nN�mero total de patches encontrados\t" << patchindex.NElements()-1 << endl;
     cout << "\n\n&&&&&&&&&&&&&&&&&&&&&&&&\n N�mero total de patches: " << patchindex.NElements()-1 << endl
     << "&&&&&&&&&&&&&&&&&&&&&&&&" << endl;
     for (i=0;i<patchindex.NElements()-1;i++){
     cout << "Patch do elemento " << i << "\t" << "N�mero de elementos componentes do patch: " << (patchindex[i+1]-patchindex[i]) << endl;
     for (j = patchindex[i]; j<patchindex[i+1]; j++){
     toclonegel[j]->Print();
     cout << "||||||||||||||||||||||||||||||||" << endl;
     }
     cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" <<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n";
     cout.flush();
     }
     */	
	comp->LoadReferences();
	
	cout.flush();
	cout << endl;
	cout.flush();
	delete comp;
	delete clonecmesh;
  	return (0);
    
}