<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi Matt, I don't think what you said concerning <span style="font-family: 'Times New Roman'; font-size: 16px;">using -pc_mg_galerkin to have it projected is what I'm looking for.
What I try to do is the following:</span>
<div><font face="Times New Roman" size="3">I already have </font><span style="font-family: Menlo; font-size: 11px;">ComputeRHS and </span><span style="font-family: Menlo; font-size: 11px;">ComputeMatrix, and hence:</span></div>
<div>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
ierr = KSPSetComputeRHS(ksp,ComputeRHS,<span style="color: #bb2ca2">NULL</span>);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
ierr = KSPSetComputeOperators(ksp,ComputeMatrix,<span style="color: #bb2ca2">NULL</span>);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
ierr = KSPSolve(ksp,<span style="color: rgb(187, 44, 162);">NULL</span>,<span style="color: rgb(187, 44, 162);">NULL</span>);CHKERRQ(ierr);</p>
<div><font face="Times New Roman" size="3"><br>
</font></div>
<div><font face="Times New Roman" size="3">Now I have a vector v, let's say:</font></div>
<div><font face="Times New Roman" size="3"><span class="Apple-tab-span" style="white-space:pre"></span></font><span style="font-family: Menlo; font-size: 11px;">ierr = KSPGetSolution(ksp,&v);CHKERRQ(ierr);</span></div>
<div><span style="font-family: Menlo; font-size: 11px;"><br>
</span></div>
<div><span style="font-family: 'Times New Roman'; font-size: medium;">After that, I want so set v to be my rhs, and solve the new system. It doesn't seem that something like this would work: </span></div>
<div>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
ierr = KSPSolve(ksp,&x,&x);CHKERRQ(ierr);</p>
</div>
<div><font face="Times New Roman" size="3"><br>
</font></div>
<div><font face="Times New Roman" size="3">So how do I set x to the rhs? It does not seem to me that </font><span style="font-family: 'Times New Roman'; font-size: 16px;">-pc_mg_galerkin would set x as the rhs of the system. </span></div>
<div><span style="font-family: 'Times New Roman'; font-size: 16px;"><br>
</span></div>
<div><font face="Times New Roman" size="3"><br>
</font>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF450586" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> Matthew Knepley [knepley@gmail.com]<br>
<b>Sent:</b> Sunday, March 01, 2015 6:02 AM<br>
<b>To:</b> Sun, Hui<br>
<b>Cc:</b> Barry Smith; petsc-users@mcs.anl.gov<br>
<b>Subject:</b> Re: [petsc-users] DMDA with dof=4, multigrid solver<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Sun, Mar 1, 2015 at 12:30 AM, Sun, Hui <span dir="ltr">
<<a href="mailto:hus003@ucsd.edu" target="_blank">hus003@ucsd.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Thank you Barry. I have yet two more questions:<br>
<br>
1) If I have a DMDA and I use KSPSetComputeOperators and KSPSetComputeRHS to set up matrices and rhs, and I use geometric mg, what if I want to change my rhs many times? Should I write many KSPSetComputeRHS, and register them with ksp? Or is there a simple
way to just register the rhs with ksp as a vector?<br>
</blockquote>
<div><br>
</div>
<div>If you just give a vector, you could use -pc_mg_galerkin to have it projected. Same with the matrix.</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
2) How do I create a Mat, whose cols follow the DMDA parallelization, and whose rows are serial?<br>
</blockquote>
<div><br>
</div>
<div>Sparse matrices are always divided by rows across processors.</div>
<div><br>
</div>
<div> Thanks,</div>
<div><br>
</div>
<div> Matt</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
By the way, I've figured out and fixed the bugs in my code concerning using mg with DMDA having 4 dof. It has to do with the interpolations. Now I can see mg works well with 4 dof DMDA.<br>
<br>
Best,<br>
Hui<br>
<br>
________________________________________<br>
From: Barry Smith [<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>]<br>
Sent: Saturday, February 28, 2015 9:35 AM<br>
To: Sun, Hui<br>
Cc: <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
Subject: Re: [petsc-users] DMDA with dof=4, multigrid solver<br>
<br>
> On Feb 27, 2015, at 7:25 PM, Sun, Hui <<a href="mailto:hus003@ucsd.edu" target="_blank">hus003@ucsd.edu</a>> wrote:<br>
><br>
> Thank you Barry. Another question: I observe that in those ksp examples, whenever multigrid is used, DMDA is also used, besides, KSPSetComputeOperators and KSPSetComputeRHS are also used.<br>
><br>
> Is it true that<br>
> 1) Only DMDA can use mg?<br>
<br>
No this is not true<br>
<br>
> 2) We have to set up matrices and rhs using KSPSetComputeOperators and KSPSetComputeRHS?<br>
<br>
No you do not have to<br>
<br>
> We cannot create a matrix and add it to KSP if we want to use mg?<br>
<br>
Yes you can.<br>
<br>
There are many many variants of multigrid one can do with PETSc; we don't have the time to have examples of all the possibilities.<br>
<br>
More details<br>
<br>
> 1) Only DMDA can use mg?<br>
<br>
Because DMDA provides structured grids with easy interpolation between levels and it is easy for users to write Jacobians we have many examples that use the DMDA. However, so long as YOU (or something) can provide interpolation between the multigrid levels
you can use multigrid. For example PCGAMG uses algebraic multigrid to generate the interpolations. If you have your own interpolations you can provide them with PCMGSetInterpolation() (when you use PCMG with DMDA PETSc essentially handles those details automatically
for you).<br>
<br>
> 2) We have to set up matrices and rhs using KSPSetComputeOperators and KSPSetComputeRHS?<br>
<br>
Normally with geometric multigrid one discretizes the operator on each level of the grid. Thus the user has to provide several matrices (one for each level). KSPSetComputeOperators() is ONE way that the user can provide them. You can also provide them by
call PCMGetSmoother(pc,level,&ksp) and then call KSPSetOperators(ksp,...) for each of the levels (KSPSetComputeOperators() essentially does the book keeping for you).<br>
<br>
> We cannot create a matrix and add it to KSP if we want to use mg?<br>
<br>
As I said in 2 normally multigrid requires you to provide a discretized operator at each level. But with Galerkin coarse grids (which is what algebraic multigrid users and can also be used by geometric multigrid) the user does not provide coarser grid operators
instead the code computes them automatically from the formula R*A*P where R is the restriction operator used in multigrid and P is the interpolation operator (usually the transpose of P).<br>
<br>
If you are looking for a simple automatic multigrid then you want to use PCGAMG in PETSc, it does algebraic multigrid and doesn't require you provide interpolations or coarser operators. However algebraic multigrid doesn't work for all problems; though it
does work for many. Try it with -pc_type gamg<br>
<br>
Barry<br>
<br>
><br>
> Best,<br>
> Hui<br>
><br>
> ________________________________________<br>
> From: Barry Smith [<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>]<br>
> Sent: Friday, February 27, 2015 5:11 PM<br>
> To: Sun, Hui<br>
> Cc: <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
> Subject: Re: [petsc-users] DMDA with dof=4, multigrid solver<br>
><br>
>> On Feb 27, 2015, at 6:36 PM, Sun, Hui <<a href="mailto:hus003@ucsd.edu" target="_blank">hus003@ucsd.edu</a>> wrote:<br>
>><br>
>> I'm trying to work on 4 Poisson's equations defined on a DMDA grid, Hence the parameter dof in DMDACreate3d should be 4, and I've set stencil width to be 4, and stencil type to be star.<br>
><br>
> Use a stencil width of 1, not 4. The stencil width is defined in terms of dof.<br>
>><br>
>> If I run the code with -pc_type ilu and -ksp_type gmres, it works alright.<br>
>><br>
>> However, if I run with pc_type mg, it gives me an error saying that when it is doing MatSetValues, the argument is out of range, and there is a new nonzero at (60,64) in the matrix. However, that new nonzero is expected to be there, the row number 60 corresponds
to i=15 and c=0 in x direction, and the column number 64 corresponds to i=16 and c=0 in x direction. So they are next to each other, and the star stencil with width 1 should include that. I have also checked with the memory allocations, and I'm found no problem.<br>
>><br>
>> So I'm wondering if there is any problem of using multigrid on a DMDA with dof greater than 1?<br>
><br>
> No it handles dof > 1 fine.<br>
><br>
> Send your code.<br>
><br>
> Barry<br>
><br>
>><br>
>> Thank you!<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="gmail_signature">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>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>