Exemplo n.º 1
0
/*
 * Calculations are node based, boundaries are aligned with
 * the nodes. For m inner cells, there are m + 1 node layers.
 * In this program, 2D and 3D space are unified, a 2D space
 * is equivalent to a non-zero thickness 3D space with 2 inner
 * cells (that is, three node layers) in the collapsed direction.
 * These three node layers are treated as domain boundary,
 * inner node, domain boundary respectively. Zero gradient
 * condition need to be forced on the collapsed dimension.
 */
static int NodeBasedMeshNumberRefine(Space *space, const Model *model)
{
    Partition *part = &(space->part);
    /* set ghost layers according to numerical scheme */
    if (WENOFIVE == model->sScheme) {
        part->gl = 3;
    }
    /* global boundary account for one ghost layer */
    part->ng = part->gl - 1;
    /* rectify ghost layers for periodic boundary conditions */
    if ((PERIODIC == part->typeBC[PWB]) || (PERIODIC == part->typeBC[PSB]) || 
            (PERIODIC == part->typeBC[PFB])) {
        part->ng = part->gl;
    }
    /* check and mark collapsed space. */
    part->collapse = COLLAPSEN;
    if (0 == (part->m[Z] - 1)) {
        part->collapse = COLLAPSEZ;
    }
    if (0 == (part->m[Y] - 1)) {
        part->collapse = 2 * part->collapse + COLLAPSEY;
    }
    if (0 == (part->m[X] - 1)) {
        part->collapse = 2 * part->collapse + COLLAPSEX;
    }
    for (int s = 0; s < DIMS; ++s) {
        /* ensure at least two inner cells per dimension */
        part->m[s] = MaxInt(part->m[s], 2);
        /* total number of nodes (including ghost nodes) */
        part->n[s] = part->m[s] + 1 + 2 * part->ng; 
    }
    return 0;
}
Exemplo n.º 2
0
void Merge(int *A, int p, int q, int r) {
    int n1 = q - p + 1;
    int n2 = r - q;
    int *L = new int[n1 + 1];
    int *R = new int[n2 + 1];

    for(int i = 0; i < n1; i++)
        L[i] = A[p+i];
    L[n1] = MaxInt();

    for(int j = 0; j < n2; j++)
        R[j] = A[q+j+1];
    R[n2] = MaxInt();

    int i = 0;
    int j = 0;
    for(int k = p; k <= r; k++)
        if(L[i] <= R[j]) A[k] = L[i++];
        else A[k] = R[j++];
    delete L;
    delete R;
}
Exemplo n.º 3
0
int ComputeSolutionError(Space *space, const Model *model)
{
    FILE *filePointer = fopen("solution_error.csv", "w");
    if (NULL == filePointer) {
        FatalError("failed to write data...");
    }
    const Partition *restrict part = &(space->part);
    Node *const node = space->node;
    Real *restrict Us = NULL; /* numerical solution */
    Real *restrict Ue = NULL; /* exact solution */
    int idx = 0; /* linear array index math variable */
    const int meshN = MaxInt(part->m[X], MaxInt(part->m[Y], part->m[Z]));
    Real norm[3] = {0.0}; /* Lp norms */
    int N = 0; /* number of nodes */
    Real err = 0.0; /* solution error */
    SetField(TN, space, model); /* compute exact solution field */
    for (int k = part->ns[PIN][Z][MIN]; k < part->ns[PIN][Z][MAX]; ++k) {
        for (int j = part->ns[PIN][Y][MIN]; j < part->ns[PIN][Y][MAX]; ++j) {
            for (int i = part->ns[PIN][X][MIN]; i < part->ns[PIN][X][MAX]; ++i) {
                idx = IndexNode(k, j, i, part->n[Y], part->n[X]);
                Us = node[idx].U[TO];
                Ue = node[idx].U[TN];
                err = fabs(Us[0] - Ue[0]);
                norm[0] = MaxReal(norm[0], err);
                norm[1] = norm[1] + err;
                norm[2] = norm[2] + err * err;
                ++N;
            }
        }
    }
    norm[1] = norm[1] / N;
    norm[2] = sqrt(norm[2] / N);
    fprintf(filePointer, "# mesh, l1 norm, l2 norm, max norm\n"); 
    fprintf(filePointer, "%d, %.6g, %.6g, %.6g\n", meshN, norm[1], norm[2], norm[0]); 
    fclose(filePointer); /* close current opened file */
    return 0;
}
//-----------------------------------------------------------------------------------------------
void ResourceStream::ReserveAtLeast( int newMinimumCapacity )
{
	if( newMinimumCapacity <= m_capacity )
		return;

	{ int q = 5; } //ConsolePrintf( "ResourceStream::ReserveAtLeast() called; current capacity is %d, extending to at least %d\n", m_capacity, newMinimumCapacity );

	// Grow at least 50% bigger and by at least a minimum amount
	const int fiftyPercentIncreasedCapacity = (m_capacity * 3) / 2;
	const int minimumIncreasedCapacity = (newMinimumCapacity + MINIMUM_ALLOC_CHUNK_SIZE_BYTES);
	const int newCapacity = MaxInt( fiftyPercentIncreasedCapacity, minimumIncreasedCapacity );

	{ int q = 5; } //ConsolePrintf( "ResourceStream::ReserveAtLeast: new capacity will be expanded to %d bytes\n", newCapacity );

	unsigned char* oldData = m_startOfData;
	m_startOfData = new unsigned char[ newCapacity ];
	memcpy( m_startOfData, oldData, m_dataBytesAvailable );
	delete[] oldData;
	m_capacity = newCapacity;
	{ int q = 5; } //ConsolePrintf( "ResourceStream::ReserveAtLeast: finished relocating into newly expanded memory buffer.\n" );
}
Exemplo n.º 5
0
bool
mozTXTToHTMLConv::FindURLStart(const PRUnichar * aInString, PRInt32 aInLength,
                               const PRUint32 pos, const modetype check,
                               PRUint32& start)
{
  switch(check)
  { // no breaks, because end of blocks is never reached
  case RFC1738:
  {
    if (!nsCRT::strncmp(&aInString[MaxInt(pos - 4, 0)], NS_LITERAL_STRING("<URL:").get(), 5))
    {
      start = pos + 1;
      return true;
    }
    else
      return false;
  }
  case RFC2396E:
  {
    nsString temp(aInString, aInLength);
    PRInt32 i = pos <= 0 ? kNotFound : temp.RFindCharInSet(NS_LITERAL_STRING("<>\"").get(), pos - 1);
    if (i != kNotFound && (temp[PRUint32(i)] == '<' ||
                           temp[PRUint32(i)] == '"'))
    {
      start = PRUint32(++i);
      return start < pos;
    }
    else
      return false;
  }
  case freetext:
  {
    PRInt32 i = pos - 1;
    for (; i >= 0 && (
         nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
         nsCRT::IsAsciiDigit(aInString[PRUint32(i)]) ||
         aInString[PRUint32(i)] == '+' ||
         aInString[PRUint32(i)] == '-' ||
         aInString[PRUint32(i)] == '.'
         ); i--)
      ;
    if (++i >= 0 && PRUint32(i) < pos && nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]))
    {
      start = PRUint32(i);
      return true;
    }
    else
      return false;
  }
  case abbreviated:
  {
    PRInt32 i = pos - 1;
    // This disallows non-ascii-characters for email.
    // Currently correct, but revisit later after standards changed.
    bool isEmail = aInString[pos] == (PRUnichar)'@';
    // These chars mark the start of the URL
    for (; i >= 0
             && aInString[PRUint32(i)] != '>' && aInString[PRUint32(i)] != '<'
             && aInString[PRUint32(i)] != '"' && aInString[PRUint32(i)] != '\''
             && aInString[PRUint32(i)] != '`' && aInString[PRUint32(i)] != ','
             && aInString[PRUint32(i)] != '{' && aInString[PRUint32(i)] != '['
             && aInString[PRUint32(i)] != '(' && aInString[PRUint32(i)] != '|'
             && aInString[PRUint32(i)] != '\\'
             && !IsSpace(aInString[PRUint32(i)])
             && (!isEmail || nsCRT::IsAscii(aInString[PRUint32(i)]))
         ; i--)
      ;
    if
      (
        ++i >= 0 && PRUint32(i) < pos
          &&
          (
            nsCRT::IsAsciiAlpha(aInString[PRUint32(i)]) ||
            nsCRT::IsAsciiDigit(aInString[PRUint32(i)])
          )
      )
    {
      start = PRUint32(i);
      return true;
    }
    else
      return false;
  }
  default:
    return false;
  } //switch
}
Exemplo n.º 6
0
float LCG::Float()
{
	return (float)Int() / ((float)MaxInt() + 1.f);
}
Exemplo n.º 7
0
int ValidNodeSpace(const int n, const int nMin, const int nMax)
{
    return MinInt(nMax - 1, MaxInt(nMin, n));
}