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