Beispiel #1
0
 def test_complex_params_Brick(self):
     domain=Brick(order=2,n0=10,n1=10,n2=10)
     pde = LinearSinglePDE(domain, isComplex=True)
     pde.setValue(D=1j)
     pde.setValue(Y=1.0)
     self.assertTrue(Lsup(pde.getSolution())==1.0, "Failed test_complex_params_Brick")
     del domain
Beispiel #2
0
class IsostaticPressure(object):
    """
    class to calculate isostatic pressure field correction due to gravity forces
    """
    def __init__(self, domain, p0=0., level0=0, gravity0=-9.81*U.m*U.sec**(-2),
                 background_density=2670* U.kg*U.m**(-3),
                 gravity_constant=U.Gravitational_Constant,
                 coordinates=None, tol=1e-8):
        """
        :param domain: domain of the model
        :type domain: `Domain`
        :param p0: pressure at level0
        :type p0: scalar `Data` or ``float``
        :param background_density: defines background_density in kg/m^3
        :type background_density: ``float``
        :param coordinates: defines coordinate system to be used
        :type coordinates: ReferenceSystem` or `SpatialCoordinateTransformation`
        :param tol: tolerance of underlying PDE
        :type tol: positive ``float``
        :param level0: pressure for z>=`level0` is set to zero.
        :type level0: ``float``
        :param gravity0: vertical background gravity at `level0`
        :type gravity0: ``float``
        """
        DIM=domain.getDim()
        self.__domain = domain
        self.__trafo=makeTransformation(domain, coordinates)
        self.__pde=LinearSinglePDE(domain)
        self.__pde.getSolverOptions().setTolerance(tol)
        self.__pde.setSymmetryOn()

        z = domain.getX()[DIM-1]
        self.__pde.setValue(q=whereNonNegative(z-level0), r=p0)

        fw = self.__trafo.getScalingFactors()**2 * self.__trafo.getVolumeFactor()
        A=self.__pde.createCoefficient("A")
        for i in range(DIM): A[i,i]=fw[i]
        self.__pde.setValue(A=A)
        z = Function(domain).getX()[DIM-1]
        self.__g_b= 4*PI*gravity_constant/self.__trafo.getScalingFactors()[DIM-1]*background_density*(level0-z) + gravity0
        self.__rho_b=background_density

    def getPressure(self, g = None, rho=None):
        """
        return the pressure for gravity force anomaly `g` and
        density anomaly `rho`

        :param g: gravity anomaly data
        :type g: ``Vector``
        :param rho: gravity anomaly data
        :type rho: ``Scalar``
        :return: pressure distribution
        :rtype: ``Scalar`
        """
        if not g: g=Vector(0., Function(self.__domain))
        if not rho: rho=Scalar(0., Function(self.__domain))

        g2=(rho * self.__g_b)*[0,0,1] + self.__rho_b*g + rho*g
        # Tests need to be updated before the following is uncommented:
        #g2=((rho+self.__rho_b) * self.__g_b)*[0,0,1] + self.__rho_b*g + rho*g
        d=self.__trafo.getScalingFactors()
        V= self.__trafo.getVolumeFactor()
        self.__pde.setValue(X = -g2*d*V)
        #self.__pde.setValue(X = g2*d*V)
        return self.__pde.getSolution()
    saveVTK("u.vtu",u=U_star,u0=U)
    #
    #  step 2:
    #
    # U2=U+teta1*(U_star-U)
    U2=U+teta1*U_star
    gg2=grad(U2)
    div_U2=gg2[0,0]+gg2[1,1]+U2[0]/r

    grad_p=grad(p)

    pressureStep2.setValue(A=r*dt*B*teta1*teta2/ro*dt*kronecker(dom), 
                           D=r,                            
                           Y=-dt*B*r*div_U2,
                           X=-r*B*dt**2/ro*teta1*(1-teta3)*grad_p)
    dp=pressureStep2.getSolution()
    #
    #  step 3:
    #
    p2=(1-teta3)*p+teta2*dp
    grad_p2=grad(p2)
    momentumStep3.setValue(D=r*ro*kronecker(dom),
                           Y=r*(ro*U_star-dt*teta2*grad_p2))
    U_new=momentumStep3.getSolution()
    #
    #   update:
    #
    p+=dp         
    U=U_new
    print("U:",inf(U),sup(U))
    print("P:",inf(p),sup(p)) 
