-
-
Notifications
You must be signed in to change notification settings - Fork 93
Handle potential exceptions from preCICE calls #366
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
Open
MakisH
wants to merge
4
commits into
precice:develop
Choose a base branch
from
MakisH:exceptions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -545,11 +545,29 @@ void preciceAdapter::Adapter::initialize() | |||||
DEBUG(adapterInfo("Initializing the preCICE solver interface...")); | ||||||
SETUP_TIMER(); | ||||||
|
||||||
if (precice_->requiresInitialData()) | ||||||
bool requiresInitialData = false; | ||||||
try | ||||||
{ | ||||||
precice_->requiresInitialData(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
if (requiresInitialData) | ||||||
{ | ||||||
DEBUG(adapterInfo("Initializing preCICE data...")); | ||||||
writeCouplingData(); | ||||||
} | ||||||
|
||||||
DEBUG(adapterInfo("Initializing preCICE data...")); | ||||||
precice_->initialize(); | ||||||
try | ||||||
{ | ||||||
precice_->initialize(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
preciceInitialized_ = true; | ||||||
ACCUMULATE_TIMER(timeInInitialize_); | ||||||
|
||||||
|
@@ -566,7 +584,14 @@ void preciceAdapter::Adapter::finalize() | |||||
|
||||||
// Finalize the preCICE solver interface | ||||||
SETUP_TIMER(); | ||||||
precice_->finalize(); | ||||||
try | ||||||
{ | ||||||
precice_->finalize(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
ACCUMULATE_TIMER(timeInFinalize_); | ||||||
|
||||||
preciceInitialized_ = false; | ||||||
|
@@ -587,7 +612,14 @@ void preciceAdapter::Adapter::advance() | |||||
DEBUG(adapterInfo("Advancing preCICE...")); | ||||||
|
||||||
SETUP_TIMER(); | ||||||
precice_->advance(timestepSolver_); | ||||||
try | ||||||
{ | ||||||
precice_->advance(timestepSolver_); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
ACCUMULATE_TIMER(timeInAdvance_); | ||||||
|
||||||
return; | ||||||
|
@@ -652,7 +684,7 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData() | |||||
the same timestep as the one determined by preCICE. | ||||||
*/ | ||||||
double tolerance = 1e-14; | ||||||
if (precice_->getMaxTimeStepSize() - timestepSolverDetermined > tolerance) | ||||||
if (getMaxTimeStepSize() - timestepSolverDetermined > tolerance) | ||||||
{ | ||||||
// Add a bool 'subCycling = true' which is checked in the storeMeshPoints() function. | ||||||
adapterInfo( | ||||||
|
@@ -668,24 +700,24 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData() | |||||
"warning"); | ||||||
} | ||||||
} | ||||||
else if (timestepSolverDetermined - precice_->getMaxTimeStepSize() > tolerance) | ||||||
else if (timestepSolverDetermined - getMaxTimeStepSize() > tolerance) | ||||||
{ | ||||||
// In the last time-step, we adjust to dt = 0, but we don't need to trigger the warning here | ||||||
if (precice_->isCouplingOngoing()) | ||||||
if (isCouplingOngoing()) | ||||||
{ | ||||||
adapterInfo( | ||||||
"The solver's timestep cannot be larger than the coupling timestep." | ||||||
" Adjusting from " | ||||||
+ std::to_string(timestepSolverDetermined) + " to " + std::to_string(precice_->getMaxTimeStepSize()), | ||||||
+ std::to_string(timestepSolverDetermined) + " to " + std::to_string(getMaxTimeStepSize()), | ||||||
"warning"); | ||||||
} | ||||||
timestepSolver_ = precice_->getMaxTimeStepSize(); | ||||||
timestepSolver_ = getMaxTimeStepSize(); | ||||||
} | ||||||
else | ||||||
{ | ||||||
DEBUG(adapterInfo("The solver's timestep is the same as the " | ||||||
"coupling timestep.")); | ||||||
timestepSolver_ = precice_->getMaxTimeStepSize(); | ||||||
timestepSolver_ = getMaxTimeStepSize(); | ||||||
} | ||||||
|
||||||
// Update the solver's timestep (but don't trigger the adjustDeltaT(), | ||||||
|
@@ -702,6 +734,20 @@ void preciceAdapter::Adapter::adjustSolverTimeStepAndReadData() | |||||
return; | ||||||
} | ||||||
|
||||||
double preciceAdapter::Adapter::getMaxTimeStepSize() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||
{ | ||||||
double maxTimeStepSize = 0.0; | ||||||
try | ||||||
{ | ||||||
maxTimeStepSize = precice_->getMaxTimeStepSize(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
return maxTimeStepSize; | ||||||
} | ||||||
|
||||||
bool preciceAdapter::Adapter::isCouplingOngoing() | ||||||
{ | ||||||
bool isCouplingOngoing = false; | ||||||
|
@@ -712,25 +758,59 @@ bool preciceAdapter::Adapter::isCouplingOngoing() | |||||
// was not available. | ||||||
if (NULL != precice_) | ||||||
{ | ||||||
isCouplingOngoing = precice_->isCouplingOngoing(); | ||||||
try | ||||||
{ | ||||||
isCouplingOngoing = precice_->isCouplingOngoing(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
} | ||||||
|
||||||
return isCouplingOngoing; | ||||||
} | ||||||
|
||||||
bool preciceAdapter::Adapter::isCouplingTimeWindowComplete() | ||||||
{ | ||||||
return precice_->isTimeWindowComplete(); | ||||||
bool complete = false; | ||||||
try | ||||||
{ | ||||||
complete = precice_->isTimeWindowComplete(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
return complete; | ||||||
} | ||||||
|
||||||
bool preciceAdapter::Adapter::requiresReadingCheckpoint() | ||||||
{ | ||||||
return precice_->requiresReadingCheckpoint(); | ||||||
bool requiresReadingCheckpoint = false; | ||||||
try | ||||||
{ | ||||||
requiresReadingCheckpoint = precice_->requiresReadingCheckpoint(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
return requiresReadingCheckpoint; | ||||||
} | ||||||
|
||||||
bool preciceAdapter::Adapter::requiresWritingCheckpoint() | ||||||
{ | ||||||
return precice_->requiresWritingCheckpoint(); | ||||||
bool requiresWritingCheckpoint = false; | ||||||
try | ||||||
{ | ||||||
requiresWritingCheckpoint = precice_->requiresWritingCheckpoint(); | ||||||
} | ||||||
catch (const std::runtime_error& e) | ||||||
{ | ||||||
std::exit(1); | ||||||
} | ||||||
return requiresWritingCheckpoint; | ||||||
} | ||||||
|
||||||
|
||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Added exception handling for preCICE API calls [#366](https://github.com/precice/openfoam-adapter/pull/366) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a rather verbose way of handling this, also a bit hard to read. Why not simply wrapping the whole code block into a
try catch
?