Ejemplo n.º 1
0
// This helper function converts the given element identifier string and number of nodes to 
// our own element enumerated type.
static fe_mesh_element_t get_element_type(const char* elem_type_id)
{
  if (string_ncasecmp(elem_type_id, "nfaced", 6) == 0)
    return FE_POLYHEDRON;
  else if (string_ncasecmp(elem_type_id, "tetra", 5) == 0)
    return FE_TETRAHEDRON;
  else if (string_ncasecmp(elem_type_id, "pyramid", 7) == 0)
    return FE_PYRAMID;
  else if (string_ncasecmp(elem_type_id, "wedge", 5) == 0)
    return FE_WEDGE;
  else if (string_ncasecmp(elem_type_id, "hex", 3) == 0)
    return FE_HEXAHEDRON;
  else
    return FE_INVALID;
}
Ejemplo n.º 2
0
Variant f_substr_compare(CStrRef main_str, CStrRef str, int offset,
                         int length /* = 0 */,
                         bool case_insensitivity /* = false */) {
  int s1_len = main_str.size();
  int s2_len = str.size();

  if (offset < 0) {
    offset = s1_len + offset;
    if (offset < 0) offset = 0;
  }
  if (offset > s1_len || length > s1_len - offset) {
    return false;
  }

  int cmp_len = length;
  if (length == 0) {
    cmp_len = s1_len - offset;
    if (cmp_len < s2_len) cmp_len = s2_len;
  }

  const char *s1 = main_str.data();
  if (case_insensitivity) {
    return string_ncasecmp(s1 + offset, str, cmp_len);
  }
  return string_ncmp(s1 + offset, str, cmp_len);
}
Ejemplo n.º 3
0
int is_uri_protocol(UriUriA *uri, const char *protocol)
{
	if (!uri || !uri->scheme.first || !uri->scheme.afterLast)
		return 0;

	if (((size_t) (uri->scheme.afterLast - uri->scheme.first)) == strlen(protocol)
		&& !string_ncasecmp(uri->scheme.first, protocol, uri->scheme.afterLast - uri->scheme.first))
		return 1;

	return 0;
}
Ejemplo n.º 4
0
int is_same_mimetype(const char *type1, const char *type2)
{
	return !string_ncasecmp(type1, type2, strlen(type2));
}
Ejemplo n.º 5
0
fe_mesh_t* exodus_file_read_mesh(exodus_file_t* file)
{
  // Create the "host" FE mesh.
  fe_mesh_t* mesh = fe_mesh_new(file->comm, file->num_nodes);

  // Count up the number of polyhedral blocks.
  int num_poly_blocks = 0;
  for (int i = 0; i < file->num_elem_blocks; ++i)
  {
    int elem_block = file->elem_block_ids[i];
    char elem_type_name[MAX_NAME_LENGTH+1];
    int num_elem, num_nodes_per_elem, num_faces_per_elem;
    ex_get_block(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                 elem_type_name, &num_elem,
                 &num_nodes_per_elem, NULL,
                 &num_faces_per_elem, NULL);
    fe_mesh_element_t elem_type = get_element_type(elem_type_name);
    if (elem_type == FE_POLYHEDRON)
      ++num_poly_blocks;
  }

  // If we have any polyhedral element blocks, we read a single face 
  // block that incorporates all of the polyhedral elements.
  if (num_poly_blocks > 0)
  {
    // Dig up the face block corresponding to this element block.
    char face_type[MAX_NAME_LENGTH+1];
    int num_faces, num_nodes;
    ex_get_block(file->ex_id, EX_FACE_BLOCK, file->face_block_ids[0], face_type, &num_faces,
                 &num_nodes, NULL, NULL, NULL);
    if (string_ncasecmp(face_type, "nsided", 6) != 0)
    {
      fe_mesh_free(mesh);
      ex_close(file->ex_id);
      polymec_error("Invalid face type for polyhedral element block.");
    }

    // Find the number of nodes for each face in the block.
    int* num_face_nodes = polymec_malloc(sizeof(int) * num_faces);
    ex_get_entity_count_per_polyhedra(file->ex_id, EX_FACE_BLOCK, 
                                      file->face_block_ids[0], 
                                      num_face_nodes);

    // Read face->node connectivity information.
    int face_node_size = 0;
    for (int i = 0; i < num_faces; ++i)
      face_node_size += num_face_nodes[i];
    int* face_nodes = polymec_malloc(sizeof(int) * face_node_size);
    ex_get_conn(file->ex_id, EX_FACE_BLOCK, 1, face_nodes, NULL, NULL);
    for (int i = 0; i < face_node_size; ++i)
      face_nodes[i] -= 1;
    fe_mesh_set_face_nodes(mesh, num_faces, num_face_nodes, face_nodes);

    // Clean up.
    polymec_free(num_face_nodes);
  }

  // Go over the element blocks and feel out the data.
  for (int i = 0; i < file->num_elem_blocks; ++i)
  {
    int elem_block = file->elem_block_ids[i];
    char elem_type_name[MAX_NAME_LENGTH+1];
    int num_elem, num_nodes_per_elem, num_faces_per_elem;
    ex_get_block(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                 elem_type_name, &num_elem,
                 &num_nodes_per_elem, NULL,
                 &num_faces_per_elem, NULL);

    // Get the type of element for this block.
    fe_mesh_element_t elem_type = get_element_type(elem_type_name);
    fe_block_t* block = NULL;
    char block_name[MAX_NAME_LENGTH+1];
    if (elem_type == FE_POLYHEDRON)
    {
      // Find the number of faces for each element in the block.
      int* num_elem_faces = polymec_malloc(sizeof(int) * num_elem);
      ex_get_entity_count_per_polyhedra(file->ex_id, EX_ELEM_BLOCK, elem_block, 
                                        num_elem_faces);

      // Get the element->face connectivity.
      int elem_face_size = 0;
      for (int j = 0; j < num_elem; ++j)
        elem_face_size += num_elem_faces[j];
      int* elem_faces = polymec_malloc(sizeof(int) * elem_face_size);
      ex_get_conn(file->ex_id, EX_ELEM_BLOCK, elem_block, NULL, NULL, elem_faces);

      // Subtract 1 from each element face.
      for (int j = 0; j < elem_face_size; ++j)
        elem_faces[j] -= 1;

      // Create the element block.
      block = polyhedral_fe_block_new(num_elem, num_elem_faces, elem_faces);
    }
    else if (elem_type != FE_INVALID)
    {
      // Get the element's nodal mapping.
      int* node_conn = polymec_malloc(sizeof(int) * num_elem * num_nodes_per_elem);
      ex_get_conn(file->ex_id, EX_ELEM_BLOCK, elem_block, node_conn, NULL, NULL);
      
      // Subtract 1 from each element node.
      for (int j = 0; j < num_elem * num_nodes_per_elem; ++j)
        node_conn[j] -= 1;

      // Build the element block.
      block = fe_block_new(num_elem, elem_type, num_nodes_per_elem, node_conn);
    }
    else
    {
      fe_mesh_free(mesh);
      ex_close(file->ex_id);
      polymec_error("Block %d contains an invalid (3D) element type.", elem_block);
    }

    // Fish out the element block name if it has one, or make a default.
    ex_get_name(file->ex_id, EX_ELEM_BLOCK, elem_block, block_name);
    if (strlen(block_name) == 0)
      sprintf(block_name, "block_%d", elem_block);

    // Add the element block to the mesh.
    fe_mesh_add_block(mesh, block_name, block);
  }

  // Fetch node positions and compute geometry.
  real_t x[file->num_nodes], y[file->num_nodes], z[file->num_nodes];
  ex_get_coord(file->ex_id, x, y, z);
  point_t* X = fe_mesh_node_positions(mesh);
  for (int n = 0; n < file->num_nodes; ++n)
  {
    X[n].x = x[n];
    X[n].y = y[n];
    X[n].z = z[n];
  }

  // Fetch sets of entities.
  for (int i = 1; i <= file->num_elem_sets; ++i)
    fetch_set(file, EX_ELEM_SET, i, mesh, fe_mesh_create_element_set);
  for (int i = 1; i <= file->num_face_sets; ++i)
    fetch_set(file, EX_FACE_SET, i, mesh, fe_mesh_create_face_set);
  for (int i = 1; i <= file->num_edge_sets; ++i)
    fetch_set(file, EX_EDGE_SET, i, mesh, fe_mesh_create_edge_set);
  for (int i = 1; i <= file->num_node_sets; ++i)
    fetch_set(file, EX_NODE_SET, i, mesh, fe_mesh_create_node_set);
  for (int i = 1; i <= file->num_side_sets; ++i)
    fetch_set(file, EX_SIDE_SET, i, mesh, fe_mesh_create_side_set);

  return mesh;
}