[petsc-users] complex values in a bvp

Swenson, Jennifer jswenson at mail.smu.edu
Mon Dec 4 15:26:13 CST 2017


Dear PETSc Users,


I have modified ex14 "Bratu nonlinear PDE in 3D" from the PETSc online examples (http://www.mcs.anl.gov/petsc/petsc-3.7/src/snes/examples/tutorials/ex14.c.html) to fit my current research problem.


Notable changes of ex14 include reducing the size of the problem to 1D and using -snes_fd_color in the Makefile instead of the given "FormJacobian" function. When using this edited version of ex14, we obtained the desired outcome of a simple Stokes test problem. Now, we extend this work to our actual problem, a boundary value problem. Although the code compiles and runs, the output does not match our analytical results.


We think that the issue is at least in part due to our equations including complex numbers via PETSC_i. We have noticed that there is a difference in output when using PetscScalar vs PetscComplex when testing PETSC_i:


  PetscScalar   test=10.0+PETSC_i*2.0;

  printf("%f+%fi\n", crealf(test), cimagf(test));

The result is 10.000000+0.000000i.


  PetscComplex   test=10.0+PETSC_i*2.0;

  printf("%f+%fi\n", crealf(test), cimagf(test));

The result is 10.000000+2.000000i.


This compelled us to change our variables (and even real parameters used with those variables) from PetscScalar to PetscComplex in FormFunction, while leaving our hz, dhz as PetscScalars:



  PetscScalar        hz, dhz;

  PetscComplex   Q=0.5, h21=1.0;

  PetscComplex   u, uz, w, wz, p, pz;



  hz     = 1.0/(PetscScalar)(Mx-1);
  dhz    = 1.0/hz;

...


  // u component of velocity
  u   = x[i].x_vel;
  uz  = (x[i].x_vel - x[i-1].x_vel)*dhz;

  // w component of velocity
  w   = x[i].z_vel;
  wz  = (x[i].z_vel - x[i-1].z_vel)*dhz;

  // pressure
  p  = x[i].pressure;
  pz = (x[i].pressure - x[i-1].pressure)*dhz;


  f[i].x_vel    = (uz + PETSC_i*Q*w + 2.0*PETSC_i*Q*h21)/(dhz);

  f[i].z_vel    = (-p + 2.0*wz)/(dhz);
  f[i].pressure = (PETSC_i*Q*u + wz)/(dhz);


This switch from PetscScalar to PetscComplex did fix the discrepancy. Therefore, we also tried to change our Field variables from PetscScalar to PetscComplex:


typedef struct {
  PetscScalar x_vel, z_vel, pressure; // variables for our system
} Field;

However, an error is thrown when the program runs:

[0]PETSC ERROR: PetscMallocValidate: error detected at  SNESComputeFunction() line 2144 in /usr/local/src/petsc-dev/src/snes/interface/snes.c
[0]PETSC ERROR: Memory at address 0x1af7d20 is corrupted
[0]PETSC ERROR: Probably write past beginning or end of array
[0]PETSC ERROR: Last intact block allocated in PetscLayoutSetUp() line 147 in /usr/local/src/petsc-dev/src/vec/is/utils/pmap.c
[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Memory corruption: http://www.mcs.anl.gov/petsc/documentation/installation.html#valgrind
[0]PETSC ERROR:
[0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.7.6, unknown
[0]PETSC ERROR: ./idea2.exe on a arch-linux2-c-debug named lovelace by jswenson Mon Dec  4 14:59:04 2017
[0]PETSC ERROR: Configure options --prefix=/usr/local/petsc-dev --with-64-bit-indices=0 --with-fortran-interfaces=1 --CFLAGS=-O2 --CXXFLAGS=-O2 --FFLAGS=-O2 --download-hypre=yes --download-fftw=yes --download-superlu=yes --download-sundials=yes --download-metis=yes --download-parmetis=yes --download-superlu_dist=yes --download-spai=yes --download-sprng=1 --download-hdf5=yes --with-valgrind=0 --with-mpi-dir=/usr --with-shared-libraries=1 --with-c2html=0 --PETSC_ARCH=arch-linux2-c-debug
[0]PETSC ERROR: #1 PetscMallocValidate() line 136 in /usr/local/src/petsc-dev/src/sys/memory/mtr.c
[0]PETSC ERROR: #2 SNESComputeFunction() line 2144 in /usr/local/src/petsc-dev/src/snes/interface/snes.c
[0]PETSC ERROR: #3 SNESSolve_NEWTONLS() line 181 in /usr/local/src/petsc-dev/src/snes/impls/ls/ls.c
[0]PETSC ERROR: #4 SNESSolve() line 4005 in /usr/local/src/petsc-dev/src/snes/interface/snes.c

My specific questions are the following:

  1.  Is it important to have my Field variables PetscComplex or is PetscScalar sufficient?
  2.  Are there any foreseeable problems with using PETSC_i (or complex numbers in general) with this method from ex14? Do I need to somehow indicate to PETSc that I am using complex values? Am I just lacking an argument or an additional line?
  3.  Is there a nice way to save the solution (to be plotted) besides including -snes_monitor_solution ascii:myproblem.txt in the Makefile and writing an additional code to read and plot the results? For example, on a separate project, I really appreciated the functionality of -ts_monitor_solution_vtk  aks=.5%05D.vts in the Makefile. A similar technique would be useful here, if it exists. I have tried -snes_monitor_solution draw -draw_pause -1, but do not know if that works with complex values. Additionally, as far as I can tell, these plots cannot be saved.

Any other comments or insight would be greatly appreciated. Thank you for your time.

Sincerely,
Jennifer Swenson

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20171204/b4326756/attachment.html>


More information about the petsc-users mailing list