<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1" class="" style="word-wrap:break-word">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi guys,<br>
<br>
Attached is a very simple program in C which uses SNESSetUpdate to switch variables while solving the following nonlinear equation:<br>
<br>
In region 1 (x <= 5):<br>
x^3 - 50 = 0<br>
<br>
In region 2 (x > 5):<br>
y = x + 3<br>
so solve:<br>
(y - 3)^3 - 50 = 0<br>
<br>
The variable switching stops the solution a small distance across the region boundary so:<br>
<br>
if currently in region 1 and x > 5:<br>
y -> 8 + epsilon, region -> 2<br>
if currently in region 2 and x <= 8:<br>
x -> 5 - epsilon, region -> 1<br>
<br>
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).<br>
<br>
Obviously this example doesn't change gradients when the variable is switched though.<br>
<br>
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.<br>
<br>
Thanks very much<br>
John<br>
<div><br>
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">
<pre>--<br>Dr John O'Sullivan
Lecturer
Department of Engineering Science
University of Auckland, New Zealand
email: <a href="https://lists.mcs.anl.gov/mailman/listinfo/petsc-dev">jp.osullivan at auckland.ac.nz</a>
tel: +64 (0)9 923 85353</pre>
</div>
</div>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF808159"><font face="Tahoma" color="#000000" size="2"><b>From:</b> Peter Lichtner [peter.lichtner@gmail.com]<br>
<b>Sent:</b> Wednesday, 17 June 2015 8:42 a.m.<br>
<b>To:</b> Barry Smith<br>
<b>Cc:</b> John O'Sullivan; petsc-dev@mcs.anl.gov; Richard Mills<br>
<b>Subject:</b> Re: [petsc-dev] Missing Fortran interfaces<br>
</font><br>
</div>
<div></div>
<div>See comments below …Peter
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Jun 16, 2015, at 13:43, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" class="" target="_blank">bsmith@mcs.anl.gov</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<blockquote type="cite" class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="Apple-interchange-newline">
On Jun 12, 2015, at 10:03 PM, Peter Lichtner <<a href="mailto:peter.lichtner@gmail.com" class="" target="_blank">peter.lichtner@gmail.com</a>> wrote:<br class="">
<br class="">
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.<span class="Apple-converted-space"> </span><br class="">
<br class="">
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).<br class="">
<br class="">
Each of these states is described by three independent (nonunique) state variables. One possibility is:<br class="">
<br class="">
l: (p_l, T, X_CO2^l)<br class="">
g: (p_g, T, X_CO2^g)<br class="">
2ph: (p_g, T, s_g)<br class="">
<br class="">
where p_l,g = liquid or gas pressure, T = temperature, and s_g = volume fraction of pore space occupied by supercritical CO2.<br class="">
<br class="">
Where variable switching comes into play is when a grid cell undergoes a phase change with the following possibilities:<br class="">
<br class="">
l -> 2ph<br class="">
g -> 2ph<br class="">
2ph -> l<br class="">
2ph -> g<br class="">
<br class="">
Note that we do not include directly l <-> g.<br class="">
<br class="">
As a consequence different regions of space have different primary variables the boundaries of which are changing with time along with the state variables.<br class="">
<br class="">
Line search is not feasible with the current implementation in petsc.<br class="">
<br class="">
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,<br class="">
</blockquote>
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<span class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important"> Do
you mean s_q < 0 or can s_g only be 1?</span><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
</div>
</blockquote>
<div><br class="">
</div>
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.<br class="">
<blockquote type="cite" class="">
<div class=""><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<blockquote type="cite" class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
then a phase change occurs from 2ph -> g or 2ph -> l, respectively, and a change of variables is necessary:<span class="Apple-converted-space"> </span><br class="">
<br class="">
(p_g, T, s_g) -> (p_l, T, X_CO2^l)<br class="">
<br class="">
or<br class="">
<br class="">
(p_g, T, s_g) -> (p_g, T, X_CO2^g)<br class="">
</blockquote>
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
</div>
</blockquote>
Agree with John here.</div>
<div><br class="">
<blockquote type="cite" class="">
<div class=""><span class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important">what
is the formula for these change of variables?</span><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<span class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important">how/when
do g and l go to 2p_h ?</span><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<span class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important"> Thanks</span><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<span class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; float:none; display:inline!important"> Barry</span><br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<blockquote type="cite" class="" style="font-family:Menlo-Regular; font-size:14px; font-style:normal; font-variant:normal; font-weight:normal; letter-spacing:normal; line-height:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px">
<br class="">
…Peter<br class="">
<br class="">
<blockquote type="cite" class="">On Jun 12, 2015, at 18:14, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" class="" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br class="">
<br class="">
<br class="">
John,<br class="">
<br class="">
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?<br class="">
<br class="">
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.<br class="">
<br class="">
Thanks<br class="">
<br class="">
Barry<br class="">
<br class="">
<blockquote type="cite" class="">On Jun 12, 2015, at 5:54 PM, John O'Sullivan <<a href="mailto:jp.osullivan@auckland.ac.nz" class="" target="_blank">jp.osullivan@auckland.ac.nz</a>> wrote:<br class="">
<br class="">
Hi,<br class="">
<br class="">
We're working on changing variables during an SNES solve so that we can handle phase changes.<br class="">
<br class="">
I'm looking into using SNESSetUpdate but there doesn't seem to be a fortran interface. I get an error:<br class="">
<br class="">
Undefined symbols for architecture x86_64:<br class="">
"_snessetupdate_", referenced from:<br class="">
_MAIN__ in phaseChange.o<br class="">
<br class="">
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...<br class="">
<br class="">
Can an interface be added please?<br class="">
<br class="">
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.<span class="Apple-converted-space"> </span><br class="">
<br class="">
Cheers<br class="">
John<br class="">
--<br class="">
Dr John O'Sullivan<br class="">
Lecturer<br class="">
Department of Engineering Science<br class="">
University of Auckland, New Zealand<br class="">
email:<span class="Apple-converted-space"> </span><br class="">
jp.osullivan at <a href="http://auckland.ac.nz" class="" target="_blank">auckland.ac.nz</a><br class="">
<br class="">
tel: +64 (0)9 923 85353</blockquote>
</blockquote>
</blockquote>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</body>
</html>