def setupERTPDE(domain, tolerance=1e-8, poisson=True, debug=0): """ used to setup all PDEs fro ERT related inversion. If available TRILINOS is usered. :param domain: domain of the PDE :type domain: `esys.escript.AbstractDomain` :param tolerance: solver tolerance :type tolerance: `float` :param poisson: if True TRILINOS settings fro Poisson problems is set. :type poisson: `bool` :return: linear, scalar PDE with real coefficients. :rtype: `esys.escript.linearPDEs.LinearPDE` """ pde = LinearSinglePDE(domain, isComplex=False) pde.setSymmetryOn() optionsG = pde.getSolverOptions() optionsG.setSolverMethod(SolverOptions.PCG) optionsG.setTolerance(tolerance) if hasFeature('trilinos'): if debug and getMPIRankWorld() == 0: print("TRILINOS solver used.") optionsG.setPackage(SolverOptions.TRILINOS) optionsG.setPreconditioner(SolverOptions.AMG) if poisson: optionsG.setTrilinosParameter("problem:type", "Poisson-3D") optionsG.setTrilinosParameter("verbosity", "none") optionsG.setTrilinosParameter("number of equations", 1) optionsG.setTrilinosParameter("problem: symmetric", True) return pde
def __init__(self, domain=None): """ sets up driver for translating Data objects in domain to TVTK object. """ if HAVE_TVTK == False: raise Exception("Failed to load the TVTK module") if hasFeature("boostnumpy") == False: raise Exception( "This feature requires boost version 1.64 or higher") if domain is None: self.domain = None else: self.setDomain(domain)
http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" """ Test suite for PDE solvers on ripley """ 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]
HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.escript import getMPISizeWorld, hasFeature from esys.escript.modelframe import DataSource from esys.pycad.gmsh import * from esys.pycad import * # Putting it in modellib dir try: MODELLIB_WORKDIR=os.environ['MODELLIB_WORKDIR'] except KeyError: MODELLIB_WORKDIR='.' GMSH = hasFeature('gmsh') mpiSize = getMPISizeWorld() @unittest.skipIf(not GMSH, "gmsh not available") @unittest.skipIf(mpiSize > 1, "not tested with more than 1 MPI rank") class Test_domainReaders(unittest.TestCase): def domain_family(self, dommodule, f): dom=RectangularDomain(dommodule, parameters=["fish","dummy"], debug=True) # need to write to both .fly and .gmsh dom.domain().write(f+"dr.fly") r1=DomainReader(dommodule) r1.source=DataSource(uri=f+"dr.fly", fileformat="fly") r1.domain() des=Design() b=Volume(Brick(Point(0,0,0), Point(1,1,1)))
http://www.opensource.org/licenses/osl-3.0.php""" __url__ = "https://launchpad.net/escript-finley" """ Test suite for PDE solvers on ripley """ 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]
import logging import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * import numpy import datetime import esys.downunder.magtel2d as mt2d import esys.escript as escript import esys.escript.pdetools as pdetools try: import esys.finley as finley HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False HAVE_GMSH = escript.hasFeature("gmsh") HAVE_DIRECT = escript.hasFeature("PASO_DIRECT") or escript.hasFeature('trilinos') # this is mainly to avoid warning messages logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO) def makeLayerCake(x_start,x_extent,z_layers): # --------------------------------------------------------------------------------------------- # DESCRIPTION: # ----------- # This is a utility function which sets up a 2D model with N layers. # # ARGUMENTS: # ----------
http://www.opensource.org/licenses/osl-3.0.php""" __url__="https://launchpad.net/escript-finley" """ Test suite for PDE solvers on dudley """ from test_simplesolve import SimpleSolveTestCase import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * from esys.dudley import Rectangle, Brick from esys.escript import hasFeature, SolverOptions from esys.escript.linearPDEs import SolverOptions HAVE_TRILINOS = hasFeature('trilinos') skip_muelu_long = False #hasFeature("longindex") # number of elements in the spatial directions NE0=12 NE1=12 NE2=8 OPTIMIZE=True @unittest.skipIf(not HAVE_TRILINOS, "Trilinos not available") class SimpleSolveOnTrilinos(SimpleSolveTestCase): pass ### BiCGStab + Jacobi class Test_SimpleSolveDudleyRect_Trilinos_BICGSTAB_Jacobi(SimpleSolveOnTrilinos):
Primary Business: Queensland, Australia""" __license__="""Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" """ Generic base class for PDE solving tests """ from esys.escript import Data, Function, Lsup, Solution, Tensor4, Vector, \ grad, inner, kronecker, matrixmult, whereZero, hasFeature from esys.escript.linearPDEs import LinearPDE, SolverOptions import esys.escriptcore.utestselect as unittest import numpy HAVE_DIRECT_PASO = hasFeature('paso') and (hasFeature('umfpack') or hasFeature("mkl") or hasFeature("mumps")) HAVE_MUMPS = hasFeature("mumps") HAVE_TRILINOS = hasFeature('trilinos') HAVE_SOLVER = HAVE_DIRECT_PASO or HAVE_TRILINOS HAVE_SOLVER_COMPLEX = HAVE_TRILINOS or HAVE_MUMPS class SolveTestCaseTemplate(unittest.TestCase): """ this is the template class for testing solvers: """ REL_TOL = 1.e-6 SOLVER_VERBOSE = False SOLVER_TOL = 1.e-8 # the following members must be set by the test methods in subclasses domain = None
__license__ = """Licensed under the Open Software License version 3.0 http://www.opensource.org/licenses/osl-3.0.php""" __url__ = "https://launchpad.net/escript-ripley" """ Test suite for PDE solvers on ripley """ 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_MUMPS = hasFeature('mumps') skip_amg = True skip_muelu_long = False #hasFeature("longindex") # number of elements in the spatial directions NE0 = 12 NE1 = 12 NE2 = 8 OPTIMIZE = True mpiSize = getMPISizeWorld() for x in [int(sqrt(mpiSize)), 2, 3, 5, 7, 1]: NX = x NY = mpiSize // x if NX * NY == mpiSize: break
HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False from esys.escript import getMPISizeWorld, hasFeature from esys.escript.modelframe import DataSource from esys.pycad.gmsh import * from esys.pycad import * # Putting it in modellib dir try: MODELLIB_WORKDIR = os.environ['MODELLIB_WORKDIR'] except KeyError: MODELLIB_WORKDIR = '.' GMSH = hasFeature('gmsh') mpiSize = getMPISizeWorld() @unittest.skipIf(not GMSH, "gmsh not available") @unittest.skipIf(mpiSize > 1, "not tested with more than 1 MPI rank") class Test_domainReaders(unittest.TestCase): def domain_family(self, dommodule, f): dom = RectangularDomain(dommodule, parameters=["fish", "dummy"], debug=True) # need to write to both .fly and .gmsh dom.domain().write(f + "dr.fly") r1 = DomainReader(dommodule) r1.source = DataSource(uri=f + "dr.fly", fileformat="fly") r1.domain()
Primary Business: Queensland, Australia""" __license__ = """Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__ = "https://launchpad.net/escript-finley" __all__ = ['AcousticWaveForm'] from .base import ForwardModel #from esys.escript.util import * import numpy as np import esys.escript.linearPDEs as lpde import esys.escript as escript from .. import coordinates as edc #import ..coordinates as edc HAVE_DIRECT = escript.hasFeature("PASO_DIRECT") or escript.hasFeature( 'trilinos') class AcousticWaveForm(ForwardModel): """ Forward Model for acoustic waveform inversion in the frequency domain. It defines a cost function: :math: `defect = 1/2 integrate( ( w * ( a * u - data ) ) ** 2 )` where w are weighting factors, data are the measured data (as a 2-comp vector of real and imaginary part) for real frequency omega, and u is the corresponding result produced by the forward model. u (as a 2-comp vector) is the solution of the complex Helmholtz equation for frequency omega, source F and complex, inverse, squared p-velocity
# #######################################################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)
""" Test suite for the linearPDE and pdetools test on finley """ __author__ = "Lutz Gross, [email protected]" import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * from test_pdetools import Test_pdetools from esys.escript import hasFeature from esys.finley import Brick NE = 10 # number of element in each spatial direction (must be even) # trilinos and paso are different TOL = 1.e-7 if hasFeature('paso') else 5.e-7 class Test_PDEToolsOnFinleyHex3DOrder2(Test_pdetools): RES_TOL = TOL ABS_TOL = 1.e-8 def setUp(self): self.domain = Brick(NE, NE, NE, 2) self.order = 2 def tearDown(self): del self.domain if __name__ == '__main__':
__url__ = "https://launchpad.net/escript-finley" """ Test suite for nonlinearPDEs class """ __author__ = "Jaco du Plessis" from esys.escript import NonlinearPDE, Symbol, whereZero, grad, sin, cos, symmetric, matrixmult, FunctionOnBoundary, hasFeature import numpy import esys.escriptcore.utestselect as unittest from esys.escript.linearPDEs import IllegalCoefficient, IllegalCoefficientValue import numpy as np from esys.escript.pdetools import Locator if hasFeature("sympy"): sympyavail = True else: sympyavail = False class Test_nonLinearPDEs(unittest.TestCase): DEBUG = False VERBOSE = False @unittest.skipIf(not sympyavail, 'sympy not available') class Test_nlpde(Test_nonLinearPDEs): def test_run(self): #test just to confirm nlpde works u = Symbol('u', dim=self.domain.getDim())
# you would like to display the final plot in a window instead. matplotlib.use('agg') import datetime import numpy import esys.downunder.magtel2d as mt2d import esys.escript as escript import esys.escript.pdetools as pdetools try: import esys.finley as finley HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False HAVE_DIRECT = escript.hasFeature("PASO_DIRECT") or escript.hasFeature('trilinos') #------------------------------------------------------------- # The following functions create the mesh used by this example #------------------------------------------------------------- def makeLayerCake(x_start,x_extent,z_layers): # -------------------------------------------------------------------------- # DESCRIPTION: # ----------- # This is a utility function which sets up a 2D model with N layers. # # ARGUMENTS: # ---------- # x_start :: start coordinate of mesh.
import logging import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * import numpy import datetime import esys.downunder.magtel2d as mt2d import esys.escript as escript import esys.escript.pdetools as pdetools try: import esys.finley as finley HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False HAVE_GMSH = escript.hasFeature("gmsh") HAVE_DIRECT = escript.hasFeature("PASO_DIRECT") or escript.hasFeature( 'trilinos') # this is mainly to avoid warning messages logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO) def makeLayerCake(x_start, x_extent, z_layers): # --------------------------------------------------------------------------------------------- # DESCRIPTION: # ----------- # This is a utility function which sets up a 2D model with N layers. # # ARGUMENTS: # ----------
# you would like to display the final plot in a window instead. matplotlib.use('agg') import datetime import numpy import esys.downunder.magtel2d as mt2d import esys.escript as escript import esys.escript.pdetools as pdetools try: import esys.finley as finley HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False HAVE_DIRECT = escript.hasFeature("PASO_DIRECT") or escript.hasFeature( 'trilinos') #------------------------------------------------------------- # The following functions create the mesh used by this example #------------------------------------------------------------- def makeLayerCake(x_start, x_extent, z_layers): # -------------------------------------------------------------------------- # DESCRIPTION: # ----------- # This is a utility function which sets up a 2D model with N layers. # # ARGUMENTS: # ----------
density=density, susceptibility=susceptibility, x=susceptibility.getFunctionSpace().getX()) print("Results saved in result_gravmag.csv") print("All done. Have a nice day!") try: import pyproj HAVE_PYPROJ = True except ImportError: HAVE_PYPROJ = False try: import esys.ripley HAVE_RIPLEY = True except ImportError: HAVE_RIPLEY = False if not hasFeature('netcdf'): print( "This example requires scipy's netcdf support which does not appear to be installed." ) elif not HAVE_RIPLEY: print("Ripley module not available") elif not HAVE_PYPROJ: print("This example requires pyproj to be installed.") else: work()
http://www.uq.edu.au Primary Business: Queensland, Australia""" __license__="""Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__="https://launchpad.net/escript-finley" __all__ = ['AcousticWaveForm'] from .base import ForwardModel from esys.downunder.coordinates import makeTransformation from esys.escript import Data, DiracDeltaFunctions, FunctionOnBoundary, hasFeature from esys.escript.linearPDEs import LinearPDE, SolverOptions from esys.escript.util import * import numpy as np HAVE_DIRECT = hasFeature("PASO_DIRECT") or hasFeature('trilinos') class AcousticWaveForm(ForwardModel): """ Forward Model for acoustic waveform inversion in the frequency domain. It defines a cost function: :math: `defect = 1/2 integrate( ( w * ( a * u - data ) ) ** 2 )` where w are weighting factors, data are the measured data (as a 2-comp vector of real and imaginary part) for real frequency omega, and u is the corresponding result produced by the forward model. u (as a 2-comp vector) is the solution of the complex Helmholtz equation for frequency omega, source F and complex, inverse, squared p-velocity sigma:
http://www.opensource.org/licenses/osl-3.0.php""" __url__ = "https://launchpad.net/escript-finley" """ Test suite for PDE solvers on ripley """ 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 = 'umfpack' HAVE_REQUESTED_SOLVER = hasFeature(SOLVER) and 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]
http://www.opensource.org/licenses/osl-3.0.php""" __url__ = "https://launchpad.net/escript-finley" """ Test suite for PDE solvers on ripley multiresolution domains """ 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 MultiResolutionDomain from esys.escript.linearPDEs import SolverOptions HAVE_TRILINOS = hasFeature("trilinos") skip_muelu_long = False # hasFeature("longindex") # number of elements in the spatial directions NE0 = 10 NE1 = 10 NE2 = 9 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.0)), int(mpiSize ** (1 / 3.0))), (2, 3), (2, 2), (1, 2), (1, 1)]: NXb = x[0]
http://www.opensource.org/licenses/osl-3.0.php""" __url__="https://launchpad.net/escript-finley" """ Test suite for PDE solvers on ripley """ 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_TRILINOS = hasFeature('trilinos') skip_muelu_long = False #hasFeature("longindex") # 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]
import os import sys import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * from esys.escript import inf, sup, saveDataCSV, getMPISizeWorld, hasFeature from esys.downunder.datasources import * 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 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:
try: import esys.dudley HAVE_DUDLEY = True except ImportError: HAVE_DUDLEY = False try: import esys.finley from esys.modellib.geometry import RectangularDomain, ScalarConstrainerOverBox, VectorConstrainerOverBox HAVE_FINLEY = True except ImportError: HAVE_FINLEY = False # TODO: once Amesos2 can deal with block matrices uncomment HAVE_DIRECT = hasFeature("PASO_DIRECT") #or hasFeature('trilinos') try: WORKDIR = os.environ['MODELLIB_WORKDIR'] except KeyError as e: WORKDIR = '.' #if this func is inside the test case, the Link() calls blow up def run(dom, stream): temp_val = InterpolateOverBox() temp_val.domain = Link(dom, "domain") temp_val.value_left_bottom_front = 1. temp_val.value_right_bottom_front = 1. temp_val.value_left_top_front = 0. temp_val.value_right_top_front = 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)
__license__ = """Licensed under the Apache License, version 2.0 http://www.apache.org/licenses/LICENSE-2.0""" __url__ = "https://launchpad.net/escript-finley" """ Test suite for PDE solvers on finley """ from test_simplesolve import SimpleSolveTestCase, SimpleSolveTestCaseOrder2 import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * from esys.escript import Data, Solution, Vector, hasFeature from esys.finley 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 OPTIMIZE = True @unittest.skipIf(not HAVE_PASO, "PASO not available") class SimpleSolveOnPaso(SimpleSolveTestCase): pass @unittest.skipIf(not HAVE_PASO, "PASO not available") class SimpleSolveOnPasoOrder2(SimpleSolveTestCaseOrder2):
""" Test suite for the linearPDE and pdetools test on finley """ __author__="Lutz Gross, [email protected]" import esys.escriptcore.utestselect as unittest from esys.escriptcore.testing import * from test_pdetools import Test_pdetools from esys.escript import hasFeature from esys.finley import Brick NE=10 # number of element in each spatial direction (must be even) # trilinos and paso are different TOL = 1.e-7 if hasFeature('paso') else 5.e-7 class Test_PDEToolsOnFinleyHex3DOrder2(Test_pdetools): RES_TOL=TOL ABS_TOL=1.e-8 def setUp(self): self.domain = Brick(NE,NE,NE,2) self.order = 2 def tearDown(self): del self.domain if __name__ == '__main__': run_tests(__name__, exit_on_failure=True)