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 class Range;
27
28 //! Interface implemented in MOAB which provides memory for mesh reading utilities
29 class ReadUtilIface
30 {
31 public:
32
33 //! Constructor
ReadUtilIface()34 ReadUtilIface(){}
35
36 //! Destructor
~ReadUtilIface()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,
89 Range &related_ents,
90 EntityHandle *file_set = NULL) = 0;
91
92 virtual ErrorCode create_entity_sets(EntityID num_sets,
93 const unsigned* set_flags,
94 EntityID preffered_start_id,
95 EntityHandle& actual_start_handle) = 0;
96
97 //! Update adjacencies
98 //! Given information about new elements, adjacency information will be updated
99 //! in MOAB. Think of this function as a way of Readers telling MOAB what elements are
100 //! new because we aren't using the Interface to create elements.
101 //! \param start_handle Handle of first new element
102 //! \param number_elements Number of new elements
103 //! \param number_vertices_per_element Number of vertices in each new element
104 //! \param conn_array Connectivity of new elements
105 //! \return status Success/failure of this call
106 virtual ErrorCode update_adjacencies(const EntityHandle start_handle,
107 const int number_elements,
108 const int number_vertices_per_element,
109 const EntityHandle* conn_array) = 0;
110
111 /**\brief Re-order incoming element connectivity
112 *
113 * Permute the connectivity of each element such that the node
114 * order is that of MBCN rather than the target file format.
115 *\param order The permutation to use. Must be an array of 'node_per_elem'
116 * integers and be a permutation of the values [0..node_per_elem-1].
117 * Such that for a single element:
118 * mbcn_conn[order[i]] == target_conn[i]
119 *\param conn The connectivity array to re-order
120 *\param num_elem The number of elements in the connectivity array
121 *\param node_per_elem The number of nodes in each element's connectivity list.
122 */
123 static inline void reorder(const int* order, EntityHandle* conn,
124 int num_elem, int node_per_elem);
125
126 //! Given an ordered list of bounding entities and the sense of
127 //! those entities, return an ordered list of vertices
128 virtual ErrorCode get_ordered_vertices(EntityHandle *bound_ents,
129 int *sense,
130 int num_bound,
131 int dim,
132 EntityHandle *bound_verts,
133 EntityType &etype) = 0;
134
135 //! Assign sequential IDS to entities in range and store IDs in tag
136 virtual ErrorCode assign_ids(Tag id_tag, const Range& ents,
137 int start = 0 ) = 0;
138
139 //! Assign to each entity in an array the ID that is its position
140 //! in the array plus the value of 'start'. For any non-zero handles
141 //! in the array, store the ID value in the passed tag.
142 virtual ErrorCode assign_ids(Tag id_tag, const EntityHandle* ents,
143 size_t num_ents, int start = 0) = 0;
144
145 //! Create a new gather set with tag GATHER_SET
146 virtual ErrorCode create_gather_set(EntityHandle& gather_set) = 0;
147
148 //! Get entity handle of an existing gather set
149 virtual ErrorCode get_gather_set(EntityHandle& gather_set) = 0;
150 };
151
reorder(const int * order,EntityHandle * conn,int num_elem,int node_per_elem)152 inline void ReadUtilIface::reorder(const int* order, EntityHandle* conn,
153 int num_elem, int node_per_elem)
154 {
155 std::vector<EntityHandle> elem(node_per_elem);
156 EntityHandle* const end = conn + num_elem*node_per_elem;
157 while (conn != end) {
158 std::copy(conn, conn + node_per_elem, elem.begin());
159 for (int j = 0; j < node_per_elem; ++j)
160 conn[order[j]] = elem[j];
161 conn += node_per_elem;
162 }
163 }
164
165 } // namespace moab
166
167 #endif
168