Exemplo n.º 1
0
# set initial value
x = dom.getX()
u0 = 1 / (4. * pi * E * T0)**(DIM / 2.) * exp(
    -length(dom.getX() - getCenter(T0))**2 / (4. * E * T0))

print("QUALITY ", QUALITY(T0, u0))

x = Function(dom).getX()
if DIM == 2:
    V = OMEGA0 * (x[0] * [0, -1] + x[1] * [1, 0])
else:
    V = OMEGA0 * (x[0] * [0, cos(ALPHA), 0] + x[1] *
                  [-cos(ALPHA), 0, sin(ALPHA)] + x[2] * [0., -sin(ALPHA), 0.])
#===================
fc = TransportPDE(dom, num_equations=1, theta=THETA)
x = Function(dom).getX()
fc.setValue(M=Scalar(1., Function(dom)),
            C=V,
            A=-Scalar(E, Function(dom)) * kronecker(dom))
#==============
if TEST_SUPG:
    supg = LinearSinglePDE(dom)
    supg.setValue(D=1.)
    supg.setSolverMethod(supg.LUMPING)
    dt_supg = 1. / (1. / inf(dom.getSize() / length(V)) +
                    1. / inf(dom.getSize()**2 / E)) * 0.3
    u_supg = u0 * 1.

c = 0
saveVTK("u.%s.vtu" % c, u=u0)
Exemplo n.º 2
0
__license__="""Licensed under the Apache License, version 2.0
http://www.apache.org/licenses/LICENSE-2.0"""
__url__="https://launchpad.net/escript-finley"


from esys.escript import *
from esys.escript.linearPDEs import TransportPDE, SolverOptions
from esys.finley import Rectangle, Brick
#from esys.ripley import Rectangle, Brick
from esys.weipa import saveVTK
from math import pi, ceil

NE=50
dom=Rectangle(NE,1,l1=1./NE)
dom=Rectangle(NE,NE)
fc=TransportPDE(dom,numEquations=1)
fc.getSolverOptions().setVerbosityOn()
fc.getSolverOptions().setODESolver(SolverOptions.LINEAR_CRANK_NICOLSON)
fc.getSolverOptions().setODESolver(SolverOptions.BACKWARD_EULER)
fc.getSolverOptions().setODESolver(SolverOptions.CRANK_NICOLSON)
fc.setValue(M=1,C=[-1,0])
x=dom.getX()
u0=whereNegative(x[0]-1./NE)

c=0
t=0

