Beispiel #1
0
void VectorFEBoundaryTangentLFIntegrator::AssembleRHSElementVect(
    const FiniteElement &el, ElementTransformation &Tr, Vector &elvect)
{
    int dof = el.GetDof();
    DenseMatrix vshape(dof, 2);
    Vector f_loc(3);
    Vector f_hat(2);

    elvect.SetSize(dof);
    elvect = 0.0;

    const IntegrationRule *ir = IntRule;
    if (ir == NULL)
    {
        int intorder = 2*el.GetOrder();  // <----------
        ir = &IntRules.Get(el.GetGeomType(), intorder);
    }

    for (int i = 0; i < ir->GetNPoints(); i++)
    {
        const IntegrationPoint &ip = ir->IntPoint(i);

        Tr.SetIntPoint(&ip);
        f.Eval(f_loc, Tr, ip);
        Tr.Jacobian().MultTranspose(f_loc, f_hat);
        el.CalcVShape(ip, vshape);

        Swap<double>(f_hat(0), f_hat(1));
        f_hat(0) = -f_hat(0);
        f_hat *= ip.weight;
        vshape.AddMult(f_hat, elvect);
    }
}
Beispiel #2
0
void steer(struct squadron *planes, int scout, int yank)
{
   register int p, k, n, s;
   int *table;
   char buf[128];
   int ran;
   struct torpedo *torp;

   for (; planes; planes = planes -> s_next) {
      table = yank ? japtable : amtable;
      for (k=0; table[k] < MAXSHIPS; k++) {
         if (shiplist[table[k]].hits && shiplist[table[k]].torps) {
            if ((ran = range(planes -> row, planes -> col, shiplist[table[k]].row, shiplist[table[k]].col)) < (scout ? 50 : 30)) {
               newbogey(table[k]);
               if (!scout && planes -> attack >= 0 && table[k] == shiplist[planes -> course].flagship) {
                  if (!planes -> attack) {
                     planes -> attack = 1;
                     sprintf(buf, "%s under attack", shiplist[table[k]].name);
                     inform(buf, 0);
                     for (p=table[k]; p < MAXSHIPS && shiplist[p].flagship == table[k]; p++)
                        sendcap(planes, p);
                  }
                  s = planes -> course = table[k];
                  if (s != player)
                     flack(aimflack(s, planes), s);
                  for (p=s+1; p < MAXSHIPS && shiplist[p].flagship == s; p++) {
                     if (p != player) {
                        if (rnd(2))
                           flack(aimflack(p, planes), p);
                        else
                           flack(intercept(p,s),p);
                     }
                  }
                  if (planes -> type == TBF) {
                     if (ran < 7) {
                        planes -> attack = -1;
                        for (n=0; n < planes -> planes; n++) {
                           if (!(torp = (struct torpedo *) calloc(1, sizeof(struct torpedo)))){
                              perror("calloc");
                              exit(1);
                           }
                           torp -> next_torp = yank ? amfish : japfish;
                           if (yank) amfish = torp;
                           else japfish = torp;
                           vshape(setcourse(planes, s), n - planes -> planes / 2, &torp -> row, &torp ->col);
                           torp -> row += planes -> row + rnd(3) - 1;
                           torp -> col += planes -> col + rnd(3) - 1;
                           torp -> fromship = planes -> from;
                           torp -> timeleft = 4 + rnd(12);
		           torp -> course = setcourse(planes, s);
                           if (!rnd(10))
                              torp -> course += rnd(5) -2;  /* a few duds */
                           planes -> course = planes -> from;
                           planes -> fuel = range(planes -> row, planes -> col, shiplist[planes -> from].row, shiplist[planes -> from].col)/10;
                        }
                     }
                  } else if (ran < 4) {
                     planes -> attack = -1;
                     planes -> course = planes -> from;
                     planes -> fuel = range(planes -> row, planes -> col, shiplist[planes -> from].row, shiplist[planes -> from].col)/10;
                     if (planes -> type == SBD) {
                        for (n=0; n < planes -> planes; n++) {
                           if (rnd(2)) {
                              sprintf(buf, "%s bombed.", shiplist[s].name);
                              inform(buf, 0);
                              shiplist[s].hits--;
                              shiplist[s].f4f -= shiplist[s].f4f/3;
                              shiplist[s].tbf -= shiplist[s].tbf/3;
                              shiplist[s].sbd -= shiplist[s].sbd/3;
                           }
                        }
                        plotsplash(shiplist[s].row, shiplist[s].col, '#');
                        if (shiplist[s].hits <= 0) {
                           shiplist[s].hits = 0;
                           sprintf(buf, "%s sinking!", shiplist[s].name);
                           inform(buf, 0);
                           shiplist[planes -> from].points += shiplist[s].value;
                           if (shiplist[s].flagship == s)
                              transferflag(s);
                           else if (s == player)
                              die();
                           break;
                        }
                     }
                  }
               }
            }
         }
      }

      if (!planes -> attack && planes -> fuel <= Fuel[planes -> type]/2) {
         planes -> attack = -1;   /* return home */
         if (scout) planes -> course = setcourse(planes, planes -> from);
         else
            planes -> course = planes -> from;
      }
      if (!scout && (!shiplist[planes -> course].hits || !shiplist[planes -> course].torps)) {
         if (planes -> course == planes -> from) {
            if (!Japanese(planes -> from))
               planes -> course = planes -> from = MIDWAY;
            else
               planes -> course = planes -> from = 22;   /* the Hiryu */
         } else {
            if (shiplist[shiplist[planes -> course].flagship].hits && shiplist[shiplist[planes -> course].flagship].torps) {
               planes -> course = shiplist[planes -> course].flagship;
            } else {
               planes -> course = planes -> from;
               planes -> attack = -1;
               planes -> fuel = range(planes -> row, planes -> col, shiplist[planes -> from].row, shiplist[planes -> from].col)/10;
            }
         }
      }
   }
}