Esempio n. 1
0
This is a demo of the use of ffc to generate kernels. It solves the identity
equation on a quadrilateral domain. It requires the pyop2 branch of ffc,
which can be obtained with:

bzr branch lp:~mapdes/ffc/pyop2

This may also depend on development trunk versions of other FEniCS programs.
"""

from pyop2 import op2, utils
from pyop2.ffc_interface import compile_form
from ufl import *
import ffc
import numpy as np

parser = utils.parser(group=True, description=__doc__)
parser.add_argument('-s', '--save-output',
                    action='store_true',
                    help='Save the output of the run (used for testing)')
opt = vars(parser.parse_args())
op2.init(**opt)

# Set up finite element identity problem

E = FiniteElement("Lagrange", "triangle", 1)

v = TestFunction(E)
u = TrialFunction(E)
f = Coefficient(E)

a = v*u*dx
Esempio n. 2
0
                         p_bound(op2.READ))

            # Update flow field
            rms = op2.Global(1, 0.0, np.double, "rms")
            op2.par_loop(update, cells,
                         p_qold(op2.READ),
                         p_q(op2.WRITE),
                         p_res(op2.RW),
                         p_adt(op2.READ),
                         rms(op2.INC))
        # Print iteration history
        rms = sqrt(rms.data / cells.size)
        if i % 100 == 0:
            print " %d  %10.5e " % (i, rms)

if __name__ == '__main__':
    parser = utils.parser(group=True, description="PyOP2 airfoil demo")
    parser.add_argument('-m', '--mesh', default='meshes/new_grid.h5',
                        help='HDF5 mesh file to use (default: meshes/new_grid.h5)')
    parser.add_argument('-p', '--profile', action='store_true',
                        help='Create a cProfile for the run')
    opt = vars(parser.parse_args())
    op2.init(**opt)

    if opt['profile']:
        import cProfile
        filename = 'airfoil.%s.cprofile' % os.path.split(opt['mesh'])[-1]
        cProfile.run('main(opt)', filename=filename)
    else:
        main(opt)
Esempio n. 3
0
            toc('diffusion')

    # Perform 1 iteration to warm up plan cache then reset initial condition
    timestep_iteration()
    op2.par_loop(i_cond, nodes, coords(op2.IdentityMap, op2.READ),
                 tracer(op2.IdentityMap, op2.WRITE))
    reset()

    # Timed iteration
    t1 = clock()
    while current_time < endtime:
        timestep_iteration()
        current_time += dt
    runtime = clock() - t1
    print "/fluidity :: %f" % runtime
    summary('profile_pyop2_%s_%s.csv' %
            (opt['mesh'].split('/')[-1], opt['backend']))


if __name__ == '__main__':
    from parameters import *
    parser = utils.parser(group=True,
                          description="PyOP2 P1 advection-diffusion demo")
    parser.add_argument(
        '-m',
        '--mesh',
        help=
        'Base name of triangle mesh (excluding the .ele or .node extension)')
    opt = vars(parser.parse_args())
    run(diffusivity, current_time, dt, endtime, **opt)
Esempio n. 4
0
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
"""PyOP2 Jacobi demo

Port of the Jacobi demo from OP2-Common.
"""

from pyop2 import op2, utils
import numpy as np
from math import sqrt

parser = utils.parser(group=True, description=__doc__)
parser.add_argument('-s',
                    '--single',
                    action='store_true',
                    help='single precision floating point mode')
parser.add_argument('-n',
                    '--niter',
                    action='store',
                    default=2,
                    type=int,
                    help='set the number of iteration')

opt = vars(parser.parse_args())
op2.init(**opt)

fp_type = np.float32 if opt['single'] else np.float64
Esempio n. 5
0
                         p_bound(op2.IdentityMap, op2.READ))

            # Update flow field
            rms = op2.Global(1, 0.0, np.double, "rms")
            op2.par_loop(update, cells,
                         p_qold(op2.IdentityMap, op2.READ),
                         p_q   (op2.IdentityMap, op2.WRITE),
                         p_res (op2.IdentityMap, op2.RW),
                         p_adt (op2.IdentityMap, op2.READ),
                         rms(op2.INC))
        # Print iteration history
        rms = sqrt(rms.data/cells.size)
        if i%100 == 0:
            print " %d  %10.5e " % (i, rms)

if __name__ == '__main__':
    parser = utils.parser(group=True, description="PyOP2 airfoil demo (vector map version)")
    parser.add_argument('-m', '--mesh', default='meshes/new_grid.h5',
                        help='HDF5 mesh file to use (default: meshes/new_grid.h5)')
    parser.add_argument('-p', '--profile', action='store_true',
                        help='Create a cProfile for the run')
    opt = vars(parser.parse_args())
    op2.init(**opt)

    if opt['profile']:
        import cProfile
        filename = 'adv_diff.%s.cprofile' % os.path.split(opt['mesh'])[-1]
        cProfile.run('main(opt)', filename=filename)
    else:
        main(opt)
Esempio n. 6
0
"""
This demo verifies that the integral of a unit cube is 1.

