OOPS
GeometryQG.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <sstream>
12 
13 #include "atlas/field.h"
14 #include "atlas/functionspace.h"
15 #include "atlas/grid.h"
16 #include "atlas/util/Config.h"
17 
18 #include "oops/util/abor1_cpp.h"
19 #include "oops/util/Logger.h"
20 
21 #include "model/GeometryQG.h"
22 #include "model/QgFortran.h"
23 
24 // -----------------------------------------------------------------------------
25 namespace qg {
26 // -----------------------------------------------------------------------------
28  const eckit::mpi::Comm & comm) : comm_(comm) {
29  qg_geom_setup_f90(keyGeom_, params.toConfiguration());
30 
31  // Set ATLAS lon/lat field
32  atlasFieldSet_.reset(new atlas::FieldSet());
34  atlas::Field atlasField = atlasFieldSet_->field("lonlat");
35 
36  // Create ATLAS function space
37  atlasFunctionSpace_.reset(new atlas::functionspace::PointCloud(atlasField));
38 
39  // Set ATLAS function space pointer in Fortran
41 
42  // Fill ATLAS fieldset
43  atlasFieldSet_.reset(new atlas::FieldSet());
45 }
46 // -----------------------------------------------------------------------------
47 GeometryQG::GeometryQG(const GeometryQG & other) : comm_(other.comm_) {
49 
50  // Copy ATLAS function space
51  atlasFunctionSpace_.reset(new atlas::functionspace::PointCloud(
52  other.atlasFunctionSpace_->lonlat()));
53 
54  // Set ATLAS function space pointer in Fortran
56 
57  // Copy ATLAS fieldset
58  atlasFieldSet_.reset(new atlas::FieldSet());
59  for (int jfield = 0; jfield < other.atlasFieldSet_->size(); ++jfield) {
60  atlas::Field atlasField = other.atlasFieldSet_->field(jfield);
61  atlasFieldSet_->add(atlasField);
62  }
63 }
64 // -----------------------------------------------------------------------------
67 }
68 // -----------------------------------------------------------------------------
70  return GeometryQGIterator(*this);
71 }
72 // -----------------------------------------------------------------------------
74  int nx = 0;
75  int ny = 0;
76  int nz;
77  double deltax;
78  double deltay;
79  qg_geom_info_f90(keyGeom_, nx, ny, nz, deltax, deltay);
80  return GeometryQGIterator(*this, nx*ny+1);
81 }
82 // -------------------------------------------------------------------------------------------------
83 std::vector<double> GeometryQG::verticalCoord(std::string & vcUnits) const {
84  // returns vertical coordinate in untis of vcUnits
85  int nx = 0;
86  int ny = 0;
87  int nz;
88  double deltax;
89  double deltay;
90  qg_geom_info_f90(keyGeom_, nx, ny, nz, deltax, deltay);
91  std::vector<double> vc(nz);
92  if (vcUnits == "levels") {
93  for (int i=0; i < nz; ++i) {vc[i]=i+1;}
94  } else {
95  std::stringstream errorMsg;
96  errorMsg << "Uknown vertical coordinate unit " << vcUnits << std::endl;
97  ABORT(errorMsg.str());
98  }
99  oops::Log::debug() << "QG vert coord: " << vc << std::endl;
100  return vc;
101 }
102 
103 // -----------------------------------------------------------------------------
104 void GeometryQG::print(std::ostream & os) const {
105  int nx;
106  int ny;
107  int nz;
108  double deltax;
109  double deltay;
110  qg_geom_info_f90(keyGeom_, nx, ny, nz, deltax, deltay);
111  os << "Geometry:" << std::endl;
112  os << "nx = " << nx << ", ny = " << ny << ", nz = " << nz << std::endl;
113  os << "deltax = " << deltax << ", deltay = " << deltay << std::endl;
114 }
115 // -----------------------------------------------------------------------------
116 } // namespace qg
qg::qg_geom_info_f90
void qg_geom_info_f90(const F90geom &, int &, int &, int &, double &, double &)
qg
The namespace for the qg model.
Definition: qg/model/AnalyticInit.cc:13
qg::GeometryQG::~GeometryQG
~GeometryQG()
Definition: GeometryQG.cc:65
qg::qg_geom_clone_f90
void qg_geom_clone_f90(F90geom &, const F90geom &)
QgFortran.h
qg::GeometryQG::GeometryQG
GeometryQG(const GeometryQgParameters &, const eckit::mpi::Comm &)
Definition: GeometryQG.cc:27
qg::GeometryQG::atlasFunctionSpace_
std::unique_ptr< atlas::functionspace::PointCloud > atlasFunctionSpace_
Definition: GeometryQG.h:78
GeometryQG.h
qg::GeometryQG::atlasFieldSet_
std::unique_ptr< atlas::FieldSet > atlasFieldSet_
Definition: GeometryQG.h:79
qg::GeometryQG::end
GeometryQGIterator end() const
Definition: GeometryQG.cc:73
qg::GeometryQGIterator
Definition: GeometryQGIterator.h:33
qg::GeometryQG::begin
GeometryQGIterator begin() const
Definition: GeometryQG.cc:69
qg::qg_geom_set_atlas_lonlat_f90
void qg_geom_set_atlas_lonlat_f90(const F90geom &, atlas::field::FieldSetImpl *)
qg::qg_geom_setup_f90
void qg_geom_setup_f90(F90geom &, const eckit::Configuration &)
qg::GeometryQG::keyGeom_
F90geom keyGeom_
Definition: GeometryQG.h:76
qg::GeometryQgParameters
Definition: GeometryQG.h:35
qg::GeometryQG::print
void print(std::ostream &) const
Definition: GeometryQG.cc:104
qg::qg_geom_set_atlas_functionspace_pointer_f90
void qg_geom_set_atlas_functionspace_pointer_f90(const F90geom &, atlas::functionspace::FunctionSpaceImpl *)
qg::qg_geom_delete_f90
void qg_geom_delete_f90(F90geom &)
qg::GeometryQG::verticalCoord
std::vector< double > verticalCoord(std::string &) const
Definition: GeometryQG.cc:83
qg::GeometryQG
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:54
qg::qg_geom_fill_atlas_fieldset_f90
void qg_geom_fill_atlas_fieldset_f90(const F90geom &, atlas::field::FieldSetImpl *)