<html>
<head>
</head>
<body class='hmmessage'><div dir='ltr'>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr">Thanks a lot, Dave,<br><br> I can pass an 1-D array into ComputeRHS via *void ctx. <br><br> I am using the following procedure:<br><br> in main()<br>{//-------<br> ...<br> double array_1d[array_size];<br><br> ComputeRHS(array_1d);<br> ierr = KSPSetComputeRHS(ksp,ComputeRHS, array_1d);<br> ...<br>//--------<br>}<br><br> in ComputeRHS(KSP,Vec,void* ctx )<br>{<br> int size_in_func<br> double* arr1d=static_cast<double *>(ctx);<br> for (i=0;i<size_in_func; i++)<br> cout<<" ComputeRHS="<<arr1d[i] <<endl; <br>}<br><br> Definitely, a 3d array can be passed by converting it to 1d in main() before calling KSPSetComputeRHS and back to 3d in ComputeRHS(). However, is it possible to pass 3d array directly? Thanks.<br><br><div><hr id="stopSpelling">Date: Sun, 4 Aug 2013 18:18:54 +0200<br>Subject: Re: [petsc-users] passing variables into (*func)(KSP, Vec, void*) in the interface of KSPSetComputeRHS<br>From: dave.mayhem23@gmail.com<br>To: pengxwang@hotmail.com<br>CC: petsc-users@mcs.anl.gov<br><br>The last argument you give to KSPSetComputeRHS() will be passed into your user defined function ComputeRHS(). All data needed to evaluate the rhs should be made available through that pointer (void *ctx)<div><br><span></span><div>
<br>On Sunday, 4 August 2013, Roc Wang wrote:<br><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">
<div><div dir="ltr">Hello, I am developing a poisson solver based on the example code petsc-3.4.0/src/ksp/ksp/examples/tutorials/ex45.c.<br><br>I have a question on utilizing functions<br><pre> KSPSetComputeRHS (KSP ksp,PetscErrorCode (*func)(KSP,Vec,void*),void *ctx) and ComputeRHS(KSP,Vec,void*) which is the (*func)(KSP,Vec,void*) in the interface. <br>
<br>Since I have source term generated on the right hand side of Poisson equation and they are computed outside KSPSetComputeRHS() and ComputeRHS(), an array of source term variables must be passed into ComuteRHS() function. From the manual online, it seems the interface of ComputeRHS is only for passing variables from inside of ComputeRHS to KSPSetComputeRHS. There is not a dummy for passing into ComputeRHS. Can anybody give me suggestions on it? Thanks in advance.<br>
<br><br></pre> </div></div>
</blockquote></div></div></div></div>
</div></body>
</html>