Beispiel #4
0
    saveVTK("u.vtu",u=U_star,u0=U)
    #
    #  step 2:
    #
    # U2=U+teta1*(U_star-U)
    U2=U+teta1*U_star
    gg2=grad(U2)
    div_U2=gg2[0,0]+gg2[1,1]+U2[0]/r

    grad_p=grad(p)

    pressureStep2.setValue(A=r*dt*B*teta1*teta2/ro*dt*kronecker(dom), 
                           D=r,                            
                           Y=-dt*B*r*div_U2,
                           X=-r*B*dt**2/ro*teta1*(1-teta3)*grad_p)
    dp=pressureStep2.getSolution()
    #
    #  step 3:
    #
    p2=(1-teta3)*p+teta2*dp
    grad_p2=grad(p2)
    momentumStep3.setValue(D=r*ro*kronecker(dom),
                           Y=r*(ro*U_star-dt*teta2*grad_p2))
    U_new=momentumStep3.getSolution()
    #
    #   update:
    #
    p+=dp         
    U=U_new
    print("U:",inf(U),sup(U))
    print("P:",inf(p),sup(p)) 
Beispiel #5
0
c = 0
saveVTK("u.%s.vtu" % c, u=u0)
fc.setInitialSolution(u0)
t = T0
while t < T_END:
    print("time step t=", t + dt)
    u = fc.solve(dt)
    if TEST_SUPG:
        #========== supg tests ================
        nn = max(ceil(dt / dt_supg), 1.)
        dt2 = dt / nn
        nnn = 0
        while nnn < nn:
            supg.setValue(X=-dt2 / 2 * E * grad(u_supg),
                          Y=u_supg + dt2 / 2 * inner(V, grad(u_supg)))
            u2 = supg.getSolution()
            supg.setValue(X=-dt2 * E * grad(u2),
                          Y=u_supg + dt2 * inner(V, grad(u2)))
            u_supg = supg.getSolution()
            nnn += 1
    c += 1
    t += dt
    print("QUALITY FCT: time = %s pi" % (t / pi), QUALITY(t, u), end=' ')
    if TEST_SUPG:
        print("QUALITY SUPG: ", QUALITY(t, u_supg))
        # saveVTK("u.%s.vtu"%c,u=u,u_supg=u_supg)
    else:
        # saveVTK("u.%s.vtu"%c,u=u)
        pass
    # if c == 20: 1/0
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')
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')
Beispiel #8
0
class SonicWave(WaveBase):
        """
        Solving the sonic wave equation

        `p_tt = (v_p**2 * p_i)_i  + f(t) * delta_s`   where (p-) velocity v_p.

        f(t) is wavelet acting at a point source term at positon s
        """
        def __init__(self, domain, v_p, wavelet, source_tag, dt=None, p0=None, p0_t=None, absorption_zone=300*U.m, absorption_cut=1e-2, lumping=True):
           """
           initialize the sonic wave solver

           :param domain: domain of the problem
           :type domain: `Domain`
           :param v_p: p-velocity field
           :type v_p: `Scalar`
           :param wavelet: wavelet to describe the time evolution of source term
           :type wavelet: `Wavelet`
           :param source_tag: tag of the source location
           :type source_tag: 'str' or 'int'
           :param dt: time step size. If not present a suitable time step size is calculated.
           :param p0: initial solution. If not present zero is used.
           :param p0_t: initial solution change rate. If not present zero is used.
           :param absorption_zone: thickness of absorption zone
           :param absorption_cut: boundary value of absorption decay factor
           :param lumping: if True mass matrix lumping is being used. This is accelerates the computing but introduces some diffusion.
           """
           f=createAbsorptionLayerFunction(Function(domain).getX(), absorption_zone, absorption_cut)
           v_p=v_p*f

           if p0 == None:
              p0=Scalar(0.,Solution(domain))
           else:
              p0=interpolate(p0, Solution(domain ))

           if p0_t == None:
              p0_t=Scalar(0.,Solution(domain))
           else:
              p0_t=interpolate(p0_t, Solution(domain ))

           if dt == None:
                  dt=min(inf((1./5.)*domain.getSize()/v_p), wavelet.getTimeScale())

           super(SonicWave, self).__init__( dt, u0=p0, v0=p0_t, t0=0.)

           self.__wavelet=wavelet
           self.__mypde=LinearSinglePDE(domain)
           if lumping: self.__mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
           self.__mypde.setSymmetryOn()
           self.__mypde.setValue(D=1./v_p**2)
           self.__source_tag=source_tag
           self.__r=Scalar(0., DiracDeltaFunctions(self.__mypde.getDomain()))


        def  _getAcceleration(self, t, u):
             """
             returns the acceleraton for time t and solution u at time t
             """
             self.__r.setTaggedValue(self.__source_tag, self.__wavelet.getValue(t))
             self.__mypde.setValue(X=-grad(u,Function(self.__mypde.getDomain())), y_dirac= self.__r)
             return self.__mypde.getSolution()
