Example #1
0
// Initialise grid of specified type and size (if relevant)
bool Grid::initialise(Grid::GridType type, Vec3<int> nXYZ)
{
	Messenger::enter("Grid::initialise");
	type_ = type;
	bool result = true;
	clear();
	switch (type_)
	{
		case (Grid::RegularXYData):
			nXYZ_ = nXYZ;
			result = allocateArrays();
			if (result) Messenger::print("Initialised grid structure for regular 2D XY data, %i points total.", nXYZ_.x*nXYZ_.y);
			break;
		case (Grid::RegularXYZData):
			nXYZ_ = nXYZ;
			result = allocateArrays();
			if (result) Messenger::print("Initialised grid structure for regular 3D XY data, %i points total.", nXYZ_.x*nXYZ_.y*nXYZ_.z);
			break;
		case (Grid::FreeXYZData):
			Messenger::print("Initialised grid structure for free 3D XYZ data.");
			break;
		default:
			break;
	}
	logChange();
	Messenger::exit("Grid::initialise");
	return result;
}
Example #2
0
void LabelSet::grow() {
  maxIndex <<= 1;
  LabelInfo** ol = labels;
  allocateArrays();
  for ( int32 i = 0;  i < index; ++i ) {
    labels[i] = ol[i];
  }
}
Example #3
0
BZ_END_STENCIL

float acoustic3D_BlitzStencil(int N, int niters)
{
    Array<float,3> P1, P2, P3, c;
    allocateArrays(shape(N,N,N), P1, P2, P3, c);

    setupInitialConditions(P1, P2, P3, c, N);

    for (int iter=0; iter < niters; ++iter)
    {
        applyStencil(acoustic3D(), P1, P2, P3, c);
        cycleArrays(P1, P2, P3);
    }

    return P1(N/2,N/2,N/2);
}
Example #4
0
BZ_END_STENCIL

/*
 * The above stencil is very simple.  In general, a stencil object
 * can contain multiple assignment statements, and call other functions.
 * For example, here is a more complicated version of the above stencil,
 * which simulates acoustic waves propagating through a medium whose
 * density is gradually decreasing in response to pressure (but only where 
 * the conduction velocity is less than 0.5).  This is completely
 * nonsensical, but illustrates what you can do in a stencil:
 *
 * BZ_DECLARE_STENCIL4(myStencil, P1,P2,P3,c)
 *   P3 = 2 * P2 + c * Laplacian3D(P2) - P1;
 *   if (c < 0.5)
 *      c = c * (1.0 - exp(- abs(P3)))
 * BZ_END_STENCIL
 */

