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 bugs: changing time step after restart and tracer tanh model #1343

Merged
merged 16 commits into from
Nov 18, 2024

Conversation

oguevremont
Copy link
Collaborator

@oguevremont oguevremont commented Nov 7, 2024

Description

There were two issues that appeared when using the tracer physics with an immersed solid:

  • Evaluation of the diffusivity model immersed solid tanh was too costly
  • Changing the time step after restarting was impossible

Solution

  • The diffusivity model now uses the optimizations from the Shape class, that allow to evaluate the distance using a cell guess; this makes RBF and composite distance evaluations magnitudes faster.
  • Time step change after a restart is now allowed when adapt==false. This behavior is not allowed when adapt==true, as then we desire a continuity in time step evolution. When using fixed time step though, users who change the value after a restart apparently aim for this behavior.

Testing

All tests still pass.

Documentation

No change needed.

Miscellaneous (will be removed when merged)

Checklist (will be removed when merged)

See this page for more information about the pull request process.

Code related list:

  • All in-code documentation related to this PR is up to date (Doxygen format)
  • Copyright headers are present and up to date
  • Lethe documentation is up to date
  • Fix has unit test(s) (preferred) or application test(s), and restart files are in the generator folder
  • The branch is rebased onto master
  • Changelog (CHANGELOG.md) is up to date
  • Code is indented with indent-all and .prm files (examples and tests) with prm-indent

Pull request related list:

  • Labels are applied
  • There are at least 2 reviewers (or 1 if small feature) excluding the responsible for the merge
  • If this PR closes an issue or is related to a project, it is linked in the "Projects" or "Development" section
  • If the fix is temporary, an issue is opened
  • The PR description is cleaned and ready for merge

@oguevremont oguevremont added Bug Something isn't working WIP When a PR is open but not ready for review labels Nov 7, 2024
@oguevremont oguevremont added Ready for review and removed WIP When a PR is open but not ready for review labels Nov 8, 2024
@oguevremont oguevremont marked this pull request as ready for review November 8, 2024 15:57
Copy link
Collaborator

@lpsaavedra lpsaavedra left a comment

Choose a reason for hiding this comment

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

I have a few comments and doubts regarding these new features

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -159,7 +159,7 @@ class TracerScratchData : public PhysicsScratchDataBase
const VectorType &current_solution,
const std::vector<VectorType> &previous_solutions,
const Function<dim> *source_function,
const Function<dim> *levelset_function)
Shape<dim> *immersed_solid_shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because we use value_with_cell_guess, no. value_with_cell_guess is not const, which allows us to add entries to a map in a caching mechanism. Without using this mechanism the code runs much too slowly.

I agree that it would be better to use a const function, but I do not see an efficient way to populate the map otherwise; we need to populate the map with the value of the distance for all quadrature points in the mesh. Maybe we could do it once, with a loop over all active cells before reinitializing the scratch? Then we could use value instead, which is const and can use an already populated map

@@ -317,7 +320,7 @@ class TracerScratchData : public PhysicsScratchDataBase
const unsigned int &neigh_face_no,
const unsigned int &neigh_sub_face_no,
const VectorType &current_solution,
const Function<dim> *levelset_function)
const Function<dim> *immersed_solid_shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this a shape? According to the previous changes?

@@ -383,7 +387,7 @@ class TracerScratchData : public PhysicsScratchDataBase
const unsigned int &face_no,
const unsigned int &boundary_index,
const VectorType &current_solution,
const Function<dim> *levelset_function)
Shape<dim> *immersed_solid_shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be const?

Suggested change
Shape<dim> *immersed_solid_shape)
const Shape<dim> *immersed_solid_shape)

Comment on lines 271 to 277
// Fix the time step to the new provided value.
// We understand that users providing this value when adaptive time stepping
// is not enabled means a time step change is the desired effect.
if (!adapt)
set_current_time_step(initial_time_step);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't fully understand why is this useful? Like in what kind of cases...Isn't it "risky" to change the time step in the middle of the simulation when restarting it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is risky business, but the way I use it is that I solve NS with small time steps, until the solution is steady, then I solve only tracer with large time steps after a restart (before and after the restart the time step is fixed). I should write this somewhere so it is clearer, thanks for pointing it out

Copy link
Collaborator

@lpsaavedra lpsaavedra left a comment

Choose a reason for hiding this comment

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

I just have one additional minor comment...

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Laura Prieto Saavedra <[email protected]>
@oguevremont oguevremont requested a review from blaisb November 18, 2024 15:16
Copy link
Contributor

@blaisb blaisb left a comment

Choose a reason for hiding this comment

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

Much better this way I like it

@blaisb blaisb merged commit 682ab4b into master Nov 18, 2024
11 checks passed
@blaisb blaisb deleted the fix_tracer_tanh branch November 18, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants