Re: [petsc-users] Write/read a DMForest to/from a file

2022-12-30 Thread David Salac
Matt and I had a student who was working with Forest that had this 
issue. The problem is that once you convert the refined Forest to Plex 
and save it to a file you lose all of the hierarchical information when 
you load it again. When you load it the mesh basically becomes the base 
mesh, with no information about the coarser levels. It wasn't a huge 
deal for us so we basically saved the original base PLEX and refined 
down to what we needed during a restart. Since we were working with a 
mesh that wasn't time-evolving this wasn't an issue, but obviously this 
isn't generalizable.




Dave Salac

On 12/30/22 17:46, Mark Adams wrote:

Oh, right, you need to convert to a Plex and then write.

I've never read a Forest but you will read in a Plex and I would think 
just convert to a Forest.


Mark

On Fri, Dec 30, 2022 at 9:29 AM Matthew Knepley  wrote:

On Fri, Dec 30, 2022 at 5:59 AM Berend van Wachem
 wrote:

Dear Mark,

Yes, I have tried that. That will only work if I convert the
DMForest to
a DMPlex first, and then write the DMPlex to file. But then, I
cannot
read in a DMForest when I want to continue the calculations
later on.

Below is the code I use to write a DMPlex to file. When I call
this
routine with a DMForest, I get the error:


This is true. I am going to have to look at this with Toby. I will
get back to you.

  THanks,

     Matt

[0]PETSC ERROR: Invalid argument
[0]PETSC ERROR: Wrong type of object: Parameter # 1
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble
shooting.
[0]PETSC ERROR: Petsc Release Version 3.18.2, Nov 28, 2022
[0]PETSC ERROR: ./bin/write_periodic on a linux-gcc-dev named
multiflow.multiflow.org  by
berend Fri Dec 30 11:54:51 2022
[0]PETSC ERROR: Configure options --with-clean
--download-metis=yes
--download-parmetis=yes --download-hdf5 --download-p4est
--download-triangle --download-tetgen
--with-zlib-lib=/usr/lib64/libz.a
--with-zlib-include=/usr/include --with-mpi=yes
--with-mpi-dir=/usr
--with-mpiexec=/usr/bin/mpiexec --download-slepc=yes
--download-fftw=yes
[0]PETSC ERROR: #1 PetscSectionGetChart() at
/usr/local/petsc-3.18.2/src/vec/is/section/interface/section.c:592
[0]PETSC ERROR: #2 DMPlexGetChart() at
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:2702
[0]PETSC ERROR: #3 DMPlexGetDepthStratum() at
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:4882
[0]PETSC ERROR: #4 DMPlexCreatePointNumbering() at
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:8303
[0]PETSC ERROR: #5 DMPlexTopologyView() at
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:1854
[0]PETSC ERROR: #6 WriteDMAndVectortoHDF5File() at
/home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:176
[0]PETSC ERROR: #7 main() at
/home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:555

The code I use to write is:

PetscErrorCode WriteDMAndVectortoHDF5File(DM dm, Vec
*DataVector, const
char *HDF5file)
{
   PetscViewer H5Viewer;
   PetscErrorCode ierr;
   DM dmCopy;
   PetscSection sectionCopy;
   PetscInt i;
   PetscScalar *xVecArray;
   PetscInt numPoints, numPointsCopy;
   Vec vectorCopy;
   PetscScalar *array;

   PetscFunctionBegin;
   ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD, HDF5file,
FILE_MODE_WRITE, );
   CHKERRQ(ierr);
   ierr = PetscObjectSetName((PetscObject) dm, "DM");
   CHKERRQ(ierr);
   ierr = PetscViewerPushFormat(H5Viewer,
PETSC_VIEWER_HDF5_PETSC);
   CHKERRQ(ierr);
   ierr = DMPlexTopologyView(dm, H5Viewer);
   CHKERRQ(ierr);
   ierr = DMPlexLabelsView(dm, H5Viewer);
   CHKERRQ(ierr);
   ierr = DMPlexCoordinatesView(dm, H5Viewer);
   CHKERRQ(ierr);
   ierr = PetscViewerPopFormat(H5Viewer);
   CHKERRQ(ierr);

   ierr = DMClone(dm, );
   CHKERRQ(ierr);
   ierr = PetscObjectSetName((PetscObject) dmCopy, "DM");
   CHKERRQ(ierr);
   ierr = DMGetLocalSection(dm, );
   CHKERRQ(ierr);
   ierr = DMSetLocalSection(dmCopy, sectionCopy);
   CHKERRQ(ierr);

   /* Write the section to the file */
   ierr = DMPlexSectionView(dm, H5Viewer, dmCopy);
   CHKERRQ(ierr);

   ierr = DMGetGlobalVector(dmCopy, );
   CHKERRQ(ierr);

   /*** We have to copy the vector into the new vector ... ***/
   ierr = VecGetArray(vectorCopy, );
   CHKERRQ(ierr);
   ierr = VecGetLocalSize(*DataVector, );
   

