Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
NCWriteESMF.hpp
Go to the documentation of this file.
1 //-------------------------------------------------------------------------
2 // Filename : NCWriteESMF.hpp
3 //
4 // Purpose : Write a generic polygonal mesh out as an ESMF unstructured
5 // grid file. Pairs with NCHelperESMF on the read side.
6 //
7 // On-disk schema (matches NCHelperESMF's reader):
8 // dimensions:
9 // nodeCount = number of unique vertices
10 // elementCount = number of cells
11 // maxNodePElement = global max vertices per cell
12 // coordDim = 2 (lat/lon) — sphere meshes
13 // variables:
14 // double nodeCoords(nodeCount, coordDim) ; units = "degrees"
15 // ; ordering: [lon, lat]
16 // int elementConn(elementCount, maxNodePElement) ; 1-based vertex indices
17 // int numElementConn(elementCount) ; actual #nodes per element
18 // double centerCoords(elementCount, coordDim) ; units = "degrees", [lon,lat]
19 // (optional) double elementArea(elementCount) ; units = "radians^2"
20 // (optional) int elementMask(elementCount)
21 //
22 // The 1-based connectivity and [lon, lat] ordering match the
23 // reader's expectations (NCHelperESMF.cpp:334 / :441).
24 //
25 // Creator : Vijay Mahadevan, 2026-06-13
26 //-------------------------------------------------------------------------
27 
28 #ifndef NCWRITEESMF_HPP_
29 #define NCWRITEESMF_HPP_
30 
31 #include "NCWriteHelper.hpp"
32 
33 namespace moab
34 {
35 
36 class NCWriteESMF : public NCWriteHelper
37 {
38  public:
39  NCWriteESMF( WriteNC* writeNC, int fileId, const FileOptions& opts, EntityHandle fileSet )
40  : NCWriteHelper( writeNC, fileId, opts, fileSet ),
42  mHasAreas( false ), mHasMask( false ),
46  {
47  }
48 
49  virtual ~NCWriteESMF() override;
50 
51  ErrorCode collect_mesh_info() override;
52  ErrorCode init_file( std::vector< std::string >& var_names,
53  std::vector< std::string >& desired_names,
54  bool _append ) override;
55  ErrorCode write_values( std::vector< std::string >& var_names, std::vector< int >& tstep_nums ) override;
56 
57  protected:
58  ErrorCode write_nonset_variables( std::vector< WriteNC::VarData >& vdatas,
59  std::vector< int >& tstep_nums ) override;
60 
61  private:
66  int mCoordDim; // always 2 for our writer (lat/lon sphere meshes)
67  bool mHasAreas;
68  bool mHasMask;
69 
70  // Per-rank node and cell arrays (all unique, owned-only).
71  std::vector< int > mLocalCellGids;
72  std::vector< double > mNodeLon; // size mLocalNodes
73  std::vector< double > mNodeLat; // size mLocalNodes
74  std::vector< int > mNodeGids; // global vertex id for dedup at rank 0
75 
76  std::vector< int > mElementConn; // size mLocalCells * mMaxCornersGlobal; global vertex GIDs (1-based)
77  std::vector< int > mElementNumNodes; // actual node count per cell
78  std::vector< double > mCenterLon;
79  std::vector< double > mCenterLat;
80  std::vector< double > mAreas; // empty if !mHasAreas
81  std::vector< int > mMask; // empty if !mHasMask
82 
93 };
94 
95 } // namespace moab
96 
97 #endif // NCWRITEESMF_HPP_