Exemplo n.º 1
0
    def __init__(self, comm, filename=None):
        # Create data structure for saving data
        self.data = {}
        self.data_header = {}

        # Flag indicating if header has been written to filename
        self._header_flag = False

        # Enable info_{blue,green,red} and reduce logging in parallel
        rank = MPI.rank(comm)
        ufl.set_level(ufl.INFO if rank == 0 else ufl.INFO + 1)
        self._comm = comm
        self._rank = rank

        # Open filename if given
        datafile = None
        if rank == 0 and filename is not None:
            prepare_output_directory(os.path.split(filename)[0])
            datafile = open(filename, 'w')
        self._datafile = datafile
Exemplo n.º 2
0
# Modified by Garth N. Wells, 2011.
#
# First added:  2008-12-04
# Last changed: 2011-09-10

__all__ = ["jit"]

from functools import wraps

# Import SWIG-generated extension module (DOLFIN C++)
import dolfin.cpp as cpp
from dolfin.cpp import MPI, info, parameters, warning, info

# Set UFL log level
import ufl
ufl.set_level(ufl.INFO)

# Import check for correct swig version from instant
from instant import check_swig_version, get_swig_version, check_and_set_swig_binary

# Cached swig check
_swig_version_ok = False

def mpi_jit_decorator(local_jit, *args, **kwargs):
    """A decorator for jit compilation

    Use this function as a decorator to any jit compiler function.  In
    a paralell run, this function will first call the jit compilation
    function on the first process. When this is done, and the module
    is in the cache, it will call the jit compiler on the remaining
    processes, which will then use the cached module.
Exemplo n.º 3
0
from __future__ import print_function
from dolfin import *
from dolfin_adjoint import *
import ufl

parameters["adjoint"]["debug_cache"] = True
ufl.set_level(INFO)

def main(c, annotate=False):
    # Prepare a mesh
    mesh = UnitIntervalMesh(50)

    # Define function space
    U = FunctionSpace(mesh, "DG", 2)

    # Set some expressions
    uinit = Expression("cos(pi*x[0])", degree=2)
    ubdr = Constant(1.0)

    # Set initial values
    u0 = interpolate(uinit, U, name="u0")

    # Define test and trial functions
    v = TestFunction(U)
    u = TrialFunction(U)

    # Set time step size
    DT = Constant(2.e-5)

    # Define fluxes on interior and exterior facets
    uhat    = avg(u0) + 0.25*jump(u0)
Exemplo n.º 4
0
from firedrake import *
import matplotlib.pyplot as plt
from matplotlib import rc
import ufl

ufl.set_level(ufl.CRITICAL)

# Mesh definition
use_quad_mesh = True
number_of_elements_x = 25
number_of_elements_y = 25
mesh = UnitSquareMesh(number_of_elements_x,
                      number_of_elements_y,
                      quadrilateral=use_quad_mesh)

# Continuous Galerkin function space (degree = 1)
p = 1
V = FunctionSpace(mesh, "CG", p)
VelSpace = VectorFunctionSpace(mesh, "CG", p)

# Strong boundary conditions
u1, u2 = 0.0, 0.0
g_left = Constant(u1)
g_right = Constant(u2)

# Marking the boundaries
bc_left = DirichletBC(V, g_left, 1)
bc_right = DirichletBC(V, g_right, 2)
dirichlet_condition = [bc_left, bc_right]

# Source term
Exemplo n.º 5
0
from dolfin import *
from dolfin_adjoint import *
import ufl

parameters["adjoint"]["debug_cache"] = True
ufl.set_level(INFO)

def main(c, annotate=False):
    # Prepare a mesh
    mesh = UnitIntervalMesh(50)

    # Define function space
    U = FunctionSpace(mesh, "DG", 2)

    # Set some expressions
    uinit = Expression("cos(pi*x[0])")
    ubdr = Constant(1.0)

    # Set initial values
    u0 = interpolate(uinit, U, name="u0")

    # Define test and trial functions
    v = TestFunction(U)
    u = TrialFunction(U)

    # Set time step size
    DT = Constant(2.e-5)

    # Define fluxes on interior and exterior facets
    uhat    = avg(u0) + 0.25*jump(u0)
    uhatbnd = -u0 + 0.25*(u0-ubdr)
Exemplo n.º 6
0
# degrading parameters since e91b4100. This assumes that this module
# is imported before DOLFIN; otherwise the assertion may fail.
# TODO: Test whether it works!
from petsc4py import PETSc
from dolfin import SubSystemsManager
assert not SubSystemsManager.responsible_petsc()
del PETSc, SubSystemsManager

# Reduce DOLFIN logging bloat in parallel
from dolfin import set_log_level, get_log_level, MPI, mpi_comm_world
set_log_level(get_log_level()+(0 if MPI.rank(mpi_comm_world())==0 else 1))
del set_log_level, get_log_level

# Parse command-line options
# FIXME: Automatic parsing temporarily commented out as it disallows parsing
#        our own application specific parameters. Do we need it somewhere?
#from dolfin import parameters
#parameters.parse()

# Enable info_{green,red,blue} on rank 0
import ufl
ufl.set_level(ufl.INFO if MPI.rank(mpi_comm_world())==0 else ufl.INFO+1)
del ufl, MPI, mpi_comm_world


from dolfintape.flux_reconstructor import FluxReconstructor
from dolfintape.cell_diameter import CellDiameters
from dolfintape.mesh_diameter import mesh_diameter

__all__ = ['FluxReconstructor', 'CellDiameters', 'mesh_diameter']
Exemplo n.º 7
0
#
# First added:  2008-12-04
# Last changed: 2011-09-10

__all__ = ["jit"]

from functools import wraps

# Import SWIG-generated extension module (DOLFIN C++)
import dolfin.cpp as cpp
from dolfin.cpp import MPI, info, parameters, warning, info

# Set UFL log level
import ufl

ufl.set_level(ufl.INFO)


def mpi_jit_decorator(local_jit, *args, **kwargs):
    """A decorator for jit compilation

    Use this function as a decorator to any jit compiler function.  In
    a paralell run, this function will first call the jit compilation
    function on the first process. When this is done, and the module
    is in the cache, it will call the jit compiler on the remaining
    processes, which will then use the cached module.

    *Example*
        .. code-block:: python

            def jit_something(something):