def test_hex_contact_2D_order2_onFace(self):
     file = "hex_contact_2D_order2_onFace.msh"
     ms1 = Rectangle(1, 1, 2, l1=0.5, useElementsOnFace=True)
     ms2 = Rectangle(1, 1, 2, l1=0.5, useElementsOnFace=True)
     ms2.setX(ms2.getX() + [0, 0.5])
     my_dom = JoinFaces([ms1, ms2], optimize=False)
     self.checker(my_dom, file)
Example #2
0
 def test_rectconstr(self):
   self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0)])
   self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40])
   self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=[40])
   self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,0), (1,1)], diracTags=["cows"])
   self.assertRaises(ValueError, Rectangle, 4,4, diracPoints=[(0,)], diracTags=["test"])
   z=Rectangle(4,4, diracPoints=[(0,0), (0.25,0.25)], diracTags=[40,51])
   z=Rectangle(4,4, diracPoints=[(0.125,0.625), (0.5,1), (0.75, 0.25), (0.89, 0.875)], diracTags=["A", "B", "A", "C"])
   v=interpolate(z.getX(), DiracDeltaFunctions(z))
   if mpisize==1:
     self.assertEqual(v.toListOfTuples(),[(0.0, 0.5), (0.5, 1.0), (0.75, 0.25), (1.0, 0.75)])
     self.assertEqual(v.getNumberOfDataPoints(), 4)
     self.assertEqual(inf(v[0]), 0)
     self.assertEqual(inf(v[1]), 0.25)
     self.assertEqual(Lsup(v[0]), 1)
     self.assertEqual(Lsup(v[1]), 1)
   v.setTaggedValue("A",(-10,0.5))
   if mpisize==1:
     self.assertEqual(inf(v[0]), -10)
     self.assertEqual(inf(v[1]), 0.5)
   v.setTaggedValue(500,(-100,-100))   # non-existant tag
   if mpisize==1:
     self.assertEqual(inf(v[0]), -10)
     self.assertEqual(inf(v[1]), 0.5)
   self.assertEqual(z.showTagNames(), 'A, B, C, bottom, left, right, top')
   self.assertEqual(z.getTag("C"), 42)