int main()
{
    Array<float,3> P1, P2, P3, c;
    const int N = 64;
    allocateArrays(shape(N,N,N), P1, P2, P3, c);

    // Initial conditions: obviously in a real application these
    // wouldn't be zeroed...
    P1 = 0;
    P2 = 0;
    P3 = 0;
    c = 0;

    const int nIterations = 10;

    for (int i=0; i < nIterations; ++i)
    {
        // Apply the stencil object to the arrays
        applyStencil(acoustic3D_stencil(), P1, P2, P3, c);

        // Set [P1,P2,P3] <- [P2,P3,P1] to set up for the next
        // time step
        cycleArrays(P1,P2,P3);
    }

    return 0;
}
Example #5
0
cStream::cStream( void )
{
  N	= 4000000; // increase to 8MB
  OFFSET = 0;
  scalar = 3.0;
  freq = 0;
  Verbose = false;
  label[ eCopy  ] = "Copy:      ";
  label[ eScale ] = "Scale:     ";
  label[ eAdd   ] = "Add:       ";
  label[ eTriad ] = "Triad:     ";
  mArraysAreAllocated = false;
#ifdef vs2005
  // obtain clock update frequency:
  QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
#else
  // obtain clock update frequency:
  freq = CLOCKS_PER_SEC;
#endif
  allocateArrays();
}; // void cStream::cStream( void )
Example #6
0
void cStream::setBufferSize( int aNewBufferSizeInBytes )
{
  N = ( int )ceil( (double)(aNewBufferSizeInBytes / sizeof( double )) );
  allocateArrays();
} // void cStream::setBufferSize( int aNewBufferSize )
Example #7
0
LabelSet::LabelSet() {
  maxIndex = 32; 
  index = 0;
  allocateArrays();
}
Example #8
0
// Assignment operator
Grid& Grid::operator=(Grid& source)
{
	// Copy PODs directly
	type_ = source.type_;
	dataFull_ = source.dataFull_;
	minimum_ = source.minimum_;
	maximum_ = source.maximum_;
	lowerPrimaryCutoff_ = source.lowerPrimaryCutoff_;
	upperPrimaryCutoff_ = source.upperPrimaryCutoff_;
	lowerSecondaryCutoff_ = source.lowerSecondaryCutoff_;
	upperSecondaryCutoff_ = source.upperSecondaryCutoff_;
	log_ = 0;
	primaryStyle_ = source.primaryStyle_;
	secondaryStyle_ = source.secondaryStyle_;
	visible_ = source.visible_;
	totalPositiveSum_ = source.totalPositiveSum_;
	partialPrimarySum_ = source.partialPrimarySum_;
	sumPoint_ = -1;
	totalNegativeSum_ = source.totalNegativeSum_;
	partialSecondarySum_ = source.partialSecondarySum_;
	for (int i=0; i<4; i++)
	{
		primaryColour_[i] = source.primaryColour_[i];
		secondaryColour_[i] = source.secondaryColour_[i];
	}
	useSecondary_ = source.useSecondary_;
	loopOrder_ = source.loopOrder_;
	colourScale_ = source.colourScale_;
	useColourScale_ = source.useColourScale_;
	useDataForZ_ = source.useDataForZ_;
	cell_ = source.cell_;
	origin_ = source.origin_;
	nXYZ_ = source.nXYZ_;
	axisLoopOrder_ = source.axisLoopOrder_;
	axisLoopSigns_ = source.axisLoopSigns_;

	// Delete any existing 2D or 3D array in this Grid
	deleteArrays();

	// Create new data structure
	allocateArrays();

	// Copy data from source structure
	int x,y,z;
	if (type_ == Grid::RegularXYZData)
	{
		for (x=0; x<nXYZ_.x; x++)
		{
			for (y=0; y<nXYZ_.y; y++)
			{
				for (z=0; z<nXYZ_.z; z++) data3d_[x][y][z] = source.data3d_[x][y][z];
			}
		}
	}
	else
	{
		for (x=0; x<nXYZ_.x; x++)
		{
			for (y=0; y<nXYZ_.y; y++) data2d_[x][y] = source.data2d_[x][y];
		}
	}
	name_ = source.name_;
	filename_ = source.filename_;

	return *this;
}
Example #9
0
void ScummEngine_v4::readIndexFile() {
	uint16 blocktype;
	uint32 itemsize;
	int numblock = 0;

	debug(9, "readIndexFile()");

	closeRoom();
	openRoom(0);

	while (true) {
		// Figure out the sizes of various resources
		itemsize = _fileHandle->readUint32LE();
		blocktype = _fileHandle->readUint16LE();
		if (_fileHandle->eos() || _fileHandle->err())
			break;

		switch (blocktype) {
		case 0x4E52:	// 'NR'
			_fileHandle->readUint16LE();
			break;
		case 0x5230:	// 'R0'
			_numRooms = _fileHandle->readUint16LE();
			break;
		case 0x5330:	// 'S0'
			_numScripts = _fileHandle->readUint16LE();
			break;
		case 0x4E30:	// 'N0'
			_numSounds = _fileHandle->readUint16LE();
			break;
		case 0x4330:	// 'C0'
			_numCostumes = _fileHandle->readUint16LE();
			break;
		case 0x4F30:	// 'O0'
			_numGlobalObjects = _fileHandle->readUint16LE();

			// Indy3 FM-TOWNS has 32 extra bytes of unknown meaning
			if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns)
				itemsize += 32;
			break;
		}
		_fileHandle->seek(itemsize - 8, SEEK_CUR);
	}

	_fileHandle->seek(0, SEEK_SET);

	readMAXS(0);
	allocateArrays();

	while (true) {
		itemsize = _fileHandle->readUint32LE();

		if (_fileHandle->eos() || _fileHandle->err())
			break;

		blocktype = _fileHandle->readUint16LE();

		numblock++;

		switch (blocktype) {

		case 0x4E52:	// 'NR'
			// Names of rooms. Maybe we should put them into a table, for use by the debugger?
			for (int room; (room = _fileHandle->readByte()); ) {
				char buf[10];
				_fileHandle->read(buf, 9);
				buf[9] = 0;
				for (int i = 0; i < 9; i++)
					buf[i] ^= 0xFF;
				debug(5, "Room %d: '%s'", room, buf);
			}
			break;

		case 0x5230:	// 'R0'
			readResTypeList(rtRoom);
			break;

		case 0x5330:	// 'S0'
			readResTypeList(rtScript);
			break;

		case 0x4E30:	// 'N0'
			readResTypeList(rtSound);
			break;

		case 0x4330:	// 'C0'
			readResTypeList(rtCostume);
			break;

		case 0x4F30:	// 'O0'
			readGlobalObjects();
			break;

		default:
			error("Bad ID %c%c found in directory", blocktype & 0xFF, blocktype >> 8);
		}
	}
	closeRoom();
}
Example #10
0
BZ_END_STENCIL


