FV3-JEDI
Geometry.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
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 
8 #include <mpi.h>
9 
10 #include <sstream>
11 
12 #include "atlas/field.h"
13 #include "atlas/functionspace.h"
14 #include "atlas/grid.h"
15 #include "atlas/util/Config.h"
16 
17 #include "eckit/config/Configuration.h"
18 
19 #include "oops/util/abor1_cpp.h"
20 #include "oops/util/Logger.h"
21 
25 
26 // -------------------------------------------------------------------------------------------------
27 
28 namespace fv3jedi {
29 
30 // -------------------------------------------------------------------------------------------------
31 
32 Geometry::Geometry(const eckit::Configuration & conf,
33  const eckit::mpi::Comm & comm) : comm_(comm), fieldsMeta_(conf) {
34  const eckit::Configuration * configc = &conf;
35 
36  // Call the initialize phase, done only once.
37  static bool initialized = false;
38  if (!initialized) {
39  stageFMSFiles(conf, comm);
41  removeFv3Files(comm);
42  initialized = true;
43  oops::Log::debug() << "FMS MPP initialized on " << comm_.name() << std::endl;
44  }
45 
46  stageFv3Files(conf, comm);
47  if ( !conf.has("nml_file") ) {
48  generateGeomFv3Conf(conf, comm);
49  }
51  removeFv3Files(comm);
52 
53  // Set ATLAS lon/lat field
54  atlasFieldSet_.reset(new atlas::FieldSet());
56  atlas::Field atlasField = atlasFieldSet_->field("lonlat");
57 
58  // Create ATLAS function space
59  atlasFunctionSpace_.reset(new atlas::functionspace::PointCloud(atlasField));
60 
61  // Set ATLAS function space pointer in Fortran
63 
64  // Fill ATLAS fieldset
65  atlasFieldSet_.reset(new atlas::FieldSet());
67 }
68 
69 // -------------------------------------------------------------------------------------------------
70 
71 Geometry::Geometry(const Geometry & other) : comm_(other.comm_), fieldsMeta_(other.fieldsMeta_) {
73  atlasFunctionSpace_.reset(new atlas::functionspace::PointCloud(
74  other.atlasFunctionSpace_->lonlat()));
76  atlasFieldSet_.reset(new atlas::FieldSet());
77  for (int jfield = 0; jfield < other.atlasFieldSet_->size(); ++jfield) {
78  atlas::Field atlasField = other.atlasFieldSet_->field(jfield);
79  atlasFieldSet_->add(atlasField);
80  }
81 }
82 
83 // -------------------------------------------------------------------------------------------------
84 
87 }
88 
89 // -------------------------------------------------------------------------------------------------
90 
92  // return start of the geometry on this mpi tile
93  int ist, iend, jst, jend, npz;
94  fv3jedi_geom_start_end_f90(keyGeom_, ist, iend, jst, jend, npz);
95  return GeometryIterator(*this, ist, jst);
96 }
97 
98 // -------------------------------------------------------------------------------------------------
99 
101  // return end of the geometry on this mpi tile
102  // (returns index out of bounds for the iterator loops to work)
103 
104  return GeometryIterator(*this, -1, -1);
105 }
106 
107 // -------------------------------------------------------------------------------------------------
108 
109 std::vector<double> Geometry::verticalCoord(std::string & vcUnits) const {
110  // returns vertical coordinate in untis of vcUnits
111  // to enable initial comparisons with GSI, verticalCoord is valid for psurf=1e5
112  // TODO(TBD) implement interface where vertical coordinate is valid for state[gridIterator].psurf
113 
114  int ist, iend, jst, jend, npz;
115  fv3jedi_geom_start_end_f90(keyGeom_, ist, iend, jst, jend, npz);
116  std::vector<double> vc(npz);
117  double psurf = 100000.0;
118  if (vcUnits == "logp") {
119  fv3jedi_geom_verticalCoord_f90(keyGeom_, vc[0], npz, psurf);
120  } else if (vcUnits == "levels") {
121  for (int i=0; i < npz; ++i) {vc[i]=i+1;}
122  } else {
123  std::stringstream errorMsg;
124  errorMsg << "Uknown vertical coordinate unit " << vcUnits << std::endl;
125  ABORT(errorMsg.str());
126  }
127  oops::Log::debug() << "fv3 vert coord: " << vc << std::endl;
128  return vc;
129 }
130 
131 // -------------------------------------------------------------------------------------------------
132 
133 void Geometry::print(std::ostream & os) const {
134  int cube;
136  os << "fv3jedi::Geometry resolution: c" << cube;
137 }
138 
139 // -------------------------------------------------------------------------------------------------
140 
141 } // namespace fv3jedi
fv3jedi::Geometry::print
void print(std::ostream &) const
Definition: Geometry.cc:133
fv3jedi::Geometry::fieldsMeta_
const FieldsMetadata fieldsMeta_
Definition: Geometry.h:66
fv3jedi::Geometry::~Geometry
~Geometry()
Definition: Geometry.cc:85
fv3jedi::fv3jedi_geom_set_atlas_lonlat_f90
void fv3jedi_geom_set_atlas_lonlat_f90(const F90geom &, atlas::field::FieldSetImpl *)
Utilities.h
fv3jedi::Geometry::end
GeometryIterator end() const
Definition: Geometry.cc:100
fv3jedi::Geometry::keyGeom_
F90geom keyGeom_
Definition: Geometry.h:62
Geometry.h
fv3jedi::fv3jedi_geom_clone_f90
void fv3jedi_geom_clone_f90(F90geom &, const F90geom &, const FieldsMetadata *)
fv3jedi::Geometry::begin
GeometryIterator begin() const
Definition: Geometry.cc:91
fv3jedi::fv3jedi_geom_initialize_f90
void fv3jedi_geom_initialize_f90(const eckit::Configuration *const *, const eckit::mpi::Comm *)
fv3jedi::Geometry::atlasFieldSet_
std::unique_ptr< atlas::FieldSet > atlasFieldSet_
Definition: Geometry.h:65
GeometryIterator.interface.h
fv3jedi::Geometry::comm_
const eckit::mpi::Comm & comm_
Definition: Geometry.h:63
fv3jedi::Geometry
Geometry handles geometry for FV3JEDI model.
Definition: Geometry.h:41
fv3jedi::fv3jedi_geom_verticalCoord_f90
void fv3jedi_geom_verticalCoord_f90(const F90geom &, double &, int &, double &)
fv3jedi::Geometry::Geometry
Geometry(const eckit::Configuration &, const eckit::mpi::Comm &)
Definition: Geometry.cc:32
fv3jedi::stageFMSFiles
void stageFMSFiles(const eckit::Configuration &conf, const eckit::mpi::Comm &comm)
Definition: Utilities.cc:32
fv3jedi::fv3jedi_geom_setup_f90
void fv3jedi_geom_setup_f90(F90geom &, const eckit::Configuration *const *, const eckit::mpi::Comm *, const FieldsMetadata *)
fv3jedi::fv3jedi_geom_start_end_f90
void fv3jedi_geom_start_end_f90(const F90geom &, int &, int &, int &, int &, int &)
fv3jedi::stageFv3Files
void stageFv3Files(const eckit::Configuration &conf, const eckit::mpi::Comm &comm)
Definition: Utilities.cc:53
fv3jedi::Geometry::verticalCoord
std::vector< double > verticalCoord(std::string &) const
Definition: Geometry.cc:109
fv3jedi::GeometryIterator
Definition: GeometryIterator.h:30
fv3jedi::fv3jedi_geom_delete_f90
void fv3jedi_geom_delete_f90(F90geom &)
fv3jedi::fv3jedi_geom_set_atlas_functionspace_pointer_f90
void fv3jedi_geom_set_atlas_functionspace_pointer_f90(const F90geom &, atlas::functionspace::FunctionSpaceImpl *)
fv3jedi
Configuration files should be formatted as e.g.
Definition: ErrorCovariance.cc:20
fv3jedi::fv3jedi_geom_fill_atlas_fieldset_f90
void fv3jedi_geom_fill_atlas_fieldset_f90(const F90geom &, atlas::field::FieldSetImpl *)
fv3jedi::generateGeomFv3Conf
void generateGeomFv3Conf(const eckit::Configuration &conf, const eckit::mpi::Comm &comm)
Definition: Utilities.cc:160
fv3jedi::Geometry::atlasFunctionSpace_
std::unique_ptr< atlas::functionspace::PointCloud > atlasFunctionSpace_
Definition: Geometry.h:64
fv3jedi::removeFv3Files
void removeFv3Files(const eckit::mpi::Comm &comm)
Definition: Utilities.cc:130
fv3jedi::fv3jedi_geom_print_f90
void fv3jedi_geom_print_f90(const F90geom &, int &)