def setUp(self):
     self.domain = Brick(l0=1.,
                         l1=1.,
                         l2=1.,
                         n0=10,
                         n1=10 * getMPISizeWorld() - 1,
                         n2=10,
                         d1=getMPISizeWorld())
Exemple #2
0
    def write(self, filename):
        """
            writes to segy file

            :param filename: file name
            :note: the function uses the `obspy` module.
            """

        if not OBSPY_AVAILABLE:
            raise RuntimeError("This feature (SimpleSEGYWriter.write())"+\
                    " depends on obspy, which is not installed, see "+\
                    "https://github.com/obspy/obspy for install guide")

        if escript.getMPISizeWorld() > 1:
            raise RuntimeError("Writing segy files with multiple ranks is"+\
                    " not yet supported.")

        stream = Stream()

        for i in range(len(self.__receiver_group)):
            trace = Trace(data=np.array(self.__trace[i], dtype='float32'))
            # Attributes in trace.stats will overwrite everything in
            # trace.stats.segy.trace_header (in Hz)
            trace.stats.sampling_rate = 1. / self.getSamplingInterval()
            #trace.stats.starttime = UTCDateTime(2011,11,11,0,0,0)
            if not hasattr(trace.stats, 'segy.trace_header'):
                trace.stats.segy = {}
            trace.stats.segy.trace_header = SEGYTraceHeader()
            trace.stats.segy.trace_header.trace_identification_code = 1
            trace.stats.segy.trace_header.trace_sequence_number_within_line = i + 1
            trace.stats.segy.trace_header.scalar_to_be_applied_to_all_coordinates = -int(
                self.COORDINATE_SCALE)
            trace.stats.segy.trace_header.coordinate_units = 1
            trace.stats.segy.trace_header.source_coordinate_x = int(
                self.__source[0] * self.COORDINATE_SCALE)
            trace.stats.segy.trace_header.source_coordinate_y = int(
                self.__source[1] * self.COORDINATE_SCALE)
            trace.stats.segy.trace_header.group_coordinate_x = int(
                self.__receiver_group[i][0] * self.COORDINATE_SCALE)
            trace.stats.segy.trace_header.group_coordinate_y = int(
                self.__receiver_group[i][1] * self.COORDINATE_SCALE)

            # Add trace to stream
            stream.append(trace)
        # A SEGY file has file wide headers. This can be attached to the stream
        # object.  If these are not set, they will be autocreated with default
        # values.
        stream.stats = AttribDict()
        stream.stats.textual_file_header = 'C.. ' + self.__text + '\nC.. with esys.escript.downunder r%s\nC.. %s' % (
            escript.getVersion(), time.asctime())
        stream.stats.binary_file_header = SEGYBinaryFileHeader()

        if escript.getMPIRankWorld() < 1:
            stream.write(filename,
                         format="SEGY",
                         data_encoding=1,
                         byteorder=sys.byteorder)
 def setUp(self):
     self.order = 2
     d1 = Brick(n0=NE // 2, n1=NE, n2=NE, l0=0.5, order=2, useElementsOnFace=True)
     d2 = Brick(n0=NE // 2 + 1, n1=NE, n2=NE, l0=0.5, order=2, useElementsOnFace=True)
     d2.setX(d2.getX() + [0.5, 0.0, 0.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)
Exemple #4
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)
 def test_geodetic_domain(self):
     COORDINATES = WGS84ReferenceSystem()
     db = DomainBuilder(reference_system=COORDINATES)
     source1a = NetCdfData(DataSource.GRAVITY,
                           NC_DATA1,
                           scale_factor=1.,
                           reference_system=COORDINATES)
     db.addSource(source1a)
     db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
     dom = db.getDomain()
     x = dom.getX()
     self.assertAlmostEqual(inf(x[0]),
                            120.2,
                            delta=0.001,
                            msg="phi range wrong")
     self.assertAlmostEqual(inf(x[1]),
                            -29.2,
                            delta=0.0001,
                            msg="lambda range wrong")
     self.assertAlmostEqual(inf(x[2]),
                            -0.2,
                            msg="h range wrong" + str(x[2]))
     # Cannot check upper bounds of coordinates with more than 1 rank
     # because ripley may adjust internally.
     if getMPISizeWorld() == 1:
         self.assertAlmostEqual(sup(x[0]),
                                120.3,
                                delta=0.001,
                                msg="phi range wrong")
         self.assertAlmostEqual(sup(x[1]),
                                -29.1,
                                delta=0.0001,
                                msg="lambda range wrong")
         self.assertAlmostEqual(sup(x[2]),
                                0.3,
                                msg="h range wrong: " + str(x[2]))
# mesh for illustration purposes only.
#
#######################################################EXTERNAL MODULES
from esys.pycad import *  #domain constructor
from esys.pycad.extras import layer_cake
from esys.pycad.gmsh import Design  #Finite Element meshing package
from esys.escript import mkDir, getMPISizeWorld
import os
try:
    from esys.finley import MakeDomain
    HAVE_FINLEY = True
except ImportError:
    print("Finley module not available")
    HAVE_FINLEY = False
########################################################MPI WORLD CHECK
if getMPISizeWorld() > 1:
    import sys
    print("This example will not run in an MPI world.")
    sys.exit(0)

if HAVE_FINLEY:
    # make sure path exists
    save_path = os.path.join("data", "example11")
    mkDir(save_path)

    ################################################ESTABLISHING PARAMETERS
    #Model Parameters
    xwidth = 500.0  #x width of model
    ywidth = 500.0  #y width of model
    depth = 250.0  #depth of model
    element_size = 5.0
from test_simplesolve import SimpleSolveTestCase
import esys.escriptcore.utestselect as unittest
from esys.escriptcore.testing import *

from esys.escript import getMPISizeWorld, hasFeature, sqrt
from esys.ripley import Rectangle, Brick
from esys.escript.linearPDEs import SolverOptions

HAVE_PASO = hasFeature('paso')

# number of elements in the spatial directions
NE0=12
NE1=12
NE2=8
mpiSize=getMPISizeWorld()
for x in [int(sqrt(mpiSize)),2,3,5,7,1]:
    NX=x
    NY=mpiSize//x
    if NX*NY == mpiSize:
        break

for x in [(int(mpiSize**(1/3.)),int(mpiSize**(1/3.))),(2,3),(2,2),(1,2),(1,1)]:
    NXb=x[0]
    NYb=x[1]
    NZb=mpiSize//(x[0]*x[1])
    if NXb*NYb*NZb == mpiSize:
        break

@unittest.skipIf(not HAVE_PASO, "PASO not available")
class SimpleSolveOnPaso(SimpleSolveTestCase):
from esys.downunder.domainbuilder import DomainBuilder
from esys.downunder.coordinates import WGS84ReferenceSystem

HAVE_RIPLEY = True
try:
    from esys.ripley import Rectangle
except ImportError as e:
    HAVE_RIPLEY = False


try:
    import pyproj
    haveProj=True
except ImportError:
    haveProj=False
mpisize = getMPISizeWorld()

# this is mainly to avoid warning messages
logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)

try:
    TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
except KeyError:
    TEST_DATA_ROOT='ref_data'

try:
    WORKDIR=os.environ['DOWNUNDER_WORKDIR']
except KeyError:
    WORKDIR='.'

ERS32_DATA = os.path.join(TEST_DATA_ROOT, 'ermapper32_test.ers')
# reference model origin (west, south, bottom)
MODEL_ORIGIN = [originX, originY, -thickness]

# we are using geodetic coordinates
COORDINATES=WGS84ReferenceSystem()

h_unit = COORDINATES.getHeightUnit()
dom_origin = [originX, originY, -thickness/h_unit]
#dom_origin = [1e-5*np.floor(oi*1e5) for oi in dom_origin]
spacing = [resolution, resolution, np.floor((thickness+l_air)/n_cells_v)/h_unit]
l0 = (dom_origin[0], dom_origin[0]+spacing[0]*NX)
l1 = (dom_origin[1], dom_origin[1]+spacing[1]*NY)
l2 = (dom_origin[2], dom_origin[2]+spacing[2]*n_cells_v)

# ensure ripley does not add additional elements in horizontal direction
d0,d1,d2=1,1,getMPISizeWorld()
mpifactors=list(factor(d2))
while len(mpifactors)>0:
    f=mpifactors.pop()
    if d1>=d0:
        if (NX+1)%(d0*f) == 0:
            d0 = d0 * f
            d2 = d2 / f
        elif (NY+1)%(d1*f) == 0:
            d1 = d1 * f
            d2 = d2 / f
    else:
        if (NY+1)%(d1*f) == 0:
            d1 = d1 * f
            d2 = d2 / f
        elif (NX+1)%(d0*f) == 0:
Exemple #10
0
#
#######################################################EXTERNAL MODULES
from esys.escript import mkDir, getMPISizeWorld, hasFeature
from esys.pycad import * #domain constructor
from esys.pycad.extras import layer_cake
from esys.pycad.gmsh import Design #Finite Element meshing package

try:
    from esys.finley import MakeDomain
    HAVE_FINLEY = True
except ImportError:
    print("Finley module not available")
    HAVE_FINLEY = False

########################################################MPI WORLD CHECK
if getMPISizeWorld() > 1 or (hasFeature('mpi') and hasFeature('gmsh_mpi')):
    print("This example will not run in an MPI world!")
elif HAVE_FINLEY:
    import os
    import subprocess as sp
    # make sure path exists
    save_path = os.path.join("data","example10m")
    mkDir(save_path)

    ################################################BIG DOMAIN
    #ESTABLISHING PARAMETERS
    width=10000.    #width of model
    depth=10000.    #depth of model
    bele_size=500.  #big element size
    #DOMAIN CONSTRUCTION
    p0=Point(0.0,    0.0)
#
#######################################################EXTERNAL MODULES
from esys.escript import mkDir, getMPISizeWorld, hasFeature
from esys.pycad import *  #domain constructor
from esys.pycad.extras import layer_cake
from esys.pycad.gmsh import Design  #Finite Element meshing package

try:
    from esys.finley import MakeDomain
    HAVE_FINLEY = True
except ImportError:
    print("Finley module not available")
    HAVE_FINLEY = False

########################################################MPI WORLD CHECK
if getMPISizeWorld() > 1 or (hasFeature('mpi') and hasFeature('gmsh_mpi')):
    print("This example will not run in an MPI world!")
elif HAVE_FINLEY:
    import os
    import subprocess as sp
    # make sure path exists
    save_path = os.path.join("data", "example10m")
    mkDir(save_path)

    ################################################BIG DOMAIN
    #ESTABLISHING PARAMETERS
    width = 10000.  #width of model
    depth = 10000.  #depth of model
    bele_size = 500.  #big element size
    #DOMAIN CONSTRUCTION
    p0 = Point(0.0, 0.0)
 def setUp(self):
     self.domain = Rectangle(l0=1.,
                             l1=1.,
                             n0=10,
                             n1=10 * getMPISizeWorld() - 1,
                             d1=getMPISizeWorld())
 def setUp(self):
      self.domain = Rectangle(l0=1.,l1=1., n0=10, n1=10*getMPISizeWorld()-1, d1=getMPISizeWorld()) 
from test_simplesolve import SimpleSolveTestCase
import esys.escriptcore.utestselect as unittest
from esys.escriptcore.testing import *

from esys.escript import getMPISizeWorld, hasFeature, sqrt
from esys.ripley import Rectangle, Brick
from esys.escript.linearPDEs import SolverOptions

SOLVER = "mkl"
HAVE_REQUESTED_SOLVER = hasFeature(SOLVER)

# number of elements in the spatial directions
NE0 = 12
NE1 = 12
NE2 = 8
mpiSize = getMPISizeWorld()
for x in [int(sqrt(mpiSize)), 2, 3, 5, 7, 1]:
    NX = x
    NY = mpiSize // x
    if NX * NY == mpiSize:
        break

for x in [(int(mpiSize**(1 / 3.)), int(mpiSize**(1 / 3.))), (2, 3), (2, 2),
          (1, 2), (1, 1)]:
    NXb = x[0]
    NYb = x[1]
    NZb = mpiSize // (x[0] * x[1])
    if NXb * NYb * NZb == mpiSize:
        break

    rho_1d = {"left": rho_1d_left, "right": rho_1d_rght}

    # ---
    # Run MT_2D
    # ---

    # Class options:
    mt2d.MT_2D._solver = "DIRECT"
    mt2d.MT_2D._debug = False

    if mt2d.MT_2D._solver == "DIRECT" and not escript.hasFeature('paso'):
        print(
            "Trilinos direct solvers cannot currently handle PDE systems. Please compile with Paso."
        )
    elif mt2d.MT_2D._solver == "DIRECT" and not HAVE_DIRECT:
        if escript.getMPISizeWorld() > 1:
            print(
                "Direct solvers and multiple MPI processes are not currently supported."
            )
        else:
            print(
                "escript was not built with support for direct solvers, aborting."
            )
    elif not escript.hasFeature('gmsh'):
        print("This example requires gmsh, aborting.")
    else:
        # Instantiate an MT_2D object with required & optional parameters:
        obj_mt2d = mt2d.MT_2D(domain,
                              mode,
                              freq_def,
                              tags,
Exemple #16
0
    # Save in dictionary with layer interfaces and resistivities left and right:
    ifc_1d = {"left":ifc_1d_left , "right":ifc_1d_rght}
    rho_1d = {"left":rho_1d_left , "right":rho_1d_rght}

    # ---
    # Run MT_2D
    # ---

    # Class options:
    mt2d.MT_2D._solver = "DIRECT"
    mt2d.MT_2D._debug   = False

    if mt2d.MT_2D._solver == "DIRECT" and not escript.hasFeature('paso'):
        print("Trilinos direct solvers cannot currently handle PDE systems. Please compile with Paso.")
    elif mt2d.MT_2D._solver == "DIRECT" and not HAVE_DIRECT:
        if escript.getMPISizeWorld() > 1:
            print("Direct solvers and multiple MPI processes are not currently supported.")
        else:
            print("escript was not built with support for direct solvers, aborting.")
    elif not escript.hasFeature('gmsh'):
        print("This example requires gmsh, aborting.")
    else:
        # Instantiate an MT_2D object with required & optional parameters:
        obj_mt2d = mt2d.MT_2D(domain, mode, freq_def, tags, rho, rho_1d, ifc_1d,
                xstep=xstep ,zstep=zstep, maps=None, plot=True)

        # Solve for fields, apparent resistivity and phase:
        mt2d_fields, arho_2d, aphi_2d = obj_mt2d.pdeSolve()

        #
        print(datetime.datetime.now()-startTime)
 def setUp(self):
      self.domain = Brick(l0=1.,l1=1.,l2=1., n0=10, n1=10*getMPISizeWorld()-1, n2=10, d1=getMPISizeWorld()) 
Exemple #18
0
#
#######################################################EXTERNAL MODULES
from esys.pycad import * #domain constructor
from esys.pycad.gmsh import Design #Finite Element meshing package
from esys.escript import mkDir, getMPISizeWorld
import os
import math
try:
    # This imports the rectangle domain function 
    from esys.finley import MakeDomain
    HAVE_FINLEY = True
except ImportError:
    print("Finley module not available")
    HAVE_FINLEY = False
########################################################MPI WORLD CHECK
if getMPISizeWorld() > 1:
        import sys
        print("This example will not run in an MPI world.")
        sys.exit(0)

if HAVE_FINLEY:
    # make sure path exists 
    save_path= os.path.join("data","example09c") 
    mkDir(save_path)

    ################################################ESTABLISHING PARAMETERS
    #Model Parameters
    origin=[0,0]                  #orign of model
    xwidth=300.0                      #width of model
    depth=-100.0                      #depth of model
    nintf=3                         #number of the interfaces
try:
    from esys.ripley import Rectangle
except ImportError as e:
    HAVE_RIPLEY = False

if hasFeature('netcdf'):
    HAVE_NETCDF = True
else:
    HAVE_NETCDF = False

try:
    import pyproj
    haveProj = True
except ImportError:
    haveProj = False
mpisize = getMPISizeWorld()

# this is mainly to avoid warning messages
logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)

try:
    TEST_DATA_ROOT = os.environ['DOWNUNDER_TEST_DATA_ROOT']
except KeyError:
    TEST_DATA_ROOT = 'ref_data'

try:
    WORKDIR = os.environ['DOWNUNDER_WORKDIR']
except KeyError:
    WORKDIR = '.'

ERS32_DATA = os.path.join(TEST_DATA_ROOT, 'ermapper32_test.ers')