<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Fipy%2FMultiple_Variable_Transient_Problem</id>
	<title>Fipy/Multiple Variable Transient Problem - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Fipy%2FMultiple_Variable_Transient_Problem"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Fipy/Multiple_Variable_Transient_Problem&amp;action=history"/>
	<updated>2026-06-19T18:28:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Fipy/Multiple_Variable_Transient_Problem&amp;diff=4773&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;This page covers the solution of a pair of coupled ODEs using Fipy.  =The Equation=  This script solves the following differential equations:  &lt;math&gt; \frac{dy}{dt} = -  \frac...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Fipy/Multiple_Variable_Transient_Problem&amp;diff=4773&amp;oldid=prev"/>
		<updated>2014-01-13T20:39:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This page covers the solution of a pair of coupled ODEs using &lt;a href=&quot;/wiki/Fipy&quot; title=&quot;Fipy&quot;&gt;Fipy&lt;/a&gt;.  =The Equation=  This script solves the following differential equations:  &amp;lt;math&amp;gt; \frac{dy}{dt} = -  \frac...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page covers the solution of a pair of coupled ODEs using [[Fipy]].&lt;br /&gt;
&lt;br /&gt;
=The Equation=&lt;br /&gt;
&lt;br /&gt;
This script solves the following differential equations:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{dy}{dt} = - &lt;br /&gt;
\frac{dz}{dt} = \phi y - (1 - \phi) z &lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\phi = sin (2*pi*t) \left[ \exp^{- t/100} \right]&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
with initial condition&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
y(t=0) = 1.0&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
which has the exact solution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
y(t) = 1.5556 \exp( -1.8 t ) - 0.5556&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information about this problem is available via [http://wolfr.am/1eveai5 Wolfram Alpha].&lt;br /&gt;
&lt;br /&gt;
=The Script=&lt;br /&gt;
&lt;br /&gt;
==Import Statements==&lt;br /&gt;
&lt;br /&gt;
We begin with our usual import statements, which allow us to use [[Fipy]] for solving the equation and [[Matplotlib]] for plotting results.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
from numpy import *&lt;br /&gt;
import matplotlib.pylab as plt&lt;br /&gt;
from fipy import *&lt;br /&gt;
&lt;br /&gt;
# Set up figure for plotting&lt;br /&gt;
fig = plt.figure()&lt;br /&gt;
ax = fig.add_subplot(111)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Input Parameters==&lt;br /&gt;
&lt;br /&gt;
The first thing we&amp;#039;ll do is set some parameters, which we will then use to construct Fipy objects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
##############################&lt;br /&gt;
# Set Fipy parameters&lt;br /&gt;
&lt;br /&gt;
# number of cells in mesh&lt;br /&gt;
nx = 1&lt;br /&gt;
&lt;br /&gt;
# timesteps&lt;br /&gt;
deltat = 0.1&lt;br /&gt;
nt = 100&lt;br /&gt;
&lt;br /&gt;
# initial value&lt;br /&gt;
iv = 1.0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Fipy Objects==&lt;br /&gt;
&lt;br /&gt;
Now assemble Fipy objects using user parameters&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
##############################&lt;br /&gt;
# Assemble Fipy objects&lt;br /&gt;
&lt;br /&gt;
# create the mesh&lt;br /&gt;
mesh = Grid1D(nx=nx,dx=1.0)&lt;br /&gt;
&lt;br /&gt;
# create the variable&lt;br /&gt;
y = CellVariable(mesh=mesh, value=iv, hasOld=1, name=&amp;#039;y&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# create the equation&lt;br /&gt;
RHS = -1.8*y - 1.0&lt;br /&gt;
eq = TransientTerm() == RHS&lt;br /&gt;
&lt;br /&gt;
# solver&lt;br /&gt;
from fipy.solvers import LinearPCGSolver&lt;br /&gt;
solver = LinearPCGSolver()&lt;br /&gt;
#from fipy.solvers import DefaultAsymmetricSolver&lt;br /&gt;
#solver = DefaultAsymmetricSolver()&lt;br /&gt;
&lt;br /&gt;
# timesteps and steps &lt;br /&gt;
dt = Variable(deltat)&lt;br /&gt;
steps = nt&lt;br /&gt;
t = dt.value * steps&lt;br /&gt;
solutions = zeros([steps+1,nx])&lt;br /&gt;
solutions[0,:] = y.value &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Solution Loop==&lt;br /&gt;
&lt;br /&gt;
Loop over each step and solve the differential equation over that step:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
# loop over timesteps &lt;br /&gt;
for step in [i+1 for i in range(steps)]:&lt;br /&gt;
    y.updateOld()&lt;br /&gt;
    eq.solve(y,&lt;br /&gt;
            solver = solver,&lt;br /&gt;
            dt=dt)&lt;br /&gt;
&lt;br /&gt;
    # store solutions&lt;br /&gt;
    solutions[step] = y.value&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Plot Computed and Exact Solution==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
ts = linspace(0,t,steps)&lt;br /&gt;
&lt;br /&gt;
# plot computed solution&lt;br /&gt;
ax.plot(ts,solutions[:step],&amp;#039;bo&amp;#039;,label=&amp;#039;Computed&amp;#039;)#arange(len(y.value)),y.value)&lt;br /&gt;
&lt;br /&gt;
# plot exact solution&lt;br /&gt;
y2 = 1.5556*exp(-1.8*ts) - 0.5556 &lt;br /&gt;
plt.hold(True)&lt;br /&gt;
ax.plot(ts,y2,&amp;#039;r-&amp;#039;,label=&amp;#039;Exact&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
ax.legend(); plt.show(); plt.draw()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The Result=&lt;br /&gt;
&lt;br /&gt;
This should result in the following plot:&lt;br /&gt;
&lt;br /&gt;
[[Image:FipySimpleTransient.png]]&lt;br /&gt;
&lt;br /&gt;
=The Py File=&lt;br /&gt;
&lt;br /&gt;
http://files.charlesmartinreid.com/FipySimpleTransient.py&lt;br /&gt;
&lt;br /&gt;
[[Category:Fipy]]&lt;br /&gt;
[[Category:Cantera]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>