BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_check_facet_orientation.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California, through
4 * Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_FN_CHECK_FACET_ORIENTATION_HPP
13#define BELFEM_FN_CHECK_FACET_ORIENTATION_HPP
14#include "assert.hpp"
15#include "cl_Facet.hpp"
16#include "cl_Element.hpp"
17namespace belfem
18{
19 namespace mesh
20 {
51 inline bool
52 check_facet_orientation( const Facet * aA, const Facet * aB )
53 {
54 const Element * tA = aA->element();
55 const Element * tB = aB->element();
58
59 if ( n == 2 && m == 2 )
60 {
61 id_t tA0 = tA->node( 0 )->original()->id();
62 id_t tA1 = tA->node( 1 )->original()->id();
63 id_t tB0 = tB->node( 0 )->original()->id();
64 id_t tB1 = tB->node( 1 )->original()->id();
65
66 // B continues A's traversal ( or reversed twin ): consistent
67 if ( tA1 == tB0 || tA0 == tB1 )
68 {
69 return true;
70 }
71
72 // both start or both end at the shared node
73 // ( or identical twin ): inverted
74 if ( tA0 == tB0 || tA1 == tB1 )
75 {
76 return false;
77 }
78 }
79 else
80 {
81 // loop over all edge pairs (p→q) from A and (r→s) from B
82 id_t p ;
83 id_t q = tA->node( n-1 )->id();
84 id_t r ;
85 id_t s ;
86
87 for ( uint i = 0; i < n; ++i )
88 {
89 p = q ;
90 q = tA->node( i )->id();
91 s = tB->node( m-1 )->id();
92 for ( uint j = 0; j < m; ++j )
93 {
94 r = s ;
95 s = tB->node( j )->id();
96
97 // A traverses P→Q, B traverses Q→P: consistent normals
98 if ( p == s && q == r )
99 {
100 return true;
101 }
102
103 // A traverses P→Q, B traverses P→Q: inverted normals
104 if ( p == r && q == s )
105 {
106 return false;
107 }
108 }
109 }
110 }
111
112 BELFEM_ERROR( false, "Could not determine orientation of facets." );
113 return false;
114 }
115 }
116}
117#endif //BELFEM_FN_CHECK_FACET_ORIENTATION_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
id_t id() const
Definition cl_Graph_Vertex.hpp:218
Lagrange Element baseclass.
Definition cl_Element.hpp:35
virtual uint number_of_corner_nodes() const
Definition cl_Element.hpp:140
Node * node(const uint aIndex) override
Definition cl_Element.hpp:254
Definition cl_Facet.hpp:24
Element * element()
expose the element pointer
Definition cl_Facet.hpp:361
Node * original()
returns the original of this node
Definition cl_Node.hpp:318
Definition cl_EF_EdgeFunction.hpp:17
bool check_facet_orientation(const Facet *aA, const Facet *aB)
Checks whether two adjacent facets have consistent orientation.
Definition fn_check_facet_orientation.hpp:52
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
unsigned int id_t
Definition typedefs.hpp:41
@ q
Definition cl_Material.hpp:176