示例#1
0
static int bloch_jacobian(long int N, realtype t,
        N_Vector M, N_Vector fM, DlsMat J, void *user_data,
        N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
{
    struct bloch_sim *bs = (struct bloch_sim*)user_data;

    int i;
    for (i=0; i < bs->num_cells; ++i)
    {
        realtype dw = bs->cell_frequencies[i] - bs->w_avg;
        realtype w_1 = bs->rf_on ? bs->w_1 : 0.0;

        XX(J,i) = -1 / bs->T_2;
        XY(J,i) = dw;
        XZ(J,i) = 0.0;
        YX(J,i) = -dw;
        YY(J,i) = -1 / bs->T_2;
        YZ(J,i) = w_1;
        ZX(J,i) = 0.0;
        ZY(J,i) = -w_1;
        ZZ(J,i) = -1 / bs->T_1;
    }

    return 0;
}
示例#2
0
    shared_ptr<ChunkModelResult> compute_chunk(const ChunkModelData &data,
                                               const BlockTypeInfo &block_data) {
        std::vector<BlockData> blocks(XZ_SIZE * XZ_SIZE * XZ_SIZE);
        std::vector<char> highest(XZ_SIZE * XZ_SIZE);

        BlockData *above = data.above->blocks;
        BlockData *below = data.below->blocks;
        BlockData *left = data.left->blocks;
        BlockData *right = data.right->blocks;
        BlockData *front = data.front->blocks;
        BlockData *back = data.back->blocks;
        BlockData *above_left = data.above_left->blocks;
        BlockData *above_right = data.above_right->blocks;
        BlockData *above_front = data.above_front->blocks;
        BlockData *above_back = data.above_back->blocks;
        BlockData *above_left_front = data.above_left_front->blocks;
        BlockData *above_right_front = data.above_right_front->blocks;
        BlockData *above_left_back = data.above_left_back->blocks;
        BlockData *above_right_back = data.above_right_back->blocks;
        BlockData *left_front = data.left_front->blocks;
        BlockData *right_front = data.right_front->blocks;
        BlockData *left_back = data.left_back->blocks;
        BlockData *right_back = data.right_back->blocks;

        const char *is_transparent = block_data.is_transparent;
        const char *is_plant = block_data.is_plant;
        const char *state = block_data.state;

        int ox = - CHUNK_SIZE - 1;
        int oy = - CHUNK_SIZE - 1;
        int oz = - CHUNK_SIZE - 1;

        /* Populate the blocks array with the chunk itself */
        const BlockData *self = data.self->blocks;

        CHUNK_FOR_EACH(self, ex, ey, ez, eb) {
            int x = ex - ox;
            int y = ey - oy;
            int z = ez - oz;
            blocks[XYZ(x, y, z)] = eb;
            if (!is_transparent[eb.type]) {
                highest[XZ(x, z)] = std::max((int)highest[XZ(x, z)], y);
            }
        } END_CHUNK_FOR_EACH;
示例#3
0
文件: Terrain.cpp 项目: lcs2/carpg
//=================================================================================================
void Terrain::FillGeometryPart(vector<Tri>& tris, vector<Vec3>& verts, int px, int pz, const Vec3& offset) const
{
	assert(px >= 0 && pz >= 0 && uint(px) < n_parts && uint(pz) < n_parts);

	verts.reserve((tiles_per_part + 1)*(tiles_per_part + 1));

	for(uint z = pz*tiles_per_part; z <= (pz + 1)*tiles_per_part; ++z)
	{
		for(uint x = px*tiles_per_part; x <= (px + 1)*tiles_per_part; ++x)
		{
			verts.push_back(Vec3(x*tile_size + offset.x, h[x + z*hszer] + offset.y, z*tile_size + offset.z));
		}
	}

	tris.reserve(tiles_per_part * tiles_per_part * 3);

#define XZ(xx,zz) (x+(xx)+(z+(zz))*(tiles_per_part+1))

	for(uint z = 0; z < tiles_per_part; ++z)
	{
		for(uint x = 0; x < tiles_per_part; ++x)
		{
			tris.push_back(Tri(XZ(0, 0), XZ(0, 1), XZ(1, 0)));
			tris.push_back(Tri(XZ(1, 0), XZ(0, 1), XZ(1, 1)));
		}
	}

#undef XZ
}
示例#4
0
文件: Terrain.cpp 项目: lcs2/carpg
//=================================================================================================
void Terrain::FillGeometry(vector<Tri>& tris, vector<Vec3>& verts)
{
	uint vcount = (n_tiles + 1)*(n_tiles + 1);
	verts.reserve(vcount);

	for(uint z = 0; z <= (n_tiles + 1); ++z)
	{
		for(uint x = 0; x <= (n_tiles + 1); ++x)
		{
			verts.push_back(Vec3(x*tile_size, h[x + z*hszer], z*tile_size));
		}
	}

	tris.reserve(n_tiles * n_tiles * 3);

#define XZ(xx,zz) (x+(xx)+(z+(zz))*(n_tiles+1))

	for(uint z = 0; z < n_tiles; ++z)
	{
		for(uint x = 0; x < n_tiles; ++x)
		{
			tris.push_back(Tri(XZ(0, 0), XZ(0, 1), XZ(1, 0)));
			tris.push_back(Tri(XZ(1, 0), XZ(0, 1), XZ(1, 1)));
		}
	}

#undef XZ
}
std::string Ioss::Full_Tensor_16::label(int which, const char) const
{
  assert(which > 0 && which <= component_count());
  switch(which) {
  case 1:  return XX();
  case 2:  return XY();
  case 3:  return YZ();
  case 4:  return ZX();
  case 5:  return YX();
  case 6:  return ZY();
  case 7:  return XZ();
  default: return "";
  }
}
示例#6
0
void WorkerItem::computeChunk(World *world)
{
    char *opaque = (char *)calloc(XZ_SIZE * XZ_SIZE * Y_SIZE, sizeof(float));
    char *light = (char *)calloc(XZ_SIZE * XZ_SIZE * Y_SIZE, sizeof(char));
    char *highest = (char *)calloc(XZ_SIZE * XZ_SIZE, sizeof(char));
    
    int ox = p * CHUNK_SIZE - CHUNK_SIZE - 1;
    int oy = -1;
    int oz = q * CHUNK_SIZE - CHUNK_SIZE - 1;
    
    // check for lights
    int has_light = 0;
    if (SHOW_LIGHTS) {
        for (int a = 0; a < 3; a++) {
            for (int b = 0; b < 3; b++) {
                Map *map = light_maps[a][b];
                if (map && map->size) {
                    has_light = 1;
                }
            }
        }
    }
    
    // populate opaque array
    for (int a = 0; a < 3; a++) {
        for (int b = 0; b < 3; b++) {
            Map *map = block_maps[a][b];
            if (!map) {
                continue;
            }
            MAP_FOR_EACH(map, ex, ey, ez, ew) {
                
                int rawx = Map::getX(i);
                int rawy = Map::getY(i);
                int rawz = Map::getZ(i);
                
                int x2 = rawx + map->dx - ox;
                int y2 = rawy + map->dy - oy;
                int z2 = rawz + map->dz - oz;
                
                int x = 0;
                int y = 0;
                int z = 0;
                
                if(entry->e.computed)
                {
                    x = x2;
                    y = y2;
                    z = z2;
                }

                int w = ew;
                // TODO: this should be unnecessary
                if (x < 0 || y < 0 || z < 0) {
                    continue;
                }
                if (x >= XZ_SIZE || y >= Y_SIZE || z >= XZ_SIZE) {
                    continue;
                }
                // END TODO
                opaque[XYZ(x, y, z)] = !is_transparent(w);
                if (opaque[XYZ(x, y, z)]) {
                    highest[XZ(x, z)] = MAX(highest[XZ(x, z)], y);
                }
            } END_MAP_FOR_EACH;
        }
    }