<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Here you have an example of a 2 dof system using MatSetValuesBlockedStencil<div class=""><br class=""></div><div class=""><a href="https://github.com/stefanozampini/petscopt/blob/master/src/ts/examples/tests/ex3.c#L186" class="">https://github.com/stefanozampini/petscopt/blob/master/src/ts/examples/tests/ex3.c#L186</a><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 29, 2020, at 8:55 PM, Lucas Banting <<a href="mailto:bantingl@myumanitoba.ca" class="">bantingl@myumanitoba.ca</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">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-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Thanks for your help.</div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Lucas<br class=""></div><div id="appendonsend" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div><hr tabindex="-1" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline-block; width: 735.96875px;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span><div id="divRplyFwdMsg" dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Friday, May 29, 2020 12:47 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Lucas Banting <<a href="mailto:bantingl@myumanitoba.ca" class="">bantingl@myumanitoba.ca</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a> <<a href="mailto:petsc-users@mcs.anl.gov" class="">petsc-users@mcs.anl.gov</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [petsc-users] How to use MatSetValuesStencil() with DOF>1</font><div class=""> </div></div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div dir="ltr" class=""><div dir="ltr" class="">On Fri, May 29, 2020 at 12:16 PM Lucas Banting <<a href="mailto:bantingl@myumanitoba.ca" class="">bantingl@myumanitoba.ca</a>> wrote:<br class=""></div><div class="x_gmail_quote"><blockquote class="x_gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">Hello,</div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">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.<span class="Apple-converted-space"> </span><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class="">I was wondering how exactly I should use MatSetValuesStencil() to fill my matrix.</div><div class="">I<span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><span class="Apple-converted-space"> </span>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 class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><br class=""></span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">For a 1 degree of freedom system to fill my 9 point stencil I did:</span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><br class=""></span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""></span><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(1)= ASW(II,JJ)</span><span class=""><br class=""></span><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(2)= AS (II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(3)= ASE(II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(4)= AW (II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(5)= AP (II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(6)= AE (II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(7)= ANW(II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(8)= AN (II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> values(9)= ANE(II,JJ)</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> <span class="Apple-converted-space"> </span></span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxm(MatStencil_i,1) = II;idxm(MatStencil_j,1) = JJ</span></div><div class=""><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,1) = II-1;idxn(MatStencil_j,1) = JJ-1</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,2) = II ;idxn(MatStencil_j,2) = JJ-1</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,3) = II+1;idxn(MatStencil_j,3) = JJ-1</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,4) = II-1 ;idxn(MatStencil_j,4) = JJ</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,5) = II ;idxn(MatStencil_j,5) = JJ</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,6) = II+1;idxn(MatStencil_j,6) = JJ</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,7) = II-1 ;idxn(MatStencil_j,7) = JJ+1</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,8) = II ;idxn(MatStencil_j,8) = JJ+1</span><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> idxn(MatStencil_i,9) = II+1;idxn(MatStencil_j,9) = JJ+1</span><br class=""></div><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""> call MatSetValuesStencil(A,1,idxm,9,idxn,values,INSERT_VALUES,ierr)</span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><br class=""></span></div><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">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 class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><br class=""></span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""><table cellspacing="0" cellpadding="1" style="border-collapse: collapse;" class=""><tbody class=""><tr style="background-color: rgb(255, 255, 255);" class=""><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_uu</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_uv</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_up</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_ut</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_uf</span><br class=""></td></tr><tr style="background-color: rgb(255, 255, 255);" class=""><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_vu</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_vv</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_vp</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_vt</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_vf</span><br class=""></td></tr><tr style="background-color: rgb(255, 255, 255);" class=""><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_pu</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_pv</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_pp</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_pt</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_pf</span><br class=""></td></tr><tr style="background-color: rgb(255, 255, 255);" class=""><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_tu</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_tv</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_tp</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_tt</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_tf</span><br class=""></td></tr><tr style="background-color: rgb(255, 255, 255);" class=""><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_fu</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_fv</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_fp</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_ft</span><br class=""></td><td style="width: 100px; border: 1px solid rgb(171, 171, 171);" class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">ap_ff</span><br class=""></td></tr></tbody></table></span></div><div class=""><br class=""></div><div class=""><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">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 class=""></span></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class=""></span></div><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">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 class=""><br class=""></div><div class="">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 class="">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 class="">column number (another MatStencil). Since ap is one point, it appears that</div><div class=""><br class=""></div><div class=""> ap_uv --> row = i,j,0 col = i,j,1</div><div class=""> ap_vv --> row = i,j,1 col = i,j,1</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Does that make sense?</div><div class=""><br class=""></div><div class=""> Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div><div class=""> </div><div class=""> </div><blockquote class="x_gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr" class=""><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">Thanks,</span></div><div class=""><br class=""></div><div class=""><span style="font-family: calibri, arial, helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);" class="">Lucas</span><br class=""></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div dir="ltr" class="x_gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a></div></div></div></div></div></div></div></div></div></div></blockquote></div><br class=""></div></body></html>