BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_inv3.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
17
18#ifndef BELFEM_FN_INV3_HPP
19#define BELFEM_FN_INV3_HPP
20
21#include "typedefs.hpp"
22#include "cl_Matrix.hpp"
23
24namespace belfem
25{
26//------------------------------------------------------------------------------
27
46 inline real
48 {
49 // compute determinant
50 real aDetJ = aA( 0, 0 ) * ( aA( 1, 1 ) * aA( 2, 2 ) - aA( 1, 2 ) * aA( 2, 1 ) )
51 + aA( 0, 1 ) * ( aA( 1, 2 ) * aA( 2, 0 ) - aA( 1, 0 ) * aA( 2, 2 ) )
52 + aA( 0, 2 ) * ( aA( 1, 0 ) * aA( 2, 1 ) - aA( 1, 1 ) * aA( 2, 0 ) );
53
54 aB( 0, 0 ) = aA( 1, 1 ) * aA( 2, 2 ) - aA( 1, 2 ) * aA( 2, 1 ) ;
55 aB( 1, 0 ) = aA( 1, 2 ) * aA( 2, 0 ) - aA( 1, 0 ) * aA( 2, 2 ) ;
56 aB( 2, 0 ) = aA( 1, 0 ) * aA( 2, 1 ) - aA( 1, 1 ) * aA( 2, 0 ) ;
57
58 aB( 0, 1 ) = aA( 0, 2 ) * aA( 2, 1 ) - aA( 0, 1 ) * aA( 2, 2 ) ;
59 aB( 1, 1 ) = aA( 0, 0 ) * aA( 2, 2 ) - aA( 0, 2 ) * aA( 2, 0 ) ;
60 aB( 2, 1 ) = aA( 0, 1 ) * aA( 2, 0 ) - aA( 0, 0 ) * aA( 2, 1 ) ;
61
62 aB( 0, 2 ) = aA( 0, 1 ) * aA( 1, 2 ) - aA( 0, 2 ) * aA( 1, 1 ) ;
63 aB( 1, 2 ) = aA( 0, 2 ) * aA( 1, 0 ) - aA( 0, 0 ) * aA( 1, 2 ) ;
64 aB( 2, 2 ) = aA( 0, 0 ) * aA( 1, 1 ) - aA( 0, 1 ) * aA( 1, 0 ) ;
65
66 // singularity test on the hadamard ratio |det| / prod( ||row_i|| ),
67 // which is dimensionless: an absolute bound on the determinant is a
68 // scale test, and rejects well conditioned but small matrices such as
69 // any fine mesh jacobian. squared here to avoid the square roots
71 * ( aA( 0, 0 ) * aA( 0, 0 ) + aA( 0, 1 ) * aA( 0, 1 ) + aA( 0, 2 ) * aA( 0, 2 ) )
72 * ( aA( 1, 0 ) * aA( 1, 0 ) + aA( 1, 1 ) * aA( 1, 1 ) + aA( 1, 2 ) * aA( 1, 2 ) )
73 * ( aA( 2, 0 ) * aA( 2, 0 ) + aA( 2, 1 ) * aA( 2, 1 ) + aA( 2, 2 ) * aA( 2, 2 ) ),
74 "Can't invert a singular matrix" );
75
76 // divide by determinant
77 aB /= aDetJ ;
78
79 // return determinant
80 return aDetJ ;
81 }
82
83//------------------------------------------------------------------------------
84}
85
86#endif //BELFEM_FN_INV3_HPP
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
real inv3(const Matrix< real > &aA, Matrix< real > &aB)
Inverse of a 3x3 matrix from the closed-form adjugate.
Definition fn_inv3.hpp:47
USER GUIDES:
Definition cl_Capacitor.cpp:16
constexpr real BELFEM_EPSILON
Definition typedefs.hpp:90
double real
Definition typedefs.hpp:36