[petsc-users] petsc-users Digest, Vol 26, Issue 31

Kontsantinos Kontzialis ckontzialis at lycos.com
Sun Feb 13 21:09:51 CST 2011


On 02/14/2011 04:38 AM, petsc-users-request at mcs.anl.gov wrote:
> Send petsc-users mailing list submissions to
> 	petsc-users at mcs.anl.gov
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	https://lists.mcs.anl.gov/mailman/listinfo/petsc-users
> or, via email, send a message with subject or body 'help' to
> 	petsc-users-request at mcs.anl.gov
>
> You can reach the person managing the list at
> 	petsc-users-owner at mcs.anl.gov
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of petsc-users digest..."
>
>
> Today's Topics:
>
>     1.  Better way to pre-allocate memory for matrix being	read in
>        ??? (Gaurish Telang)
>     2. Re:  Better way to pre-allocate memory for matrix being read
>        in ??? (Jed Brown)
>     3.  Question on LOCDIR (Gaurish Telang)
>     4. Re:  petsc-users Digest, Vol 26, Issue 30
>        (Kontsantinos Kontzialis)
>     5. Re:  petsc-users Digest, Vol 26, Issue 30 (Matthew Knepley)
>     6. Re:  petsc-users Digest, Vol 26, Issue 30
>        (Kontsantinos Kontzialis)
>     7. Re:  Question on LOCDIR (Barry Smith)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 13 Feb 2011 17:37:11 -0500
> From: Gaurish Telang<gaurish108 at gmail.com>
> Subject: [petsc-users] Better way to pre-allocate memory for matrix
> 	being	read in ???
> To: petsc-users at mcs.anl.gov
> Message-ID:
> 	<AANLkTin-XQ1Dgp=e8gxEMjy+wmyODz3uphjjeTa94awv at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I have a text file containing the non-zero entries of a sparse matrix of
> dimension 2683x1274, stored in the form (row, column, element) i.e. [i, j,
> element] format.
>
> That is ALL the information I have regarding the matrix.
>
> However when pre-allocating memory with  MatSeqAIJSetPreallocation(Mat
> B,PetscInt nz,const PetscInt nnz[]),  the parameters nz and nnz need to be
> known,
>
> nz=number of nonzeros per row (same for all rows)
> nnz=array containing the number of nonzeros in the various rows (possibly
> different for each row) or
> PETSC_NULL<http://www.mcs.anl.gov/petsc/petsc-2/snapshots/petsc-dev/docs/manualpages/Sys/PETSC_NULL.html#PETSC_NULL>
>
> which i do not know for my matrix, ( unless I resort to using MATLAB. ).
>
> Does that mean I have to set nz= 1274 (the length of a row) and
> nnz=PETSC_NULL ?  Though,  I guess this setting would consume a lot of
> memory for higher order matrices.
>
> How then, should I go about memory pre-allocation more efficiently?
>
> Thanks,
> Gaurish Telang
>
>
>
>
>
>
>
>
>
> There is a code in the PETSc folder (/src/mat/examples/tests/ex78.c ) which
> reads in a matrix of this format.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:<http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110213/72d7080a/attachment-0001.htm>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 13 Feb 2011 23:47:46 +0100
> From: Jed Brown<jed at 59A2.org>
> Subject: Re: [petsc-users] Better way to pre-allocate memory for
> 	matrix being read in ???
> To: PETSc users list<petsc-users at mcs.anl.gov>
> Message-ID:
> 	<AANLkTi=0gsQKxaQwRinKc1ybwett5vf1qE0k4oZUvDgv at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Sun, Feb 13, 2011 at 23:37, Gaurish Telang<gaurish108 at gmail.com>  wrote:
>
>> I have a text file containing the non-zero entries of a sparse matrix of
>> dimension 2683x1274, stored in the form (row, column, element) i.e. [i, j,
>> element] format.
>>
> This is a horrible format and can not scale. If it becomes a performance
> issue, change the format.
>
>
>> That is ALL the information I have regarding the matrix.
>>
>> However when pre-allocating memory with  MatSeqAIJSetPreallocation(Mat
>> B,PetscInt nz,const PetscInt nnz[]),  the parameters nz and nnz need to be
>> known,
>>
>> nz=number of nonzeros per row (same for all rows)
>> nnz=array containing the number of nonzeros in the various rows (possibly
>> different for each row) or PETSC_NULL<http://www.mcs.anl.gov/petsc/petsc-2/snapshots/petsc-dev/docs/manualpages/Sys/PETSC_NULL.html#PETSC_NULL>
>>
>> which i do not know for my matrix, ( unless I resort to using MATLAB. ).
>>
>> Does that mean I have to set nz= 1274 (the length of a row) and
>> nnz=PETSC_NULL ?
>>
> No, read the file twice. The first time through, just count the number of
> nonzeros (per row), then set preallocation with the correct size, and
> finally read the file a second time calling MatSetValue() for each entry.
>
> For a matrix this small, you could just read it in without preallocating,
> but that will get too expensive quickly if you increase the matrix size.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:<http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110213/3e8b77eb/attachment-0001.htm>
>
> ------------------------------
>
> Message: 3
> Date: Sun, 13 Feb 2011 19:16:47 -0500
> From: Gaurish Telang<gaurish108 at gmail.com>
> Subject: [petsc-users] Question on LOCDIR
> To: petsc-users at mcs.anl.gov
> Message-ID:
> 	<AANLkTi=pCn+C1zJK2qdFi0iJhekgOBLsWAdeFbU5TaN5 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I notice that in the tutorial codes in $PETSC_DIR , the makefiles have the
> LOCDIR variable defined at the top, to be the current working directory.
> Whereas in the makefile chapter of the manual,
>
> the given template makefile has no mention of the LOCDIR variable. So, what
> is the significance of this variable?
>
> My PETSc programs seem to compile fine without introducing it into my
> makefile.
>
> Gaurish
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:<http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110213/984ec05b/attachment-0001.htm>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 14 Feb 2011 04:12:13 +0200
> From: Kontsantinos Kontzialis<ckontzialis at lycos.com>
> Subject: Re: [petsc-users] petsc-users Digest, Vol 26, Issue 30
> To: petsc-users at mcs.anl.gov
> Message-ID:<4D588F7D.2060209 at lycos.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 02/13/2011 08:00 PM, petsc-users-request at mcs.anl.gov wrote:
>> Send petsc-users mailing list submissions to
>> 	petsc-users at mcs.anl.gov
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> 	https://lists.mcs.anl.gov/mailman/listinfo/petsc-users
>> or, via email, send a message with subject or body 'help' to
>> 	petsc-users-request at mcs.anl.gov
>>
>> You can reach the person managing the list at
>> 	petsc-users-owner at mcs.anl.gov
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of petsc-users digest..."
>>
>>
>> Today's Topics:
>>
>>      1. Re:  Guidelines for solving the euler equations with an
>>         implicit matrix free approach (Matthew Knepley)
>>      2.  Reading vtk file in parallel and assigning to an array
>>         (khalid ashraf)
>>      3. Re:  Reading vtk file in parallel and assigning to an	array
>>         (Matthew Knepley)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Sat, 12 Feb 2011 16:12:36 -0600
>> From: Matthew Knepley<knepley at gmail.com>
>> Subject: Re: [petsc-users] Guidelines for solving the euler equations
>> 	with an implicit matrix free approach
>> To: PETSc users list<petsc-users at mcs.anl.gov>
>> Message-ID:
>> 	<AANLkTimus8N2jUu7Bvu0TZe59dr4FTpoJFh+m0QQUN-V at mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> On Fri, Feb 11, 2011 at 10:37 AM, Kontsantinos Kontzialis<
>> ckontzialis at lycos.com>   wrote:
>>
>>> Dear Petsc team,
>>>
>>>    I'm new in Petsc and I'm trying to solve the euler equations of fluid
>>> dynamics
>>> using an implicit matrix free approach with a spatial discontinues galerkin
>>> discretization.
>>> I need some directions about how can I solve the following system:
>>>
>>> (M/dt+dR/du)*DU=R
>>>
>>> where R denotes the residual of the system and dR/du the residual jacobian.
>>> Please help.
>>>
>> Petsc provides linear algebra and nonlinear solvers. This is fine once you
>> have discretized.
>> It sounds like you will use DG:
>>
>>     a) on a structured or unstructured grid?
>>
>> The PETSc DA supports structured grids in any dimension. After this, you
>> want to use the
>> TS object to present your system. There are many examples in the TS, e.g.
>> ex10 for
>> radiation-diffusion or ex14 for hydrostatic ice flow.
>>
>> Once you have your problem producing the correct residual and Jacobian, we
>> can talk
>> about solvers.
>>
>>      Matt
>>
>>
>>> Kostas
>>>
> Mat,
>
> Thank you for your reply. I have done the discretization and the
> residual and jacobian are computes correctly. Furthermore, I managed to
> do some calculation using TS but with an explicit scheme. I need to work
> with an implicit time discretization and I have read in a quite few
> papers that they follow the matrix free approach.
>
> Thank you,
>
> Kostas
>
>
> ------------------------------
>
> Message: 5
> Date: Sun, 13 Feb 2011 20:18:42 -0600
> From: Matthew Knepley<knepley at gmail.com>
> Subject: Re: [petsc-users] petsc-users Digest, Vol 26, Issue 30
> To: PETSc users list<petsc-users at mcs.anl.gov>
> Message-ID:
> 	<AANLkTikEmwG1n1aqBcqthQP0Y=0RSSa0njhgz6k=6-Hs at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Sun, Feb 13, 2011 at 8:12 PM, Kontsantinos Kontzialis<
> ckontzialis at lycos.com>  wrote:
>
>> Message: 1
>>> Date: Sat, 12 Feb 2011 16:12:36 -0600
>>> From: Matthew Knepley<knepley at gmail.com>
>>> Subject: Re: [petsc-users] Guidelines for solving the euler equations
>>>         with an implicit matrix free approach
>>> To: PETSc users list<petsc-users at mcs.anl.gov>
>>> Message-ID:
>>>         <AANLkTimus8N2jUu7Bvu0TZe59dr4FTpoJFh+m0QQUN-V at mail.gmail.com>
>>> Content-Type: text/plain; charset="iso-8859-1"
>>>
>>> On Fri, Feb 11, 2011 at 10:37 AM, Kontsantinos Kontzialis<
>>> ckontzialis at lycos.com>   wrote:
>>>
>>>   Dear Petsc team,
>>>>   I'm new in Petsc and I'm trying to solve the euler equations of fluid
>>>> dynamics
>>>> using an implicit matrix free approach with a spatial discontinues
>>>> galerkin
>>>> discretization.
>>>> I need some directions about how can I solve the following system:
>>>>
>>>> (M/dt+dR/du)*DU=R
>>>>
>>>> where R denotes the residual of the system and dR/du the residual
>>>> jacobian.
>>>> Please help.
>>>>
>>>>   Petsc provides linear algebra and nonlinear solvers. This is fine once
>>> you
>>> have discretized.
>>> It sounds like you will use DG:
>>>
>>>    a) on a structured or unstructured grid?
>>>
>>> The PETSc DA supports structured grids in any dimension. After this, you
>>> want to use the
>>> TS object to present your system. There are many examples in the TS, e.g.
>>> ex10 for
>>> radiation-diffusion or ex14 for hydrostatic ice flow.
>>>
>>> Once you have your problem producing the correct residual and Jacobian, we
>>> can talk
>>> about solvers.
>>>
>>>     Matt
>>>
>>>
>>>   Kostas
>>>>   Mat,
>> Thank you for your reply. I have done the discretization and the residual
>> and jacobian are computes correctly. Furthermore, I managed to do some
>> calculation using TS but with an explicit scheme. I need to work with an
>> implicit time discretization and I have read in a quite few papers that they
>> follow the matrix free approach.
>>
> Once you plug your Residual and Jacobian into the TS, you can start to try
> out different solvers. Is this working?
>
>    Thanks,
>
>       Matt
>
>
>> Thank you,
>>
>> Kostas
>>
>
>
Matt,

