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

Add IMEX SolveImplicitSector mutator #5653

Merged

Conversation

wthrowe
Copy link
Member

@wthrowe wthrowe commented Dec 5, 2023

This is the actual solver for the IMEX code. The remaining stuff to submit is mostly actions and other similar wrappers.

Proposed changes

Upgrade instructions

Code review checklist

  • The code is documented and the documentation renders correctly. Run
    make doc to generate the documentation locally into BUILD_DIR/docs/html.
    Then open index.html.
  • The code follows the stylistic and code quality guidelines listed in the
    code review guide.
  • The PR lists upgrade instructions and is labeled bugfix or
    new feature if appropriate.

Further comments

@wthrowe wthrowe force-pushed the imex/solve_implicit_sector branch 2 times, most recently from 0e38ae4 to adbe671 Compare December 6, 2023 04:19
Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks for all your hard work on the IMEX code! I have a few suggestions/comments/questions. Please feel free to rebase and squash directly since I don't think any of them are major.


namespace imex {
namespace OptionTags {
struct ImexMode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add Doxygen comments for the tags, mostly for discoverability?

struct ImexMode {
static constexpr Options::String help{"IMEX implementation to use"};
using type = ::imex::Mode;
using group = evolution::OptionTags::Group;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to add an Imex subgroup into Evolution to group the options together? [later in a separate PR is totally fine if you think it's a good idea!]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and renamed some tags both to avoid duplicating the group name and for consistency.


namespace imex {
namespace OptionTags {
struct ImexImplicitSolveTolerance {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same doxygen question

using attempt_tags = tmpl::transform<typename ImplicitSector::solve_attempts,
get_tags_from_evolution<tmpl::_1>>;
using evolution_data_tags =
tmpl::push_front<attempt_tags,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible tmpl::append here to combine the two lists? If not, maybe a comment why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed a thing and added some comments to try to make this clearer. Not sure if it's enough.

// Only allocated if used.
Matrix semi_implicit_jacobian{};

bool had_failure = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would find reading the code easier if this was solve_succeeded or something like that. not had_failure I think is success and I would find it easier to read

if (solve_succeeded) {
  return;
}

return inhomogeneous_terms_;
}

bool do_solve() const { return implicit_weight_ != 0.0; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function name makes me think it does some computation. Maybe rename to something like solved_needed?

: solve_box_(db::create<simple_tags, compute_tags>()),
implicit_equation_(&implicit_equation) {
static_assert(std::is_same_v<PassedEvolutionData, const EvolutionData&>,
"ImplicitSolver was passed a temporary.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expand this error message? I'm not sure what I should do if I were to get this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should stop passing a temporary. I've added a brief explanation of why.

};

template <typename ImplicitSector, typename SolveAttempt>
class ImplicitSolver {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would some overview documentation be useful here? Not necessarily for doxygen, but to get a quick overview of what the different functions do and why? Maybe also for ImplicitEquation?

struct ReadOnly : Tag, ::db::ComputeTag {
using base = Tag;
using argument_tags = tmpl::list<ReadOnlySource<Tag>>;
static void function(gsl::not_null<typename ReadOnly::type*> dest,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const gsl::not_null?

};
// End stuff only used for DataBox handling

// [initial_guess]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want this initial_guess to be around the AnalyticSolution or the InitialGuess class below? Right now I think it's around the AnalyticSolution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. They are both valid "initial_guess" structs (the example chooses between them with a tmpl::conditional_t), but this one does a reasonable calculation while InitialGuess just does some nonsensical modifications to the data.

Copy link
Member Author

@wthrowe wthrowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now dependent on (and includes the commits from) #5657.

using attempt_tags = tmpl::transform<typename ImplicitSector::solve_attempts,
get_tags_from_evolution<tmpl::_1>>;
using evolution_data_tags =
tmpl::push_front<attempt_tags,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed a thing and added some comments to try to make this clearer. Not sure if it's enough.

: solve_box_(db::create<simple_tags, compute_tags>()),
implicit_equation_(&implicit_equation) {
static_assert(std::is_same_v<PassedEvolutionData, const EvolutionData&>,
"ImplicitSolver was passed a temporary.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should stop passing a temporary. I've added a brief explanation of why.

break;
}
case Mode::SemiImplicit: {
auto correction_array = solver(initial_guess);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There weren't supposed to be any after the first point, but you're right that I missed one in the LAPACK wrapper, so I fixed that.

I've made the types of some variables and temporaries explicitly arrays, so it should be clear that there are no allocations in them.

};
// End stuff only used for DataBox handling

// [initial_guess]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. They are both valid "initial_guess" structs (the example chooses between them with a tmpl::conditional_t), but this one does a reasonable calculation while InitialGuess just does some nonsensical modifications to the data.

struct ImexMode {
static constexpr Options::String help{"IMEX implementation to use"};
using type = ::imex::Mode;
using group = evolution::OptionTags::Group;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and renamed some tags both to avoid duplicating the group name and for consistency.

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please go ahead and squash!

@wthrowe
Copy link
Member Author

wthrowe commented Dec 15, 2023

@nilsdeppe I think this is ready to go.

@nilsdeppe nilsdeppe merged commit 71cf42d into sxs-collaboration:develop Dec 15, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants