void CESets::add_tag(const std::string &tag_name, const char *value) { iBase_TagHandle tag_handle; int err; iMesh_getTagHandle(impl_, tag_name.c_str(), &tag_handle, &err, tag_name.size()); check_error(impl_, err); add_tag(tag_handle, value); }
static dErr doGlobalID(iMesh_Instance mesh,iBase_EntitySetHandle root) { MeshListEH ents=MLZ; MeshListInt type=MLZ; int count[4] = {0,0,0,0}; int owned,*number; dMeshTag idTag; dErr err; dFunctionBegin; iMesh_getEntities(mesh,root,iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES,MLREF(ents),&err);dICHK(mesh,err); iMesh_getEntArrType(mesh,ents.v,ents.s,MLREF(type),&err);dICHK(mesh,err); err = dMalloc(ents.s*sizeof(number[0]),&number);dCHK(err); owned = ents.s; for (int i=0; i<owned; i++) { number[i] = count[type.v[i]]++; } iMesh_getTagHandle(mesh,"GLOBAL_ID",&idTag,&err,sizeof("GLOBAL_ID"));dICHK(mesh,err); iMesh_setIntArrData(mesh,ents.v,owned,idTag,number,owned,&err);dICHK(mesh,err); err = dFree(number);dCHK(err); MeshListFree(ents); MeshListFree(type); dFunctionReturn(0); }
// Generates a mesh of a brick using run-time parameters. // The new mesh populates the given root set. // This should be converted to have a useful programmatic API. dErr dMeshGenerateBlock(dMesh dmesh,dMeshESH root,PetscBool do_geom) { const char pTagName[]="OWNING_PART", pSetName[]="PARALLEL_PARTITION"; PetscBool assoc_with_brick=0,do_color_bdy=0,do_material = 1,do_uniform = 1,do_global_number = 0,do_global_id = 1; PetscBool do_partition = 1,do_pressure = 0,do_faces = 1,do_edges = 1; dReal rotate_y = 0; dInt verbose = 0; iMesh_Instance mesh; iBase_EntityHandle *entbuf; iBase_EntitySetHandle facesets[6]; iBase_TagHandle pTag; MeshListEH v=MLZ,e=MLZ,f=MLZ,r=MLZ,c=MLZ; MeshListReal x=MLZ; MeshListInt s=MLZ,part=MLZ; dInt *face[6],facecount[6]={0}; int err,i,j,k,m,n,p,M,N,P,I,J,K,order=iBase_INTERLEAVED; Box box; PetscViewer viewer; dFunctionBegin; dValidHeader(dmesh,dMESH_CLASSID,1); err = PetscViewerASCIIGetStdout(((PetscObject)dmesh)->comm,&viewer);dCHK(err); err = PetscOptionsBegin(((PetscObject)dmesh)->comm,((PetscObject)dmesh)->prefix,"dMeshGenerate Block: generate cartesian meshes",NULL);dCHK(err); { char boxstr[256] = "-1:1,-1:1,-1:1",mnp[256] = "5,5,5",MNP[256] = "2,2,2"; err = PetscOptionsInt("-dmeshgen_block_verbose","verbosity of output","none",verbose,&verbose,NULL);dCHK(err); if (do_geom) { err = PetscOptionsBool("-dmeshgen_block_assoc_with_brick","associate boundaries with brick","none",assoc_with_brick,&assoc_with_brick,NULL);dCHK(err); } err = PetscOptionsBool("-dmeshgen_block_color_bdy","color boundary sets","none",do_color_bdy,&do_color_bdy,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_material","create material sets","none",do_material,&do_material,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_uniform","create uniform sets","none",do_uniform,&do_uniform,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_global_number","create global_number tags","none",do_global_number,&do_global_number,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_global_id","create GLOBAL_ID tags","none",do_global_id,&do_global_id,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_partition","create partition sets","none",do_partition,&do_partition,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_pressure","create pressure sets","none",do_pressure,&do_pressure,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_faces","create face entities","none",do_faces,&do_faces,NULL);dCHK(err); err = PetscOptionsBool("-dmeshgen_block_edges","create face entities","none",do_edges,&do_edges,NULL);dCHK(err); err = PetscOptionsReal("-dmeshgen_block_rotate_y","rotate domain by given angle (degrees) around y axis)","none",rotate_y,&rotate_y,NULL);dCHK(err); rotate_y *= PETSC_PI/180.; err = PetscOptionsString("-dmeshgen_block_box","box x0:x1,y0:y1,z0:z1","none",boxstr,boxstr,sizeof(boxstr),NULL);dCHK(err); err = PetscOptionsString("-dmeshgen_block_mnp","number of points m,n,p","none",mnp,mnp,sizeof(mnp),NULL);dCHK(err); err = PetscOptionsString("-dmeshgen_block_procs_mnp","number of procs M,N,P","none",MNP,MNP,sizeof(MNP),NULL);dCHK(err); i = sscanf(boxstr,"%lf:%lf,%lf:%lf,%lf:%lf",&box.x0,&box.x1,&box.y0,&box.y1,&box.z0,&box.z1); if (i != 6) dERROR(PETSC_COMM_SELF,1,"Failed to parse bounding box."); i = sscanf(mnp,"%d,%d,%d",&m,&n,&p); if (i != 3) dERROR(PETSC_COMM_SELF,1,"Failed to parse size."); i = sscanf(MNP,"%d,%d,%d",&M,&N,&P); if (i != 3) dERROR(PETSC_COMM_SELF,1,"Failed to parse partition size."); } err = PetscOptionsEnd(); err = dMeshGetInstance(dmesh,&mesh);dCHK(err); /* Allocate buffers */ err = dMallocA(m*n*p*3,&entbuf);dCHK(err); /* More than enough to hold all entities of any given type */ for (i=0; i<6; i++) { int n2max = dSqrInt(dMaxInt(m,dMaxInt(n,p))); err = dMallocA(2*n2max,&face[i]);dCHK(err); iMesh_createEntSet(mesh,0,&facesets[i],&err);dICHK(mesh,err); } /* Create vertices */ x.a = x.s = m*n*p*3; x.v = malloc(x.a*sizeof(double)); for (i=0; i<m; i++) { for (j=0; j<n; j++) { for (k=0; k<p; k++) { dReal X,Y,Z; I = (i*n+j)*p+k; if (i==0) AddToFace(face,facecount,3,I); else if (i==m-1) AddToFace(face,facecount,1,I); else if (j==0) AddToFace(face,facecount,0,I); else if (j==n-1) AddToFace(face,facecount,2,I); else if (k==0) AddToFace(face,facecount,4,I); else if (k==p-1) AddToFace(face,facecount,5,I); X = box.x0 + (box.x1-box.x0)*(1.*i/(m-1)); Y = box.y0 + (box.y1-box.y0)*(1.*j/(n-1)); Z = box.z0 + (box.z1-box.z0)*(1.*k/(p-1)); x.v[3*I+0] = cos(rotate_y) * X - sin(rotate_y) * Z; x.v[3*I+1] = Y; x.v[3*I+2] = sin(rotate_y) * X + cos(rotate_y) * Z; } } } iMesh_createVtxArr(mesh,m*n*p,order,x.v,x.s,&v.v,&v.a,&v.s,&err);dICHK(mesh,err); err = CommitToFaceSets(mesh,v.v,face,facecount,facesets,entbuf); MeshListFree(x); /* Create regions */ c.a = c.s = (m-1)*(n-1)*(p-1)*8; c.v = malloc(c.a*sizeof(iBase_EntityHandle)); /* connectivity */ I=0; for (i=0; i<m-1; i++) { for (j=0; j<n-1; j++) { for (k=0; k<p-1; k++) { c.v[I++] = v.v[((i+0)*n+(j+0))*p+(k+0)]; c.v[I++] = v.v[((i+1)*n+(j+0))*p+(k+0)]; c.v[I++] = v.v[((i+1)*n+(j+1))*p+(k+0)]; c.v[I++] = v.v[((i+0)*n+(j+1))*p+(k+0)]; c.v[I++] = v.v[((i+0)*n+(j+0))*p+(k+1)]; c.v[I++] = v.v[((i+1)*n+(j+0))*p+(k+1)]; c.v[I++] = v.v[((i+1)*n+(j+1))*p+(k+1)]; c.v[I++] = v.v[((i+0)*n+(j+1))*p+(k+1)]; } } } if (I != c.s) dERROR(PETSC_COMM_SELF,1,"Wrong number of regions."); iMesh_createEntArr(mesh,iMesh_HEXAHEDRON,c.v,c.s,&r.v,&r.a,&r.s,&s.v,&s.a,&s.s,&err);dICHK(mesh,err); if (r.s != (m-1)*(n-1)*(p-1)) dERROR(PETSC_COMM_SELF,1,"Wrong number of regions created."); if (verbose > 0) {err = PetscViewerASCIIPrintf(viewer,"region size %d, status size %d\n",r.s,s.s);dCHK(err);} if (do_global_number) {err = doGlobalNumber(mesh,root);dCHK(err);} if (do_global_id) {err = doGlobalID(mesh,root);dCHK(err);} if (do_partition) { /* Partition tags */ /* Create partition. */ part.a = part.s = r.s; part.v = malloc(part.a*sizeof(int)); for (i=0; i<m-1; i++) { for (j=0; j<n-1; j++) { for (k=0; k<p-1; k++) { I = i*M/(m-1); J = j*N/(n-1); K = k*P/(p-1); part.v[(i*(n-1)+j)*(p-1)+k] = (I*N+J)*P+K; } } } /* MATERIAL_SET is a special name associated with all iMesh instances * If we are using a different name, we can assume it is not special. */ if (strcmp(pTagName,"MATERIAL_SET")) { iMesh_createTag(mesh,pTagName,1,iBase_INTEGER,&pTag,&err,sizeof(pTagName));dICHK(mesh,err); } else { iMesh_getTagHandle(mesh,"MATERIAL_SET",&pTag,&err,sizeof("MATERIAL_SET"));dICHK(mesh,err); } iMesh_setIntArrData(mesh,r.v,r.s,pTag,part.v,part.s,&err);dICHK(mesh,err); MeshListFree(part); } if (do_partition) /* Partition sets */ { int ii,jj,kk; iBase_EntitySetHandle partset; iBase_EntityHandle *entp; /* reuse some stuff, set up the a partition set */ iMesh_createTag(mesh,pSetName,1,iBase_INTEGER,&pTag,&err,sizeof(pSetName));dICHK(mesh,err); for (i=0; i<M; i++) { for (j=0; j<N; j++) { for (k=0; k<P; k++) { iMesh_createEntSet(mesh,0,&partset,&err);dICHK(mesh,err); entp = entbuf; for (ii=i*(m-1)/M; ii<(i+1)*(m-1)/M; ii++) { for (jj=j*(n-1)/N; jj<(j+1)*(n-1)/N; jj++) { for (kk=k*(p-1)/P; kk<(k+1)*(p-1)/P; kk++) { *entp++ = r.v[(ii*(n-1)+jj)*(p-1)+kk]; } } } if (verbose > 0) {err = PetscViewerASCIIPrintf(viewer,"part[%d (%d,%d,%d)] has %d regions\n",(i*N+j)*P+k,i,j,k,(int)(entp-entbuf));dCHK(err);} iMesh_addEntArrToSet(mesh,entbuf,(int)(entp-entbuf),partset,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,partset,pTag,(i*N+j)*P+k,&err);dICHK(mesh,err); } } } } MeshListFree(r); MeshListFree(s); MeshListFree(c); if (do_faces) { /* Create faces */ c.a = c.s = 4*((m-1)*(n-1)*p + (m-1)*n*(p-1) + m*(n-1)*(p-1)); c.v = malloc(c.a*sizeof(iBase_EntityHandle)); I = 0; for (i=0; i<m-1; i++) { /* Faces with normal pointing in positive z direction */ for (j=0; j<n-1; j++) { for (k=0; k<p; k++) { if (k==0) AddToFace(face,facecount,4,I/4); if (k==p-1) AddToFace(face,facecount,5,I/4); c.v[I++] = v.v[((i+0)*n+(j+0))*p+k]; c.v[I++] = v.v[((i+1)*n+(j+0))*p+k]; c.v[I++] = v.v[((i+1)*n+(j+1))*p+k]; c.v[I++] = v.v[((i+0)*n+(j+1))*p+k]; } } } for (i=0; i<m-1; i++) { /* Faces with normal pointing in negative y direction */ for (j=0; j<n; j++) { for (k=0; k<p-1; k++) { if (j==0) AddToFace(face,facecount,0,I/4); if (j==n-1) AddToFace(face,facecount,2,I/4); c.v[I++] = v.v[((i+0)*n+j)*p+(k+0)]; c.v[I++] = v.v[((i+1)*n+j)*p+(k+0)]; c.v[I++] = v.v[((i+1)*n+j)*p+(k+1)]; c.v[I++] = v.v[((i+0)*n+j)*p+(k+1)]; } } } for (i=0; i<m; i++) { /* Faces with normal pointing in positive x direction */ for (j=0; j<n-1; j++) { for (k=0; k<p-1; k++) { if (i==0) AddToFace(face,facecount,3,I/4); if (i==m-1) AddToFace(face,facecount,1,I/4); c.v[I++] = v.v[(i*n+(j+0))*p+(k+0)]; c.v[I++] = v.v[(i*n+(j+1))*p+(k+0)]; c.v[I++] = v.v[(i*n+(j+1))*p+(k+1)]; c.v[I++] = v.v[(i*n+(j+0))*p+(k+1)]; } } } if (I != c.s) dERROR(PETSC_COMM_SELF,1, "Wrong number of faces."); iMesh_createEntArr(mesh,iMesh_QUADRILATERAL,c.v,c.s,&f.v,&f.a,&f.s,&s.v,&s.a,&s.s,&err);dICHK(mesh,err); err = CommitToFaceSets(mesh,f.v,face,facecount,facesets,entbuf);dCHK(err); if (verbose > 0) {err = PetscViewerASCIIPrintf(viewer,"face size %d, status size %d\n",f.s,s.s);dCHK(err);} MeshListFree(f); MeshListFree(s); MeshListFree(c); } if (do_edges) { /* Create edges */ c.a = c.s = 2*(m*n*(p-1) + m*(n-1)*p + (m-1)*n*p); c.v = malloc(c.a*sizeof(iBase_EntityHandle)); I = 0; for (i=0; i<m; i++) { for (j=0; j<n; j++) { for (k=0; k<p-1; k++) { if (i==0) AddToFace(face,facecount,0,I/2); else if (i==m-1) AddToFace(face,facecount,2,I/2); else if (j==0) AddToFace(face,facecount,3,I/2); else if (j==n-1) AddToFace(face,facecount,1,I/2); c.v[I++] = v.v[(i*n+j)*p+(k+0)]; c.v[I++] = v.v[(i*n+j)*p+(k+1)]; } } } for (i=0; i<m; i++) { for (j=0; j<n-1; j++) { for (k=0; k<p; k++) { if (i==0) AddToFace(face,facecount,0,I/2); else if (i==m-1) AddToFace(face,facecount,2,I/2); else if (k==0) AddToFace(face,facecount,4,I/2); else if (k==p-1) AddToFace(face,facecount,5,I/2); c.v[I++] = v.v[(i*n+(j+0))*p+k]; c.v[I++] = v.v[(i*n+(j+1))*p+k]; } } } for (i=0; i<m-1; i++) { for (j=0; j<n; j++) { for (k=0; k<p; k++) { if (j==0) AddToFace(face,facecount,3,I/2); else if (j==n-1) AddToFace(face,facecount,1,I/2); else if (k==0) AddToFace(face,facecount,4,I/2); else if (k==p-1) AddToFace(face,facecount,5,I/2); c.v[I++] = v.v[((i+0)*n+j)*p+k]; c.v[I++] = v.v[((i+1)*n+j)*p+k]; } } } if (I != c.s) dERROR(PETSC_COMM_SELF,1, "Wrong number of edges."); iMesh_createEntArr(mesh,iMesh_LINE_SEGMENT,c.v,c.s, &e.v,&e.a,&e.s, &s.v,&s.a,&s.s,&err);dICHK(mesh,err); err = CommitToFaceSets(mesh,e.v,face,facecount,facesets,entbuf);dCHK(err); if (verbose > 0) {err = PetscViewerASCIIPrintf(viewer,"edge size %d, status size %d\n",e.s,s.s);dCHK(err);} MeshListFree(e); MeshListFree(s); MeshListFree(c); } /* We are done with the master vertex record. */ MeshListFree(v); /* Create boundary sets, these are not related to geometry here */ { dMeshESH wallset,topset,bottomset,senseSet; iBase_TagHandle bdyTag,senseTag; iMesh_getTagHandle(mesh,"NEUMANN_SET",&bdyTag,&err,sizeof("NEUMANN_SET"));dICHK(mesh,err); iMesh_createTag(mesh,"SENSE",1,iBase_INTEGER,&senseTag,&err,sizeof "SENSE");dICHK(mesh,err); iMesh_createEntSet(mesh,0,&wallset,&err);dICHK(mesh,err); iMesh_createEntSet(mesh,0,&topset,&err);dICHK(mesh,err); iMesh_createEntSet(mesh,0,&bottomset,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,wallset,bdyTag,100,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,topset,bdyTag,200,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,bottomset,bdyTag,300,&err);dICHK(mesh,err); for (i=0; i<4; i++) {iMesh_addEntSet(mesh,facesets[i],wallset,&err);dICHK(mesh,err);} iMesh_addEntSet(mesh,facesets[5],topset,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,facesets[4],bottomset,&err);dICHK(mesh,err); /* Deal with SENSE on the walls */ iMesh_createEntSet(mesh,0,&senseSet,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,facesets[2],senseSet,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,facesets[3],senseSet,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,senseSet,senseTag,-1,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,senseSet,wallset,&err);dICHK(mesh,err); /* Deal with SENSE on the bottom */ iMesh_createEntSet(mesh,0,&senseSet,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,facesets[4],senseSet,&err);dICHK(mesh,err); iMesh_setEntSetIntData(mesh,senseSet,senseTag,-1,&err);dICHK(mesh,err); iMesh_addEntSet(mesh,senseSet,bottomset,&err);dICHK(mesh,err); for (i=0; i<6; i++) {err = dFree(face[i]);} err = dFree(entbuf);dCHK(err); } if (do_material) {err = doMaterial(mesh,root);dCHK(err);} /* Add a real valued tag over the vertices. */ if (do_pressure) { static const char *myTagName = "pressure"; iBase_TagHandle myTag; double *myData; iMesh_getEntities(mesh,root,iBase_VERTEX,iMesh_POINT,&v.v,&v.a,&v.s,&err);dICHK(mesh,err); iMesh_createTag(mesh,myTagName,1,iBase_DOUBLE,&myTag,&err,(int)strlen(myTagName));dICHK(mesh,err); err = PetscMalloc(v.s*sizeof(double),&myData);dCHK(err); for (i=0; i<v.s; i++) { myData[i] = 1.0 * i; } iMesh_setDblArrData(mesh,v.v,v.s,myTag,myData,v.s,&err);dICHK(mesh,err); err = PetscFree(myData);dCHK(err); MeshListFree(v); } if (do_uniform) {err = createUniformTags(mesh,root);dCHK(err);} if (do_geom) #ifndef dHAVE_ITAPS_REL dERROR(((dObject)dmesh)->comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Dohp has not been configured with support for geometry"); #else { const char geom_options[] = ";ENGINE=OCC;"; const char rel_options[] = ""; iGeom_Instance geom; iRel_Instance assoc; iRel_PairHandle pair; iBase_EntityHandle brick; iGeom_newGeom(geom_options,&geom,&err,sizeof geom_options);dIGCHK(geom,err); iRel_create(rel_options,&assoc,&err,sizeof rel_options);dIRCHK(assoc,err); iRel_createPair(assoc,geom,0,iRel_IGEOM_IFACE,iRel_ACTIVE,mesh,1,iRel_IMESH_IFACE,iRel_ACTIVE,&pair,&err);dIGCHK(assoc,err); iGeom_createBrick(geom,box.x1-box.x0,box.y1-box.y0,box.z1-box.z0,&brick,&err);dIGCHK(geom,err); iGeom_moveEnt(geom,brick,0.5*(box.x0+box.x1),0.5*(box.y0+box.y1),0.5*(box.z0+box.z1),&err);dIGCHK(geom,err); if (verbose > 0) {err = BoundingBoxView(geom,brick,"brick",viewer);dCHK(err);} { iBase_EntityHandle gface[6],*gface_p=gface; int gface_a=6,gface_s; iGeom_getEntAdj(geom,brick,2,&gface_p,&gface_a,&gface_s,&err);dIGCHK(geom,err); for (i=0; i<6; i++) { char name[20]; sprintf(name,"face_%d",i); err = BoundingBoxView(geom,gface[i],name,viewer);dCHK(err); } if (assoc_with_brick) { for (i=0; i<6; i++) { iRel_setEntSetRelation(assoc,pair,brick,facesets[i],&err);dIRCHK(assoc,err); } } else { /* Set associations. With the current Lasso implementation, these will not be saved */ iRel_setEntSetRelation(assoc,pair,gface[0],facesets[3],&err);dIRCHK(assoc,err); iRel_setEntSetRelation(assoc,pair,gface[1],facesets[1],&err);dIRCHK(assoc,err); iRel_setEntSetRelation(assoc,pair,gface[2],facesets[0],&err);dIRCHK(assoc,err); iRel_setEntSetRelation(assoc,pair,gface[3],facesets[2],&err);dIRCHK(assoc,err); iRel_setEntSetRelation(assoc,pair,gface[4],facesets[4],&err);dIRCHK(assoc,err); iRel_setEntSetRelation(assoc,pair,gface[5],facesets[5],&err);dIRCHK(assoc,err); } } { dMeshTag meshGlobalIDTag,meshGeomDimTag,geomGlobalIDTag; /* Manually set association tags, these are set so that the associations above can be inferred. */ iMesh_getTagHandle(mesh,"GLOBAL_ID",&meshGlobalIDTag,&err,sizeof "GLOBAL_ID");dICHK(mesh,err); iMesh_getTagHandle(mesh,"GEOM_DIMENSION",&meshGeomDimTag,&err,sizeof "GEOM_DIMENSION");dICHK(mesh,err); iGeom_getTagHandle(geom,"GLOBAL_ID",&geomGlobalIDTag,&err,sizeof "GLOBAL_ID");dIGCHK(geom,err); for (i=0; i<6; i++) { iBase_EntityHandle gface; int gid,gdim; iRel_getSetEntRelation(assoc,pair,facesets[i],1,&gface,&err);dIRCHK(assoc,err); iGeom_getEntType(geom,gface,&gdim,&err);dIGCHK(geom,err); if (gdim != 2) dERROR(PETSC_COMM_SELF,1,"Geometric dimension is %d, expected 2",gdim); iGeom_getIntData(geom,gface,geomGlobalIDTag,&gid,&err);dIGCHK(geom,err); iMesh_setEntSetIntData(mesh,facesets[i],meshGeomDimTag,2,&err);dICHK(mesh,err); /* If the following line is disabled, Lasso will pick up the wrong relations, but at least they will still be with * surfaces. Wouldn't it be better to not find relations? */ iMesh_setEntSetIntData(mesh,facesets[i],meshGlobalIDTag,gid,&err);dICHK(mesh,err); } } err = dMeshSetGeometryRelation(dmesh,geom,assoc);dCHK(err); } #endif dFunctionReturn(0); }
// This consistent interpolation example loads a linear quad mesh // tagged with a scalar field and interpolates it along with the gradient // pullback onto a delaunay tri mesh mesh. (Function domain = func_dmn, // function range = func_rng ) int main(int argc, char* argv[]) { // Setup communication. Teuchos::GlobalMPISession mpiSession(&argc,&argv); Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); if ( getDefaultComm<int>()->getRank() == 0 ) // Force scalar execution. { int error; // The tensor template can be shared by both the range and // domain value. Teuchos::RCP<FOOD::TensorTemplate> tensor_template = Teuchos::rcp( new FOOD::TensorTemplate(0, 1, FOOD::FOOD_REAL, Teuchos::null) ); // Need another one for the gradient. Here the gradient is a 3-vector. Teuchos::RCP<FOOD::TensorTemplate> grad_tensor_template = Teuchos::rcp( new FOOD::TensorTemplate(1, 3, FOOD::FOOD_REAL, Teuchos::null) ); // Set up the func_dmn mesh. iMesh_Instance func_dmn_mesh; iMesh_newMesh("", &func_dmn_mesh, &error, 0); assert( iBase_SUCCESS == error ); iBase_EntitySetHandle func_dmn_root_set; iMesh_getRootSet( func_dmn_mesh, &func_dmn_root_set, &error ); assert( iBase_SUCCESS == error ); std::string func_dmn_mesh_filename = "tagged_quad_flat_surf.vtk"; iMesh_load( func_dmn_mesh, func_dmn_root_set, &func_dmn_mesh_filename[0], "", &error, (int) func_dmn_mesh_filename.size(), 0 ); assert( iBase_SUCCESS == error ); // Set up the func_dmn mesh field. Teuchos::RCP<FOOD::Domain> func_dmn_domain = Teuchos::rcp( new FOOD::Domain(func_dmn_mesh, func_dmn_root_set, FOOD::FOOD_MBCN) ); Teuchos::RCP< FOOD::DFuncKernel<double> > func_dmn_dfunckernel = Teuchos::rcp( new FOOD::DFuncKernel<double>( iBase_FACE, iMesh_QUADRILATERAL, iBase_VERTEX, iMesh_POINT, FOOD::FOOD_CARTESIAN, FOOD::FOOD_FEM, FOOD::FOOD_HGRAD, FOOD::FOOD_SHARDSCN, 2 ) ); Teuchos::RCP< FOOD::TensorField<double> > func_dmn_field = Teuchos::rcp( new FOOD::TensorField<double>( getDefaultComm<int>(), func_dmn_domain, func_dmn_dfunckernel, FOOD::FOOD_CARTESIAN, tensor_template, Teuchos::null, "FUNC_DMN_FIELD" ) ); std::string func_dmn_tag_name = "domain"; iBase_TagHandle func_dmn_tag; iMesh_getTagHandle( func_dmn_domain->getMesh(), &func_dmn_tag_name[0], &func_dmn_tag, &error, (int) func_dmn_tag_name.size() ); assert( iBase_SUCCESS == error ); func_dmn_field->attachToTagData( func_dmn_tag, error ); assert( iBase_SUCCESS == error ); // Set up the func_rng mesh. iMesh_Instance func_rng_mesh; iMesh_newMesh("", &func_rng_mesh, &error, 0); assert( iBase_SUCCESS == error ); iBase_EntitySetHandle func_rng_root_set; iMesh_getRootSet( func_rng_mesh, &func_rng_root_set, &error ); assert( iBase_SUCCESS == error ); std::string func_rng_mesh_filename = "tagged_delaunay_flat_surf.vtk"; iMesh_load( func_rng_mesh, func_rng_root_set, &func_rng_mesh_filename[0], "", &error, (int) func_rng_mesh_filename.size(), 0 ); assert( iBase_SUCCESS == error ); // Set up the func_rng mesh field for function values. Teuchos::RCP<FOOD::Domain> func_rng_domain = Teuchos::rcp( new FOOD::Domain(func_rng_mesh, func_rng_root_set, FOOD::FOOD_MBCN) ); Teuchos::RCP< FOOD::DFuncKernel<double> > func_rng_dfunckernel = Teuchos::rcp( new FOOD::DFuncKernel<double>( iBase_FACE, iMesh_TRIANGLE, iBase_VERTEX, iMesh_POINT, FOOD::FOOD_CARTESIAN, FOOD::FOOD_FEM, FOOD::FOOD_HGRAD, FOOD::FOOD_SHARDSCN, 1 ) ); Teuchos::RCP< FOOD::TensorField<double> > func_rng_field = Teuchos::rcp( new FOOD::TensorField<double>( getDefaultComm<int>(), func_rng_domain, func_rng_dfunckernel, FOOD::FOOD_CARTESIAN, tensor_template, Teuchos::null, "FUNC_RNG_FIELD" ) ); std::string func_rng_tag_name = "range"; iBase_TagHandle func_rng_tag; iMesh_getTagHandle( func_rng_domain->getMesh(), &func_rng_tag_name[0], &func_rng_tag, &error, (int) func_rng_tag_name.size() ); assert( iBase_SUCCESS == error ); func_rng_field->attachToTagData( func_rng_tag, error ); assert( iBase_SUCCESS == error ); // Setup the gradient field. Teuchos::RCP< FOOD::TensorField<double> > func_rng_grad_field = Teuchos::rcp( new FOOD::TensorField<double>( getDefaultComm<int>(), func_rng_domain, func_rng_dfunckernel, FOOD::FOOD_CARTESIAN, grad_tensor_template, Teuchos::null, "FUNC_RNG_GRAD_FIELD" ) ); std::string func_rng_grad_tag_name = "grad_range"; iBase_TagHandle func_rng_grad_tag; iMesh_getTagHandle( func_rng_domain->getMesh(), &func_rng_grad_tag_name[0], &func_rng_grad_tag, &error, (int) func_rng_grad_tag_name.size() ); assert( iBase_SUCCESS == error ); func_rng_grad_field->attachToTagData( func_rng_grad_tag, error ); assert( iBase_SUCCESS == error ); // Do interpolation. FOOD::ConsistentScheme<double> fem_interp_val( func_dmn_field, func_rng_field ); fem_interp_val.setup(); fem_interp_val.transferValueDF(); FOOD::ConsistentScheme<double> fem_interp_grad( func_dmn_field, func_rng_grad_field ); fem_interp_grad.setup(); fem_interp_grad.transferGradDF(); // Write the interpolated mesh to file. std::string interp_file = "flat_surf_output.vtk"; iMesh_save( func_rng_domain->getMesh(), func_rng_domain->getMeshSet(), &interp_file[0], "", &error, (int) interp_file.size(), 0 ); assert( iBase_SUCCESS == error ); } // end rank 0 return 0; }