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

New ModelArrayRef #250

Merged
merged 98 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
c2dd0d2
Make the writable ModelArrayRef more generic.
timspainNERSC Feb 21, 2023
10a4fa2
Move the BlahBackingStore typedefs out of MAR.hpp
timspainNERSC Feb 21, 2023
ebb4ad3
ModelArrayRef version 3.
timspainNERSC Feb 24, 2023
9351f94
Remove memory leaks in the waiting* arrays.
timspainNERSC Feb 24, 2023
b9a2868
Remove iostream and rename (I)MARBackingStore.
timspainNERSC Feb 24, 2023
f21bebe
Use if logic, not exceptions in MARBackingStore stores.
timspainNERSC Feb 24, 2023
e935cf7
Remove the BackingStore template parameter.
timspainNERSC Feb 24, 2023
e50fc8b
Move the field definition to the declaration, using an auxiliary struct.
timspainNERSC Feb 27, 2023
d579ff0
Move the definition of the field type to the declaration.
timspainNERSC Feb 27, 2023
1bab280
Break out TextTag. Rename to MARStore.
timspainNERSC Feb 27, 2023
f924abd
Add TextTags to ModelComponent.
timspainNERSC Feb 27, 2023
ddefca6
Change the commented tests to use the new syntax.
timspainNERSC Feb 27, 2023
b653ce8
Don't copy the backing store, reference it.
timspainNERSC Feb 27, 2023
00b5489
Add new ModelArrayRef features to ModelComponent.
timspainNERSC Feb 27, 2023
72859da
Add more indexing operations to MAR3.
timspainNERSC Feb 28, 2023
590da61
Change all code to use the new ModelArrayRef (not tested).
timspainNERSC Feb 28, 2023
63f4f2d
Anything registered as shared should be RW.
timspainNERSC Feb 28, 2023
24cb899
Fix the ModelComponent test.
timspainNERSC Feb 28, 2023
7bc2f16
Fix the FiniteElementFluxes test.
timspainNERSC Feb 28, 2023
f08a020
Always add arrays to the waiting lists in all cases.
timspainNERSC Mar 1, 2023
f22c8cc
Fix the ThermoWinton test.
timspainNERSC Mar 1, 2023
5be8c2e
clang formatting
timspainNERSC Mar 1, 2023
86a2379
Use the new ModelArrayRef in ConfiguredAtmosphere.
timspainNERSC Mar 1, 2023
1933bba
Sweep aside the last vestiges of the old ModelArrayRef impl.
timspainNERSC Mar 1, 2023
886290e
Fix the BIOHF test.
timspainNERSC Mar 1, 2023
016a5bb
Remove the old ModelArrayRef type.
timspainNERSC Mar 1, 2023
af8c698
Fix the ConfiguredAtmosphere test.
timspainNERSC Mar 1, 2023
a990da2
Make ModelArrayRef3 into ModelArrayRef.
timspainNERSC Mar 1, 2023
efb0688
Fully remove the old MAR test.
timspainNERSC Mar 1, 2023
db5e4a9
Remove the fieldName member and use the template parameter directly.
timspainNERSC Mar 2, 2023
e0aad7b
Privatize MARStore functions.
timspainNERSC Mar 2, 2023
25b7f20
Use the standard unordered multimap, rather than faking it.
timspainNERSC Mar 2, 2023
fd4608e
Forward define TextTag, rather than include it.
timspainNERSC Mar 2, 2023
66e5ff5
Clean old registered array references before assigning the new one.
timspainNERSC Mar 2, 2023
2d0cc37
clang formatting
timspainNERSC Mar 3, 2023
10e8665
More clang formatting
timspainNERSC Mar 3, 2023
b82815f
Remove the MARBackingStore types.
timspainNERSC Mar 3, 2023
560d5fc
Access all data, tagged by name but read-only.
timspainNERSC Mar 3, 2023
e72eddd
Add explicit arithmetic operators for the RW MAR.
timspainNERSC Mar 3, 2023
7b4e0a6
Add attribution for the TextTag struct.
timspainNERSC Mar 6, 2023
0f88426
Correct include paths for ModelArrayRef.hpp.
timspainNERSC Mar 6, 2023
ea39b6a
clang formatting
timspainNERSC Mar 6, 2023
4750e57
Add some documentation on ModelArray(Ref).
timspainNERSC Mar 20, 2023
e36d499
Swap indexing in ModelArray and its test.
timspainNERSC May 3, 2023
43bd272
Fix zIndexAndLayer for the swapped array ordering.
timspainNERSC May 5, 2023
a794191
Add a test of zIndexAndLayer.
timspainNERSC May 5, 2023
e830625
Add a three-dimensional test ModelArray type.
timspainNERSC May 5, 2023
0513329
Update the 10x10 restart file and script to use swapped array indices.
timspainNERSC May 10, 2023
c383bee
Update the 30x30 restart file and script to use swapped array indices.
timspainNERSC May 10, 2023
dd25209
Regenerate the 20x30 init file, along with a new generation script.
timspainNERSC May 10, 2023
3c5731d
Remove commented code.
timspainNERSC Aug 25, 2023
d95119f
Make ParaGridIO compatible with reversed array index ordering.
timspainNERSC Aug 25, 2023
237801f
Only reverse the array dimensions once.
timspainNERSC Aug 28, 2023
16cae3b
Correct the ERA5 test for the swapped array ordering.
timspainNERSC Aug 28, 2023
ecb65f4
Correct the TOPAZ test for the swapped array ordering.
timspainNERSC Aug 28, 2023
c6a89a6
Merge branch 'develop' into issue275_2_arrayordering
timspainNERSC Aug 30, 2023
94f6a7d
Add some documentation on ModelArray(Ref). (#377)
timspainNERSC Aug 30, 2023
9b4b42c
The docstring should reflect the (changed) file name.
timspainNERSC Aug 30, 2023
3ad2fb4
Rename ref to be more explanatory.
timspainNERSC Aug 31, 2023
acc3604
Rename MARStore to ModelArrayReferenceStore.
timspainNERSC Aug 31, 2023
149957c
Match the docstring name to the filename.
timspainNERSC Aug 31, 2023
9cf019d
Add explanatory comments to tests and expand names.
timspainNERSC Sep 4, 2023
ee5ba90
Test the array ordering in ParaGridIO by reading from a netCDF.
timspainNERSC May 3, 2023
733e54c
Swap x and y in the forcing test file.
timspainNERSC May 4, 2023
107c3a3
Fix the forcing reading to work with the swapped x and y dimensions.
timspainNERSC May 4, 2023
e26a5e6
Remove commented code.
timspainNERSC May 4, 2023
18165d2
Change the dimensionKeys to match what will come from netCDF.
timspainNERSC May 4, 2023
699ef35
Swap indexing in ModelArray and its test.
timspainNERSC May 8, 2023
72d7ac8
Convert the parametric file creation to the swapped array ordering.
timspainNERSC May 8, 2023
3fb3533
Update the script to make TOPAZ/ERA restart files with swapped indices.
timspainNERSC May 8, 2023
508c490
Update the TOPAZ/ERA forcing creation script to use swapped indices.
timspainNERSC May 8, 2023
1fd1bd4
Update the topaz/era initial file with swapped indices.
timspainNERSC May 9, 2023
0ebe366
Convert the ERA5 test script and data to use swapped array indices.
timspainNERSC May 9, 2023
d6e41d9
Update the TOPAZ test script and data to use swapped array indices.
timspainNERSC May 9, 2023
f0924c4
Switch TOPAZ test values to the new dimension ordering.
timspainNERSC Jun 13, 2023
1380991
clang formatting
timspainNERSC Sep 6, 2023
c27af07
Correct the dimension ordering, which was wrong.
timspainNERSC Sep 6, 2023
4e46a82
Generate the test ERA5 file.
timspainNERSC Sep 6, 2023
663681c
Merge branch 'issue275_2_arrayordering' into develop+373
timspainNERSC Sep 6, 2023
85366ab
Remove the erroneous conflict markers.
timspainNERSC Sep 6, 2023
277ede3
Merge branch 'develop+373' into feat_mar3
timspainNERSC Sep 7, 2023
87cf64a
Mathematical operators between ModelArrayRefs and scalars.
timspainNERSC Feb 1, 2023
3901d70
Update ConfigOutput to MAR3.
timspainNERSC Sep 8, 2023
d08345c
Update the other output classes to MAR3.
timspainNERSC Sep 8, 2023
8ed9a87
Update the boundary ocean classes to MAR3.
timspainNERSC Sep 8, 2023
a8022fe
Update the atmosphere boundary classes to MAR3.
timspainNERSC Sep 8, 2023
446e85f
Add velocity and slab ocean tags to Protected.
timspainNERSC Sep 8, 2023
7189dca
Update PrognosticData to MAR3.
timspainNERSC Sep 8, 2023
6939950
Update the MAR test to use doctest.
timspainNERSC Sep 8, 2023
9022296
Update the dynamics interface to MAR3.
timspainNERSC Sep 8, 2023
d491b31
Update the ice thermodynamics tests to MAR3.
timspainNERSC Sep 8, 2023
3af2f92
clang formatting
timspainNERSC Sep 8, 2023
f0c5c10
Register to Protected::C_ICE as well.
timspainNERSC Sep 8, 2023
9f74f09
clang formatting
timspainNERSC Sep 8, 2023
a2d9c47
clang formatting 3
timspainNERSC Sep 8, 2023
bc4475b
Make the constexpr TextTags inline to prevent ODR violations.
timspainNERSC Sep 18, 2023
bfa5e5b
Make read-only sharing explicit with RO arguments.
timspainNERSC Sep 18, 2023
da7edf8
clang formatting
timspainNERSC Sep 18, 2023
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
15 changes: 1 addition & 14 deletions core/src/ModelComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace Nextsim {

std::unordered_map<std::string, ModelComponent*> ModelComponent::registeredModules;
MARBackingStore ModelComponent::sharedArrays(static_cast<size_t>(SharedArray::COUNT));
MARConstBackingStore ModelComponent::protectedArrays(static_cast<size_t>(ProtectedArray::COUNT));
MARStore ModelComponent::store;
ModelArray* ModelComponent::p_oceanMaskH = nullptr;
size_t ModelComponent::nOcean;
std::vector<size_t> ModelComponent::oceanIndex;
Expand Down Expand Up @@ -47,18 +46,6 @@ void ModelComponent::getAllFieldNames(std::unordered_set<std::string>& uF,
}
}

void ModelComponent::registerSharedArray(SharedArray type, ModelArray* addr)
{
// Assignment of pointer in array
sharedArrays[static_cast<size_t>(type)] = addr;
}

void ModelComponent::registerProtectedArray(ProtectedArray type, const ModelArray* addr)
{
// Assignment of pointer in array
protectedArrays[static_cast<size_t>(type)] = addr;
}

/*
* This assumes that the HField array size has already been set in the restart
* reading routine. The mask, like all ModelArrays, is double precision,
Expand Down
16 changes: 8 additions & 8 deletions core/src/PrognosticData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ PrognosticData::PrognosticData()
, pOcnBdy(0)

{
registerProtectedArray(ProtectedArray::H_ICE, &m_thick);
registerProtectedArray(ProtectedArray::C_ICE, &m_conc);
registerProtectedArray(ProtectedArray::H_SNOW, &m_snow);
registerProtectedArray(ProtectedArray::T_ICE, &m_tice);
getStore().registerArray(Protected::H_ICE, &m_thick);
timspainNERSC marked this conversation as resolved.
Show resolved Hide resolved
getStore().registerArray(Protected::C_ICE, &m_conc);
getStore().registerArray(Protected::H_SNOW, &m_snow);
getStore().registerArray(Protected::T_ICE, &m_tice);
}

void PrognosticData::configure()
Expand Down Expand Up @@ -71,10 +71,10 @@ void PrognosticData::update(const TimestepTime& tst)
iceGrowth.update(tst);
pOcnBdy->updateAfter(tst);

ModelArrayRef<SharedArray::H_ICE, MARBackingStore, RO> hiceTrueUpd(getSharedArray());
ModelArrayRef<SharedArray::C_ICE, MARBackingStore, RO> ciceUpd(getSharedArray());
ModelArrayRef<SharedArray::H_SNOW, MARBackingStore, RO> hsnowTrueUpd(getSharedArray());
ModelArrayRef<SharedArray::T_ICE, MARBackingStore, RO> ticeUpd(getSharedArray());
ModelArrayRef<Shared::H_ICE, RO> hiceTrueUpd(getStore());
timspainNERSC marked this conversation as resolved.
Show resolved Hide resolved
ModelArrayRef<Shared::C_ICE, RO> ciceUpd(getStore());
ModelArrayRef<Shared::H_SNOW, RO> hsnowTrueUpd(getStore());
ModelArrayRef<Shared::T_ICE, RO> ticeUpd(getStore());

// Calculate the cell average thicknesses
HField hiceUpd = hiceTrueUpd * ciceUpd;
Expand Down
126 changes: 126 additions & 0 deletions core/src/include/MARStore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*!
* @file MARBackingStore.hpp
timspainNERSC marked this conversation as resolved.
Show resolved Hide resolved
*
* @date 22 Feb 2023
* @author Tim Spain <timothy.spain@nersc.no>
*/

#ifndef MARSTORE_HPP
#define MARSTORE_HPP

#include <list>
#include <string>
#include <unordered_map>

struct TextTag;

namespace Nextsim {

class ModelArray;

typedef ModelArray* ModelArrayReference;
typedef const ModelArray* ModelArrayConstReference;

class MARStore {
public:
void registerArray(const std::string& field, ModelArray* ptr, bool isReadWrite = false)
{
// Clean the old array, if set
if (storeRW.count(field)) {
// If the pointer was in the RW array, null it
storeRW[field] = nullptr;
// Set any RW references with this field to nullptr
auto range = referencesRW.equal_range(field);
for (auto it = range.first; it != range.second; ++it) {
*(it->second) = nullptr;
}
} else if (storeRO.count(field)) {
storeRO[field] = nullptr;
}
// Set any RO references with this field to nullptr
auto range = referencesRO.equal_range(field);
for (auto it = range.first; it != range.second; ++it) {
*(it->second) = nullptr;
}

// Set the new reference based on the passed access boolean
if (!isReadWrite) {
storeRO[field] = ptr;
} else {
storeRW[field] = ptr;
auto range = referencesRW.equal_range(field);
for (auto it = range.first; it != range.second; ++it) {
*(it->second) = ptr;
}
}
range = referencesRO.equal_range(field);
for (auto it = range.first; it != range.second; ++it) {
*(it->second) = ptr;
}
}

std::unordered_map<std::string, const ModelArray*> getAllData() const
{
std::unordered_map<std::string, const ModelArray*> dataMap;

for (auto entry : storeRW) {
dataMap.insert(entry);
}
for (auto entry : storeRO) {
dataMap.insert(entry);
}
return dataMap;
}

private:
ModelArray* getFieldAddr(const std::string& field, ModelArrayReference& ptr)
{
// Add this address to the waiting list for RW fields.
referencesRW.insert({ field, &ptr });
return storeRW.count(field) ? ptr = storeRW.at(field) : nullptr;
}

const ModelArray* getFieldAddr(const std::string& field, ModelArrayConstReference& ptr)
{
referencesRO.insert({ field, &ptr });
if (storeRO.count(field)) {
ptr = storeRO.at(field);
return ptr;
} else if (storeRW.count(field)) {
ptr = storeRW.at(field);
return ptr;
} else {
return nullptr;
}
}

void removeReference(const std::string& field, ModelArrayConstReference& ptr)
{
auto range = referencesRO.equal_range(field);
for (auto it = range.first; it != range.second;)
if (it->second == &ptr)
it = referencesRO.erase(it);
else
++it;
}

void removeReference(const std::string& field, ModelArrayReference& ptr)
{
auto range = referencesRW.equal_range(field);
for (auto it = range.first; it != range.second;)
if (it->second == &ptr)
it = referencesRW.erase(it);
else
++it;
}

std::unordered_map<std::string, ModelArray*> storeRO;
std::unordered_map<std::string, ModelArray*> storeRW;
std::unordered_multimap<std::string, ModelArrayReference*> referencesRW;
std::unordered_multimap<std::string, ModelArrayConstReference*> referencesRO;
template <const TextTag& fieldName, bool isReadWrite> friend class ModelArrayRef;
};

}

#endif /* MARSTORE_HPP */
Loading