Loading...
Searching...
No Matches
pointConstraint.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2024-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
35 const char* const pTraits<pointConstraint>::typeName = "pointConstraint";
38 (
41 );
42}
43
44
45// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
46
47namespace
48{
49
50// Binary reading of <label, vector> tuple from a different precision
51//
52// NOTE: cannot simply use readRawLabel, readRawScalar since the tuple
53// may include trailing padding and/or padding between its members
54
55template<class IntType, class FloatType>
56static void reading
57(
58 Foam::Istream& is,
60 size_t nElem
61)
62{
63 using namespace Foam;
64
65 // (label, vector) in the specified read precision
66 typedef Tuple2<IntType, Vector<FloatType>> inputType;
67
68 for (const pointConstraint* last = data + nElem; data != last; ++data)
69 {
70 inputType tup;
71
72 is.readRaw(reinterpret_cast<char*>(&tup), sizeof(inputType));
73
74 if constexpr (sizeof(Foam::label) < sizeof(IntType))
75 {
76 // Narrowing: currently only need (int32_t <- int64_t)
77 data->first() = Foam::narrowInt32(tup.first());
78 }
79 else
80 {
81 data->first() = tup.first();
82 }
83
84 if constexpr (sizeof(Foam::scalar) < sizeof(FloatType))
85 {
86 // Narrowing: currently only need (float <- double)
87 data->second().x() = Foam::narrowFloat(tup.second().x());
88 data->second().y() = Foam::narrowFloat(tup.second().y());
89 data->second().z() = Foam::narrowFloat(tup.second().z());
90 }
91 else
92 {
93 data->second().x() = tup.second().x();
94 data->second().y() = tup.second().y();
95 data->second().z() = tup.second().z();
96 }
97 }
98}
99
100} // End anonymous namespace
102
103// * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
104
105// Binary reading of Tuple2<label, vector>
106
107template<>
109(
110 Istream& is,
111 char* byteData,
112 std::streamsize byteCount
113)
114{
115 if (is.checkNativeSizes())
116 {
117 // Native label/scalar sizes
118 is.read(byteData, byteCount);
119 }
120 else
121 {
122 // Non-native label/scalar size
123 is.beginRawRead();
124
125 auto* data = reinterpret_cast<pointConstraint*>(byteData);
126 const auto nElem = (byteCount/sizeof(pointConstraint));
127
128 switch ((is.labelByteSize() << 8) | is.scalarByteSize())
129 {
130 case ((sizeof(int32_t) << 8) | sizeof(float)) :
131 {
132 reading<int32_t, float>(is, data, nElem);
133 break;
134 }
135 case ((sizeof(int32_t) << 8) | sizeof(double)) :
136 {
137 reading<int32_t, double>(is, data, nElem);
138 break;
139 }
140 case ((sizeof(int64_t) << 8) | sizeof(float)) :
141 {
142 reading<int32_t, float>(is, data, nElem);
143 break;
144 }
145 case ((sizeof(int64_t) << 8) | sizeof(double)) :
146 {
147 reading<int32_t, double>(is, data, nElem);
148 break;
149 }
150 default:
151 {
152 // Unknown combination
154 break;
155 }
156 }
157
158 is.endRawRead();
159 }
160}
161
162
163// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
Definition IOstream.H:340
bool checkNativeSizes() const noexcept
Test if the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.H:386
bool fatalCheckNativeSizes(const char *operation) const
Assert that the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.C:67
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
Definition IOstream.H:332
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
virtual bool endRawRead()=0
End of low-level raw binary read.
virtual bool beginRawRead()=0
Start of low-level raw binary read.
virtual Istream & readRaw(char *data, std::streamsize count)=0
Low-level raw binary read (without possible block delimiters). Reading into a null pointer shall idea...
virtual Istream & read(token &)=0
Return next token from stream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition Tuple2.H:51
const T1 & first() const noexcept
Access the first element.
Definition Tuple2.H:132
const T2 & second() const noexcept
Access the second element.
Definition Tuple2.H:142
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition Vector.H:145
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
Accumulates point constraints through successive applications of the applyConstraint function.
#define FUNCTION_NAME
void readContiguous(Istream &is, char *data, std::streamsize byteCount)
Read binary block of contiguous data, possibly with conversion.
Definition Istream.H:322
Namespace for OpenFOAM.
List< pointConstraint > pointConstraintList
List of pointConstraint.
constexpr int32_t narrowInt32(const int64_t val) noexcept
Type narrowing from int64_t to int32_t.
Definition label.H:248
constexpr float narrowFloat(const double val) noexcept
Type narrowing from double to float.
Definition scalar.H:278
#define addCompoundToRunTimeSelectionTable(Type, Tag)
Add compound to selection tables, lookup using typeName.
Definition token.H:1463
#define defineCompoundTypeName(Type, UnusedTag)
Define compound using Type for its name.
Definition token.H:1451