Esempio n. 1
0
/* copy (memcpy) the data of a dataArray_double to an AVSfield_double 
 *  -assumes 2vec input
 */
AVSfield_double *dataArray_2_AVSfield(dataArray_double *in)
{
    assert(in != NULL);
    assert(in->dimensions[0] == 2); /* veclen */

    /* copy input array dimensions, copy veclen as a new dimension */
    int *dim = (int*) malloc( sizeof(int)*((in->nd)) );
    for(int i=0;i<(in->nd)-1;i++) dim[i] = in->dimensions[i+1];

    /* allocate new dataArray_double */
    char field_str[100]; /* generate a data type description for AVS */
    sprintf(field_str,"field %dD %d-vector uniform double", 3, 2);
    AVSfield_double *out = (AVSfield_double *) AVSdata_alloc(field_str, dim);/* let AVS allocate array */
    free(dim);

    /* copy the data */
    memcpy(out->data, in->data, sizeof(double)*(in->num_elem));

    return(out);
}
Esempio n. 2
0
/************************************************************************** Module Compute Routine */
int module_compute( AVSfield_double *coords,
                    AVSfield_double *weights, 
                    AVSfield *kernelt_table_in, 
                    AVSfield_double **out, 
                    int iterations, 
                    int effective_matrix, 
                    float *rad_fov_prod, 
                    float *osf_in)
{
    /* rfp is relative to the grid size */
    float norm_rfp = (RADIUS_FOV_PRODUCT)*(*osf_in);

    /* update UI */
    AVSmodify_float_parameter ("rad fov prod (pix)", AVS_VALUE|AVS_MINVAL|AVS_MAXVAL, 
                                norm_rfp, norm_rfp, norm_rfp);

    /* free downstream data */
    if(*out!= NULL) AVSfield_free((AVSfield *) *out);

    /* COORDS */
    /* copy from dataArray_double to AVSfield_double */       
    unsigned long *tmp_dims_l = (unsigned long *) malloc(sizeof(int)*(coords->ndim+1)); // make copy of dims
    tmp_dims_l[0] = coords->veclen; // add veclen as the first dimension
    for(int i=0;i<coords->ndim+1;i++) tmp_dims_l[i+1] = coords->dimensions[i];  // copy dims 
    dataArray_double *crds_tmp = new_dataArray_double(coords->ndim+1,tmp_dims_l); // make new dataArray_double
    free(tmp_dims_l);
    memcpy(crds_tmp->data,coords->data,(crds_tmp->num_elem)*sizeof(double)); // copy coords

    /* make temporary output from sdc3grid_main() */
    dataArray_double *out_tmp = NULL;

    /* make a temporary array for input weights, if available */
    dataArray_double *weights_tmp = NULL;

    /* copy weights to a temporary dataArray_double if the user has passed them */
    if(weights != NULL)
    {
        /* COORDS */
        /* copy from dataArray_double to AVSfield_double */       
        unsigned long *tmp_dims_l = (unsigned long *) malloc(sizeof(int)*(weights->ndim)); // make copy of dims
        for(int i=0;i<weights->ndim;i++) tmp_dims_l[i] = weights->dimensions[i];  // copy dims 
        weights_tmp = new_dataArray_double(weights->ndim,tmp_dims_l); // make new dataArray_double
        free(tmp_dims_l);
        memcpy(weights_tmp->data,weights->data,(weights_tmp->num_elem)*sizeof(double)); // copy weights
    }

    /* run sample density estimation */
    out_tmp = sdc3grid_main(crds_tmp,weights_tmp,iterations,effective_matrix,*osf_in,2);

    /* OUTPUT */
    /* copy from dataArray_double to AVSfield_double */
    char field_str[100]; // generate a data type description for AVS
    sprintf(field_str,"field %dD %d-vector uniform double",out_tmp->nd, 1);
    int *tmp_dims = (int *) malloc(sizeof(int)*(out_tmp->nd));
    for(int i=0;i<out_tmp->nd;i++) tmp_dims[i] = out_tmp->dimensions[i];
    *out = (AVSfield_double *) AVSdata_alloc(field_str, tmp_dims);// let AVS allocate array
    free(tmp_dims);
    memcpy((*out)->data,out_tmp->data,out_tmp->num_elem*sizeof(double)); // copy the data

    /* free temp data */
    free_dataArray_double(out_tmp);
    free_dataArray_double(crds_tmp);

	return 1;
}
Esempio n. 3
0
//bool UniField::allocField(int nDims, int *dims, int vecLen, int nSpace, bool, int, const char *name)
bool UniField::allocField(int nDims, int *dims, int nSpace, bool, int nComp, int *compVecLen, const char **compNames, int)
#endif
#endif
{ // compNames: may be NULL and may have NULL entries
#ifdef AVS
    char regularity[256];
    sprintf(regularity, (regular ? "regular" : "irregular"));

    char type[256];
    switch (dataType)
    {
    case DT_FLOAT:
    {
        sprintf(type, "float");
    }
    break;
    default:
        printf("UniField: ERROR: unsupported data type\n");
    }

    if (nComp > 1)
        printf("UniField: ERROR: compVecLen>1 not supported\n");

    char desc[256];
    sprintf(desc, "field %dD %d-vector %s %d-space %s",
            nDims, compVecLen[0], regularity, nSpace, type);

    AVSfield_float *wf;
    wf = (AVSfield_float *)AVSdata_alloc(desc, dims);
    avsFld = (AVSfield *)wf;
    return (avsFld);
#endif

#ifdef COVISE
    if (outPorts.size() < 1)
    {
        fprintf(stderr, "UniField:allocField: no output port information, exit\n");
        exit(1); // ###
    }
#ifdef COVISE5
    covGrid = new DO_StructuredGrid
#else
    covGrid = new coDoStructuredGrid
#endif
        (outPorts[0]->getObjName(), // ### not ok
         dims[0],
         (nDims >= 2 ? dims[1] : 1),
         (nDims >= 3 ? dims[2] : 1));
    if (compVecLen[0] <= 1)
    {
#ifdef COVISE5
        covScalarData = new DO_Structured_S3D_Data(outPorts[1]->getObjName(), // ### not ok
                                                   dims[0],
                                                   (nDims >= 2 ? dims[1] : 1),
                                                   (nDims >= 3 ? dims[2] : 1));
#else
        covScalarData = new coDoFloat(outPorts[1]->getObjName(), // ### not ok
                                      dims[0] * (nDims >= 2 ? dims[1] : 1) * (nDims >= 3 ? dims[2] : 1));
#endif
    }
    else if (compVecLen[0] == 2)
    {
#ifdef COVISE5
        covVector2Data = new DO_Structured_V2D_Data(outPorts[1]->getObjName(), // ### not ok
                                                    dims[0],
                                                    (nDims >= 2 ? dims[1] : 1),
                                                    (nDims >= 3 ? dims[2] : 1));
#else
        covVector2Data = new coDoVec2(outPorts[1]->getObjName(), // ### not ok
                                      dims[0] * (nDims >= 2 ? dims[1] : 1) * (nDims >= 3 ? dims[2] : 1));
#endif
    }

    else if (compVecLen[0] == 3)
    {
#ifdef COVISE5
        covVector3Data = new DO_Structured_V3D_Data(outPorts[1]->getObjName(), // ### not ok
                                                    dims[0],
                                                    (nDims >= 2 ? dims[1] : 1),
                                                    (nDims >= 3 ? dims[2] : 1));
#else
        covVector3Data = new coDoVec3(outPorts[1]->getObjName(), // ### not ok
                                      dims[0] * (nDims >= 2 ? dims[1] : 1) * (nDims >= 3 ? dims[2] : 1));
#endif
    }
    else
    {
        fprintf(stderr, "UniField: error: unsupported vector length\n");
    }
    return (covGrid && (covScalarData || covVector2Data || covVector3Data));
#endif

#ifdef VTK
#if 0
  this->nDims = nDims;

  int vSize = 1;
  for (int i=0; i<nDims; i++) {
    this->dims[i] = dims[i];
    vSize *= dims[i];
  }

  this->vecLen = vecLen;

  this->nSpace = nSpace;
  
  this->regular = regular;

  vtkFld = (float *) malloc(vSize * vecLen * sizeof(float));

  vtkPositions = (float *) malloc(vSize * nSpace * sizeof(float));
#else

    if (!vtkFld)
        vtkFld = vtkStructuredGrid::New();

    selectedComp = 0;

    // get dims
    // ##### TODO: seems that VTK only supports 3-dims
    int dimensions[3] = { 1, 1, 1 };
    if (nDims > 3)
    {
        printf("UniField: error: VTK supports only 3-dim\n");
        nDims = 3;
    }
    int nnodes = 1;
    for (int i = 0; i < nDims; i++)
    {
        dimensions[i] = dims[i];
        nnodes *= dims[i];
    }

    // grid
    vtkFld->SetDimensions(dimensions);

    // coords
    vtkFloatArray *coords = vtkFloatArray::New();
    coords->SetNumberOfComponents(nSpace);
    coords->SetNumberOfTuples(nnodes);
    vtkPoints *points = vtkPoints::New();
    points->SetData(coords);
    vtkFld->SetPoints(points);
    coords->Delete();
    points->Delete();

    // data
    for (int c = 0; c < nComp; c++)
    {
        vtkFloatArray *dat = vtkFloatArray::New();
        dat->SetNumberOfComponents(compVecLen[c]);
        dat->SetNumberOfTuples(nnodes);
        if (compNames && compNames[c])
            dat->SetName(compNames[c]);
        else
        {
            char buf[256];
            sprintf(buf, "%p", dat);
            dat->SetName(buf);
        }
        vtkFld->GetPointData()->AddArray(dat);
        dat->Delete();
    }
#endif
    return true; // ###
#endif
}
Esempio n. 4
0
/* *****************************************/
int ucd_Mz_compute(UCD_structure *ucd, UCD_structure *grid, UCD_structure **ucd_out, AVSfield_float **trajectories,
                   float *origin_x, float *origin_y, float *origin_z,
                   int cells_x, int cells_y, int cells_z,
                   float *cell_size,
                   char *velocity,
                   int unsteady,
                   char *velocity_file,
                   int strong_hyperbolicity,
                   int ABC_steady,
                   float *start_time,
                   float *integration_time,
                   int time_intervals,
                   int integ_steps_max, int forward, int smoothing_range,
                   int omit_boundary_cells,
                   int grad_neigh_disabled,
                   int execute)
{

    /* ----> START OF USER-SUPPLIED CODE SECTION #3 (COMPUTE ROUTINE BODY)   */

    // system wrapper
    UniSys us;

    if (ucd_findNodeCompByVeclen(ucd, 3, 0) < 0)
    {
        us.error("UCD must contain at least one 3-vect component");
        return 0;
    }

    //if (AVSparameter_changed("mode")) {
    {
        char *cp1, *cp2;

        if (grid)
        {
            AVScommand("kernel", "manipulator \"$Module:origin x\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin y\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin z\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells x\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells y\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells z\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cell size\" -hide", &cp1, &cp2);
        }
        else
        {
            AVScommand("kernel", "manipulator \"$Module:origin x\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin y\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:origin z\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells x\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells y\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cells z\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:cell size\" -show", &cp1, &cp2);
        }

        if (unsteady)
        {
            AVScommand("kernel", "manipulator \"$Module:velocity file\" -show", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:start time\" -show", &cp1, &cp2);
        }
        else
        {
            AVScommand("kernel", "manipulator \"$Module:velocity file\" -hide", &cp1, &cp2);
            AVScommand("kernel", "manipulator \"$Module:start time\" -hide", &cp1, &cp2);
        }
    }

    if (*integration_time <= 0.0)
    {
        us.error("integration time must be larger than zero");
        return 0;
    }

    // input wrapper
    if (AVSinput_changed("ucd", 0))
    {
        if (unst)
            delete unst;
        unst = new Unstructured(ucd);
    }

    // process component choice selection
    int compVelo = ucd_processCompChoice(ucd, "ucd", velocity, "velocity", 3,
                                         unst->getVectorNodeDataComponent());
    if (compVelo >= 0)
        unst->selectVectorNodeData(compVelo);

    // init

    /* Allocate output UCD */
    if (*ucd_out && *ucd_out != ucd)
        UCDstructure_free(*ucd_out);
    UCD_structure *ucd1 = NULL;
    char labels[256] = "Mz.integration time";
    int components[2] = { 1, 1 };
    if (grid)
    {
        ucd1 = ucdClone(grid, 2, components, "ucd out", labels, ".");
    }
    else
    {
        ucd1 = generateUniformUCD("ucd out", *origin_x, *origin_y, *origin_z,
                                  cells_x, cells_y, cells_z,
                                  *cell_size,
                                  2, components,
                                  labels, ".");
    }
    *ucd_out = ucd1;

    // unstructured wrapper for output
    Unstructured *unst_out = new Unstructured(*ucd_out);

    // allocate field for trajectories
    if (*trajectories)
        AVSfield_free((AVSfield *)*trajectories);
    int dims[2];
    dims[0] = integ_steps_max + 1;
    dims[1] = ucd1->nnodes;
    *trajectories = (AVSfield_float *)AVSdata_alloc("field 2D 2-vector irregular 3-space float", dims);
    if (*trajectories == NULL)
    {
        AVSerror("allocation failed");
        return (0);
    }

    // field wrapper for output
    UniField *unif_traj = new UniField((AVSfield *)*trajectories);

    // compute
    if (execute)
    {
        Mz_impl(&us, unst, compVelo, unsteady, velocity_file,
                strong_hyperbolicity,
                ABC_steady,
                *start_time,
                *integration_time,
                time_intervals, integ_steps_max, forward,
                unst_out, smoothing_range,
                omit_boundary_cells, grad_neigh_disabled, unif_traj);

        // ##### work around, because there is a bug in unsetVector3CB()
        if (unst)
            delete unst;
        unst = new Unstructured(ucd);
    }

    // delete unstructured wrapper for output (but not the field)
    delete unst_out;

    // delete field wrapper (but not the field)
    delete unif_traj;

    /* <---- END OF USER-SUPPLIED CODE SECTION #3              */
    return (1);
}