PetscErrorCode DMView_Cartesian_Ascii(const ALE::Obj<ALE::CartesianMesh>& mesh, PetscViewer viewer) { PetscViewerFormat format; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscViewerGetFormat(viewer, &format); CHKERRQ(ierr); if (format == PETSC_VIEWER_ASCII_VTK) { #if 0 ierr = VTKViewer::writeHeader(viewer); CHKERRQ(ierr); ierr = VTKViewer::writeVertices(mesh, viewer); CHKERRQ(ierr); ierr = VTKViewer::writeElements(mesh, viewer); CHKERRQ(ierr); #endif } else { int dim = mesh->getDimension(); ierr = PetscViewerASCIIPrintf(viewer, "Mesh in %d dimensions:\n", dim); CHKERRQ(ierr); /* FIX: Need to globalize */ ierr = PetscViewerASCIIPrintf(viewer, " %d vertices\n", mesh->getSieve()->getNumVertices()); CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer, " %d cells\n", mesh->getSieve()->getNumCells()); CHKERRQ(ierr); } ierr = PetscViewerFlush(viewer); CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode OutputVTK(ALE::Obj<ALE::Mesh> mesh, Options *options, std::string outname) { PetscViewer viewer; PetscErrorCode ierr; PetscFunctionBegin; if (options->outputVTK) { ALE::LogStage stage = ALE::LogStageRegister("VTKOutput"); ALE::LogStagePush(stage); ierr = PetscPrintf(mesh->comm(), "Creating VTK mesh files\n");CHKERRQ(ierr); ierr = PetscViewerCreate(mesh->comm(), &viewer);CHKERRQ(ierr); ierr = PetscViewerSetType(viewer, PETSC_VIEWER_ASCII);CHKERRQ(ierr); ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr); ierr = PetscViewerFileSetName(viewer, outname.c_str());CHKERRQ(ierr); ierr = VTKViewer::writeHeader(viewer);CHKERRQ(ierr); ierr = VTKViewer::writeVertices(mesh, viewer); ierr = VTKViewer::writeElements(mesh, viewer); // ierr = VTKViewer::writeHierarchyVertices(mesh, viewer, options->zScale);CHKERRQ(ierr); // ierr = VTKViewer::writeHierarchyElements(mesh, viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr); //const ALE::Mesh::topology_type::sheaf_type& patches = mesh->getTopology()->getPatches(); ALE::LogStagePop(stage); } PetscFunctionReturn(0); }
PetscErrorCode DMCoarsen_Cartesian(DM mesh, MPI_Comm comm, DM *coarseMesh) { ALE::Obj<ALE::CartesianMesh> oldMesh; PetscErrorCode ierr; PetscFunctionBegin; if (comm == MPI_COMM_NULL) comm = ((PetscObject)mesh)->comm; ierr = DMCartesianGetMesh(mesh, oldMesh); CHKERRQ(ierr); ierr = DMCartesianCreate(comm, coarseMesh); CHKERRQ(ierr); #if 0 ALE::Obj<ALE::Mesh> newMesh = ALE::Generator::refineMesh(oldMesh, refinementLimit, false); ierr = MeshCartesianSetMesh(*coarseMesh, newMesh); CHKERRQ(ierr); const ALE::Obj<ALE::CartesianMesh::real_section_type>& s = newMesh->getRealSection("default"); newMesh->setDiscretization(oldMesh->getDiscretization()); newMesh->setBoundaryCondition(oldMesh->getBoundaryCondition()); newMesh->setupField(s); #else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP, "Not yet implemented"); #endif PetscFunctionReturn(0); }
PetscErrorCode DMMeshConvertOverlapToSF(DM dm, PetscSF *sf) { ALE::Obj<PETSC_MESH_TYPE> mesh; PetscInt *local; PetscSFNode *remote; PetscInt numPoints; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscSFCreate(((PetscObject) dm)->comm, sf); CHKERRQ(ierr); ierr = DMMeshGetMesh(dm, mesh); CHKERRQ(ierr); { /* The local points have degree 1 We use the recv overlap */ ALE::Obj<PETSC_MESH_TYPE::recv_overlap_type> overlap = mesh->getRecvOverlap(); numPoints = overlap->getNumPoints(); ierr = PetscMalloc(numPoints * sizeof(PetscInt), &local); CHKERRQ(ierr); ierr = PetscMalloc(numPoints * sizeof(PetscSFNode), &remote); CHKERRQ(ierr); for (PetscInt r = 0, i = 0; r < overlap->getNumRanks(); ++r) { const PetscInt rank = overlap->getRank(r); const PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator cBegin = overlap->supportBegin(rank); const PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator cEnd = overlap->supportEnd(rank); for (PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator c_iter = cBegin; c_iter != cEnd; ++c_iter, ++i) { local[i] = *c_iter; remote[i].rank = rank; remote[i].index = c_iter.color(); } } ierr = PetscSFSetGraph(*sf, numPoints, numPoints, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER); CHKERRQ(ierr); ierr = PetscSFView(*sf, NULL); CHKERRQ(ierr); } PetscFunctionReturn(0); }
PetscErrorCode DMCartesianGetSectionReal(DM dm, const char name[], SectionReal *section) { ALE::Obj<ALE::CartesianMesh> m; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCartesianGetMesh(dm, m); CHKERRQ(ierr); ierr = SectionRealCreate(m->comm(), section); CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) *section, name); CHKERRQ(ierr); #if 0 ierr = SectionRealSetSection(*section, m->getRealSection(std::string(name))); CHKERRQ(ierr); ierr = SectionRealSetBundle(*section, m); CHKERRQ(ierr); #endif PetscFunctionReturn(0); }
void viewConesAndSupports(const ALE::Obj<BiGraphInt3>& bg, const char *name) { // View the cones for all base points std::cout << name << " cones:" << std::endl; BiGraphInt3::traits::baseSequence base = bg->base(); for (BiGraphInt3::traits::baseSequence::traits::iterator i = base.begin(); i != base.end(); i++) { BiGraphInt3::traits::coneSequence cone = bg->cone(*i); std::cout << *i << ": "; cone.view(std::cout, true); } // View the supports for all cap points std::cout << name << " supports:" << std::endl; BiGraphInt3::traits::capSequence cap = bg->cap(); for (BiGraphInt3::traits::capSequence::traits::iterator i = cap.begin(); i != cap.end(); i++) { BiGraphInt3::traits::supportSequence supp = bg->support(*i); std::cout << *i << ": "; supp.view(std::cout, true); } } /* viewConesAndSupports() */
PetscErrorCode CreateSieve(MPI_Comm comm, int debug) { PetscErrorCode ierr; PetscFunctionBegin; ALE::Obj<sieve_type> sieve = sieve_type(comm, debug); ierr = PetscPrintf(comm, "Creating a 'Hat' Sieve of global size %d: 3 base nodes and 1 cap node per process\n", 3*sieve->commSize()+1);CHKERRQ(ierr); for (int i = 0; i < 3; i++) { sieve_type::point_type p(sieve->commRank(), 0), b(-1,2*sieve->commRank()+i); sieve->addArrow(p,b); } sieve->view(std::cout, "Hat"); PetscFunctionReturn(0); }
PetscErrorCode PETSCDM_DLLEXPORT MeshRefineSingularity_Fichera(ALE::Obj<ALE::Mesh> mesh, MPI_Comm comm, double * singularity, double factor, ALE::Obj<ALE::Mesh> * refinedMesh, PetscTruth interpolate = PETSC_FALSE) { ALE::Obj<ALE::Mesh> oldMesh = mesh; double oldLimit; PetscErrorCode ierr; PetscFunctionBegin; //ierr = MeshGetMesh(mesh, oldMesh);CHKERRQ(ierr); //ierr = MeshCreate(comm, refinedMesh);CHKERRQ(ierr); int dim = oldMesh->getDimension(); oldLimit = oldMesh->getMaxVolume(); //double oldLimInv = 1./oldLimit; double curLimit, tmpLimit; double minLimit = oldLimit/16384.; //arbitrary; const ALE::Obj<ALE::Mesh::real_section_type>& coordinates = oldMesh->getRealSection("coordinates"); const ALE::Obj<ALE::Mesh::real_section_type>& volume_limits = oldMesh->getRealSection("volume_limits"); volume_limits->setFiberDimension(oldMesh->heightStratum(0), 1); oldMesh->allocate(volume_limits); const ALE::Obj<ALE::Mesh::label_sequence>& cells = oldMesh->heightStratum(0); ALE::Mesh::label_sequence::iterator c_iter = cells->begin(); ALE::Mesh::label_sequence::iterator c_iter_end = cells->end(); double centerCoords[dim]; while (c_iter != c_iter_end) { const double * coords = oldMesh->restrictClosure(coordinates, *c_iter); for (int i = 0; i < dim; i++) { centerCoords[i] = 0; for (int j = 0; j < dim+1; j++) { centerCoords[i] += coords[j*dim+i]; } centerCoords[i] = centerCoords[i]/(dim+1); //PetscPrintf(oldMesh->comm(), "%f, ", centerCoords[i]); } //PetscPrintf(oldMesh->comm(), "\n"); double dist = 0.; double cornerdist = 0.; //HERE'S THE DIFFERENCE: if centercoords is less than the singularity coordinate for each direction, include that direction in the distance /* for (int i = 0; i < dim; i++) { if (centerCoords[i] <= singularity[i]) { dist += (centerCoords[i] - singularity[i])*(centerCoords[i] - singularity[i]); } } */ //determine: the per-dimension distance: cases if (dim > 2) { for (int i = 0; i < dim; i++) { cornerdist = 0.; if (centerCoords[i] > singularity[i]) { for (int j = 0; j < dim; j++) { if (j != i) cornerdist += (centerCoords[j] - singularity[j])*(centerCoords[j] - singularity[j]); } if (cornerdist < dist || dist == 0.) dist = cornerdist; } } } //patch up AROUND the corner by minimizing between the distance from the relevant axis and the singular vertex double singdist = 0.; for (int i = 0; i < dim; i++) { singdist += (centerCoords[i] - singularity[i])*(centerCoords[i] - singularity[i]); } if (singdist < dist || dist == 0.) dist = singdist; if (dist > 0.) { dist = sqrt(dist); double mu = pow(dist, factor); //PetscPrintf(oldMesh->comm(), "%f, %f\n", mu, dist); tmpLimit = oldLimit*pow(mu, dim); if (tmpLimit > minLimit) { curLimit = tmpLimit; } else curLimit = minLimit; } else curLimit = minLimit; //PetscPrintf(oldMesh->comm(), "%f, %f\n", dist, tmpLimit); volume_limits->updatePoint(*c_iter, &curLimit); c_iter++; } ALE::Obj<ALE::Mesh> newMesh = ALE::Generator::refineMesh(oldMesh, volume_limits, interpolate); //ierr = MeshSetMesh(*refinedMesh, newMesh);CHKERRQ(ierr); *refinedMesh = newMesh; const ALE::Obj<ALE::Mesh::real_section_type>& s = newMesh->getRealSection("default"); const Obj<std::set<std::string> >& discs = oldMesh->getDiscretizations(); for(std::set<std::string>::const_iterator f_iter = discs->begin(); f_iter != discs->end(); ++f_iter) { newMesh->setDiscretization(*f_iter, oldMesh->getDiscretization(*f_iter)); } newMesh->setupField(s); // PetscPrintf(newMesh->comm(), "refined\n"); PetscFunctionReturn(0); }
EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "DMConvert_DA_Mesh" PetscErrorCode DMConvert_DA_Mesh(DM dm, const DMType newtype, DM *dmNew) { PetscSection section; DM cda; DMDALocalInfo info; Vec coordinates; PetscInt *cone, *coneO; PetscInt dim, M, N, P, numCells, numGlobalCells, numCorners, numVertices, c = 0, v = 0; PetscInt ye, ze; PetscInt debug = 0; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscOptionsGetInt(PETSC_NULL, "-dm_mesh_debug", &debug, PETSC_NULL);CHKERRQ(ierr); ierr = DMDAGetInfo(dm, &dim, &M, &N, &P, 0,0,0,0,0,0,0,0,0);CHKERRQ(ierr); ierr = DMDAGetLocalInfo(dm, &info);CHKERRQ(ierr); if (info.sw > 1) SETERRQ(((PetscObject) dm)->comm, PETSC_ERR_SUP, "Currently, only DMDAs with unti stencil width can be converted to DMMeshes."); /* In order to get a partition of cells, rather than vertices, we give each process the cells between vertices it owns and also higher numbered ghost vertices (vertices to the right and up) */ numCorners = 1 << dim; numCells = ((info.gxm+info.gxs - info.xs) - 1); if (dim > 1) {numCells *= ((info.gym+info.gys - info.ys) - 1);} if (dim > 2) {numCells *= ((info.gzm+info.gzs - info.zs) - 1);} numVertices = (info.gxm+info.gxs - info.xs); if (dim > 1) {numVertices *= (info.gym+info.gys - info.ys);} if (dim > 2) {numVertices *= (info.gzm+info.gzs - info.zs);} numGlobalCells = M-1; if (dim > 1) {numGlobalCells *= N-1;} if (dim > 2) {numGlobalCells *= P-1;} ALE::Obj<PETSC_MESH_TYPE> mesh = new PETSC_MESH_TYPE(((PetscObject) dm)->comm, info.dim, debug); ALE::Obj<PETSC_MESH_TYPE::sieve_type> sieve = new PETSC_MESH_TYPE::sieve_type(((PetscObject) dm)->comm, 0, numCells+numVertices, debug); PETSC_MESH_TYPE::renumbering_type renumbering; mesh->setSieve(sieve); /* Number each cell for the vertex in the lower left corner */ if (dim < 3) {ze = 1; P = 1;} else {ze = info.gzs+info.gzm-1;} if (dim < 2) {ye = 1; N = 1;} else {ye = info.gys+info.gym-1;} for(PetscInt k = info.zs; k < ze; ++k) { for(PetscInt j = info.ys; j < ye; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm-1; ++i, ++c) { PetscInt globalC = (k*(N-1) + j)*(M-1) + i; renumbering[globalC] = c; sieve->setConeSize(c, numCorners); } } } if (c != numCells) {SETERRQ2(((PetscObject) dm)->comm, PETSC_ERR_PLIB, "Error in generated cell numbering, %d should be %d", c, numCells);} /* Get vertex renumbering */ for(PetscInt k = info.zs; k < info.gzs+info.gzm; ++k) { for(PetscInt j = info.ys; j < info.gys+info.gym; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i, ++v) { PetscInt globalV = (k*N + j)*M + i + numGlobalCells; renumbering[globalV] = v+numCells; } } } if (v != numVertices) {SETERRQ2(((PetscObject) dm)->comm, PETSC_ERR_PLIB, "Error in generated vertex numbering, %d should be %d", v, numVertices);} /* Calculate support sizes */ for(PetscInt k = info.zs; k < ze; ++k, ++c) { for(PetscInt j = info.ys; j < ye; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm-1; ++i) { for(PetscInt kp = k; kp <= k+(dim>2); ++kp) { for(PetscInt jp = j; jp <= j+(dim>1); ++jp) { for(PetscInt ip = i; ip <= i+1; ++ip) { PetscInt globalV = (kp*N + jp)*M + ip + numGlobalCells; sieve->addSupportSize(renumbering[globalV], 1); } } } } } } sieve->allocate(); ierr = PetscMalloc2(numCorners,PetscInt,&cone,numCorners,PetscInt,&coneO);CHKERRQ(ierr); for(PetscInt v = 0; v < numCorners; ++v) { coneO[v] = 1; } for(PetscInt k = info.zs; k < ze; ++k) { for(PetscInt j = info.ys; j < ye; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm-1; ++i) { PetscInt globalC = (k*(N-1) + j)*(M-1) + i; PetscInt v = 0; cone[v++] = renumbering[(k*N + j)*M + i+0 + numGlobalCells]; cone[v++] = renumbering[(k*N + j)*M + i+1 + numGlobalCells]; if (dim > 1) { cone[v++] = renumbering[(k*N + j+1)*M + i+0 + numGlobalCells]; cone[v++] = renumbering[(k*N + j+1)*M + i+1 + numGlobalCells]; } if (dim > 2) { cone[v++] = renumbering[((k+1)*N + j+0)*M + i+0 + numGlobalCells]; cone[v++] = renumbering[((k+1)*N + j+0)*M + i+1 + numGlobalCells]; cone[v++] = renumbering[((k+1)*N + j+1)*M + i+0 + numGlobalCells]; cone[v++] = renumbering[((k+1)*N + j+1)*M + i+1 + numGlobalCells]; } sieve->setCone(cone, renumbering[globalC]); sieve->setConeOrientation(coneO, renumbering[globalC]); } } } ierr = PetscFree2(cone,coneO);CHKERRQ(ierr); sieve->symmetrize(); mesh->stratify(); /* Create boundary marker */ { const Obj<PETSC_MESH_TYPE::label_type>& boundary = mesh->createLabel("marker"); for(PetscInt k = info.zs; k < info.gzs+info.gzm; ++k) { for(PetscInt j = info.ys; j < info.gys+info.gym; ++j) { if (info.xs == 0) { PetscInt globalV = (k*N + j)*M + info.xs + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } if (info.gxs+info.gxm-1 == M-1) { PetscInt globalV = (k*N + j)*M + info.gxs+info.gxm-1 + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } } } if (dim > 1) { for(PetscInt k = info.zs; k < info.gzs+info.gzm; ++k) { for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i) { if (info.ys == 0) { PetscInt globalV = (k*N + info.ys)*M + i + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } if (info.gys+info.gym-1 == N-1) { PetscInt globalV = (k*N + info.gys+info.gym-1)*M + i + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } } } } if (dim > 2) { for(PetscInt j = info.ys; j < info.gys+info.gym; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i) { if (info.zs == 0) { PetscInt globalV = (info.zs*N + j)*M + i + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } if (info.gzs+info.gzm-1 == P-1) { PetscInt globalV = ((info.gzs+info.gzm-1)*N + j)*M + i + numGlobalCells; mesh->setValue(boundary, renumbering[globalV], 1); } } } } } /* Create new DM */ ierr = DMMeshCreate(((PetscObject) dm)->comm, dmNew);CHKERRQ(ierr); ierr = DMMeshSetMesh(*dmNew, mesh);CHKERRQ(ierr); /* Set coordinates */ ierr = PetscSectionCreate(((PetscObject) dm)->comm, §ion);CHKERRQ(ierr); ierr = PetscSectionSetChart(section, numCells, numCells+numVertices);CHKERRQ(ierr); for(PetscInt v = numCells; v < numCells+numVertices; ++v) { ierr = PetscSectionSetDof(section, v, dim);CHKERRQ(ierr); } ierr = PetscSectionSetUp(section);CHKERRQ(ierr); ierr = DMMeshSetCoordinateSection(*dmNew, section);CHKERRQ(ierr); ierr = DMDAGetCoordinateDA(dm, &cda);CHKERRQ(ierr); ierr = DMDAGetGhostedCoordinates(dm, &coordinates);CHKERRQ(ierr); { Obj<PETSC_MESH_TYPE::real_section_type> coordSection = mesh->getRealSection("coordinates"); switch(dim) { case 1: { PetscScalar **coords; ierr = DMDAVecGetArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i) { PetscInt globalV = i + numGlobalCells; coordSection->updatePoint(renumbering[globalV], coords[i]); } ierr = DMDAVecRestoreArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); break; } case 2: { PetscScalar ***coords; ierr = DMDAVecGetArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); for(PetscInt j = info.ys; j < info.gys+info.gym; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i) { PetscInt globalV = j*M + i + numGlobalCells; coordSection->updatePoint(renumbering[globalV], coords[j][i]); } } ierr = DMDAVecRestoreArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); break; } case 3: { PetscScalar ****coords; ierr = DMDAVecGetArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); for(PetscInt k = info.zs; k < info.gzs+info.gzm; ++k, ++v) { for(PetscInt j = info.ys; j < info.gys+info.gym; ++j) { for(PetscInt i = info.xs; i < info.gxs+info.gxm; ++i) { PetscInt globalV = (k*N + j)*M + i + numGlobalCells; coordSection->updatePoint(renumbering[globalV], coords[k][j][i]); } } } ierr = DMDAVecRestoreArrayDOF(cda, coordinates, &coords);CHKERRQ(ierr); break; } default: SETERRQ1(((PetscObject) dm)->comm, PETSC_ERR_ARG_OUTOFRANGE, "Invalid DMDA dimension %d", dim); } } /* Get overlap for interdomain communication */ { typedef PETSC_MESH_TYPE::point_type point_type; PETSc::Log::Event("CreateOverlap").begin(); ALE::Obj<PETSC_MESH_TYPE::send_overlap_type> sendParallelMeshOverlap = mesh->getSendOverlap(); ALE::Obj<PETSC_MESH_TYPE::recv_overlap_type> recvParallelMeshOverlap = mesh->getRecvOverlap(); // Can I figure this out in a nicer way? ALE::SetFromMap<std::map<point_type,point_type> > globalPoints(renumbering); ALE::OverlapBuilder<>::constructOverlap(globalPoints, renumbering, sendParallelMeshOverlap, recvParallelMeshOverlap); if (debug) { sendParallelMeshOverlap->view("Send Overlap"); recvParallelMeshOverlap->view("Recieve Overlap"); } mesh->setCalculatedOverlap(true); PETSc::Log::Event("CreateOverlap").end(); } PetscFunctionReturn(0); }
PetscErrorCode testBiGraphDiv2() { PetscInt debug; PetscBool flag; PetscErrorCode ierr; PetscFunctionBegin; debug = 0; ierr = PetscOptionsGetInt(NULL, "-debug", &debug, &flag);CHKERRQ(ierr); ALE::Obj<BiGraphInt3> bg = BiGraphInt3(PETSC_COMM_SELF, debug); // Add arrows from the first 10 integers to the first 20 integers, coloring the arrows for 0 (even target) or 1 (odd target) for (int i = 0; i < 10; i++) { bg->addArrow(2*i+0, i, 0); bg->addArrow(2*i+1, i, 1); } // View bg->view(std::cout, "bigraph/2"); // View cones and supports viewConesAndSupports(bg, "bigraph/2"); // Take and view the cone of the whole base ALE::Obj<BiGraphInt3::traits::coneSet> cone = bg->cone(bg->base()); std::cout << "Total cone of bigraph/2" << std::endl; std::cout << "["; for (BiGraphInt3::traits::coneSet::iterator i = cone->begin(); i != cone->end(); i++) { std::cout << " " << *i; } std::cout << " ]" << std::endl; // Take and view the support of the whole cap ALE::Obj<BiGraphInt3::traits::supportSet> supp = bg->support(bg->cap()); std::cout << "Total support of bigraph/2" << std::endl; std::cout << "["; for (BiGraphInt3::traits::supportSet::iterator i = supp->begin(); i != supp->end(); i++) { std::cout << *i; } std::cout << "]"; // Change each arrow color to its negative BiGraphInt3::baseSequence base = bg->base(); for (BiGraphInt3::baseSequence::iterator i = base.begin(); i != base.end(); i++) { BiGraphInt3::coneSequence cone = bg->cone(*i); for (BiGraphInt3::coneSequence::iterator j = cone.begin(); j != cone.end(); j++) { bg->setColor(*j,*i,-(j.color())); } } // View bg->view(std::cout, "bigraph/2 after negation"); // Remove the arrow from 4 to 2 with color 0 BiGraphInt3::traits::arrow_type a(4,2,0), b(4,3,0); bg->removeArrow(a); bg->removeArrow(b); // View ostringstream txt; txt << "bigraph/2 after removal of arrows " << a << " and " << b; bg->view(std::cout, txt.str().c_str()); // Remove first cone { BiGraphInt3::baseSequence base = bg->base(); bg->clearCone(*(base.begin())); } // View bg->view(std::cout, "bigraph/2 after removal of the first cone"); // Remove first support { BiGraphInt3::capSequence cap = bg->cap(); bg->clearSupport(*(cap.begin())); } // View bg->view(std::cout, "bigraph/2 after removal of the first support"); // Now restrict the base to the [0,8[ interval try { { ALE::Obj<int_set> base = int_set(); for (int i = 0; i < 8; i++) { base->insert(i); } bg->restrictBase(base); } } catch(ALE::Exception e) { std::cout << "Caught exception: " << e.message() << std::endl; } // View bg->view(std::cout, "bigraph/2 after restricting base to [0,8["); // Now exclude [0,5[ from the base try { { ALE::Obj<int_set> ebase = int_set(); for (int i = 0; i < 5; i++) { ebase->insert(i); } bg->excludeBase(ebase); } } catch(ALE::Exception e) { std::cout << "Caught exception: " << e.message() << std::endl; } // View bg->view(std::cout, "bigraph/2 after excluding [0,5[ from base"); PetscFunctionReturn(0); } /* testBiGraphDiv2() */
PetscErrorCode DMCreateInterpolation_Cartesian(DM fineMesh, DM coarseMesh, Mat *interpolation, Vec *scaling) { ALE::Obj<ALE::CartesianMesh> coarse; ALE::Obj<ALE::CartesianMesh> fine; Mat P; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCartesianGetMesh(fineMesh, fine); CHKERRQ(ierr); ierr = DMCartesianGetMesh(coarseMesh, coarse); CHKERRQ(ierr); #if 0 const ALE::Obj<ALE::Mesh::real_section_type>& coarseCoordinates = coarse->getRealSection("coordinates"); const ALE::Obj<ALE::Mesh::real_section_type>& fineCoordinates = fine->getRealSection("coordinates"); const ALE::Obj<ALE::Mesh::label_sequence>& vertices = fine->depthStratum(0); const ALE::Obj<ALE::Mesh::real_section_type>& sCoarse = coarse->getRealSection("default"); const ALE::Obj<ALE::Mesh::real_section_type>& sFine = fine->getRealSection("default"); const ALE::Obj<ALE::Mesh::order_type>& coarseOrder = coarse->getFactory()->getGlobalOrder(coarse, "default", sCoarse); const ALE::Obj<ALE::Mesh::order_type>& fineOrder = fine->getFactory()->getGlobalOrder(fine, "default", sFine); const int dim = coarse->getDimension(); double *v0, *J, *invJ, detJ, *refCoords, *values; #endif ierr = MatCreate(fine->comm(), &P); CHKERRQ(ierr); #if 0 ierr = MatSetSizes(P, sFine->size(), sCoarse->size(), PETSC_DETERMINE, PETSC_DETERMINE); CHKERRQ(ierr); ierr = MatSetFromOptions(P); CHKERRQ(ierr); ierr = PetscMalloc5(dim,double,&v0,dim*dim,double,&J,dim*dim,double,&invJ,dim,double,&refCoords,dim+1,double,&values); CHKERRQ(ierr); for(ALE::Mesh::label_sequence::iterator v_iter = vertices->begin(); v_iter != vertices->end(); ++v_iter) { const ALE::Mesh::real_section_type::value_type *coords = fineCoordinates->restrictPoint(*v_iter); const ALE::Mesh::point_type coarseCell = coarse->locatePoint(coords); coarse->computeElementGeometry(coarseCoordinates, coarseCell, v0, J, invJ, detJ); for(int d = 0; d < dim; ++d) { refCoords[d] = 0.0; for(int e = 0; e < dim; ++e) { refCoords[d] += invJ[d*dim+e]*(coords[e] - v0[e]); } refCoords[d] -= 1.0; } values[0] = 1.0/3.0 - (refCoords[0] + refCoords[1])/3.0; values[1] = 0.5*(refCoords[0] + 1.0); values[2] = 0.5*(refCoords[1] + 1.0); ierr = updateOperatorGeneral(P, fine, sFine, fineOrder, *v_iter, sCoarse, coarseOrder, coarseCell, values, INSERT_VALUES); CHKERRQ(ierr); } ierr = PetscFree5(v0,J,invJ,refCoords,values); CHKERRQ(ierr); #endif ierr = MatAssemblyBegin(P, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatAssemblyEnd(P, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); *interpolation = P; PetscFunctionReturn(0); }