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

A starting point for a polymorphic solver-based TDycore interface. #211

Merged
merged 2 commits into from
Sep 28, 2021
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
2 changes: 1 addition & 1 deletion demo/SPE10/steady.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int main(int argc, char **argv) {
ierr = TDySetBoundaryPressureFn(tdy,Pressure,NULL); CHKERRQ(ierr);

/* Setup problem parameters */
ierr = TDySetupNumericalMethods(tdy); CHKERRQ(ierr);
ierr = TDySetup(tdy); CHKERRQ(ierr);

/* Compute system */
Mat K;
Expand Down
2 changes: 1 addition & 1 deletion demo/steady/steady.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ int main(int argc, char **argv) {
}
}

ierr = TDySetupNumericalMethods(tdy); CHKERRQ(ierr);
ierr = TDySetup(tdy); CHKERRQ(ierr);

/* Compute system */
Mat K;
Expand Down
2 changes: 1 addition & 1 deletion demo/transient/transient.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main(int argc, char **argv) {
ierr = TDySetForcingFunction(tdy,Forcing,NULL); CHKERRQ(ierr);
ierr = TDySetBoundaryPressureFn(tdy,Pressure,NULL); CHKERRQ(ierr);

ierr = TDySetupNumericalMethods(tdy); CHKERRQ(ierr);
ierr = TDySetup(tdy); CHKERRQ(ierr);

/* Setup initial condition */
Vec U;
Expand Down
2 changes: 1 addition & 1 deletion demo/transient/transient_mpfaof90.F90
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ program main
call TDySetResidualSaturationValuesLocal(tdy,cEnd-cStart,index,residualSat,ierr);
CHKERRA(ierr);

call TDySetupNumericalMethods(tdy,ierr);
call TDySetup(tdy,ierr);
CHKERRA(ierr);

! Set initial condition
Expand Down
2 changes: 1 addition & 1 deletion demo/transient/transient_snes_mpfaof90.F90
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ program main
if (use_tdydriver) then
call TDyDriverInitializeTDy(tdy, ierr);
else
call TDySetupNumericalMethods(tdy,ierr);
call TDySetup(tdy,ierr);
CHKERRA(ierr);
end if

Expand Down
42 changes: 36 additions & 6 deletions include/private/tdycoreimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,31 @@

typedef struct _TDyOps *TDyOps;
struct _TDyOps {
// Called by TDyCreate to allocate implementation-specific resources. Returns
// a pointer to a context.
PetscErrorCode (*create)(TDy);
PetscErrorCode (*destroy)(TDy);
PetscErrorCode (*view)(TDy);
PetscErrorCode (*setup)(TDy);
PetscErrorCode (*setfromoptions)(TDy);

// Called by TDyDestroy to free implementation-specific resources.
PetscErrorCode (*destroy)(void*);

// Implements the view operation for the TDy implementation with the given
// viewer.
PetscErrorCode (*view)(void*, PetscViewer);

//PetscErrorCode (*setup)(TDy);

// Called by TDySetFromOptions -- sets implementation-specific options
// from command-line arguments.
PetscErrorCode (*set_from_options)(void*);

// Called by TDySetup -- configures the DM for the dycore.
PetscErrorCode (*config_dm)(void*, DM);

// Called by TDyComputeErrorNorms -- computes error norms given a solution
// vector.
PetscErrorCode (*compute_error_norms)(void*,Vec,PetscReal*,PetscReal*);

// Material and boundary condition functions--we'll sort these out later.
PetscErrorCode (*computeporosity)(TDy,PetscReal*,PetscReal*,void*);
PetscErrorCode (*computepermeability)(TDy,PetscReal*,PetscReal*,void*);
PetscErrorCode (*computethermalconductivity)(TDy,PetscReal*,PetscReal*,void*);
Expand All @@ -37,11 +57,21 @@ struct _TDyOps {

struct _p_TDy {
PETSCHEADER(struct _TDyOps);
PetscBool setup;

// Implementation-specific context pointer
void *context;

// Flags that indicate where the dycore is in the setup process
TDySetupFlags setup_flags;

// Grid and data management -- handed to a solver when the dycore is fully
// configured
DM dm;

// We'll likely get rid of this.
TDyTimeIntegrator ti;
TDySetupFlags setupflags;

// I/O subsystem
TDyIO io;

// options that determine the behavior(s) of the dycore
Expand Down
6 changes: 4 additions & 2 deletions include/tdycore.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ PETSC_EXTERN PetscErrorCode TDyFinalize(void);
PETSC_EXTERN PetscErrorCode TDyCreate(TDy*);
PETSC_EXTERN PetscErrorCode TDySetMode(TDy,TDyMode);
PETSC_EXTERN PetscErrorCode TDySetDiscretizationMethod(TDy,TDyMethod);
PETSC_EXTERN PetscErrorCode TDySetDM(TDy,DM);
PETSC_EXTERN PetscErrorCode TDySetFromOptions(TDy);
PETSC_EXTERN PetscErrorCode TDySetupNumericalMethods(TDy);
PETSC_EXTERN PetscErrorCode TDySetup(TDy);
PETSC_EXTERN PetscErrorCode TDyDestroy(TDy *tdy);
PETSC_EXTERN PetscErrorCode TDyView(TDy,PetscViewer viewer);

Expand Down Expand Up @@ -155,11 +154,14 @@ PETSC_EXTERN PetscErrorCode TDySetWaterDensityType(TDy,TDyWaterDensityType);
PETSC_EXTERN PetscErrorCode TDySetMPFAOGmatrixMethod(TDy,TDyMPFAOGmatrixMethod);
PETSC_EXTERN PetscErrorCode TDySetMPFAOBoundaryConditionType(TDy,TDyMPFAOBoundaryConditionType);

// We will probably remove the following functions.
PETSC_EXTERN PetscErrorCode TDySetDM(TDy,DM);
PETSC_EXTERN PetscErrorCode TDyComputeSystem(TDy,Mat,Vec);
PETSC_EXTERN PetscErrorCode TDySetIFunction(TS,TDy);
PETSC_EXTERN PetscErrorCode TDySetIJacobian(TS,TDy);
PETSC_EXTERN PetscErrorCode TDySetSNESFunction(SNES,TDy);
PETSC_EXTERN PetscErrorCode TDySetSNESJacobian(SNES,TDy);

PETSC_EXTERN PetscErrorCode TDyComputeErrorNorms(TDy,Vec,PetscReal*,PetscReal*);

PETSC_EXTERN PetscErrorCode TDySetDtimeForSNESSolver(TDy,PetscReal);
Expand Down
4 changes: 2 additions & 2 deletions src/f90-mod/tdycoremod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ subroutine TDyTimeIntegratorOutputRegression(a,z)
end subroutine TDyTimeIntegratorOutputRegression
end interface
interface
subroutine TDySetupNumericalMethods(a,z)
subroutine TDySetup(a,z)
use tdycoredef
TDy a
integer z
end subroutine TDySetupNumericalMethods
end subroutine TDySetup
end interface
interface
subroutine TDyComputeSystem(a,b,c,z)
Expand Down
8 changes: 4 additions & 4 deletions src/interface/ftn/tdycoref.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define tdydtimeintegratorruntotime_ TDYTIMEINTEGRATORRUNTOTIME
#define tdydtimeintegratorsettimestep_ TDYTIMEINTEGRATORSETTIMESTEP
#define tdydtimeintegratoroutputregression_ TDYTIMEINTEGRATOROUTPUTREGRESSION
#define tdysetupnumericalmethods_ TDYSETUPNUMERICALMETHODS
#define tdysetup_ TDYSETUP
#define tdysetwaterdensitytype_ TDYSETWATERDENSITYTYPE
#define tdysetmpfaogmatrixmethod_ TDYSETMPFAOGMATRIXMETHOD
#define tdysetmpfaoboundaryconditiontype_ TDYSETMPFAOGBOUNDARYCONDITIONTYPE
Expand Down Expand Up @@ -80,7 +80,7 @@
#define tdydtimeintegratorruntotime_ tdydtimeintegratorruntotime
#define tdydtimeintegratorsettimestep_ tdydtimeintegratorsettimestep
#define tdydtimeintegratoroutputregression_ tdydtimeintegratoroutputregression
#define tdysetupnumericalmethods_ tdysetupnumericalmethods
#define tdysetup_ tdysetup
#define tdysetwaterdensitytype_ tdysetwaterdensitytype
#define tdysetmpfaogmatrixmethod_ tdysetmpfaogmatrixmethod
#define tdysetmpfaoboundaryconditiontype_ tdysetmpfaoboundaryconditiontype
Expand Down Expand Up @@ -255,8 +255,8 @@ PETSC_EXTERN void tdytimeintegratoroutputregression_(TDy tdy, int *__ierr){
#if defined(__cplusplus)
extern "C" {
#endif
PETSC_EXTERN void tdysetupnumericalmethods_(TDy _tdy, int *__ierr){
*__ierr = TDySetupNumericalMethods((TDy)PetscToPointer((_tdy)));
PETSC_EXTERN void tdysetup_(TDy _tdy, int *__ierr){
*__ierr = TDySetup((TDy)PetscToPointer((_tdy)));
}
#if defined(__cplusplus)
}
Expand Down
24 changes: 13 additions & 11 deletions src/tdycore.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ PetscErrorCode TDyCreate(TDy *_tdy) {
ierr = PetscHeaderCreate(tdy,TDY_CLASSID,"TDy","TDy","TDy",PETSC_COMM_WORLD,
TDyDestroy,TDyView); CHKERRQ(ierr);
*_tdy = tdy;
tdy->setupflags |= TDyCreated;
tdy->setup_flags |= TDyCreated;

SetDefaultOptions(tdy);

Expand All @@ -260,7 +260,7 @@ PetscErrorCode TDyCreate(TDy *_tdy) {
tdy->quad = NULL;
tdy->faces = NULL; tdy->LtoG = NULL; tdy->orient = NULL;

tdy->setupflags |= TDyParametersInitialized;
tdy->setup_flags |= TDyParametersInitialized;
PetscFunctionReturn(0);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ PetscErrorCode TDyCreateGrid(TDy tdy) {
PetscErrorCode ierr;
PetscFunctionBegin;
MPI_Comm comm = PETSC_COMM_WORLD;
if ((tdy->setupflags & TDyOptionsSet) == 0) {
if ((tdy->setup_flags & TDyOptionsSet) == 0) {
SETERRQ(comm,PETSC_ERR_USER,"Options must be set prior to TDyCreateGrid()");
}

Expand Down Expand Up @@ -607,7 +607,7 @@ PetscErrorCode TDyView(TDy tdy,PetscViewer viewer) {
}

/// Sets options for the dycore based on command line arguments supplied by a
/// user. TDySetFromOptions must be called before TDySetupNumericalMethods,
/// user. TDySetFromOptions must be called before TDySetup,
/// since the latter uses options specified by the former.
/// @param tdy The dycore instance
PetscErrorCode TDySetFromOptions(TDy tdy) {
Expand All @@ -616,8 +616,8 @@ PetscErrorCode TDySetFromOptions(TDy tdy) {

MPI_Comm comm = PETSC_COMM_WORLD;

if ((tdy->setupflags & TDySetupFinished) != 0) {
SETERRQ(comm,PETSC_ERR_USER,"TDySetFromOptions must be called prior to TDySetupNumericalMethods()");
if ((tdy->setup_flags & TDySetupFinished) != 0) {
SETERRQ(comm,PETSC_ERR_USER,"TDySetFromOptions must be called prior to TDySetup()");
}

// Collect options from command line arguments.
Expand Down Expand Up @@ -743,7 +743,7 @@ PetscErrorCode TDySetFromOptions(TDy tdy) {

// Wrap up and indicate that options are set.
ierr = PetscOptionsEnd(); CHKERRQ(ierr);
tdy->setupflags |= TDyOptionsSet;
tdy->setup_flags |= TDyOptionsSet;

// Create our mesh.
ierr = TDyCreateGrid(tdy); CHKERRQ(ierr);
Expand Down Expand Up @@ -793,16 +793,18 @@ PetscErrorCode TDySetupDiscretizationScheme(TDy tdy) {
PetscFunctionReturn(0);
}

PetscErrorCode TDySetupNumericalMethods(TDy tdy) {
PetscErrorCode TDySetup(TDy tdy) {
/* must follow TDySetFromOptions() is it relies upon options set by
TDySetFromOptions */
PetscErrorCode ierr;
PetscFunctionBegin;
if ((tdy->setupflags & TDyOptionsSet) == 0) {
SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"TDySetFromOptions must be called prior to TDySetupNumericalMethods()");
if ((tdy->setup_flags & TDyOptionsSet) == 0) {
SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"TDySetFromOptions must be called prior to TDySetup()");
}
TDY_START_FUNCTION_TIMER()
TDyEnterProfilingStage("TDycore Setup");
// TODO: Stick a call to tdy->ops->config_dm here to configure the DM for our
// TODO: specific dycore setup.
ierr = TDySetupDiscretizationScheme(tdy); CHKERRQ(ierr);
if (tdy->options.regression_testing) {
/* must come after Sections are set up in
Expand All @@ -816,7 +818,7 @@ PetscErrorCode TDySetupNumericalMethods(TDy tdy) {
}
}
TDyExitProfilingStage("TDycore Setup");
tdy->setupflags |= TDySetupFinished;
tdy->setup_flags |= TDySetupFinished;
TDY_STOP_FUNCTION_TIMER()
PetscFunctionReturn(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tdydriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ PetscErrorCode TDyDriverInitializeTDy(TDy tdy) {
}
}

ierr = TDySetupNumericalMethods(tdy); CHKERRQ(ierr);
ierr = TDySetup(tdy); CHKERRQ(ierr);

ierr = TDyTimeIntegratorCreate(&tdy->ti); CHKERRQ(ierr);
ierr = TDyCreateVectors(tdy); CHKERRQ(ierr);
Expand Down