saveVTK("u.%s.vtu"%c,u=u0)
fc.setInitialSolution(u0)
dt=fc.getSafeTimeStepSize() 
Exemplo n.º 3
0
def XXX(dim, tend, dt, s, h, b, c, d, c_dir="x", d_dir="x", a=1., CN=True):
    """
     dim - sparial dimension 
     s - width of initial profile
     h - mesh size
    """
    v_c = c / a * getDirection(dim, c_dir)
    v_d = d / a * getDirection(dim, d_dir)
    v = (v_c + v_d)
    E = b / a
    if VERBOSITY:
        print("=" * 100)
        print(
            "XX Start test dim  = %d , h=%e, b=%e, c=%e, d=%e, c_dir=%s, d_dir=%s, a=%e, s=%e"
            % (dim, h, b, c, d, c_dir, d_dir, a, s))
        print("=" * 100)
        print("initial width s = ", s)
        print("diffusion = ", E)
        print("total velocity = ", v)
        print("tend = ", tend)
        print("tolerance = ", TOL)
        print("number of elements over s =", s / h)
    b0 = sqrt(-log(TAU) * 4 * (s**2 + E * tend))
    b1 = sqrt(-log(TAU)) * 2 * s
    X0_0 = max(b1, -v[0] * tend + b0)
    X0_1 = max(b1, -v[1] * tend + b0)
    l_0 = X0_0 + max(v[0] * tend + b0, b1)
    l_1 = X0_1 + max(v[1] * tend + b0, b1)
    NE_0 = max(int(l_0 / h + 0.5), 1)
    NE_1 = max(int(l_1 / h + 0.5), 1)
    if dim == 2:
        if VERBOSITY:
            print("%d x %d grid over %e  x %e with element size %e." %
                  (NE_0, NE_1, l_0, l_1, h))
        if NE_0 * NE_1 > NE_MAX:
            raise ValueError("too many elements %s." % (NE_0 * NE_1, ))
        dom = Rectangle(n0=NE_0, n1=NE_1, l0=l_0, l1=l_1)
        x0 = [X0_0, X0_1]
    else:
        X0_2 = max(b1, -v[2] * tend + b0)
        l_2 = X0_2 + max(v[2] * tend + b0, b1)
        NE_2 = max(int(l_2 / h + 0.5), 1)
        if VERBOSITY:
            print(
                "%d x %d x %d grid over %e  x %e x %e with element size %e." %
                (NE_0, NE_1, NE_2, l_0, l_1, l_2, h))
        if NE_0 * NE_1 * NE_2 > NE_MAX:
            raise ValueError("too many elements %s." % (NE_0 * NE_1 * NE_2, ))
        dom = Brick(n0=NE_0, n1=NE_1, ne2=NE_2, l0=l_0, l1=l_1, l2=l_2)
        x0 = [X0_0, X0_1, X0_2]
    if VERBOSITY:
        print("initial location = ", x0)
    print("XX", interpolate(uRef(dom, 0., E, s, v, x0),
                            FunctionOnBoundary(dom)))

    fc_BE = TransportPDE(dom, numEquations=1, useBackwardEuler=True)
    fc_BE.setValue(M=a, A=-b * kronecker(dom), B=-v_d * a, C=-v_c * a)
    fc_BE.getSolverOptions().setVerbosity(VERBOSITY)
    fc_BE.getSolverOptions().setTolerance(TOL)
    #
    fc_BE.getSolverOptions().setPreconditioner(
        fc_BE.getSolverOptions().GAUSS_SEIDEL)
    fc_BE.getSolverOptions().setNumSweeps(5)
    if VERBOSITY: print("Backward Euler Transport created")

    fc_CN = TransportPDE(dom, numEquations=1, useBackwardEuler=False)
    fc_CN.setValue(M=a, A=-b * kronecker(dom), B=-v_d * a, C=-v_c * a)
    fc_CN.getSolverOptions().setVerbosity(VERBOSITY)
    fc_CN.getSolverOptions().setTolerance(TOL)

    #fc_CN.getSolverOptions().setPreconditioner(fc_CN.getSolverOptions().GAUSS_SEIDEL)
    fc_CN.getSolverOptions().setNumSweeps(2)
    if VERBOSITY: print("Crank Nicolson Transport created")
    dt_CN = fc_CN.getSafeTimeStepSize()
    if VERBOSITY: print("time step size by Crank Nicolson=", dt_CN)

    U0 = uRef(dom, 0, E, s, v, x0)
    U0_e = uRef(dom, 0, E, s, v, x0, True)
    fc_CN.setInitialSolution(U0)
    fc_BE.setInitialSolution(U0)
    initial_error_L2 = sqrt(integrate((U0 - U0_e)**2))
    if VERBOSITY:
        print("initial Lsup = ", Lsup(U0), Lsup(U0_e))
        print("initial integral = ", integrate(U0_e))
        print("initial error = ", initial_error_L2)
        print("used time step size =", dt)

    if not CN:
        n = int(ceil(tend / dt))
        if VERBOSITY:
            print("Solve Backward Euler:")
            print("substeps : ", n)
        t0 = clock()
        for i in range(n):
            u = fc_BE.getSolution(dt)
        t0 = clock() - t0
    else:
        if VERBOSITY: print("Solve Crank Nicolson:")
        dt = dt_CN
        t0 = clock()
        u = fc_CN.getSolution(tend)
        t0 = clock() - t0
    out = QUALITY(u, uRef(dom, tend, E, s, v, x0, True))
    print("XX",
          interpolate(uRef(dom, tend, E, s, v, x0), FunctionOnBoundary(dom)))
    out['time'] = t0
    out['tend'] = tend
    out['dt'] = dt
    out['dx'] = h
    if abs(b) > 0:
        out["peclet"] = length(v) * s / b
    else:
        out["peclet"] = 9999999.
    # saveVTK("bb.vtu",u0=U0,u_CN=u_CN, uRef=uRef(dom,dt2,E,s,v,X0) )
    return out
Exemplo n.º 4
0
Primary Business: Queensland, Australia"""
__license__ = """Licensed under the Apache License, version 2.0
http://www.apache.org/licenses/LICENSE-2.0"""
__url__ = "https://launchpad.net/escript-finley"

from esys.escript import *
from esys.escript.linearPDEs import TransportPDE, SolverOptions
from esys.finley import Rectangle, Brick
#from esys.ripley import Rectangle, Brick
from esys.weipa import saveVTK
from math import pi, ceil

