コード例 #1
0
/*^-----------------------------------------------------------------------------
| PF
| mod_image_gen_mktile : command function for user command "mktile"
|   struct lxrcmd *c: Command-control-block calling this command function.
|
|
|
| Returns : PASS/FAIL
+-----------------------------------------------------------------------------*/
PF mod_image_gen_mktile ( struct lxrcmd *c ) 
{

    make_tile ( c->args[1].v.s, c->args[2].v.ld, c->args[3].v.s);   


    c->results = NULL;   // NULL results block. Change as appropriate


    return(PASS);
}
コード例 #2
0
int HECMW_vis_surface_compute(Surface *sff, struct hecmwST_local_mesh *mesh,
                              struct hecmwST_result_data *data, int *bdflag,
                              int *sum_v, int *sum_t, int *tvertex, int *tpatch,
                              double *minc, double *maxc, Result *result,
                              int sf_i, int mynode, HECMW_Comm VIS_COMM)

{
  /* in_volume */
  int i, j, k, mm;
  Point **CS_verts_head;
  Polygon **CS_polys_head;
  int alpha_index, beta_index;
  int sum_verts;
  int sum_table;
  Point **CS_verts_tail, **CS_verts_refer;
  Polygon **CS_polys_tail;
  Cube_polygons alpha_cube, beta_cube;

  int n_elem, tmp_int;
  Cell *cell;
  Tetra *tetra;

  int disamb_flag;

  Polygon *CS_polys, *CS_polys_tmp;
  Point *CS_verts, *CS_verts_tmp;
  int sum_polys, poly_num;
  int aplist_size, bplist_size, cplist_size;
  int num_nh_verts,
      num_nh_patch; /* vertex on patches generated in non-hexahedra */
  int flag_hexa, flag_tetra;
  Hash_vertex *vertex_hash_table;
  Tetra_point *tetra_point;
  Head_patch_tetra *head_patch_tetra;
  Tetra_point *p1, *p2;
  Patch_tetra *t1, *t2;
  Hash_vertex *h1, *h2;
  int minus_patch;
  double tmp_data[9];
  int tn_component, c_base;
  double tmp;

  sum_verts    = 0;
  num_nh_verts = 0;
  num_nh_patch = 0;
  sum_polys    = 0;

  n_elem       = mesh->n_elem;
  tn_component = 0;
  for (i = 0; i < data->nn_component; i++) tn_component += data->nn_dof[i];

  /*  prism = (Prism *)HECMW_malloc(sizeof(Prism));
   */
  if (mesh->elem_type[0] > 300) {
    flag_hexa  = 0;
    flag_tetra = 0;

    disamb_flag = 1;
    /*   fprintf(stderr, "sff inf: color=%d color_sub=%d con=%lf %lf %lf% lf\n",
sff->color_comp, sff->color_subcomp, sff->cont_equ[6],
sff->cont_equ[7], sff->cont_equ[8],sff->cont_equ[9]);

sprintf(test_file, "test_ucd.%d.%d.inp", time_step, mynode);
write_mesh_display(test_file, mesh, data);
HECMW_Barrier(VIS_COMM);
     */
    /*
for(i = 0; i < mesh->ne_internal; i++) {
    tmp_int=mesh->elem_internal_list[i]-1;
     */
    for (i = 0; i < mesh->n_elem; i++)
      if (mesh->elem_ID[i * 2 + 1] == mynode) {
        tmp_int = i;
        if ((mesh->elem_type[tmp_int] == 361) ||
            (mesh->elem_type[tmp_int] == 362) ||
            (mesh->elem_type[tmp_int] == 351) ||
            (mesh->elem_type[tmp_int] == 352)) {
          if (flag_hexa == 0) {
            flag_hexa = 1;

            CS_polys_head = (Polygon **)HECMW_malloc(sizeof(Polygon *));
            CS_verts_head = (Point **)HECMW_calloc(TABLE_SIZE, sizeof(Point *));
            sum_table     = TABLE_SIZE;
            CS_verts_tail = (Point **)HECMW_calloc(sum_table, sizeof(Point *));
            CS_verts_refer = (Point **)HECMW_calloc(sum_table, sizeof(Point *));
            for (j = 0; j < sum_table; j++) {
              if ((CS_verts_refer[j] = CS_verts_tail[j] = CS_verts_head[j] =
                       alloc_verts(VERTEX_PACK)) == NULL)
                HECMW_vis_memory_exit("verts for hexahedra");
            }

            CS_polys_tail = (Polygon **)HECMW_malloc(sizeof(Polygon *));
            if ((*CS_polys_tail = *CS_polys_head =
                     alloc_polygons(POLYGON_PACK)) == NULL)
              HECMW_vis_memory_exit("CS_polys_tail");

            alpha_cube.isosurf = (int **)HECMW_malloc(sizeof(int *));
            beta_cube.isosurf  = (int **)HECMW_malloc(sizeof(int *));
            cell               = (Cell *)HECMW_malloc(sizeof(Cell));
          }
          get_data(sff, mesh, data, tmp_int, cell, tn_component);
          if (sff->surface_style == 2) {
            alpha_index = make_tile(mesh, cell, sff->iso_value, 0, &alpha_cube,
                                    disamb_flag);
            beta_index = make_tile(mesh, cell, sff->iso_value, 1, &beta_cube,
                                   disamb_flag);
            if (alpha_index && beta_index) {
              if ((alpha_index + beta_index) == HEX_NODE_INDEX) {
                if (!merge_vol_iso(0, cell, sff->iso_value, &alpha_cube, 0,
                                   &beta_cube, bdflag[i], &sum_verts,
                                   CS_verts_tail, CS_verts_refer, CS_verts_head,
                                   CS_polys_tail)) {
                  return 0;
                }
              }
            }

          } else if (sff->surface_style == 3) {
            alpha_index = make_tile(mesh, cell, 0, 0, &alpha_cube, disamb_flag);
            beta_index  = make_tile(mesh, cell, 0, 1, &beta_cube, disamb_flag);
            if (alpha_index && beta_index) {
              if ((alpha_index + beta_index) == HEX_NODE_INDEX) {
                if (!merge_vol_iso(0, cell, 0, &alpha_cube, 0, &beta_cube,
                                   bdflag[i], &sum_verts, CS_verts_tail,
                                   CS_verts_refer, CS_verts_head,
                                   CS_polys_tail)) {
                  return 0;
                }
              }
            }
          }
        } else if ((mesh->elem_type[tmp_int] == 341) ||
                   (mesh->elem_type[tmp_int] == 342)) {
          /* tetrahedra */
          if (flag_tetra == 0) {
            flag_tetra = 1;
            /* initialize  */
            tetra             = (Tetra *)HECMW_malloc(sizeof(Tetra));
            vertex_hash_table = (Hash_vertex *)HECMW_calloc(
                mesh->n_node * 2, sizeof(Hash_vertex));
            tetra_point = (Tetra_point *)HECMW_malloc(sizeof(Tetra_point));
            head_patch_tetra =
                (Head_patch_tetra *)HECMW_malloc(sizeof(Head_patch_tetra));
            if ((vertex_hash_table == NULL) || (tetra == NULL) ||
                (tetra_point == NULL) || (head_patch_tetra == NULL))
              HECMW_vis_memory_exit("initialize tetra");
            for (j = 0; j < mesh->n_node * 2; j++) {
              vertex_hash_table[j].ident       = 0;
              vertex_hash_table[j].next_vertex = NULL;
            }
            tetra_point->ident          = 0;
            head_patch_tetra->num_patch = 0;
          }
          get_tetra_data(sff, mesh, data, tmp_int, tetra, tn_component);
          if (sff->surface_style == 3) sff->iso_value = 0.0;
          find_intersection_tetra(tetra, sff->iso_value, tetra_point,
                                  head_patch_tetra, vertex_hash_table);
        }
      }
    if (flag_tetra == 1) {
      num_nh_verts = tetra_point->ident;
      num_nh_patch = head_patch_tetra->num_patch;
      HECMW_free(tetra);
      for (j = 0; j < mesh->n_node * 2; j++) {
        h1 = vertex_hash_table[j].next_vertex;
        for (i = 0; i < vertex_hash_table[j].ident; i++) {
          h2 = h1->next_vertex;
          HECMW_free(h1);
          h1 = h2;
        }
      }
      HECMW_free(vertex_hash_table);
    }

    if (flag_hexa > 0) {
      mfree(alpha_cube.isosurf);
      mfree(beta_cube.isosurf);
      mfree(CS_verts_tail);
      mfree(CS_verts_refer);
      mfree(CS_polys_tail);

      *sum_v = sum_verts;
      *sum_t = sum_table;
      HECMW_free(cell);

      CS_polys = *CS_polys_head;

      sum_polys = 0;

      aplist_size = bplist_size = cplist_size = 1;
      while (CS_polys->plist != NULL) {
        switch (CS_polys->type) {
          case 0:
            aplist_size += CS_polys->plist[0] + 1;
            sum_polys++;
            break;
          case 1:
            bplist_size += CS_polys->plist[0] + 1;
            sum_polys++;
            break;
          case 2:
            cplist_size += (CS_polys->plist[0] - 2) * 4;
            sum_polys += CS_polys->plist[0] - 2;
            break;
        }
        CS_polys = CS_polys->nextpolygon;
      }
    }
    /*sum_polys=sum_polys*2;*/
    if ((sum_verts + num_nh_verts) > 0) {
      result[sf_i].n_vertex = sum_verts + num_nh_verts;
      result[sf_i].n_patch  = sum_polys + num_nh_patch;
      result[sf_i].vertex =
          (double *)HECMW_calloc(result[sf_i].n_vertex * 3, sizeof(double));
      result[sf_i].patch =
          (int *)HECMW_calloc(result[sf_i].n_patch * 3, sizeof(int));
      result[sf_i].color =
          (double *)HECMW_calloc(result[sf_i].n_vertex, sizeof(double));
      if ((result[sf_i].vertex == NULL) || (result[sf_i].patch == NULL) ||
          (result[sf_i].color == NULL))
        HECMW_vis_memory_exit("result");
    }
    mm = 0;
    if (sum_verts > 0) {
      /*  make main vertex table of CS  */
      for (i = 0; i < sum_table; i++) {
        CS_verts_tmp = CS_verts = CS_verts_head[i];
        j                       = 0;
        while (CS_verts->ident != 0) {
          /*      verts_geom[CS_verts->ident] = CS_verts->geom;
verts_field[CS_verts->ident] = CS_verts->field;
verts_color[CS_verts->ident] = CS_verts->cdata;

fprintf(vfile, " %d %lf %lf %lf\n",  *tvertex+CS_verts->ident,
verts_geom[CS_verts->ident].x,
verts_geom[CS_verts->ident].y,
verts_geom[CS_verts->ident].z);
           */
          result[sf_i].vertex[mm * 3]     = CS_verts->geom.x;
          result[sf_i].vertex[mm * 3 + 1] = CS_verts->geom.y;
          result[sf_i].vertex[mm * 3 + 2] = CS_verts->geom.z;
          result[sf_i].color[mm]          = CS_verts->cdata;
          mm++;
          CS_verts = CS_verts->nextpoint;
          if (!((++j) % VERTEX_PACK)) {
            mfree(CS_verts_tmp);
            CS_verts_tmp = CS_verts;
          }
        }
        mfree(CS_verts_tmp);
      }
      mfree(CS_verts_head);

      /*  make polygon table and decide vertex ID
of each object (alpha,beta,cross)  */
      /*  trilist=(Triangle *)HECMW_calloc(sum_polys+1,sizeof(Triangle));
       */
      CS_polys_tmp = CS_polys = *CS_polys_head;
      i                       = 0;
      poly_num                = 1;
      minus_patch             = 0;

      while (CS_polys->plist != NULL) {
        switch (CS_polys->type) {
          case 0:
            /*	      fprintf(pfile, "%d ", poly_num+(*tpatch));
             */
            k = -1;
            for (j = 1; j <= CS_polys->plist[0]; j++) {
              k++;
              /*		fprintf(pfile, "%d ",
(*tvertex)+CS_polys->plist[j]);

trilist[poly_num -1].vertex[k]=CS_polys->plist[j];
               */
              if ((sff->output_type == 1) || (sff->output_type == 2))
                result[sf_i].patch[(poly_num - 1) * 3 + k] =
                    *tvertex + CS_polys->plist[j];
              else
                result[sf_i].patch[(poly_num - 1) * 3 + k] = CS_polys->plist[j];

              tmp_data[k * 3] =
                  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3];
              tmp_data[k * 3 + 1] =
                  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3 + 1];
              tmp_data[k * 3 + 2] =
                  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3 + 2];
            }
            if (((fabs(tmp_data[0] - tmp_data[3]) < EPSILON) &&
                 (fabs(tmp_data[1] - tmp_data[4]) < EPSILON) &&
                 (fabs(tmp_data[2] - tmp_data[5]) < EPSILON)) ||
                ((fabs(tmp_data[0] - tmp_data[6]) < EPSILON) &&
                 (fabs(tmp_data[1] - tmp_data[7]) < EPSILON) &&
                 (fabs(tmp_data[2] - tmp_data[8]) < EPSILON)) ||
                ((fabs(tmp_data[6] - tmp_data[3]) < EPSILON) &&
                 (fabs(tmp_data[7] - tmp_data[4]) < EPSILON) &&
                 (fabs(tmp_data[8] - tmp_data[5]) < EPSILON)))
              minus_patch++;
            else
              poly_num++;

            break;
        }

        CS_polys = CS_polys->nextpolygon;
        if (!((++i) % POLYGON_PACK)) {
          mfree(CS_polys_tmp->plist);

          mfree(CS_polys_tmp);
          CS_polys_tmp = CS_polys;
        }
      }
      /*#ifdef DEBUG
fprintf(stderr, "the previous patch num is %d now is %d\n",
result[sf_i].n_patch, result[sf_i].n_patch-minus_patch);
#endif
       */
      result[sf_i].n_patch -= minus_patch;

      mfree(CS_polys_tmp);
    }
    if (num_nh_verts > 0) {
      p1 = tetra_point->nextpoint;
      for (i = 0; i < tetra_point->ident; i++) {
        for (j                                                 = 0; j < 3; j++)
          result[sf_i].vertex[(sum_verts + p1->ident) * 3 + j] = p1->geom[j];
        result[sf_i].color[sum_verts + p1->ident]              = p1->cdata;
        p2                                                     = p1;
        p1                                                     = p1->nextpoint;
        HECMW_free(p2);
      }
      HECMW_free(tetra_point);
    }
    if (num_nh_patch > 0) {
      t1 = head_patch_tetra->patch_link;
      for (i = 0; i < head_patch_tetra->num_patch; i++) {
        for (j = 0; j < 3; j++) {
          if (sff->output_type == 3)
            result[sf_i].patch[(sum_polys - minus_patch + i) * 3 + j] =
                t1->patch[j] + 1 + sum_verts;
          else
            result[sf_i].patch[(sum_polys - minus_patch + i) * 3 + j] =
                *tvertex + t1->patch[j] + 1 + sum_verts;
        }
        t2 = t1;
        t1 = t1->next_patch;
        HECMW_free(t2);
      }
      HECMW_free(head_patch_tetra);
    }

    /*
fprintf(stderr, "On surface %d PE %d: n_vertex is %d  n_patch is %d\n", sf_i,
mynode, result[sf_i].n_vertex, result[sf_i].n_patch);
     */
    if (result[sf_i].n_vertex > 0) {
      *minc = *maxc = result[sf_i].color[0];
      for (i = 1; i <= result[sf_i].n_vertex; i++) {
        if (result[sf_i].color[i - 1] < (*minc))
          (*minc) = result[sf_i].color[i - 1];
        if (result[sf_i].color[i - 1] > (*maxc))
          (*maxc) = result[sf_i].color[i - 1];
      }
      /*
#ifdef DEBUG
fprintf(stderr,"On surface %d PE %d: minimum color=%lf maximum color=%lf\n",
sf_i, mynode, *minc,*maxc);
#endif
       */
    }
  } /* endof if elem_type>300 */
  else if ((mesh->elem_type[0] > 200) && (mesh->elem_type[0] < 300)) {
    result[sf_i].n_patch = 0;
    for (i = 0; i < n_elem; i++) {
      if (mesh->elem_type[i] == 231)
        result[sf_i].n_patch++;
      else if (mesh->elem_type[i] == 241)
        result[sf_i].n_patch += 2;
    }
    result[sf_i].n_vertex = mesh->n_node;
    result[sf_i].vertex =
        (double *)HECMW_calloc(mesh->n_node * 3, sizeof(double));
    result[sf_i].color = (double *)HECMW_calloc(mesh->n_node, sizeof(double));
    result[sf_i].patch =
        (int *)HECMW_calloc(result[sf_i].n_patch * 3, sizeof(int));
    if ((result[sf_i].vertex == NULL) || (result[sf_i].color == NULL) ||
        (result[sf_i].patch == NULL))
      HECMW_vis_memory_exit("result: vertex, color and patch");
    for (i = 0; i < mesh->n_node; i++) {
      for (j                           = 0; j < 3; j++)
        result[sf_i].vertex[i * 3 + j] = mesh->node[i * 3 + j];
    }
    if (data->nn_dof[sff->color_comp] == 1) {
      c_base = 0;
      for (i = 0; i < sff->color_comp; i++) c_base += data->nn_dof[i];
    } else if (data->nn_dof[sff->color_comp] > 1) {
      c_base = 0;
      for (i = 0; i < sff->color_comp; i++) c_base += data->nn_dof[i];
    }

    if ((data->nn_dof[sff->color_comp] > 1) && (sff->color_subcomp == 0)) {
      for (i = 0; i < mesh->n_node; i++) {
        result[sf_i].color[i] = 0.0;
        for (j = 0; j < data->nn_dof[sff->color_comp]; j++) {
          tmp = data->node_val_item[c_base + i * tn_component + j];
          result[sf_i].color[i] += tmp * tmp;
        }
        result[sf_i].color[i] = sqrt(result[sf_i].color[i]);
      }
    }

    else if (data->nn_dof[sff->color_comp] > 1) {
      for (i = 0; i < mesh->n_node; i++) {
        result[sf_i].color[i] = data->node_val_item[c_base + i * tn_component +
                                                    (sff->color_subcomp - 1)];
      }
    } else if (data->nn_dof[sff->color_comp] == 1) {
      for (i = 0; i < mesh->n_node; i++) {
        result[sf_i].color[i] = data->node_val_item[c_base + i * tn_component];
      }
    }
    poly_num = 0;
    for (i = 0; i < n_elem; i++) {
      if (mesh->elem_type[i] == 231) {
        for (j = 0; j < 3; j++)
          result->patch[poly_num * 3 + j] =
              mesh->elem_node_item[mesh->elem_node_index[i] + j] + *tvertex;
        poly_num++;
      } else if (mesh->elem_type[i] == 241) {
        for (j = 0; j < 3; j++)
          result->patch[poly_num * 3 + j] =
              mesh->elem_node_item[mesh->elem_node_index[i] + j] + *tvertex;
        poly_num++;
        result->patch[poly_num * 3 + 0] =
            mesh->elem_node_item[mesh->elem_node_index[i] + 0] + *tvertex;
        result->patch[poly_num * 3 + 1] =
            mesh->elem_node_item[mesh->elem_node_index[i] + 2] + *tvertex;
        result->patch[poly_num * 3 + 2] =
            mesh->elem_node_item[mesh->elem_node_index[i] + 3] + *tvertex;
        poly_num++;
      }
    }
    /*
fprintf(stderr, "n_vertex is %d  n_patch is %d\n", result[sf_i].n_vertex,
result[sf_i].n_patch);
     */
    if (result[sf_i].n_vertex > 0) {
      *minc = *maxc = result[sf_i].color[0];
      for (i = 1; i <= result[sf_i].n_vertex; i++) {
        if (result[sf_i].color[i - 1] < (*minc))
          (*minc) = result[sf_i].color[i - 1];
        if (result[sf_i].color[i - 1] > (*maxc))
          (*maxc) = result[sf_i].color[i - 1];
      }
      /*
#ifdef DEBUG
fprintf(stderr,"On surface %d PE %d: minimum color=%lf maximum color=%lf\n",
sf_i, mynode, *minc,*maxc);
#endif
       */
    }
  }

  (*tvertex) += result[sf_i].n_vertex;
  (*tpatch) += result[sf_i].n_patch;
  /*  if(sum_verts>0) {
   *minv=mincolor;
   *maxv=maxcolor;
}

mfree(verts_info);
mfree(verts_geom);
mfree(verts_field);
mfree(verts_color);
mfree(trilist);
   */

  return (1);
}