1 #ifndef AMREX_LU_SOLVER_H_
2 #define AMREX_LU_SOLVER_H_
3 #include <AMReX_Config.H>
14 template <
int N,
typename T>
29 for (
int i = 0; i < N; ++i) {
31 for (
int k = 0; k < i; ++k) {
36 for (
int i = N-1; i >= 0; --i) {
37 for (
int k = i+1; k < N; ++k) {
48 for (
int j = 0; j < N; ++j) {
49 for (
int i = 0; i < N; ++i) {
50 IA(i,j) = (
m_piv(i) == j) ? T(1.0) : T(0.0);
51 for (
int k = 0; k < i; ++k) {
52 IA(i,j) -=
m_mat(i,k) * IA(k,j);
55 for (
int i = N-1; i >= 0; --i) {
56 for (
int k = i+1; k < N; ++k) {
57 IA(i,j) -=
m_mat(i,k) * IA(k,j);
59 IA(i,j) *=
m_mat(i,i);
69 for (
int i = 1; i < N; ++i) {
73 return (
m_npivs % 2 == 0) ? det : -det;
86 template <
int N,
typename T>
94 template <
int N,
typename T>
101 template <
int N,
typename T>
105 static_assert(N > 1);
106 static_assert(std::is_floating_point_v<T>);
108 for (
int i = 0; i < N; ++i) { m_piv(i) = i; }
111 for (
int i = 0; i < N; ++i) {
115 for (
int k = i; k < N; ++k) {
116 auto const absA =
std::abs(m_mat(k,i));
129 for (
int j = 0; j < N; ++j) {
135 for (
int j = i+1; j < N; ++j) {
136 m_mat(j,i) /= m_mat(i,i);
137 for (
int k = i+1; k < N; ++k) {
138 m_mat(j,k) -= m_mat(j,i) * m_mat(i,k);
143 for (
int i = 0; i < N; ++i) {
144 m_mat(i,i) = T(1) / m_mat(i,i);
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition: AMReX_Extension.H:37
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_LUSolver.H:16
int m_npivs
Definition: AMReX_LUSolver.H:83
AMREX_GPU_HOST_DEVICE T determinant() const
Definition: AMReX_LUSolver.H:66
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void define_innard()
Definition: AMReX_LUSolver.H:103
Array2D< T, 0, N-1, 0, N-1, Order::C > m_mat
Definition: AMReX_LUSolver.H:81
Array1D< int, 0, N-1 > m_piv
Definition: AMReX_LUSolver.H:82
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T *AMREX_RESTRICT x, T const *AMREX_RESTRICT b) const
Definition: AMReX_LUSolver.H:27
AMREX_GPU_HOST_DEVICE Array2D< T, 0, N-1, 0, N-1, Order::C > invert() const
Definition: AMReX_LUSolver.H:45
void define(Array2D< T, 0, N-1, 0, N-1, Order::C > const &a_mat)
Definition: AMReX_LUSolver.H:95
@ min
Definition: AMReX_ParallelReduce.H:18
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Swap(T &t1, T &t2) noexcept
Definition: AMReX_Algorithm.H:75
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
const int[]
Definition: AMReX_BLProfiler.cpp:1664
Definition: AMReX_Array.H:161