• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision3c24066b5cd0bb10668cef2bf5c45939cd99b34e (tree)
Time2011-03-29 01:25:56
Authorlorenzo
Commiterlorenzo

Log Message

I added a script solving the diffusion equation on a circle.

Change Summary

Incremental Difference

diff -r e61011792ce9 -r 3c24066b5cd0 Python-codes/circle.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/circle.py Mon Mar 28 16:25:56 2011 +0000
@@ -0,0 +1,78 @@
1+#!/usr/bin/env python
2+
3+
4+from fipy import *
5+
6+
7+cellSize = 0.05
8+radius = 1.
9+
10+transient=0
11+
12+mesh = GmshImporter2D('''
13+ cellSize = %(cellSize)g;
14+ radius = %(radius)g;
15+ Point(1) = {0, 0, 0, cellSize};
16+ Point(2) = {-radius, 0, 0, cellSize};
17+ Point(3) = {0, radius, 0, cellSize};
18+ Point(4) = {radius, 0, 0, cellSize};
19+ Point(5) = {0, -radius, 0, cellSize};
20+ Circle(6) = {2, 1, 3};
21+ Circle(7) = {3, 1, 4};
22+ Circle(8) = {4, 1, 5};
23+ Circle(9) = {5, 1, 2};
24+ Line Loop(10) = {6, 7, 8, 9};
25+ Plane Surface(11) = {10};
26+ ''' % locals())
27+
28+
29+
30+phi = CellVariable(name = "solution variable",mesh = mesh,value = 0.)
31+
32+viewer = None
33+if __name__ == '__main__':
34+ try:
35+ viewer = Viewer(vars=phi, datamin=-1, datamax=1.)
36+ viewer.plotMesh()
37+ raw_input("Irregular circular mesh. Press <return> to proceed...")
38+ except:
39+ print "Unable to create a viewer for an irregular mesh (try Gist2DViewer, Matplotlib2DViewer, or MayaviViewer)"
40+
41+D = 1.
42+
43+X, Y = mesh.getFaceCenters()
44+
45+BCs = (FixedValue(faces=mesh.getExteriorFaces(), value=X),)
46+
47+
48+if (transient==1):
49+
50+ eq = TransientTerm() == DiffusionTerm(coeff=D)
51+
52+
53+ timeStepDuration = 10 * 0.9 * cellSize**2 / (2 * D)
54+ steps = 10
55+ for step in range(steps):
56+ eq.solve(var=phi,boundaryConditions=BCs,dt=timeStepDuration)
57+ if viewer is not None:
58+ viewer.plot()
59+
60+
61+ TSVViewer(vars=(phi, phi.getGrad())).plot(filename="myTSV.tsv")
62+
63+# SS solution
64+
65+
66+DiffusionTerm(coeff=D).solve(var=phi,boundaryConditions=BCs)
67+
68+
69+print "phi.allclose(X, atol = 0.02), ", phi.allclose(X, atol = 0.02)
70+
71+if viewer is not None:
72+ viewer.plot()
73+ raw_input("Steady-state diffusion. Press <return> to proceed...")
74+
75+
76+
77+
78+print "So far so good"