Add SfcCoupling class as an interface layer to the coupler #458
Add SfcCoupling class as an interface layer to the coupler #458andrewdnolan wants to merge 21 commits into
SfcCoupling class as an interface layer to the coupler #458Conversation
Avg - for averaged fields Inst - for instantaneous fields (ie. SSH) Acc - for accumulated fields (to be added later)
Host array for the OcnToCplFields class were made private to protect from different units on host and device array. Needed to balance performance with correct units.
|
@andrewdnolan Besides the ctest, is testing this as a part of e3sm also possible (with cpl history output)? |
|
@cbegeman Not quite yet, there will be some work to get the coupled driver branch hook up to use this branch. I can try to get that working, but that testing would be pretty ad-hoc. I think it'd be best to get this in with just the CTest testing, with the understanding that this PR is just a first pass, and a follow on will be needed to fully "hook things up". That being said, I tried to be very thorough in the CTest and have mock pointers that mimic the raw attribute vectors passed by the coupler. I have tests for both unpacking (import) and packing (export) with both MCT and MOAB layouts. The data varies per-field and per cell, so a pretty reasonable test. I feel fairly confident in the code mechanics here, given the CTest, though there will absolutely be more work to get physically meaningful coupling. (But that will be dependent on a coupled driver). |
|
@andrewdnolan Thanks for clarifying! That all sounds good. |
| std::map<std::string, int> ImportIdx; | ||
| std::map<std::string, int> ExportIdx; |
There was a problem hiding this comment.
| std::map<std::string, int> ImportIdx; | |
| std::map<std::string, int> ExportIdx; | |
| std::map<std::string, int> ImportIdxMap; | |
| std::map<std::string, int> ExportIdxMap; |
I'd like to use some variable name here and elsewhere that implies this contains multiple field-index mappings. To me ImportIdx suggests a single integer index.
|
|
||
| // Kokkok views created with a label are zero-initialized by default. | ||
| // We reset the fields here anyway to be explicit about the fact that the | ||
| // OcnToCpl fields need to being a coupling interval with all zeros. |
| int HaloErr = Halo::init(); | ||
| if (HaloErr != 0) { | ||
| Err++; | ||
| LOG_ERROR("SfcCouplingTest: Error initializing defualt halo"); |
There was a problem hiding this comment.
| LOG_ERROR("SfcCouplingTest: Error initializing defualt halo"); | |
| LOG_ERROR("SfcCouplingTest: Error initializing default halo"); |
| std::map<std::string, int> ImportIdx = {{"Foxx_taux", 3}, {"Foxx_tauy", 8}}; | ||
| std::map<std::string, int> ExportIdx = { | ||
| {"So_t", 2}, {"So_s", 4}, {"So_u", 6}, {"So_v", 9}, {"So_ssh", 1}}; | ||
| }; |
There was a problem hiding this comment.
What's the ultimate plan for where these maps would be set?
There was a problem hiding this comment.
These maps will be created in the coupled driver; see here and here.
For the CTest's we just need maps where the key (string) matches the values provided from the coupler and then we just make up mock integer for testing. I've intentionally tried to make this non-continuous (i.e. uneven stride). I don't think we really need to have "mock" entries for every field, just a few per import and export, to test the packing and unpacking into the pointer arrays.
| deepCopy(InstSshCellH, SSHCellOwned); | ||
| } | ||
|
|
||
| // OcnToCpl fields need to being a coupling interval with all values set to 0. |
There was a problem hiding this comment.
I'm confused on what this is supposed to say... is it "...need to bring..."?
| } | ||
|
|
||
| // OcnToCpl fields need to being a coupling interval with all values set to 0. | ||
| void OcnToCplFields::resetFields() { |
There was a problem hiding this comment.
Is resetting everything to 0 the safest thing here? Maybe I am misunderstanding, but is the a chance that these zeros could not be overwritten and get sent to the coupler?
There was a problem hiding this comment.
Yes, we need to be able to reset all field to zero. The field contained in OcnToCpl are averaged fields, so each ocean time step (within the coupling interval) we calculate the update average. Given the average function: if we did not have a way to reset values to zero at the end of a coupling interval, these values would continue accumulating over the whole simulation, which is no good.
So this should only be called at then end of coupling interval, after the SfcCoupling::exportToCoupler has been called.
There was a problem hiding this comment.
Ok, that makes sense. Now I understand the need to reset. I guess is there a change nothing gets accumulated in those averages and we send 0 to the coupler? I think for ssh or velocity that would be fine, but not so much for temp or salt.
| return Array; | ||
| } | ||
|
|
||
| // Shaed index formula for packing/unpacking from rae coupler buffer |
| auto SfcStressZonal_ = CplToOcn.SfcStressZonal; | ||
| auto SfcStressMerid_ = CplToOcn.SfcStressMerid; | ||
|
|
||
| /// TODO: Shouldn't be making direct calls to Kokkos here. |
There was a problem hiding this comment.
Will this be a part of this PR or another follow on one?
There was a problem hiding this comment.
This will have to be a follow on PR.
Updating the wrappers in src/infra/OmegaKokkos.h is a bit out of my comfort zone. Plus we'd need to support a hybrid (GPU + openmp) build, which is a larger can of worms.
| ///< So_t [K], in-situ approx (potential temp at P=0) | ||
| HostArray1DReal AvgSfcTemperatureH; | ||
|
|
||
| /// TODO: Export practical salinity (unitless) to coupler |
There was a problem hiding this comment.
Will this be a part of this PR or another follow on one?
There was a problem hiding this comment.
EOS does not currently have a method for converting from absolute to practical salinity. So this will have to part of a follow on PR, after that's implemented.
|
Ran CTests on PM-CPU and GPU. All tests passed on CPU, but |
Adds
SfcCoupling, which manages the variables exchanged to (o2x) and from (x2o) the coupler for a sub-domain of the global mesh.Changes
SfcCouplingclass supporting bothMCTandMOABcoupling layoutsCouplingLayoutEnum allows for CTesting ofMCT(column major) andMOAB(row major) layouts.applyImportFields()to push imported fields intoForcingupdateExportFields()to accumulate running averages of export fields on-deviceKnown limitations
Checklist
Testingwith the following:have been run on and indicate that are all passing.
has passed, using the Polaris
e3sm_submodules/Omegabaseline-pfor both the baseline (Polarise3sm_submodules/Omega) and the PR build