Пример #1
0
void
ppbuiltin(void)
{
	register int		c;
	register char*		p;
	register char*		a;

	int			n;
	int			op;
	char*			token;
	char*			t;
	long			number;
	long			onumber;
	struct ppinstk*		in;
	struct pplist*		list;
	struct ppsymbol*	sym;
	Sfio_t*			sp;

	number = pp.state;
	pp.state |= DISABLE|FILEPOP|NOSPACE;
	token = pp.token;
	p = pp.token = pp.tmpbuf;
	*(a = pp.args) = 0;
	if ((c = pplex()) != T_ID)
	{
		error(2, "%s: #(<identifier>...) expected", p);
		*p = 0;
	}
	switch (op = (int)hashget(pp.strtab, p))
	{
	case V_DEFAULT:
		n = 0;
		p = pp.token = pp.valbuf;
		if ((c = pplex()) == ',')
		{
			op = -1;
			c = pplex();
		}
		pp.state &= ~NOSPACE;
		for (;;)
		{
			if (!c)
			{
				error(2, "%s in #(...) argument", pptokchr(c));
				break;
			}
			if (c == '(') n++;
			else if (c == ')' && !n--) break;
			else if (c == ',' && !n && op > 0) op = 0;
			if (op) pp.token = pp.toknxt;
			c = pplex();
		}
		*pp.token = 0;
		pp.token = token;
		pp.state = number;
		break;
	case V_EMPTY:
		p = pp.valbuf;
		if ((c = pplex()) == ')') *p = '1';
		else
		{
			*p = '0';
			n = 0;
			for (;;)
			{
				if (!c)
				{
					error(2, "%s in #(...) argument", pptokchr(c));
					break;
				}
				if (c == '(') n++;
				else if (c == ')' && !n--) break;
				c = pplex();
			}
		}
		*(p + 1) = 0;
		pp.token = token;
		pp.state = number;
		break;
	case V_ITERATE:
		n = 0;
		pp.token = pp.valbuf;
		if ((c = pplex()) != T_ID || !(sym = ppsymref(pp.symtab, pp.token)) || !sym->macro || sym->macro->arity != 1 || (c = pplex()) != ',')
		{
			error(2, "#(%s <macro(x)>, ...) expected", p);
			for (;;)
			{
				if (!c)
				{
					error(2, "%s in #(...) argument", pptokchr(c));
					break;
				}
				if (c == '(') n++;
				else if (c == ')' && !n--) break;
				c = pplex();
			}
			*pp.valbuf = 0;
		}
		else while (c != ')')
		{
			p = pp.token;
			if (pp.token > pp.valbuf) *pp.token++ = ' ';
			STRCOPY(pp.token, sym->name, a);
			*pp.token++ = '(';
			if (!c || !(c = pplex()))
			{
				pp.token = p;
				error(2, "%s in #(...) argument", pptokchr(c));
				break;
			}
			pp.state &= ~NOSPACE;
			while (c)
			{
				if (c == '(') n++;
				else if (c == ')' && !n--) break;
				else if (c == ',' && !n) break;
				pp.token = pp.toknxt;
				c = pplex();
			}
			*pp.token++ = ')';
			pp.state |= NOSPACE;
		}
		p = pp.valbuf;
		pp.token = token;
		pp.state = number;
		break;
	default:
		pp.token = token;
		while (c != ')')
		{
			if (!c)
			{
				error(2, "%s in #(...) argument", pptokchr(c));
				break;
			}
			if ((c = pplex()) == T_ID && !*a)
				strcpy(a, pp.token);
		}
		pp.state = number;
		switch (op)
		{
		case V_ARGC:
			c = -1;
			for (in = pp.in; in; in = in->prev)
				if ((in->type == IN_MACRO || in->type == IN_MULTILINE) && (in->symbol->flags & SYM_FUNCTION))
				{
					c = *((unsigned char*)(pp.macp->arg[0] - 2));
					break;
				}
			sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", c);
			break;
		case V_BASE:
			p = (a = strrchr(error_info.file, '/')) ? a + 1 : error_info.file;
			break;
		case V_DATE:
			if (!(p = pp.date))
			{
				time_t	tm;

				time(&tm);
				a = p = ctime(&tm) + 4;
				*(p + 20) = 0;
				for (p += 7; *p = *(p + 9); p++);
				pp.date = p = strdup(a);
			}
			break;
		case V_FILE:
			p = error_info.file;
			break;
		case V_LINE:
			sfsprintf(p = pp.valbuf, MAXTOKEN, "%d", error_info.line);
			break;
		case V_PATH:
			p = pp.path;
			break;
		case V_SOURCE:
			p = error_info.file;
			for (in = pp.in; in->prev; in = in->prev)
				if (in->prev->type == IN_FILE && in->file)
					p = in->file;
			break;
		case V_STDC:
			p = pp.valbuf;
			p[0] = ((pp.state & (COMPATIBILITY|TRANSITION)) || (pp.mode & (HOSTED|HOSTEDTRANSITION)) == (HOSTED|HOSTEDTRANSITION)) ? '0' : '1';
			p[1] = 0;
			break;
		case V_TIME:
			if (!(p = pp.time))
			{
				time_t	tm;

				time(&tm);
				p = ctime(&tm) + 11;
				*(p + 8) = 0;
				pp.time = p = strdup(p);
			}
			break;
		case V_VERSION:
			p = (char*)pp.version;
			break;
		case V_DIRECTIVE:
			pp.state |= NEWLINE;
			pp.mode |= RELAX;
			strcpy(p = pp.valbuf, "#");
			break;
		case V_GETENV:
			if (!(p = getenv(a))) p = "";
			break;
		case V_GETMAC:
			p = (sym = pprefmac(a, REF_NORMAL)) ? sym->macro->value : "";
			break;
		case V_GETOPT:
			sfsprintf(p = pp.valbuf, MAXTOKEN, "%ld", ppoption(a));
			break;
		case V_GETPRD:
			p = (list = (struct pplist*)hashget(pp.prdtab, a)) ? list->value : "";
			break;
		case V__PRAGMA:
			if ((c = pplex()) == '(')
			{
				number = pp.state;
				pp.state |= NOSPACE|STRIP;
				c = pplex();
				pp.state = number;
				if (c == T_STRING || c == T_WSTRING)
				{
					if (!(sp = sfstropen()))
						error(3, "temporary buffer allocation error");
					sfprintf(sp, "#%s %s\n", dirname(PRAGMA), pp.token);
					a = sfstruse(sp);
					if ((c = pplex()) == ')')
					{
						pp.state |= NEWLINE;
						PUSH_BUFFER(p, a, 1);
					}
					sfstrclose(sp);
				}
			}
			if (c != ')')
				error(2, "%s: (\"...\") expected", p);
			return;
		case V_FUNCTION:

#define BACK(a,p)	((a>p)?*--a:(number++?0:((p=pp.outbuf+PPBUFSIZ),(a=pp.outbuf+2*PPBUFSIZ),*--a)))
#define PEEK(a,p)	((a>p)?*(a-1):(number?0:*(pp.outbuf+2*PPBUFSIZ-1)))

			number = pp.outbuf != pp.outb;
			a = pp.outp;
			p = pp.outb;
			op = 0;
			while (c = BACK(a, p))
			{
				if (c == '"' || c == '\'')
				{
					op = 0;
					while ((n = BACK(a, p)) && n != c || PEEK(a, p) == '\\');
				}
				else if (c == '\n')
				{
					token = a;
					while (c = BACK(a, p))
						if (c == '\n')
						{
							a = token;
							break;
						}
						else if (c == '#' && PEEK(a, p) == '\n')
							break;
				}
				else if (c == ' ')
					/*ignore*/;
				else if (c == '{') /* '}' */
					op = 1;
				else if (op == 1)
				{
					if (c == ')')
					{
						op = 2;
						n = 1;
					}
					else
						op = 0;
				}
				else if (op == 2)
				{
					if (c == ')')
						n++;
					else if (c == '(' && !--n)
						op = 3;
				}
				else if (op == 3)
				{
					if (ppisidig(c))
					{
						for (t = p, token = a, onumber = number; ppisidig(PEEK(a, p)) && a >= p; BACK(a, p));
						p = pp.valbuf + 1;
						if (a > token)
						{
							for (; a < pp.outbuf+2*PPBUFSIZ; *p++ = *a++);
							a = pp.outbuf;
						}
						for (; a <= token; *p++ = *a++);
						*p = 0;
						p = pp.valbuf + 1;
						if (streq(p, "for") || streq(p, "if") || streq(p, "switch") || streq(p, "while"))
						{
							op = 0;
							p = t;
							number = onumber;
							continue;
						}
					}
					else
						op = 0;
					break;
				}
			}
			if (op == 3)
				p = strncpy(pp.funbuf, p, sizeof(pp.funbuf) - 1);
			else if (*pp.funbuf)
				p = pp.funbuf;
			else
				p = "__FUNCTION__";
			break;
		default:
			if (pp.builtin && (a = (*pp.builtin)(pp.valbuf, p, a)))
				p = a;
			break;
		}
		break;
	}
	if (strchr(p, MARK))
	{
		a = pp.tmpbuf;
		strcpy(a, p);
		c = p != pp.valbuf;
		p = pp.valbuf + c;
		for (;;)
		{
			if (p < pp.valbuf + MAXTOKEN - 2)
				switch (*p++ = *a++)
				{
				case 0:
					break;
				case MARK:
					*p++ = MARK;
					/*FALLTHROUGH*/
				default:
					continue;
				}
			break;
		}
		p = pp.valbuf + c;
	}
	if (p == pp.valbuf)
		PUSH_STRING(p);
	else
	{
		if (p == pp.valbuf + 1)
			*pp.valbuf = '"';
		else
		{
			if (strlen(p) > MAXTOKEN - 2)
				error(1, "%-.16s: builtin value truncated", p);
			sfsprintf(pp.valbuf, MAXTOKEN, "\"%-.*s", MAXTOKEN - 2, p);
		}
		PUSH_QUOTE(pp.valbuf, 1);
	}
}
Пример #2
0
/*
 - step - map set of states reachable before char to set reachable after
 == static states step(struct re_guts *g, sopno start, sopno stop, \
 ==	states bef, int ch, states aft);
 == #define	BOL	(OUT-1)
 == #define	EOL	(BOL-1)
 == #define	BOLEOL	(BOL-2)
 == #define	NOTHING	(BOL-3)
 == #define	BOW	(BOL-4)
 == #define	EOW	(BOL-5)
 == #define	BADCHAR	(BOL-6)
 == #define	NONCHAR(c)	((c) <= OUT)
 */
