Exemple #1
0
void UniField::freeField()
{
#ifdef AVS
    if (avsFld)
    {
        AVSfield_free(avsFld);
        avsFld = NULL;
    }
#endif

#ifdef COVISE
// HACK ### actually assuming that field got assigned to a Covise output port
// -> nothing to be done
#endif

#ifdef VTK
#if 0
  if (vtkFld) {
    free(vtkFld);
    vtkFld = NULL;
    free(vtkPositions);
    vtkPositions = NULL;
  }
#else
    if (vtkFld)
        vtkFld->Delete();
#endif
#endif
}
Exemple #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;
}
Exemple #3
0
/*  BEGIN Module Compute Routine */
int module_compute( AVSfield *data, 
                    AVSfield *coords, 
                    AVSfield *weights, 
                    AVSfield *table, 
                    AVSfield **out, 
                    float *radiusFOVproduct, 
                    int width_in, 
                    float *OverSampFact, 
                    float *windowLength, 
                    float *taper_start, 
                    float *taper_length, 
                    int num_threads,
                    int veclen, /* if data is not present */
                    int compute)
{
    
    /* check to see if the body should run or not */
    if(!compute) 
    {
        /* don't signal downstream modules */
        AVSmark_output_unchanged("spectrum");  
        return(1);
    }

    /* grid size */
    int width = (float)width_in * (*OverSampFact);

    /* allocate kernel table */
    unsigned long dim[1];
    dim[0] = DEFAULT_KERNEL_TABLE_SIZE;
    dataArray_double *kern = (dataArray_double*) new_dataArray_double(1,dim);

    for(long i=0;i<kern->num_elem;i++) kern->data[i]=0.;
    loadGrid3Kernel(kern);

    /* make dataArray_double copies of input data */
    dataArray_double *data_tmp = AVSfield_2_dataArray( (AVSfield_double*)data   );
    dataArray_double *crds_tmp = AVSfield_2_dataArray( (AVSfield_double*)coords );
    dataArray_double *wght_tmp = NULL; 
    if (weights != NULL) wght_tmp = AVSfield_2_dataArray( (AVSfield_double*)weights );
    unsigned long dims[4];
    dims[0] = 2; /* complex */
    dims[1] = width;
    dims[2] = width;
    dims[3] = width;
    dataArray_double *out_tmp = new_dataArray_double(4,dims);
	
    /* choose either octant split gridding or single thread */
    if(num_threads == 8)
    {

        /* GRID3_threaded */

        /* 1) map threads */
        dataArray_double *threadMask = NULL;
        dataArray_double *centerPts  = NULL;
        int partsize = -1;
        double rfp_d = *radiusFOVproduct;
        partitionGrid_octants(crds_tmp,
                              rfp_d,
                              width,
                              &threadMask,
                              &centerPts,
                              &partsize);

        /* 2) grid it */
		grid3_threaded(data_tmp, 
                       crds_tmp, 
                       wght_tmp, 
                       out_tmp, 
                       kern, 
                       *radiusFOVproduct, 
                       *windowLength, 
                       num_threads, 
                       threadMask, 
                       centerPts, 
                       partsize); 

        /* free tmp data */
        free_dataArray_double(threadMask);
        free_dataArray_double(centerPts);

    }
    else
    {
        /* GRID3 non-threaded */
        int nt = 1;
        int ct = 0;
        double rfp_d = *radiusFOVproduct;
        double win_d = *windowLength;
        grid3 ( &nt, &ct, 
                data_tmp, 
                crds_tmp, 
                wght_tmp, 
                &out_tmp, 
                kern, 
                NULL,
                NULL,
                &width,
                &rfp_d,
                &win_d );
    }

    /* allocate output array */
    if(*out != NULL) AVSfield_free((AVSfield*)*out);
    *out = (AVSfield *)dataArray_2_AVSfield(out_tmp);

    /* free kernel table */
    free_dataArray_double(kern);
    free_dataArray_double(out_tmp);

	return 1;
}
Exemple #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);
}