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

add VADER to SOCA #887

Merged
merged 5 commits into from
May 30, 2023
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
env:
global:
- MAIN_REPO=soca
- LIB_REPOS="gsw mom6 icepack oops ioda ufo saber"
- LIB_REPOS="gsw mom6 icepack oops vader ioda ufo saber"
- BUILD_OPT="-DBUILD_ICEPACK=ON"
- BUILD_OPT_mom6="-DENABLE_OCEAN_BGC=ON"
- BUILD_OPT_oops="-DENABLE_QG_MODEL=OFF -DENABLE_LORENZ95_MODEL=OFF"
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ find_package( eckit 1.11.6 REQUIRED)
find_package( fckit 0.7.0 REQUIRED)
find_package( atlas 0.20.2 REQUIRED)
find_package( oops 1.3.0 REQUIRED)
find_package( vader 1.3.0 REQUIRED)
find_package( saber 1.0.0 REQUIRED)
find_package( ioda 1.0.0 REQUIRED)
find_package( ufo 1.3.0 REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions bundle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ option(BUILD_UFSM6C6 "download and install the UFS" OFF)
# required repositories

ecbuild_bundle( PROJECT oops GIT "https://github.com/jcsda-internal/oops.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT vader GIT "https://github.com/jcsda-internal/vader.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT saber GIT "https://github.com/jcsda-internal/saber.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT ioda GIT "https://github.com/jcsda-internal/ioda.git" UPDATE BRANCH develop )
ecbuild_bundle( PROJECT gsw GIT "https://github.com/jcsda-internal/GSW-Fortran.git" UPDATE BRANCH develop )
Expand Down
1 change: 1 addition & 0 deletions src/soca/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ target_link_libraries( soca PUBLIC oops )
target_link_libraries( soca PUBLIC saber )
target_link_libraries( soca PUBLIC ioda )
target_link_libraries( soca PUBLIC ufo )
target_link_libraries( soca PUBLIC vader )
if ( BUILD_ICEPACK )
target_link_libraries( soca PUBLIC icepack )
endif()
Expand Down
7 changes: 7 additions & 0 deletions src/soca/State/State.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,11 @@ namespace soca {
// get field, with halo, and no masked values
soca_state_to_fieldset_f90(toFortran(), vars_, fset.get(), false);
}

// -----------------------------------------------------------------------------

void State::fromFieldSet(const atlas::FieldSet &fs) {
// set field, with halo, and no masked values
soca_state_from_fieldset_f90(toFortran(), vars_, fs.get(), false);
}
} // namespace soca
3 changes: 2 additions & 1 deletion src/soca/State/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ namespace soca {
void zero();
void accumul(const double &, const State &);

/// Interfaces required for OOPS interpolation
/// ATLAS Interfaces
void toFieldSet(atlas::FieldSet &) const;
void fromFieldSet(const atlas::FieldSet &);

private:
void print(std::ostream &) const override;
Expand Down
4 changes: 4 additions & 0 deletions src/soca/State/StateFortran.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ namespace soca {
const oops::Variables &,
atlas::field::FieldSetImpl *,
const bool &);
void soca_state_from_fieldset_f90(const F90flds &,
const oops::Variables &,
const atlas::field::FieldSetImpl *,
const bool &);
}
} // namespace soca
#endif // SOCA_STATE_STATEFORTRAN_H_
21 changes: 21 additions & 0 deletions src/soca/State/soca_state.interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,25 @@ subroutine soca_state_to_fieldset_c(c_key_self, c_vars, c_fieldset, c_masked) &
call self%to_fieldset(vars, afieldset, logical(c_masked))
end subroutine

! ------------------------------------------------------------------------------
!> C++ interface for soca_increment_mod::soca_increment::from_fieldset()
subroutine soca_state_from_fieldset_c(c_key_self, c_vars, c_afieldset, c_masked) &
bind (c,name='soca_state_from_fieldset_f90')
integer(c_int), intent(in) :: c_key_self
type(c_ptr), value, intent(in) :: c_vars
type(c_ptr), value, intent(in) :: c_afieldset
logical(c_bool), intent(in) :: c_masked

type(soca_state), pointer :: self
type(oops_variables) :: vars
type(atlas_fieldset) :: afieldset

call soca_state_registry%get(c_key_self, self)
vars = oops_variables(c_vars)
afieldset = atlas_fieldset(c_afieldset)

call self%from_fieldset(vars, afieldset, logical(c_masked))

end subroutine

