How to use the underworld._stgermain function in underworld

To help you get started, we’ve selected a few underworld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github underworldcode / underworld2 / underworld / systems / _timeintegration.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld as uw
import underworld._stgermain as _stgermain
import libUnderworld

class TimeIntegration(_stgermain.StgCompoundComponent):
    """
    Abstract class for integrating numerical objects (fields, swarms, etc.) in time.

    The integration algorithm is a modified Runge Kutta method that only evaluates
    midpoint information varying in space - using only the present timestep solution.
    The order of the integration used can be 1,2,4

    Parameters
    ----------
    order: int {1,2,4}
        Defines the numerical order 'in space' of the Runge Kutta like integration scheme.

    """
    _objectsDict = {     "_system" : "TimeIntegrator",
                      "_integrand" : None }
    _selfObjectName = "_system"
github underworldcode / underworld2 / underworld / systems / sle / _fvector.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld as uw
import underworld._stgermain as _stgermain
import underworld.mesh as mesh
import numpy as np
import weakref
from libUnderworld import *

class ForceVector(_stgermain.StgCompoundComponent):
    """
    Parameters
    ----------
    meshVariable : underworld.mesh.MeshVariable
        MeshVariable object for which this SLE vector corresponds.
    
    """
    _objectsDict = { "_vector": "ForceVector" }
    _selfObjectName = "_vector"

    def __init__(self, meshVariable, **kwargs):
        
        if not isinstance(meshVariable, mesh.MeshVariable):
            raise TypeError("'meshVariable' object passed in must be of type 'MeshVariable'")
        self._meshVariable = meshVariable
github underworldcode / underworld2 / underworld / swarm / layouts.py View on Github external
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
'''
This module contains classes for populating swarms with particles across
the domain.
'''
import underworld._stgermain as _stgermain
import _swarm
import abc as _abc

class ParticleLayoutAbstract(_stgermain.StgCompoundComponent):
    """
    Abstract class. Children classes are responsible for populating 
    swarms with particles, generally across the entire domain.

    Parameters
    ----------
    swarm : underworld.swarm.Swarm
        The swarm this layout will act upon
    
    """
    _objectsDict = {  "_layout": None }
    _selfObjectName = "_layout"

    __metaclass__ = _abc.ABCMeta
    def __init__(self, swarm, **kwargs ):
github underworldcode / underworld2 / underworld / systems / sle / _svector.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld as uw
import underworld._stgermain as _stgermain

class SolutionVector(_stgermain.StgCompoundComponent):
    """
    The SolutionVector manages the numerical solution vectors used by Underworld's equation systems.
    Interface between meshVariables and systems.

    Parameters
    ----------
    meshVariable: underworld.mesh.MeshVariable
        MeshVariable object for which this SLE vector corresponds.
    eqNumber:     underworld.systems.sle.EqNumber
        Equation numbering object corresponding to this vector.
    
    Example
    -------
    >>> linearMesh = uw.mesh.FeMesh_Cartesian( elementType='Q1/dQ0', elementRes=(4,4), minCoord=(0.,0.), maxCoord=(1.,1.) )
    >>> tField = uw.mesh.MeshVariable( linearMesh, 1 )
    >>> eqNum = uw.systems.sle.EqNumber( tField )
github underworldcode / underworld2 / underworld / swarm / _weights.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld._stgermain as _stgermain
from . import _swarm

class DVC(_stgermain.StgCompoundComponent):
    """
    Discrete Voronoi Cell weights calculator.

    Parameters
    ----------
    resolutionX, resolutionY, resolutionZ : int
        The resolution of the grid used for the discrete voronoi algorithm.

    """
    _objectsDict = { "_weights": "DVCWeights" }
    _selfObjectName = "_weights"

        # build parent
    def __init__(self, resx=15,resy=15,resz=15, **kwargs):
        self.resx=resx
        self.resy=resy
github underworldcode / underworld2 / underworld / swarm / _swarmabstract.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld as uw
import underworld._stgermain as _stgermain
import weakref
import libUnderworld
from . import _swarmvariable as svar
import abc

class SwarmAbstract(_stgermain.StgCompoundComponent, metaclass = abc.ABCMeta):
    """
    The SwarmAbstract class supports particle like data structures. Each instance of 
    this class will store a set of unique particles. In this context, particles
    are data structures which store a location variable, along with any other
    variables the user requests.

    Parameters
    ----------
    mesh : underworld.mesh.FeMesh
        The FeMesh the swarm is supported by. See Swarm.mesh property docstring
        for further information.

    """
    _objectsDict = {            "_swarm" : None,
                           "_cellLayout" : None
                    }
github underworldcode / underworld2 / underworld / systems / _stokes.py View on Github external
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
##                                                                                   ##
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld as uw
import underworld._stgermain as _stgermain
from . import sle
import libUnderworld

class Stokes(_stgermain.StgCompoundComponent):
    """
    This class provides functionality for a discrete representation
    of the Stokes flow equations.

    Specifically, the class uses a mixed finite element method to
    construct a system of linear equations which may then be solved
    using an object of the underworld.system.Solver class.

    The underlying element types are determined by the supporting
    mesh used for the 'velocityField' and 'pressureField' parameters.

    The strong form of the given boundary value problem, for :math:`f`,
    :math:`g` and :math:`h` given, is

    .. math::
        \\begin{align}
