Skip to content

Commit

Permalink
minor cleanup toward release, fixes albedo evaluators to only require…
Browse files Browse the repository at this point in the history
… snow density if they will use it
  • Loading branch information
ecoon committed Mar 18, 2024
1 parent c39a817 commit 6930a11
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ namespace Relations {
AlbedoThreeComponentEvaluator::AlbedoThreeComponentEvaluator(Teuchos::ParameterList& plist)
: EvaluatorSecondaryMonotypeCV(plist)
{
// parameters
a_ice_ = plist_.get<double>("albedo ice [-]", 0.44);
a_water_ = plist_.get<double>("albedo water [-]", 0.1168);
is_constant_snow_albedo_ = plist_.isParameter("albedo snow [-]");
if (is_constant_snow_albedo_) { a_snow_ = plist_.get<double>("albedo snow [-]"); }

e_ice_ = plist_.get<double>("emissivity ice [-]", 0.98);
e_water_ = plist_.get<double>("emissivity water [-]", 0.995);
e_snow_ = plist_.get<double>("emissivity snow [-]", 0.98);

// determine the domain
Key akey = my_keys_.front().first;
domain_ = Keys::getDomain(akey);
Expand All @@ -40,22 +50,14 @@ AlbedoThreeComponentEvaluator::AlbedoThreeComponentEvaluator(Teuchos::ParameterL

// dependencies
// -- snow properties
snow_dens_key_ = Keys::readKey(plist, domain_snow_, "snow density", "density");
dependencies_.insert(KeyTag{ snow_dens_key_, tag });
if (!is_constant_snow_albedo_) {
snow_dens_key_ = Keys::readKey(plist, domain_snow_, "snow density", "density");
dependencies_.insert(KeyTag{ snow_dens_key_, tag });
}

// -- skin properties
unfrozen_fraction_key_ = Keys::readKey(plist, domain_, "unfrozen fraction", "unfrozen_fraction");
dependencies_.insert(KeyTag{ unfrozen_fraction_key_, tag });

// parameters
a_ice_ = plist_.get<double>("albedo ice [-]", 0.44);
a_water_ = plist_.get<double>("albedo water [-]", 0.1168);
is_constant_snow_albedo_ = plist_.isParameter("albedo snow [-]");
if (is_constant_snow_albedo_) { a_snow_ = plist_.get<double>("albedo snow [-]"); }

e_ice_ = plist_.get<double>("emissivity ice [-]", 0.98);
e_water_ = plist_.get<double>("emissivity water [-]", 0.995);
e_snow_ = plist_.get<double>("emissivity snow [-]", 0.98);
}

// Required methods from EvaluatorSecondaryMonotypeCV
Expand Down Expand Up @@ -113,7 +115,10 @@ AlbedoThreeComponentEvaluator::EvaluatePartialDerivative_(
void
AlbedoThreeComponentEvaluator::EnsureCompatibility_Structure_(State& S)
{
S.GetRecordSetW(my_keys_.front().first).set_subfieldnames({ "bare", "water", "snow" });
EnsureCompatibility_StructureSame_(S);
for (const auto& key : my_keys_) {
S.GetRecordSetW(key.first).set_subfieldnames({ "bare", "water", "snow" });
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ namespace Relations {
AlbedoTwoComponentEvaluator::AlbedoTwoComponentEvaluator(Teuchos::ParameterList& plist)
: EvaluatorSecondaryMonotypeCV(plist)
{
// parameters
a_ice_ = plist_.get<double>("albedo ice [-]", 0.44);
a_water_ = plist_.get<double>("albedo water [-]", 0.1168);
is_constant_snow_albedo_ = plist_.isParameter("albedo snow [-]");
if (is_constant_snow_albedo_) { a_snow_ = plist_.get<double>("albedo snow [-]"); }

e_ice_ = plist_.get<double>("emissivity ice [-]", 0.98);
e_water_ = plist_.get<double>("emissivity water [-]", 0.995);
e_snow_ = plist_.get<double>("emissivity snow [-]", 0.98);

// determine the domain
Key akey = my_keys_.front().first;
domain_ = Keys::getDomain(akey);
Expand All @@ -40,8 +50,10 @@ AlbedoTwoComponentEvaluator::AlbedoTwoComponentEvaluator(Teuchos::ParameterList&

// dependencies
// -- snow properties
snow_dens_key_ = Keys::readKey(plist, domain_snow_, "snow density", "density");
dependencies_.insert(KeyTag{ snow_dens_key_, tag });
if (!is_constant_snow_albedo_) {
snow_dens_key_ = Keys::readKey(plist, domain_snow_, "snow density", "density");
dependencies_.insert(KeyTag{ snow_dens_key_, tag });
}

// -- skin properties
unfrozen_fraction_key_ = Keys::readKey(plist, domain_, "unfrozen fraction", "unfrozen_fraction");
Expand All @@ -50,16 +62,6 @@ AlbedoTwoComponentEvaluator::AlbedoTwoComponentEvaluator(Teuchos::ParameterList&
// -- skin properties
ponded_depth_key_ = Keys::readKey(plist, domain_, "ponded depth", "ponded_depth");
dependencies_.insert(KeyTag{ ponded_depth_key_, tag });

// parameters
a_ice_ = plist_.get<double>("albedo ice [-]", 0.44);
a_water_ = plist_.get<double>("albedo water [-]", 0.1168);
is_constant_snow_albedo_ = plist_.isParameter("albedo snow [-]");
if (is_constant_snow_albedo_) { a_snow_ = plist_.get<double>("albedo snow [-]"); }

e_ice_ = plist_.get<double>("emissivity ice [-]", 0.98);
e_water_ = plist_.get<double>("emissivity water [-]", 0.995);
e_snow_ = plist_.get<double>("emissivity snow [-]", 0.98);
}

// Required methods from EvaluatorSecondaryMonotypeCV
Expand Down Expand Up @@ -127,7 +129,10 @@ AlbedoTwoComponentEvaluator::EvaluatePartialDerivative_(
void
AlbedoTwoComponentEvaluator::EnsureCompatibility_Structure_(State& S)
{
S.GetRecordSetW(my_keys_.front().first).set_subfieldnames({ "bare_or_water", "snow" });
EnsureCompatibility_StructureSame_(S);
for (const auto& key : my_keys_) {
S.GetRecordSetW(key.first).set_subfieldnames({ "bare_or_water", "snow" });
}
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class CanopyRadiationEvaluator : public EvaluatorSecondaryMonotypeCV {

protected:
virtual void EnsureCompatibility_ToDeps_(State& S) override;
virtual void EnsureCompatibility_Structure_(State& S) {
EnsureCompatibility_StructureSame_(S);
}

// Required methods from EvaluatorSecondaryMonotypeCV
virtual void Evaluate_(const State& S, const std::vector<CompositeVector*>& results) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class DrainageEvaluator : public EvaluatorSecondaryMonotypeCV {
const Tag& wrt_tag,
const std::vector<CompositeVector*>& results) override;

virtual void EnsureCompatibility_Structure_(State& S) {
EnsureCompatibility_StructureSame_(S);
}

protected:
Key drainage_key_;
Key fracwet_key_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class InterceptionFractionEvaluator : public EvaluatorSecondaryMonotypeCV {
const Key& wrt_key,
const Tag& wrt_tag,
const std::vector<CompositeVector*>& results) override;
virtual void EnsureCompatibility_Structure_(State& S) {
EnsureCompatibility_StructureSame_(S);
}

void InitializeFromPlist_();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Here the net radiation is positive for energy inputs to the layer. Note that
ground is based on the two-channel (land + snow) while canopy is assumed to be
a simple, single layer.
This evaluator requires that the surface temperature, snow temperature, and
canopy temperature are known, or at least being solved for.
Requires the use of LandCover types, for albedo and Beer's law coefficients.
This is combination of CLM v4.5 Tech Note and Beer's law for attenuation of
Expand Down Expand Up @@ -90,6 +93,9 @@ class RadiationBalanceEvaluator : public EvaluatorSecondaryMonotypeCV {

protected:
virtual void EnsureCompatibility_ToDeps_(State& S) override;
virtual void EnsureCompatibility_Structure_(State& S) {
EnsureCompatibility_StructureSame_(S);
}

// Required methods from EvaluatorSecondaryMonotypeCV
virtual void Evaluate_(const State& S, const std::vector<CompositeVector*>& results) override;
Expand Down
8 changes: 7 additions & 1 deletion src/pks/surface_balance/surface_balance_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ SurfaceBalanceBase::Setup()
.SetMesh(mesh_)
->AddComponent("cell", AmanziMesh::Entity_kind::CELL, 1);
S_->RequireDerivative<CompositeVector, CompositeVectorSpace>(
conserved_key_, tag_next_, key_, tag_next_);
conserved_key_, tag_next_, key_, tag_next_)
.SetMesh(mesh_)
->AddComponent("cell", AmanziMesh::Entity_kind::CELL, 1);
// NOTE, remove SetMesh/AddComponent lines after fixing amanzi/ats#167.
// The mesh should get set by the evaluator, but when
// the evaluator isn't actually differentiable, it
// doesn't get done.

// and at the current time, where it is a copy evaluator
requireAtCurrent(conserved_key_, tag_current_, *S_, name_);
Expand Down

0 comments on commit 6930a11

Please sign in to comment.