Example #3
0
 def setUp(self):
     self.order = 2
     d1 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0)
     d2 = Rectangle(n0=NE // 2, n1=NE, l0=0.5, order=2, useElementsOnFace=0)
     d2.setX(d2.getX() + [0.5, 0.])
     if getMPISizeWorld() > 1:
         with self.assertRaises(NotImplementedError) as pkg:
             self.domain = JoinFaces([d1, d2], optimize=False)
         e = pkg.exception
         if FINLEY_MERGE_ERROR not in str(e):
             raise e
         raise unittest.SkipTest(FINLEY_MERGE_ERROR)
     else:
         self.domain = JoinFaces([d1, d2], optimize=False)
Example #4
0
 def setUp(self):
     Stations = [(0., 0.), (1., 0), (0, 1), (1, 1)]
     StationsTags = ["A1", "A2", "A3", "A4"]
     self.domain = Rectangle(n0=5,
                             n1=5,
                             diracPoints=Stations,
                             diracTags=StationsTags)
 def test_Rectangle_optimize_order1(self):
     mydomain1 = Rectangle(n0=NE0,
                           n1=NE1,
                           order=1,
                           l0=1.,
                           l1=1.,
                           optimize=False,
                           useElementsOnFace=0)
     mydomain2 = Rectangle(n0=NE0,
                           n1=NE1,
                           order=1,
                           l0=1.,
                           l1=1.,
                           optimize=True,
                           useElementsOnFace=0)
     self.domainsEqual(mydomain1, mydomain2)
Example #6
0
    def setUp(self):
        try:
           self.workdir=os.environ['FINLEY_WORKDIR']
        except KeyError:
           self.workdir='.'
        NE0=NE
        NE1=NE+1
        self.domain = Rectangle(NE0, NE1, order=2)
        self.functionspaces = [ ContinuousFunction ]
        # number of total data points for each function space
        self.linecounts=[ (2*NE0+1)*(2*NE1+1)-NE0*NE1+1 ]
        # number of masked points, i.e. where X[0] is non-zero
        self.linecounts_masked=[ (2*NE0+1)*(2*NE1+1)-(2+NE0)*NE1 ]
        # expected values in first line of masked data = [ X[:], X[0] ]
        self.firstline=[ [1./(2*NE0), 0., 1./(2*NE0)] ]

        if getMPISizeWorld() == 1:
            self.functionspaces += [ ReducedContinuousFunction, Function,
                ReducedFunction, FunctionOnBoundary, ReducedFunctionOnBoundary ]
            self.linecounts += [ 31, 181, 81, 55, 37 ]
            self.linecounts_masked += [ 25, 181, 81, 40, 27 ]
            self.firstline += [ [.25, 0., .25],
                    [.02817541634481463,.02254033307585171,.02817541634481463],
                    [.05283121635129676,.04226497308103741,.05283121635129676],
                    [.02817541634481463,0.,.02817541634481463],
                    [.05283121635129676,0.,.05283121635129676]
                    ]
        else:
            print("Skipping some CSV tests on finley since MPI size > 1")
Example #7
0
 def test_setXError(self):
     domain=Rectangle(NE,NE)
     x=domain.getX()
     z=interpolate(x, Function(domain))
     self.assertRaises(ValueError, domain.setX, z)
     del x
     del z
     del domain
 def test_hex2D_macro_integorder10(self):
     NE = getMPIRankWorld()
     my_dom = Rectangle(NE,
                        NE,
                        order=-1,
                        useElementsOnFace=0,
                        integrationOrder=10)
     self.__test_2DQ(my_dom, 10)
Example #9
0
 def setUp(self):
     try:
         self.workdir = os.environ['FINLEY_WORKDIR']
     except KeyError:
         self.workdir = '.'
     self.domain = Rectangle(NE, NE + 1, 2)
     self.functionspace = FunctionOnBoundary(
         self.domain
     )  # due to a bug in escript python needs to hold a reference to the domain
 def test_mesh_read_rectangle_from_finley_file(self):
     mydomain1 = Rectangle(n0=8,
                           n1=10,
                           order=1,
                           l0=1.,
                           l1=1.,
                           optimize=False)
     mydomain2 = ReadMesh(
         os.path.join(FINLEY_TEST_MESH_PATH, "rectangle_8x10.fly"))
     self.domainsEqual(mydomain1, mydomain2)
Example #11
0
 def test_mesh_dump_to_NetCDF_rectangle(self):
     mydomain1 = Rectangle(n0=NE0,
                           n1=NE1,
                           order=1,
                           l0=1.,
                           l1=1.,
                           optimize=False)
     dumpfile = os.path.join(FINLEY_WORKDIR, "tempfile.mesh.nc")
     mydomain1.dump(dumpfile)
     mydomain2 = LoadMesh(dumpfile)
     self.domainsEqual(mydomain1, mydomain2)
 def test_connectivity_info(self):
     if hasFeature("boostnumpy"):
         domain = Rectangle(n0=3, n1=4)
         testvalues = domain.getConnectivityInfo()
         correctvalues = [[0., 1., 5., 4.], [1., 2., 6., 5.],
                          [2., 3., 7., 6.], [4., 5., 9., 8.],
                          [5., 6., 10., 9.], [6., 7., 11., 10.],
                          [8., 9., 13., 12.], [9., 10., 14., 13.],
                          [10., 11., 15., 14.], [12., 13., 17., 16.],
                          [13., 14., 18., 17.], [14., 15., 19., 18.]]
         for i in range(0, testvalues.shape[0]):
             for j in range(0, 4):
                 self.assertEqual(testvalues[i][j], correctvalues[i][j])
 def test_data_dump_to_NetCDF_rectangle(self):
     mydomain1 = Rectangle(n0=NE0,
                           n1=NE1,
                           order=1,
                           l0=1.,
                           l1=1.,
                           optimize=False,
                           useElementsOnFace=0)
     d1 = Data(mydomain1.getMPIRank(), Function(mydomain1))
     d1.expand()
     dumpfile = os.path.join(FINLEY_WORKDIR, "tempfile.dump.nc")
     d1.dump(dumpfile)
     d2 = load(dumpfile, mydomain1)
     self.assertTrue(Lsup(abs(d1 - d2)) <= REL_TOL, "data objects differ")
Example #14
0
    def test_getPotential2d(self):
        dom = Rectangle(20, 20, l0=1000, l1=-1000, d1=mpisize)
        extents = [1000, 1000]
        primaryConductivity = Data(1 / 100., ContinuousFunction(dom))
        secondaryConductivity = Data(1 / 130., ContinuousFunction(dom))
        current = 1000.
        a = 0.05 * extents[0]
        start = [0.25 * extents[0]]
        directionVector = [1]
        numElectrodes = 10

        self.assertRaises(
            NotImplementedError, lambda: PolePoleSurvey(
                dom, primaryConductivity, secondaryConductivity, current, a,
                start, directionVector, numElectrodes))
Example #15
0
 def setUp(self):
     Width = self.DX * self.NEx
     Center = self.NEx // 2 * self.DX
     self.domain = Rectangle(self.NEx,
                             self.NEx,
                             l0=Width,
                             l1=Width,
                             diracPoints=[(Center, Center)],
                             diracTags=["src"],
                             order=self.Order,
                             fullOrder=True)
     numStation = (self.NEx // 2 - 3 - self.NE_STATION0 - 1)
     stations = [((self.NE_STATION0 + i) * self.DX, Center)
                 for i in range(numStation)]
     self.loc = Locator(Solution(self.domain), stations)
     self.source = Scalar(0j, DiracDeltaFunctions(self.domain))
     self.source.setTaggedValue("src", self.Amplitude)
     self.sourceX = (Center, Center)
 def test_hex_2D_order1_macro(self):
     file = "hex_2D_order1_macro.msh"
     my_dom = Rectangle(1, 1, -1, useElementsOnFace=0)
     self.checker(my_dom, file)
 def test_hex_2D_order2(self):
     file = "hex_2D_order2.msh"
     my_dom = Rectangle(1, 1, 2, useElementsOnFace=0)
     self.checker(my_dom, file)
Example #18
0
 def setUp(self):
     self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE)
     self.package = SolverOptions.PASO
     self.method = SolverOptions.BICGSTAB
     self.preconditioner = SolverOptions.JACOBI
Example #19
0
 def setUp(self):
     self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE)
     self.package = SolverOptions.PASO
     self.method = SolverOptions.MINRES
     self.preconditioner = SolverOptions.RILU
