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

Collab/ndrop #172

Merged
merged 141 commits into from
Jul 21, 2023
Merged

Collab/ndrop #172

merged 141 commits into from
Jul 21, 2023

Conversation

odiazib
Copy link
Contributor

@odiazib odiazib commented May 17, 2023

This PR contains the C++ port of the Fortran subroutine ndrop We port and create validation tests for the following subroutines:

  1. Ccncalc: test for a single cell and another one for a column; passing with a relative error of 1e-5 and 2e-3
  2. get_activate_frac: column test; passing with a relative error of 5e-5
  3. loadaer: single cell test; passing with a relative error of 6e-8
  4. activate_modal: single cell test; passing with a relative error of 7e-5
  5. explmix: column tests; passing with a relative error of 1e-9 and 1e-10
  6. maxsat: single cell test; passing with relative error of 1e-11
  7. update_from_newcld: single cell tests; passing with relative errors of 1e-11, 1e-3, 2e-9
  8. update_from_cldn_profile: single cell tests; passing with relative errors of 1e-12 and 9e-3
  9. dropmixnuc: column tests; passing with relative error of 5e-5 and 6.9e-4
  10. A validation test for update_from_explmix will part of a future PR.

Notes:

  1. The ndrop fortran code involves multiple columns; however, our porting was adapted for one column. As a result, ndrop/mam4xx returns a per cell value for index kk, instead of returning a column-integrated variable ndropcol (column-integrated droplet number).
  2. Instead of allocating temporary arrays in the main driver (dropmixnuc), we pass work arrays as inputs.
  3. We added nested parallelism in dropmixnuc. Therefore, we added team_barriers to synchronize threads and avoid race conditions.
  4. Index-mapping arrays (mam_idx, mam_cnst_idx, numptr_amode, lmassptr_amode, lspectype_amode) are inputs in ndrop/mam4xx. In addition, conversion from Fortran indexing to C++ indexing is done inside of the functions. We did not modify ndrop/mam4 indexing arrays. For future work, we could work on merging these different mapping arrays.
  5. In an effort to understand the index arrays in mam4, we made some notes on Confluence.

Closes #161

@odiazib odiazib closed this May 18, 2023
@odiazib odiazib reopened this May 19, 2023
@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #172 (74a244a) into main (4ebe844) will increase coverage by 0.37%.
The diff coverage is 99.32%.

@@            Coverage Diff             @@
##             main     #172      +/-   ##
==========================================
+ Coverage   95.93%   96.30%   +0.37%     
==========================================
  Files          28       28              
  Lines        4626     5202     +576     
==========================================
+ Hits         4438     5010     +572     
- Misses        188      192       +4     
Impacted Files Coverage Δ
src/mam4xx/ndrop.hpp 99.34% <99.32%> (-0.66%) ⬇️

@odiazib odiazib marked this pull request as ready for review July 4, 2023 16:05
@@ -66,7 +66,7 @@ target_compile_options(mam4_nucleate_ice_unit_tests PRIVATE -Werror)
# TODO: return to this test once we have more context for get_aer_num
EkatCreateUnitTest(mam4_ndrop_unit_tests mam4_ndrop_unit_tests.cpp
LIBS mam4xx_tests ${HAERO_LIBRARIES} EXCLUDE_TEST_SESSION)
target_compile_options(mam4_ndrop_unit_tests PRIVATE -Werror)
target_compile_options(mam4_ndrop_unit_tests PRIVATE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can delete this line, which no longer does anything.

maxsat.cpp
update_from_newcld.cpp
update_from_cldn_profile.cpp
# update_from_explmix.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is update_from_explmix still in progress? I noticed a comment in that file related to a thread team.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The validation test is still in progress, but the subroutine was ported. We could remove this code from this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fine to leave the code in with this comment. I remember you and Mike telling me about this now.

// update_from_explmix(ensemble);
} else if (func_name == "dropmixnuc") {
dropmixnuc(ensemble);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like this code will silently do nothing if the function name doesn't match any of the names above. Might be good to put in an } else { block to make sure that doesn't happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This if statement is inside of a try statement that print an error.

auto func_name = settings.get("function");
 try {
 if {
} else if {
}...
...
 } catch (std::exception &e) {
   std::cerr << argv[0] << ": Error: " << e.what() << std::endl;
 }

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, but if func_name doesn't match any of the names in the if tests, no exception is thrown, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct. I will fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

0.1999170945E005, 0.9524671355E005};

for (int i = 0; i < AeroConfig::num_modes(); ++i) {
ss << "i = " << i;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but you might find the fmt library a little more convenient for creating log messages. EKAT provides fmt in addition to our logging library, so feel free to use it.

#include <haero/math.hpp>

#include <mam4xx/aero_config.hpp>
#include <mam4xx/conversions.hpp>
#include <mam4xx/mam4_types.hpp>
#include <mam4xx/ndrop.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this file including itself?

Slightly related: can you add a line to src/CMakeLists to make sure that the ndrop.hpp header is installed when we run make install?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const Real pi = haero::Constants::pi;

// surface tension coefficient [m-K] (from mam4)
// FIXME: any thoughts on what [m-K] means?
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my experience, fit coefficients often can't be interpreted physically, at least not directly. It seems to me that ssat_coeff captures a power-law temperature dependence which is expressed in the form of this "surface tension" component. Note also the headache-inducing fractional-power (power law) units of ssat_coeff.

// critical supersaturation at mode radius [fraction]
// here we assume "value shouldn't matter much since naerosol is small"
// ^(from mam4)
// NOTE: excuse me... what??
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤣

// @param [out] flux_fullact flux of activated aerosol fraction assuming
// 100% activation [m/s]
const Real zero = 0;
const int nmodes = AeroConfig::num_modes();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this (and statements like it) be constexpr int instead of const int to make sure that it can be used to provide a size for automatic arrays?

Copy link
Collaborator

@jeff-cohere jeff-cohere left a comment

Choose a reason for hiding this comment

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

I took a pass and left some minor comments. It looks really good! Nice work on this.

Copy link
Contributor

@pressel pressel left a comment

Choose a reason for hiding this comment

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

Thanks to all who worked on this, it looks great. I am fine with merging this now.

@odiazib odiazib merged commit 1068da0 into main Jul 21, 2023
7 checks passed
@odiazib odiazib deleted the collab/ndrop branch July 21, 2023 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ndrop get_aer_num GPU config
6 participants