Exemplo n.º 1
0
def ffc_jit(ufl_form, form_compiler_parameters=None):

    # Prepare form compiler parameters with overrides from dolfin and kwargs
    p = ffc.default_jit_parameters()
    p.update(dict(parameters["form_compiler"]))
    p.update(form_compiler_parameters or {})
    return ffc.jit(ufl_form, parameters=p)
Exemplo n.º 2
0
def ffc_default_parameters():
    """Get default parameters of FFC"""
    # Get dict with defaults

    # FIXME: intialising MPI because setting parameters makes MPI
    # calls, possibly via the log systems. Needs to be fixed.
    cpp.MPI.init()

    d = default_jit_parameters()
    p = cpp.parameter.Parameters("form_compiler")

    typemap = {"quadrature_rule": "", "quadrature_degree": 0, "precision": 0}

    # Add the rest
    for key, value in d.items():
        if value is None:
            p.add(key, typemap[key])
            p[key] = None
        else:
            p.add(key, value)

    # Update the scalar type according to the mode (real or complex)
    p["scalar_type"] = "double complex" if common.has_petsc_complex else "double"

    return p
Exemplo n.º 3
0
def ffc_jit(ufl_form, form_compiler_parameters=None):

    # Prepare form compiler parameters with overrides from dolfin and kwargs
    p = ffc.default_jit_parameters()
    p.update(dict(parameters["form_compiler"]))
    p.update(form_compiler_parameters or {})
    return ffc.jit(ufl_form, parameters=p)
Exemplo n.º 4
0
Arquivo: run.py Projeto: miklos1/urumi
def ffc_compile_form(form, parameters=None):
    # Use jit=True to disable element compilation.
    # Makes time comparison fairer.
    if parameters is None:
        parameters = ffc.default_jit_parameters()
    else:
        _ = ffc.default_jit_parameters()
        _.update(parameters)
        parameters = _

    tic = time()
    result = ffc.compile_form([form], parameters=parameters, jit=True)
    T1 = time() - tic

    # Some versions return a third result which we do not care about.
    assert isinstance(result, tuple)
    assert 2 <= len(result) <= 3
    code_h = result[0]  # noqa: F841
    code_c = result[1]
    # lines = ['#include <math.h>', '#include <string.h>']  # TSFC representation
    # lines = ['#include <algorithm>']  # UFLACS representation
    # lines = ['#include <algorithm>', "#include <ufc_geometry.h>"]  # Legacy representations
    lines = ["#include <cstring>", "#include <algorithm>", "#include <ufc_geometry.h>"]
    it = iter(code_c.split('\n'))
    for line in it:
        if '::tabulate_tensor' in line:
            lines.append(re.sub(' .*::', ' ', line))
            for line in it:
                lines.append(re.sub('\) const', ')', line))
                if line == '}':
                    break
            else:
                assert False
    code_c = '\n'.join(lines)
    print(code_c, file=open("Form.cpp", 'w'))

    tic = time()
    subprocess.check_call(["c++", "-pipe", "-c", "-O2", "-std=c++11", "-I/home/mh1714/ffc-tsfc/src/ffc/ffc/backends/ufc/", "Form.cpp"])
    T2 = time() - tic

    inst = int(subprocess.check_output("objdump -d Form.o | wc -l", shell=True))
    return T1 + T2, inst
Exemplo n.º 5
0
def ffc_jit(ufl_object, form_compiler_parameters=None):
    # Prepare form compiler parameters with overrides from dolfin
    p = ffc.default_jit_parameters()
    p["scalar_type"] = "double complex" if common.has_petsc_complex else "double"
    p.update(form_compiler_parameters or {})

    # Switch on type and compile, returning cffi object
    if isinstance(ufl_object, ufl.Form):
        r = ffc.codegeneration.jit.compile_forms([ufl_object], parameters=p)
    elif isinstance(ufl_object, ufl.FiniteElementBase):
        r = ffc.codegeneration.jit.compile_elements([ufl_object], parameters=p)
    elif isinstance(ufl_object, ufl.Mesh):
        r = ffc.codegeneration.jit.compile_coordinate_maps([ufl_object], parameters=p)
    else:
        raise TypeError(type(ufl_object))

    return r[0][0]
Exemplo n.º 6
0
def ffc_default_parameters():
    """Get default parameters of FFC"""
    # Get dict with defaults

    # FIXME: intialising MPI because setting parameters makes MPI
    # calls, possibly via the log systems. Needs to be fixed.
    dolfin.cpp.MPI.init()

    d = default_jit_parameters()
    p = Parameters("form_compiler")

    typemap = {"quadrature_rule": "", "quadrature_degree": 0, "precision": 0}

    # Add the rest
    for key, value in d.items():
        if value is None:
            p.add(key, typemap[key])
            p[key] = None
        else:
            p.add(key, value)

    return p
Exemplo n.º 7
0
def ffc_default_parameters():
    """Get default parameters of FFC"""
    # Get dict with defaults

    # FIXME: intialising MPI because setting parameters makes MPI
    # calls, possibly via the log systems. Needs to be fixed.
    cpp.MPI.init()

    d = default_jit_parameters()
    p = Parameters("form_compiler")

    typemap = {"quadrature_rule": "", "quadrature_degree": 0,
               "precision": 0}

    # Add the rest
    for key, value in d.items():
        if value is None:
            p.add(key, typemap[key])
            p[key] = None
        else:
            p.add(key, value)

    return p
Exemplo n.º 8
0
def ffc_jit(ufl_form, form_compiler_parameters=None):
    # Prepare form compiler parameters with overrides from dolfin
    p = ffc.default_jit_parameters()
    p["scalar_type"] = "double complex" if common.has_petsc_complex else "double"
    p.update(form_compiler_parameters or {})
    return ffc.jit(ufl_form, parameters=p)