-
Notifications
You must be signed in to change notification settings - Fork 8
Add add increment application with variable change capability #67
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # AddIncrement | ||
| ecbuild_add_executable( TARGET fv3jedi_add_increment.x | ||
| SOURCES fv3jedi_add_increment.cc add_increment.h) | ||
| target_compile_features( fv3jedi_add_increment.x PUBLIC cxx_std_17) | ||
| target_link_libraries( fv3jedi_add_increment.x PUBLIC NetCDF::NetCDF_CXX oops fv3jedi) | ||
|
|
||
| # Ensemble AddIncrement | ||
| ecbuild_add_executable( TARGET fv3jedi_ensemble_add_increment.x | ||
| SOURCES fv3jedi_ensemble_add_increment.cc add_increment.h) | ||
| target_compile_features( fv3jedi_ensemble_add_increment.x PUBLIC cxx_std_17) | ||
| target_link_libraries( fv3jedi_ensemble_add_increment.x PUBLIC NetCDF::NetCDF_CXX oops fv3jedi) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * (C) Copyright 2026 NOAA | ||
| * | ||
| * This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
| */ | ||
|
|
||
| #ifndef OOPS_RUNS_ADDINCREMENT_H_ | ||
| #define OOPS_RUNS_ADDINCREMENT_H_ | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "oops/base/Geometry.h" | ||
| #include "oops/base/Increment.h" | ||
| #include "oops/base/State.h" | ||
| #include "oops/base/Variables.h" | ||
| #include "oops/interface/VariableChange.h" | ||
| #include "oops/mpi/mpi.h" | ||
| #include "oops/runs/Application.h" | ||
| #include "oops/util/DateTime.h" | ||
| #include "oops/util/Duration.h" | ||
| #include "oops/util/Logger.h" | ||
|
|
||
| namespace dautils { | ||
|
|
||
| /// Application that adds an increment to a state and writes the sum to a file. | ||
| /// | ||
| /// The increment may optionally be multiplied by a scaling factor and have a different resolution | ||
| /// than the state. | ||
| template <typename MODEL> class AddIncrement : public oops::Application { | ||
| typedef oops::Geometry<MODEL> Geometry_; | ||
| typedef oops::State<MODEL> State_; | ||
| typedef oops::Increment<MODEL> Increment_; | ||
| typedef oops::VariableChange<MODEL> VariableChange_; | ||
|
|
||
| public: | ||
| // ----------------------------------------------------------------------------- | ||
| explicit AddIncrement(const eckit::mpi::Comm & comm = oops::mpi::world()) : Application(comm) {} | ||
| // ----------------------------------------------------------------------------- | ||
| virtual ~AddIncrement() {} | ||
| // ----------------------------------------------------------------------------- | ||
| int execute(const eckit::Configuration & fullConfig) const override { | ||
| // Setup resolution | ||
| const Geometry_ stateResol(eckit::LocalConfiguration(fullConfig, "state geometry"), | ||
| this->getComm()); | ||
|
|
||
| const Geometry_ incResol(eckit::LocalConfiguration(fullConfig, "increment geometry"), | ||
| this->getComm()); | ||
|
|
||
| // Read state | ||
| State_ xx(stateResol, eckit::LocalConfiguration(fullConfig, "state")); | ||
| oops::Log::test() << "State: " << xx << std::endl; | ||
|
|
||
| // Read increment | ||
| const eckit::LocalConfiguration incParams(fullConfig, "increment"); | ||
| oops::Variables addedVars(incParams, "added variables"); | ||
| Increment_ dx(incResol, addedVars, xx.validTime()); | ||
| dx.read(incParams); | ||
| oops::Log::test() << "Increment: " << dx << std::endl; | ||
|
|
||
| // Scale increment | ||
| if (incParams.has("scaling factor")) { | ||
| dx *= incParams.getDouble("scaling factor"); | ||
| oops::Log::test() << "Scaled the increment: " << dx << std::endl; | ||
| } | ||
|
|
||
| // Assertions on state versus increment | ||
| ASSERT(xx.validTime() == dx.validTime()); | ||
|
|
||
| // Add increment to state | ||
| xx += dx; | ||
|
|
||
| // Optional variable change to recomputed chosen state variables in final state | ||
| // This is useful if, for example, the state has both delp and ps but the increment only has | ||
| // delp. Simple increment addition of just delp to the state would result in an incorrect ps | ||
| // value since ps is a function of delp. ps would need to be recalculated after the increment addition. | ||
| if ( fullConfig.has("variable change") ) { | ||
| // Setup variable change | ||
| const eckit::LocalConfiguration varChangeConfig(fullConfig, "variable change"); | ||
| std::unique_ptr<VariableChange_> vc; | ||
| vc.reset(new VariableChange_(varChangeConfig, stateResol)); | ||
|
|
||
| // Get additional variables to be derived by variable change | ||
| oops::Variables varsChanged(varChangeConfig, "recalculated variables"); | ||
|
|
||
| // Save state variables with and without variable change variables | ||
| oops::Variables stateVarsReduced = xx.variables(); | ||
| oops::Variables stateVarsExpanded = xx.variables(); | ||
| stateVarsReduced -= varsChanged; | ||
| stateVarsExpanded += varsChanged; | ||
|
|
||
| // Change state to reduced set of variables | ||
| // This is necessary since a variable needs to be missing from the state in order | ||
| // for it to be computed by the final variable change. | ||
| vc->changeVar(xx, stateVarsReduced); | ||
|
|
||
| // Change variables to expanded set of variables | ||
| // This step actually computes the variables we want | ||
| vc->changeVar(xx, stateVarsExpanded); | ||
| } | ||
|
|
||
| // Write state | ||
| xx.write(eckit::LocalConfiguration(fullConfig, "output")); | ||
|
|
||
| oops::Log::test() << "State plus increment: " << xx << std::endl; | ||
|
|
||
| return 0; | ||
| } | ||
| // ----------------------------------------------------------------------------- | ||
| private: | ||
| std::string appname() const override { | ||
| return "dautils::AddIncrement<" + MODEL::name() + ">"; | ||
| } | ||
| // ----------------------------------------------------------------------------- | ||
| }; | ||
|
|
||
| } // namespace oops | ||
| #endif // OOPS_RUNS_ADDINCREMENT_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include "add_increment.h" | ||
|
|
||
| #include "fv3jedi/Utilities/Traits.h" | ||
|
|
||
| #include "oops/runs/Run.h" | ||
|
|
||
| int main(int argc, char ** argv) { | ||
| oops::Run run(argc, argv); | ||
| dautils::AddIncrement<fv3jedi::Traits> addIncrement; | ||
| return run.execute(addIncrement); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include "add_increment.h" | ||
|
|
||
| #include "fv3jedi/Utilities/Traits.h" | ||
|
|
||
| #include "oops/runs/EnsembleApplication.h" | ||
| #include "oops/runs/Run.h" | ||
|
|
||
| int main(int argc, char ** argv) { | ||
| oops::Run run(argc, argv); | ||
| oops::EnsembleApplication<dautils::AddIncrement<fv3jedi::Traits>> addIncrement; | ||
| return run.execute(addIncrement); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.