Skip to content

Commit

Permalink
Merge pull request #1195 from LLNL/mish2/lazily_evaluate_sparse_matri…
Browse files Browse the repository at this point in the history
…x_LUTs

lazily evaluate sparse matrix LUTs
  • Loading branch information
tupek2 authored Aug 7, 2024
2 parents a13dbef + fab936b commit c80628b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/serac/numerics/functional/dof_numbering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,18 @@ struct GradientAssemblyLookupTables {
};
};

/// dummy default ctor to enable deferred initialization
GradientAssemblyLookupTables() : initialized{false} {};

/**
* @param block_test_dofs object containing information about dofs for the test space
* @param block_trial_dofs object containing information about dofs for the trial space
*
* @brief create lookup tables describing which degrees of freedom
* correspond to each domain/boundary element
*/
GradientAssemblyLookupTables(const serac::BlockElementRestriction& block_test_dofs,
const serac::BlockElementRestriction& block_trial_dofs)
void init(const serac::BlockElementRestriction& block_test_dofs,
const serac::BlockElementRestriction& block_trial_dofs)
{
// we start by having each element and boundary element emit the (i,j) entry that it
// touches in the global "stiffness matrix", and also keep track of some metadata about
Expand Down Expand Up @@ -342,6 +345,8 @@ struct GradientAssemblyLookupTables {
}

row_ptr.back() = static_cast<int>(nnz);

initialized = true;
}

/**
Expand All @@ -368,6 +373,9 @@ struct GradientAssemblyLookupTables {
* corresponding to the (i,j) entry
*/
std::unordered_map<Entry, uint32_t, Entry::Hasher> nz_LUT;

/// @brief specifies if the table has already been initialized or not
bool initialized;
};

} // namespace serac
6 changes: 5 additions & 1 deletion src/serac/numerics/functional/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ class Functional<test(trials...), exec> {
Gradient(Functional<test(trials...), exec>& f, uint32_t which = 0)
: mfem::Operator(f.test_space_->GetTrueVSize(), f.trial_space_[which]->GetTrueVSize()),
form_(f),
lookup_tables(f.G_test_[Domain::Type::Elements], f.G_trial_[Domain::Type::Elements][which]),
which_argument(which),
test_space_(f.test_space_),
trial_space_(f.trial_space_[which]),
Expand Down Expand Up @@ -576,6 +575,11 @@ class Functional<test(trials...), exec> {

constexpr bool col_ind_is_sorted = true;

if (!lookup_tables.initialized) {
lookup_tables.init(form_.G_test_[Domain::Type::Elements],
form_.G_trial_[Domain::Type::Elements][which_argument]);
}

double* values = new double[lookup_tables.nnz]{};

std::map<mfem::Geometry::Type, ExecArray<double, 3, exec>> element_gradients[Domain::num_types];
Expand Down

0 comments on commit c80628b

Please sign in to comment.