Skip to content

Commit

Permalink
update 07.06.24-01
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-lormi committed Jun 7, 2024
1 parent 1631e61 commit c9cbaeb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 36 deletions.
50 changes: 16 additions & 34 deletions src/atlas/interpolation/method/binning/Binning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Binning::Binning(const Config& config) : Method(config) {
const auto* ptr_config = dynamic_cast<const eckit::LocalConfiguration*>(&config);
interpAncillaryScheme_ = ptr_config->getSubConfiguration("ancillary_scheme");
halo_exchange_ = ptr_config->getBool("halo_exchange", true);
adjoint_ = ptr_config->getBool("adjoint", false);
}


Expand All @@ -61,8 +62,10 @@ void Binning::do_setup(const FunctionSpace& source,
return;
}

// enabling or disabling halo exchange
// enabling or disabling the halo exchange
this->allow_halo_exchange_ = halo_exchange_;
// enabling or disabling the adjoint operation
this->adjoint_ = adjoint_;

// note that the 'source' grid for the low-to-high regridding (interpolation)
// is the 'target' grid for high-to-low regridding (binning) and
Expand Down Expand Up @@ -99,29 +102,16 @@ void Binning::do_setup(const FunctionSpace& source,
// start of the indexes associated with the row 'i+1'
size_t ubound = ptr_tamx_o[idx_row_next];

if (lbound == ubound)
continue;

double sum_row = 0;
for (size_t i = lbound; i < ubound; ++i) {
sum_row += (ptr_tamx_data[i] * ds_aweights.at(ptr_tamx_idxs_col[i]));
}



// ...XX...
if (sum_row == 0) {

Log::info() << "\nDEBUG - BPX1" << std::endl;

}

// ...XX...
double nfactor {1.};
if (sum_row != 0) {

// normalization factor
nfactor = 1/sum_row;

}

// normalization factor
double nfactor = 1/sum_row;

for (size_t i = lbound; i < ubound; ++i) {
// evaluating the non-zero elements of the binning matrix
Expand All @@ -146,12 +136,15 @@ std::vector<double> Binning::getAreaWeights(const FunctionSpace& fspace) const {
// diagonal of 'area weights matrix', W
std::vector<double> ds_aweights;

bool is_cubed_sphere {false};
if (auto csfs = functionspace::NodeColumns(fspace)) {
if (CubedSphereGrid(csfs.mesh().grid())) {
is_cubed_sphere = true;
}
}

if (is_cubed_sphere) {

// ...XX...
// note that this should be used only in the case of 'CubedSphereGrid' ...

if (fspace.type().compare(functionspace::detail::NodeColumns::static_type()) == 0) {
const auto csfs = functionspace::NodeColumns(fspace);

const auto csgrid = CubedSphereGrid(csfs.mesh().grid());
Expand All @@ -176,17 +169,6 @@ std::vector<double> Binning::getAreaWeights(const FunctionSpace& fspace) const {
ds_aweights.emplace_back(aweight_temp);
}
}

} else if (fspace.type().compare(functionspace::detail::StructuredColumns::static_type()) == 0) {

const auto scfs = functionspace::StructuredColumns(fspace);

const auto scgrid = scfs.grid();
// area weight (appoximated)
// area weight = area_cell/area_total
// = area_cell/(no_cells*area_cell) = 1/no_cells
const double aweight = 1/static_cast<double>(scgrid.size());
ds_aweights.assign(fspace.size(), aweight);

} else {

Expand Down
5 changes: 3 additions & 2 deletions src/atlas/interpolation/method/binning/Binning.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "atlas/interpolation/Cache.h"
#include "atlas/interpolation/method/Method.h"
#include "atlas/grid/Grid.h"
#include "atlas/util/Config.h"

#include "eckit/config/Configuration.h"


namespace atlas {
Expand Down Expand Up @@ -61,7 +62,7 @@ class Binning : public Method {

std::vector<double> getAreaWeights(const FunctionSpace& source) const;

util::Config interpAncillaryScheme_;
eckit::LocalConfiguration interpAncillaryScheme_{};

FunctionSpace source_{};
FunctionSpace target_{};
Expand Down

0 comments on commit c9cbaeb

Please sign in to comment.