Exemple #1
0
def getDomain(dim, ne, height):

    if dim == 2:
        ne1 = int(ne * height + 0.5)
        mydomain = finley.Rectangle(n0=ne, n1=ne1, l1=height, order=1)
        totne = ne1 * ne
    else:
        ne2 = int(ne * height + 0.5)
        mydomain = finley.Brick(n0=ne, n1=ne, n2=ne2, l2=height, order=2)
        totne = ne2 * ne * ne
    print("%d -dimensional domain generated." % dim)
    print("height of the domain is ", height)
    print("total number of elements is ", totne)
    return mydomain
Exemple #2
0
def setup_rectangular_mesh(Parameters,
                           mesh_filename):
    """
    Create a rectangular mesh.
    """
    nx = int(math.ceil(Parameters.L / Parameters.cellsize_x))
    ny = int(math.ceil(Parameters.thickness / Parameters.cellsize_y))
    mesh = fl.Rectangle(l0=Parameters.L, l1=Parameters.thickness,
                        n0=nx, n1=ny)

    # calculate surface
    xy = mesh.getX()
    z_surface = (xy[0] - xy[0] + 1) * Parameters.thickness
    surface = es.whereZero(xy[1] - z_surface)
    sea_surface = None
    seawater = None

    return mesh, surface, sea_surface, seawater, z_surface
Exemple #3
0
# Very basic sanity checks following a build
# It is important that this script does not create any files unless
# it is _certain_ they are removed when finished or failed.
# We do not want the source directory polluted by actions here

from esys.escript import *
from esys.escript.linearPDEs import Poisson
import esys.ripley as ripley
import esys.finley as finley
import esys.speckley as speckley
from esys.weipa import saveVTK

mydomain = finley.Rectangle(l0=1., l1=1., n0=40, n1=20)
# define characteristic function of Gamma^D
x = mydomain.getX()
gammaD = whereZero(x[0]) + whereZero(x[1])
# define PDE and get its solution u
mypde = Poisson(domain=mydomain)
mypde.setValue(f=1, q=gammaD)
u = mypde.getSolution()
# write u to an external file
#saveVTK("u.vtu",sol=u)
Exemple #4
0
 else:
     onElmtext = ""
 for order in [1, 2]:
     for reduce in [False, True]:
         if reduce == True:
             redtext = ",reduced"
         else:
             redtext = ""
         for dim in [2, 3]:
             if dim == 2:
                 for i0 in [True, True]:
                     for i1 in [True, True]:
                         msh = finley.Rectangle(
                             numElements,
                             numElements,
                             order,
                             periodic0=i0,
                             periodic1=i1,
                             useElementsOnFace=onElements)
                         n = ContinuousFunction(msh)
                         x = n.getX()
                         c = Scalar(0, what=n)
                         if i0 == False:
                             c += whereZero(x[0]) + whereZero(x[0] - 1.)
                         if i1 == False:
                             c += whereZero(x[1]) + whereZero(x[1] - 1.)
                         error = TheTest(msh, c, reduce)
                         text = "Rectangle order = %d%s%s, periodic0= %d, periodic1= %d: error= %f" % (
                             order, redtext, onElmtext, i0, i1, error)
                         print("@@ ", text)
                         if error > max_error:
def runValetAcceleration(order):
   domain=finley.Rectangle(100,10,order)
   x=domain.getX()
   
   
   # test Velet scheme 
   dt=inf(domain.getSize()/c)*(1./6.)
   q=whereZero(x[0])+whereZero(x[0]-1.)
   
   mypde_f=LinearSinglePDE(domain)
   mypde_f.setSymmetryOn()
   mypde_f.setValue(D=1,q=q)
   u_f_old=ref_u(x,-dt)
   u_f=ref_u(x,0)
   
   mypde_HRZ=LinearSinglePDE(domain)
   mypde_HRZ.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
   mypde_HRZ.setValue(D=1,q=q)
   u_HRZ_old=ref_u(x,-dt)
   u_HRZ=ref_u(x,0)
   
   mypde_RS=LinearSinglePDE(domain)
   mypde_RS.getSolverOptions().setSolverMethod(SolverOptions.ROWSUM_LUMPING)
   mypde_RS.setValue(D=1,q=q)
   u_RS_old=ref_u(x,-dt)
   u_RS=ref_u(x,0)
   
   l=Locator(domain,[0.5,0.5])
   t=0
   
   u=ref_u(x,t)
   t_list=[t]
   u_list=[l(u)]
   f_list=[l(u_f)]
   HRZ_list=[l(u_HRZ)]
   RS_list=[l(u_RS)]
   print(t_list[-1], u_list[-1], f_list[-1], HRZ_list[-1] , RS_list[-1])
   
   while t< 4/n/c:
       t+=dt
       u=ref_u(x,t)
       mypde_f.setValue(X=-c**2*grad(u_f), r=-c**2*u)
       mypde_HRZ.setValue(X=-c**2*grad(u_HRZ), r=-c**2*u)
       mypde_RS.setValue(X=-c**2*grad(u_RS), r=-c**2*u)
    
       a_f=mypde_f.getSolution()
       a_HRZ=mypde_HRZ.getSolution()
       a_RS=mypde_RS.getSolution()
   
       u_f, u_f_old = 2*u_f-u_f_old + dt**2*a_f ,  u_f
       u_HRZ, u_HRZ_old = 2*u_HRZ-u_HRZ_old + dt**2*a_HRZ ,  u_HRZ
       u_RS, u_RS_old = 2*u_RS-u_RS_old + dt**2*a_RS ,  u_RS
      
       t_list.append(t)
       u_list.append(l(u))
       f_list.append(l(u_f))
       HRZ_list.append(l(u_HRZ))
       RS_list.append(l(u_RS))
       print(t_list[-1], u_list[-1], f_list[-1], HRZ_list[-1] , RS_list[-1])
     
   
   import matplotlib.pyplot as plt
   if getMPIRankWorld() == 0:
         plt.clf()
         plt.plot(t_list, u_list, '-', label="exact", linewidth=1)
         plt.plot(t_list, f_list, '-', label="full", linewidth=1)
         plt.plot(t_list, HRZ_list, '-', label="HRZ lumping", linewidth=1)
         plt.plot(t_list, RS_list, '-', label="row sum lumping", linewidth=1)
         plt.axis([0.,max(t_list),-1.3,1.3])
         plt.xlabel('time')
         plt.ylabel('displacement')
         plt.legend()
         plt.savefig('lumping_valet_a_%d.png'%order, format='png')
