<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="monospace" class="">PetscObjectUseFortranCallback((PetscDS)ctx, </font></div></blockquote></div></blockquote><div class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="monospace" class="">*ierr = PetscObjectSetFortranCallback((PetscObject)*prob</font></div></blockquote></div></blockquote><div class=""><br class=""></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 class=""><br class=""></div><div class="">The manual page for PetscDSAddBoundary() says</div><div class=""><br class=""></div><div class=""> - ctx - An optional user context for bcFunc </div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">It looks like you make the ctx be the <font face="monospace" class="">PetscDS prob argument when you call </font><span style="font-family: monospace;" class="">PetscDSAddBoundary</span></div><div class=""><span style="font-family: monospace;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace;" class="">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;" class="">ourbocofunc() is actually the PetscDS prob variable and if not why it is not.</span></div><div class=""><span style="font-family: monospace;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace;" class=""> Barry</span></div><div class=""><span style="font-family: monospace;" class=""><br class=""></span></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 22, 2020, at 5:49 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" class="">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Dear all,<div class=""><br class=""></div><div class="">I have hit two snags while implementing the missing wrappers necessary to transcribe ex11 to Fortran.</div><div class=""><br class=""></div><div class="">First is about the PetscDSAddBoundary wrapper, that I have done so :</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class=""><font face="monospace" class="">static PetscErrorCode ourbocofunc(PetscReal time, const PetscReal *c, const PetscReal *n, const PetscScalar *a_xI, const PetscScalar *a_xG, void *ctx)</font></div><div class=""><font face="monospace" class="">{</font></div><div class=""><font face="monospace" class=""> PetscObjectUseFortranCallback((PetscDS)ctx, bocofunc,</font></div><div class=""><font face="monospace" class=""> (PetscReal*,const PetscReal*,const PetscReal*,const PetscScalar*,const PetscScalar*,void*,PetscErrorCode*),</font></div><div class=""><font face="monospace" class=""> (&time,c,n,a_xI,a_xG,ctx,&ierr));</font></div><div class=""><font face="monospace" class="">}</font></div><div class=""><font face="monospace" class="">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 class=""><font face="monospace" class="">{</font></div><div class=""><font face="monospace" class=""> PetscObjectUseFortranCallback((PetscDS)ctx, bocofunc_time,</font></div><div class=""><font face="monospace" class=""> (PetscReal*,const PetscReal*,const PetscReal*,const PetscScalar*,const PetscScalar*,void*,PetscErrorCode*),</font></div><div class=""><font face="monospace" class=""> (&time,c,n,a_xI,a_xG,ctx,&ierr));</font></div><div class=""><font face="monospace" class="">}</font></div><div class=""><font face="monospace" class="">PETSC_EXTERN void petscdsaddboundary_(PetscDS *prob, DMBoundaryConditionType *type, char *name, char *labelname, PetscInt *field, PetscInt *numcomps, PetscInt *comps,</font></div><div class=""><font face="monospace" class=""> void (*bcFunc)(void),</font></div><div class=""><font face="monospace" class=""> void (*bcFunc_t)(void),</font></div><div class=""><font face="monospace" class=""> PetscInt *numids, const PetscInt *ids, void *ctx, PetscErrorCode *ierr,</font></div><div class=""><font face="monospace" class=""> PETSC_FORTRAN_CHARLEN_T namelen, PETSC_FORTRAN_CHARLEN_T labelnamelen)</font></div><div class=""><font face="monospace" class="">{</font></div><div class=""><font face="monospace" class=""> char *newname, *newlabelname;</font></div><div class=""><font face="monospace" class=""> FIXCHAR(name, namelen, newname);</font></div><div class=""><font face="monospace" class=""> FIXCHAR(labelname, labelnamelen, newlabelname);</font></div><div class=""><font face="monospace" class=""> *ierr = PetscObjectSetFortranCallback((PetscObject)*prob, PETSC_FORTRAN_CALLBACK_CLASS, &bocofunc, (PetscVoidFunction)bcFunc, ctx);</font></div><div class=""><font face="monospace" class=""> *ierr = PetscObjectSetFortranCallback((PetscObject)*prob, PETSC_FORTRAN_CALLBACK_CLASS, &bocofunc_time, (PetscVoidFunction)bcFunc_t, ctx);</font></div><div class=""><font face="monospace" class=""> *ierr = PetscDSAddBoundary(*prob, *type, newname, newlabelname, *field, *numcomps, comps,</font></div><div class=""><font face="monospace" class=""> (void (*)(void))ourbocofunc,</font></div><div class=""><font face="monospace" class=""> (void (*)(void))ourbocofunc_time,</font></div><div class=""><font face="monospace" class=""> *numids, ids, *prob);</font></div><div class=""><font face="monospace" class=""> FREECHAR(name, newname);</font></div><div class=""><font face="monospace" class=""> FREECHAR(labelname, newlabelname);</font></div><div class=""><font face="monospace" class="">}</font></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">but when I call it in the program, with adequate routines, I obtain the following error :</div><div class=""><br class=""></div><div class=""><pre class="gmail-highlight gmail-code" lang="plaintext"><span id="gmail-LC1" class="gmail-line" lang="plaintext">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</span>
<span id="gmail-LC2" class="gmail-line" lang="plaintext">[0]PETSC ERROR: Corrupt argument: <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" class="">https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a></span>
<span id="gmail-LC3" class="gmail-line" lang="plaintext">[0]PETSC ERROR: Fortran callback not set on this object</span>
<span id="gmail-LC4" class="gmail-line" lang="plaintext">[0]PETSC ERROR: See <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html" class="">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</span>
<span id="gmail-LC5" class="gmail-line" 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-LC6" class="gmail-line" 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-LC7" class="gmail-line" 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-LC8" class="gmail-line" 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-LC9" class="gmail-line" 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-LC10" class="gmail-line" 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-LC11" class="gmail-line" 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-LC12" class="gmail-line" 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-LC13" class="gmail-line" 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-LC14" class="gmail-line" 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-LC15" class="gmail-line" 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-LC16" class="gmail-line" 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-LC17" class="gmail-line" 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-LC18" class="gmail-line" 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-LC19" class="gmail-line" 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-LC20" class="gmail-line" 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-LC21" class="gmail-line" 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-LC22" class="gmail-line" lang="plaintext">[0]PETSC ERROR: #15 User provided function() line 0 in User file</span>
</pre><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">Second is about the DMProjectFunction wrapper, that I have done so :<br class=""></div><div class=""><br class=""></div></div></div></div></div></div></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">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 class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">{</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> PetscObjectUseFortranCallback((DM)ctx, dmprojfunc,</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> (PetscInt*,PetscReal*,PetscReal*,PetscInt*,PetscScalar*,void*,PetscErrorCode*),</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> (&dim,&time,x,&Nf,u,_ctx,&ierr))</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">}</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">PETSC_EXTERN void dmprojectfunction_(DM *dm, PetscReal *time,</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> void (*func)(PetscInt*,PetscReal*,PetscReal*,PetscInt*,PetscScalar*,void*,PetscErrorCode*),</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> void *ctx, InsertMode *mode, Vec X, PetscErrorCode *ierr)</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">{</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> 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 class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> *ierr = PetscObjectSetFortranCallback((PetscObject)*dm, PETSC_FORTRAN_CALLBACK_CLASS, &dmprojfunc, (PetscVoidFunction)func, ctx);</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> funcarr[0] = ourdmprojfunc;</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class=""> *ierr = DMProjectFunction(*dm, *time, funcarr, &ctx, *mode, X);</font></div></div></div></div></div></div></div></div></div><div class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><font face="monospace" class="">}</font></div></div></div></div></div></div></div></div></div></blockquote><div class=""><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Does anyone have any idea what could be going wrong with those two wrappers ? </div><div class=""><br class=""></div><div class="">Thank you very much in advance !!</div><div class=""><br class=""></div><div class="">Thibault<br class=""></div></div></div></div></div></div></div></div></div></div><br class=""><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" class="">thibault.bridelbertomeu@gmail.com</a>> a écrit :<br class=""></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" class="">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 class=""><br class=""></div><div class="">The MR will appear in a little while !<br class=""><div class=""><br clear="all" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class="">Thibault</div></div></div></div></div></div></div></div></div></div></div><br class=""></div></div></div><br class=""><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" class="">bsmith@petsc.dev</a>> a écrit :<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class=""><br class=""></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 class=""><br class=""></div><div class=""> 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 class=""><br class=""></div><div class=""> Locate the line that has url = <a href="mailto:git@gitlab.com" target="_blank" class="">git@gitlab.com</a>:petsc/petsc.git (this may have an https at the beginning of the line)</div><div class=""><br class=""></div><div class=""> 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 class=""><br class=""></div><div class=""> 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 class=""><br class=""></div><div class=""> I hope I have explained this clearly enough it goes smoothly.</div><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2020, at 3:00 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank" class="">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hello Barry, <div class=""><br class=""></div><div class="">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 class=""><br clear="all" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class="">Thibault<br class=""></div></div></div></div></div></div></div></div></div></div></div><br class=""></div></div><br class=""><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" class="">bsmith@petsc.dev</a>> a écrit :<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class=""><br class=""></div><div class=""> Thibault,</div><div class=""><br class=""></div> A subdirectory for the example is fine; we have other examples that use subdirectories and multiple files.<div class=""><br class=""></div><div class=""> 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 class=""><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 16, 2020, at 12:35 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank" class="">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="">Hello everyone, <br class=""></div><div class=""><br class=""></div><div class="">Thank you Barry for the feedback.</div><div class="">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 class=""><br class=""></div><div class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class="">Thibault Bridel-Bertomeu</div></div></div></div></div></div></div></div></div></div></div><br class=""></div></div><br class=""><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" class="">bsmith@petsc.dev</a>> a écrit :<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class=""><br class=""></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" class="">https://docs.petsc.org/en/latest/developers/integration/</a><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 15, 2020, at 5:35 AM, Thibault Bridel-Bertomeu <<a href="mailto:thibault.bridelbertomeu@gmail.com" target="_blank" class="">thibault.bridelbertomeu@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="">Hello everyone, <br class=""></div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thank you again for your help, I'll try to post updates of the F90 version of ex11 regularly in this thread.</div><div class=""><br class=""></div><div class="">Stay safe, <br class=""></div><div class=""><br class=""></div><div class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class="">Thibault Bridel-Bertomeu<br class=""></div></div></div></div></div></div></div></div></div></div></div></div></div><br class=""><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" class="">jed@jedbrown.org</a>> a écrit :<br class=""></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" class="">thibault.bridelbertomeu@gmail.com</a>> writes:<br class="">
<br class="">
> Thank you Mark for your answer.<br class="">
><br class="">
> I am not sure what you think could be in the setBC1 routine ? How to make<br class="">
> the connection with the PetscDS ?<br class="">
><br class="">
> On the other hand, I actually found after a while TSMonitorSet has a<br class="">
> fortran wrapper, and it does take as arguments two function pointers, so I<br class="">
> guess it is possible ? Although I am not sure exactly how to play with the<br class="">
> PetscObjectSetFortranCallback & PetscObjectUseFortranCallback macros -<br class="">
> could anybody advise please ?<br class="">
<br class="">
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 class="">
<br class="">
static struct {<br class="">
PetscFortranCallbackId prestep;<br class="">
PetscFortranCallbackId poststep;<br class="">
PetscFortranCallbackId rhsfunction;<br class="">
PetscFortranCallbackId rhsjacobian;<br class="">
PetscFortranCallbackId ifunction;<br class="">
PetscFortranCallbackId ijacobian;<br class="">
PetscFortranCallbackId monitor;<br class="">
PetscFortranCallbackId mondestroy;<br class="">
PetscFortranCallbackId transform;<br class="">
#if defined(PETSC_HAVE_F90_2PTR_ARG)<br class="">
PetscFortranCallbackId function_pgiptr;<br class="">
#endif<br class="">
} _cb;<br class="">
<br class="">
/*<br class="">
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 class="">
*/<br class="">
static PetscErrorCode ourmonitor(TS ts,PetscInt i,PetscReal d,Vec v,void *ctx)<br class="">
{<br class="">
PetscObjectUseFortranCallback(ts,_cb.monitor,(TS*,PetscInt*,PetscReal*,Vec *,void*,PetscErrorCode*),(&ts,&i,&d,&v,_ctx,&ierr));<br class="">
}<br class="">
<br class="">
Then follow as in tsmonitorset_, which sets two callbacks. <br class="">
<br class="">
PETSC_EXTERN void tsmonitorset_(TS *ts,void (*func)(TS*,PetscInt*,PetscReal*,Vec*,void*,PetscErrorCode*),void *mctx,void (*d)(void*,PetscErrorCode*),PetscErrorCode *ierr)<br class="">
{<br class="">
CHKFORTRANNULLFUNCTION(d);<br class="">
if ((PetscVoidFunction)func == (PetscVoidFunction) tsmonitordefault_) {<br class="">
*ierr = TSMonitorSet(*ts,(PetscErrorCode (*)(TS,PetscInt,PetscReal,Vec,void*))TSMonitorDefault,*(PetscViewerAndFormat**)mctx,(PetscErrorCode (*)(void **))PetscViewerAndFormatDestroy);<br class="">
} else {<br class="">
*ierr = PetscObjectSetFortranCallback((PetscObject)*ts,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.monitor,(PetscVoidFunction)func,mctx);<br class="">
*ierr = PetscObjectSetFortranCallback((PetscObject)*ts,PETSC_FORTRAN_CALLBACK_CLASS,&_cb.mondestroy,(PetscVoidFunction)d,mctx);<br class="">
*ierr = TSMonitorSet(*ts,ourmonitor,*ts,ourmonitordestroy);<br class="">
}<br class="">
}<br class="">
</blockquote></div>
<span id="gmail-m_-3167854981072692381gmail-m_8759974974518583617gmail-m_2866696447715203370gmail-m_1645657168228053713cid:f_kipwslzw0" class=""><wrapper_petsc.h90></span><span id="gmail-m_-3167854981072692381gmail-m_8759974974518583617gmail-m_2866696447715203370gmail-m_1645657168228053713cid:f_kipwsm1a1" class=""><wrapper_petsc.c></span></div></blockquote></div><br class=""></div></div></blockquote></div>
</div></blockquote></div><br class=""></div></div></div></div></blockquote></div>
</div></blockquote></div><br class=""></div></div></blockquote></div>
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>