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();
81 void build_reverse_map_no_lock();
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 bool reorders() const { return !m_reorder.empty(); }
102
103 private:
104 template <typename INT> void reverse_map_data(INT *data, size_t count) const;
105 template <typename INT> void map_data(INT *data, size_t count) const;
106 template <typename INT> void map_implicit_data(INT *data, size_t count, size_t offset) const;
107
108 int64_t global_to_local__(int64_t global, bool must_exist = true) const;
109 void build_reorder_map__(int64_t start, int64_t count);
110 void build_reverse_map__(int64_t num_to_get, int64_t offset);
111 void verify_no_duplicate_ids(std::vector<Ioss::IdPair> &reverse_map);
112
113 #if defined(IOSS_THREADSAFE)
114 mutable std::mutex m_;
115 #endif
116 MapContainer m_map;
117 MapContainer m_reorder;
118 ReverseMapContainer m_reverse;
119 std::string m_entityType{"unknown"}; // node, element, edge, face
120 std::string m_filename{"undefined"}; // For error messages only.
121 int64_t m_offset{-1}; // local to global offset if m_map is sequential.
122 int m_myProcessor{0}; // For error messages...
123 bool m_defined{false}; // For use by some clients; not all, so don't read too much into value...
124 };
125 } // namespace Ioss
126
127 #endif // IOSS_Ioss_Map_h
Ioss::Map::set_default
void set_default(size_t count, size_t offset=0)
Definition: Ioss_Map.C:337
Ioss::Map::size
size_t size() const
Definition: Ioss_Map.h:66
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss::Map::m_defined
bool m_defined
Definition: Ioss_Map.h:123
Ioss::Map::build_reverse_map__
void build_reverse_map__(int64_t num_to_get, int64_t offset)
Definition: Ioss_Map.C:167
Ioss::Map::verify_no_duplicate_ids
void verify_no_duplicate_ids(std::vector< Ioss::IdPair > &reverse_map)
Definition: Ioss_Map.C:243
Ioss::Map::map
MapContainer & map()
Definition: Ioss_Map.h:96
Ioss::Map::set_size
void set_size(size_t entity_count)
Definition: Ioss_Map.C:150
Ioss::Map::release_memory
void release_memory()
Definition: Ioss_Map.C:108
Ioss::Map::m_myProcessor
int m_myProcessor
Definition: Ioss_Map.h:122
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
anonymous_namespace{Iovs_DatabaseIO.C}::entity_type
entity_type
Definition: Iovs_DatabaseIO.C:81
Ioss::Map::m_reorder
MapContainer m_reorder
Definition: Ioss_Map.h:117
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::Map::build_reverse_map
void build_reverse_map()
Definition: Ioss_Map.C:159
Ioss::Map::map_field_to_db_scalar_order
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:459
Ioss::IdPair
std::pair< int64_t, int64_t > IdPair
Definition: Ioss_Map.h:49
Ioss::Map::build_reorder_map__
void build_reorder_map__(int64_t start, int64_t count)
Definition: Ioss_Map.C:488
Ioss::Map::global_to_local__
int64_t global_to_local__(int64_t global, bool must_exist=true) const
Definition: Ioss_Map.C:560
Ioss::Map::Map
Map(std::string entity_type, std::string file_name, int processor)
Definition: Ioss_Map.h:56
Ioss::Map::m_map
MapContainer m_map
Definition: Ioss_Map.h:116
Ioss::Map::global_to_local
int64_t global_to_local(int64_t global, bool must_exist=true) const
Definition: Ioss_Map.C:554
Ioss::Map::map_implicit_data
void map_implicit_data(void *data, const Ioss::Field &field, size_t count, size_t offset) const
Definition: Ioss_Map.C:434
Ioss::Map::build_reverse_map_no_lock
void build_reverse_map_no_lock()
Definition: Ioss_Map.C:160
Ioss::Map::m_offset
int64_t m_offset
Definition: Ioss_Map.h:121
Ioss::Map::operator=
Map & operator=(const Map &from)=delete
Ioss::ReverseMapContainer
std::vector< IdPair > ReverseMapContainer
Definition: Ioss_Map.h:50
Ioss::Map::m_filename
std::string m_filename
Definition: Ioss_Map.h:120
Ioss::Map::set_is_sequential
void set_is_sequential(bool yesno)
Definition: Ioss_Map.h:68
Ioss::Map
Definition: Ioss_Map.h:52
Ioss::Map::map
const MapContainer & map() const
Definition: Ioss_Map.h:95
Ioss::Map::Map
Map()=default
Ioss::Map::reverse_map_data
void reverse_map_data(void *data, const Ioss::Field &field, size_t count) const
Release memory for all maps.
Definition: Ioss_Map.C:368
Ioss::Map::set_defined
void set_defined(bool yes_no)
Definition: Ioss_Map.h:99
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Ioss::Map::m_reverse
ReverseMapContainer m_reverse
Definition: Ioss_Map.h:118
Ioss::Map::is_sequential
bool is_sequential(bool check_all=false) const
Definition: Ioss_Map.C:117
Ioss::Map::~Map
~Map()=default
Ioss::Map::reorders
bool reorders() const
Definition: Ioss_Map.h:101
Ioss::Map::defined
bool defined() const
Definition: Ioss_Map.h:98
Ioss::Map::set_map
bool set_map(INT *ids, size_t count, size_t offset, bool in_define_mode=true)
Definition: Ioss_Map.C:264
Ioss::Map::m_entityType
std::string m_entityType
Definition: Ioss_Map.h:119
Ioss::MapContainer
std::vector< int64_t > MapContainer
Definition: Ioss_Map.h:48
Ioss::Map::map_data
void map_data(void *data, const Ioss::Field &field, size_t count) const
Definition: Ioss_Map.C:400
Ioss_CodeTypes.h