Example #1
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);
}
Example #2
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);
}
Example #3
0
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);
}