Skip to content

Commit 7acca22

Browse files
committed
2 parents 6d61829 + c24b294 commit 7acca22

File tree

3 files changed

+163
-5
lines changed

3 files changed

+163
-5
lines changed

docs/atmospheric_physics/Tagging-Instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This page lists instructions for how to create a new atmospheric_physics tag. A
44

55
1. Tags should always be annotated (no lightweight tags).
66
2. Tags should follow the naming convention listed [below](#tag-naming-conventions).
7-
3. Tags should point to merge commits into the main branch.
7+
3. All merge commits into the main branch should be tagged.
88
4. Tags can only be created by people who have write access.
99

1010
## How to create a git tag via the command line

docs/atmospheric_physics/development_workflow.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ The general workflow for adding a feature, bug-fix, or modification to atmospher
1818

1919
If you need an official tag for your new additions, then once your `development` PR has been merged you will need to do the following:
2020

21-
1. **Open a PR that merges the atmospheric_physics `development` branch into `main`. Ensure that the PR description lists every PR that went into `development` since the last update to `main`.**
21+
1. **Open a PR that merges the atmospheric_physics `development` branch into `main`. Ensure that the PR description lists the title and number of every PR that went into `development` since the last update to `main`.**
2222
2. **Fix any failing tests. This includes tests on the target host models that will be using the new tag.**
2323
3. **Merge (do not squash!) the PR.**
24-
4. **Tag the new merge commit.**
24+
4. **[Tag](Tagging-Instructions.md) the new merge commit.**
2525

2626
## Workflow details
2727

@@ -224,7 +224,10 @@ At a minimum, unit tests for ESCOMP source code should:
224224

225225
**11. Update the `NamesNotInDictionary.txt` file using the instructions [below](#updating-namesnotindictionarytxt-file).**
226226

227-
**12. Once all reviewers sign off on your modifications, then the PR will be squashed and merged. Congratulations! Your code is now in atmospheric_physics!**
227+
**12. Once all reviewers sign off on your modifications, then the PR can be merged. Congratulations! Your code is now in atmospheric_physics!**
228+
229+
- If the PR is to `develop`, you should select "Squash and Merge"
230+
- If the PR is to `main`, DO NOT squash and instead select "Merge Commit"
228231

229232
### Updating NamesNotInDictionary.txt file
230233

docs/conversion/walkthrough.md

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,162 @@ Bug gets extremely lucky (or maybe he's just really skilled) and there are no di
690690
Bug commits his changes to his fork/branch of the three repos: CAM, CAM-SIMA, atmospheric_physics.
691691

692692
### Unit testing
693-
Bug adds PfUnit tests for his newly-created scheme per the [atmospheric_physics development workflow](../atmospheric_physics/development_workflow.md#5-unit-testing).
693+
694+
Lets say you added a utility function in `physics_tendency_updaters.F90
695+
` to apply the pressure tendency of the atmosphere:
696+
697+
```fortran
698+
subroutine apply_tendency_of_air_pressure_run(nz, p_tend, pressure, dPdt_total, &
699+
dt, errcode, errmsg)
700+
! Dummy arguments
701+
integer, intent(in) :: nz ! Num vertical layers
702+
real(kind_phys), intent(in) :: p_tend(:,:) ! pressure tendency
703+
real(kind_phys), intent(inout) :: pressure(:,:) ! air pressure
704+
real(kind_phys), intent(inout) :: dPdt_total(:,:) ! total temp. tendency
705+
real(kind_phys), intent(in) :: dt ! physics time step
706+
integer, intent(out) :: errcode
707+
character(len=512), intent(out) :: errmsg
708+
709+
! Local variable
710+
integer :: klev
711+
712+
errcode = 0
713+
errmsg = ''
714+
715+
do klev = 1, nz
716+
pressure(:, klev) = pressure(:, klev) + (p_tend(:, klev) * dt)
717+
dPdt_total(:, klev) = dPdt_total(:, klev) + p_tend(:, klev)
718+
end do
719+
720+
end subroutine apply_tendency_of_air_pressure_run
721+
```
722+
723+
Then you would need to check that the file you've modified is being built by the tests. You can check this in `test/unit-test/CMakeLists.txt` and see that we have:
724+
725+
```cmake
726+
set(UTILITIES_SRC
727+
../../schemes/utilities/state_converters.F90
728+
../../schemes/utilities/static_energy.F90
729+
../../schemes/utilities/physics_tendency_updaters.F90
730+
include/ccpp_kinds.F90
731+
)
732+
```
733+
734+
Since the file is being built, we don't have to add to this list.
735+
736+
Next we look for `test/unit-test/tests/utilities/CMakeLists.txt` to see if there is a matching test file:
737+
738+
```bash
739+
$ ls test/unit-test/tests/utilities/
740+
CMakeLists.txt
741+
test_state_converters.pf
742+
$ cat test/unit-test/tests/utilities/CMakeLists.txt
743+
add_pfunit_ctest(utilities_tests
744+
TEST_SOURCES test_state_converters.pf
745+
LINK_LIBRARIES utilities
746+
)
747+
```
748+
749+
Because there is no matching file or test, we need to create it:
750+
751+
```bash
752+
$ cat > test/unit-test/tests/utilities/test_physics_tendency_updaters.pf << EOF
753+
@test
754+
subroutine test_pressure_tendency_update()
755+
use funit
756+
use physics_tendency_updaters
757+
758+
end subroutine test_pressure_tendency_update
759+
EOF
760+
```
761+
762+
And add the ability to build/run it from the test harness by updating `test/unit-test/tests/utilities/CMakeLists.txt`:
763+
764+
```cmake
765+
add_pfunit_ctest(utilities_tests
766+
TEST_SOURCES test_state_converters.pf test_physics_tendency_updaters.pf
767+
LINK_LIBRARIES utilities
768+
```
769+
where `test_physics_tendency_updaters.pf` has been added to the `TEST_SOURCES` list.
770+
771+
Now, to actually test the function, we can try something like:
772+
773+
```fortran
774+
@test
775+
subroutine test_pressure_tendency_update()
776+
use funit
777+
use ccpp_kinds, only: kind_phys
778+
use physics_tendency_updaters
779+
780+
# Declare and setup test data with known results
781+
782+
integer, parameter :: ncol = 3 ! Num columns
783+
integer, parameter :: nz = 3 ! Num vertical layers
784+
integer, parameter :: errcode = 0
785+
character(len=512), parameter :: errmsg = ''
786+
787+
real(kind_phys) :: p_tend(ncol, nz) ! pressure tendency
788+
real(kind_phys) :: pressure(ncol, nz) ! air pressure
789+
real(kind_phys) :: dPdt_total(nol, nz) ! total temp. tendency
790+
real(kind_phys) :: dt ! physics time step
791+
792+
pressure = 1
793+
p_tend = 1
794+
dPdt_total = 0
795+
dt = 1
796+
797+
call apply_tendency_of_air_pressure_run(nz, p_tend, pressure, &
798+
dPdt_total, dt, &
799+
errcode, errmsg)
800+
801+
@assertEqual(2, pressure)
802+
@assertEqual(1, dPdt_total)
803+
@assertEqual(0, errcode)
804+
@assertEqual('', errmsg)
805+
end subroutine test_pressure_tendency_update
806+
```
807+
808+
The values should be scientifically relevant to test a valid physics case or be set up to test edge cases that the subroutine must support.
809+
810+
Notice that we are only testing `intent(out)` and `intent(inout)` as these are the only values that can change.
811+
812+
Assuming you have built the test framework according to the [instructions](../atmospheric_physics/development_workflow.md#5-unit-testing), you can now run:
813+
814+
```bash
815+
$ cmake \
816+
-DCMAKE_PREFIX_PATH=<PATH_TO_PFUNIT>/build/installed \
817+
-DATMOSPHERIC_PHYSICS_ENABLE_CODE_COVERAGE=ON \
818+
-B./build \
819+
-S./test/unit-test
820+
$ cd build
821+
$ make
822+
$ ctest -V --output-on-failure
823+
```
824+
825+
After which you should see output similar to:
826+
827+
```
828+
1: Start: <test_state_converters_suite.test_temp_to_potential_temp>
829+
1: . end: <test_state_converters_suite.test_temp_to_potential_temp>
830+
1:
831+
1: Time: 0.000 seconds
832+
1:
833+
1: OK
834+
1: (1 test)
835+
1:
836+
2: Start: <test_physics_tendency_updaters_suite.test_pressure_tendency_update>
837+
2: . end: <test_physics_tendency_updaters_suite.test_pressure_tendency_update>
838+
2:
839+
2: Time: 0.000 seconds
840+
2:
841+
2: OK
842+
2: (1 test)
843+
2/2 Test #1: utilities_tests .................. Passed 0.00 sec
844+
845+
100% tests passed, 0 tests failed out of 1
846+
```
847+
848+
If 100% of the tests pass, you may proceed to the next section.
694849

695850
### Pull Requests
696851
- He opens a PR into atmospheric_physics (target: `development` branch), goes through the review process, updates the NamesNotInDictionary.txt file, and then commits the PR when approvals are received. He then opens a PR from `development` to `main` and makes a tag (incrementing the minor version) when that is merged.

0 commit comments

Comments
 (0)