Exemple #6
0
def runTaylorGalerkinIncremental(order):
    domain = finley.Rectangle(100, 10, order)
    x = domain.getX()

    # test Velet scheme
    dt = inf(domain.getSize() / length(v)) * (1. / 6.)
    q = whereZero(x[0]) + whereZero(x[0] - 1.)

    mypde_f = LinearSinglePDE(domain)
    mypde_f.setSymmetryOn()
    mypde_f.setValue(D=1, q=q)
    u_f = ref_u(x, 0)

    mypde_HRZ = LinearSinglePDE(domain)
    mypde_HRZ.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
    mypde_HRZ.setValue(D=1, q=q)
    u_HRZ = ref_u(x, 0)

    mypde_RS = LinearSinglePDE(domain)
    mypde_RS.getSolverOptions().setSolverMethod(SolverOptions.ROWSUM_LUMPING)
    mypde_RS.setValue(D=1, q=q)
    u_RS = ref_u(x, 0)

    l = Locator(domain, [0.5, 0.5])
    t = 0

    u = ref_u(x, t)
    t_list = [t]
    u_list = [l(u)]
    f_list = [l(u_f)]
    HRZ_list = [l(u_HRZ)]
    RS_list = [l(u_RS)]
    print(t_list[-1], u_list[-1], f_list[-1], HRZ_list[-1], RS_list[-1])

    while t < 1. / Lsup(v):
        t += dt
        u = ref_u(x, t)
        mypde_f.setValue(X=-dt / 2. * u_f * v, r=ref_u(x, t - dt / 2) - u_f)
        mypde_HRZ.setValue(X=-dt / 2. * u_HRZ * v,
                           r=ref_u(x, t - dt / 2) - u_f)
        mypde_RS.setValue(X=-dt / 2. * u_RS * v, r=ref_u(x, t - dt / 2) - u_f)

        u_f_h = u_f + mypde_f.getSolution()
        u_HRZ_h = u_HRZ + mypde_HRZ.getSolution()
        u_RS_h = u_RS + mypde_RS.getSolution()

        mypde_f.setValue(X=-dt * u_f_h * v, r=u - u_f)
        mypde_HRZ.setValue(X=-dt * u_HRZ_h * v, r=u - u_HRZ)
        mypde_RS.setValue(X=-dt * u_RS_h * v, r=u - u_RS)

        u_f = u_f + mypde_f.getSolution()
        u_HRZ = u_HRZ + mypde_HRZ.getSolution()
        u_RS = u_RS + mypde_RS.getSolution()

        t_list.append(t)
        u_list.append(l(u))
        f_list.append(l(u_f))
        HRZ_list.append(l(u_HRZ))
        RS_list.append(l(u_RS))
        print(t_list[-1], u_list[-1], f_list[-1], HRZ_list[-1], RS_list[-1],
              " : ", sup(u))

    import matplotlib.pyplot as plt
    if getMPIRankWorld() == 0:
        plt.clf()
        plt.plot(t_list, u_list, '-', label="exact", linewidth=1)
        plt.plot(t_list, f_list, '-', label="full", linewidth=1)
        plt.plot(t_list, HRZ_list, '-', label="HRZ lumping", linewidth=1)
        plt.plot(t_list, RS_list, '-', label="row sum lumping", linewidth=1)
        plt.axis([0., max(t_list), -.3, 2.])
        plt.xlabel('time')
        plt.ylabel('displacement')
        plt.legend()
        plt.savefig('lumping_SUPG_du_%d.png' % order, format='png')
Exemple #7
0

#    - u_{j,ii} + b*u_i+ a*sum_{k<>j}  (u_i-u_k) = F_j

    mypde.setValue(A=A, D=D, y=y, q=q, r=u_ref, Y=Y)
    mypde.getSolverOptions().setVerbosityOn()
    mypde.getSolverOptions().setTolerance(TOL)
    mypde.setSymmetryOn()
    u = mypde.getSolution()
    error = Lsup(u - u_ref) / Lsup(u_ref)
    print("error = ", error)
    if error > 10 * TOL:
        print(
            "XXXXXXXXXX Error to large ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

domain = finley.Rectangle(10, 20, 1, l0=1., l1=1.0)
# or Brick or ReadMesh
runTest(dom=domain, n=1, b=0)
runTest(dom=domain, n=1, b=5)
runTest(dom=domain, n=1, b=50)

runTest(dom=domain, n=2, a=0, b=0)
runTest(dom=domain, n=2, a=5, b=0)
runTest(dom=domain, n=2, a=50, b=0)

runTest(dom=domain, n=2, a=0, b=10)
runTest(dom=domain, n=2, a=5, b=10)
runTest(dom=domain, n=2, a=50, b=10)

runTest(dom=domain, n=3, a=0, b=0)
runTest(dom=domain, n=3, a=5, b=0)