Beispiel #1
0
int sdf_read_lagran_mesh(sdf_file_t *h)
{
    sdf_block_t *b = h->current_block;
    int n;
    int64_t nelements = 1;

    if (b->done_data) return 0;
    if (!b->done_info) sdf_read_blocklist(h);

    h->current_location = b->data_location;

    if (!b->grids) {
        b->ngrids = 3;
        b->grids = calloc(b->ngrids, sizeof(float*));
    }

    if (h->print) {
        h->indent = 0;
        SDF_DPRNT("\n");
        SDF_DPRNT("b->name: %s ", b->name);
        for (n=0; n < b->ndims; n++) SDF_DPRNT("%" PRIi64 " ",b->local_dims[n]);
        SDF_DPRNT("\n");
        h->indent = 2;
    }

    sdf_plain_mesh_distribution(h);

    for (n = 0; n < b->ndims; n++) nelements *= b->dims[n];

    for (n = 0; n < 3; n++) {
        if (b->ndims > n) {
            sdf_helper_read_array(h, &b->grids[n], -1);
            sdf_convert_array_to_float(h, &b->grids[n], b->nelements_local);
            if (h->print) {
                SDF_DPRNT("%s: ", b->dim_labels[n]);
                SDF_DPRNTar(b->grids[n], b->nelements_local);
            }
            h->current_location = h->current_location
                    + SDF_TYPE_SIZES[b->datatype] * nelements;
        } else {
            b->grids[n] = calloc(1, SDF_TYPE_SIZES[b->datatype]);
        }
    }

    sdf_free_distribution(h);

    b->done_data = 1;

    return 0;
}
Beispiel #2
0
int sdf_read_plain_mesh(sdf_file_t *h)
{
    sdf_block_t *b = h->current_block;
    int n;

    if (b->done_data) return 0;
    if (!b->done_info) sdf_read_blocklist(h);

    h->current_location = b->data_location;

    if (!b->grids) {
        b->ngrids = 3;
        b->grids = calloc(b->ngrids, sizeof(float*));
    }

    if (h->print) {
        h->indent = 0;
        SDF_DPRNT("\n");
        SDF_DPRNT("b->name: %s ", b->name);
        for (n=0; n < b->ndims; n++) SDF_DPRNT("%" PRIi64 " ",b->local_dims[n]);
        SDF_DPRNT("\n");
        h->indent = 2;
    }

    for (n = 0; n < 3; n++) {
        if (b->ndims > n) {
#ifdef PARALLEL
            sdf_create_1d_distribution(h, (int)b->dims[n],
                    (int)b->local_dims[n], b->starts[n]);
#endif
            sdf_helper_read_array(h, &b->grids[n], n);
            sdf_free_distribution(h);
            if (h->print) {
                SDF_DPRNT("%s: ", b->dim_labels[n]);
                SDF_DPRNTar(b->grids[n], b->local_dims[n]);
            }
            h->current_location = h->current_location
                    + SDF_TYPE_SIZES[b->datatype] * b->dims[n];
        }
    }

    b->done_data = 1;

    return 0;
}
Beispiel #3
0
int sdf_read_blocklist_all(sdf_file_t *h)
{
    sdf_extension_t *ext;
    char **preload;
    sdf_block_t *b, *next, *cur, *block;
    int i;

    // Retrieve the extended interface library from the plugin manager
    sdf_extension_load(h);
    ext = sdf_global_extension;

    if (h->blocklist) {
        if (ext) ext->timestate_update(ext, h);
        return 0;
    }

    sdf_read_blocklist(h);

    // Append derived data to the blocklist using built-in library.
    sdf_add_derived_blocks(h);

    if (ext) {
        preload = ext->preload(ext, h);
        // For each entry in the preload array, try to find the block
        // and populate its data.
        if (preload) {
            int n = 0;
            cur = h->current_block;
            while(preload[n]) {
                b = sdf_find_block_by_id(h, preload[n]);
                if (b && !b->data) {
                    h->current_block = b;
                    sdf_read_data(h);
                }
                free(preload[n]);
                n++;
            }
            free(preload);
            h->current_block = cur;
        }

        // Append derived data to the blocklist using the extension library.
        ext->read_blocklist(ext, h);
    }

    // Append additional derived data for blocks added by the extension.
    sdf_add_derived_blocks_final(h);
    sdf_purge_duplicates(h);

    // Fill in dimensions for derived blocks
    next = h->last_block_in_file;
    while (next) {
        b = next;
        next = b->next;

        if (b->blocktype != SDF_BLOCKTYPE_PLAIN_DERIVED
                && b->blocktype == SDF_BLOCKTYPE_POINT_DERIVED) continue;

        if (b->ndims > 0 || !b->mesh_id) continue;

        block = sdf_find_block_by_id(h, b->mesh_id);
        b->ndims = block->ndims;
        memcpy(b->local_dims, block->local_dims,
               b->ndims * sizeof(*b->local_dims));

        if (b->blocktype == SDF_BLOCKTYPE_POINT_DERIVED) {
            b->nelements_local = block->dims[0];
        } else {
            b->nelements_local = 1;
            for (i = 0; i < b->ndims; i++) {
                if (b->stagger == SDF_STAGGER_CELL_CENTRE && !b->station_id)
                    b->local_dims[i]--;
                b->nelements_local *= b->local_dims[i];
            }
        }

        if (!b->datatype_out)
            b->datatype_out = block->datatype_out;
    }

    return 0;
}