Re: [petsc-users] DMLabel Views

2022-12-30 Thread Matthew Knepley
On Fri, Dec 30, 2022 at 7:52 PM Nicholas Arnold-Medabalimi <
narno...@umich.edu> wrote:

> Hi Petsc Users
>
> I'm in the process of tagging cells in a DMPlex for identification before
> a mesh filter. I'm trying to debug some issues related to my tagging
> metrics that is only appearing for more complex meshes. This makes using
> the ASCII DMLabelView a little tedious to parse and I was wondering if
> there is a convenient way to visualize DMLabels on the mesh. At least, from
> what I can tell, I can't send the DMLabel into a VTK file.
>
> I'm considering making a 1 DOF vector and just copying the Label values
> into it and visualizing that, but I wanted to ask if there is a more
> convenient way.
>

There is not. Maybe we should automate that.

  Thanks

Matt


> Sincerely
> Nicholas
>
>
>
>
>
> --
> Nicholas Arnold-Medabalimi
>
> Ph.D. Candidate
> Computational Aeroscience Lab
> University of Michigan
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


[petsc-users] DMLabel Views

2022-12-30 Thread Nicholas Arnold-Medabalimi
Hi Petsc Users

I'm in the process of tagging cells in a DMPlex for identification before a
mesh filter. I'm trying to debug some issues related to my tagging metrics
that is only appearing for more complex meshes. This makes using the ASCII
DMLabelView a little tedious to parse and I was wondering if there is a
convenient way to visualize DMLabels on the mesh. At least, from what I can
tell, I can't send the DMLabel into a VTK file.

I'm considering making a 1 DOF vector and just copying the Label values
into it and visualizing that, but I wanted to ask if there is a more
convenient way.

Sincerely
Nicholas





-- 
Nicholas Arnold-Medabalimi

Ph.D. Candidate
Computational Aeroscience Lab
University of Michigan


Re: [petsc-users] Write/read a DMForest to/from a file

2022-12-30 Thread Mark Adams
Oh, right, you need to convert to a Plex and then write.

I've never read a Forest but you will read in a Plex and I would think just
convert to a Forest.

Mark

On Fri, Dec 30, 2022 at 9:29 AM Matthew Knepley  wrote:

