From charlesreid1

bug in adsorbingSurfactantEquation.py?
5 messages
Charles Reid <charlesreid1@gmail.com>	 Thu, Dec 12, 2013 at 4:26 PM
To: fipy@nist.gov
Hi there,

While using the AdsorbingSurfactantEquation class, defined in the electroChem example, located in:

fipy/examples/levelSet/electroChem/adsorbingSurfactantEquation.py

I noticed two lines that seem erroneous, both related to the timestep used for the solution. On line 331, the following code:

        self.eq.solve(var,
                      boundaryConditions=boundaryConditions,
                      solver = solver,
                      dt=1.)

should, I think, be:

        self.eq.solve(var,
                      boundaryConditions=boundaryConditions,
                      solver = solver,
                      dt=self.dt)

and likewise, line 358, the following code:

        return self.eq.sweep(var, solver=solver, boundaryConditions=boundaryConditions, underRelaxation=underRelaxation, residualFn=residualFn, dt=1.)

should be:

        return self.eq.sweep(var, solver=solver, boundaryConditions=boundaryConditions, underRelaxation=underRelaxation, residualFn=residualFn, dt=self.dt)

so that the timestep information set by the user is not ignored. Attached is a patch (created with git diff --no-prefix) that fixes this. If it passes the muster, would someone mind checking the change into the git repository?

Thanks,
Charles


		adsorbingSurfactantEquation_dt_fix.patch
2K
Daniel Wheeler <daniel.wheeler2@gmail.com>	 Fri, Dec 13, 2013 at 8:51 AM
Reply-To: fipy@nist.gov
To: Multiple recipients of list <fipy@nist.gov>
On Thu, Dec 12, 2013 at 7:26 PM, Charles Reid <charlesreid1@gmail.com> wrote:
> Hi there,
>
> While using the AdsorbingSurfactantEquation class, defined in the
> electroChem example, located in:
>
> fipy/examples/levelSet/electroChem/adsorbingSurfactantEquation.py
>
> I noticed two lines that seem erroneous, both related to the timestep used
> for the solution. On line 331, the following code:
>
>         self.eq.solve(var,
>                       boundaryConditions=boundaryConditions,
>                       solver = solver,
>                       dt=1.)

Hi Charles,

This isn't a mistake. I know it is very confusing. It should probably
not take a time step at all. The equation in question is not
controlled by the time step. It evolves with the zero level set. It
stores values at cells that are close to the zero level set and when
the zero level set moves the material is "pushed" by the zero level
set from cell to cell. The main benefit of this method is that it is
entirely conservative, but it is only first order accurate. Hope this
helps to explain what''s happening a little bit. I can field more
questions if you need to use it for a problem.

Thanks for the patch and don't be shy about submitting more patches.

Cheers,

Daniel

--
Daniel Wheeler
_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
Charles Reid <charlesreid1@gmail.com>	 Mon, Dec 16, 2013 at 11:40 AM
To: fipy@nist.gov
Hi Daniel,

Thanks very much for your response. I am interested in using the class for solving a catalysis problem, where surface species coverages evolve with time. From the documentation, I've gathered that the class solves the same equations I'm using to model my system (& I'm interested in extending the class to three or more surface variables). I follow what you mean about zero level set approach (some trial-and-error helped me make sense of this), but I'm having trouble understanding why the timestep doesn't come into play, so I have a few questions to help clarify.

Is the time-evolution tied to the interface's/zero-level-set's time-evolution, such that for each change in location of the interface, a steady-state equation is solved, and the time-evolution of the equation is kind of "implicit" with the interface's time-evolution (which is how I interpret your comment about material being pushed by the zero level set)? If this is the case, why would there be a transient term in the equation defined in the AdsorbingSurfactantEquation class, instead of solving a steady-state equation and calling solve() when the interface moves?

More numerical experiments have raised more questions. I tried varying the timestep, to see what effect it had, and it ended up changing the solution. I've attached a simple example (ASE.py contains the AdsorbingSurfactantEquation class, same as in the git repository but with the patch applied so that dt can be changed, and simpleExample.py contains a simple 1D example with a 10-cell one-dimensional domain, and a zero-level at the middle of the domain) and its output (output.png). The simple example plots the interface variable value with time; it increases, but at a decreasing rate, which makes sense physically, since as the surface coverage increases, the rate at which the surface species is adsorbed decreases. I've run it for several values of timesteps, and the timestep apparently affects the solution. I'm confused as to what makes a value of dt=1.0 (the hard-coded dt value in AdsorbingSurfactantEquation in the git repository) special? And why do you think it shouldn't take a timestep at all?

Thanks for the help!




Charles
[Quoted text hidden]

3 attachments
		output.png
81K
		ASE.py
7K
		simpleExample.py
2K
Daniel Wheeler <daniel.wheeler2@gmail.com>	 Tue, Dec 17, 2013 at 9:35 AM
Reply-To: fipy@nist.gov
To: Multiple recipients of list <fipy@nist.gov>
On Mon, Dec 16, 2013 at 2:40 PM, Charles Reid <charlesreid1@gmail.com> wrote:
> Hi Daniel,
>
> Thanks very much for your response. I am interested in using the class for
> solving a catalysis problem, where surface species coverages evolve with
> time. From the documentation, I've gathered that the class solves the same
> equations I'm using to model my system (& I'm interested in extending the
> class to three or more surface variables).