Beispiel #9
0
class IsostaticPressure(object):
    """
    class to calculate isostatic pressure field correction due to gravity forces
    """
    def __init__(self,
                 domain,
                 p0=0.,
                 level0=0,
                 gravity0=-9.81 * U.m * U.sec**(-2),
                 background_density=2670 * U.kg * U.m**(-3),
                 gravity_constant=U.Gravitational_Constant,
                 coordinates=None,
                 tol=1e-8):
        """
        :param domain: domain of the model
        :type domain: `Domain`
        :param p0: pressure at level0
        :type p0: scalar `Data` or ``float``
        :param background_density: defines background_density in kg/m^3
        :type background_density: ``float``
        :param coordinates: defines coordinate system to be used
        :type coordinates: ReferenceSystem` or `SpatialCoordinateTransformation`
        :param tol: tolerance of underlying PDE
        :type tol: positive ``float``
        :param level0: pressure for z>=`level0` is set to zero.
        :type level0: ``float``
        :param gravity0: vertical background gravity at `level0`
        :type gravity0: ``float``
        """
        DIM = domain.getDim()
        self.__domain = domain
        self.__trafo = makeTransformation(domain, coordinates)
        self.__pde = LinearSinglePDE(domain)
        self.__pde.getSolverOptions().setTolerance(tol)
        self.__pde.setSymmetryOn()

        z = domain.getX()[DIM - 1]
        self.__pde.setValue(q=whereNonNegative(z - level0), r=p0)

        fw = self.__trafo.getScalingFactors(
        )**2 * self.__trafo.getVolumeFactor()
        A = self.__pde.createCoefficient("A")
        for i in range(DIM):
            A[i, i] = fw[i]
        self.__pde.setValue(A=A)
        z = Function(domain).getX()[DIM - 1]
        self.__g_b = 4 * PI * gravity_constant / self.__trafo.getScalingFactors(
        )[DIM - 1] * background_density * (level0 - z) + gravity0
        self.__rho_b = background_density

    def getPressure(self, g=None, rho=None):
        """
        return the pressure for gravity force anomaly `g` and
        density anomaly `rho`

        :param g: gravity anomaly data
        :type g: ``Vector``
        :param rho: gravity anomaly data
        :type rho: ``Scalar``
        :return: pressure distribution
        :rtype: ``Scalar``
        """
        if not g: g = Vector(0., Function(self.__domain))
        if not rho: rho = Scalar(0., Function(self.__domain))

        g2 = (rho * self.__g_b) * [0, 0, 1] + self.__rho_b * g + rho * g
        # Tests need to be updated before the following is uncommented:
        #g2=((rho+self.__rho_b) * self.__g_b)*[0,0,1] + self.__rho_b*g + rho*g
        d = self.__trafo.getScalingFactors()
        V = self.__trafo.getVolumeFactor()
        self.__pde.setValue(X=-g2 * d * V)
        #self.__pde.setValue(X = g2*d*V)
        return self.__pde.getSolution()
Beispiel #10
0
   u_supg=u0*1.

c=0
saveVTK("u.%s.vtu"%c,u=u0)
fc.setInitialSolution(u0)
t=T0
while t<T_END:
    print("time step t=",t+dt)
    u=fc.solve(dt)
    if TEST_SUPG:
        #========== supg tests ================
        nn=max(ceil(dt/dt_supg),1.)
        dt2=dt/nn
        nnn=0
        while nnn<nn :
            supg.setValue(X=-dt2/2*E*grad(u_supg),Y=u_supg+dt2/2*inner(V,grad(u_supg)))
            u2=supg.getSolution()
            supg.setValue(X=-dt2*E*grad(u2),Y=u_supg+dt2*inner(V,grad(u2)))
            u_supg=supg.getSolution()
            nnn+=1
    c+=1
    t+=dt
    print("QUALITY FCT: time = %s pi"%(t/pi),QUALITY(t,u), end=' ')
    if TEST_SUPG: 
       print("QUALITY SUPG: ",QUALITY(t,u_supg))
       # saveVTK("u.%s.vtu"%c,u=u,u_supg=u_supg)
    else:
       # saveVTK("u.%s.vtu"%c,u=u)
       pass
    # if c == 20: 1/0