NE = 50
dom = Rectangle(NE, 1, l1=1. / NE)
dom = Rectangle(NE, NE)
fc = TransportPDE(dom, numEquations=1)
fc.getSolverOptions().setVerbosityOn()
fc.getSolverOptions().setODESolver(SolverOptions.LINEAR_CRANK_NICOLSON)
fc.getSolverOptions().setODESolver(SolverOptions.BACKWARD_EULER)
fc.getSolverOptions().setODESolver(SolverOptions.CRANK_NICOLSON)
fc.setValue(M=1, C=[-1, 0])
x = dom.getX()
u0 = whereNegative(x[0] - 1. / NE)

c = 0
t = 0

saveVTK("u.%s.vtu" % c, u=u0)
fc.setInitialSolution(u0)
dt = fc.getSafeTimeStepSize()
Exemplo n.º 5
0
# print "XX"*80
dom.setX(2 * dom.getX() - 1)

# set initial value
x = dom.getX()
r = sqrt(x[0]**2 + (x[1] - 1. / 3.)**2)
# u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5))

x = Function(dom).getX()
if DIM == 2:
    V = OMEGA0 * (x[0] * [0, -1] + x[1] * [1, 0])
else:
    V = OMEGA0 * (x[0] * [0, cos(ALPHA), 0] + x[1] *
                  [-cos(ALPHA), 0, sin(ALPHA)] + x[2] * [0., -sin(ALPHA), 0.])
#===================
fc = TransportPDE(dom, num_equations=1, theta=THETA)
x = Function(dom).getX()
fc.setValue(M=Scalar(1., Function(dom)), C=V)
#==============
if TEST_SUPG:
    supg = LinearSinglePDE(dom)
    supg.setValue(D=1.)
    supg.setSolverMethod(supg.LUMPING)
    dt_supg = inf(dom.getSize() / length(V))
    u_supg = u0 * 1.

c = 0
# saveVTK("u.%s.vtu"%c,u=u0)
fc.setInitialSolution(u0)
t = T0
print("QUALITY FCT: time = %s pi" % (t / pi), inf(u0), sup(u0), integrate(u0))
Exemplo n.º 6
0
  dom=Brick(NE,NE,NE)
dom.setX(2*dom.getX()-1)

# set initial value 
x=dom.getX()
u0=1/(4.*pi*E*T0)**(DIM/2.)*exp(-length(dom.getX()-getCenter(T0))**2/(4.*E*T0)) 

print("QUALITY ",QUALITY(T0,u0))

x=Function(dom).getX()
if DIM == 2:
   V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0])
else:
   V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.])
#===================
fc=TransportPDE(dom,num_equations=1,theta=THETA)
x=Function(dom).getX()
fc.setValue(M=Scalar(1.,Function(dom)),C=V,A=-Scalar(E,Function(dom))*kronecker(dom))
#==============
if TEST_SUPG:
   supg=LinearSinglePDE(dom)
   supg.setValue(D=1.)
   supg.setSolverMethod(supg.LUMPING)
   dt_supg=1./(1./inf(dom.getSize()/length(V))+1./inf(dom.getSize()**2/E))*0.3
   u_supg=u0*1.

c=0
saveVTK("u.%s.vtu"%c,u=u0)
fc.setInitialSolution(u0)
t=T0
while t<T_END:
Exemplo n.º 7
0
from esys.escript import *
from esys.escript.linearPDEs import LinearPDE, TransportPDE
from esys.finley import Rectangle
from esys.weipa import saveVTK

# dom=Rectangle(12,8,l0=1.5)
# dom=Rectangle(24,16,l0=1.5)
dom=Rectangle(48,32,l0=1.5)
saveDataCSV("t.csv",x=dom.getX(), rho=length(dom.getX()))
1/0
# dom=Rectangle(8*48,8*32,l0=1.5)
# dom=Rectangle(120,80,l0=1.5)
V=Scalar(1.,Function(dom))*[-1.,0]
THETA=0.
fc=TransportPDE(dom,num_equations=1,theta=THETA)
fc.setTolerance(1.e-12)
fc.setValue(M=Scalar(1.,Function(dom)),C=V)
x=dom.getX()
x_0=[0.5,0.5]
sigma=0.075
u0=1.
for i in range(dom.getDim()):
    u0=u0*exp(-(x[i]-x_0[i])**2/sigma**2)