I've solved for three surface variable in some of my electrochemistry
work. Getting the interactions right can be quite difficult.

> Is the time-evolution tied to the interface's/zero-level-set's
> time-evolution, such that for each change in location of the interface, a
> steady-state equation is solved, and the time-evolution of the equation is
> kind of "implicit" with the interface's time-evolution (which is how I
> interpret your comment about material being pushed by the zero level set)?

Yes. That is exactly how it works.

> If this is the case, why would there be a transient term in the equation
> defined in the AdsorbingSurfactantEquation class, instead of solving a
> steady-state equation and calling solve() when the interface moves?

Basically, the equation is multiplied through by "dt" so the transient
term is just a sort of update term. Take a look at the following

    https://docs.google.com/file/d/0B4101gT3tHveVUhZZHRwXzlCSDg/edit

Equation 26 does not have a time step associated with it. The time is
only needed in the adsorption term.

> More numerical experiments have raised more questions. I tried varying the
> timestep, to see what effect it had, and it ended up changing the solution.

It will, but it isn't doing anything sensible if the time step is
anything other than 1. It should probably use source terms instead of
a transient term. It would make this a lot less confusing.

> I've attached a simple example (ASE.py contains the
> AdsorbingSurfactantEquation class, same as in the git repository but with
> the patch applied so that dt can be changed, and simpleExample.py contains a
> simple 1D example with a 10-cell one-dimensional domain, and a zero-level at
> the middle of the domain) and its output (output.png). The simple example
> plots the interface variable value with time; it increases, but at a
> decreasing rate, which makes sense physically, since as the surface coverage
> increases, the rate at which the surface species is adsorbed decreases. I've
> run it for several values of timesteps, and the timestep apparently affects
> the solution. I'm confused as to what makes a value of dt=1.0 (the
> hard-coded dt value in AdsorbingSurfactantEquation in the git repository)
> special?

It is totally confusing. Hopefully reading the above link will help
explain. Adding the time step as you have done essentially means that
your time step is 'dt**2'.

> And why do you think it shouldn't take a timestep at all?

It needs a time step for the rate of adsorption. No time step is
needed simply for evolving a fixed surfactant quantity, which is
neither desorbing or adsorbing. The problem is that the equation
doesn't really fit neatly into the FiPy framework very well. It
probably belongs more with the level set module.

> Thanks for the help!

I hope it does help.
[Quoted text hidden]
Charles Reid <charlesreid1@gmail.com>	 Tue, Dec 17, 2013 at 12:19 PM
To: fipy@nist.gov
Ah! This makes a lot more sense now. With your explanation and the document, it makes sense - particularly, thinking about the transient term as a source term instead of a transient term. Thanks for sending the link; the document is very clear and thorough.

I also saw several references to Harry Moffat's work - I know of Harry's work through my use of Cantera, for which Harry is a primary developer. His approach is (presumably) the same as, or similar to, what's in Cantera, which is the tool I'm currently using to solve coverage equations for catalysts. So making that connection was very helpful too!