end module soca_state_mod_c
68 changes: 56 additions & 12 deletions src/soca/VariableChange/VariableChange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace soca {

VariableChange::VariableChange(const Parameters_ & params,
const Geometry & geometry) {
// setup vader
vader_.reset(new vader::Vader(params.vader));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider passing Vader a defined cookbook when you construct it, maybe just including a single recipe for now. (I haven't tested Vader with an empty cookbook.) That way you control it. Otherwise Vader will use its default cookbook, which gets updated from time to time. But since Vader doesn't currently have any recipes (I don't think) for variables you're producing, it probably doesn't matter much either way right now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ svahl991 Thanks I thought about that, but I figured would take my chances for now since there are no relevant recipes that could break anything for me. I'll add a proper cookbook when I (soonish?) work on getting some marine var changes into vader.


// Create the variable change
variableChange_.reset(VariableChangeFactory::create(geometry,
params.variableChangeParametersWrapper.variableChangeParameters.value()));
Expand All @@ -44,8 +47,27 @@ void VariableChange::changeVar(State & x, const oops::Variables & vars) const {
// TODO(travis) rename in/out variables so that skipping this
// works for Model2Ana (i.e. we need rotated/unrotate u/v renamed different)
// // If the variables are the same, don't bother doing anything!
// if (!(x.variables() == vars)) {

// if (!(x.variables() == vars))

// call Vader
// ----------------------------------------------------------------------------
// Record start variables
oops::Variables varsFilled = x.variables();
oops::Variables varsVader = vars;
varsVader -= varsFilled; // Pass only the needed variables

// Call Vader. On entry, varsVader holds the vars requested from Vader; on exit,
// it holds the vars NOT fulfilled by Vader, i.e., the vars still to be requested elsewhere.
// vader_->changeVar also returns the variables fulfilled by Vader. These variables are allocated
// and populated and added to the FieldSet (xfs).
atlas::FieldSet xfs;
x.toFieldSet(xfs);
varsFilled += vader_->changeVar(xfs, varsVader);
x.updateFields(varsFilled);
x.fromFieldSet(xfs);

// soca specific transforms
// ----------------------------------------------------------------------------
// Create output state
State xout(x.geometry(), vars, x.time());

Expand All @@ -56,7 +78,6 @@ void VariableChange::changeVar(State & x, const oops::Variables & vars) const {
x.updateFields(vars);
x = xout;

// }

Log::trace() << "VariableChange::changeVar done" << std::endl;
}
Expand All @@ -73,18 +94,41 @@ void VariableChange::changeVarInverse(State & x,
<< vars << std::endl;

// If the variables are the same, don't bother doing anything!
if (!(x.variables() == vars)) {
// Create output state
State xout(x.geometry(), vars, x.time());

// Call variable change
variableChange_->changeVarInverse(x, xout);

// Copy data from temporary state
if (vars <= x.variables()) {
x.updateFields(vars);
x = xout;
oops::Log::info() << "VariableChange::changeVarInverse done (identity)" << std::endl;
return;
}

// call Vader
// ----------------------------------------------------------------------------
// Record start variables
oops::Variables varsFilled = x.variables();
oops::Variables varsVader = vars;
varsVader -= varsFilled; // Pass only the needed variables

// Call Vader. On entry, varsVader holds the vars requested from Vader; on exit,
// it holds the vars NOT fulfilled by Vader, i.e., the vars still to be requested elsewhere.
// vader_->changeVar also returns the variables fulfilled by Vader. These variables are allocated
// and populated and added to the FieldSet (xfs).
atlas::FieldSet xfs;
x.toFieldSet(xfs);
varsFilled += vader_->changeVar(xfs, varsVader);
x.updateFields(varsFilled);
x.fromFieldSet(xfs);

// soca specific transforms
// -----------------------------------------------------------------------------
// Create output state
State xout(x.geometry(), vars, x.time());

// Call variable change
variableChange_->changeVarInverse(x, xout);

// Copy data from temporary state
x.updateFields(vars);
x = xout;

Log::trace() << "VariableChange::changeVarInverse done" << std::endl;
}

Expand Down
5 changes: 5 additions & 0 deletions src/soca/VariableChange/VariableChange.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#include "oops/util/parameters/Parameters.h"
#include "oops/util/Printable.h"

#include "vader/vader.h"

#include "soca/VariableChange/Base/VariableChangeBase.h"

// Forward declarations
namespace soca {
class Geometry;
class State;
Expand All @@ -32,6 +35,7 @@ class VariableChangeParameters : public oops::VariableChangeParametersBase {
public:
// Wrapper to VariableChange parameters
VariableChangeParametersWrapper variableChangeParametersWrapper{this};
oops::Parameter<vader::VaderParameters> vader{"vader", {}, this};
};

// -----------------------------------------------------------------------------
Expand All @@ -51,6 +55,7 @@ class VariableChange : public util::Printable {
private:
void print(std::ostream &) const override;
std::unique_ptr<VariableChangeBase> variableChange_;
std::unique_ptr<vader::Vader> vader_;
};

// -----------------------------------------------------------------------------
Expand Down