Skip to content

Conversation

@MaxBille
Copy link
Collaborator

@MaxBille MaxBille commented Sep 2, 2024

Description

Closes #174
Closes #272
Adding two reporters, that check for signs of simulation crashes (NaN in f or Ma > 0.3 in u) and abort simulation with respective abort messages, optional final vtk-frame and (in case of HighMaReporter) optional output file with locations of the 100 highest velocity magnitudes for crash-troubleshooting and analysis.

NaNReporter:

  • checks f in interval steps for any NaN value. If NaN is found, simulation is aborted.
  • if outdir is provided, lists indices q,x,y,[z] for all found NaN values (attention: produces large files for large intervals, because NaN replicates through the domain fast.
  • "old" argument (True, False) is for backwards compatibility with lettuce that has no aborting functionality in the simulation.py class. No vtk output in this case...
  • vtk argument (True, False) allows for vtk output of the current single flow state frame to outdir (if vtk_dir is not specified) or vtk_dir (if specified)

HighMaReporter:

  • calculates mach number from norm(u(f)) every interval steps and checks if Ma > 0.3 occurs. If Ma > 0.3 is found, simulation is aborted. The location (in LU coordinates) of up to 100 highest Ma numbers in the domain are reported to a file in outdir, if outdir argument is provided.
  • "old" argument (True, False) is for backwards compatibility with lettuce that has no aborting functionality in the simulation.py class. No vtk output in this case...
  • vtk argument (True, False) allows for vtk output of the current single flow state frame to outdir (if vtk_dir is not specified) or vtk_dir (if specified)
  • relies on unravel_index() method for torch.tensors, defined in the same file, for sorting and selection of high-Ma-locations.

DISCLAIMER: originally written for a modified version of lettuceCFD, based on Version 0.2.3; Adaptation for new Lettuce Master pending...

Checklist

  • This pull request is associated to an issue
  • This PR contains a description
  • Add someone else as reviewer and wait for approval before merging.

@pep8speaks
Copy link

pep8speaks commented Sep 2, 2024

Hello @MaxBille! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 7:29: E128 continuation line under-indented for visual indent
Line 14:80: E501 line too long (111 > 79 characters)

Comment last updated at 2024-09-05 09:53:25 UTC

@MaxBille MaxBille requested review from McBs and PhiSpel September 2, 2024 11:41
@MaxBille MaxBille added the enhancement New feature or request label Sep 2, 2024
Copy link
Contributor

@PhiSpel PhiSpel left a comment

Choose a reason for hiding this comment

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

  1. Could you check if we need to set non_native in BreakableSimulation? If so, can you rename to BreakableSimulationNonNative?
  2. Maybe rename example to FailingTGVandObstacle.py?

 - renamed FailingTGVandObstacle.py
 - removed hardcoded non-native execution from breakable simulation class.
 - set Obstacle flow to non-native
@MaxBille
Copy link
Collaborator Author

@PhiSpel would you mind, reviewing the changes I've made, regarding your change requests and recommendation? :) (if you have the time...)

@MaxBille MaxBille requested a review from PhiSpel December 17, 2025 15:34
@MaxBille MaxBille removed the request for review from McBs December 17, 2025 15:35
Copy link
Contributor

@PhiSpel PhiSpel left a comment

Choose a reason for hiding this comment

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

Some comments and changes still.
A nice setup!

Please remove lettuce/ext/_reporter/nan_repoter.py (the comments still apply to lettuce/ext/_reporter/failure_reporter.py!)

Generally, please revisit the typing of inputs and outputs of the classes and functions :)

self.failed_iteration = None
super().__init__(interval)

def __call__(self, simulation: 'Simulation'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you import Simulation with no apparent issues, you can type it directly. Keep in mind, though: This must be a BreakableSimulation

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille have you tried this?

f'details!')
# telling simulation to abort simulation by setting i too high
simulation.flow.i = int(simulation.flow.i + 1e10)
# TODO: maybe make this more robust with a failed-flag in simulation and not rely on flow.i to be high/low?
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure! Since we're working with BreakableSimulation anyway, it can just get a flag lastIteration, such that any other Reporter (also VTKReporter!) can also check if the simulation failed and output one last time. This is also implemented in NATriuM.

This may have been my own TODO-comment, btw ... :) So, for now, you could just post ths into another issue

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxBille is this a won't-do, or something for a new issue?

cleanup and small corrections to comments, typing and code formating
@MaxBille MaxBille requested a review from PhiSpel December 18, 2025 11:40
stencil=lt.D2Q9
)
nan_reporter = lt.NaNReporter(100, outdir="./data/nan_reporter", vtk=True)
simulation = lt.BreakableSimulation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the reporters only work with this specific Simulation class (i.e. BreakableSimulation)?
If not, I prefer to initialize this class within the example script (i.e. header).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @MaxBille
Is there an update on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@McBs yes, it should be BreakableSimulation since we manipulate simulation.flow.i. If simulation this is not BreakableSimulation, it will continue running because call() contains a blind for-loop (

for _ in range(num_steps):
) that won't be broken.

Copy link
Contributor

@PhiSpel PhiSpel left a comment

Choose a reason for hiding this comment

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

Typing is still incomplete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: abort conditions - there are several reasons a simulation can fail Reporter to interrupt simulation

4 participants