~reducedmodelling/fluidity/ROM_Non-intrusive-ann

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*  Copyright (C) 2006 Imperial College London and others.
    
    Please see the AUTHORS file in the main source directory for a full list
    of copyright holders.

    Prof. C Pain
    Applied Modelling and Computation Group
    Department of Earth Science and Engineering
    Imperial College London

    amcgsoftware@imperial.ac.uk
    
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation,
    version 2.1 of the License.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
    USA
*/

#ifndef NEMOREADER_H
#define NEMOREADER_H

#include "fmangle.h"
#include "c++debug.h"

#include <cassert>
#include <cmath>
#ifdef __SUN
double round(double);
#endif
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#ifdef HAVE_NETCDF
extern "C" {
#include <netcdf.h>
}
#endif

#ifdef NEMOReader_UNIT_TEST
#include <vtk.h>

#ifndef vtkFloatingPointType
#define vtkFloatingPointType vtkFloatingPointType
typedef float vtkFloatingPointType;
#endif
#endif

#ifdef HAVE_MPI
#include <mpi.h>
#endif

#include <stdio.h>
#include <stdlib.h>

#include "Calendar.h"

#include <fstream>    // |
                      // |--> These two lines need to be removed. Here for temporary printing to file purposes.
using namespace std;  // |

class NEMOReader{
 public:
  NEMOReader();
  ~NEMOReader();
  
  void AddFieldOfInterest(std::string);
  void ClearFields();
  bool Enabled() const;
  int GetScalars(double, double, double, double*);
  int RegisterDataFile(std::string);
  int SetSimulationTimeUnits(std::string);
  int SetTimeSeconds(double);
  void VerboseOff();
  void VerboseOn();
  void WriteVTS(std::string) const;

 private:
  bool verbose, modified;
  double time_set;

  std::pair<size_t, size_t> GetInterval(double value, const std::map<double, int>&lut) const;

  double GetScalar(std::string, double, double);
  double GetScaleFactor(std::string) const;
  int Read(int);
  int Update();
  inline double SolveLine(double y, double x0, double x1, double y0, double y1) const;

  int NProcs, MyRank, NParts;
  std::deque<std::string> NEMO_data_files;
  
  //
  // NEMO data file specification
  //
  int ncid; // NetCDF file handle
  std::map<std::string, long> spec;
  std::vector<double> longitude, latitude;
  std::map<double, int> lut_longitude, lut_latitude, lut_depth;
  double dlong, dlat;
  std::vector<double> depth;
  std::vector<double> time;
  std::map<double, int> lut_time;

  // Grid space and time dimensions
  long vdimension[2];
  long ndepth, ntime;      
  
  std::string simulation_time_units, data_time_units;
  Calendar *calendar;

  //
  // Data
  //
  int time_fore, time_aft;
  int hour_index;
  
  // Fields of interest
  std::deque<std::string> fields_of_interest;

  //    time index    |  name of field  | field values
  std::map<int, std::map<std::string, std::vector<double> > > fields;

};

extern NEMOReader NEMOReader_global;
extern NEMOReader NEMOReader_v2_global;

#endif