Example #20
0
 def setUp(self):
     self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE)
     self.package = SolverOptions.PASO
     self.method = SolverOptions.TFQMR
     self.preconditioner = SolverOptions.GAUSS_SEIDEL
 def test_hex2D_order2_integorder10(self):
     NE = getMPIRankWorld()
     my_dom = Rectangle(NE, NE, order=2, integrationOrder=10)
     self.__test_2DQ(my_dom, 10)
Example #22
0
if HAVE_FINLEY:
    NE = 16
    DIM = 3
    H = 1.
    L = 2 * H
    OMEGA = 10
    EPS = 0.01
    t = 0
    T_END = 0.05  # set T_END=(2*pi)/OMEGA to run a full simulation
    n = 0
    if DIM == 2:
        mydomain = Rectangle(int(ceil(L * NE / H)),
                             NE,
                             l0=L,
                             l1=H,
                             order=1,
                             useFullElementOrder=True,
                             optimize=True)
    else:
        mydomain = Brick(int(ceil(L * NE / H)),
                         int(ceil(L * NE / H)),
                         NE,
                         l0=L,
                         l1=L,
                         l2=H,
                         order=1,
                         useFullElementOrder=True,
                         optimize=True)

    x = mydomain.getX()
 def test_hex_2D_order1_onFace(self):
     file = "hex_2D_order1_onFace.msh"
     my_dom = Rectangle(1, 1, 1, useElementsOnFace=1)
     self.checker(my_dom, file)
 def setUp(self):
     self.domain = Rectangle(NE0, NE1, 2, optimize=OPTIMIZE)
     self.package = SolverOptions.TRILINOS
     self.method = SolverOptions.PCG
     self.preconditioner = SolverOptions.ILUT
 def test_hex2D_order1_integorder9(self):
     NE = getMPIRankWorld()
     my_dom = Rectangle(NE, NE, integrationOrder=9)
     self.__test_2DQ(my_dom, 9)
Example #26
0
    else:
        tend = 1.5  # end time

    h = 0.001  # time step
    # data recording times
    rtime = 0.0  # first time to record
    rtime_inc = tend / 20.0  # time increment to record
    #Check to make sure number of time steps is not too large.
    print("Time step size= ", h, "Expected number of outputs= ", tend / h)

    U0 = 0.005  # amplitude of point source
    # want a spherical source in the middle of area
    xc = [500, 500]  # with reference to mx,my this is the source location

    ####################################################DOMAIN CONSTRUCTION
    mydomain = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy)  # create the domain
    x = mydomain.getX()  # get the node locations of the domain

    ##########################################################ESTABLISH PDE
    mypde = LinearPDE(mydomain)  # create pde
    mypde.setSymmetryOn()  # turn symmetry on
    mypde.setValue(D=1.)  # set the value of D in the general form to 1.

    ############################################FIRST TIME STEPS AND SOURCE
    # define small radius around point xc
    src_radius = 30
    print("src_radius = ", src_radius)
    # set initial values for first two time steps with source terms
    u = U0 * (cos(length(x - xc) * 3.1415 / src_radius) +
              1) * whereNegative(length(x - xc) - src_radius)
    u_m1 = u
Example #27
0
    from esys.finley import Rectangle
    HAVE_FINLEY = True
