/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (20 months, 1 week ago) by jfenwick
File MIME type: text/x-python
File size: 3659 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
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
17 from __future__ import print_function, division
18
19 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Apache License, version 2.0
23 http://www.apache.org/licenses/LICENSE-2.0"""
24 __url__="https://launchpad.net/escript-finley"
25
26 #
27 # upwinding test moving a Gaussian hill around
28 #
29 # we solve U_,t + v_i u_,i =0
30 #
31 # the solution is given as u(x,t)=1/(4*pi*E*t)^{dim/2} * exp ( - |x-x_0(t)|^2/(4*E*t) )
32 #
33 # where x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=2 and
34 #
35 # x_0(t) = [ cos(OMEGA0*T0)*0.5,-sin(OMEGA0*T0)*0.5 ] and v=[-y,x]*OMEGA0 for dim=3
36 #
37 # the solution is started from some time T0>0.
38 #
39 # We are using five quality messurements for u_h
40 #
41 # - inf(u_h) > 0
42 # - sup(u_h)/sup(u(x,t)) = sup(u_h)*(4*pi*E*t)^{dim/2} ~ 1
43 # - integrate(u_h) ~ 1
44 # - | x_0h-x_0 | ~ 0 where x_0h = integrate(x*u_h)
45 # - sigma_h/4*E*t ~ 1 where sigma_h=sqrt(integrate(length(x-x0h)**2 * u_h) * (DIM==3 ? sqrt(2./3.) :1 )
46 #
47 #
48
49 from esys.escript import *
50 from esys.escript.linearPDEs import TransportPDE, SolverOptions
51 from esys.finley import Rectangle, Brick
52 #from esys.ripley import Rectangle, Brick
53 from esys.weipa import saveVTK
54 from math import pi, ceil
55 NE=128
56 #NE=4
57 DIM=2
58 THETA=0.5
59 OMEGA0=1.
60 ALPHA=pi/4
61 T0=0
62 T_END=2.*pi
63 dt=1e-3*10*10
64 E=1.e-3
65
66
67 dom=Rectangle(NE,NE)
68 u0=dom.getX()[0]
69 # saveVTK("u.%s.vtu"%0,u=u0)
70 # print "XX"*80
71
72 # set initial value
73 #dom.setX(2*dom.getX()-1)
74 #x=dom.getX()
75 #r=sqrt(x[0]**2+(x[1]-1./3.)**2)
76 #u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5))
77
78 #x=Function(dom).getX()
79 #if DIM == 2:
80 # V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0])
81 #else:
82 # V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.])
83
84 x=dom.getX()
85
86 R0=0.15
87 #cylinder:
88 X0=0.5
89 Y0=0.75
90 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
91 u0=whereNegative(r-1)*wherePositive(wherePositive(abs(x[0]-X0)-0.025)+wherePositive(x[1]-0.85))
92 # cone:
93 X0=0.5
94 Y0=0.25
95 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
96 u0=u0+wherePositive(1-r)*(1-r)
97 #hump
98 X0=0.25
99 Y0=0.5
100 r=sqrt((x[0]-X0)**2+(x[1]-Y0)**2)/R0
101 u0=u0+1./4.*(1+cos(pi*clip(r,maxval=1)))
102
103 x=Function(dom).getX()
104 V=OMEGA0*((0.5-x[0])*[0,1]+(0.5-x[1])*[-1,0])
105 #===================
106
107 fc=TransportPDE(dom,numEquations=1)
108 fc.getSolverOptions().setVerbosityOn()
109 #fc.getSolverOptions().setODESolver(SolverOptions.BACKWARD_EULER)
110 fc.getSolverOptions().setODESolver(SolverOptions.LINEAR_CRANK_NICOLSON)
111 fc.getSolverOptions().setODESolver(SolverOptions.CRANK_NICOLSON)
112 x=Function(dom).getX()
113 fc.setValue(M=1,C=V)
114
115 c=0
116 saveVTK("u.%s.vtu"%c,u=u0)
117 fc.setInitialSolution(u0)
118 dt=fc.getSafeTimeStepSize()
119 #dt=1.e-3
120 print("dt = ",dt)
121 t=T0
122 print("QUALITY FCT: time = %s pi"%(t/pi),inf(u0),sup(u0),integrate(u0))
123 #T_END=200*dt
124 while t<T_END:
125
126 print("time step t=",t+dt)
127 u=fc.getSolution(dt)
128 print("QUALITY FCT: time = %s pi"%(t+dt/pi),inf(u),sup(u),integrate(u))
129 saveVTK("u.%s.vtu"%(c+1,),u=u)
130 c+=1
131 t+=dt

  ViewVC Help
Powered by ViewVC 1.1.26