/[escript]/trunk/finley/test/python/FCT_test1.py
ViewVC logotype

Contents of /trunk/finley/test/python/FCT_test1.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4821 - (show annotations)
Tue Apr 1 04:58:33 2014 UTC (5 years, 4 months ago) by sshaw
File MIME type: text/x-python
File size: 3661 byte(s)
moved SolverOptions to c++, split into SolverOptions for the options and SolverBuddy as the state as a precursor to per-pde solving... does break some use cases (e.g. pde.getSolverOptions().DIRECT will now fail, new value access is with SolverOptions.DIRECT), examples and documentation updated to match
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16 from __future__ import print_function
17
18 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23 __url__="https://launchpad.net/escript-finley"
24
25 #
26 # upwinding test moving a Gaussian hill around
27 #
28 # we solve U_,t + v_i u_,i =0
29 #
30 # the solution is given as u(x,t)=1/(4*pi*E*t)^{dim/2} * exp ( - |x-x_0(t)|^2/(4*E*t) )
31 #
32 # where x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=2 and
33 #
34 # x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=3
35 #
36 # the solution is started from some time T0>0.
37 #
38 # We are using five quality messurements for u_h
39 #
40 # - inf(u_h) > 0
41 # - sup(u_h)/sup(u(x,t)) = sup(u_h)*(4*pi*E*t)^{dim/2} ~ 1
42 # - integrate(u_h) ~ 1
43 # - | x_0h-x_0 | ~ 0 where x_0h = integrate(x*u_h)
44 # - sigma_h/4*E*t ~ 1 where sigma_h=sqrt(integrate(length(x-x0h)**2 * u_h) * (DIM==3 ? sqrt(2./3.) :1 )
45 #
46 #
47
48 from esys.escript import *
49 from esys.escript.linearPDEs import TransportPDE, SolverOptions
50 from esys.finley import Rectangle, Brick
51 #from esys.ripley import Rectangle, Brick
52 from esys.weipa import saveVTK
53 from math import pi, ceil
54 NE=128
55 #NE=4
56 DIM=2
57 THETA=0.5
58 OMEGA0=1.
59 ALPHA=pi/4
60 T0=0
61 T_END=2.*pi
62 dt=1e-3*10*10
63 E=1.e-3
64
65
66 dom=Rectangle(NE,NE)
67 u0=dom.getX()[0]
68 # saveVTK("u.%s.vtu"%0,u=u0)
69 # print "XX"*80
70
71 # set initial value
72 #dom.setX(2*dom.getX()-1)
73 #x=dom.getX()
74 #r=sqrt(x[0]**2+(x[1]-1./3.)**2)
75 #u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5))
76
77 #x=Function(dom).getX()
78 #if DIM == 2:
79 # V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0])
80 #else:
81 # V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.])
82
83 x=dom.getX()
84
85 R0=0.15
86 #cylinder:
87 X0=0.5
88 Y0=0.75
89 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
90 u0=whereNegative(r-1)*wherePositive(wherePositive(abs(x[0]-X0)-0.025)+wherePositive(x[1]-0.85))
91 # cone:
92 X0=0.5
93 Y0=0.25
94 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
95 u0=u0+wherePositive(1-r)*(1-r)
96 #hump
97 X0=0.25
98 Y0=0.5
99 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
100 u0=u0+1./4.*(1+cos(pi*clip(r,maxval=1)))
101
102 x=Function(dom).getX()
103 V=OMEGA0*((0.5-x[0])*[0,1]+(0.5-x[1])*[-1,0])
104 #===================
105
106 fc=TransportPDE(dom,numEquations=1)
107 fc.getSolverOptions().setVerbosityOn()
108 #fc.getSolverOptions().setODESolver(SolverOptions.BACKWARD_EULER)
109 fc.getSolverOptions().setODESolver(SolverOptions.LINEAR_CRANK_NICOLSON)
110 fc.getSolverOptions().setODESolver(SolverOptions.CRANK_NICOLSON)
111 x=Function(dom).getX()
112 fc.setValue(M=1,C=V)
113
114 c=0
115 saveVTK("u.%s.vtu"%c,u=u0)
116 fc.setInitialSolution(u0)
117 dt=fc.getSafeTimeStepSize()
118 #dt=1.e-3
119 print("dt = ",dt)
120 t=T0
121 print("QUALITY FCT: time = %s pi"%(t/pi),inf(u0),sup(u0),integrate(u0))
122 #T_END=200*dt
123 while t<T_END:
124
125 print("time step t=",t+dt)
126 u=fc.getSolution(dt)
127 print("QUALITY FCT: time = %s pi"%(t+dt/pi),inf(u),sup(u),integrate(u))
128 saveVTK("u.%s.vtu"%(c+1,),u=u)
129 c+=1
130 t+=dt

  ViewVC Help
Powered by ViewVC 1.1.26