-
Notifications
You must be signed in to change notification settings - Fork 0
/
fv_create_data.cxx
210 lines (196 loc) · 5.72 KB
/
fv_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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <sstream>
#include "Grid.h"
#include "vtkCPDataDescription.h"
#include "vtkCPInputDataDescription.h"
#include "vtkCPProcessor.h"
#include "vtkCPPythonScriptPipeline.h"
#include "vtkUnstructuredGrid.h"
#include "vtkSmartPointer.h"
namespace
{
vtkCPProcessor* g_coprocessor; // catalyst coprocessor
vtkCPDataDescription* g_coprocessorData; // input, sinput, input3D, sinput3D
bool g_isTimeDataSet; // is time data set?
Grid<RECTILINEAR>* g_grid; // rectilinear grid (2D, 3D)
Grid<SPHERE>* g_sgrid; // structured (spherical) (2D, 3Da) grids
};
//////////////////////////////////////////////////////////////////////
// Initializes the Catalyst Coprocessor
// WARNING: Make sure you pass a zero terminated string
extern "C" void fv_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");
g_coprocessorData->AddInput("sinput");
g_coprocessorData->AddInput("sinput3D");
}
}
// Creates the Grids for 2D, 3D rectilinear and 2D, 3D spherical
extern "C" void fv_create_grid_(
int* dim, double* lonCoord, double* latCoord, double* levCoord,
int* nCells2d, int* maxNcols,
int* myRank)
{
//printCreateGrid(dim, lonCoord, latCoord, levCoord, nCells2d, maxNcols, myRank);
if (!g_coprocessorData)
{
vtkGenericWarningMacro("Unable to access CoProcessorData.");
return;
}
g_grid = new Grid<RECTILINEAR>();
g_grid->SetMpiRank(*myRank);
g_grid->SetChunkCapacity(*maxNcols);
g_grid->SetNCells2d(*nCells2d);
g_grid->SetNLon(dim[0]);
g_grid->SetNLat(dim[1]);
g_grid->SetLev(dim[2], levCoord);
g_grid->SetLonStep(lonCoord[1] - lonCoord[0]);
g_grid->SetLatStep(latCoord[1] - latCoord[0]);
g_grid->Create();
if (! Grid<RECTILINEAR>::SetToCoprocessor(g_coprocessorData, "input", g_grid->GetGrid2d()) ||
! Grid<RECTILINEAR>::SetToCoprocessor(g_coprocessorData, "input3D", g_grid->GetGrid3d()))
{
vtkGenericWarningMacro(<< "No input data description");
delete g_grid;
g_grid = NULL;
}
g_sgrid = new Grid<SPHERE>();
g_sgrid->SetMpiRank(*myRank);
g_sgrid->SetChunkCapacity(*maxNcols);
g_sgrid->SetNCells2d(*nCells2d);
g_sgrid->SetNLon(dim[0]);
g_sgrid->SetNLat(dim[1]);
g_sgrid->SetLev(dim[2], levCoord);
g_sgrid->SetLonStep(lonCoord[1] - lonCoord[0]);
g_sgrid->SetLatStep(latCoord[1] - latCoord[0]);
g_sgrid->Create();
if (! Grid<SPHERE>::SetToCoprocessor(g_coprocessorData, "sinput", g_sgrid->GetGrid2d()) ||
! Grid<SPHERE>::SetToCoprocessor(g_coprocessorData, "sinput3D", g_sgrid->GetGrid3d()))
{
vtkGenericWarningMacro(<< "No input data description");
delete g_sgrid;
g_sgrid = 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 fv_add_chunk_(
int* nstep, int* chunkSize,
double* lonRad, double* latRad,
double* psScalar, double *tScalar, double* uScalar, double* vScalar)
{
if (*nstep == 0)
{
for (int i = 0; i < *chunkSize; ++i)
{
if (g_grid)
{
g_grid->AddPointsAndCells(lonRad[i], latRad[i]);
}
if (g_sgrid)
{
g_sgrid->AddPointsAndCells(lonRad[i], latRad[i]);
}
}
}
if (g_grid)
{
// g_grid->PrintAddChunk(
// nstep, chunkSize, lonRad, latRad, psScalar, tScalar);
g_grid->SetAttributeValue(*chunkSize, lonRad, latRad,
psScalar, tScalar, uScalar, vScalar);
}
if (g_sgrid)
{
g_sgrid->SetAttributeValue(*chunkSize, lonRad, latRad,
psScalar, tScalar, uScalar, vScalar);
}
}
// Deletes global data
extern "C" void fv_finalize_()
{
if (g_grid)
{
delete g_grid;
}
if (g_sgrid)
{
delete g_sgrid;
}
}
// Deletes the Catalyt Coprocessor and data
extern "C" void fv_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 fv_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 fv_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 fv_coprocess_()
{
if(!g_isTimeDataSet)
{
vtkGenericWarningMacro("Time data not set.");
}
else
{
g_coprocessor->CoProcess(g_coprocessorData);
}
// Reset time data.
g_isTimeDataSet = false;
}