<div class="gmail_quote">On Fri, Sep 9, 2011 at 17:06, Dominik Szczerba <span dir="ltr">&lt;<a href="mailto:dominik@itis.ethz.ch">dominik@itis.ethz.ch</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
<br>
I have an application where I do not know how many linears systems I<br>
will solve. Solution of the first will determine coefficient of the<br>
second etc., e.g., in case of a pressure correction method.<br>
I do not see a problem of having a std::vector of KSP objects,<br>
matrices and vectors (at least not yet...) but I am not sure how to<br>
handle<br>
<br>
KSPSetConvergenceTest(this-&gt;ksp, DefaultConvergenceTest, (void*)<br>
&amp;ctxConvergence, DestroyDefaultConvergenceContext);<br>
<br>
where the functions are defined as<br>
<br>
<br></blockquote><div><br></div><div><div>It sounds like you are wanting to define something like</div><div><br></div><div>class MyConvergenceTest {</div><div>  virtual PetscErrorCode test(KSP ksp,PetscInt it,PetscReal rnorm,KSPConvergedReason *reason) {</div>
<div>  // ...</div><div>  *reason = ...;</div><div>  }</div></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
#undef __FUNCT__<br>
#define __FUNCT__ &quot;DefaultConvergenceTest&quot;<br>
PetscErrorCode DefaultConvergenceTest(KSP ksp, int n, PetscReal rnorm,<br>
KSPConvergedReason *reason, void *void_ctx)<br>
{<br>
// ...<br></blockquote><div><br></div><div>MyConvergenceTest *p = (MyConvergenceClass*)void_ctx;</div><div>return p-&gt;(ksp,n,rnorm,reason);</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
#undef __FUNCT__<br>
#define __FUNCT__ &quot;destroyConvergenceContext&quot;<br>
PetscErrorCode DestroyDefaultConvergenceContext(void *void_ctx)<br>
// ...</blockquote><div> </div><div>  MyConvergenceTest *p = (MyConvergenceClass*)void_ctx;</div><div>  delete p;</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

}<br>
<br>
I would like something like a user defining how many linear system he<br>
wants and I want these functions to be pre-filled for them with a<br>
default generic content, which the user could, however, overwrite to<br>
possibly have different criteria for different solvers.<br>
<br>
I am unsure how to achieve this elegantly. I am thinking about a<br>
class, whereby such a function would be virtual static member. Then I<br>
could create a vector of instances.</blockquote><div><br></div><div>You can manage creation of these however you want. The Destroy callback can be used to call the destructor on your object, so you don&#39;t need to manage that yourself.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> But will the __FUNCT__ mechanism<br>
accept such functions? </blockquote><div><br></div><div>__FUNCT__ has nothing to do with this. It&#39;s just a way to get stack traces despite only C99 having standardized a way to get the name of the current function (__func__).</div>
</div>