<div dir="ltr">Good morning everyone, <div><br></div><div>Thank you Barry for the answer, it works now !<br></div><div><br></div><div>I am facing (yet) another situation: the TSAdaptRegister function.</div><div>In the MR on gitlab, Jed mentioned that sometimes, when function pointers are not stored in PETSc objects, one can use stack memory to pass that pointer from fortran to C.</div><div>Can anyone develop that idea ? Because for TSAdaptRegister, i guess the wrapper would start like :</div><div><br></div><div>PETSC_EXTERN void tsadaptregister_(char *sname,<br> void (*func)(TSAdapt*,PetscErrorCode*),<br> PetscErrorCode *ierr,<br> PETSC_FORTRAN_CHARLEN_T snamelen)<br></div><div><br></div><div>but then the C TSAdaptRegister function takes a PetscErrorCode (*func)(TSAdapt) function pointer as argument ... I cannot use any FORTRAN_CALLBACK here since I do not have any object to hook it to, and I could not find a similar situation among the pre-existing wrappers. Does anyone have an idea on how to proceed ? </div><div><br></div><div>Thanks !!</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault</div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 22 déc. 2020 à 21:20, Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><br></div><blockquote type="cite"><div dir="ltr"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace">PetscObjectUseFortranCallback((PetscDS)ctx, </font></div></blockquote></div></blockquote><div><br></div><blockquote type="cite"><div dir="ltr"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace">*ierr = PetscObjectSetFortranCallback((PetscObject)*prob</font></div></blockquote></div></blockquote><div><br></div> It looks like the problem is that these user provided functions do not take a PetscDS directly as an argument so the Fortran callback information cannot be obtained from them. <div><br></div><div>The manual page for PetscDSAddBoundary() says</div><div><br></div><div> - ctx - An optional user context for bcFunc </div><div><br></div><div>but then when it lists the calling sequence for bcFunc it does not list the ctx as an argument, so either the manual page or code is wrong. </div><div><br></div><div>It looks like you make the ctx be the <font face="monospace">PetscDS prob argument when you call </font><span style="font-family:monospace">PetscDSAddBoundary</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">In principle this sounds like it might work. I think you need to track through the debugger to see if the ctx passed to </span><span style="font-family:monospace">ourbocofunc() is actually the PetscDS prob variable and if not why it is not.</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"> Barry</span></div><div><span style="font-family:monospace"><br></span></div><div><div><br><blockquote type="cite"><div>On Dec 22, 2020, at 5:49 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Dear all,<div><br></div><div>I have hit two snags while implementing the missing wrappers necessary to transcribe ex11 to Fortran.</div><div><br></div><div>First is about the PetscDSAddBoundary wrapper, that I have done so :</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace">static PetscErrorCode ourbocofunc(PetscReal time, const PetscReal *c, const PetscReal *n, const PetscScalar *a_xI, const PetscScalar *a_xG, void *ctx)</font></div><div><font face="monospace">{</font></div><div><font face="monospace"> PetscObjectUseFortranCallback((PetscDS)ctx, bocofunc,</font></div><div><font face="monospace"> (PetscReal*,const PetscReal*,const PetscReal*,const PetscScalar*,const PetscScalar*,void*,PetscErrorCode*),</font></div><div><font face="monospace"> (&time,c,n,a_xI,a_xG,ctx,&ierr));</font></div><div><font face="monospace">}</font></div><div><font face="monospace">static PetscErrorCode ourbocofunc_time(PetscReal time, const PetscReal *c, const PetscReal *n, const PetscScalar *a_xI, const PetscScalar *a_xG, void *ctx)</font></div><div><font face="monospace">{</font></div><div><font face="monospace"> PetscObjectUseFortranCallback((PetscDS)ctx, bocofunc_time,</font></div><div><font face="monospace"> (PetscReal*,const PetscReal*,const PetscReal*,const PetscScalar*,const PetscScalar*,void*,PetscErrorCode*),</font></div><div><font face="monospace"> (&time,c,n,a_xI,a_xG,ctx,&ierr));</font></div><div><font face="monospace">}</font></div><div><font face="monospace">PETSC_EXTERN void petscdsaddboundary_(PetscDS *prob, DMBoundaryConditionType *type, char *name, char *labelname, PetscInt *field, PetscInt *numcomps, PetscInt *comps,</font></div><div><font face="monospace"> void (*bcFunc)(void),</font></div><div><font face="monospace"> void (*bcFunc_t)(void),</font></div><div><font face="monospace"> PetscInt *numids, const PetscInt *ids, void *ctx, PetscErrorCode *ierr,</font></div><div><font face="monospace"> PETSC_FORTRAN_CHARLEN_T namelen, PETSC_FORTRAN_CHARLEN_T labelnamelen)</font></div><div><font face="monospace">{</font></div><div><font face="monospace"> char *newname, *newlabelname;</font></div><div><font face="monospace"> FIXCHAR(name, namelen, newname);</font></div><div><font face="monospace"> FIXCHAR(labelname, labelnamelen, newlabelname);</font></div><div><font face="monospace"> *ierr = PetscObjectSetFortranCallback((PetscObject)*prob, PETSC_FORTRAN_CALLBACK_CLASS, &bocofunc, (PetscVoidFunction)bcFunc, ctx);</font></div><div><font face="monospace"> *ierr = PetscObjectSetFortranCallback((PetscObject)*prob, PETSC_FORTRAN_CALLBACK_CLASS, &bocofunc_time, (PetscVoidFunction)bcFunc_t, ctx);</font></div><div><font face="monospace"> *ierr = PetscDSAddBoundary(*prob, *type, newname, newlabelname, *field, *numcomps, comps,</font></div><div><font face="monospace"> (void (*)(void))ourbocofunc,</font></div><div><font face="monospace"> (void (*)(void))ourbocofunc_time,</font></div><div><font face="monospace"> *numids, ids, *prob);</font></div><div><font face="monospace"> FREECHAR(name, newname);</font></div><div><font face="monospace"> FREECHAR(labelname, newlabelname);</font></div><div><font face="monospace">}</font></div></blockquote><div><br></div><div><br></div><div>but when I call it in the program, with adequate routines, I obtain the following error :</div><div><br></div><div><pre lang="plaintext"><span id="gmail-m_-1849793084642070778gmail-LC1" lang="plaintext">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</span>
<span id="gmail-m_-1849793084642070778gmail-LC2" lang="plaintext">[0]PETSC ERROR: Corrupt argument: <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank">https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a></span>
<span id="gmail-m_-1849793084642070778gmail-LC3" lang="plaintext">[0]PETSC ERROR: Fortran callback not set on this object</span>
<span id="gmail-m_-1849793084642070778gmail-LC4" lang="plaintext">[0]PETSC ERROR: See <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</span>
<span id="gmail-m_-1849793084642070778gmail-LC5" lang="plaintext">[0]PETSC ERROR: Petsc Development GIT revision: v3.14.2-297-gf36a7edeb8 GIT Date: 2020-12-18 04:42:53 +0000</span>
<span id="gmail-m_-1849793084642070778gmail-LC6" lang="plaintext">[0]PETSC ERROR: ../../../bin/eulerian3D on a named macbook-pro-de-thibault.home by tbridel Sun Dec 20 15:05:15 2020</span>
<span id="gmail-m_-1849793084642070778gmail-LC7" lang="plaintext">[0]PETSC ERROR: Configure options --with-clean=0 --prefix=/Users/tbridel/Documents/1-CODES/04-PETSC/build --with-make-np=2 --with-windows-graphics=0 --with-debugging=0 --download-fblaslapack --download-mpich-shared=0 --with-x=0 --with-pthread=0 --with-valgrind=0 --PETSC_ARCH=macosx --with-fc=/usr/local/Cellar/open-mpi/4.0.1_2/bin/mpifort --with-cc=/usr/local/Cellar/open-mpi/4.0.1_2/bin/mpicc --with-cxx=/usr/local/Cellar/open-mpi/4.0.1_2/bin/mpic++ --with-openmp=0 --download-hypre=yes --download-sowing=yes --download-metis=yes --download-parmetis=yes --download-triangle=yes --download-tetgen=yes --download-ctetgen=yes --download-p4est=yes --download-zlib=yes --download-c2html=yes --download-eigen=yes --download-pragmatic=yes --with-hdf5-dir=/usr/local/Cellar/hdf5/1.10.5_1 --with-cmake-dir=/usr/local/Cellar/cmake/3.15.3</span>
<span id="gmail-m_-1849793084642070778gmail-LC8" lang="plaintext">[0]PETSC ERROR: #1 PetscObjectGetFortranCallback() line 258 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/sys/objects/inherit.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC9" lang="plaintext">[0]PETSC ERROR: #2 ourbocofunc() line 141 in /Users/tbridel/Documents/1-CODES/59-EULERIAN3D/sources/petsc_wrapping/wrapper_petsc.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC10" lang="plaintext">[0]PETSC ERROR: #3 DMPlexInsertBoundaryValuesRiemann() line 989 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/dm/impls/plex/plexfem.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC11" lang="plaintext">[0]PETSC ERROR: #4 DMPlexInsertBoundaryValues_Plex() line 1052 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/dm/impls/plex/plexfem.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC12" lang="plaintext">[0]PETSC ERROR: #5 DMPlexInsertBoundaryValues() line 1142 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/dm/impls/plex/plexfem.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC13" lang="plaintext">[0]PETSC ERROR: #6 DMPlexComputeResidual_Internal() line 4524 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/dm/impls/plex/plexfem.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC14" lang="plaintext">[0]PETSC ERROR: #7 DMPlexTSComputeRHSFunctionFVM() line 74 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/utils/dmplexts.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC15" lang="plaintext">[0]PETSC ERROR: #8 ourdmtsrhsfunc() line 186 in /Users/tbridel/Documents/1-CODES/59-EULERIAN3D/sources/petsc_wrapping/wrapper_petsc.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC16" lang="plaintext">[0]PETSC ERROR: #9 TSComputeRHSFunction_DMLocal() line 105 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/utils/dmlocalts.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC17" lang="plaintext">[0]PETSC ERROR: #10 TSComputeRHSFunction() line 653 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/interface/ts.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC18" lang="plaintext">[0]PETSC ERROR: #11 TSSSPStep_RK_3() line 120 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/impls/explicit/ssp/ssp.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC19" lang="plaintext">[0]PETSC ERROR: #12 TSStep_SSP() line 208 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/impls/explicit/ssp/ssp.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC20" lang="plaintext">[0]PETSC ERROR: #13 TSStep() line 3757 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/interface/ts.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC21" lang="plaintext">[0]PETSC ERROR: #14 TSSolve() line 4154 in /Users/tbridel/Documents/1-CODES/04-PETSC/src/ts/interface/ts.c</span>
<span id="gmail-m_-1849793084642070778gmail-LC22" lang="plaintext">[0]PETSC ERROR: #15 User provided function() line 0 in User file</span>
</pre><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div><div><br></div><div>Second is about the DMProjectFunction wrapper, that I have done so :<br></div><div><br></div></div></div></div></div></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><div><div><div><div><div><div><font face="monospace">static PetscErrorCode ourdmprojfunc(PetscInt dim, PetscReal time, PetscReal x[], PetscInt Nf, PetscScalar u[], void *ctx)</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace">{</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> PetscObjectUseFortranCallback((DM)ctx, dmprojfunc,</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> (PetscInt*,PetscReal*,PetscReal*,PetscInt*,PetscScalar*,void*,PetscErrorCode*),</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> (&dim,&time,x,&Nf,u,_ctx,&ierr))</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace">}</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace">PETSC_EXTERN void dmprojectfunction_(DM *dm, PetscReal *time,</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> void (*func)(PetscInt*,PetscReal*,PetscReal*,PetscInt*,PetscScalar*,void*,PetscErrorCode*),</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> void *ctx, InsertMode *mode, Vec X, PetscErrorCode *ierr)</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace">{</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> PetscErrorCode (*funcarr[1]) (PetscInt dim, PetscReal time, PetscReal x[], PetscInt Nf, PetscScalar *u, void *ctx);</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> *ierr = PetscObjectSetFortranCallback((PetscObject)*dm, PETSC_FORTRAN_CALLBACK_CLASS, &dmprojfunc, (PetscVoidFunction)func, ctx);</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> funcarr[0] = ourdmprojfunc;</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace"> *ierr = DMProjectFunction(*dm, *time, funcarr, &ctx, *mode, X);</font></div></div></div></div></div></div></div></div></div><div><div><div><div><div><div><div><div><div><font face="monospace">}</font></div></div></div></div></div></div></div></div></div></blockquote><div><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div><div><br></div><div>This time there is no error because I cannot reach this point in the program, but I am not sure anyways how to write this wrapper, especially because of the double pointers that DMProjectFunction takes as arguments.</div><div><br></div><div>Does anyone have any idea what could be going wrong with those two wrappers ? </div><div><br></div><div>Thank you very much in advance !!</div><div><br></div><div>Thibault<br></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 18 déc. 2020 à 11:02, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Aah that is a nice trick, I was getting ready to fork, clone the fork and redo the work, but that worked fine ! Thank you Barry !<div><br></div><div>The MR will appear in a little while !<br><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault</div></div></div></div></div></div></div></div></div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 18 déc. 2020 à 10:16, Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br></div> Good question. There is a trick to limit the amount of work you need to do with a new fork after you have already made changes with a PETSc clone, but it looks like we do not document this clearly in the webpages. (I couldn't find it).<div><br></div><div> Yes, you do need to make a fork, but after you have made the fork on the GitLab website (and have done nothing on your machine) edit the file $PETSC_DIR/.git/config for your clone on your machine </div><div><br></div><div> Locate the line that has url = <a href="mailto:git@gitlab.com" target="_blank">git@gitlab.com</a>:petsc/petsc.git (this may have an https at the beginning of the line)</div><div><br></div><div> Change this line to point to the fork url instead with git@ not https, which will be pretty much the same URL but with your user id instead of petsc in the address. Then git push and it will push to your fork.</div><div><br></div><div> Now you changes will be in your fork and you can make the MR from your fork URL on Gitlab. (In other words this editing trick converts your PETSc clone on your machine to a PETSc fork).</div><div><br></div><div> I hope I have explained this clearly enough it goes smoothly.</div><div><br></div><div> Barry</div><div><br></div><div><br><div><br><blockquote type="cite"><div>On Dec 18, 2020, at 3:00 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hello Barry, <div><br></div><div>I'll start the MR as soon as possible then so that specialists can indeed have a look. Do I have to fork PETSc to start a MR or are PETSc repo settings such that can I push a branch from the PETSc clone I got ?</div><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault<br></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 16 déc. 2020 à 07:47, Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br></div><div> Thibault,</div><div><br></div> A subdirectory for the example is fine; we have other examples that use subdirectories and multiple files.<div><br></div><div> Note: even if you don't have something completely working you can still make MR and list it as DRAFT request for comments, some other PETSc members who understand the packages you are using and Fortran better than I may be able to help as you develop the code.</div><div><div><br></div><div> Barry</div><div><br><div><br></div><div><br><div><br><blockquote type="cite"><div>On Dec 16, 2020, at 12:35 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>Hello everyone, <br></div><div><br></div><div>Thank you Barry for the feedback.</div><div>OK, yes I'll work up an MR as soon as I have got something working. By the way, does the fortran-version of the example have to be a single file ? If my push contains a directory with several files (different modules and the main), and the Makefile that goes with it, is that ok ?</div><div><br></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault Bridel-Bertomeu</div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 16 déc. 2020 à 04:46, Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br></div> This is great. If you make a branch off of the PETSc git repository with these additions and work on ex11 you can make a merge request and we can run the code easily on all our test systems (for security reasons one of use needs to launch the tests from your MR). <a href="https://docs.petsc.org/en/latest/developers/integration/" target="_blank">https://docs.petsc.org/en/latest/developers/integration/</a><div><br></div><div> Barry</div><div><br><div><br><blockquote type="cite"><div>On Dec 15, 2020, at 5:35 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>Hello everyone, <br></div><div><br></div><div>So far, I have the wrappers in the files attached to this e-mail. I still do not know if they work properly - at least the code compiles and the calls to the wrapped-subroutine do not fail - but I wanted to put this here in case someone sees something really wrong with it already.</div><div><br></div><div>Thank you again for your help, I'll try to post updates of the F90 version of ex11 regularly in this thread.</div><div><br></div><div>Stay safe, <br></div><div><br></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div><div><div><div>Thibault Bridel-Bertomeu<br></div></div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 13 déc. 2020 à 16:39, Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank">thibault.bridelbertomeu@gmail.com</a>> writes:<br>
<br>
> Thank you Mark for your answer.<br>
><br>
> I am not sure what you think could be in the setBC1 routine ? How to make<br>
> the connection with the PetscDS ?<br>
><br>
> On the other hand, I actually found after a while TSMonitorSet has a<br>
> fortran wrapper, and it does take as arguments two function pointers, so I<br>
> guess it is possible ? Although I am not sure exactly how to play with the<br>
> PetscObjectSetFortranCallback & PetscObjectUseFortranCallback macros -<br>
> could anybody advise please ?<br>
<br>
tsmonitorset_ is a good example to follow. In your file, create one of these static structs with a member for each callback. These are IDs that will be used as keys for Fortran callbacks and their contexts. The salient parts of the file are below.<br>
<br>
static struct {<br>
PetscFortranCallbackId prestep;<br>
PetscFortranCallbackId poststep;<br>
PetscFortranCallbackId rhsfunction;<br>
PetscFortranCallbackId rhsjacobian;<br>
PetscFortranCallbackId ifunction;<br>
PetscFortranCallbackId ijacobian;<br>
PetscFortranCallbackId monitor;<br>
PetscFortranCallbackId mondestroy;<br>
PetscFortranCallbackId transform;<br>
#if defined(PETSC_HAVE_F90_2PTR_ARG)<br>
PetscFortranCallbackId function_pgiptr;<br>
#endif<br>
} _cb;<br>
<br>
/*<br>
Note ctx is the same as ts so we need to get the Fortran context out of the TS; this gets put in _ctx using the callback ID<br>
*/<br>
static PetscErrorCode ourmonitor(TS ts,PetscInt i,PetscReal d,Vec v,void *ctx)<br>
{<br>
PetscObjectUseFortranCallback(ts,_cb.monitor,(TS*,PetscInt*,PetscReal*,Vec *,void*,PetscErrorCode*),(&ts,&i,&d,&v,_ctx,&ierr));<br>
}<br>
<br>
Then follow as in tsmonitorset_, which sets two callbacks. <br>
<br>
PETSC_EXTERN void tsmonitorset_(TS *ts,void (*func)(TS*,PetscInt*,PetscReal*,Vec*,void*,PetscErrorCode*),void *mctx,void (*d)(void*,PetscErrorCode*),PetscErrorCode *ierr)<br>
{<br>
CHKFORTRANNULLFUNCTION(d);<br>
if ((PetscVoidFunction)func == (PetscVoidFunction) tsmonitordefault_) {<br>
*ierr = TSMonitorSet(*ts,(PetscErrorCode (*)(TS,PetscInt,PetscReal,Vec,void*))TSMonitorDefault,*(PetscViewerAndFormat**)mctx,(PetscErrorCode (*)(void **))PetscViewerAndFormatDestroy);<br>
} else {<br>
*ierr = PetscObjectSetFortranCallback((PetscObject)*ts,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitor,(PetscVoidFunction)func,mctx);<br>
*ierr = PetscObjectSetFortranCallback((PetscObject)*ts,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.mondestroy,(PetscVoidFunction)d,mctx);<br>
*ierr = TSMonitorSet(*ts,ourmonitor,*ts,ourmonitordestroy);<br>
}<br>
}<br>
</blockquote></div>
<span id="gmail-m_-1849793084642070778gmail-m_-3167854981072692381gmail-m_8759974974518583617gmail-m_2866696447715203370gmail-m_1645657168228053713cid:f_kipwslzw0"><wrapper_petsc.h90></span><span id="gmail-m_-1849793084642070778gmail-m_-3167854981072692381gmail-m_8759974974518583617gmail-m_2866696447715203370gmail-m_1645657168228053713cid:f_kipwsm1a1"><wrapper_petsc.c></span></div></blockquote></div><br></div></div></blockquote></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>
</blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>