except ImportError:
    HAVE_FINLEY = False
from esys.weipa import saveVTK
from esys.escript.unitsSI import DEG

if not HAVE_FINLEY:
    print("Finley module not available")
else:
    #... set some parameters ...
    lam = 1.
    mu = 1
    slip_max = 1.

    mydomain = Rectangle(l0=1., l1=1., n0=16,
                         n1=16)  # n1 need to be multiple of 4!!!
    # .. create the fault system
    fs = FaultSystem(dim=2)
    fs.addFault(V0=[0.5, 0.25], strikes=90 * DEG, ls=0.5, tag=1)
    # ... create a slip distribution on the fault:
    p, m = fs.getParametrization(mydomain.getX(), tag=1)
    p0, p1 = fs.getW0Range(tag=1)
    s = m * (p - p0) * (p1 - p) / ((p1 - p0) / 2)**2 * slip_max * [0., 1.]
    # ... calculate stress according to slip:
    D = symmetric(grad(s))
    chi, d = fs.getSideAndDistance(D.getFunctionSpace().getX(), tag=1)
    sigma_s = (mu * D + lam * trace(D) * kronecker(mydomain)) * chi
    #... open symmetric PDE ...
    mypde = LinearPDE(mydomain)
    mypde.setSymmetryOn()
    #... set coefficients ...
    ################################################ESTABLISHING PARAMETERS
    t = 0 * day  # our start time, usually zero
    tend = 0.5 * day  # - time to end simulation
    outputs = 200  # number of time steps required.
    h = (tend - t) / outputs  #size of time step
    #user warning statement
    print("Expected Number of time outputs is: ", (tend - t) / h)
    i = 0  #loop counter
    #the folder to put our outputs in, leave blank "" for script path
    save_path = os.path.join("data", "example02")
    #ensure the dir exists
    mkDir(save_path, os.path.join(save_path, "tempT"))

    ####################################################DOMAIN CONSTRUCTION
    rod = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy)
    x = Solution(rod).getX()
    ###############################################ESCRIPT PDE CONSTRUCTION
    mypde = LinearPDE(rod)
    A = zeros((2, 2))
    A[0, 0] = kappa
    q = whereZero(x[0])
    mypde.setValue(A=A, D=rhocp / h, q=q, r=T0)
    # ... set initial temperature ....
    T = T0 * whereZero(x[0]) + Tref * (1 - whereZero(x[0]))

    # ... open a collector for the time marks and corresponding total energy
    t_list = []
    E_list = []
    # ... convert solution points for plotting
    plx = x.toListOfTuples()
Example #29
0
    my = -5000 * m  #meters - model width
    ndx = 100  # mesh steps in x direction
    ndy = 100  # mesh steps in y direction - one dimension means one element
    #PDE related
    rho = 200.0
    rholoc = [2500, -2500]
    G = 6.67300 * 10E-11

    ################################################ESTABLISHING PARAMETERS
    #the folder to put our outputs in, leave blank "" for script path
    save_path = os.path.join("data", "example10")
    #ensure the dir exists
    mkDir(save_path)

    ####################################################DOMAIN CONSTRUCTION
    domain = Rectangle(l0=mx, l1=my, n0=ndx, n1=ndy)
    x = Solution(domain).getX()
    mask = wherePositive(10 - length(x - rholoc))
    rho = rho * mask
    kro = kronecker(domain)

    q = whereZero(x[1] - my) + whereZero(x[1]) + whereZero(
        x[0]) + whereZero(x[0] - mx)
    ###############################################ESCRIPT PDE CONSTRUCTION

    mypde = LinearPDE(domain)
    mypde.setValue(A=kro, Y=4. * 3.1415 * G * rho)
    mypde.setValue(q=q, r=0)
    mypde.setSymmetryOn()
    sol = mypde.getSolution()
# This example demonstrates both interpolation and saving data in CSV format

from esys.escript import saveDataCSV, sup, interpolateTable
import numpy
try:
    from esys.finley import Rectangle
    HAVE_FINLEY = True
except ImportError:
    HAVE_FINLEY = False

if not HAVE_FINLEY:
    print("Finley module not available")
else:

    n = 4  #Change this to whatever you like
    r = Rectangle(n, n)
    x = r.getX()
    x0 = x[0]
    x1 = x[1]  #we'll use this later
    toobig = 100  #An exception will be thrown if interpolation produces a value larger than this

    #First one dimensional interpolation

    #In this example we will interpolate a sine curve
    #The values we take from the domain will range from 0 to 1 (inclusive)

    sine_table = [
        0, 0.70710678118654746, 1, 0.70710678118654746, 0,
        -0.70710678118654746, -1, -0.70710678118654746, 0
    ]