UFO
MetOfficeBMatrixStatic.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 Met Office
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
9 #include "oops/util/Logger.h"
10 
11 namespace ufo {
12 
13 // -----------------------------------------------------------------------------
14 /// \brief Constructor
15 MetOfficeBMatrixStatic::MetOfficeBMatrixStatic(const eckit::Configuration & config):
16  nbands_(0), nelements_(0), southlimits_(), northlimits_(), elements_()
17 {
18  oops::Log::trace() << "MetOfficeBMatrixStatic constructor starting" << std::endl;
19 
20  // Read bmatrix file into Fortran object
22 
23  // Map Fortran data to c++
24  northlimits_.resize(nbands_);
25  southlimits_.resize(nbands_);
26  size_t ntotal = nelements_ * nelements_ * nbands_;
27  std::vector<float> Btotal(ntotal);
30  northlimits_.data(), Btotal.data());
31 
32  // For each of nbands, store B matrix in container
33  for (size_t i = 0; i < nbands_; ++i) {
34  Eigen::Map<Eigen::MatrixXf> bmap(Btotal.data()+i*nelements_*nelements_,
36  elements_.push_back(bmap);
37  }
38 
39  // Remove the Fortran object because it is no longer needed
41 
42  oops::Log::trace() << "MetOfficeBMatrixStatic constructor end" << std::endl;
43 }
44 // -----------------------------------------------------------------------------
45 /// \brief Return bmatrix size (number of rows or columns of square matrix)
46 size_t MetOfficeBMatrixStatic::getsize(void) const {
47  return nelements_;
48 }
49 // -----------------------------------------------------------------------------
50 /// \brief Find bmatrix band index for a given latitude
51 size_t MetOfficeBMatrixStatic::getindex(const float latitude) const {
52  auto lower = std::lower_bound(northlimits_.begin(), northlimits_.end(), latitude);
53  return std::distance(northlimits_.begin(), lower);
54 }
55 // -----------------------------------------------------------------------------
56 /// \brief Multiply input matrix by bmatrix array based on latitude
57 void MetOfficeBMatrixStatic::multiply(const float lat,
58  const Eigen::MatrixXf & in,
59  Eigen::MatrixXf & out) const {
60  size_t index = this->getindex(lat);
61  out = elements_[index] * in;
62 }
63 
64 // -----------------------------------------------------------------------------
65 /// \brief Print
66 void MetOfficeBMatrixStatic::print(std::ostream & os) const {
67  os << "MetOfficeBMatrixStatic: start print" << std::endl;
68  os << "nbands_ = " << nbands_ << std::endl;
69  os << "nelements_ = " << nelements_ << std::endl;
70  os << "southlimits_[0] = " << southlimits_[0] << std::endl;
71  os << "northlimits_[0] = " << northlimits_[0] << std::endl;
72  os << "MetOfficeBMatrixStatic: end print" << std::endl;
73 }
74 // -----------------------------------------------------------------------------
75 } // namespace ufo
size_t getsize(void) const
Return bmatrix size (number of rows or columns of square matrix)
void print(std::ostream &) const override
Print.
size_t getindex(const float) const
Find bmatrix band index for a given latitude.
std::vector< Eigen::MatrixXf > elements_
void multiply(const float, const Eigen::MatrixXf &, Eigen::MatrixXf &) const
Multiply input matrix by bmatrix array based on latitude.
MetOfficeBMatrixStatic(const eckit::Configuration &)
Constructor.
float distance(const Point &a, const Point &b)
Returns the distance between the two cartesian-mapped Point arguments
Definition: RunCRTM.h:27
void ufo_metoffice_bmatrixstatic_getelements_f90(F90obfilter &, const size_t &, const size_t &, float *, float *, float *)
void ufo_metoffice_bmatrixstatic_setup_f90(F90obfilter &, const eckit::Configuration &, size_t &, size_t &)
Interface to Fortran routines.
void ufo_metoffice_bmatrixstatic_delete_f90(F90obfilter &)