u0=whereNonPositive(abs(x[0]-0.4)-0.2)*whereNonPositive(abs(x[1]-0.5)-0.2)
# f1=0.5
# f2=2.
# u0=f2*clip(x[0]-0.5,0.)-clip(0.5-x[0],0.)*f1+f1*0.5
# u0=exp(-3*(x[0]-2.)**2)
# u0=x[0]
Exemplo n.º 8
0
def XXX(dim,tend,dt, s, h,b,c,d,c_dir="x", d_dir="x", a=1., CN=True):
    """
     dim - sparial dimension 
     s - width of initial profile
     h - mesh size
    """
    v_c=c/a*getDirection(dim,c_dir)
    v_d=d/a*getDirection(dim,d_dir)
    v = (v_c+v_d)
    E=b/a 
    if VERBOSITY: 
           print("="*100)
           print("XX Start test dim  = %d , h=%e, b=%e, c=%e, d=%e, c_dir=%s, d_dir=%s, a=%e, s=%e"%(dim, h,b,c,d,c_dir, d_dir, a, s))
           print("="*100)
           print("initial width s = ",s)
           print("diffusion = ",E)
           print("total velocity = ",v)
           print("tend = ", tend)
           print("tolerance = ",TOL)
           print("number of elements over s =",s/h)
    b0=sqrt(- log(TAU) * 4*(s**2+E*tend))
    b1=sqrt(- log(TAU)) * 2*s 
    X0_0=max(b1,-v[0]*tend + b0)
    X0_1=max(b1,-v[1]*tend + b0)
    l_0=X0_0+max(v[0]*tend + b0 , b1)
    l_1=X0_1+max(v[1]*tend + b0 , b1)
    NE_0=max(int(l_0/h+0.5),1)
    NE_1=max(int(l_1/h+0.5),1)
    if dim == 2:
        if VERBOSITY: print("%d x %d grid over %e  x %e with element size %e."%(NE_0,NE_1,l_0,l_1,h))
        if NE_0*NE_1 > NE_MAX:
           raise ValueError("too many elements %s."%(NE_0*NE_1,))
        dom=Rectangle(n0=NE_0,n1=NE_1,l0=l_0,l1=l_1)
        x0=[X0_0, X0_1]
    else:
       X0_2=max(b1,-v[2]*tend + b0)
       l_2=X0_2+max(v[2]*tend + b0 , b1)
       NE_2=max(int(l_2/h+0.5),1)
       if VERBOSITY: print("%d x %d x %d grid over %e  x %e x %e with element size %e."%(NE_0,NE_1,NE_2,l_0,l_1,l_2,h))
       if NE_0*NE_1*NE_2 > NE_MAX:
          raise ValueError("too many elements %s."%(NE_0*NE_1*NE_2,))
       dom=Brick(n0=NE_0,n1=NE_1, ne2=NE_2, l0=l_0,l1=l_1, l2=l_2)
       x0=[X0_0, X0_1, X0_2]
    if VERBOSITY: 
        print("initial location = ",x0)
    print("XX", interpolate(uRef(dom,0.,E,s,v,x0), FunctionOnBoundary(dom)))
     
    fc_BE=TransportPDE(dom,numEquations=1)
    fc_BE.setValue(M=a, A=-b*kronecker(dom), B=-v_d*a, C=-v_c*a)
    fc_BE.getSolverOptions().setVerbosity(VERBOSITY)
    fc_BE.getSolverOptions().setTolerance(TOL)
    #
    fc_BE.getSolverOptions().setPreconditioner(fc_BE.getSolverOptions().GAUSS_SEIDEL)
    fc_BE.getSolverOptions().setNumSweeps(5)  
    if VERBOSITY: print("Backward Euler Transport created")

    fc_CN=TransportPDE(dom,numEquations=1)
    fc_CN.setValue(M=a, A=-b*kronecker(dom), B=-v_d*a, C=-v_c*a)
    fc_CN.getSolverOptions().setVerbosity(VERBOSITY)
    fc_CN.getSolverOptions().setTolerance(TOL)
   
    #fc_CN.getSolverOptions().setPreconditioner(fc_CN.getSolverOptions().GAUSS_SEIDEL) 
    fc_CN.getSolverOptions().setNumSweeps(2)  
    if VERBOSITY: print("Crank Nicolson Transport created")
    dt_CN=fc_CN.getSafeTimeStepSize()
    if VERBOSITY: print("time step size by Crank Nicolson=",dt_CN)

    U0=uRef(dom,0,E,s,v,x0)
    U0_e=uRef(dom,0,E,s,v,x0,True)
    fc_CN.setInitialSolution(U0)
    fc_BE.setInitialSolution(U0)
    initial_error_L2=sqrt(integrate((U0-U0_e)**2))
    if VERBOSITY:
      print("initial Lsup = ",Lsup(U0), Lsup(U0_e))
      print("initial integral = ",integrate(U0_e))
      print("initial error = ",initial_error_L2)
      print("used time step size =",dt) 
      
    if not CN:
       n=int(ceil(tend/dt))
       if VERBOSITY: 
          print("Solve Backward Euler:")
          print("substeps : ",n)
       t0=clock()
       for i in range(n): u=fc_BE.getSolution(dt)
       t0=clock()-t0
    else:
       if VERBOSITY: print("Solve Crank Nicolson:")
       dt=dt_CN
       t0=clock()
       u=fc_CN.getSolution(tend)
       t0=clock()-t0
    out=QUALITY(u,uRef(dom,tend,E,s,v,x0,True))
    print("XX", interpolate(uRef(dom,tend,E,s,v,x0), FunctionOnBoundary(dom)))
    out['time']=t0
    out['tend']=tend
    out['dt']=dt
    out['dx']=h
    if abs(b)>0:
       out["peclet"]=length(v)*s/b
    else:
        out["peclet"]=9999999.
    # saveVTK("bb.vtu",u0=U0,u_CN=u_CN, uRef=uRef(dom,dt2,E,s,v,X0) )
    return out
