Loading...
Searching...
No Matches
interface.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include <cmath>
26
27#include "bitpit_common.hpp"
28#include "bitpit_operators.hpp"
29
30#include "cell.hpp"
31#include "interface.hpp"
32
33namespace bitpit {
34
48 : Element()
49{
50 _initialize(NULL_ID, -1, NULL_ID, -1);
51}
52
60 : Element(id, type)
61{
62 _initialize(NULL_ID, -1, NULL_ID, -1);
63}
64
73Interface::Interface(long id, ElementType type, int connectSize)
74 : Element(id, type, connectSize)
75{
76 _initialize(NULL_ID, -1, NULL_ID, -1);
77}
78
87Interface::Interface(long id, ElementType type, std::unique_ptr<long[]> &&connectStorage)
88 : Element(id, type, std::move(connectStorage))
89{
90 _initialize(NULL_ID, -1, NULL_ID, -1);
91}
92
100void Interface::swap(Interface &other) noexcept
101{
102 Element::swap(other);
103
104 std::swap(other.m_owner, m_owner);
105 std::swap(other.m_ownerFace, m_ownerFace);
106 std::swap(other.m_neigh, m_neigh);
107 std::swap(other.m_neighFace, m_neighFace);
108}
109
117{
118 Element::initialize(id, type);
119
120 _initialize(NULL_ID, -1, NULL_ID, -1);
121}
122
131void Interface::initialize(long id, ElementType type, int connectSize)
132{
133 Element::initialize(id, type, connectSize);
134
135 _initialize(NULL_ID, -1, NULL_ID, -1);
136}
137
146void Interface::initialize(long id, ElementType type, std::unique_ptr<long[]> &&connectStorage)
147{
148 Element::initialize(id, type, std::move(connectStorage));
149
150 _initialize(NULL_ID, -1, NULL_ID, -1);
151}
152
161void Interface::_initialize(long owner, long ownerFace, long neigh, long neighFace)
162{
163 m_owner = owner;
164 m_ownerFace = ownerFace;
165
166 m_neigh = neigh;
167 m_neighFace = neighFace;
168}
169
192std::array<std::array<double, 3>, 3> Interface::evalRotationFromCartesian(std::array<double, 3> &versor)
193{
194 // The rotation matrix has in its rows the versors that define
195 // the interface coordinate system.
196 //
197 // | [x_int] |
198 // R = | [y_int] |
199 // | [z_int] |
200 //
201 std::array<std::array<double, 3>, 3> R = {{{{0., 0., 0.}}, {{0., 0., 0.}}, {{0., 0., 0.}}}};
202
203 // x-interface axis
204 for (int k = 0; k < 3; ++k) {
205 R[0][k] = versor[k];
206 }
207
208 // y-interface axis
209 if (std::abs(std::abs(versor[2]) - 1.) > 1e-8) {
210 std::array<double, 3> z = {{0.0, 0.0, 1.0}};
211 R[1] = crossProduct(z, R[0]);
212 } else {
213 std::array<double, 3> x = {{1.0, 0.0, 0.0}};
214 R[1] = crossProduct(x, R[0]);
215 }
216 R[1] = R[1] / norm2(R[1]);
217
218 // z-interface axis
219 R[2] = crossProduct(R[0], R[1]);
220 R[2] = R[2] / norm2(R[2]);
221
222 return R;
223}
224
243std::array<std::array<double, 3>, 3> Interface::evalRotationToCartesian(std::array<double, 3> &versor)
244{
246}
247
257std::array<std::array<double, 3>, 3> Interface::evalRotationInverse(const std::array<std::array<double, 3>, 3> &R)
258{
259 return evalRotationTranspose(R);
260}
261
268std::array<std::array<double, 3>, 3> Interface::evalRotationTranspose(const std::array<std::array<double, 3>, 3> &R)
269{
270 std::array<std::array<double, 3>, 3> R_transposed = {{{{0., 0., 0.}}, {{0., 0., 0.}}, {{0., 0., 0.}}}};
271 for (int i = 0; i < 3; i++) {
272 for (int j = 0; j < 3; j++) {
273 R_transposed[j][i] = R[i][j];
274 }
275 }
276
277 return R_transposed;
278}
279
286{
287 return (m_neigh < 0);
288}
289
296void Interface::setOwner(long owner, int onwerFace)
297{
298 m_owner = owner;
299 m_ownerFace = onwerFace;
300}
301
306{
307 m_owner = Element::NULL_ID;
308 m_ownerFace = -1;
309}
310
317{
318 return m_owner;
319}
320
327{
328 return m_ownerFace;
329}
330
337void Interface::setNeigh(long neigh, int neighFace)
338{
339 m_neigh = neigh;
340 m_neighFace = neighFace;
341}
342
347{
348 m_neigh = Element::NULL_ID;
349 m_neighFace = -1;
350}
351
358{
359 return m_neigh;
360}
361
368{
369 return m_neighFace;
370}
371
378std::array<long, 2> Interface::getOwnerNeigh() const
379{
380 return {{m_owner, m_neigh}};
381}
382
390void Interface::display(std::ostream &out, unsigned short int indent) const
391{
392 std::string t_s = std::string(indent, ' ');
393
394 // If the type is unknown there are no information to display
395 if (getType() == ElementType::UNDEFINED) {
396 out << t_s << "interface type: (unknown)" << std::endl;
397 return;
398 }
399
400 // General info ----------------------------------------------------- //
401 out << t_s << "interface type: " << getType() << std::endl;
402 out << t_s << "ID: " << getId() << std::endl;
403 out << t_s << "is border: ";
404 if (getNeigh() >= 0) { out << "(false)"; }
405 else { out << "(true)"; }
406 out << std::endl;
407
408 // Connectivity infos --------------------------------------------------- //
409 int nVertices = getVertexCount();
410 ConstProxyVector<long> cellVertexIds = getVertexIds();
411 out << t_s << "connectivity: [ ";
412 for (int i = 0; i < nVertices - 1; ++i) {
413 out << cellVertexIds[i] << ", ";
414 } //next i
415 out << cellVertexIds[nVertices - 1] << " ]" << std::endl;
416
417 // Onwer infos ---------------------------------------------------------- //
418 out << t_s << "onwer ID: " << getOwner() << std::endl;
419 out << t_s << "owner face: " << getOwnerFace() << std::endl;
420
421 // Onwer infos ---------------------------------------------------------- //
422 if (getNeigh() >= 0) {
423 out << t_s << "neighbour ID: " << getNeigh() << std::endl;
424 out << t_s << "neighbour face: " << getNeighFace() << std::endl;
425 }
426}
427
428// Explicit instantiation of the Interface containers
429template class PiercedVector<Interface>;
430
433
434}
The Element class provides an interface for defining elements.
Definition element.hpp:46
long getId() const
Definition element.cpp:510
ElementType getType() const
Definition element.cpp:551
void swap(Element &other) noexcept
Definition element.cpp:399
ConstProxyVector< long > getVertexIds() const
Definition element.cpp:1181
void initialize(long id, ElementType type, int connectSize=0)
Definition element.cpp:415
int getVertexCount() const
Definition element.cpp:1152
The Interface class defines the interfaces among cells.
Definition interface.hpp:37
long getNeigh() const
static std::array< std::array< double, 3 >, 3 > evalRotationInverse(const std::array< std::array< double, 3 >, 3 > &R)
void setOwner(long owner, int onwerFace)
long getOwner() const
void initialize(long id, ElementType type)
void setNeigh(long neigh, int neighFace)
bool isBorder() const
std::array< long, 2 > getOwnerNeigh() const
int getOwnerFace() const
static std::array< std::array< double, 3 >, 3 > evalRotationTranspose(const std::array< std::array< double, 3 >, 3 > &R)
static std::array< std::array< double, 3 >, 3 > evalRotationToCartesian(std::array< double, 3 > &versor)
void swap(Interface &other) noexcept
static std::array< std::array< double, 3 >, 3 > evalRotationFromCartesian(std::array< double, 3 > &versor)
int getNeighFace() const
void display(std::ostream &out, unsigned short int indent) const
Metafunction for generating a pierced vector.
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
The QualifiedInterfaceHalfEdge class defines interface half-edges.
Definition interface.hpp:84
std::array< T, 3 > crossProduct(const std::array< T, 3 > &x, const std::array< T, 3 > &y)
double norm2(const std::array< T, d > &x)
--- layout: doxygen_footer ---