static states
step(struct re_guts *g,
	sopno start,		/* start state within strip */
	sopno stop,		/* state after stop state within strip */
	states bef,		/* states reachable before */
	wint_t ch,		/* character or NONCHAR code */
	states aft)		/* states already known reachable after */
{
	cset *cs;
	sop s;
	sopno pc;
	onestate here;		/* note, macros know this name */
	sopno look;
	int i;

	for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
		s = g->strip[pc];
		switch (OP(s)) {
		case OEND:
			assert(pc == stop-1);
			break;
		case OCHAR:
			/* only characters can match */
			assert(!NONCHAR(ch) || ch != OPND(s));
			if (ch == OPND(s))
				FWD(aft, bef, 1);
			break;
		case OBOL:
			if (ch == BOL || ch == BOLEOL)
				FWD(aft, bef, 1);
			break;
		case OEOL:
			if (ch == EOL || ch == BOLEOL)
				FWD(aft, bef, 1);
			break;
		case OBOW:
			if (ch == BOW)
				FWD(aft, bef, 1);
			break;
		case OEOW:
			if (ch == EOW)
				FWD(aft, bef, 1);
			break;
		case OANY:
			if (!NONCHAR(ch))
				FWD(aft, bef, 1);
			break;
		case OANYOF:
			cs = &g->sets[OPND(s)];
			if (!NONCHAR(ch) && CHIN(cs, ch))
				FWD(aft, bef, 1);
			break;
		case OBACK_:		/* ignored here */
		case O_BACK:
			FWD(aft, aft, 1);
			break;
		case OPLUS_:		/* forward, this is just an empty */
			FWD(aft, aft, 1);
			break;
		case O_PLUS:		/* both forward and back */
			FWD(aft, aft, 1);
			i = ISSETBACK(aft, OPND(s));
			BACK(aft, aft, OPND(s));
			if (!i && ISSETBACK(aft, OPND(s))) {
				/* oho, must reconsider loop body */
				pc -= OPND(s) + 1;
				INIT(here, pc);
			}
			break;
		case OQUEST_:		/* two branches, both forward */
			FWD(aft, aft, 1);
			FWD(aft, aft, OPND(s));
			break;
		case O_QUEST:		/* just an empty */
			FWD(aft, aft, 1);
			break;
		case OLPAREN:		/* not significant here */
		case ORPAREN:
			FWD(aft, aft, 1);
			break;
		case OCH_:		/* mark the first two branches */
			FWD(aft, aft, 1);
			assert(OP(g->strip[pc+OPND(s)]) == OOR2);
			FWD(aft, aft, OPND(s));
			break;
		case OOR1:		/* done a branch, find the O_CH */
			if (ISSTATEIN(aft, here)) {
				for (look = 1;
						OP(s = g->strip[pc+look]) != O_CH;
						look += OPND(s))
					assert(OP(s) == OOR2);
				FWD(aft, aft, look);
			}
			break;
		case OOR2:		/* propagate OCH_'s marking */
			FWD(aft, aft, 1);
			if (OP(g->strip[pc+OPND(s)]) != O_CH) {
				assert(OP(g->strip[pc+OPND(s)]) == OOR2);
				FWD(aft, aft, OPND(s));
			}
			break;
		case O_CH:		/* just empty */
			FWD(aft, aft, 1);
			break;
		default:		/* ooooops... */
			assert(nope);
			break;
		}
	}

	return(aft);
}
Пример #3
0
task main()
{
  bMotorFlippedMode[port6] = 1;
  bMotorFlippedMode[port1] = 1;
  wait1Msec(2000);

  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

  while(SensorValue[RightEncoder] > -1500 )
  {
  	if(SensorValue[RightEncoder] > -1490 )
  	{
  		GO(122);
  	}
  	else
  	{
  		GO(0);
  	}
  }
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

  while(SensorValue[RightEncoder] > -355 )
  {
  	if(SensorValue[RightEncoder] > -350 )
  	{
  		TURNLEFT(127);
  	}
  	else
  	{
  		GO(0);
  	}
  }
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

  while(SensorValue[Pot] > 460  )
  {
  	if(SensorValue[Pot] > 450 )
  	{
  		LIFTUP(127);
  	}
  }

  LIFTUP(0);
	wait1Msec(1000);


  while(SensorValue[RightEncoder] > -135 )
  {
  	if(SensorValue[RightEncoder] > -130 )
  	{
  		GO(71);
  	}
  	else
  	{
  		GO(0);
  	}
  }
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

  LIFTUP(0);
	wait1Msec(1000);

  GRAB(127);
	wait1Msec(1000);

	GRAB(0);
	wait1Msec(2000);

	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	while(SensorValue[RightEncoder] < 410 )
	{
		if(SensorValue[RightEncoder] < 405 )
		{
			BACK(87);
		}
		else
		{
			GO(0);
		}
	}

	while (SensorValue[Pot] < 625 )
	{
		if(SensorValue[Pot] < 620 )
		{
			LIFTDOWN(105);
		}
	}

	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

  while(SensorValue[RightEncoder] < 285 )
	{
		if(SensorValue[RightEncoder] < 280 )
		{
		  TURNRIGHT(57);
		}
		else
		{
			GO(0);
		}
	}
	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	while (SensorValue[Pot] > 500 )
	{
		if(SensorValue[Pot] > 500 )
		{
			LIFTUP(103);
		}
	}

  {
	  LIFTDOWN(0);
	  wait1Msec(1000);
	}


	while(SensorValue[RightEncoder] > -435 )
	{
		if(SensorValue[RightEncoder] > -430 )
		{
			GO(58);
		}
		else
		{
			GO(0);
		}
	}
	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	LIFTDOWN(0);
	wait1Msec(1000);

	GRAB(127);
	wait1Msec(1000);

	GRAB(0);
	wait1Msec(2000);

	while(SensorValue[RightEncoder] < 385 )
	{
		if(SensorValue[RightEncoder] < 380 )
		{
			BACK(127);
		}
		else
		{
			GO(0);
		}
	}
	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	while(SensorValue[RightEncoder] < 405 )
	{
		if(SensorValue[RightEncoder] < 400 )
		{
			TURNRIGHT(127);
		}
		else
		{
			GO(0);
		}
	}
	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	while(SensorValue[RightEncoder] > -1095 )
	{
		if(SensorValue[RightEncoder] > -1090 )
		{
			GO(127);
		}
		else
		{
			GO(0);
		}
	}
	SensorValue[LeftEncoder] = 0;
	SensorValue[RightEncoder] = 0;

	while(SensorValue[RightEncoder] > -300 )
  {
  	if(SensorValue[RightEncoder] > -295 )
  	{
  		TURNLEFT(127);
  	}
  	else
  	{
  		GO(0);
  	}
  }
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

  while(SensorValue[RightEncoder] > -335 )
  {
  	if(SensorValue[RightEncoder] > -330 )
  	{
  		GO(58);
  	}
  	else
  	{
  		GO(0);
  	}
  }
  SensorValue[LeftEncoder] = 0;
  SensorValue[RightEncoder] = 0;

	bVexAutonomousMode = false;

	while(true)
	{
		motor[port1] = vexRT[Ch5];
		motor[port2] = vexRT[Ch1] + vexRT[Ch2];
		motor[port3] = vexRT[Ch1] - vexRT[Ch2];
		motor[port4] = vexRT[Ch3];
		motor[port5] = vexRT[Ch5];
		motor[port6] = vexRT[Ch3];
		motor[port7] = vexRT[Ch1] + vexRT[Ch2];
		motor[port8] = vexRT[Ch1] - vexRT[Ch2];
	}
}
Пример #4
0
void generateBlocked(MatGenFD mg, HYPRE_Int *rp, HYPRE_Int *cval, double *aval, Mat_dh A, Vec_dh b)
{
  START_FUNC_DH
  bool applyBdry = true;
  double *stencil = mg->stencil;
  HYPRE_Int id = mg->id;
  bool threeD = mg->threeD;
  HYPRE_Int px = mg->px, py = mg->py, pz = mg->pz; /* processor grid dimensions */
  HYPRE_Int p, q, r; /* this proc's position in processor grid */
  HYPRE_Int cc = mg->cc; /* local grid dimension (grid of unknowns) */
  HYPRE_Int nx = cc, ny = cc, nz = cc;
  HYPRE_Int lowerx, upperx, lowery, uppery, lowerz, upperz;
  HYPRE_Int startRow;
  HYPRE_Int x, y, z;
  bool debug = false;
  HYPRE_Int idx = 0, localRow = 0; /* nabor; */
  HYPRE_Int naborx1, naborx2, nabory1, nabory2, naborz1, naborz2;
  double *rhs;

  double hhalf = 0.5 * mg->hh;
  double bcx1 = mg->bcX1;
  double bcx2 = mg->bcX2;
  double bcy1 = mg->bcY1;
  double bcy2 = mg->bcY2;
  /* double bcz1 = mg->bcZ1; */
  /* double bcz2 = mg->bcZ2; */

  Vec_dhInit(b, A->m); CHECK_V_ERROR;
  rhs = b->vals;

  if (mg->debug && logFile != NULL) debug = true;
  if (! threeD) nz = 1;

  /* compute p,q,r from P,Q,R and myid */
  p = id % px;
  q = (( id - p)/px) % py;
  r = ( id - p - px*q)/( px*py );

  if (debug) {
    hypre_sprintf(msgBuf_dh, "this proc's position in subdomain grid: p= %i  q= %i  r= %i", p,q,r);
    SET_INFO(msgBuf_dh);
  }

   /* compute ilower and iupper from p,q,r and nx,ny,nz */
   /* zero-based */

   lowerx = nx*p;
   upperx = lowerx + nx;
   lowery = ny*q;
   uppery = lowery + ny;
   lowerz = nz*r;
   upperz = lowerz + nz;

  if (debug) {
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowerx= %i  upperx= %i", lowerx, upperx);
    SET_INFO(msgBuf_dh);
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowery= %i  uppery= %i", lowery, uppery);
    SET_INFO(msgBuf_dh);
    hypre_sprintf(msgBuf_dh, "local grid parameters: lowerz= %i  upperz= %i", lowerz, upperz);
    SET_INFO(msgBuf_dh);
  }

  startRow = mg->first;
  rp[0] = 0;

  for (z=lowerz; z<upperz; z++) {
    for (y=lowery; y<uppery; y++) {
      for (x=lowerx; x<upperx; x++) {

        if (debug) {
          hypre_fprintf(logFile, "row= %i  x= %i  y= %i  z= %i\n", localRow+startRow+1, x, y, z);
        }

        /* compute row values and rhs, at the current node */
        getstencil(mg,x,y,z);

        /* down plane */
        if (threeD) {
          if (z > 0) {
            naborz1 = rownum(threeD, x,y,z-1,nx,ny,nz,px,py);
            cval[idx]   = naborz1;
            aval[idx++] = FRONT(stencil);
          }
        }

        /* south */
        if (y > 0) {
          nabory1 = rownum(threeD, x,y-1,z,nx,ny,nz,px,py);
          cval[idx]   = nabory1;
          aval[idx++] = SOUTH(stencil);
        }

        /* west */
        if (x > 0) {
          naborx1 = rownum(threeD, x-1,y,z,nx,ny,nz,px,py);
          cval[idx]   = naborx1;
          aval[idx++] = WEST(stencil);
/*hypre_fprintf(logFile, "--- row: %i;  naborx1= %i\n", localRow+startRow+1, 1+naborx1);
*/
        }
/*
else {
hypre_fprintf(logFile, "--- row: %i;  x >= nx*px-1; naborx1 has old value: %i\n", localRow+startRow+1,1+naborx1);
}
*/

        /* center node */
        cval[idx]   = localRow+startRow;
        aval[idx++] = CENTER(stencil);


        /* east */
        if (x < nx*px-1) {
          naborx2 = rownum(threeD,x+1,y,z,nx,ny,nz,px,py);
          cval[idx]   = naborx2;
          aval[idx++] = EAST(stencil);
        }
/*
else {
hypre_fprintf(logFile, "--- row: %i;  x >= nx*px-1; nobors2 has old value: %i\n", localRow+startRow,1+naborx2);
}
*/

        /* north */
        if (y < ny*py-1) {
          nabory2 = rownum(threeD,x,y+1,z,nx,ny,nz,px,py);
          cval[idx]   = nabory2;
          aval[idx++] = NORTH(stencil);
        }

        /* up plane */
        if (threeD) {
          if (z < nz*pz-1) {
            naborz2 = rownum(threeD,x,y,z+1,nx,ny,nz,px,py);
            cval[idx]   = naborz2;
            aval[idx++] = BACK(stencil);
          }
        }

       /* rhs[rhsIdx++] = RHS(stencil); */
       rhs[localRow] = 0.0;

       ++localRow;
       rp[localRow] = idx; 

       /* apply boundary conditions; only for 2D! */
       if (!threeD && applyBdry) {
         HYPRE_Int globalRow = localRow+startRow-1;
         HYPRE_Int offset = rp[localRow-1];
         HYPRE_Int len = rp[localRow] - rp[localRow-1];
         double ctr, coeff;

/* hypre_fprintf(logFile, "globalRow = %i; naborx2 = %i\n", globalRow+1, naborx2+1); */

         if (x == 0) {         /* if x1 */
           coeff = mg->A(mg->a, x+hhalf,y,z);
           ctr   = mg->A(mg->a, x-hhalf,y,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx1, coeff, ctr, naborx2);
         } else if (x == nx*px-1) {  /* if x2 */
           coeff = mg->A(mg->a, x-hhalf,y,z);
           ctr   = mg->A(mg->a, x+hhalf,y,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx2, coeff, ctr, naborx1);
         } else if (y == 0) {  /* if y1 */
           coeff = mg->B(mg->b, x, y+hhalf,z);
           ctr   = mg->B(mg->b, x, y-hhalf,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, nabory2);
         } else if (y == ny*py-1) {        /* if y2 */
           coeff = mg->B(mg->b, x, y-hhalf,z);
           ctr   = mg->B(mg->b, x, y+hhalf,z);
           setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy2, coeff, ctr, nabory1);
         } else if (threeD) {
           if (z == 0) {
             coeff = mg->B(mg->b, x, y, z+hhalf);
             ctr   = mg->B(mg->b, x, y, z-hhalf);
             setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, naborz2);
           } else if (z == nz*nx-1) {
             coeff = mg->B(mg->b, x, y, z-hhalf);
             ctr   = mg->B(mg->b, x, y, z+hhalf);
             setBoundary_private(globalRow, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, naborz1);
           }
         }
       }
      }
    }
  }
  END_FUNC_DH
}
Пример #5
0
void getstencil(MatGenFD g, HYPRE_Int ix, HYPRE_Int iy, HYPRE_Int iz)
{
  HYPRE_Int k; 
  double h = g->hh;
  double hhalf = h*0.5;
  double x = h*ix;
  double y = h*iy;
  double z = h*iz;
  double cntr = 0.0;
  double *stencil = g->stencil;
  double coeff;
  bool threeD = g->threeD;

  for (k=0; k<8; ++k) stencil[k] = 0.0;

  /* differentiation wrt x */
  coeff = g->A(g->a, x+hhalf,y,z);
  EAST(stencil) += coeff;
  cntr += coeff;

  coeff = g->A(g->a, x-hhalf,y,z);
  WEST(stencil) += coeff;
  cntr += coeff;

  coeff = g->D(g->d, x,y,z)*hhalf;
  EAST(stencil) += coeff;
  WEST(stencil) -= coeff;

  /* differentiation wrt y */
  coeff = g->B(g->b,x,y+hhalf,z);
  NORTH(stencil) += coeff;
  cntr += coeff;

  coeff = g->B(g->b,x,y-hhalf,z);
  SOUTH(stencil) += coeff;
  cntr += coeff;

  coeff = g->E(g->e,x,y,z)*hhalf;
  NORTH(stencil) += coeff;
  SOUTH(stencil) -= coeff;

  /* differentiation wrt z */
  if (threeD) {
    coeff = g->C(g->c,x,y,z+hhalf);
    BACK(stencil) += coeff;
    cntr += coeff;

    coeff = g->C(g->c,x,y,z-hhalf);
    FRONT(stencil) += coeff;
    cntr += coeff;

    coeff = g->F(g->f,x,y,z)*hhalf;
    BACK(stencil) += coeff;
    FRONT(stencil) -= coeff;
  }

  /* contribution from function G: */
  coeff = g->G(g->g,x,y,z);
  CENTER(stencil) = h*h*coeff - cntr;

  RHS(stencil) = h*h*g->H(g->h,x,y,z);
}
Пример #6
0
void generateStriped(MatGenFD mg, HYPRE_Int *rp, HYPRE_Int *cval, double *aval, Mat_dh A, Vec_dh b)
{
  START_FUNC_DH
  HYPRE_Int mGlobal;
  HYPRE_Int m = mg->m;
  HYPRE_Int beg_row, end_row;
  HYPRE_Int i, j, k, row;
  bool threeD = mg->threeD;
  HYPRE_Int idx = 0;
  double *stencil = mg->stencil;
  bool debug = false;
  HYPRE_Int plane, nodeRemainder;
  HYPRE_Int naborx1, naborx2, nabory1, nabory2;
  double *rhs;

  bool applyBdry = true;
  double hhalf;
  double bcx1 = mg->bcX1;
  double bcx2 = mg->bcX2;
  double bcy1 = mg->bcY1;
  double bcy2 = mg->bcY2;
  /* double bcz1 = mg->bcZ1; */
  /* double bcz2 = mg->bcZ2; */
  HYPRE_Int nx, ny;

  printf_dh("@@@ using striped partitioning\n");

  if (mg->debug && logFile != NULL) debug = true;

  /* recompute values (yuck!) */
  m = 9;
  Parser_dhReadInt(parser_dh,"-m", &m);  /* global grid dimension */
  mGlobal = m*m;                         /* global unkknowns */
  if (threeD) mGlobal *= m;
  i = mGlobal/mg->np;                    /* unknowns per processor */
  beg_row = i*mg->id;                    /* global number of 1st local row */
  end_row = beg_row + i;
  if (mg->id == mg->np-1) end_row = mGlobal;
  nx = ny = m;

  mg->hh = 1.0/(m-1);
  hhalf = 0.5 * mg->hh;

  A->n = m*m;
  A->m = end_row - beg_row;
  A->beg_row = beg_row;

  Vec_dhInit(b, A->m); CHECK_V_ERROR;
  rhs = b->vals;

  plane = m*m;

  if (debug) {
    hypre_fprintf(logFile, "generateStriped: beg_row= %i; end_row= %i; m= %i\n", beg_row+1, end_row+1, m);
  }

  for (row = beg_row; row<end_row; ++row) {
        HYPRE_Int localRow = row-beg_row;

        /* compute current node's position in grid */
        k = (row / plane);      
        nodeRemainder = row - (k*plane); /* map row to 1st plane */
        j = nodeRemainder / m;
        i = nodeRemainder % m;

        if (debug) {
          hypre_fprintf(logFile, "row= %i  x= %i  y= %i  z= %i\n", row+1, i,j,k);
        }

        /* compute column values and rhs entry for the current node */
        getstencil(mg,i,j,k);

        /* only homogenous Dirichlet boundary conditions presently supported */

        /* down plane */
        if (threeD) {
          if (k > 0) {
            cval[idx]   = row - plane;
            aval[idx++] = BACK(stencil);
          }
        }

        /* south */
        if (j > 0) {
          nabory1 = cval[idx] = row - m;
          aval[idx++] = SOUTH(stencil);
        }

        /* west */
        if (i > 0) {
          naborx1 = cval[idx] = row - 1;
          aval[idx++] = WEST(stencil);
        }

        /* center node */
        cval[idx]   = row;
        aval[idx++] = CENTER(stencil);

        /* east */
        if (i < m-1) {
          naborx2 = cval[idx] = row + 1;
          aval[idx++] = EAST(stencil);
        }

        /* north */
        if (j < m-1) {
          nabory2 = cval[idx] = row + m;
          aval[idx++] = NORTH(stencil);
        }

        /* up plane */
        if (threeD) {
          if (k < m-1) {
            cval[idx]   = row + plane;
            aval[idx++] = FRONT(stencil);
          }
        }
       rhs[localRow] = 0.0;
       ++localRow;
       rp[localRow] = idx; 

       /* apply boundary conditions; only for 2D! */
       if (!threeD && applyBdry) {
         HYPRE_Int offset = rp[localRow-1];
         HYPRE_Int len = rp[localRow] - rp[localRow-1];
         double ctr, coeff;

/* hypre_fprintf(logFile, "globalRow = %i; naborx2 = %i\n", row+1, row); */

         if (i == 0) {         /* if x1 */
           coeff = mg->A(mg->a, i+hhalf,j,k);
           ctr   = mg->A(mg->a, i-hhalf,j,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx1, coeff, ctr, naborx2);
         } else if (i == nx-1) {  /* if x2 */
           coeff = mg->A(mg->a, i-hhalf,j,k);
           ctr   = mg->A(mg->a, i+hhalf,j,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcx2, coeff, ctr, naborx1);
         } else if (j == 0) {  /* if y1 */
           coeff = mg->B(mg->b, i, j+hhalf,k);
           ctr   = mg->B(mg->b, i, j-hhalf,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy1, coeff, ctr, nabory2);
         } else if (j == ny-1) {        /* if y2 */
           coeff = mg->B(mg->b, i, j-hhalf,k);
           ctr   = mg->B(mg->b, i, j+hhalf,k);
           setBoundary_private(row, cval+offset, aval+offset, len,
                               &(rhs[localRow-1]), bcy2, coeff, ctr, nabory1);
         }
       }
  }
  END_FUNC_DH
}
Пример #7
0
void
__smapValidateSphereMapMesh(SphereMapMesh *mesh)
{
    /* setup some local variables for variable array size indexing */
    INITFACE(mesh);
    INITBACK(mesh);

    float st[2];     /* (s,t) coordinate  */
                     /* range=[0..1,0..1] */
    float v[3];      /* (x,y,z) location on cube map */
                     /* range=[-1..1,-1..1,-1..1] */
    float rv[3];     /* reflection vector, ie. cube map location */
                     /* normalized onto unit sphere */
    float len;       /* distance from v[3] to origin */
                     /* for converting to rv[3] */
    int side;        /* which of 5 faces (all but back face) */
    int i, j;
    int xl, yl, zl;  /* renamed X, Y, Z index */
    int swap;
    int flip;
    int edge;        /* which edge of back face */
    float sc, tc;    /* singularity (s,t) on back face circle */

    if (mesh->face) {
        assert(mesh->back == &(mesh->face[5*sqsteps]));
        return;
    }
    assert(mesh->back == NULL);

    mesh->face = (STXY*)
        malloc((5*sqsteps+4*ringedspokes) * sizeof(STXY));
    mesh->back = &(mesh->face[5*sqsteps]);

    /* for the front and four side faces */
    for (side=0; side<5; side++) {
        /* use faceInfo to parameterize face construction */
        xl  = faceInfo[side].xl;
        yl  = faceInfo[side].yl;
        zl  = faceInfo[side].zl;
        swap = faceInfo[side].swap;
        flip = faceInfo[side].flip;
        /* cube map "Z" coordinate */
        v[zl] = faceInfo[side].dir;

        for (i=0; i<mesh->steps; i++) {
            /* cube map "Y" coordinate */
            v[yl] = 2.0/(mesh->steps-1) * i - 1.0;
            for (j=0; j<mesh->steps; j++) {
                /* cube map "X" coordinate */
                v[xl] = 2.0/(mesh->steps-1) * j - 1.0;

                /* normalize cube map location to construct */
                /* reflection vector */
                len = sqrt(1.0 + v[xl]*v[xl] + v[yl]*v[yl]);
                rv[0] = v[0]/len;
                rv[1] = v[1]/len;
                rv[2] = v[2]/len;

                /* map reflection vector to sphere map (s,t) */
                /* NOTE: face[side][i][j] (x,y) gets updated */
                smapRvecToSt(rv, FACExy(side,i,j));

                /* update texture coordinate, */
                /* normalize [-1..1,-1..1] to [0..1,0..1] */
                if (!swap) {
                    FACE(side,i,j).s = (-v[xl] + 1.0)/2.0;
                    FACE(side,i,j).t = (flip*v[yl] + 1.0)/2.0;
                } else {
                    FACE(side,i,j).s = (flip*-v[yl] + 1.0)/2.0;
                    FACE(side,i,j).t = (v[xl] + 1.0)/2.0;
                }
            }
        }
    }


    /* The back face must be specially handled.  The center
       point in the back face of a cube map becomes a
       a singularity around the circular edge of a sphere map. */

    /* Carefully work from each edge of the back face to center
       of back face mapped to the outside of the sphere map. */

    /* cube map "Z" coordinate, always -1 since backface */
    v[2] = -1;

    /* for each edge */
    /*   [x=-1, y=-1..1, z=-1] */
    /*   [x= 1, y=-1..1, z=-1] */
    /*   [x=-1..1, y=-1, z=-1] */
    /*   [x=-1..1, y= 1, z=-1] */
    for (edge=0; edge<4; edge++) {
        /* cube map "X" coordinate */
        v[edgeInfo[edge].xl] = edgeInfo[edge].dir;
        for (j=0; j<mesh->steps; j++) {         
            /* cube map "Y" coordinate */
            v[edgeInfo[edge].yl] = 2.0/(mesh->steps-1) * j - 1.0;

            /* normalize cube map location to construct */
            /* reflection vector */
            len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
            rv[0] = v[0]/len;
            rv[1] = v[1]/len;
            rv[2] = v[2]/len;

            /* Map reflection vector to sphere map (s,t). */
            smapRvecToSt(rv, st);

            /* Determine distinance from the center of sphere */
            /* map (0.5,0.5) to (s,t) */
            len = sqrt((st[0]-0.5)*(st[0]-0.5) + (st[1]-0.5)*(st[1]-0.5));

            /* Calculate (s,t) location extended to the singularity */
            /* at the center of the back face (ie, extend to */
            /* circle edge of the sphere map). */
            sc = (st[0]-0.5)/len * 0.5 + 0.5;
            tc = (st[1]-0.5)/len * 0.5 + 0.5;

            /* (s,t) at back face edge. */
            BACK(edge,0,j).s = (-v[0] + 1.0)/2.0;
            BACK(edge,0,j).t = (-v[1] + 1.0)/2.0;
            BACK(edge,0,j).x = st[0];
            BACK(edge,0,j).y = st[1];

            /* If just two rings, we just generate a back face edge
               vertex and a center vertex (2 rings), but if there
               are more rings, we carefully interpolate between the
               edge and center vertices.  Notice how smapStToRvec is used
               to map the interpolated (s,t) into a reflection vector
               that must then be extended to the back cube face (it is
               not correct to just interpolate the texture
               coordinates!). */
            if (mesh->rings > 2) {
                float ist[2];  /* interpolated (s,t) */
                float ds, dt;  /* delta s and delta t */

                /* Start interpolating from the edge. */
                ist[0] = st[0];
                ist[1] = st[1];

                /* Calculate delta s and delta t for interpolation. */
                ds = (sc - ist[0]) / (mesh->rings-1);
                dt = (tc - ist[1]) / (mesh->rings-1);

                for (i=1; i<mesh->rings-1; i++) {
                    /* Incremental interpolation of (s,t). */
                    ist[0] = ist[0] + ds;
                    ist[1] = ist[1] + dt;

                    /* Calculate reflection vector from interpolated (s,t). */
                    smapStToRvec(ist, rv);
                    /* Assert that z must be on the back cube face. */
                    assert(rv[2] <= -sqrt(1.0/3.0));
                    /* Extend reflection vector out of back cube face. */
                    /* Note: z is negative value so negate z to avoid */
                    /* inverting x and y! */
                    rv[0] = rv[0] / -rv[2];
                    rv[1] = rv[1] / -rv[2];

                    BACK(edge,i,j).s = (-rv[0] + 1.0)/2.0;
                    BACK(edge,i,j).t = (-rv[1] + 1.0)/2.0;
                    BACK(edge,i,j).x = ist[0];
                    BACK(edge,i,j).y = ist[1];
                }
            }

            /* (s,t) at circle edge of the sphere map is ALWAYS */
            /* at center of back cube map face */
            BACK(edge,mesh->rings-1,j).s = 0.5;
            BACK(edge,mesh->rings-1,j).t = 0.5;
            /* Location of singularity at the edge of the sphere map. */
            BACK(edge,mesh->rings-1,j).x = sc;
            BACK(edge,mesh->rings-1,j).y = tc;

            if (mesh->edgeExtend) {
                /* Add an extra ring to avoid seeing the */
                /* tessellation boundary of the sphere map's sphere. */
                BACK(edge,mesh->rings,j).s = 0.5;
                BACK(edge,mesh->rings,j).t = 0.5;
                /* 0.33 below is a fudge factor. */
                BACK(edge,mesh->rings,j).x = sc + 0.33*(sc - st[0]);
                BACK(edge,mesh->rings,j).y = tc + 0.33*(tc - st[1]);
            }
        }
    }
    for (edge=0; edge<4; edge++) {
        for (j=0; j<mesh->steps; j++) {         
            for (i=1; i<mesh->rings-1; i++) {
            }
        }
    }
}