[petsc-dev] Missing Fortran interfaces

John O'Sullivan jp.osullivan at auckland.ac.nz
Tue Jun 23 03:11:34 CDT 2015

Hi guys,

Attached is a very simple program in C which uses SNESSetUpdate to switch variables while solving the following nonlinear equation:

In region 1 (x <= 5):
    x^3 - 50 = 0

In region 2 (x > 5):
    y = x + 3
    so solve:
    (y - 3)^3 - 50 = 0

The variable switching stops the solution a small distance across the region boundary so:

if currently in region 1 and x > 5:
    y -> 8 + epsilon,     region -> 2
if currently in region 2 and x <= 8:
   x -> 5 - epsilon,     region -> 1

This is very simplified but analogous to what we want to do. It seems to work ok and has similar convergence to the non-swtiching case (also included).

Obviously this example doesn't change gradients when the variable is switched though.

Could you guys add the fortran interfaces for SNESSetUpdate (missing), and SNESSetApplicationContext and SNESGetApplicationContext (if they're missing) and I will try it out on some more complicated examples.

Thanks very much

Dr John O'Sullivan
Department of Engineering Science
University of Auckland, New Zealand
email: jp.osullivan at auckland.ac.nz<https://lists.mcs.anl.gov/mailman/listinfo/petsc-dev>
tel: +64 (0)9 923 85353

From: Peter Lichtner [peter.lichtner at gmail.com]
Sent: Wednesday, 17 June 2015 8:42 a.m.
To: Barry Smith
Cc: John O'Sullivan; petsc-dev at mcs.anl.gov; Richard Mills
Subject: Re: [petsc-dev] Missing Fortran interfaces

See comments below …Peter

On Jun 16, 2015, at 13:43, Barry Smith <bsmith at mcs.anl.gov<mailto:bsmith at mcs.anl.gov>> wrote:

On Jun 12, 2015, at 10:03 PM, Peter Lichtner <peter.lichtner at gmail.com<mailto:peter.lichtner at gmail.com>> wrote:

Barry: here is an attempt to explain how variable switching works in pflotran (we may need to iterate on this if it's not clear). I will consider as an example the 2-phase, 3-component water-supercritical CO2 system.

Any grid cell (we use finite volume) can exist in one of three possible states: single-phase pure liquid water (l); single-phase pure supercritical CO2 (g); or two-phase coexistence of water and supercritical CO2 (2ph).

Each of these states is described by three independent (nonunique) state variables. One possibility is:

l: (p_l, T, X_CO2^l)
g: (p_g, T, X_CO2^g)
2ph: (p_g, T, s_g)

where p_l,g = liquid or gas pressure, T = temperature, and s_g = volume fraction of pore space occupied by supercritical CO2.

Where variable switching comes into play is when a grid cell undergoes a phase change with the following possibilities:

l -> 2ph
g -> 2ph
2ph -> l
2ph -> g

Note that we do not include directly l <-> g.

As a consequence different regions of space have different primary variables the boundaries of which are changing with time along with the state variables.

Line search is not feasible with the current implementation in petsc.

After a completed time step or Newton iteration, the stability of the solution in each grid cell must be checked for a change of phase. For example, if the cell is in a 2 phase state, but the solution gives s_g > 1 or s_g < 1,

  Do you mean s_q < 0 or can s_g only be 1?

This was a typo—sorry about that: I meant s_g < 0 or s_g > 1 triggers a phase change. For a two-phase system the physical values of s_g are: 0 < s_g < 1.

then a phase change occurs from 2ph -> g or 2ph -> l, respectively, and a change of variables is necessary:

(p_g, T, s_g) -> (p_l, T, X_CO2^l)


(p_g, T, s_g) -> (p_g, T, X_CO2^g)

Agree with John here.

what is the formula for these change of variables?

how/when do g and l go to 2p_h ?




On Jun 12, 2015, at 18:14, Barry Smith <bsmith at mcs.anl.gov<mailto:bsmith at mcs.anl.gov>> wrote:


We can provide any Fortran stubs you need but before we do could you please outline to us (in algebraic notation; not in reference to PETSc code) how you plan to handle your "variable switching". That is, what is the problem being solved, what are the constraints, when do you need to switch variables etc?

I would say everyone who has tried to do variable switching in PETSc before has failed because we (the PETSc developers) did not help them enough and  understand what is needed in the Newton solver. I suspect we need to provide a bit more functionality in PETSc to make variable switching a success and I'd like to understand what that is and add it to the PETSc algorithms. Also if you know of any references that actually explain variable switching in detail, that would be great, all I've found are vague hand-wavy discussions that leave too many important details unexplained.



On Jun 12, 2015, at 5:54 PM, John O'Sullivan <jp.osullivan at auckland.ac.nz<mailto:jp.osullivan at auckland.ac.nz>> wrote:


We're working on changing variables during an SNES solve so that we can handle phase changes.

I'm looking into using SNESSetUpdate but there doesn't seem to be a fortran interface. I get an error:

Undefined symbols for architecture x86_64:
"_snessetupdate_", referenced from:
   _MAIN__ in phaseChange.o

I've looked in the interface files and can't find it either. I tried writing one myself but things get a bit too complicated to guess...

Can an interface be added please?

Is this the best to do variable switching? If not where would be the right place and are there Fortran interfaces? We will be changing from Pressure, Temperature to Pressure, Saturation etc. But for now I'm just working on a simple example code.

Dr John O'Sullivan
Department of Engineering Science
University of Auckland, New Zealand
jp.osullivan at auckland.ac.nz<http://auckland.ac.nz>

tel: +64 (0)9 923 85353

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20150623/ef70d70a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ex1ajpo.c
Type: application/octet-stream
Size: 10679 bytes
Desc: ex1ajpo.c
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20150623/ef70d70a/attachment.obj>

More information about the petsc-dev mailing list