Skip to content

Commit

Permalink
Create a default parameterlist to validate against.
Browse files Browse the repository at this point in the history
  • Loading branch information
Merijn Verstraaten committed Oct 29, 2019
1 parent 4d6b91f commit 14bbef1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 28 deletions.
106 changes: 79 additions & 27 deletions src/ocean/Ocean.C
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,24 @@ extern "C" _SUBROUTINE_(set_seaice_parameters)(SeaIce::CommPars*);

//=====================================================================
// Constructor:
Ocean::Ocean(RCP<Epetra_Comm> Comm)
: Ocean(Comm, defaultParameters())
{}

Ocean::Ocean(RCP<Epetra_Comm> Comm, Model::ParameterList paramListPtr)
: Ocean(Comm, *paramListPtr)
: Ocean(Comm, paramListPtr == Teuchos::null ? defaultParameters() : *paramListPtr)
{}

Ocean::Ocean(RCP<Epetra_Comm> Comm, Teuchos::ParameterList& oceanParamList)
Ocean::Ocean(RCP<Epetra_Comm> Comm, const Teuchos::ParameterList& oceanParamList)
:
params(defaultParameters()),
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);
setParameters(oceanParamList);

// initialize postprocessing counter
ppCtr_ = 0;
Expand Down Expand Up @@ -2202,3 +2184,73 @@ void Ocean::setPar(std::string const &parName, double value)
if (parIdent > 0 && parIdent <= _NPAR_)
FNAME(setparcs)(&parIdent, &value);
}

//====================================================================
static Teuchos::ParameterList
createDefaultParameterList()
{
Teuchos::ParameterList result;
result.set("Load salinity flux", false);
result.set("Save salinity flux", true);
result.set("Load temperature flux", false);
result.set("Save temperature flux", true);

result.set("Use legacy fort.3 output", false);
result.set("Use legacy fort.44 output", true);
result.set("Save column integral", false);
result.set("Max mask fixes", 5);

result.sublist("THCM").set("Land Mask", "none");

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

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

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

return result;
}

const Teuchos::ParameterList&
Ocean::defaultParameters()
{ return Ocean::defaultParams; }

const Teuchos::ParameterList& Ocean::getParameters()
{ return params; }

void Ocean::setParameters(const Teuchos::ParameterList& newParams)
{
params.setParameters(newParams);

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");

landmaskFile_ = params.sublist("THCM").get<std::string>("Land Mask");
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");
}

const Teuchos::ParameterList
Ocean::defaultParams = createDefaultParameterList();
11 changes: 10 additions & 1 deletion 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::ParameterList params;

Teuchos::RCP<THCM> thcm_;

Expand Down Expand Up @@ -157,8 +158,9 @@ protected:

public:
//! constructor
Ocean(Teuchos::RCP<Epetra_Comm> Comm);
Ocean(Teuchos::RCP<Epetra_Comm> Comm, Model::ParameterList oceanParamList);
Ocean(Teuchos::RCP<Epetra_Comm> Comm, Teuchos::ParameterList& oceanParamList);
Ocean(Teuchos::RCP<Epetra_Comm> Comm, const Teuchos::ParameterList& oceanParamList);

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

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

static const Teuchos::ParameterList& defaultParameters();

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

Expand Down Expand Up @@ -428,5 +435,7 @@ private:
Teuchos::RCP<Epetra_Vector> initialState();

void inspectVector(VectorPtr x);

static const Teuchos::ParameterList defaultParams;
};
#endif

0 comments on commit 14bbef1

Please sign in to comment.