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

Centralise Ocean parameters #64

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eb73243
Eliminate unused setParameters from Ocean.
Oct 29, 2019
6933f06
Remove belos parameter list from class definition.
Oct 29, 2019
8066481
Change THCM to initialise from const parameterlists.
Oct 29, 2019
e48210c
Change to initialise from references, rather than Teuchos RCP.
Oct 29, 2019
be97260
Create a default parameterlist to validate against.
Oct 29, 2019
b4054bd
Suffix class variable with underscore.
Oct 30, 2019
9309a85
Keep using get with default.
Oct 30, 2019
68e7592
Alternative branch for configuring THCM from Ocean.
Nov 15, 2019
0451c9b
Move parameter initialisation to separate THCM methods.
Nov 15, 2019
6def126
Add distinction between init and update parameters for Ocean.
Nov 15, 2019
3365437
Handle integral row parameters properly.
Nov 25, 2019
8140bf1
Only write new parameters.
Nov 25, 2019
e805b81
Initialise default parameter values for Fortran.
Nov 25, 2019
274d0dc
Enable parameter validation.
Nov 25, 2019
d92f808
Drop parameters that are never used.
Nov 25, 2019
f26d1f8
Stop using HexFloat because GCC on some Travis pipelines doesn't supp…
Nov 25, 2019
427215c
Update default value of AL_T in parameter list to match actual value.
Nov 28, 2019
fcbed1f
Readd renamed parameter.
Nov 28, 2019
1e9fb9e
Configure Topo solver via sublist.
Nov 29, 2019
f842d2b
Move Belos config into Ocean parameterlist.
Nov 29, 2019
21d9129
Remove unnecessary methods and switch to using validateAndSetDefaults.
Jan 15, 2020
f70ccad
Remove underscore from non-member variable.
Jan 17, 2020
4db40f3
Name method parameter.
Jan 17, 2020
6fed3b9
Switch back to using Teuchos::RCP as ParameterList references.
Jan 17, 2020
074674a
Make setParameters update the argument list to show defaulted paramet…
Jan 17, 2020
3d64209
make sure newparams are validated first and changes propagated to THCM
ipelupessy Jan 22, 2020
bba773b
fix sres parameter (still needs update)
ipelupessy Jan 22, 2020
9d55e0e
change the ocean and thcm parameter list to purely private
ipelupessy Jan 23, 2020
4c63a7b
remove unimplemented constructor and fix info
ipelupessy Jan 23, 2020
832f5f4
Readd reference based constructors for Ocean & THCM.
Jan 28, 2020
4e7c544
Name Teuchos::ParameterLists for debugging.
Jan 28, 2020
f4f0070
Default all parameters to be immutable and set members from the const…
Jan 31, 2020
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
196 changes: 117 additions & 79 deletions src/ocean/Ocean.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,20 @@ extern "C" _SUBROUTINE_(set_seaice_parameters)(SeaIce::CommPars*);

//=====================================================================
// Constructor:
Ocean::Ocean(RCP<Epetra_Comm> Comm, ParameterList oceanParamList)
Ocean::Ocean(RCP<Epetra_Comm> Comm)
: Ocean(Comm, Teuchos::rcp(new Teuchos::ParameterList()))
{}

Ocean::Ocean(RCP<Epetra_Comm> Comm, Teuchos::RCP<Teuchos::ParameterList> oceanParamList)
:
params_ (Teuchos::rcp(new Teuchos::ParameterList)),
solverInitialized_ (false), // Solver needs initialization
precInitialized_ (false), // Preconditioner needs initialization
recompPreconditioner_ (true), // We need a preconditioner to start with
recompMassMat_ (true), // We need a mass matrix to start with

loadSalinityFlux_ (oceanParamList->get("Load salinity flux", false)),
saveSalinityFlux_ (oceanParamList->get("Save salinity flux", true)),
loadTemperatureFlux_ (oceanParamList->get("Load temperature flux", false)),
saveTemperatureFlux_ (oceanParamList->get("Save temperature flux", true)),

useFort3_ (oceanParamList->get("Use legacy fort.3 output", false)),
useFort44_ (oceanParamList->get("Use legacy fort.44 output", true)),
saveColumnIntegral_ (oceanParamList->get("Save column integral", false)),
maxMaskFixes_ (oceanParamList->get("Max mask fixes", 5)),

