IOSS 2.0
Loading...
Searching...
No Matches
Ioss_ZoneConnectivity.h
Go to the documentation of this file.
1// Copyright(C) 1999-2024 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// See packages/seacas/LICENSE for details
6
7#pragma once
8
9#include "Ioss_CodeTypes.h"
10#include <array>
11#include <cassert>
12#include <cmath>
13#include <iosfwd>
14#include <stdlib.h>
15#include <string>
16#include <vector>
17
18#include "ioss_export.h"
19
20namespace Ioss {
21 class Region;
22
23 struct IOSS_EXPORT ZoneConnectivity
24 {
25 // cereal requires a default constructor when de-serializing vectors of objects. Because
26 // StructuredBlock contains a vector of ZoneConnectivity objects, this default constructor is
27 // necessary.
28 ZoneConnectivity() = default;
29
30 ZoneConnectivity(std::string name, int owner_zone, std::string donor_name, int donor_zone,
31 const Ioss::IJK_t p_transform, const Ioss::IJK_t range_beg,
32 const Ioss::IJK_t range_end, const Ioss::IJK_t donor_beg,
33 const Ioss::IJK_t donor_end, const Ioss::IJK_t owner_offset = IJK_t(),
34 const Ioss::IJK_t donor_offset = IJK_t())
35 : m_connectionName(std::move(name)), m_donorName(std::move(donor_name)),
36 m_transform(p_transform), m_ownerRangeBeg(range_beg), m_ownerRangeEnd(range_end),
37 m_ownerOffset(owner_offset), m_donorRangeBeg(donor_beg), m_donorRangeEnd(donor_end),
38 m_donorOffset(donor_offset), m_ownerZone(owner_zone), m_donorZone(donor_zone)
39 {
40 assert(is_valid());
41 m_ownsSharedNodes = m_ownerZone < m_donorZone || m_donorZone == -1;
42 m_isActive = has_faces();
43 }
44
45 ZoneConnectivity(std::string name, int owner_zone, std::string donor_name, int donor_zone,
46 Ioss::IJK_t p_transform, Ioss::IJK_t range_beg, Ioss::IJK_t range_end,
47 Ioss::IJK_t donor_beg, Ioss::IJK_t donor_end, bool owns_nodes,
48 bool from_decomp)
49 : m_connectionName(std::move(name)), m_donorName(std::move(donor_name)),
50 m_transform(p_transform), m_ownerRangeBeg(range_beg), m_ownerRangeEnd(range_end),
51 m_donorRangeBeg(donor_beg), m_donorRangeEnd(donor_end), m_ownerZone(owner_zone),
52 m_donorZone(donor_zone), m_ownsSharedNodes(owns_nodes), m_fromDecomp(from_decomp)
53 {
54 // This constructor typically called from decomposition process.
55 assert(is_valid());
56 m_isActive = has_faces();
57 }
58
59 ZoneConnectivity(const ZoneConnectivity &copy_from) = default;
60 ZoneConnectivity &operator=(const ZoneConnectivity &copy_from) = default;
61
62 // Return number of nodes in the connection shared with the donor zone.
64 {
65 size_t snc = 1;
66 for (int i = 0; i < 3; i++) {
67 snc *= (std::abs(m_ownerRangeEnd[i] - m_ownerRangeBeg[i]) + 1);
68 }
69 return snc;
70 }
71
72 // Validate zgc -- if is_active(), then must have non-zero entries for all ranges.
73 // transform must have valid entries.
74 IOSS_NODISCARD bool is_valid() const;
75 IOSS_NODISCARD bool has_faces() const;
76 IOSS_NODISCARD bool retain_original() const; // True if need to retain in parallel decomp
77
78 IOSS_NODISCARD std::array<int, 9> transform_matrix() const;
79 IOSS_NODISCARD Ioss::IJK_t transform(const Ioss::IJK_t &index_1) const;
80 IOSS_NODISCARD Ioss::IJK_t inverse_transform(const Ioss::IJK_t &index_1) const;
81
82 IOSS_NODISCARD std::vector<int> get_range(int ordinal) const;
83
84 /* COMPARE two ZoneConnectivity objects */
85 IOSS_NODISCARD bool operator==(const Ioss::ZoneConnectivity &rhs) const;
86 IOSS_NODISCARD bool operator!=(const Ioss::ZoneConnectivity &rhs) const;
87 IOSS_NODISCARD bool equal(const Ioss::ZoneConnectivity &rhs) const;
88
89 IOSS_NODISCARD bool is_from_decomp() const { return m_fromDecomp; }
90 IOSS_NODISCARD bool is_active() const { return m_isActive && has_faces(); }
91
92 std::string m_connectionName{}; // Name of the connection; either generated or from file
93 std::string m_donorName{}; // Name of the zone (m_donorZone) to which this zone is connected via
94 // this connection.
95 Ioss::IJK_t m_transform{}; // The transform. In the same form as defined by CGNS
96
97 template <class Archive> void serialize(Archive &archive)
98 {
99 archive(m_connectionName, m_donorName, m_transform, m_ownerRangeBeg, m_ownerRangeEnd,
100 m_ownerOffset, m_donorRangeBeg, m_donorRangeEnd, m_donorOffset, m_ownerGUID,
101 m_donorGUID, m_ownerZone, m_donorZone, m_ownerProcessor, m_donorProcessor,
102 m_sameRange, m_ownsSharedNodes, m_fromDecomp, m_isActive);
103 }
104
105 // The following are all subsetted down to the portion that is actually on this zone
106 // This can be different than m_ownerRange and m_donorRange in a parallel run if the
107 // decomposition splits the connection. In a serial run, they are the same.
108 //
109 // 1 of ijk should be the same for rangeBeg and rangeEnd defining a surface.
110 Ioss::IJK_t m_ownerRangeBeg{}; // ijk triplet defining beginning of range on this zone
111 Ioss::IJK_t m_ownerRangeEnd{}; // ijk triplet defining end of range on this zone
112 Ioss::IJK_t m_ownerOffset{}; // ijk triplet with offset of this zone. Used to convert
113 // rangeBeg and rangeEnd global indices to local indices
114 Ioss::IJK_t m_donorRangeBeg{}; // ijk triplet defining beginning of range on the connected zone
115 Ioss::IJK_t m_donorRangeEnd{}; // ijk triplet defining end of range on the connected zone
116 Ioss::IJK_t m_donorOffset{}; // ijk triplet with offset of the donor zone. Used to convert
117 // donorRangeBeg and End global indices to local indices
118
119 size_t m_ownerGUID{}; // globally-unique id of owner
120 size_t m_donorGUID{}; // globally-unique id of donor
121
122 // NOTE: Shared nodes are "owned" by the zone with the lowest zone id.
123 int m_ownerZone{}; // "id" of zone that owns this connection
124 int m_donorZone{}; // "id" of zone that is donor (or other side) of this connection
125 int m_ownerProcessor{-1}; // processor that owns the owner zone
126 int m_donorProcessor{-1}; // processor that owns the donor zone
127 bool m_sameRange{false}; // True if owner and donor range should always match...(special use
128 // during decomp)
129 // True if it is the "lower" zone id in the connection. Uses adam unless both have same adam.
130 bool m_ownsSharedNodes{false}; // Deprecate soon
131
132 // True if this zc is created due to processor decompositions in a parallel run
133 mutable bool m_fromDecomp{false};
134
135 bool m_isActive{true}; // True if non-zero range. That is, it has at least one face
136
137 private:
138 bool equal_(const Ioss::ZoneConnectivity &rhs, bool quiet) const;
139 };
140
141 IOSS_EXPORT std::ostream &operator<<(std::ostream &os, const ZoneConnectivity &zgc);
142} // namespace Ioss
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
std::ostream & operator<<(std::ostream &os, const Field &fld)
Definition Ioss_Field.C:41
std::array< int, 3 > IJK_t
Definition Ioss_CodeTypes.h:24
Definition Ioss_ZoneConnectivity.h:24
ZoneConnectivity(const ZoneConnectivity &copy_from)=default
IOSS_NODISCARD bool is_from_decomp() const
Definition Ioss_ZoneConnectivity.h:89
IOSS_NODISCARD size_t get_shared_node_count() const
Definition Ioss_ZoneConnectivity.h:63
ZoneConnectivity(std::string name, int owner_zone, std::string donor_name, int donor_zone, const Ioss::IJK_t p_transform, const Ioss::IJK_t range_beg, const Ioss::IJK_t range_end, const Ioss::IJK_t donor_beg, const Ioss::IJK_t donor_end, const Ioss::IJK_t owner_offset=IJK_t(), const Ioss::IJK_t donor_offset=IJK_t())
Definition Ioss_ZoneConnectivity.h:30
void serialize(Archive &archive)
Definition Ioss_ZoneConnectivity.h:97
ZoneConnectivity(std::string name, int owner_zone, std::string donor_name, int donor_zone, Ioss::IJK_t p_transform, Ioss::IJK_t range_beg, Ioss::IJK_t range_end, Ioss::IJK_t donor_beg, Ioss::IJK_t donor_end, bool owns_nodes, bool from_decomp)
Definition Ioss_ZoneConnectivity.h:45
ZoneConnectivity & operator=(const ZoneConnectivity &copy_from)=default
IOSS_NODISCARD bool is_active() const
Definition Ioss_ZoneConnectivity.h:90