BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_crossmat.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,
4 * through 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
29
30#ifndef BELFEM_FN_CROSSMAT_HPP
31#define BELFEM_FN_CROSSMAT_HPP
32
33#include "cl_Vector.hpp"
34#include "cl_Matrix.hpp"
35#include "fn_norm.hpp"
36
37#include "assert.hpp"
38namespace belfem
39{
47 inline void
49 const Vector< real > & aN,
50 const Matrix< real > & aA,
51 Vector< real > & aNxA )
52 {
53
54 uint tN = aA.n_cols() ;
55
56 BELFEM_ASSERT( aN.length() == 2,
57 "Length of normal vector must be 2 (is %u)",
58 ( unsigned int ) aN.length() );
59
60 BELFEM_ASSERT( aNxA.length() == tN,
61 "Length of solution vector does not match (is %u but expect %u )",
62 ( unsigned int ) aNxA.length(),
63 ( unsigned int ) tN );
64
65 for( uint k=0; k<tN; ++k )
66 {
67 aNxA( k ) = aN( 0 ) * aA( 1, k ) - aN( 1 ) * aA( 0, k ) ;
68 }
69
70 // remove dust ( can be removed in the future if too slow, just for beautification )
71 real tInvNorm = 1.0/norm( aNxA );
72 for( uint k=0; k<tN; ++k )
73 {
74 if( std::abs( aNxA( k ) * tInvNorm ) < BELFEM_EPSILON )
75 {
76 aNxA( k ) = 0.0 ;
77 }
78 }
79
80 }
81
82
91 inline void
93 const Vector< real > & aN,
94 const Matrix< real > & aA,
95 const real aScale,
96 Vector< real > & aNxA )
97 {
98
99 uint tN = aA.n_cols() ;
100
101 BELFEM_ASSERT( aN.length() == 2,
102 "Length of normal vector must be 2 (is %u)",
103 ( unsigned int ) aN.length() );
104
105 BELFEM_ASSERT( aNxA.length() == tN,
106 "Length of solution vector does not match (is %u but expect %u )",
107 ( unsigned int ) aNxA.length(),
108 ( unsigned int ) tN );
109
110 for( uint k=0; k<tN; ++k )
111 {
112 aNxA( k ) += aScale * ( aN( 0 ) * aA( 1, k ) - aN( 1 ) * aA( 0, k ) );
113 }
114
115 // remove dust ( can be removed in the future if too slow, just for beautification )
116 real tInvNorm = 1.0/norm( aNxA );
117 for( uint k=0; k<tN; ++k )
118 {
119 if( std::abs( aNxA( k ) * tInvNorm ) < BELFEM_EPSILON )
120 {
121 aNxA( k ) = 0.0 ;
122 }
123 }
124 }
125
133 inline void
135 const Vector< real > & aN,
136 const Matrix< real > & aA,
137 Matrix< real > & aNxA )
138 {
139 uint tN = aA.n_cols() ;
140
141 BELFEM_ASSERT( aN.length() == 3,
142 "Length of normal vector must be 3 (is %u)",
143 ( unsigned int ) aN.length() );
144
145 BELFEM_ASSERT( aNxA.n_cols() == tN,
146 "Number of columns of solution matrix does not match (is %u but expect %u )",
147 ( unsigned int ) aNxA.n_cols(),
148 ( unsigned int ) tN );
149
150 BELFEM_ASSERT( aNxA.n_rows() == 3,
151 "Number of rows of solution matrix does not match (is %u but expect 3)",
152 ( unsigned int ) aNxA.n_rows() );
153
154 for( uint k=0; k<tN; ++k )
155 {
156 aNxA( 0, k ) = aN( 1 ) * aA( 2, k ) - aN( 2 ) * aA( 1, k ) ;
157 aNxA( 1, k ) = aN( 2 ) * aA( 0, k ) - aN( 0 ) * aA( 2, k ) ;
158 aNxA( 2, k ) = aN( 0 ) * aA( 1, k ) - aN( 1 ) * aA( 0, k ) ;
159
160 }
161 }
162
171 inline void
173 const Vector< real > & aN,
174 const Matrix< real > & aA,
175 const real aScale,
176 Matrix< real > & aNxA )
177 {
178 uint tN = aA.n_cols() ;
179
180 BELFEM_ASSERT( aN.length() == 3,
181 "Length of normal vector must be 3 (is %u)",
182 ( unsigned int ) aN.length() );
183
184 BELFEM_ASSERT( aNxA.n_cols() == tN,
185 "Number of columns of solution matrix does not match (is %u but expect %u )",
186 ( unsigned int ) aNxA.n_cols(),
187 ( unsigned int ) tN );
188
189 BELFEM_ASSERT( aNxA.n_rows() == 3,
190 "Number of rows of solution matrix does not match (is %u but expect 3)",
191 ( unsigned int ) aNxA.n_rows() );
192
193 for( uint k=0; k<tN; ++k )
194 {
195 aNxA( 0, k ) += aScale * ( aN( 1 ) * aA( 2, k ) - aN( 2 ) * aA( 1, k ) );
196 aNxA( 1, k ) += aScale * ( aN( 2 ) * aA( 0, k ) - aN( 0 ) * aA( 2, k ) );
197 aNxA( 2, k ) += aScale * ( aN( 0 ) * aA( 1, k ) - aN( 1 ) * aA( 0, k ) );
198 }
199 }
200}
201#endif //BELFEM_FN_CROSSMAT_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
size_t n_rows() const
Definition cl_AR_Matrix.hpp:205
size_t n_cols() const
Definition cl_AR_Matrix.hpp:213
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
Euclidean length of a vector.
auto norm(const Vector< T > &aA) -> decltype(norm(aA.vector_data()))
Euclidean (L2) norm of a vector.
Definition fn_norm.hpp:56
void crossmat(const Vector< real > &aN, const Matrix< real > &aA, Vector< real > &aNxA)
Crosses a normal vector with every column of a matrix, 2D.
Definition fn_crossmat.hpp:48
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
constexpr real BELFEM_EPSILON
Definition typedefs.hpp:90
double real
Definition typedefs.hpp:36