Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with is_jacobian_term_used() #1500

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion integration/VODE/vode_dvjac.H
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ void dvjac (int& IERPJ, BurnT& state, DvodeT& vstate)
int IER{};

#ifdef NEW_NETWORK_IMPLEMENTATION
RHS::dgefa(vstate.jac);
if (vstate.jacobian_type == 1) {
constexpr bool allow_skipping_zero_entries{true};
RHS::dgefa<allow_skipping_zero_entries>(vstate.jac);
}
else {
constexpr bool allow_skipping_zero_entries{false};
RHS::dgefa<allow_skipping_zero_entries>(vstate.jac);
}
IER = 0;
#else
if (integrator_rp::linalg_do_pivoting == 1) {
Expand Down
9 changes: 8 additions & 1 deletion integration/VODE/vode_dvnlsd.H
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ Real dvnlsd (int& NFLAG, BurnT& state, DvodeT& vstate)
}

#ifdef NEW_NETWORK_IMPLEMENTATION
RHS::dgesl(vstate.jac, vstate.y);
if (vstate.jacobian_type == 1) {
constexpr bool allow_skipping_zero_entries{true};
RHS::dgesl<allow_skipping_zero_entries>(vstate.jac, vstate.y);
}
else {
constexpr bool allow_skipping_zero_entries{false};
RHS::dgesl<allow_skipping_zero_entries>(vstate.jac, vstate.y);
}
#else
if (integrator_rp::linalg_do_pivoting == 1) {
constexpr bool allow_pivot{true};
Expand Down
12 changes: 7 additions & 5 deletions networks/rhs.H
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ constexpr int is_jacobian_term_used ()
}
}

if (is_spec_1_used || is_spec_2_used) {
if (is_spec_1_used && is_spec_2_used) {
term_is_used = 1;
}
});
Expand All @@ -272,6 +272,7 @@ constexpr int is_jacobian_term_used ()
#endif
}

template <bool allow_skipping_zero_entries>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void dgesl (RArray2D& a1, RArray1D& b1)
{
Expand All @@ -289,7 +290,7 @@ void dgesl (RArray2D& a1, RArray1D& b1)
{
constexpr int j = n2;

if (is_jacobian_term_used<j, k>()) {
if (is_jacobian_term_used<j+1, k+1>() || !allow_skipping_zero_entries) {
b(j) += t * a(j,k);
}
});
Expand All @@ -305,13 +306,14 @@ void dgesl (RArray2D& a1, RArray1D& b1)

constexpr_for<0, k>([&] (auto j)
{
if (is_jacobian_term_used<j, k>()) {
if (is_jacobian_term_used<j+1, k+1>() || !allow_skipping_zero_entries) {
b(j) += t * a(j,k);
}
});
});
}

template <bool allow_skipping_zero_entries>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void dgefa (RArray2D& a1)
{
Expand All @@ -329,7 +331,7 @@ void dgefa (RArray2D& a1)
{
[[maybe_unused]] constexpr int j = n2;

if (is_jacobian_term_used<j, k>()) {
if (is_jacobian_term_used<j+1, k+1>() || !allow_skipping_zero_entries) {
a(j,k) *= t;
}
});
Expand All @@ -344,7 +346,7 @@ void dgefa (RArray2D& a1)
{
[[maybe_unused]] constexpr int i = n3;

if constexpr (is_jacobian_term_used<i, k>()) {
if constexpr (is_jacobian_term_used<i+1, k+1>() || !allow_skipping_zero_entries) {
a(i,j) += t * a(i,k);
}
});
Expand Down
12 changes: 10 additions & 2 deletions unit_test/test_linear_algebra/test_linear_algebra.H
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ void linear_algebra() {

// solve the linear system with the templated solver

RHS::dgefa(A);
RHS::dgesl(A, b);
if (jacobian == 1) {
constexpr bool allow_skipping_zero_entries{true};
RHS::dgefa<allow_skipping_zero_entries>(A);
RHS::dgesl<allow_skipping_zero_entries>(A, b);
}
else {
constexpr bool allow_skipping_zero_entries{false};
RHS::dgefa<allow_skipping_zero_entries>(A);
RHS::dgesl<allow_skipping_zero_entries>(A, b);
}

std::cout << std::setprecision(16);

Expand Down
Loading