# Help with adding a new routine to the MATMFFD module

Rafael Santos Coelho rafaelsantoscoelho at gmail.com
Thu Jan 8 17:42:15 CST 2009

```Hello everyone,

I've implemented a new routine for computing the differencing parameter "h"
used with the finite-difference based matrix-free Jacobian by the MATMFFD
module. This new approach, which I labeled "avg", can be found in the
article entitled "Jacobian-free Newton-Krylov methods: a survey of
approaches and applications", authored by D. A. Knoll and D. E. Keyes. It
has the following formula:

h = b * {[S / (n * || a ||)] + 1}

- "b" is the square root of the machine round-off (10^-6 for 64-bit
double precision);
- "n" is the problem dimension (number of unknowns);
- "a" is the vector in the Jacobian-vector product that is being
approximated (J(U)a);
- "S" = sum[i = 1, n] |Ui| is the sum of the absolute values of the
solution vector entries.

Well, the programming part is all done and correct, but I'm experiecing
difficulties to (statically) incorporate the routine in the PETSc API. I've
done everything that I could, but whenever I try to test my code by running
an example with the -mat_mffd_type avg command-line option, I get this error
message:

{PETSC_DIR}/petsc-2.3.3-p15/src/snes/examples/tutorials\$ mpirun -np 2 ./ex5
-snes_mf -mat_mffd_type avg
[1]PETSC ERROR: --------------------- Error Message
------------------------------------
[1]PETSC ERROR: Unknown type. Check for miss-spelling or missing external
package needed for type!
[1]PETSC ERROR: Unknown MatMFFD type avg given!
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: Petsc Release Version 2.3.3, Patch 15, Tue Sep 23 10:02:49
CDT 2008 HG revision: 31306062cd1a6f6a2496fccb4878f485c9b91760
[1]PETSC ERROR: See docs/changes/index.html for recent updates.
[1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
[1]PETSC ERROR: See docs/index.html for manual pages.
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: ./ex5 on a linux-gnu named hepburn by rafael Thu Jan  8
19:52:36 2009
/home/rafael/ufes/petsc-2.3.3-p15/lib/linux-gnu-c-debug
[1]PETSC ERROR: Configure run at Sun Nov 23 02:11:51 2008
[1]PETSC ERROR: Configure options --with-cc=mpicc --with-cxx=mpicxx
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: MatMFFDSetType() line 107 in src/mat/impls/mffd/mffd.c
[1]PETSC ERROR: MatMFFDSetFromOptions() line 493 in
src/mat/impls/mffd/mffd.c
[1]PETSC ERROR: SNESSetUp() line 1194 in src/snes/interface/snes.c
[1]PETSC ERROR: SNESSolve() line 1855 in src/snes/interface/snes.c
[1]PETSC ERROR: main() line 209 in src/snes/examples/tutorials/ex5.c
[hepburn:22928] MPI_ABORT invoked on rank 1 in communicator MPI_COMM_WORLD
with errorcode 86
[0]PETSC ERROR: --------------------- Error Message
------------------------------------
[0]PETSC ERROR: Unknown type. Check for miss-spelling or missing external
package needed for type!
[0]PETSC ERROR: Unknown MatMFFD type avg given!
[0]PETSC ERROR:
------------------------------------------------------------------------

So, here's what I did:

1. Put the source code (avg.c) in the {PETSC_DIR}/src/mat/impls/mffd/
directory (when writing the avg.c, I basically followed the same code
structure in the wp.c file);
2. Added "avg.c" and "avg.o" to {PETSC_DIR}/src/mat/impls/mffd/makefile;
3. Added the macro "#define MATMFFD_AVG "avg"" to the petscmat.h file;
4. Called MatMFFDRegisterDynamic(MATMFFD_AVG, path, "MatMFFDCreate_AVG",
MatMFFDCreate_AVG) inside the MatMFFDRegisterAll routine in the mfregis.c
file.

What step am I missing here? Why is this not working? Thanks in advance!

Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20090108/224a4f41/attachment.htm>
```