Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
ReadUtilIface.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifndef MOAB_READ_UTIL_IFACE_HPP
17 #define MOAB_READ_UTIL_IFACE_HPP
18 
19 #include <vector>
20 #include <string>
21 #include "moab/Types.hpp"
22 #include "moab/Compiler.hpp"
23 
24 namespace moab
25 {
26 
27 class Range;
28 
29 //! Interface implemented in MOAB which provides memory for mesh reading utilities
31 {
32  public:
33  //! Constructor
35 
36  //! Destructor
37  virtual ~ReadUtilIface() {}
38 
39  //! Given a requested number of vertices and number of coordinates, returns
40  //! memory space which will be used to store vertex coordinates and information
41  //! about what handles those new vertices are assigned; allows direct read of
42  //! coordinate data into memory
43  //! \param num_arrays Number of node position arrays requested
44  //! \param num_nodes Number of nodes
45  //! \param preferred_start_id Preferred integer id starting value
46  //! \param actual_start_handle Actual starting id value
47  //! \param arrays STL vector of double*'s, point to memory storage to be used for
48  //! these vertices
49  //! \param sequence_size If specified, allocate this sequence size instead of
50  //! SequenceManager::DEFAULT_VERTEX_SEQUENCE_SIZE
51  //! \return status Success/failure of this call
52  virtual ErrorCode get_node_coords( const int num_arrays,
53  const int num_nodes,
54  const int preferred_start_id,
55  EntityHandle& actual_start_handle,
56  std::vector< double* >& arrays,
57  const int sequence_size = -1 ) = 0;
58 
59  //! Given requested number of elements, element type, and number of
60  //! elements, returns pointer to memory space allocated to store connectivity
61  //! of those elements; allows direct read of connectivity data into memory
62  //! \param num_elements Number of elements being requested
63  //! \param verts_per_element Number of vertices per element (incl. higher-order nodes)
64  //! \param mdb_type Element type
65  //! \param preferred_start_id Preferred integer id for first element
66  //! \param actual_start_handle Actual integer id for first element (returned)
67  //! \param array Pointer to memory allocated for storing connectivity for these elements
68  //! \param sequence_size If specified, allocate this sequence size instead of
69  //! SequenceManager::DEFAULT_VERTEX_SEQUENCE_SIZE
70  //! \return status Success/failure of this call
71  virtual ErrorCode get_element_connect( const int num_elements,
72  const int verts_per_element,
73  const EntityType mdb_type,
74  const int preferred_start_id,
75  EntityHandle& actual_start_handle,
76  EntityHandle*& array,
77  int sequence_size = -1 ) = 0;
78 
79  /**
80  *\brief Gather entities related to those in the partition
81  * Gather entities related to those in the input partition. Related
82  * means down-adjacent to, contained in, etc.
83  * \param partition Entities for which to gather related entities
84  * \param related_ents Related entities
85  * \param file_set If non-NULL, entity sets contained in this set will be checked;
86  * otherwise, all sets in the instance will be checked
87  */
88  virtual ErrorCode gather_related_ents( Range& partition, Range& related_ents, EntityHandle* file_set = NULL ) = 0;
89 
91  const unsigned* set_flags,
92  EntityID preffered_start_id,
93  EntityHandle& actual_start_handle ) = 0;
94 
95  //! Update adjacencies
96  //! Given information about new elements, adjacency information will be updated
97  //! in MOAB. Think of this function as a way of Readers telling MOAB what elements are
98  //! new because we aren't using the Interface to create elements.
99  //! \param start_handle Handle of first new element
100  //! \param number_elements Number of new elements
101  //! \param number_vertices_per_element Number of vertices in each new element
102  //! \param conn_array Connectivity of new elements
103  //! \return status Success/failure of this call
104  virtual ErrorCode update_adjacencies( const EntityHandle start_handle,
105  const int number_elements,
106  const int number_vertices_per_element,
107  const EntityHandle* conn_array ) = 0;
108 
109  /**\brief Re-order incoming element connectivity
110  *
111  * Permute the connectivity of each element such that the node
112  * order is that of MBCN rather than the target file format.
113  *\param order The permutation to use. Must be an array of 'node_per_elem'
114  * integers and be a permutation of the values [0..node_per_elem-1].
115  * Such that for a single element:
116  * mbcn_conn[order[i]] == target_conn[i]
117  *\param conn The connectivity array to re-order
118  *\param num_elem The number of elements in the connectivity array
119  *\param node_per_elem The number of nodes in each element's connectivity list.
120  */
121  static inline void reorder( const int* order, EntityHandle* conn, int num_elem, int node_per_elem );
122 
123  //! Given an ordered list of bounding entities and the sense of
124  //! those entities, return an ordered list of vertices
126  int* sense,
127  int num_bound,
128  int dim,
129  EntityHandle* bound_verts,
130  EntityType& etype ) = 0;
131 
132  //! Assign sequential IDS to entities in range and store IDs in tag
133  virtual ErrorCode assign_ids( Tag id_tag, const Range& ents, int start = 0 ) = 0;
134 
135  //! Assign to each entity in an array the ID that is its position
136  //! in the array plus the value of 'start'. For any non-zero handles
137  //! in the array, store the ID value in the passed tag.
138  virtual ErrorCode assign_ids( Tag id_tag, const EntityHandle* ents, size_t num_ents, int start = 0 ) = 0;
139 
140  //! Create a new gather set with tag GATHER_SET
141  virtual ErrorCode create_gather_set( EntityHandle& gather_set ) = 0;
142 
143  //! Get entity handle of an existing gather set
144  virtual ErrorCode get_gather_set( EntityHandle& gather_set ) = 0;
145 };
146 
147 inline void ReadUtilIface::reorder( const int* order, EntityHandle* conn, int num_elem, int node_per_elem )
148 {
149  std::vector< EntityHandle > elem( node_per_elem );
150  EntityHandle* const end = conn + num_elem * node_per_elem;
151  while( conn != end )
152  {
153  std::copy( conn, conn + node_per_elem, elem.begin() );
154  for( int j = 0; j < node_per_elem; ++j )
155  conn[order[j]] = elem[j];
156  conn += node_per_elem;
157  }
158 }
159 
160 } // namespace moab
161 
162 #endif