//! main constructor
    Panel(point_type p0, point_type p1, point_type p2) : BC(POTENTIAL) {
      vertices.resize(3);
      vertices[0] = p0;
      vertices[1] = p1;
      vertices[2] = p2;

      // get the center
      center = (p0+p1+p2)/3;

      // area & normal
      point_type L0 = p2-p0;
      point_type L1 = p1-p0;

      point_type c = point_type(L0[1]*L1[2]-L0[2]*L1[1],
                                -(L0[0]*L1[2]-L0[2]*L1[0]),
                                L0[0]*L1[1]-L0[1]*L1[0]);
      Area = 0.5*norm(c);
      normal = c/2/Area;

      // generate the quadrature points
      // assume K = 3 for now
      auto Config = BEMConfig::Instance();
      unsigned k = Config->getK();
      auto& points = Config->GaussPoints();
      quad_points.resize(k);
      // loop over K points performing matvecs
      for (unsigned i=0; i<k; i++) {
        double x = vertices[0][0]*points[i][0]+vertices[1][0]*points[i][1]+vertices[2][0]*points[i][2];
        double y = vertices[0][1]*points[i][0]+vertices[1][1]*points[i][1]+vertices[2][1]*points[i][2];
        double z = vertices[0][2]*points[i][0]+vertices[1][2]*points[i][1]+vertices[2][2]*points[i][2];

        quad_points[i] = point_type(x,y,z);
      }
    }
Exemplo n.º 2
0
/* Allocate memory for main structure and set initial conditions */
CELL *Init()
{
    void ReadInput();
    void InitCondEuler(REAL, REAL *);
    UINT i, j, k, l;
    REAL dx, U[NVAR], v;
    CELL *cell;

    ReadInput();

    /* Coefficients for RK3 */
    ark[0] = 0.0;
    ark[1] = 3.0 / 4.0;
    ark[2] = 1.0 / 3.0;

    brk[0] = 1.0;
    brk[1] = 1.0 / 4.0;
    brk[2] = 2.0 / 3.0;

    NG = PORD + 2;

    printf("Allocating memory and setting initial condition ...\n");

    cell = (CELL *) calloc(NC, sizeof(CELL));
    if(cell == NULL) {
        printf("Init: Could not allocate cell\n");
        exit(0);
    }

    dx = (xmax - xmin) / NC;
    printf("No of cells = %d\n", NC);
    printf("         dx = %f\n", dx);

    for(i = 0; i < NC; i++) {
        cell[i].xl = xmin + i * dx;
        cell[i].xr = cell[i].xl + dx;
        cell[i].x = 0.5 * (cell[i].xl + cell[i].xr);
        cell[i].h = cell[i].xr - cell[i].xl;


        cell[i].p = PORD;

        cell[i].ng = NG;
        cell[i].xg = (REAL *) calloc(cell[i].ng, sizeof(REAL));
        GaussPoints(&cell[i]);

        cell[i].Un = (REAL **) calloc(NVAR, sizeof(REAL *));
        cell[i].Uo = (REAL **) calloc(NVAR, sizeof(REAL *));
        cell[i].Re = (REAL **) calloc(NVAR, sizeof(REAL *));
        for(j = 0; j < NVAR; j++) {
            cell[i].Un[j] = (REAL *) calloc(cell[i].p, sizeof(REAL));
            cell[i].Uo[j] = (REAL *) calloc(cell[i].p, sizeof(REAL));
            cell[i].Re[j] = (REAL *) calloc(cell[i].p, sizeof(REAL));
        }
    }

    /* Set initial condition by L2 projection */
    for(i = 0; i < NC; i++) {

        for(j = 0; j < NVAR; j++)
            for(k = 0; k < cell[i].p; k++)
                cell[i].Un[j][k] = 0.0;

        for(j = 0; j < cell[i].p; j++)
            for(k = 0; k < cell[i].ng; k++) {
                InitCondEuler(cell[i].xg[k], U);
                v = ShapeFun(cell[i].xg[k], &cell[i], j);
                for(l = 0; l < NVAR; l++)
                    cell[i].Un[l][j] += 0.5 * U[l] * v * wg[cell[i].ng - 1][k];
            }
    }

    return cell;
}