here is a fragment from my code where I try to work on the implicit scheme

// Apply initial conditions
     ierr = initial_conditions(sys);
     CHKERRQ(ierr);

     ierr = TSCreate(sys.comm, &sys.ts);
     CHKERRQ(ierr);

     ierr = TSSetSolution(sys.ts, sys.gsv);
     CHKERRQ(ierr);

     ierr = TSSetFromOptions(sys.ts);
     CHKERRQ(ierr);

     ierr = TSSetProblemType(sys.ts, TS_NONLINEAR);
     CHKERRQ(ierr);

     ierr = TSSetType(sys.ts, TSBEULER);
     CHKERRQ(ierr);

     ierr = TSSetRHSFunction(sys.ts, base_residual, &sys);
     CHKERRQ(ierr);

     ierr = TSGetSNES(sys.ts, &sys.snes);
     CHKERRQ(ierr);

     ierr = SNESSetFromOptions(sys.snes);
     CHKERRQ(ierr);

     ierr = MatCreateSNESMF(sys.snes, &sys.J);
     CHKERRQ(ierr);

     ierr = TSSetRHSJacobian(sys.ts, sys.J, sys.J, jacobian_matrix, &sys);
     CHKERRQ(ierr);

     ierr = SNESGetKSP(sys.snes, &sys.ksp);
     CHKERRQ(ierr)

     ierr = MatScale(sys.M, 1.0 / sys.con->dt);
     CHKERRQ(ierr);

     ierr = MatAYPX(sys.J, -1.0, sys.M, DIFFERENT_NONZERO_PATTERN);
     CHKERRQ(ierr);

     ierr = KSPSetOperators(sys.ksp, sys.J, sys.J, SAME_NONZERO_PATTERN);
     CHKERRQ(ierr);

     sys.con->j = 0;
     sys.con->tm = 0;

     ierr = TSSetDuration(sys.ts, 10000, sys.con->etime);
     CHKERRQ(ierr);

     ierr = TSMonitorSet(sys.ts, monitor, &sys, PETSC_NULL);
     CHKERRQ(ierr);

     ierr = PetscMalloc (sys.ldof*sizeof (PetscScalar ),&sys.Lim);
     CHKERRQ(ierr);

     ierr = TSSetSolution(sys.ts, PETSC_NULL);
     CHKERRQ(ierr);

sys is my application context. Petsc tells me that I should call first 
the snessetfunction due to
MatCreateSNESMF, 'cause I want to use an MF approach. what can I do? on 
an explicit run I do
not use the jacobian, but how can I use it there now with a MF? Im confused.

Thank you,

kostas


More information about the petsc-users mailing list