Beispiel #11
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')
def runTaylorGalerkinIncremental(order):
    domain = finley.Rectangle(100, 10, order)
    x = domain.getX()

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

    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.0 / Lsup(v):
        t += dt
        u = ref_u(x, t)
        mypde_f.setValue(X=-dt / 2.0 * u_f * v, r=ref_u(x, t - dt / 2) - u_f)
        mypde_HRZ.setValue(X=-dt / 2.0 * u_HRZ * v, r=ref_u(x, t - dt / 2) - u_f)
        mypde_RS.setValue(X=-dt / 2.0 * 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.0, max(t_list), -0.3, 2.0])
        plt.xlabel("time")
        plt.ylabel("displacement")
        plt.legend()
        plt.savefig("lumping_SUPG_du_%d.png" % order, format="png")
Beispiel #13
0
from esys.escript import *
from esys.escript.linearPDEs import LinearSinglePDE
from esys.weipa import saveVTK

try:
    from esys.finley import Rectangle
    HAVE_FINLEY = True
except ImportError:
    HAVE_FINLEY = False
# generate domain:
if not HAVE_FINLEY:
    print("Finley module not available")
else:
    mydomain=Rectangle(30,30, l0=3, l1=2, 
                diracPoints=[(1.,1.), (2.,1.)],  diracTags=['in', 'out'])
    # fix the solution on the boundary
    x = mydomain.getX()
    gammaD = whereZero(x[0])+whereZero(x[1])+whereZero(x[0]-3.)+whereZero(x[1]-2.)
    # fix the solution on the boundary
    s=Scalar(0., DiracDeltaFunctions(mydomain))
    s.setTaggedValue('in', +1.)
    s.setTaggedValue('out', -1.)
    # define PDE and get its solution u
    mypde = LinearSinglePDE(domain=mydomain)
    mypde.setValue(q=gammaD, A=kronecker(2), y_dirac=s)
    u = mypde.getSolution()
    print("Solution = ",str(u))
    # write u to an external file
    saveVTK("u.vtu",sol=u)
from esys.weipa import saveVTK, saveSilo
from esys.escript.linearPDEs import LinearSinglePDE, SolverOptions
from esys.finley import ReadGmsh
from esys.escript.pdetools import Locator

print("read in mesh")
domain = ReadGmsh("simplemesh.msh", 3, optimize=True)

pde = LinearSinglePDE(domain, isComplex=False)
pde.setSymmetryOn()
x = domain.getX()

pde.setValue(A=kronecker(3), Y=1, q=whereZero(x[0] - inf(x[0])))

options = pde.getSolverOptions()
options.setPackage(SolverOptions.TRILINOS)
options.setSolverMethod(SolverOptions.PCG)
options.setPreconditioner(SolverOptions.AMG)
options.setTrilinosParameter("multigrid algorithm", "sa")
options.setTrilinosParameter("sa: damping factor", 1.3)
options.setTrilinosParameter("max levels", 10)
options.setTrilinosParameter("coarse: max size", 2000)
options.setTrilinosParameter("coarse: type", "SuperLU")
options.setTrilinosParameter("verbosity", "low")

print("solve pde")
u = pde.getSolution()

saveSilo("asimple", u=u)
print("finished")
Beispiel #15
0
try:
    from esys.finley import Rectangle
    HAVE_FINLEY = True
except ImportError:
    HAVE_FINLEY = False
# generate domain:
if not HAVE_FINLEY:
    print("Finley module not available")
else:
    mydomain = Rectangle(30,
                         30,
                         l0=3,
                         l1=2,
                         diracPoints=[(1., 1.), (2., 1.)],
                         diracTags=['in', 'out'])
    # fix the solution on the boundary
    x = mydomain.getX()
    gammaD = whereZero(x[0]) + whereZero(
        x[1]) + whereZero(x[0] - 3.) + whereZero(x[1] - 2.)
    # fix the solution on the boundary
    s = Scalar(0., DiracDeltaFunctions(mydomain))
    s.setTaggedValue('in', +1.)
    s.setTaggedValue('out', -1.)
    # define PDE and get its solution u
    mypde = LinearSinglePDE(domain=mydomain)
    mypde.setValue(q=gammaD, A=kronecker(2), y_dirac=s)
    u = mypde.getSolution()
    print("Solution = ", str(u))
    # write u to an external file
    saveVTK("u.vtu", sol=u)