/*
 * Allocate arrays and set their initial state
 */
void setup(const int N, vectorField& V, vectorField& nextV, scalarField& P,
    scalarField& P_rhs, vectorField& advect, vectorField& force)
{
    // A 1m x 1m x 1m domain
    spatialStep = 1.0 / (N - 1);
    geom = UniformCubicGeometry<3>(spatialStep);

    // Allocate arrays
    allocateArrays(shape(N,N,N), advect, V, nextV, force);  // vector fields
    allocateArrays(shape(N,N,N), P, P_rhs);                 // scalar fields

    // Since incompressibility is assumed, pressure only shows up as
    // derivative terms in the equations.  We choose airPressure = 0
    // as an arbitrary datum.

    airPressure = 0;             // Pa
    rho = 1000;                  // density of fluid, kg/m^3
    recip_rho = 1.0 / rho;       // inverse of density
    eta = 1.0e-6;                // kinematic viscosity of fluid, m^2/s
    gravity = 9.81;              // m/s^2
    delta_t = 0.001;             // initial time step, in seconds
    volume = pow3(spatialStep);  // cubic volume associated with grid point

    // Kludge: Set eta high, so that the flow will spread faster.
    // This means the cube is filled with molasses, rather than water.
    eta *= 1000;
   
    // Initial conditions: quiescent
    V = 0.0; 
    P_rhs = 0.0;
    advect = 0.0;
    nextV = 0.0;

    // Initial pressure condition: gravity causes a linear increase
    // in pressure with depth.  Note that tensor::k means the index
    // associated with the z axis (they are labelled i, j, k).
#ifdef NO_GRAVITY
    gravityPressureGradient = 0.0;
    P = 0.0;
#else
    gravityPressureGradient = spatialStep * gravity * rho;

#ifdef BZ_HAVE_NAMESPACES
    P = airPressure + tensor::k * gravityPressureGradient;
#else
    P = airPressure + k * gravityPressureGradient;
#endif

#endif

    // Set up the forcing function: gravity plus a stirring force
    // at the bottom
    double gravity_z = gravity * rho;

    const int x = 0, y = 1, z = 2;
    force[x] = 0.0;
    force[y] = 0.0;
#ifdef NO_GRAVITY
    force[z] = 0.0;
#else
    force[z] = gravity_z;    
#endif

#ifndef NO_STIRRING
    // Centre of the stirring
    int centrex = int(2 * N / 3.0);
    int centrey = int(2 * N / 3.0);
    int centrez = int(4 * N / 5.0);

    const double stirRadius = 1.0 / 3.0;

    vector3d zaxis(0,0,1);

    // Loop through the 2D slice where the stirring occurs

    for (int i=force.lbound(firstDim); i <= force.ubound(firstDim); ++i)
    {
      for (int j=force.lbound(secondDim); j <= force.ubound(secondDim); ++j)
      {
         // Vector from the centre of the stirring to the current
         // coordinate

         vector3d r((i-centrex) * spatialStep, (j-centrey) * spatialStep, 0.0);

         if (norm(r) < stirRadius)
         {
             // The cross product of the z-axis and the vector3d to this
             // coordinate yields the direction of the force.  Multiply
             // by gravity to get a reasonable magnitude (max force =
             // 5 * gravity)
             force(i,j,centrez) += cross(zaxis, r) 
                 * (5 * gravity_z / stirRadius);
         }
      }
    }
#endif // NO_STIRRING
}