github underworldcode / underworld2 / underworld / __init__.py View on Github external
by the class' __init__ method.  This is necessary for StgCompountComponent
    subclasses (the only type this method applies to) due to the metaclassing
    which results in the __call__ method's signature (as defined in _SetupClass)
    being the one inspect.signature() returns (which is *not* what the user
    should see).
    '''
    import inspect
    # first gather info
    mods = {}
    for guy in dir(mod):
        if guy[0] != "_":  # don't grab private guys
            obj = getattr(mod,guy)
            if inspect.ismodule(obj):
                mods[guy] = obj
            elif inspect.isclass(obj):
                if issubclass(obj, _stgermain.StgCompoundComponent):
                    # replace signature here
                    obj.__signature__ = inspect.signature(obj.__init__)
    for key in mods:
        # recurse into submodules
        _set_init_sig_as_sig(getattr(mod,key))
github underworldcode / underworld2 / underworld / systems / _advectiondiffusion.py View on Github external
maxDiffusion = self._maxDiff.max_global()

        # the minimum separation of the mesh (globally)
        dx = self._minDx
        #dx = self.vField.mesh._typicalDx # from LM implementation

        # Note, if dx is not constant, these tests are potentially
        # overly pessimistic

        diff_dt = dx * dx / maxDiffusion
        adv_dt  = dx / vmax

        return min(adv_dt, diff_dt)


class _SUPG_AdvectionDiffusion(_stgermain.StgCompoundComponent):
    """
    This class provides functionality for a discrete representation
    of an advection-diffusion equation.

    The class uses the Streamline Upwind Petrov Galerkin SUPG method
    to integrate through time.

    .. math::
        \\frac{\\partial\\phi}{\\partial t}  + {\\bf u } \\cdot \\nabla \\phi= \\nabla { ( k  \\nabla \\phi ) } + H


    Parameters
    ----------
    phiField : underworld.mesh.MeshVariable
        The concentration field, typically the temperature field
    phiDotField : underworld.mesh.MeshVariable
github underworldcode / underworld2 / underworld / mesh / _meshvariable.py View on Github external
##  This file forms part of the Underworld geophysics modelling application.         ##
##                                                                                   ##
##  For full license and copyright information, please refer to the LICENSE.md file  ##
##  located at the project root, or contact the authors.                             ##
##                                                                                   ##
##~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~##
import underworld._stgermain as _stgermain
import underworld as uw
import libUnderworld.libUnderworldPy.Function as _cfn
import libUnderworld
from mpi4py import MPI
import h5py
import numpy as np
import os

class MeshVariable(_stgermain.StgCompoundComponent,uw.function.Function,_stgermain.Save,_stgermain.Load):
    """
    The MeshVariable class generates a variable supported by a finite element mesh.

    To set / read nodal values, use the numpy interface via the 'data' property.

    Parameters
    ----------
    mesh : underworld.mesh.FeMesh
        The supporting mesh for the variable.
    dataType : string
        The data type for the variable.
        Note that only 'double' type variables are currently
        supported.
    nodeDofCount : int
        Number of degrees of freedom per node the variable will have.