diff --git a/demo/SPE10/steady.c b/demo/SPE10/steady.c index 74c968b0..1f1d4003 100644 --- a/demo/SPE10/steady.c +++ b/demo/SPE10/steady.c @@ -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; diff --git a/demo/steady/steady.c b/demo/steady/steady.c index 18a433e0..f67a4bea 100644 --- a/demo/steady/steady.c +++ b/demo/steady/steady.c @@ -734,7 +734,7 @@ int main(int argc, char **argv) { } } - ierr = TDySetupNumericalMethods(tdy); CHKERRQ(ierr); + ierr = TDySetup(tdy); CHKERRQ(ierr); /* Compute system */ Mat K; diff --git a/demo/transient/transient.c b/demo/transient/transient.c index 19825598..ac70aa4c 100644 --- a/demo/transient/transient.c +++ b/demo/transient/transient.c @@ -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; diff --git a/demo/transient/transient_mpfaof90.F90 b/demo/transient/transient_mpfaof90.F90 index 7cafa0b0..7adf2790 100644 --- a/demo/transient/transient_mpfaof90.F90 +++ b/demo/transient/transient_mpfaof90.F90 @@ -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 diff --git a/demo/transient/transient_snes_mpfaof90.F90 b/demo/transient/transient_snes_mpfaof90.F90 index 86029245..14113b83 100644 --- a/demo/transient/transient_snes_mpfaof90.F90 +++ b/demo/transient/transient_snes_mpfaof90.F90 @@ -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 diff --git a/include/private/tdycoreimpl.h b/include/private/tdycoreimpl.h index 2b70ffec..89f08d74 100644 --- a/include/private/tdycoreimpl.h +++ b/include/private/tdycoreimpl.h @@ -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*); @@ -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 diff --git a/include/tdycore.h b/include/tdycore.h index d384241c..6d909c0b 100644 --- a/include/tdycore.h +++ b/include/tdycore.h @@ -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); @@ -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); diff --git a/src/f90-mod/tdycoremod.F90 b/src/f90-mod/tdycoremod.F90 index c5088069..f217c9da 100644 --- a/src/f90-mod/tdycoremod.F90 +++ b/src/f90-mod/tdycoremod.F90 @@ -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) diff --git a/src/interface/ftn/tdycoref.c b/src/interface/ftn/tdycoref.c index 57cab46f..4058835b 100644 --- a/src/interface/ftn/tdycoref.c +++ b/src/interface/ftn/tdycoref.c @@ -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 @@ -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 @@ -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) } diff --git a/src/tdycore.c b/src/tdycore.c index 1261d450..a0a5a1b3 100644 --- a/src/tdycore.c +++ b/src/tdycore.c @@ -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); @@ -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); } @@ -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()"); } @@ -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) { @@ -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. @@ -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); @@ -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 @@ -816,7 +818,7 @@ PetscErrorCode TDySetupNumericalMethods(TDy tdy) { } } TDyExitProfilingStage("TDycore Setup"); - tdy->setupflags |= TDySetupFinished; + tdy->setup_flags |= TDySetupFinished; TDY_STOP_FUNCTION_TIMER() PetscFunctionReturn(0); } diff --git a/src/tdydriver.c b/src/tdydriver.c index 30cfd169..74f713b1 100644 --- a/src/tdydriver.c +++ b/src/tdydriver.c @@ -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);