/[escript]/trunk/doc/examples/geotutorial/backward_euler.py
ViewVC logotype

Annotation of /trunk/doc/examples/geotutorial/backward_euler.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6756 - (hide annotations)
Thu Nov 29 07:23:43 2018 UTC (3 years ago) by aellery
File MIME type: text/x-python
File size: 2392 byte(s)
Temporarily undoing last commit.
1 jfenwick 3981 ##############################################################################
2 gross 2156 #
3 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
4 jfenwick 3981 # http://www.uq.edu.au
5 gross 2156 #
6     # Primary Business: Queensland, Australia
7 jfenwick 6112 # Licensed under the Apache License, version 2.0
8     # http://www.apache.org/licenses/LICENSE-2.0
9 gross 2156 #
10 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
12     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 jfenwick 3981 #
14     ##############################################################################
15 sshaw 5707 from __future__ import division, print_function
16 gross 2156
17 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 gross 2156 Primary Business: Queensland, Australia"""
20 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
21     http://www.apache.org/licenses/LICENSE-2.0"""
22 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
23 gross 2156
24     # import tools
25     from esys.escript import *
26     from esys.escript.linearPDEs import LinearPDE
27 sshaw 5288 try:
28     from esys.dudley import Rectangle
29     HAVE_DUDLEY = True
30     except ImportError:
31     HAVE_DUDLEY = False
32 caltinay 3346 from esys.weipa import saveVTK
33 sshaw 5288
34     if not HAVE_DUDLEY:
35     print("Dudley module not available")
36     else:
37     # end of simulation time
38     t_end=0.1
39     # time step size:
40     dt=0.01
41     # dimensions:
42     L0=1.;L1=1.
43     # location, size and value of heat source
44     xc=[0.3,0.4]; r=0.1; Qc=3000
45     # material parameter
46     k=1; rhocp=100;
47     # bottom temperature:
48     T_bot=100
49     # generate domain:
50     mydomain=Rectangle(l0=L0,l1=L1,n0=20,n1=20)
51     x=mydomain.getX()
52     # set boundray temperature:
53     T_D=T_bot/L1*(L1-x[1])
54     # set heat source:
55     Q=Qc*whereNegative(length(x-xc)-r)
56     # generate domain:
57     mypde=LinearPDE(mydomain)
58     mypde.setSymmetryOn()
59     # set PDE coefficients:
60     mypde.setValue(A=dt*k*kronecker(mydomain), D=dt*rhocp,
61     r=T_D, q=whereZero(x[1])+whereZero(x[1]-L1))
62     # initial temperature
63     T=T_D
64     # step counter and time marker:
65     N=0; t=0
66     # stop when t_end is reached:
67     while t<t_end:
68     print("time step %d, t=%s"%(N,t))
69     # update PDE coefficient:
70     mypde.setValue(Y=dt*rhocp*T+dt*Q)
71     # new temperature:
72     T=mypde.getSolution()
73     # save as VTK for visualisation:
74     saveVTK("u.%s.vtu"%N,T=T)
75     # increase counter and marker:
76     N+=1; t+=dt

  ViewVC Help
Powered by ViewVC 1.1.26