def test_SphericalTransformation2D(self): dom=Rectangle(NE,NE, l0=45., l1=10.) cs=SphericalReferenceSystem() tf=cs.createTransformation(dom) self.assertEqual(tf.getReferenceSystem(),cs , "wrong reference") self.assertEqual(tf.getDomain(),dom , "wrong reference") self.assertFalse(tf.isCartesian(), "wrong isCartesian check") R=6378137.0 x=esys.escript.Function(dom).getX() phi=(90.-x[0])/180.*pi h=x[1]*1000. r=h+R v=tf.getVolumeFactor() self.assertTrue(isinstance(v, esys.escript.Data), "wrong volume factor type") self.assertEqual(v.getFunctionSpace(), esys.escript.Function(dom), "wrong volume factor type") error=Lsup(v-r*pi/180.*1000.) self.assertTrue(error<=RTOL*R, "volume factor") s=tf.getScalingFactors() self.assertTrue(isinstance(s, esys.escript.Data), "scaling factor type") self.assertEqual(s.getShape(), (dom.getDim(),), "scaling factor length") self.assertEqual(s.getFunctionSpace(), esys.escript.Function(dom), "wrong 0-th scaling factor type") error=Lsup(s[0]-1./r/pi*180.) self.assertTrue(error<=RTOL/R/pi*180., "0-th scaling factor") error=Lsup(s[1]-1./1000) self.assertTrue(error<=RTOL/1000., "1-th scaling factor")
def test_CartesianTransformation2D(self): dom=Rectangle(NE,NE, l0=10, l1=10) cs=CartesianReferenceSystem() tf=cs.createTransformation(dom) self.assertEqual(tf.getReferenceSystem(),cs , "wrong reference") self.assertEqual(tf.getDomain(),dom , "wrong reference") self.assertTrue(tf.isCartesian(), "wrong isCartesian check") v=tf.getVolumeFactor() self.assertTrue(isinstance(v, esys.escript.Data), "wrong volume factor type") self.assertEqual(v.getFunctionSpace(), esys.escript.Function(dom), "wrong volume factor type") error=Lsup(v-1.) self.assertTrue(error<=RTOL, "volume factor") s=tf.getScalingFactors() self.assertTrue(isinstance(s, esys.escript.Data), "scaling factor type") self.assertEqual(s.getShape(), (dom.getDim(),), "scaling factor length") self.assertEqual(s.getFunctionSpace(), esys.escript.Function(dom), "wrong 0-th scaling factor type") error=Lsup(s[0]-1.) self.assertTrue(error<=RTOL, "0-th scaling factor") error=Lsup(s[1]-1.) self.assertTrue(error<=RTOL, "1-th scaling factor")
def setUp(self): self.domain = Rectangle(self.NEX, self.NEZ, l0=self.WIDTH, l1=self.DEPTH) self.loc = Locator(ReducedFunction(self.domain), [(self.STATION_OFFSET, self.DEPTH - self.AIR_LAYER - self.DEPTH / self.NEZ / 2)]) self.airLayerMask = whereNonNegative(self.domain.getX()[1] - self.DEPTH + self.AIR_LAYER) self.airLayerMaskCenter = whereNonNegative( ReducedFunction(self.domain).getX()[1] - self.DEPTH + self.AIR_LAYER)
def setUp(self): self.boundary_tag_list = [1, 2, 10, 20] self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.rdomain = Rectangle(n0=(NE + 6) * NX - 1, n1=(NE + 6) * NY - 1, l0=1., l1=1., d0=NX, d1=NY)
def test_Creation(self): r = self.numRanks el = self.numRanks * 3 - 1 #test bad types with self.assertRaises(TypeError): Rectangle(5, el, d1=r, diracPoints=(.0, 0.), diracTags=["test"]) with self.assertRaises(TypeError): Rectangle(5, el, d1=r, diracPoints=[(.0, 0.)], diracTags=("test")) with self.assertRaises(TypeError): Rectangle(5, el, d1=r, diracPoints=[.0], diracTags=["test"]) with self.assertRaises(TypeError): Rectangle(5, el, d1=r, diracPoints=[.0, .0], diracTags=["test"]) with self.assertRaises(TypeError): Brick(5, el, 5, d1=r, diracPoints=(.0, 0., 0.), diracTags=["test"]) with self.assertRaises(TypeError): Brick(5, el, 5, d1=r, diracPoints=[(.0, 0., 0.)], diracTags=("test")) with self.assertRaises(TypeError): Brick(5, el, 5, d1=r, diracPoints=[.0, 0.], diracTags=["test"]) #test bad arg lengths with self.assertRaises(RuntimeError): Rectangle(5, el, d1=r, diracPoints=[(.0, )], diracTags=["test"]) with self.assertRaises(RuntimeError): Rectangle(5, el, d1=r, diracPoints=[(.0, 1.)], diracTags=[]) with self.assertRaises(RuntimeError): Rectangle(5, el, d1=r, diracPoints=[(.0, 0.)], diracTags=["test", "break"]) with self.assertRaises(RuntimeError): Rectangle(5, el, d1=r, diracPoints=[(.0, 0., 0.)], diracTags=["test"]) with self.assertRaises(RuntimeError): Brick(5, el, 5, d1=r, diracPoints=[(.0, 0., 0., 0.)], diracTags=["test"]) with self.assertRaises(RuntimeError): Brick(5, el, 5, d1=r, diracPoints=[( .0, 0., )], diracTags=["test"]) with self.assertRaises(RuntimeError): Brick(5, el, 5, d1=r, diracPoints=[(.0, )], diracTags=["test"])
def generateRects(self, a, b): rectX = Rectangle(self.longEdge, self.shortEdge, l0=self.longEdge, l1=self.shortEdge, d0=self.numRanks, diracPoints=[(a, b)], diracTags=["test"]) rectY = Rectangle(self.shortEdge, self.longEdge, l0=self.shortEdge, l1=self.longEdge, d1=self.numRanks, diracPoints=[(b, a)], diracTags=["test"]) return [rectX, rectY]
class TestMagneticApp2D(unittest.TestCase): xdim = 1000. zdim = 1000. NEX = 100 NEZ = 100 TESTTOL = 1e-3 def setUp(self): self.domain = Rectangle(self.NEX, self.NEZ, l0=self.xdim, l1=self.zdim) def tearDown(self): del self.domain def test_pde_answer(self): model = MagneticModel2D(self.domain, fixVert=True) x = self.domain.getX() xmin = inf(x[0]) xmax = sup(x[0]) ymin = inf(x[1]) ymax = sup(x[1]) xp = 2. * np.pi / (xmax - xmin) yp = 2. * np.pi / (ymax - ymin) Bh = [1., 0.] k = ((xp**2 + yp**2) / xp) * cos(xp * x[0]) * cos(yp * x[1]) model.setSusceptibility(k) outk = model.getSusceptibility() kdiff = abs(k - outk) self.assertLessEqual(sup(kdiff), self.TESTTOL) model.setBackgroundMagneticField(Bh) actualanswer = sin(xp * x[0]) * cos(yp * x[1]) abserror = abs(actualanswer - model.getAnomalyPotential()) biggesterror = sup(abserror) self.assertLessEqual(biggesterror, self.TESTTOL)
def setUp(self): self.workdir = RIPLEY_WORKDIR self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.functionspaces = [ ContinuousFunction, Function, ReducedFunction, FunctionOnBoundary, ReducedFunctionOnBoundary ] NE0 = NE * NX - 1 NE1 = NE * NY - 1 # number of total data points for each function space self.linecounts = [(NE0 + 1) * (NE1 + 1) + 1, 4 * NE0 * NE1 + 1, NE0 * NE1 + 1, 4 * NE0 + 4 * NE1 + 1, 2 * NE0 + 2 * NE1 + 1] # number of masked points, i.e. where X[0] is non-zero self.linecounts_masked = [ NE0 * (NE1 + 1) + 1, 4 * NE0 * NE1 + 1, NE0 * NE1 + 1, 4 * NE0 + 2 * NE1 + 1, 2 * NE0 + NE1 + 1 ] # expected values in first line of masked data = [ X[:], X[0] ] self.firstline = [[1. / NE0, 0., 1. / NE0], [None, None, None], [None, None, None], [None, None, None], [None, None, None]]
def setUp(self): self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY) self.functionspace = FunctionOnBoundary(self.domain) # due to a bug in escript python needs to hold a reference to the domain try: self.workdir=os.environ['RIPLEY_WORKDIR'] except KeyError: self.workdir='.'
def setUp(self): self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.tol = 0.001
def setUp(self): self.domain = Rectangle(20, 20, l0=100., l1=100., diracTags=["source"], diracPoints=[(0, 0)]) self.wavelet = Ricker(100.)
def setUp(self): self.order = 1 self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY)
def setUp(self): self.domain = Rectangle(self.NEX, self.NEZ, l0=self.WIDTH, l1=self.DEPTH) self.loc = Locator( ReducedFunction(self.domain), [(self.STATION_OFFSET, self.DEPTH - self.DEPTH / self.NEZ / 2)])
def setUp(self): self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.domain_with_different_number_of_samples = Rectangle( n0=7 * NE * NX - 1, n1=3 * NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.domain_with_different_number_of_data_points_per_sample = Rectangle( n0=7 * NE * NX - 1, n1=3 * NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.domain_with_different_sample_ordering = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY) self.filename_base = RIPLEY_WORKDIR self.mainfs = Function(self.domain) self.otherfs = Solution(self.domain)
def test_FillRectangle(self): fs = ContinuousFunction( Rectangle(10 * (int(sqrt(mpiSize) + 1)), 10 * (int(sqrt(mpiSize) + 1)))) RandomData((), fs, 2, ("gaussian", 1, 0.5)) RandomData((), fs, 0, ("gaussian", 2, 0.76)) self.assertRaises(NotImplementedError, RandomData, (2, 2), fs, 0, ("gaussian", 2, 0.76)) #data not scalar self.assertRaises(ValueError, RandomData, (), fs, 0, ("gaussian", 11, 0.1)) #radius too large RandomData((2, 3), fs)
def __createDomain(self): """ Creates and returns an escript domain that spans the entire area of available data plus a padding zone. This method is called only once the first time `getDomain()` is invoked. :return: The escript domain :rtype: `esys.escript.Domain` """ X0, NX, DX = self.__getTotalExtentsWithPadding() # number of domain elements NE = NX + [self._v_num_cells] # origin of domain origin = X0 + [-self._v_depth * self.__v_scale] if self.getReferenceSystem().isCartesian(): # rounding will give us about meter-accuracy with UTM coordinates self._dom_origin = [np.floor(oi) for oi in origin] else: # this should give us about meter-accuracy with lat/lon coords self._dom_origin = [1e-5 * np.floor(oi * 1e5) for oi in origin] # cell size / point spacing spacing = DX + [ self.__v_scale * np.floor( (self._v_depth + self._v_air_layer) / self._v_num_cells) ] #self._spacing = [float(np.floor(si)) for si in spacing] self._spacing = spacing lo = [(self._dom_origin[i], self._dom_origin[i] + NE[i] * self._spacing[i]) for i in range(self.__dim)] if self.__dim == 3: dom = Brick(*NE, l0=lo[0], l1=lo[1], l2=lo[2]) else: dom = Rectangle(*NE, l0=lo[0], l1=lo[1]) # ripley may internally adjust NE and length, so recompute self._dom_len = [ esu.sup(dom.getX()[i]) - esu.inf(dom.getX()[i]) for i in range(self.__dim) ] self._dom_NE = [ int(self._dom_len[i] / self._spacing[i]) for i in range(self.__dim) ] self.logger.debug("Domain size: " + str(self._dom_NE)) self.logger.debug(" length: " + str(self._dom_len)) self.logger.debug(" origin: " + str(self._dom_origin)) return dom
def setUp(self): for x in [int(sqrt(mpiSize)), 2, 3, 5, 7, 1]: NX = x NY = mpiSize // x if NX * NY == mpiSize: break self.domain = Rectangle(n0=NE * NX - 1, n1=NE * NY - 1, l0=1., l1=1., d0=NX, d1=NY)
def setUp(self): self.fs = Function(Rectangle(40, 40))
class TestMT2DTMWithAirLayer(unittest.TestCase): DEPTH = 3000. WIDTH = 1000. RHO0 = 100. NEX = 100 NEZ = 300 STATION_OFFSET = 1000. AIR_LAYER = 300. TRUE_PHASE = 45. TRUE_RHO = 100. USEFASTSOLVER = False # True works not yet def setUp(self): self.domain = Rectangle(self.NEX, self.NEZ, l0=self.WIDTH, l1=self.DEPTH) self.loc = Locator(ReducedFunction(self.domain), [(self.STATION_OFFSET, self.DEPTH - self.AIR_LAYER - self.DEPTH / self.NEZ / 2)]) self.airLayerMask = whereNonNegative(self.domain.getX()[1] - self.DEPTH + self.AIR_LAYER) self.airLayerMaskCenter = whereNonNegative( ReducedFunction(self.domain).getX()[1] - self.DEPTH + self.AIR_LAYER) def tearDown(self): del self.domain del self.loc def runModel(self, model, PERIODS, TOL): for frq in PERIODS: Zyx = model.getImpedance(f=frq) self.assertIsInstance(Zyx, Data) self.assertEqual(Zyx.getShape(), ()) self.assertEqual(Zyx.getFunctionSpace(), ReducedFunction(self.domain)) rho = model.getApparentResitivity(frq, Zyx) self.assertIsInstance(rho, Data) self.assertEqual(rho.getShape(), ()) self.assertEqual(rho.getFunctionSpace(), ReducedFunction(self.domain)) phi = model.getPhase(frq, Zyx) self.assertIsInstance(phi, Data) self.assertEqual(phi.getShape(), ()) self.assertEqual(phi.getFunctionSpace(), ReducedFunction(self.domain)) #print(frq, self.loc(rho)[0], self.loc(phi)[0]) self.assertAlmostEqual(self.loc(rho)[0], self.TRUE_RHO, delta=TOL * self.TRUE_RHO) self.assertAlmostEqual(self.loc(phi)[0], self.TRUE_PHASE, delta=TOL * self.TRUE_PHASE) def test_RhoBFloat(self): """ resistivity set on elements, radiation condition """ PERIODS = np.logspace(-2, 2, num=5, endpoint=True, base=10.0, dtype=float) rho = self.airLayerMaskCenter * 9999999 + ( 1 - self.airLayerMaskCenter) * self.RHO0 model = MT2DTMModel(self.domain, fixBottom=False, airLayer=self.DEPTH - self.AIR_LAYER, useFastSolver=self.USEFASTSOLVER) self.assertEqual(0, Lsup(model.airLayer - self.airLayerMask)) model.setResistivity(rho, rho_boundary=self.RHO0) self.runModel(model, PERIODS, TOL=1.e-3) def test_RhoBDataFixedButtom(self): """ resistivity set on elements, no value on boundary but interpolation is not possible fixed bottom """ PERIODS = np.logspace(2, 3, num=3, endpoint=True, base=10.0, dtype=float) rho = self.airLayerMaskCenter * 9999999 + ( 1 - self.airLayerMaskCenter) * self.RHO0 model = MT2DTMModel(self.domain, fixBottom=True, airLayer=self.DEPTH - self.AIR_LAYER, useFastSolver=self.USEFASTSOLVER) self.assertEqual(0, Lsup(model.airLayer - self.airLayerMask)) model.setResistivity(rho) self.runModel(model, PERIODS, TOL=1.e-1) def test_RhoBDataFailed(self): """ resistivity set on elements, no value on boundary but interpolation is not possible fixed bottom """ PERIODS = np.logspace(2, 3, num=3, endpoint=True, base=10.0, dtype=float) rho = self.airLayerMaskCenter * 9999999 + ( 1 - self.airLayerMaskCenter) * self.RHO0 model = MT2DTMModel(self.domain, fixBottom=False, airLayer=self.DEPTH - self.AIR_LAYER, useFastSolver=self.USEFASTSOLVER) self.assertEqual(0, Lsup(model.airLayer - self.airLayerMask)) self.assertRaises(RuntimeError, model.setResistivity, *(rho, ))
def setUp(self): self.domain = Rectangle(n0=NE0 * NX - 1, n1=NE1 * NY - 1, d0=NX, d1=NY) self.package = SolverOptions.MKL self.method = SolverOptions.DIRECT
def setUp(self): self.domain = Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY) self.package = SolverOptions.TRILINOS self.method = SolverOptions.BICGSTAB self.preconditioner = SolverOptions.JACOBI
def setUp(self): self.domain = Rectangle(self.NEX, self.NEZ, l0=self.xdim, l1=self.zdim)
rg.append((receiver_line[ix], 0.)) else: rcv_locations.append((receiver_line[ix], mid_point, depth)) rg.append((receiver_line[ix], mid_point)) # North-south line of receiver if DIM == 3: for iy in range(len(receiver_line)): rcv_locations.append((mid_point, receiver_line[iy], depth)) rg.append((mid_point, receiver_line[iy])) # # create domain: # if DIM == 2: domain = Rectangle(ne_x, ne_z, l0=width_x, l1=depth, diracPoints=src_locations, diracTags=src_tags) else: domain = Brick(ne_x, ne_x, ne_z, l0=width_x, l1=width_y, l2=depth, diracPoints=src_locations, diracTags=src_tags) wl = Ricker(frq, tcenter) #====================================================================== z = Function(domain).getX()[DIM - 1]
# you want to increase the value for `num` to get nicer plots. #================================================ print("Width [m] = ",WIDTH) print("Depth [m] = ", DEPTH) print("Mesh size [m] = ", WIDTH/NEX) print("Number of cells in x direction = ", NEX) print("Number of cells in z direction = ", NEZ) print("Air layer [m] = ", L_AIR) print("periods [s] = ", PERIODS) #============================================== print("generating mesh ...") domain=Rectangle(NEX,NEZ,l0=WIDTH,l1=DEPTH) print("generating conductivity ...") # you can replace this by an interpolation table read from a CSV file. z=ReducedFunction(domain).getX()[domain.getDim()-1] sigma=Scalar(SIGMA0, z.getFunctionSpace()) rho=Scalar(1./SIGMA0, z.getFunctionSpace()) z_top=sup(domain.getX()[domain.getDim()-1]) m_top=0. for l, s in zip(LAYERS, SIGMA ): m2=wherePositive(z-z_top+l) m=m2-m_top sigma=(1-m)*sigma+m*s if s > 0: rho=(1-m)*rho+m*1./s else:
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 setUp(self): self.domain = Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY) self.package = SolverOptions.PASO self.method = SolverOptions.PCG self.preconditioner = SolverOptions.JACOBI
def setUp(self): self.domain = Rectangle(20, 20)
def setUp(self): self.domain = Rectangle(l0=1., l1=1., n0=10, n1=10 * getMPISizeWorld() - 1, d1=getMPISizeWorld())