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

TransientProblemInterface has TimeStepAdapt object and getters for it #681

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/godzilla/TSAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ class TSAbstract {
protected:
TS get_ts();

/// Get time step adaptor
///
/// @return Time step adaptor
TimeStepAdapt & get_adapt();
const TimeStepAdapt & get_adapt() const;

TSConvergedReason get_reason() const;
void set_reason(TSConvergedReason reason);
Expand Down
3 changes: 2 additions & 1 deletion include/godzilla/TimeStepAdapt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TimeStepAdapt {
};

TimeStepAdapt();
TimeStepAdapt(TS ts, TSAdapt tsadapt);

/// Add a candidate scheme for the adaptive controller to select from
///
Expand Down Expand Up @@ -152,6 +151,8 @@ class TimeStepAdapt {
void set_type(Type type);

private:
TimeStepAdapt(TS ts, TSAdapt tsadapt);

TS ts;
TSAdapt tsadapt;

Expand Down
13 changes: 13 additions & 0 deletions include/godzilla/TransientProblemInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace godzilla {
class Problem;
class Parameters;
class TimeSteppingAdaptor;
class TimeStepAdapt;

/// Interface for transient simulations
///
Expand Down Expand Up @@ -155,6 +156,16 @@ class TransientProblemInterface {
return *static_cast<TSAbstract *>(this->ts->data);
}

/// Get time step adaptivity
///
/// @return Time step adaptivity object
const TimeStepAdapt & get_time_step_adapt() const;

/// Get time step adaptivity
///
/// @return Time step adaptivity object
TimeStepAdapt & get_time_step_adapt();

protected:
/// Get underlying non-linear solver
SNESolver get_snes() const;
Expand Down Expand Up @@ -253,6 +264,8 @@ class TransientProblemInterface {

/// PETSc TS object
TS ts;
/// Time step adapt object
TimeStepAdapt time_step_adapt;
/// Method for monitoring the solve
Delegate<void(Int it, Real rnorm, const Vector & x)> monitor_method;
/// Method for computing right-hand side
Expand Down
7 changes: 7 additions & 0 deletions src/TSAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@
return this->adapt;
}

const TimeStepAdapt &
TSAbstract::get_adapt() const

Check warning on line 176 in src/TSAbstract.cpp

View check run for this annotation

Codecov / codecov/patch

src/TSAbstract.cpp#L176

Added line #L176 was not covered by tests
{
CALL_STACK_MSG();
return this->adapt;

Check warning on line 179 in src/TSAbstract.cpp

View check run for this annotation

Codecov / codecov/patch

src/TSAbstract.cpp#L178-L179

Added lines #L178 - L179 were not covered by tests
}

TSConvergedReason
TSAbstract::get_reason() const
{
Expand Down
17 changes: 17 additions & 0 deletions src/TransientProblemInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "godzilla/Godzilla.h"
#include "godzilla/CallStack.h"
#include "godzilla/Problem.h"
#include "godzilla/TimeStepAdapt.h"
#include "godzilla/TimeSteppingAdaptor.h"
#include "godzilla/TransientProblemInterface.h"
#include "godzilla/LoggingInterface.h"
Expand Down Expand Up @@ -129,6 +130,8 @@
{
CALL_STACK_MSG();
PETSC_CHECK(TSCreate(this->problem->get_comm(), &this->ts));
this->time_step_adapt = TimeStepAdapt::from_ts(this->ts);

if (this->tpi_params.is_param_valid("end_time") && this->tpi_params.is_param_valid("num_steps"))
this->problem->log_error(
"Cannot provide 'end_time' and 'num_steps' together. Specify one or the other.");
Expand Down Expand Up @@ -228,6 +231,20 @@
return this->step_num;
}

const TimeStepAdapt &
TransientProblemInterface::get_time_step_adapt() const

Check warning on line 235 in src/TransientProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/TransientProblemInterface.cpp#L235

Added line #L235 was not covered by tests
{
CALL_STACK_MSG();
return this->time_step_adapt;

Check warning on line 238 in src/TransientProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/TransientProblemInterface.cpp#L237-L238

Added lines #L237 - L238 were not covered by tests
}

TimeStepAdapt &
TransientProblemInterface::get_time_step_adapt()

Check warning on line 242 in src/TransientProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/TransientProblemInterface.cpp#L242

Added line #L242 was not covered by tests
{
CALL_STACK_MSG();
return this->time_step_adapt;

Check warning on line 245 in src/TransientProblemInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/TransientProblemInterface.cpp#L244-L245

Added lines #L244 - L245 were not covered by tests
}

void
TransientProblemInterface::init()
{
Expand Down
Loading