Exemplo n.º 9
0
from esys.escript import *
from esys.escript.linearPDEs import LinearPDE, TransportPDE
from esys.finley import Rectangle
from esys.weipa import saveVTK

# dom=Rectangle(12,8,l0=1.5)
# dom=Rectangle(24,16,l0=1.5)
dom = Rectangle(48, 32, l0=1.5)
saveDataCSV("t.csv", x=dom.getX(), rho=length(dom.getX()))
1 / 0
# dom=Rectangle(8*48,8*32,l0=1.5)
# dom=Rectangle(120,80,l0=1.5)
V = Scalar(1., Function(dom)) * [-1., 0]
THETA = 0.
fc = TransportPDE(dom, num_equations=1, theta=THETA)
fc.setTolerance(1.e-12)
fc.setValue(M=Scalar(1., Function(dom)), C=V)
x = dom.getX()
x_0 = [0.5, 0.5]
sigma = 0.075
u0 = 1.
for i in range(dom.getDim()):
    u0 = u0 * exp(-(x[i] - x_0[i])**2 / sigma**2)

u0 = whereNonPositive(abs(x[0] - 0.4) -
                      0.2) * whereNonPositive(abs(x[1] - 0.5) - 0.2)
# f1=0.5
# f2=2.
# u0=f2*clip(x[0]-0.5,0.)-clip(0.5-x[0],0.)*f1+f1*0.5
# u0=exp(-3*(x[0]-2.)**2)
Exemplo n.º 10
0
# saveVTK("u.%s.vtu"%0,u=u0)
# print "XX"*80
dom.setX(2*dom.getX()-1)

# set initial value 
x=dom.getX()
r=sqrt(x[0]**2+(x[1]-1./3.)**2)
# u0=whereNegative(r-1./3.)*wherePositive(wherePositive(abs(x[0])-0.05)+wherePositive(x[1]-0.5))

x=Function(dom).getX()
if DIM == 2:
   V=OMEGA0*(x[0]*[0,-1]+x[1]*[1,0])
else:
   V=OMEGA0*(x[0]*[0,cos(ALPHA),0]+x[1]*[-cos(ALPHA),0,sin(ALPHA)]+x[2]*[0.,-sin(ALPHA),0.])
#===================
fc=TransportPDE(dom,num_equations=1,theta=THETA)
x=Function(dom).getX()
fc.setValue(M=Scalar(1.,Function(dom)),C=V)
#==============
if TEST_SUPG:
   supg=LinearSinglePDE(dom)
   supg.setValue(D=1.)
   supg.setSolverMethod(supg.LUMPING)
   dt_supg=inf(dom.getSize()/length(V))
   u_supg=u0*1.

c=0
# saveVTK("u.%s.vtu"%c,u=u0)
fc.setInitialSolution(u0)
t=T0
print("QUALITY FCT: time = %s pi"%(t/pi),inf(u0),sup(u0),integrate(u0))