Example #1
0
def integrate_assemble_p0(family, degree):
    power = 5
    m = UnitSquareMesh(2**power, 2**power)
    layers = 10

    # Populate the coordinates of the extruded mesh by providing the
    # coordinates as a field.
    # TODO: provide a kernel which will describe how coordinates are extruded.

    mesh = ExtrudedMesh(m, layers, layer_height=0.1)

    fs = FunctionSpace(mesh, family, degree, name="fs")

    f = Function(fs)

    fs1 = FunctionSpace(mesh, family, degree, name="fs1")

    f_rhs = Function(fs1)

    populate_p0 = op2.Kernel(
        """
void populate_tracer(double *x[], double *c[])
{
  x[0][0] = (c[1][2] + c[0][2]) / 2;
}""", "populate_tracer")

    coords = f.function_space().mesh().coordinates

    op2.par_loop(populate_p0, f.cell_set, f.dat(op2.INC, f.cell_node_map()),
                 coords.dat(op2.READ, coords.cell_node_map()))

    volume = op2.Kernel(
        """
void comp_vol(double *rhs[], double *x[], double *y[])
{
  double area = x[0][0]*(x[2][1]-x[4][1]) + x[2][0]*(x[4][1]-x[0][1])
               + x[4][0]*(x[0][1]-x[2][1]);
  if (area < 0)
    area = area * (-1.0);
  rhs[0][0] += 0.5 * area * (x[1][2] - x[0][2]) * y[0][0];
}""", "comp_vol")

    op2.par_loop(volume, f.cell_set, f_rhs.dat(op2.WRITE,
                                               f_rhs.cell_node_map()),
                 coords.dat(op2.READ, coords.cell_node_map()),
                 f.dat(op2.READ, f.cell_node_map()))

    g = op2.Global(1, data=0.0, name='g')

    reduction = op2.Kernel(
        """
void comp_reduction(double A[1], double *x[])
{
  A[0] += x[0][0];
}""", "comp_reduction")

    op2.par_loop(reduction, f_rhs.cell_set, g(op2.INC),
                 f_rhs.dat(op2.READ, f_rhs.cell_node_map()))

    return np.abs(g.data[0] - 0.5)
Example #2
0
def integrate_unit_square(family, degree):
    power = 5
    m = UnitIntervalMesh(2**power)
    layers = 10

    # Populate the coordinates of the extruded mesh by providing the
    # coordinates as a field.
    # A kernel which describes how coordinates are extruded.

    mesh = ExtrudedMesh(m, layers, layer_height=0.1)

    fs = FunctionSpace(mesh, family, degree, name="fs")

    f = Function(fs)

    area = op2.Kernel(
        """
void comp_area(double A[1], double *x[], double *y[])
{
  double area = (x[1][1]-x[0][1])*(x[2][0]-x[0][0]);
  if (area < 0)
    area = area * (-1.0);
  A[0] += area;
}""", "comp_area")

    g = op2.Global(1, data=0.0, name='g')

    coords = f.function_space().mesh().coordinates

    op2.par_loop(area, f.cell_set, g(op2.INC),
                 coords.dat(op2.READ, coords.cell_node_map()),
                 f.dat(op2.READ, f.cell_node_map()))

    return np.abs(g.data[0] - 1.0)
Example #3
0
def computeAvgHessian(meshd, sol, t, tIni, tEnd, nbrSpl, H, hessian, options) :
    
    print "DEBUG  hessian-metric assembly"; sys.stdout.flush()
    chrono1 = clock()

    mesh = meshd.mesh

    detMax = Function(meshd.V).interpolate(abs(det(H))).dat.data.max()   
    lbdmax = sqrt(detMax)
    lbdmin = 1.e-20 * lbdmax

    lbdMin = op2.Global(1, lbdmin, dtype=float);
    op2.par_loop(options.absValHessian_kernel, H.node_set().superset, H.dat(op2.RW), lbdMin(op2.READ))

    # sum with previous hessians
    # 3 cases: if t=tIni or tEnd or in between
    cof = float(tEnd-tIni)/(nbrSpl-1)
    if (t == tIni) or (t == tEnd) : cof *= 0.5
    hessian.dat.data[...] += cof*H.dat.data

    chrono2 = clock()
    print "DEBUG  end Hessian-metric assembly. Elapsed time: %1.2e" %(chrono2-chrono1); sys.stdout.flush()