> On Fri, Dec 30, 2022 at 5:59 AM Berend van Wachem <
> berend.vanwac...@ovgu.de> wrote:
>
>> Dear Mark,
>>
>> Yes, I have tried that. That will only work if I convert the DMForest to
>> a DMPlex first, and then write the DMPlex to file. But then, I cannot
>> read in a DMForest when I want to continue the calculations later on.
>>
>> Below is the code I use to write a DMPlex to file. When I call this
>> routine with a DMForest, I get the error:
>>
>
> This is true. I am going to have to look at this with Toby. I will get
> back to you.
>
>   THanks,
>
>  Matt
>
>
>> [0]PETSC ERROR: Invalid argument
>> [0]PETSC ERROR: Wrong type of object: Parameter # 1
>> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.18.2, Nov 28, 2022
>> [0]PETSC ERROR: ./bin/write_periodic on a linux-gcc-dev named
>> multiflow.multiflow.org by berend Fri Dec 30 11:54:51 2022
>> [0]PETSC ERROR: Configure options --with-clean --download-metis=yes
>> --download-parmetis=yes --download-hdf5 --download-p4est
>> --download-triangle --download-tetgen --with-zlib-lib=/usr/lib64/libz.a
>> --with-zlib-include=/usr/include --with-mpi=yes --with-mpi-dir=/usr
>> --with-mpiexec=/usr/bin/mpiexec --download-slepc=yes --download-fftw=yes
>> [0]PETSC ERROR: #1 PetscSectionGetChart() at
>> /usr/local/petsc-3.18.2/src/vec/is/section/interface/section.c:592
>> [0]PETSC ERROR: #2 DMPlexGetChart() at
>> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:2702
>> [0]PETSC ERROR: #3 DMPlexGetDepthStratum() at
>> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:4882
>> [0]PETSC ERROR: #4 DMPlexCreatePointNumbering() at
>> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:8303
>> [0]PETSC ERROR: #5 DMPlexTopologyView() at
>> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:1854
>> [0]PETSC ERROR: #6 WriteDMAndVectortoHDF5File() at
>> /home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:176
>> [0]PETSC ERROR: #7 main() at
>> /home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:555
>>
>> The code I use to write is:
>>
>> PetscErrorCode WriteDMAndVectortoHDF5File(DM dm, Vec *DataVector, const
>> char *HDF5file)
>> {
>>PetscViewer H5Viewer;
>>PetscErrorCode ierr;
>>DM dmCopy;
>>PetscSection sectionCopy;
>>PetscInt i;
>>PetscScalar *xVecArray;
>>PetscInt numPoints, numPointsCopy;
>>Vec vectorCopy;
>>PetscScalar *array;
>>
>>PetscFunctionBegin;
>>ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD, HDF5file,
>> FILE_MODE_WRITE, );
>>CHKERRQ(ierr);
>>ierr = PetscObjectSetName((PetscObject) dm, "DM");
>>CHKERRQ(ierr);
>>ierr = PetscViewerPushFormat(H5Viewer, PETSC_VIEWER_HDF5_PETSC);
>>CHKERRQ(ierr);
>>ierr = DMPlexTopologyView(dm, H5Viewer);
>>CHKERRQ(ierr);
>>ierr = DMPlexLabelsView(dm, H5Viewer);
>>CHKERRQ(ierr);
>>ierr = DMPlexCoordinatesView(dm, H5Viewer);
>>CHKERRQ(ierr);
>>ierr = PetscViewerPopFormat(H5Viewer);
>>CHKERRQ(ierr);
>>
>>ierr = DMClone(dm, );
>>CHKERRQ(ierr);
>>ierr = PetscObjectSetName((PetscObject) dmCopy, "DM");
>>CHKERRQ(ierr);
>>ierr = DMGetLocalSection(dm, );
>>CHKERRQ(ierr);
>>ierr = DMSetLocalSection(dmCopy, sectionCopy);
>>CHKERRQ(ierr);
>>
>>/* Write the section to the file */
>>ierr = DMPlexSectionView(dm, H5Viewer, dmCopy);
>>CHKERRQ(ierr);
>>
>>ierr = DMGetGlobalVector(dmCopy, );
>>CHKERRQ(ierr);
>>
>>/*** We have to copy the vector into the new vector ... ***/
>>ierr = VecGetArray(vectorCopy, );
>>CHKERRQ(ierr);
>>ierr = VecGetLocalSize(*DataVector, );
>>CHKERRQ(ierr);
>>ierr = VecGetLocalSize(vectorCopy, );
>>CHKERRQ(ierr);
>>assert(numPoints == numPointsCopy);
>>ierr = VecGetArray(*DataVector, );
>>CHKERRQ(ierr);
>>
>>for (i = 0; i < numPoints; i++) /* Loop over all internal cells */
>>{
>>  array[i] = xVecArray[i];
>>}
>>
>>ierr = VecRestoreArray(vectorCopy, );
>>CHKERRQ(ierr);
>>ierr = VecRestoreArray(*DataVector, );
>>CHKERRQ(ierr);
>>
>>ierr = PetscObjectSetName((PetscObject) vectorCopy, "DataVector");
>>CHKERRQ(ierr);
>>
>>/* Write the vector to the file */
>>ierr = DMPlexGlobalVectorView(dm, H5Viewer, dmCopy, vectorCopy);
>>CHKERRQ(ierr);
>>
>>/* Close the file */
>>ierr = PetscViewerDestroy();
>>CHKERRQ(ierr);
>>
>>ierr = DMDestroy();
>>CHKERRQ(ierr);
>>/*** End of writing /
>>PetscFunctionReturn(0);
>> }
>>
>>
>>
>>
>>
>> On 29/12/2022 21:54, Mark Adams wrote:
>> > Have you tried using the DMForest as you would use a DMPLex?
>> > That should work. Forst has extra stuff but it just makes a Plex and
>> the
>> > end of the day.
>> >
>> > On Tue, Dec 27, 2022 

Re: [petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread Jed Brown
This is what I'd expect to observe if you didn't preallocate correctly for the 
second matrix, which has more nonzeros per row.

https://petsc.org/release/docs/manual/mat/#sec-matsparse

김성익  writes:

> Hello,
>
>
>
> I have a question about memory of matsetvalue.
>
> When I assembly the local matrix to global matrix, I’m just using
> matsetvalue.
> Because the connectivity is so complex I can’t use matsetvalues.
>
> I asked this question because I was curious about how ram memory is
> allocated differently for the two simtuations below.
>
>
>
> First situation.
>
> The local matrix size is 24 by 24. And the number of local matrix is
> 125,000.
>
> When assembly procedure by using matsetvalue, memory allocation does not
> increase.
> So I just put Matassemblybegin and matassemblyend after all matsetvalue.
>
>
>
> Second situation.
>
> The local matrix size is 60 by 60. And the number of local matrix is 27,000.
>
> When assembly procedure by using matsetvalue, memory allocation does
> increase.
>
> So I just put Matassemblybegin and matassemblyend after each local matrix
> assembly.
> This did not increase the memory further..
>
>
>
> Why this situation is happen?
>
> And is there any way to prevent the memory allocation from increasing?
>
>
>
>
>
>
>
> Thanks,
>
> Hyung Kim


Re: [petsc-users] Write/read a DMForest to/from a file

2022-12-30 Thread Matthew Knepley
On Fri, Dec 30, 2022 at 5:59 AM Berend van Wachem 
wrote:

> Dear Mark,
>
> Yes, I have tried that. That will only work if I convert the DMForest to
> a DMPlex first, and then write the DMPlex to file. But then, I cannot
> read in a DMForest when I want to continue the calculations later on.
>
> Below is the code I use to write a DMPlex to file. When I call this
> routine with a DMForest, I get the error:
>

This is true. I am going to have to look at this with Toby. I will get back
to you.

  THanks,

 Matt


> [0]PETSC ERROR: Invalid argument
> [0]PETSC ERROR: Wrong type of object: Parameter # 1
> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.18.2, Nov 28, 2022
> [0]PETSC ERROR: ./bin/write_periodic on a linux-gcc-dev named
> multiflow.multiflow.org by berend Fri Dec 30 11:54:51 2022
> [0]PETSC ERROR: Configure options --with-clean --download-metis=yes
> --download-parmetis=yes --download-hdf5 --download-p4est
> --download-triangle --download-tetgen --with-zlib-lib=/usr/lib64/libz.a
> --with-zlib-include=/usr/include --with-mpi=yes --with-mpi-dir=/usr
> --with-mpiexec=/usr/bin/mpiexec --download-slepc=yes --download-fftw=yes
> [0]PETSC ERROR: #1 PetscSectionGetChart() at
> /usr/local/petsc-3.18.2/src/vec/is/section/interface/section.c:592
> [0]PETSC ERROR: #2 DMPlexGetChart() at
> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:2702
> [0]PETSC ERROR: #3 DMPlexGetDepthStratum() at
> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:4882
> [0]PETSC ERROR: #4 DMPlexCreatePointNumbering() at
> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:8303
> [0]PETSC ERROR: #5 DMPlexTopologyView() at
> /usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:1854
> [0]PETSC ERROR: #6 WriteDMAndVectortoHDF5File() at
> /home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:176
> [0]PETSC ERROR: #7 main() at
> /home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:555
>
> The code I use to write is:
>
> PetscErrorCode WriteDMAndVectortoHDF5File(DM dm, Vec *DataVector, const
> char *HDF5file)
> {
>PetscViewer H5Viewer;
>PetscErrorCode ierr;
>DM dmCopy;
>PetscSection sectionCopy;
>PetscInt i;
>PetscScalar *xVecArray;
>PetscInt numPoints, numPointsCopy;
>Vec vectorCopy;
>PetscScalar *array;
>
>PetscFunctionBegin;
>ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD, HDF5file,
> FILE_MODE_WRITE, );
>CHKERRQ(ierr);
>ierr = PetscObjectSetName((PetscObject) dm, "DM");
>CHKERRQ(ierr);
>ierr = PetscViewerPushFormat(H5Viewer, PETSC_VIEWER_HDF5_PETSC);
>CHKERRQ(ierr);
>ierr = DMPlexTopologyView(dm, H5Viewer);
>CHKERRQ(ierr);
>ierr = DMPlexLabelsView(dm, H5Viewer);
>CHKERRQ(ierr);
>ierr = DMPlexCoordinatesView(dm, H5Viewer);
>CHKERRQ(ierr);
>ierr = PetscViewerPopFormat(H5Viewer);
>CHKERRQ(ierr);
>
>ierr = DMClone(dm, );
>CHKERRQ(ierr);
>ierr = PetscObjectSetName((PetscObject) dmCopy, "DM");
>CHKERRQ(ierr);
>ierr = DMGetLocalSection(dm, );
>CHKERRQ(ierr);
>ierr = DMSetLocalSection(dmCopy, sectionCopy);
>CHKERRQ(ierr);
>
>/* Write the section to the file */
>ierr = DMPlexSectionView(dm, H5Viewer, dmCopy);
>CHKERRQ(ierr);
>
>ierr = DMGetGlobalVector(dmCopy, );
>CHKERRQ(ierr);
>
>/*** We have to copy the vector into the new vector ... ***/
>ierr = VecGetArray(vectorCopy, );
>CHKERRQ(ierr);
>ierr = VecGetLocalSize(*DataVector, );
>CHKERRQ(ierr);
>ierr = VecGetLocalSize(vectorCopy, );
>CHKERRQ(ierr);
>assert(numPoints == numPointsCopy);
>ierr = VecGetArray(*DataVector, );
>CHKERRQ(ierr);
>
>for (i = 0; i < numPoints; i++) /* Loop over all internal cells */
>{
>  array[i] = xVecArray[i];
>}
>
>ierr = VecRestoreArray(vectorCopy, );
>CHKERRQ(ierr);
>ierr = VecRestoreArray(*DataVector, );
>CHKERRQ(ierr);
>
>ierr = PetscObjectSetName((PetscObject) vectorCopy, "DataVector");
>CHKERRQ(ierr);
>
>/* Write the vector to the file */
>ierr = DMPlexGlobalVectorView(dm, H5Viewer, dmCopy, vectorCopy);
>CHKERRQ(ierr);
>
>/* Close the file */
>ierr = PetscViewerDestroy();
>CHKERRQ(ierr);
>
>ierr = DMDestroy();
>CHKERRQ(ierr);
>/*** End of writing /
>PetscFunctionReturn(0);
> }
>
>
>
>
>
> On 29/12/2022 21:54, Mark Adams wrote:
> > Have you tried using the DMForest as you would use a DMPLex?
> > That should work. Forst has extra stuff but it just makes a Plex and the
> > end of the day.
> >
> > On Tue, Dec 27, 2022 at 5:21 AM Berend van Wachem
> > mailto:berend.vanwac...@ovgu.de>> wrote:
> >
> > Dear Petsc-team/users,
> >
> > I am trying to save a DMForest which has been used for a calculation
> > (so
> > refined/coarsened in places) to a file and later read it from the
> file
> > to continue a calculation with.
> > My question is: how do I do this? I've tried a few things, such as

Re: [petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread Matthew Knepley
On Fri, Dec 30, 2022 at 4:36 AM 김성익  wrote:

> Hello,
>
>
>
> I have a question about memory of matsetvalue.
>
> When I assembly the local matrix to global matrix, I’m just using
> matsetvalue.
> Because the connectivity is so complex I can’t use matsetvalues.
>
> I asked this question because I was curious about how ram memory is
> allocated differently for the two simtuations below.
>
>
>
> First situation.
>
> The local matrix size is 24 by 24. And the number of local matrix is
> 125,000.
>
> When assembly procedure by using matsetvalue, memory allocation does not
> increase.
> So I just put Matassemblybegin and matassemblyend after all matsetvalue.
>
>
>
> Second situation.
>
> The local matrix size is 60 by 60. And the number of local matrix is
> 27,000.
>
> When assembly procedure by using matsetvalue, memory allocation does
> increase.
>
> So I just put Matassemblybegin and matassemblyend after each local matrix
> assembly.
> This did not increase the memory further..
>
>
>
> Why this situation is happen?
>
> And is there any way to prevent the memory allocation from increasing?
>

Matrix assembly has two stages. First you insert entries into the local
portion of your parallel matrix
using MatSetValue(s). If all values you try to insert are local, this is
the end.

However, if you try to insert values that are local to another process, we
store those values. When you
call MatAssemblyBegin/End(), we communicate them to the correct process and
insert.

For a scalable code, you should insert most values on the correct process.
If not, significant memory
can be consumed storing these values. Anywhere in the assembly process you
can call

  MatAssemblyBegin(A, MAT_ASSEMBLY_FLUSH);
  MatAssemblyEnd(A, MAT_ASSEMBLY_FLUSH);

This will communicate the cache of values, but not end the assembly.

   Thanks,

   Matt



> Thanks,
>
> Hyung Kim
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


Re: [petsc-users] Write/read a DMForest to/from a file

2022-12-30 Thread Berend van Wachem

Dear Mark,

Yes, I have tried that. That will only work if I convert the DMForest to 
a DMPlex first, and then write the DMPlex to file. But then, I cannot 
read in a DMForest when I want to continue the calculations later on.


Below is the code I use to write a DMPlex to file. When I call this 
routine with a DMForest, I get the error:


[0]PETSC ERROR: Invalid argument
[0]PETSC ERROR: Wrong type of object: Parameter # 1
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.18.2, Nov 28, 2022
[0]PETSC ERROR: ./bin/write_periodic on a linux-gcc-dev named 
multiflow.multiflow.org by berend Fri Dec 30 11:54:51 2022
[0]PETSC ERROR: Configure options --with-clean --download-metis=yes 
--download-parmetis=yes --download-hdf5 --download-p4est 
--download-triangle --download-tetgen --with-zlib-lib=/usr/lib64/libz.a 
--with-zlib-include=/usr/include --with-mpi=yes --with-mpi-dir=/usr 
--with-mpiexec=/usr/bin/mpiexec --download-slepc=yes --download-fftw=yes
[0]PETSC ERROR: #1 PetscSectionGetChart() at 
/usr/local/petsc-3.18.2/src/vec/is/section/interface/section.c:592
[0]PETSC ERROR: #2 DMPlexGetChart() at 
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:2702
[0]PETSC ERROR: #3 DMPlexGetDepthStratum() at 
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:4882
[0]PETSC ERROR: #4 DMPlexCreatePointNumbering() at 
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:8303
[0]PETSC ERROR: #5 DMPlexTopologyView() at 
/usr/local/petsc-3.18.2/src/dm/impls/plex/plex.c:1854
[0]PETSC ERROR: #6 WriteDMAndVectortoHDF5File() at 
/home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:176
[0]PETSC ERROR: #7 main() at 
/home/berend/git/Code/petsc-dmplex-restart-test/src/createandwrite.c:555


The code I use to write is:

PetscErrorCode WriteDMAndVectortoHDF5File(DM dm, Vec *DataVector, const 
char *HDF5file)

{
  PetscViewer H5Viewer;
  PetscErrorCode ierr;
  DM dmCopy;
  PetscSection sectionCopy;
  PetscInt i;
  PetscScalar *xVecArray;
  PetscInt numPoints, numPointsCopy;
  Vec vectorCopy;
  PetscScalar *array;

  PetscFunctionBegin;
  ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD, HDF5file, 
FILE_MODE_WRITE, );

  CHKERRQ(ierr);
  ierr = PetscObjectSetName((PetscObject) dm, "DM");
  CHKERRQ(ierr);
  ierr = PetscViewerPushFormat(H5Viewer, PETSC_VIEWER_HDF5_PETSC);
  CHKERRQ(ierr);
  ierr = DMPlexTopologyView(dm, H5Viewer);
  CHKERRQ(ierr);
  ierr = DMPlexLabelsView(dm, H5Viewer);
  CHKERRQ(ierr);
  ierr = DMPlexCoordinatesView(dm, H5Viewer);
  CHKERRQ(ierr);
  ierr = PetscViewerPopFormat(H5Viewer);
  CHKERRQ(ierr);

  ierr = DMClone(dm, );
  CHKERRQ(ierr);
  ierr = PetscObjectSetName((PetscObject) dmCopy, "DM");
  CHKERRQ(ierr);
  ierr = DMGetLocalSection(dm, );
  CHKERRQ(ierr);
  ierr = DMSetLocalSection(dmCopy, sectionCopy);
  CHKERRQ(ierr);

  /* Write the section to the file */
  ierr = DMPlexSectionView(dm, H5Viewer, dmCopy);
  CHKERRQ(ierr);

  ierr = DMGetGlobalVector(dmCopy, );
  CHKERRQ(ierr);

  /*** We have to copy the vector into the new vector ... ***/
  ierr = VecGetArray(vectorCopy, );
  CHKERRQ(ierr);
  ierr = VecGetLocalSize(*DataVector, );
  CHKERRQ(ierr);
  ierr = VecGetLocalSize(vectorCopy, );
  CHKERRQ(ierr);
  assert(numPoints == numPointsCopy);
  ierr = VecGetArray(*DataVector, );
  CHKERRQ(ierr);

  for (i = 0; i < numPoints; i++) /* Loop over all internal cells */
  {
array[i] = xVecArray[i];
  }

  ierr = VecRestoreArray(vectorCopy, );
  CHKERRQ(ierr);
  ierr = VecRestoreArray(*DataVector, );
  CHKERRQ(ierr);

  ierr = PetscObjectSetName((PetscObject) vectorCopy, "DataVector");
  CHKERRQ(ierr);

  /* Write the vector to the file */
  ierr = DMPlexGlobalVectorView(dm, H5Viewer, dmCopy, vectorCopy);
  CHKERRQ(ierr);

  /* Close the file */
  ierr = PetscViewerDestroy();
  CHKERRQ(ierr);

  ierr = DMDestroy();
  CHKERRQ(ierr);
  /*** End of writing /
  PetscFunctionReturn(0);
}





On 29/12/2022 21:54, Mark Adams wrote:

Have you tried using the DMForest as you would use a DMPLex?
That should work. Forst has extra stuff but it just makes a Plex and the 
end of the day.


On Tue, Dec 27, 2022 at 5:21 AM Berend van Wachem 
mailto:berend.vanwac...@ovgu.de>> wrote:


Dear Petsc-team/users,

I am trying to save a DMForest which has been used for a calculation
(so
refined/coarsened in places) to a file and later read it from the file
to continue a calculation with.
My question is: how do I do this? I've tried a few things, such as
using
DMView and DMLoad, and saving the BaseDM, but that doesn't seem to save
the refining/coarsening which has taken place in the initial
calculation.
I haven't been able to find any example or documentation for this. Any
pointers or examples would be very much appreciated!

Best regards, Berend.



[petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread 김성익
Hello,



I have a question about memory of matsetvalue.

When I assembly the local matrix to global matrix, I’m just using
matsetvalue.
Because the connectivity is so complex I can’t use matsetvalues.

I asked this question because I was curious about how ram memory is
allocated differently for the two simtuations below.



First situation.

The local matrix size is 24 by 24. And the number of local matrix is
125,000.

When assembly procedure by using matsetvalue, memory allocation does not
increase.
So I just put Matassemblybegin and matassemblyend after all matsetvalue.



Second situation.

The local matrix size is 60 by 60. And the number of local matrix is 27,000.

When assembly procedure by using matsetvalue, memory allocation does
increase.

So I just put Matassemblybegin and matassemblyend after each local matrix
assembly.
This did not increase the memory further..



Why this situation is happen?

And is there any way to prevent the memory allocation from increasing?







Thanks,

Hyung Kim