<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:2 11 6 9 3 8 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
p.p1, li.p1, div.p1
        {mso-style-name:p1;
        margin:0in;
        font-size:8.5pt;
        font-family:Menlo;
        color:black;}
p.p2, li.p2, div.p2
        {mso-style-name:p2;
        margin:0in;
        font-size:8.5pt;
        font-family:Menlo;
        color:#9D206F;}
p.p3, li.p3, div.p3
        {mso-style-name:p3;
        margin:0in;
        font-size:8.5pt;
        font-family:Menlo;
        color:#2D961E;}
p.p4, li.p4, div.p4
        {mso-style-name:p4;
        margin:0in;
        font-size:8.5pt;
        font-family:Menlo;
        color:#C1651C;}
span.s1
        {mso-style-name:s1;
        color:#9D206F;}
span.s3
        {mso-style-name:s3;
        color:#C200FF;}
span.s4
        {mso-style-name:s4;
        color:black;}
span.s5
        {mso-style-name:s5;
        color:#C1651C;}
span.s2
        {mso-style-name:s2;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Jose,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Unfortunately, I was unable to implement the MATOP_DUPLICATE operation in fortran (and I do not know enough c to work in c).  Here is the error message I get:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p style="margin:0in;background:white"><span style="color:red">[0]PETSC ERROR: #1 MatShellSetOperation_Fortran() at /Users/hall/Documents/Fortran_Codes/Packages/petsc/src/mat/impls/shell/ftn-custom/zshellf.c:283</span><span style="color:black"><o:p></o:p></span></p>
<p style="margin:0in;background:white"><span style="color:red">[0]PETSC ERROR: #2 src/test_nep.f90:62</span><span style="color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">When I look at zshellf.c, MATOP_DUPLICATE is not one of the supported operations. See below.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Kenneth<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="p1"><span class="s1">/** </span><span class="apple-converted-space">                                                                                                                                                                                   
                                                                                    </span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space"><span style="color:#9D206F"> </span></span><span class="s1">* Subset of MatOperation that is supported by the Fortran wrappers.</span><span class="apple-converted-space"><span style="color:#9D206F"> </span></span><span class="s2">
</span><span class="apple-converted-space">                                                                                                                                                                                                     </span><o:p></o:p></p>
<p class="p2"><span class="apple-converted-space"> </span><span class="s2">*/</span><o:p></o:p></p>
<p class="p3"><span class="s3">enum</span><span class="s4"> </span><span class="s2">FortranMatOperation</span><span class="s4"> {</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_MULT</span><span class="s2">
</span><span class="apple-converted-space">              </span><span class="s2">= 0,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_MULT_ADD</span><span class="s4"> </span><span class="apple-converted-space"><span style="color:black">         
</span></span><span class="s4">= 1,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_MULT_TRANSPOSE</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">    </span></span><span class="s4">= 2,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_MULT_TRANSPOSE_ADD</span><span class="s4"> = 3,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_SOR</span><span class="apple-converted-space">               
</span><span class="s2">= 4,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_TRANSPOSE</span><span class="apple-converted-space"><span style="color:black">         
</span></span><span class="s4">= 5,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_GET_DIAGONAL</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">      </span></span><span class="s4">= 6,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_DIAGONAL_SCALE</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">    </span></span><span class="s4">= 7,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_ZERO_ENTRIES</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">      </span></span><span class="s4">= 8,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_AXPY</span><span class="s2">
</span><span class="apple-converted-space">              </span><span class="s2">= 9,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_SHIFT</span><span class="apple-converted-space">             
</span><span class="s2">= 10,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_DIAGONAL_SET</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">      </span></span><span class="s4">= 11,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_DESTROY</span><span class="apple-converted-space"><span style="color:black">           
</span></span><span class="s4">= 12,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_VIEW</span><span class="s2">
</span><span class="apple-converted-space">              </span><span class="s2">= 13,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_CREATE_VECS</span><span class="apple-converted-space"><span style="color:black">       
</span></span><span class="s4">= 14,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_GET_DIAGONAL_BLOCK</span><span class="s4"> = 15,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_COPY</span><span class="s2">
</span><span class="apple-converted-space">              </span><span class="s2">= 16,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_SCALE</span><span class="apple-converted-space">             
</span><span class="s2">= 17,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_SET_RANDOM</span><span class="s4"> </span><span class="apple-converted-space"><span style="color:black">       
</span></span><span class="s4">= 18,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_ASSEMBLY_BEGIN</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">    </span></span><span class="s4">= 19,</span><o:p></o:p></p>
<p class="p4"><span class="apple-converted-space"><span style="color:black">  </span>
</span><span class="s2">FORTRAN_MATOP_ASSEMBLY_END</span><span class="s4"> </span>
<span class="apple-converted-space"><span style="color:black">      </span></span><span class="s4">= 20,</span><o:p></o:p></p>
<p class="p1"><span class="apple-converted-space">  </span><span class="s5">FORTRAN_MATOP_SIZE</span><span class="s2">
</span><span class="apple-converted-space">              </span><span class="s2">= 21</span><o:p></o:p></p>
<p class="p1"><span class="s2">};</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Jose E. Roman <jroman@dsic.upv.es><br>
<b>Date: </b>Friday, October 6, 2023 at 7:01 AM<br>
<b>To: </b>Kenneth C Hall <kenneth.c.hall@duke.edu><br>
<b>Cc: </b>petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov><br>
<b>Subject: </b>Re: [petsc-users] SLEPc/NEP for shell matrice T(lambda) and T'(lambda)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:11.0pt">I am getting an error in a different place than you. I started to debug, but don't have much time at the moment.<br>
Can you try something? Comparing to ex21.c, I see that a difference that may be relevant is the MATOP_DUPLICATE operation. Can you try defining it for your A matrix?<br>
<br>
Note: If you plan to use the NLEIGS solver, there is no need to define the derivative T' so you can skip the call to NEPSetJacobian().<br>
<br>
Jose<br>
<br>
<br>
> El 6 oct 2023, a las 0:37, Kenneth C Hall <kenneth.c.hall@duke.edu> escribió:<br>
> <br>
> Hi all,<br>
>  <br>
> I have a very large eigenvalue problem of the form T(\lambda).x = 0. The eigenvalues appear in a complicated way, and I must use a matrix-free approach to compute the products T.x and T’.x.<br>
>  <br>
> I am trying to implement in SLEPc/NEP.  To get started, I have defined a much smaller and simpler system of the form<br>
> A.x - \lambda x = 0 where A is a 10x10 matrix. This is of course a simple standard eigenvalue problem, but I am using it as a surrogate to understand how to use NEP.<br>
>  <br>
> I have set the problem up using shell matrices (as that is my ultimate goal).  The full code is attached, but here is a smaller snippet of code:<br>
>  <br>
> !.... Create matrix-free operators for A and B<br>
>       PetscCall(MatCreateShell(PETSC_COMM_SELF,n,n,PETSC_DETERMINE,PETSC_DETERMINE, PETSC_NULL_INTEGER, A, ierr))<br>
>       PetscCall(MatCreateShell(PETSC_COMM_SELF,n,n,PETSC_DETERMINE,PETSC_DETERMINE, PETSC_NULL_INTEGER, B, ierr))<br>
>       PetscCall(MatShellSetOperation(A, MATOP_MULT, MatMult_A, ierr))<br>
>       PetscCall(MatShellSetOperation(B, MATOP_MULT, MatMult_B, ierr))<br>
>  <br>
> !.... Create nonlinear eigensolver<br>
>       PetscCall(NEPCreate(PETSC_COMM_SELF, nep, ierr))<br>
>  <br>
> !.... Set the problem type<br>
>       PetscCall(NEPSetProblemType(nep, NEP_GENERAL, ierr))<br>
> !<br>
> !.... set the solver type<br>
>       PetscCall(NEPSetType(nep, NEPNLEIGS, ierr))<br>
> !<br>
> !.... Set functions and Jacobians for NEP<br>
>       PetscCall(NEPSetFunction(nep, A, A, MyNEPFunction, PETSC_NULL_INTEGER, ierr))<br>
>       PetscCall(NEPSetJacobian(nep, B,    MyNEPJacobian, PETSC_NULL_INTEGER, ierr))<br>
>  <br>
> The code runs, calls MyNEPFunction and MatMult_A multiple times, sweeping over the prescribed RG range, but crashes before it ever calls MyNEPJacobian or MatMult_B.  The NEP viewer and error messages are attached.<br>
>  <br>
> Any help on getting this problem properly set up would be greatly appreciated.<br>
>  <br>
> Kenneth Hall<br>
> ATTACHMENTS: <br>
> test_nep.f90<br>
> code_output<br>
>  <br>
> <code_output><test_nep.f90><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>