﻿ Sample Problems > Usage > Misc > ifthen

# ifthen

Navigation:  Sample Problems > Usage > Misc >

# ifthen   { IFTHEN.PDE

This example demonstrates the use of "IF...THEN" conditionals in arithmetic statements.

We solve a heat equation in which the conductivity is defined by a conditional

(IF..THEN) expression.

Caveat:

IF..THEN can be dangerous if used improperly.

Equation coefficients that are discontinuous functions of the system

variables can cause convergence failure or tiny timesteps and slow

execution.  See SWAGETEST.PDE.

}

title 'Nonlinear heatflow, conditional conductivity'

Variables

u

definitions

a =   IF (u<0.5) and (x<100)

THEN   IF u < 0.2

THEN 1.4

ELSE 1+2*abs(u)

ELSE 2

Initial values

u = 1 - (x-1)^2 - (y-1)^2

equations

U: div(a*grad(u)) + 4 = 0;

boundaries

Region 1

start(0,0)

value(u)=0

line to (2,0) to (2,2) to (0,2) to close

monitors

contour(u)

plots

surface(u)

contour(u)

contour(a) as "Conditional Conductivity"

elevation(a,u) from (0,1) to (2,1) as "Conductivity and Solution"

end