The cube will be unstructured in the 2D plane and structured vertically.
"""

from pyop2 import op2, utils
from triangle_reader import read_triangle
from ufl import *
from pyop2.computeind import compute_ind_extr

import numpy as np
import time

parser = utils.parser(group=True, description="PyOP2 2D mass equation demo")
parser.add_argument('-m', '--mesh', action='store', type=str, required=True,
                    help='Base name of triangle mesh \
                          (excluding the .ele or .node extension)')
parser.add_argument('-ll', '--layers', action='store', type=str, required=True,
                    help='Number of extruded layers.')
parser.add_argument('-p', '--partsize', action='store', type=str,
                    required=False, default=1024,
                    help='Partition size in the base mesh.')
opt = vars(parser.parse_args())
op2.init(**opt)
mesh_name = opt['mesh']
layers = int(opt['layers'])
partition_size = int(opt['partsize'])

# Generate code for kernel
Esempio n. 7
0
# OF THE POSSIBILITY OF SUCH DAMAGE.
"""
This demo verifies that the integral of a unit cube is 1.

The cube will be unstructured in the 2D plane and structured vertically.
"""

from pyop2 import op2, utils
from triangle_reader import read_triangle
from ufl import *
from pyop2.computeind import compute_ind_extr

import numpy as np
import time

parser = utils.parser(group=True, description="PyOP2 2D mass equation demo")
parser.add_argument('-m',
                    '--mesh',
                    action='store',
                    type=str,
                    required=True,
                    help='Base name of triangle mesh \
                          (excluding the .ele or .node extension)')
parser.add_argument('-ll',
                    '--layers',
                    action='store',
                    type=str,
                    required=True,
                    help='Number of extruded layers.')
parser.add_argument('-p',
                    '--partsize',
Esempio n. 8
0
            # Update flow field
            rms = op2.Global(1, 0.0, np.double, "rms")
            op2.par_loop(update, cells,
                         p_qold(op2.READ),
                         p_q(op2.WRITE),
                         p_res(op2.RW),
                         p_adt(op2.READ),
                         rms(op2.INC))
        # Print iteration history
        rms = sqrt(rms.data / cells.size)
        if i % 100 == 0:
            print " %d  %10.5e " % (i, rms)

if __name__ == '__main__':
    parser = utils.parser(group=True,
                          description="PyOP2 airfoil demo (vector map version)")
    parser.add_argument('-m', '--mesh', default='meshes/new_grid.h5',
                        help='HDF5 mesh file to use (default: meshes/new_grid.h5)')
    parser.add_argument('-p', '--profile', action='store_true',
                        help='Create a cProfile for the run')
    opt = vars(parser.parse_args())
    op2.init(**opt)

    if opt['profile']:
        import cProfile
        filename = 'adv_diff.%s.cprofile' % os.path.split(opt['mesh'])[-1]
        cProfile.run('main(opt)', filename=filename)
    else:
        main(opt)
Esempio n. 9
0
                         p_bound(op2.READ))

            # Update flow field
            rms = op2.Global(1, 0.0, np.double, "rms")
            op2.par_loop(update, cells,
                         p_qold(op2.READ),
                         p_q(op2.WRITE),
                         p_res(op2.RW),
                         p_adt(op2.READ),
                         rms(op2.INC))
        # Print iteration history
        rms = sqrt(rms.data / cells.size)
        if i % 100 == 0:
            print " %d  %10.5e " % (i, rms)

if __name__ == '__main__':
    parser = utils.parser(group=True, description="PyOP2 airfoil demo")
    parser.add_argument('-m', '--mesh', default='meshes/new_grid.h5',
                        help='HDF5 mesh file to use (default: meshes/new_grid.h5)')
    parser.add_argument('-p', '--profile', action='store_true',
                        help='Create a cProfile for the run')
    opt = vars(parser.parse_args())
    op2.init(**opt)

    if opt['profile']:
        import cProfile
        filename = 'airfoil.%s.cprofile' % os.path.split(opt['mesh'])[-1]
        cProfile.run('main(opt)', filename=filename)
    else:
        main(opt)
Esempio n. 10
0
            )

            toc("assembly")
            tic("solve")
            op2.solve(mat, tracer, b)
            toc("solve")
            toc("diffusion")

    # Perform 1 iteration to warm up plan cache then reset initial condition
    timestep_iteration()
    op2.par_loop(i_cond, nodes, coords(op2.IdentityMap, op2.READ), tracer(op2.IdentityMap, op2.WRITE))
    reset()

    # Timed iteration
    t1 = clock()
    while current_time < endtime:
        timestep_iteration()
        current_time += dt
    runtime = clock() - t1
    print "/fluidity :: %f" % runtime
    summary("profile_pyop2_%s_%s.csv" % (opt["mesh"].split("/")[-1], opt["backend"]))


if __name__ == "__main__":
    from parameters import *

    parser = utils.parser(group=True, description="PyOP2 P1 advection-diffusion demo")
    parser.add_argument("-m", "--mesh", help="Base name of triangle mesh (excluding the .ele or .node extension)")
    opt = vars(parser.parse_args())
    run(diffusivity, current_time, dt, endtime, **opt)