IOSS  2.0
Ioss_Map.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 #ifndef IOSS_Ioss_Map_h
34 #define IOSS_Ioss_Map_h
35 
36 #include <Ioss_CodeTypes.h>
37 #include <cstddef> // for size_t
38 #include <cstdint> // for int64_t
39 #include <string> // for string
40 #include <utility> // for pair
41 #include <vector> // for vector
42 namespace Ioss {
43  class Field;
44 } // namespace Ioss
45 
46 namespace Ioss {
47 
48  using MapContainer = std::vector<int64_t>;
49  using IdPair = std::pair<int64_t, int64_t>;
50  using ReverseMapContainer = std::vector<IdPair>;
51 
52  class Map
53  {
54  public:
55  Map() = default;
56  Map(std::string entity_type, std::string file_name, int processor)
57  : m_entityType(std::move(entity_type)), m_filename(std::move(file_name)),
58  m_myProcessor(processor)
59  {
60  }
61  Map(const Map &from) = delete;
62  Map &operator=(const Map &from) = delete;
63  ~Map() = default;
64 
65  void set_size(size_t entity_count);
66  size_t size() const { return m_map.empty() ? 0 : m_map.size() - 1; }
67 
68  void set_is_sequential(bool yesno) { m_map[0] = yesno ? -1 : 1; }
69 
70  // Determines whether the input map is sequential (m_map[i] == i)
71  bool is_sequential(bool check_all = false) const;
72 
73  int64_t global_to_local(int64_t global, bool must_exist = true) const;
74 
75  template <typename INT>
76  bool set_map(INT *ids, size_t count, size_t offset, bool in_define_mode = true);
77 
78  void set_default(size_t count, size_t offset = 0);
79 
80  void build_reverse_map();
82  void build_reverse_map(int64_t num_to_get, int64_t offset);
83 
84  void release_memory(); //! Release memory for all maps.
85 
86  void reverse_map_data(void *data, const Ioss::Field &field, size_t count) const;
87  void map_data(void *data, const Ioss::Field &field, size_t count) const;
88  void map_implicit_data(void *data, const Ioss::Field &field, size_t count, size_t offset) const;
89 
90  template <typename T>
91  size_t map_field_to_db_scalar_order(T *variables, std::vector<double> &db_var,
92  size_t begin_offset, size_t count, size_t stride,
93  size_t offset);
94 
95  const MapContainer &map() const { return m_map; }
96  MapContainer & map() { return m_map; }
97 
98  bool defined() const { return m_defined; }
99  void set_defined(bool yes_no) { m_defined = yes_no; }
100 
101  private:
102  template <typename INT> void reverse_map_data(INT *data, size_t count) const;
103  template <typename INT> void map_data(INT *data, size_t count) const;
104  template <typename INT> void map_implicit_data(INT *data, size_t count, size_t offset) const;
105 
106  int64_t global_to_local__(int64_t global, bool must_exist = true) const;
107  void build_reorder_map__(int64_t start, int64_t count);
108  void build_reverse_map__(int64_t num_to_get, int64_t offset);
109  void verify_no_duplicate_ids(std::vector<Ioss::IdPair> &reverse_map);
110 
111 #if defined(IOSS_THREADSAFE)
112  mutable std::mutex m_;
113 #endif
117  std::string m_entityType{"unknown"}; // node, element, edge, face
118  std::string m_filename{"undefined"}; // For error messages only.
119  int64_t m_offset{-1}; // local to global offset if m_map is sequential.
120  int m_myProcessor{0}; // For error messages...
121  bool m_defined{false}; // For use by some clients; not all, so don't read too much into value...
122  };
123 } // namespace Ioss
124 
125 #endif // IOSS_Ioss_Map_h
bool is_sequential(bool check_all=false) const
Definition: Ioss_Map.C:116
void release_memory()
Definition: Ioss_Map.C:107
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
void build_reverse_map()
Definition: Ioss_Map.C:158
void set_default(size_t count, size_t offset=0)
Definition: Ioss_Map.C:333
std::pair< int64_t, int64_t > IdPair
Definition: Ioss_Map.h:49
int64_t global_to_local__(int64_t global, bool must_exist=true) const
Definition: Ioss_Map.C:550
Definition: json.h:1157
size_t map_field_to_db_scalar_order(T *variables, std::vector< double > &db_var, size_t begin_offset, size_t count, size_t stride, size_t offset)
Definition: Ioss_Map.C:449
void build_reverse_map__(int64_t num_to_get, int64_t offset)
Definition: Ioss_Map.C:166
int64_t global_to_local(int64_t global, bool must_exist=true) const
Definition: Ioss_Map.C:544
MapContainer & map()
Definition: Ioss_Map.h:96
void set_size(size_t entity_count)
Definition: Ioss_Map.C:149
Map & operator=(const Map &from)=delete
MapContainer m_reorder
Definition: Ioss_Map.h:115
void map_implicit_data(void *data, const Ioss::Field &field, size_t count, size_t offset) const
Definition: Ioss_Map.C:424
void build_reverse_map_no_lock()
Definition: Ioss_Map.C:159
int m_myProcessor
Definition: Ioss_Map.h:120
void set_defined(bool yes_no)
Definition: Ioss_Map.h:99
int64_t m_offset
Definition: Ioss_Map.h:119
~Map()=default
void set_is_sequential(bool yesno)
Definition: Ioss_Map.h:68
std::vector< int64_t > MapContainer
Definition: Ioss_Map.h:48
bool defined() const
Definition: Ioss_Map.h:98
ReverseMapContainer m_reverse
Definition: Ioss_Map.h:116
void map_data(void *data, const Ioss::Field &field, size_t count) const
Definition: Ioss_Map.C:392
int INT
Definition: Ioss_StructuredBlock.h:53
Definition: Ioss_Map.h:52
std::vector< IdPair > ReverseMapContainer
Definition: Ioss_Map.h:50
void build_reorder_map__(int64_t start, int64_t count)
Definition: Ioss_Map.C:478
std::string m_entityType
Definition: Ioss_Map.h:117
MapContainer m_map
Definition: Ioss_Map.h:114
Map(std::string entity_type, std::string file_name, int processor)
Definition: Ioss_Map.h:56
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
bool m_defined
Definition: Ioss_Map.h:121
void verify_no_duplicate_ids(std::vector< Ioss::IdPair > &reverse_map)
Definition: Ioss_Map.C:241
size_t size() const
Definition: Ioss_Map.h:66
const MapContainer & map() const
Definition: Ioss_Map.h:95
Map()=default
void reverse_map_data(void *data, const Ioss::Field &field, size_t count) const
Release memory for all maps.
Definition: Ioss_Map.C:362
entity_type
Definition: Iovs_DatabaseIO.C:81
std::vector< char > data
Definition: Ioss_Utils.C:78
std::string m_filename
Definition: Ioss_Map.h:118
bool set_map(INT *ids, size_t count, size_t offset, bool in_define_mode=true)
Definition: Ioss_Map.C:261