Example #1
0
def compile_vforms(vfs, verbose=False):
    vfs = tuple(vfs)
    n = len(vfs)
    names = tuple('CustomAssembler%d' % i for i in range(n))

    code = codegen.CodeGen()
    for (name, vf) in zip(names, vfs):
        codegen.AsmGenerator(vf, name, code).generate()
    src = codegen.preamble() + '\n' + code.result()

    mod = compile_cython_module(src, verbose=verbose)
    return tuple(getattr(mod, name) for name in names)
Example #2
0
def compile_vforms(vfs, verbose=False):
    """Compile a list of vforms into assembler classes.

    This may be faster than compiling each vform individually since they are
    all combined into one source file.
    """
    vfs = tuple(vfs)
    names = tuple('CustomAssembler%d' % i for i in range(len(vfs)))

    code = codegen.CodeGen()
    for (name, vf) in zip(names, vfs):
        codegen.AsmGenerator(vf, name, code).generate()
    src = codegen.preamble() + '\n' + code.result()

    mod = compile_cython_module(src, verbose=verbose)
    return tuple(getattr(mod, name) for name in names)
Example #3
0
if __name__ == '__main__':
    _args = parse_args()

    vf = vform.VForm(dim=_args.dim)
    u, v = vf.basisfuns()

    # create scalar input fields
    if _args.scalarinput:
        for funcname in _args.scalarinput:
            locals()[funcname] = vf.input(funcname)

    # create vector input fields
    if _args.vectorinput:
        for funcname in _args.vectorinput:
            locals()[funcname] = vf.input(funcname, shape=(_args.dim, ))

    e = eval(_args.expr, vars(vform), locals())
    if _args.dumptree:
        vform.tree_print(e)
    vf.add(e)

    code = backend.CodeGen()
    backend.AsmGenerator(vf, _args.name, code,
                         on_demand=_args.ondemand).generate()

    f = open(_args.output, 'w') if _args.output else None
    print(backend.preamble(), file=f)
    print(code.result(), file=f)
    if _args.output:
        f.close()
Example #4
0
def generate(vf, classname='CustomAssembler', on_demand=False):
    """Generate Cython code for an assembler class which implements the vform `vf`."""
    code = codegen.CodeGen()
    codegen.AsmGenerator(vf, classname, code, on_demand=on_demand).generate()
    return codegen.preamble() + '\n' + code.result()
Example #5
0
def test_codegen_wave_st2d():
    code = codegen.CodeGen()
    vf = vform.wave_st_vf(2)
    assert (not vf.vec) and vf.arity == 2 and vf.spacetime
    codegen.AsmGenerator(vf, 'TestAsm', code).generate()
    code = codegen.preamble() + '\n' + code.result()
Example #6
0
def test_codegen_vecfunctional():
    code = codegen.CodeGen()
    vf = vector_L2functional_vf(3)
    assert vf.vec == 3 and vf.arity == 1
    codegen.AsmGenerator(vf, 'TestAsm', code).generate()
    code = codegen.preamble() + '\n' + code.result()
Example #7
0
def test_codegen_functional():
    code = codegen.CodeGen()
    vf = vform.L2functional_vf(3, updatable=True)
    assert (not vf.vec) and vf.arity == 1
    codegen.AsmGenerator(vf, 'TestAsm', code).generate()
    code = codegen.preamble() + '\n' + code.result()
Example #8
0
def test_codegen_vectorlaplace2d():
    code = codegen.CodeGen()
    vf = vector_laplace_vf(2)
    assert vf.vec == 2 * 2 and vf.arity == 2
    codegen.AsmGenerator(vf, 'TestAsm', code).generate()
    code = codegen.preamble() + '\n' + code.result()
Example #9
0
def test_codegen_poisson3d():
    code = codegen.CodeGen()
    vf = my_stiffness_vf(3)
    assert (not vf.vec) and vf.arity == 2
    codegen.AsmGenerator(vf, 'TestAsm', code).generate()
    code = codegen.preamble() + '\n' + code.result()
Example #10
0
    def gen(vf, classname):
        backend.AsmGenerator(vf, classname, code).generate()

    nD = str(dim) + 'D'
    gen(vform.mass_vf(dim), 'MassAssembler' + nD)
    gen(vform.stiffness_vf(dim), 'StiffnessAssembler' + nD)
    gen(vform.heat_st_vf(dim), 'HeatAssembler_ST' + nD)
    gen(vform.wave_st_vf(dim), 'WaveAssembler_ST' + nD)
    gen(vform.divdiv_vf(dim), 'DivDivAssembler' + nD)
    gen(vform.L2functional_vf(dim), 'L2FunctionalAssembler' + nD)

    return code.result()


if __name__ == '__main__':
    if '--generic' in argv[1:]:
        path = os.path.join(os.path.dirname(__file__), "..", "pyiga",
                            "genericasm.pxi")
        with open(path, 'w') as f:
            f.write('# file generated by generate-assemblers.py\n')
            f.write(backend.generate_generic(dim=2))
            f.write(backend.generate_generic(dim=3))

    if not '--generic-only' in argv[1:]:
        path = os.path.join(os.path.dirname(__file__), "..", "pyiga",
                            "assemblers.pyx")
        with open(path, 'w') as f:
            f.write(backend.preamble())
            f.write(generate(dim=2))
            f.write(generate(dim=3))
Example #11
0
def generate(vf, classname='CustomAssembler'):
    code = codegen.CodeGen()
    codegen.AsmGenerator(vf, classname, code).generate()
    return codegen.preamble() + '\n' + code.result()