[petsc-users] Periodic BC with AMR
Daniil Svyatsky
dasvyat at gmail.com
Wed Jun 9 00:25:51 CDT 2021
Dear petsc developers and users,
I'm trying to set up a periodic BC on a mesh obtained by AMR technique.
I have a problem accessing the real coordinates of nodes on the periodic
boundary.
First, I generated a box mesh and apply periodic BC:
bc_cond[0] = DM_BOUNDARY_PERIODIC;
bc_cond[1] = DM_BOUNDARY_PERIODIC;
bc_cond[2] = DM_BOUNDARY_PERIODIC;
DMPlexCreateBoxMesh(PETSC_COMM_WORLD, dim, PETSC_FALSE,
num_faces, lower_cor, top_cor, bc_cond, interpolate,
&(dm));
DM baseParallel;
PetscPartitioner part;
ierr = DMPlexGetPartitioner(dm,&part);CHKERRQ(ierr);
ierr = PetscPartitionerSetFromOptions(part);CHKERRQ(ierr);
ierr = DMPlexDistribute(dm,0,NULL,&baseParallel);CHKERRQ(ierr);
if (baseParallel) {
ierr = DMDestroy(&(dm));CHKERRQ(ierr);
dm = baseParallel;
}
After this step I can access coordinates of boundary nodes correctly.
Then I applied AMR on this mesh:
DM preForest, postForest;
DMLabel adaptLabel = NULL;
ierr = DMCreate(PETSC_COMM_SELF, &preForest);CHKERRQ(ierr);
ierr = DMSetType(preForest,(dim == 2) ? DMP4EST :
DMP8EST);CHKERRQ(ierr);
ierr = DMForestSetBaseDM(preForest,env->dstruct->dm);CHKERRQ(ierr);
ierr = DMForestSetMinimumRefinement(preForest,0);CHKERRQ(ierr);
ierr = DMForestSetInitialRefinement(preForest,0);CHKERRQ(ierr);
ierr = DMSetFromOptions(preForest);CHKERRQ(ierr);
ierr = DMSetUp(preForest);CHKERRQ(ierr);
ierr = CreateAdaptivityLabel(env,preForest,&adaptLabel);CHKERRQ(ierr);
ierr = DMForestTemplate(preForest,PETSC_COMM_SELF,
&postForest);CHKERRQ(ierr);
ierr = DMForestSetAdaptivityLabel(postForest,adaptLabel);CHKERRQ(ierr);
ierr = DMLabelDestroy(&adaptLabel);CHKERRQ(ierr);
ierr = DMSetUp(postForest);CHKERRQ(ierr);
DM dmConv;
ierr = DMConvert(postForest,DMPLEX,&dmConv);CHKERRQ(ierr);
if (dmConv){
DMDestroy(&dm);
dm = dmConv;
}
In my example, boundary cells were also refined. After AMR I have a
problem accessing the coordinates of nodes.
To access node coordinates I do the following:
DMGetCoordinatesLocal(dm, &coordinates);
DMGetCoordinateDM(dm, &cdm);
DMGetSection(cdm, &cs);
for (cell = cStart; cell < cEnd; ++cell) {
PetscInt numFaces;
const PetscInt *faces;
ierr = DMPlexGetConeSize(dm, cell, &numFaces);
ierr = DMPlexGetCone(dm, cell, &faces);
for (int f = 0; f<numFaces; f++){
temp_f = NULL;
DMPlexVecGetClosure(dm, cs, coordinates, faces[f], &fsize, &temp_f);
for (p=0; p<fsize;p+=dim){
DMLocalizeCoordinate(dm, temp_f+p, PETSC_FALSE, coord_p)
}
}
}
coord_p has wrong coordinates either I used PETSC_TRUE or PETSC_FALSE
in DMLocalizeCoordinate.
What am I doing wrong? I'm using petsc-3.14.1 version.
Thank you for your help in advance.
Best regards,
Daniil Svyatsky.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210608/bccdf3d3/attachment-0001.html>
More information about the petsc-users
mailing list