landmaskFile_ (oceanParamList->sublist("THCM").get("Land Mask", "none")),

analyzeJacobian_ (oceanParamList->get("Analyze Jacobian", true))
recompMassMat_ (true) // We need a mass matrix to start with
{
INFO("Ocean: constructor...");

// inherited input/output datamembers
inputFile_ = oceanParamList->get("Input file", "ocean_input.h5");
outputFile_ = oceanParamList->get("Output file", "ocean_output.h5");
saveMask_ = oceanParamList->get("Save mask", true);
loadMask_ = oceanParamList->get("Load mask", true);

loadState_ = oceanParamList->get("Load state", false);
saveState_ = oceanParamList->get("Save state", true);
saveEvery_ = oceanParamList->get("Save frequency", 0);

// initialize postprocessing counter
ppCtr_ = 0;

Expand All @@ -95,11 +76,12 @@ Ocean::Ocean(RCP<Epetra_Comm> Comm, ParameterList oceanParamList)
// THCM is implemented as a Singleton, which allows only a single
// instance at a time. The Ocean class can access THCM with a call
// to THCM::Instance()
Teuchos::ParameterList &thcmList =
oceanParamList->sublist("THCM");
auto thcmList = Teuchos::sublist(oceanParamList, "THCM", true);

thcm_ = rcp(new THCM(thcmList, comm_));

setParameters(*oceanParamList); // note: setParameters needs thcm_ to exist

// Throw a few errors if the parameters are odd
if ((thcm_->getSRES() || thcm_->getITS()) && loadSalinityFlux_)
{
Expand Down Expand Up @@ -127,11 +109,6 @@ Ocean::Ocean(RCP<Epetra_Comm> Comm, ParameterList oceanParamList)
// grid representation of te state
grid_ = rcp(new OceanGrid(domain_));

// Read starting parameters from xml
Teuchos::ParameterList& startList =
thcmList.sublist("Starting Parameters");
THCM::Instance().ReadParameters(startList);

// If specified we load a pre-existing state and parameters (x,l)
// thereby overwriting the starting parameters
// This will be able to load salinity and temperature fluxes as well.
Expand Down Expand Up @@ -202,7 +179,7 @@ Ocean::Ocean(RCP<Epetra_Comm> Comm, ParameterList oceanParamList)
surfaceSimporter_ =
Teuchos::rcp(new Epetra_Import(*sIndexMap_, state_->Map()));

INFO(*oceanParamList);
INFO(oceanParamList);
ipelupessy marked this conversation as resolved.
Show resolved Hide resolved
INFO("\n");
INFO("Ocean couplings: coupled_T = " << getCoupledT() );
INFO(" coupled_S = " << getCoupledS() );
Expand Down Expand Up @@ -941,9 +918,6 @@ void Ocean::initializeSolver()
{
INFO("Ocean: initialize solver...");

solverParams_ = rcp(new Teuchos::ParameterList);
updateParametersFromXmlFile("solver_params.xml", solverParams_.ptr());

// Initialize the preconditioner
if (!precInitialized_)
initializePreconditioner();
Expand Down Expand Up @@ -975,42 +949,44 @@ void Ocean::initializeBelos()

problem_->setRightPrec(belosPrec);

const Teuchos::ParameterList &belosParams = params_->sublist("Belos Solver");

// A few FGMRES parameters are made available in solver_params.xml:
int gmresIters = solverParams_->get("FGMRES iterations", 500);
double gmresTol = solverParams_->get("FGMRES tolerance", 1e-8);
int maxrestarts = solverParams_->get("FGMRES restarts", 0);
int output = solverParams_->get("FGMRES output", 100);
bool testExpl = solverParams_->get("FGMRES explicit residual test", false);
int gmresIters = belosParams.get<int>("FGMRES iterations");
double gmresTol = belosParams.get<double>("FGMRES tolerance");
int maxrestarts = belosParams.get<int>("FGMRES restarts");
int output = belosParams.get<int>("FGMRES output");
bool testExpl = belosParams.get<bool>("FGMRES explicit residual test");

int NumGlobalElements = state_->GlobalLength();
int blocksize = 1; // number of vectors in rhs
int maxiters = NumGlobalElements/blocksize - 1;

// Create Belos parameterlist
belosParamList_ = rcp(new Teuchos::ParameterList());
belosParamList_->set("Block Size", blocksize);
belosParamList_->set("Flexible Gmres", true);
belosParamList_->set("Adaptive Block Size", true);
belosParamList_->set("Num Blocks", gmresIters);
belosParamList_->set("Maximum Restarts", maxrestarts);
belosParamList_->set("Orthogonalization","DGKS");
belosParamList_->set("Output Frequency", output);
belosParamList_->set("Verbosity", Belos::Errors + Belos::Warnings);
belosParamList_->set("Maximum Iterations", maxiters);
belosParamList_->set("Convergence Tolerance", gmresTol);
belosParamList_->set("Explicit Residual Test", testExpl);
belosParamList_->set("Implicit Residual Scaling",
RCP<Teuchos::ParameterList> belosParamList = rcp(new Teuchos::ParameterList());
belosParamList->set("Block Size", blocksize);
belosParamList->set("Flexible Gmres", true);
belosParamList->set("Adaptive Block Size", true);
belosParamList->set("Num Blocks", gmresIters);
belosParamList->set("Maximum Restarts", maxrestarts);
belosParamList->set("Orthogonalization","DGKS");
belosParamList->set("Output Frequency", output);
belosParamList->set("Verbosity", Belos::Errors + Belos::Warnings);
belosParamList->set("Maximum Iterations", maxiters);
belosParamList->set("Convergence Tolerance", gmresTol);
belosParamList->set("Explicit Residual Test", testExpl);
belosParamList->set("Implicit Residual Scaling",
"Norm of Preconditioned Initial Residual");

// belosParamList_->set("Implicit Residual Scaling", "Norm of RHS");
// belosParamList_->set("Implicit Residual Scaling", "Norm of Initial Residual");
// belosParamList_->set("Explicit Residual Scaling", "Norm of RHS");
// belosParamList->set("Implicit Residual Scaling", "Norm of RHS");
// belosParamList->set("Implicit Residual Scaling", "Norm of Initial Residual");
// belosParamList->set("Explicit Residual Scaling", "Norm of RHS");

// Belos block FGMRES setup
belosSolver_ =
rcp(new Belos::BlockGmresSolMgr
<double, Epetra_MultiVector, Epetra_Operator>
(problem_, belosParamList_));
(problem_, belosParamList));

// initialize effort counter
effortCtr_ = 0;
Expand Down Expand Up @@ -2200,27 +2176,89 @@ void Ocean::setPar(std::string const &parName, double value)
}

//====================================================================
void Ocean::setParameters(ParameterList pars)

Teuchos::ParameterList
Ocean::getDefaultInitParameters()
{
std::string parName;
double parValue;
// This is similar to reading from HDF5
for (int par = 1; par <= _NPAR_; ++par)
{
parName = THCM::Instance().int2par(par);
parValue = getPar(parName);
Teuchos::ParameterList result = getDefaultParameters();
result.sublist("THCM") = THCM::getDefaultInitParameters();
return result;
}

// Overwrite continuation parameter and put it in THCM
try
{
parValue = pars->get(parName, parValue);
}
catch (EpetraExt::Exception &e)
{
e.Print();
continue;
}
Teuchos::ParameterList
Ocean::getDefaultParameters()
{
Teuchos::ParameterList result;
result.get("Load salinity flux", false);
result.get("Save salinity flux", true);
result.get("Load temperature flux", false);
result.get("Save temperature flux", true);

setPar(parName, parValue);
}
result.get("Use legacy fort.3 output", false);
result.get("Use legacy fort.44 output", true);
result.get("Save column integral", false);
result.get("Max mask fixes", 5);

result.get("Analyze Jacobian", true);

result.get("Input file", "ocean_input.h5");
result.get("Output file", "ocean_output.h5");
result.get("Save mask", true);
result.get("Load mask", true);

result.get("Load state", false);
result.get("Save state", true);
result.get("Save frequency", 0);
result.get("Store everything", false);

Teuchos::ParameterList& solverParams = result.sublist("Belos Solver");
solverParams.get("FGMRES iterations", 500);
solverParams.get("FGMRES tolerance", 1e-8);
solverParams.get("FGMRES restarts", 0);
solverParams.get("FGMRES output", 100);
solverParams.get("FGMRES explicit residual test", false);

result.sublist("THCM") = THCM::getDefaultParameters();

return result;
}

const Teuchos::ParameterList& Ocean::getParameters()
{
params_->sublist("THCM")=thcm_->getParameters();
return *params_;
}

void Ocean::setParameters(Teuchos::ParameterList& newParams)
{
Teuchos::ParameterList tmpParams(*params_);
tmpParams.setParameters(newParams);
thcm_->setParameters(newParams.sublist("THCM"));
tmpParams.validateParametersAndSetDefaults(getDefaultInitParameters());

params_->setParameters(tmpParams);

loadSalinityFlux_ = params_->get<bool>("Load salinity flux");
saveSalinityFlux_ = params_->get<bool>("Save salinity flux");
loadTemperatureFlux_ = params_->get<bool>("Load temperature flux");
saveTemperatureFlux_ = params_->get<bool>("Save temperature flux");

useFort3_ = params_->get<bool>("Use legacy fort.3 output");
useFort44_ = params_->get<bool>("Use legacy fort.44 output");
saveColumnIntegral_ = params_->get<bool>("Save column integral");
maxMaskFixes_ = params_->get<int>("Max mask fixes");

analyzeJacobian_ = params_->get<bool>("Analyze Jacobian");

// inherited input/output datamembers
inputFile_ = params_->get<std::string>("Input file");
outputFile_ = params_->get<std::string>("Output file");
saveMask_ = params_->get<bool>("Save mask");
loadMask_ = params_->get<bool>("Load mask");

loadState_ = params_->get<bool>("Load state");
saveState_ = params_->get<bool>("Save state");
saveEvery_ = params_->get<int>("Save frequency");

newParams = *params_;
}
20 changes: 10 additions & 10 deletions src/ocean/Ocean.H
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public:
using LandMask = Utils::MaskStruct;

protected:
Teuchos::RCP<Teuchos::ParameterList> params_;

Teuchos::RCP<THCM> thcm_;

Expand Down Expand Up @@ -93,10 +94,7 @@ protected:
// grid representation of the state
mutable Teuchos::RCP<OceanGrid> grid_;

ParameterList solverParams_;

// Belos flexible GMRES members
ParameterList belosParamList_;
Teuchos::RCP<Belos::LinearProblem
<double, Epetra_MultiVector, Epetra_Operator> > problem_;
Teuchos::RCP<Belos::BlockGmresSolMgr
Expand Down Expand Up @@ -132,9 +130,6 @@ protected:
//! Maximum number of mask fixing cycles
int maxMaskFixes_;

//! Landmask file
std::string landmaskFile_;

//! Select Jacobian analysis
bool analyzeJacobian_;

Expand All @@ -158,8 +153,9 @@ protected:

public:
//! constructor
Ocean(Teuchos::RCP<Epetra_Comm> Comm,
ParameterList oceanParamList);
Ocean(Teuchos::RCP<Epetra_Comm> Comm);
Ocean(Teuchos::RCP<Epetra_Comm> Comm, Model::ParameterList oceanParamList);
Ocean(Teuchos::RCP<Epetra_Comm> Comm, const Teuchos::ParameterList& oceanParamList);
ipelupessy marked this conversation as resolved.
Show resolved Hide resolved

//! destructor
~Ocean();
Expand All @@ -168,6 +164,12 @@ public:
int modelIdent() const { return 0; }
Teuchos::RCP<Epetra_Comm> Comm() const { return comm_; }

const Teuchos::ParameterList& getParameters();
void setParameters(Teuchos::ParameterList& oceanParamList);

static Teuchos::ParameterList getDefaultInitParameters();
static Teuchos::ParameterList getDefaultParameters();

//! Solve may optionally accept an rhs of VectorPointer type
void solve(Teuchos::RCP<const Epetra_MultiVector> rhs = Teuchos::null);

Expand Down Expand Up @@ -381,8 +383,6 @@ public:
VectorPtr getRowScaling();
VectorPtr getColScaling();

void setParameters(ParameterList pars);

void copyMask(std::string const &fname);

void dumpBlocks()
Expand Down
Loading