[petsc-users] arbitrary number of linear systems in an application

Jed Brown jedbrown at mcs.anl.gov
Sat Sep 10 07:14:54 CDT 2011


On Fri, Sep 9, 2011 at 17:06, Dominik Szczerba <dominik at itis.ethz.ch> wrote:

> Hi,
>
> I have an application where I do not know how many linears systems I
> will solve. Solution of the first will determine coefficient of the
> second etc., e.g., in case of a pressure correction method.
> I do not see a problem of having a std::vector of KSP objects,
> matrices and vectors (at least not yet...) but I am not sure how to
> handle
>
> KSPSetConvergenceTest(this->ksp, DefaultConvergenceTest, (void*)
> &ctxConvergence, DestroyDefaultConvergenceContext);
>
> where the functions are defined as
>
>
>
It sounds like you are wanting to define something like

class MyConvergenceTest {
  virtual PetscErrorCode test(KSP ksp,PetscInt it,PetscReal
rnorm,KSPConvergedReason *reason) {
  // ...
  *reason = ...;
  }


> #undef __FUNCT__
> #define __FUNCT__ "DefaultConvergenceTest"
> PetscErrorCode DefaultConvergenceTest(KSP ksp, int n, PetscReal rnorm,
> KSPConvergedReason *reason, void *void_ctx)
> {
> // ...
>

MyConvergenceTest *p = (MyConvergenceClass*)void_ctx;
return p->(ksp,n,rnorm,reason);


>
> #undef __FUNCT__
> #define __FUNCT__ "destroyConvergenceContext"
> PetscErrorCode DestroyDefaultConvergenceContext(void *void_ctx)
> // ...


  MyConvergenceTest *p = (MyConvergenceClass*)void_ctx;
  delete p;


> }
>
> I would like something like a user defining how many linear system he
> wants and I want these functions to be pre-filled for them with a
> default generic content, which the user could, however, overwrite to
> possibly have different criteria for different solvers.
>
> I am unsure how to achieve this elegantly. I am thinking about a
> class, whereby such a function would be virtual static member. Then I
> could create a vector of instances.


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't need to manage
that yourself.


> But will the __FUNCT__ mechanism
> accept such functions?


__FUNCT__ has nothing to do with this. It's just a way to get stack traces
despite only C99 having standardized a way to get the name of the current
function (__func__).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110910/79f60323/attachment.htm>


More information about the petsc-users mailing list