-
Notifications
You must be signed in to change notification settings - Fork 0
/
se_create_data.cxx
177 lines (164 loc) · 4.57 KB
/
se_create_data.cxx
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <sstream>
#include <set>
#include <iterator>
#include <cfloat>
#include "Grid.h"
#include "vtkCPDataDescription.h"
#include "vtkCPInputDataDescription.h"
#include "vtkCPProcessor.h"
#include "vtkCPPythonScriptPipeline.h"
#include "vtkMath.h"
#include "vtkUnstructuredGrid.h"
#include "vtkSmartPointer.h"
namespace
{
vtkCPProcessor* g_coprocessor; // catalyst coprocessor
vtkCPDataDescription* g_coprocessorData; // sinput, sinput3d
bool g_isTimeDataSet; // is time data set?
Grid<CUBE_SPHERE>* g_grid; // 2d,3d cubed-spheres
};
///////////////////////////////////////////////////////////////////////////
// Initializes the Catalyst Coprocessor
// WARNING: Make sure you pass a zero terminated string
extern "C" void se_coprocessorinitializewithpython_(const char* pythonScriptName)
{
if (!g_coprocessor)
{
g_coprocessor = vtkCPProcessor::New();
g_coprocessor->Initialize();
// python pipeline
vtkSmartPointer<vtkCPPythonScriptPipeline> pipeline =
vtkSmartPointer<vtkCPPythonScriptPipeline>::New();
pipeline->Initialize(pythonScriptName);
g_coprocessor->AddPipeline(pipeline);
}
if (!g_coprocessorData)
{
g_coprocessorData = vtkCPDataDescription::New();
g_coprocessorData->AddInput("input");
g_coprocessorData->AddInput("input3D");
}
}
// Creates grids for 2d and 3d cubed-spheres
extern "C" void se_create_grid_(
int* ne, int* np, int* nlon, double* lonRad, int* nlat, double* latRad,
int* nlev, double* lev, int* nCells2d, int* maxNcols, int* mpiRank)
{
if (!g_coprocessorData)
{
vtkGenericWarningMacro("Unable to access CoProcessorData.");
return;
}
g_grid = new Grid<CUBE_SPHERE>();
g_grid->SetMpiRank(*mpiRank);
g_grid->SetChunkCapacity(*maxNcols);
int points = *ne * *np + 1;
g_grid->SetNCells2d(points * points * 6);
g_grid->SetCubeGridPoints(*ne, *np, *nlon, lonRad, *nlat, latRad);
g_grid->SetLev(*nlev, lev);
g_grid->Create();
if (! Grid<CUBE_SPHERE>::SetToCoprocessor(g_coprocessorData, "input", g_grid->GetGrid2d()) ||
! Grid<CUBE_SPHERE>::SetToCoprocessor(g_coprocessorData, "input3D", g_grid->GetGrid3d()))
{
vtkGenericWarningMacro(<< "No input data description");
delete g_grid;
g_grid = NULL;
}
}
// for timestep 0: creates the points and cells for the grids.
// for all timesteps: copies data from the simulation to Catalyst.
extern "C" void se_add_chunk_(
int* nstep, int* chunkSize,
double* lonRad, double* latRad,
double* psScalar, double *tScalar, double* uScalar, double* vScalar)
{
if (*nstep == 0)
{
std::ostringstream ostr;
ostr << "se_add_chunk: " << *chunkSize << std::endl;
std::cerr << ostr.str();
for (int i = 0; i < *chunkSize; ++i)
{
if (g_grid)
{
g_grid->AddPointsAndCells(lonRad[i], latRad[i]);
}
}
}
if (g_grid)
{
g_grid->SetAttributeValue(*chunkSize, lonRad, latRad,
psScalar, tScalar, uScalar, vScalar);
}
}
// Deletes global data
extern "C" void se_finalize_()
{
if (g_grid)
{
delete g_grid;
}
}
// Deletes the Catalyt Coprocessor and data
extern "C" void se_coprocessorfinalize_()
{
if (g_coprocessor)
{
g_coprocessor->Delete();
g_coprocessor = NULL;
}
if (g_coprocessorData)
{
g_coprocessorData->Delete();
g_coprocessorData = NULL;
}
}
// Checks if Catalyst needs to coprocess data
extern "C" int se_requestdatadescription_(int* timeStep, double* time)
{
if(!g_coprocessorData || !g_coprocessor)
{
vtkGenericWarningMacro("Data or coprocessor are not initialized.");
return 0;
}
vtkIdType tStep = *timeStep;
g_coprocessorData->SetTimeData(*time, tStep);
if(g_coprocessor->RequestDataDescription(g_coprocessorData))
{
g_isTimeDataSet = true;
return 1;
}
else
{
g_isTimeDataSet = false;
return 0;
}
}
// Checks if the grids need to be created
extern "C" int se_needtocreategrid_()
{
if(!g_isTimeDataSet)
{
vtkGenericWarningMacro("Time data not set.");
return 0;
}
// assume that the grid is not changing so that we only build it
// the first time, otherwise we clear out the field data
vtkCPInputDataDescription* idd =
g_coprocessorData->GetInputDescriptionByName("input");
return (idd == NULL || idd->GetGrid() == NULL);
}
// calls the coprocessor
extern "C" void se_coprocess_()
{
if(!g_isTimeDataSet)
{
vtkGenericWarningMacro("Time data not set.");
}
else
{
g_coprocessor->CoProcess(g_coprocessorData);
}
// Reset time data.
g_isTimeDataSet = false;
}