<div dir="ltr"><div dir="ltr">On Fri, May 22, 2020 at 12:57 PM Shashwat Tiwari <<a href="mailto:shaswat121994@gmail.com" target="_blank">shaswat121994@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi, <br></div><div>I am working on a Finite Volume scheme for a hyperbolic system of equations equations with 6 variables on unstructured grids. I am trying to create a section with 6 fields for this purpose, and have written a small test code for creating the section by editing the example given at src/dm/impls/plex/tutorials/ex1.c as follows:</div></div></blockquote><div><br></div><div>If you use the PetscFV stuff, it assumes everything is in a single field. This is because FV methods often want Riemann solvers with all the fields, but Plex<br></div><div>splits the callbacks by field in order to get sparsity in the finite element matrix. In order to make things more understandable, we added</div><div><br></div><div> <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/PetscSection/PetscSectionSetComponentName.html#PetscSectionSetComponentName">https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/PetscSection/PetscSectionSetComponentName.html#PetscSectionSetComponentName</a></div><div><br></div><div>so you can name the components just like you would name fields. I think this may be what you want. Let me know if this does not help.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>int main(int argc, char **argv)<br>{<br> DM dm, dmDist = NULL;<br> Vec U;<br> PetscSection section;<br> PetscViewer viewer;<br> PetscInt dim = 2, numFields, numBC, i;<br> PetscInt numComp[6];<br> PetscInt numDof[18];<br> PetscBool interpolate = PETSC_TRUE, useCone = PETSC_TRUE, useClosure = PETSC_TRUE;<br> PetscReal lower[3], upper[3]; // lower left and upper right coordinates of domain<br> PetscInt cells[2];<br> PetscErrorCode ierr;<br><br> // define domain properties<br> cells[0] = 4; cells[1] = 4;<br> lower[0] = -1; lower[1] = -1; lower[2] = 0;<br> upper[0] = 1; upper[1] = 1; upper[2] = 0;<br><br> ierr = PetscInitialize(&argc, &argv, NULL, help); CHKERRQ(ierr);<br> // create the mesh<br> ierr = PetscPrintf(PETSC_COMM_WORLD, "Generating mesh ... "); CHKERRQ(ierr);<br> ierr = DMPlexCreateBoxMesh(PETSC_COMM_WORLD, dim, PETSC_TRUE,<br> cells, lower, upper, NULL, interpolate, &dm); CHKERRQ(ierr);<br> ierr = PetscPrintf(PETSC_COMM_WORLD, "Done\n"); CHKERRQ(ierr);<br><br> // set cell adjacency<br> ierr = DMSetBasicAdjacency(dm, useCone, useClosure); CHKERRQ(ierr);<br> // Distribute mesh over processes<br> ierr = DMPlexDistribute(dm, 1, NULL, &dmDist);CHKERRQ(ierr);<br> if (dmDist) {ierr = DMDestroy(&dm);CHKERRQ(ierr); dm = dmDist;}<br><br> // Create scalar fields<br> numFields = 6;<br> numComp[0] = 1;<br> numComp[1] = 1;<br> numComp[2] = 1;<br> numComp[3] = 1;<br> numComp[4] = 1;<br> numComp[5] = 1;<br><br> for (i = 0; i < numFields*(dim+1); ++i) numDof[i] = 0;<br> numDof[0*(dim+1)+dim] = 1;<br> numDof[1*(dim+1)+dim] = 1;<br> numDof[2*(dim+1)+dim] = 1;<br> numDof[3*(dim+1)+dim] = 1;<br> numDof[4*(dim+1)+dim] = 1;<br> numDof[5*(dim+1)+dim] = 1;<br> <br> numBC = 0;<br><br> // Create a PetscSection with this data layout<br> ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr);<br> ierr = DMPlexCreateSection(dm, NULL, numComp, numDof, numBC, NULL, NULL, NULL, NULL, §ion);CHKERRQ(ierr);<br> <br> // Name the Field variables<br> ierr = PetscSectionSetFieldName(section, 0, "h");CHKERRQ(ierr);<br> ierr = PetscSectionSetFieldName(section, 1, "m1");CHKERRQ(ierr);<br> ierr = PetscSectionSetFieldName(section, 2, "m2");CHKERRQ(ierr);<br> ierr = PetscSectionSetFieldName(section, 3, "E11");CHKERRQ(ierr);<br> ierr = PetscSectionSetFieldName(section, 4, "E12");CHKERRQ(ierr);<br> ierr = PetscSectionSetFieldName(section, 5, "E22");CHKERRQ(ierr);<br><br> // set adjacency for each field<br> ierr = DMSetAdjacency(dm, 0, useCone, useClosure); CHKERRQ(ierr);<br> ierr = DMSetAdjacency(dm, 1, useCone, useClosure); CHKERRQ(ierr);<br> ierr = DMSetAdjacency(dm, 2, useCone, useClosure); CHKERRQ(ierr);<br> ierr = DMSetAdjacency(dm, 3, useCone, useClosure); CHKERRQ(ierr);<br> ierr = DMSetAdjacency(dm, 4, useCone, useClosure); CHKERRQ(ierr);<br> ierr = DMSetAdjacency(dm, 5, useCone, useClosure); CHKERRQ(ierr);<br> <br> ierr = PetscSectionView(section, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);<br> <br> // Tell the DM to use this data layout<br> ierr = DMSetLocalSection(dm, section);CHKERRQ(ierr);<br> ierr = DMView(dm, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr);<br> <br> // Create a Vec with this layout and view it<br> ierr = DMGetGlobalVector(dm, &U);CHKERRQ(ierr);<br> ierr = PetscObjectSetName((PetscObject) U, "U"); CHKERRQ(ierr);<br> ierr = PetscViewerCreate(PETSC_COMM_WORLD, &viewer);CHKERRQ(ierr);<br> ierr = PetscViewerSetType(viewer, PETSCVIEWERVTK);CHKERRQ(ierr);<br> ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr);<br> ierr = PetscViewerFileSetName(viewer, "sol.vtk");CHKERRQ(ierr);<br> //ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_VTK_VTU);CHKERRQ(ierr);<br> //ierr = PetscViewerFileSetName(viewer, "sol.vtu");CHKERRQ(ierr);<br> ierr = VecView(U, viewer);CHKERRQ(ierr);<br> ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);<br> ierr = DMRestoreGlobalVector(dm, &U);CHKERRQ(ierr);<br> <br> // Cleanup<br> ierr = PetscSectionDestroy(§ion);CHKERRQ(ierr);<br> ierr = DMDestroy(&dm);CHKERRQ(ierr);<br> ierr = PetscFinalize();<br> return ierr;<br>}</div><div><br></div><div>When exporting the vector data to "vtk" format, the code works fine and I am able to see the 6 field names in the visualizer. But when I change it to "vtu", I get the following error:</div><div><br></div><div> [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: Petsc has generated inconsistent data<br>[0]PETSC ERROR: Total number of field components 1 != block size 6<br>[0]PETSC ERROR: See <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>[0]PETSC ERROR: Petsc Release Version 3.13.0, unknown <br>[0]PETSC ERROR: ./ex1 on a arch-linux2-c-debug named shashwat by shashwat Fri May 22 22:11:13 2020<br>[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack --with-debugging=1 --download-triangle --download-metis --download-parmetis --download-cmake<br>[0]PETSC ERROR: #1 DMPlexVTKWriteAll_VTU() line 334 in /home/shashwat/local/petsc/src/dm/impls/plex/plexvtu.c<br>[0]PETSC ERROR: #2 DMPlexVTKWriteAll() line 688 in /home/shashwat/local/petsc/src/dm/impls/plex/plexvtk.c<br>[0]PETSC ERROR: #3 PetscViewerFlush_VTK() line 100 in /home/shashwat/local/petsc/src/sys/classes/viewer/impls/vtk/vtkv.c<br>[0]PETSC ERROR: #4 PetscViewerFlush() line 26 in /home/shashwat/local/petsc/src/sys/classes/viewer/interface/flush.c<br>[0]PETSC ERROR: #5 PetscViewerDestroy() line 113 in /home/shashwat/local/petsc/src/sys/classes/viewer/interface/view.c<br>[0]PETSC ERROR: #6 main() line 485 in ex1.c<br>[0]PETSC ERROR: No PETSc Option Table entries<br>[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------<br>application called MPI_Abort(MPI_COMM_SELF, 485077) - process 0</div><div><br></div><div>I would like to use the "vtu" format for visualiztion. Kindly have a look and let me know I might be doing wrong here, and how can I make it work.<br></div><div><br></div><div>Regards,</div><div>Shashwat<br></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>