Snakelet
Snakelet

Reputation: 43

Translating PDEs into proper Fipy syntax

I was wondering how to code the following equation in FiPy:

The messy equation in question

(In case anyone is curious, it comes from this type of model). I'm having a little trouble translating the third term on the right side into FiPy code. In the example, A and B are both variables.

I tried something of the form:

(ImplicitSourceTerm(coeff=chi_A) * (B.getGrad()) / \
 (numerix.sqrt(1 + lambda_ * (B.getGrad())^2))).getGrad()

But I suppose one cannot .getGrad() something that is not a variable. I would welcome any help; many thanks!

Upvotes: 2

Views: 353

Answers (1)

wd15
wd15

Reputation: 1068

The representation of the term in the question is only an explicit representation. There are two ways to represent the term in an implicit way.

Single Equation for A

Assuming only A is being solved for (a single equation for A), then the term in question can be represented as a ConvectionTerm.

ConvectionTerm(coeff=chi_A * B.getGrad() / \
               numerix.sqrt(1 + lambda_ * B.grad.mag**2), var=A)

See this FAQ.

Multiple Equations for A and B

If A is being solved alongside B (multiple equations), then it's possible to couple the equations so that the term in question can be a diffusion term with B as the variable being solved for (the dependent variable for the term),

DiffusionTerm(coeff=chi_A * A / \
              numerix.sqrt(1 + lambda_ * B.grad.mag**2), var=B)

The equations for A and B then need to be coupled,

coupled_eqn = eqn_A & eqn_B

See this example.

This choice (coupled) is better as the explicit time step restriction on B is more stringent than the time step restriction on A for the term in question.

Note

The syntax, (B.getGrad())^2 in the question is incorrect, it should be B.grad.mag**2.

Upvotes: 2

Related Questions