<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Yes, I think that makes sense to me. Each cell is at i,j but then you can set the 25 coefficients per node using MatStencil_c from 0 to 4 for both idxm and idxn.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for your help.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Lucas<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Matthew Knepley <knepley@gmail.com><br>
<b>Sent:</b> Friday, May 29, 2020 12:47 PM<br>
<b>To:</b> Lucas Banting <bantingl@myumanitoba.ca><br>
<b>Cc:</b> petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov><br>
<b>Subject:</b> Re: [petsc-users] How to use MatSetValuesStencil() with DOF>1</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">On Fri, May 29, 2020 at 12:16 PM Lucas Banting <<a href="mailto:bantingl@myumanitoba.ca">bantingl@myumanitoba.ca</a>> wrote:<br>
</div>
<div class="x_gmail_quote">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hello,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I have a structured grid problem with 5 unknowns per cell: U,V,P,T,F, this is a CFD code but I don't think these details are necessary to answer my question.
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I was wondering how exactly I should use MatSetValuesStencil() to fill my matrix.</div>
<div>I<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> have 5 degrees of freedom, so I need to set up to 25 coefficients per grid cell. I don't understand how i,j, and c map to all
coefficients.</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"><br>
</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">For a 1 degree of freedom system to fill my 9 point stencil I did:</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"><br>
</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"></span><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">
values(1)= ASW(II,JJ)</span><span><br>
</span>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(2)= AS (II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(3)= ASE(II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(4)= AW (II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(5)= AP (II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(6)= AE (II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(7)= ANW(II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(8)= AN (II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> values(9)= ANE(II,JJ)</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">
</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxm(MatStencil_i,1) = II;idxm(MatStencil_j,1) = JJ</span></div>
<div><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,1) = II-1;idxn(MatStencil_j,1) = JJ-1</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,2) = II ;idxn(MatStencil_j,2) = JJ-1</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,3) = II+1;idxn(MatStencil_j,3) = JJ-1</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,4) = II-1 ;idxn(MatStencil_j,4) = JJ</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,5) = II ;idxn(MatStencil_j,5) = JJ</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,6) = II+1;idxn(MatStencil_j,6) = JJ</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,7) = II-1 ;idxn(MatStencil_j,7) = JJ+1</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,8) = II ;idxn(MatStencil_j,8) = JJ+1</span><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> idxn(MatStencil_i,9) = II+1;idxn(MatStencil_j,9) = JJ+1</span><br>
</div>
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"> call MatSetValuesStencil(A,1,idxm,9,idxn,values,INSERT_VALUES,ierr)</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"><br>
</span></div>
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">Which seemed to work just fine. For 5 degrees of freedom, instead of just having a single AP coefficient for example, I have an AP
matrix:</span>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"><br>
</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">
<table cellspacing="0" cellpadding="1" style="border-collapse:collapse">
<tbody>
<tr style="background-color:rgb(255,255,255)">
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_uu</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_uv</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_up</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_ut</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_uf</span><br>
</td>
</tr>
<tr style="background-color:rgb(255,255,255)">
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_vu</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_vv</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_vp</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_vt</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_vf</span><br>
</td>
</tr>
<tr style="background-color:rgb(255,255,255)">
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_pu</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_pv</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_pp</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_pt</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_pf</span><br>
</td>
</tr>
<tr style="background-color:rgb(255,255,255)">
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_tu</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_tv</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_tp</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_tt</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_tf</span><br>
</td>
</tr>
<tr style="background-color:rgb(255,255,255)">
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_fu</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_fv</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_fp</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_ft</span><br>
</td>
<td style="width:100px; border-color:rgb(171,171,171); border-style:solid; border-width:1px">
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">ap_ff</span><br>
</td>
</tr>
</tbody>
</table>
</span></div>
<div><br>
</div>
<div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">In 1 degree of freedom, i and j corresponded to the solution variable in the grid. For multi degree of freedom, I don't understand
how values of i, j, and c could distinguish from an ap_uv and ap_vv coefficent for example, wouldn't they both be at i, j ,c=2?<br>
</span></div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)"></span></div>
<span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">Is there anyway I can use MatSetValuesStencil() to fill in my 9 point stencil with my 5x5 matrix coefficients? To clarify I have nine
5x5 matrices for each cell which correspond to the 5 unknowns per cell.</span></div>
</div>
</blockquote>
<div><br>
</div>
<div>In MatSetValuesStencil(), I think it is best to think of the Stencils as another way of providing row/col numbers. So each MatStencil corresponds</div>
<div>to some row number. So your ap_uv is some entry in the input matrix, and thus corresponds to some row number (a MatStencil) and some</div>
<div>column number (another MatStencil). Since ap is one point, it appears that</div>
<div><br>
</div>
<div> ap_uv --> row = i,j,0 col = i,j,1</div>
<div> ap_vv --> row = i,j,1 col = i,j,1</div>
<div><br>
</div>
<div>So you line up your MatStencil arguments to match the order of your input. It sounds like you want the field index to be the fastest in your input.</div>
<div><br>
</div>
<div>Does that make sense?</div>
<div><br>
</div>
<div> Thanks,</div>
<div><br>
</div>
<div> Matt</div>
<div> </div>
<div> </div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">Thanks,</span></div>
<div><br>
</div>
<div><span style="font-family:calibri,arial,helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0); background-color:rgba(0,0,0,0)">Lucas</span><br>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">
<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>
</div>
</body>
</html>