File: vtkQuadratureSchemeDictionaryGenerator.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (304 lines) | stat: -rw-r--r-- 12,138 bytes parent folder | download | duplicates (2)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQuadratureSchemeDictionaryGenerator.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkQuadratureSchemeDictionaryGenerator.h"
#include "vtkQuadratureSchemeDefinition.h"

#include "vtkUnstructuredGrid.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkType.h"
#include "vtkDoubleArray.h"
#include "vtkDataArray.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkCellArray.h"
#include "vtkIdTypeArray.h"
#include "vtkIntArray.h"
#include "vtkUnstructuredGridAlgorithm.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
#include "vtkObjectFactory.h"

#include <sstream>
#include <string>
#include "vtkSmartPointer.h"
using std::ostringstream;
using std::string;

// Here are some default shape functions weights which
// we will use to create dictionaries in a gvien data set.
// Unused weights are commented out to avoid compiler warnings.
namespace
{
// double W_T_11_A[]={
//     3.33333333333334e-01, 3.33333333333333e-01, 3.33333333333333e-01};

double W_T_32_A[] = { 1.66666666666660e-01, 6.66666666666670e-01,
    1.66666666666670e-01, 6.66666666666660e-01, 1.66666666666670e-01,
    1.66666666666670e-01, 1.66666666666660e-01, 1.66666666666670e-01,
    6.66666666666670e-01 };

// double W_T_32_B[]={
//     5.00000000000000e-01, 5.00000000000000e-01, 0.00000000000000e+00,
//     5.00000000000000e-01, 0.00000000000000e+00, 5.00000000000000e-01,
//     0.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01};

double W_QT_43_A[] = { -1.11111111111111e-01, -1.11111111111111e-01,
    -1.11111111111111e-01, 4.44444444444445e-01, 4.44444444444444e-01,
    4.44444444444445e-01, -1.20000000000000e-01, 1.20000000000000e-01,
    -1.20000000000000e-01, 4.80000000000000e-01, 4.80000000000000e-01,
    1.60000000000000e-01, 1.20000000000000e-01, -1.20000000000000e-01,
    -1.20000000000000e-01, 4.80000000000000e-01, 1.60000000000000e-01,
    4.80000000000000e-01, -1.20000000000000e-01, -1.20000000000000e-01,
    1.20000000000000e-01, 1.60000000000000e-01, 4.80000000000000e-01,
    4.80000000000000e-01 };

double W_Q_42_A[] = { 6.22008467928145e-01, 1.66666666666667e-01,
    4.46581987385206e-02, 1.66666666666667e-01, 1.66666666666667e-01,
    4.46581987385206e-02, 1.66666666666667e-01, 6.22008467928145e-01,
    1.66666666666667e-01, 6.22008467928145e-01, 1.66666666666667e-01,
    4.46581987385206e-02, 4.46581987385206e-02, 1.66666666666667e-01,
    6.22008467928145e-01, 1.66666666666667e-01 };

double W_QQ_93_A[] = { 4.32379000772438e-01, -1.00000000000001e-01,
    -3.23790007724459e-02, -1.00000000000001e-01, 3.54919333848301e-01,
    4.50806661517046e-02, 4.50806661517046e-02, 3.54919333848301e-01,
    -1.00000000000001e-01, -1.00000000000001e-01, -1.00000000000001e-01,
    -1.00000000000001e-01, 2.00000000000003e-01, 1.12701665379260e-01,
    2.00000000000003e-01, 8.87298334620740e-01, -1.00000000000001e-01,
    -3.23790007724459e-02, -1.00000000000001e-01, 4.32379000772438e-01,
    4.50806661517046e-02, 4.50806661517046e-02, 3.54919333848301e-01,
    3.54919333848301e-01, -1.00000000000001e-01, -1.00000000000001e-01,
    -1.00000000000001e-01, -1.00000000000001e-01, 8.87298334620740e-01,
    2.00000000000003e-01, 1.12701665379260e-01, 2.00000000000003e-01,
    -2.50000000000000e-01, -2.50000000000000e-01, -2.50000000000000e-01,
    -2.50000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01,
    5.00000000000000e-01, 5.00000000000000e-01, -1.00000000000001e-01,
    -1.00000000000001e-01, -1.00000000000001e-01, -1.00000000000001e-01,
    1.12701665379260e-01, 2.00000000000003e-01, 8.87298334620740e-01,
    2.00000000000003e-01, -1.00000000000001e-01, 4.32379000772438e-01,
    -1.00000000000001e-01, -3.23790007724459e-02, 3.54919333848301e-01,
    3.54919333848301e-01, 4.50806661517046e-02, 4.50806661517046e-02,
    -1.00000000000001e-01, -1.00000000000001e-01, -1.00000000000001e-01,
    -1.00000000000001e-01, 2.00000000000003e-01, 8.87298334620740e-01,
    2.00000000000003e-01, 1.12701665379260e-01, -3.23790007724459e-02,
    -1.00000000000001e-01, 4.32379000772438e-01, -1.00000000000001e-01,
    4.50806661517046e-02, 3.54919333848301e-01, 3.54919333848301e-01,
    4.50806661517046e-02 };

// double W_E_41_A[]={
//      2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01};

double W_E_42_A[] = { 6.25000000000000e-01, 1.25000000000000e-01,
    1.25000000000000e-01, 1.25000000000000e-01, 1.25000000000000e-01,
    5.62500000000000e-01, 1.87500000000000e-01, 1.25000000000000e-01,
    1.25000000000000e-01, 1.87500000000000e-01, 5.62500000000000e-01,
    1.25000000000000e-01, 1.25000000000000e-01, 6.25000000000000e-02,
    6.25000000000000e-02, 7.50000000000000e-01 };

// double W_QE_41_A[]={
//     -1.25000000000000e-01, -1.25000000000000e-01, -1.25000000000000e-01, -1.25000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01, 2.50000000000000e-01};

double W_QE_42_A[] = { 1.56250000000000e-01, -9.37500000000000e-02,
    -9.37500000000000e-02, -9.37500000000000e-02, 3.12500000000000e-01,
    6.25000000000000e-02, 3.12500000000000e-01, 3.12500000000000e-01,
    6.25000000000000e-02, 6.25000000000000e-02, -9.37500000000000e-02,
    7.03125000000000e-02, -1.17187500000000e-01, -9.37500000000000e-02,
    2.81250000000000e-01, 4.21875000000000e-01, 9.37500000000000e-02,
    6.25000000000000e-02, 2.81250000000000e-01, 9.37500000000000e-02,
    -9.37500000000000e-02, -1.17187500000000e-01, 7.03125000000000e-02,
    -9.37500000000000e-02, 9.37500000000000e-02, 4.21875000000000e-01,
    2.81250000000000e-01, 6.25000000000000e-02, 9.37500000000000e-02,
    2.81250000000000e-01, -9.37500000000000e-02, -5.46875000000000e-02,
    -5.46875000000000e-02, 3.75000000000000e-01, 3.12500000000000e-02,
    1.56250000000000e-02, 3.12500000000000e-02, 3.75000000000000e-01,
    1.87500000000000e-01, 1.87500000000000e-01 };

}
;

vtkStandardNewMacro(vtkQuadratureSchemeDictionaryGenerator);

//-----------------------------------------------------------------------------
vtkQuadratureSchemeDictionaryGenerator::vtkQuadratureSchemeDictionaryGenerator()
{
  this->SetNumberOfInputPorts(1);
  this->SetNumberOfOutputPorts(1);
}

//-----------------------------------------------------------------------------
vtkQuadratureSchemeDictionaryGenerator::~vtkQuadratureSchemeDictionaryGenerator()
{
}

//-----------------------------------------------------------------------------
int vtkQuadratureSchemeDictionaryGenerator::FillInputPortInformation(int port,
    vtkInformation *info)
{
  switch (port)
  {
    case 0:
      info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
      break;
  }
  return 1;
}

//-----------------------------------------------------------------------------
int vtkQuadratureSchemeDictionaryGenerator::FillOutputPortInformation(int port,
    vtkInformation *info)
{
  switch (port)
  {
    case 0:
      info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
      break;
  }
  return 1;
}

//-----------------------------------------------------------------------------
int vtkQuadratureSchemeDictionaryGenerator::RequestData(vtkInformation *,
    vtkInformationVector **input, vtkInformationVector *output)
{
  vtkDataObject *tmpDataObj;
  // Get the inputs
  tmpDataObj = input[0]->GetInformationObject(0)->Get(
      vtkDataObject::DATA_OBJECT());
  vtkUnstructuredGrid *usgIn = vtkUnstructuredGrid::SafeDownCast(tmpDataObj);
  // Get the outputs
  tmpDataObj = output->GetInformationObject(0)->Get(
      vtkDataObject::DATA_OBJECT());
  vtkUnstructuredGrid *usgOut = vtkUnstructuredGrid::SafeDownCast(tmpDataObj);

  // Quick sanity check.
  if (usgIn == NULL || usgOut == NULL || usgIn->GetNumberOfPoints() == 0
      || usgIn->GetPointData()->GetNumberOfArrays() == 0)
  {
    vtkWarningMacro("Filter data has not been configured correctly. Aborting.");
    return 1;
  }

  // Copy the unstructured grid on the input
  usgOut->ShallowCopy(usgIn);

  // Interpolate the data arrays, but no points. Results
  // are stored in field data arrays.
  this->Generate(usgOut);

  return 1;
}

//-----------------------------------------------------------------------------
int vtkQuadratureSchemeDictionaryGenerator::Generate(
    vtkUnstructuredGrid *usgOut)
{
  // Get the dictionary key.
  vtkInformationQuadratureSchemeDefinitionVectorKey *key =
      vtkQuadratureSchemeDefinition::DICTIONARY();

  // Get the cell types used by the data set.
  vtkCellTypes *cellTypes = vtkCellTypes::New();
  usgOut->GetCellTypes(cellTypes);
  // add a definition to the dictionary for each cell type.
  int nCellTypes = cellTypes->GetNumberOfTypes();

  // create the offset array and store the dictionnary within
  vtkIdTypeArray* offsets = vtkIdTypeArray::New();
  string basename = "QuadratureOffset";
  string finalname = basename;
  vtkDataArray* data = usgOut->GetCellData()->GetArray(basename.c_str());
  ostringstream interpolatedName;
  int i = 0;
  while (data != NULL)
  {
    interpolatedName << basename << i;
    data = usgOut->GetCellData()->GetArray(interpolatedName.str().c_str());
    finalname = interpolatedName.str();
    i++;
  }

  offsets->SetName(finalname.c_str());
  usgOut->GetCellData()->AddArray(offsets);
  vtkInformation *info = offsets->GetInformation();

  for (int typeId = 0; typeId < nCellTypes; ++typeId)
  {
    int cellType = cellTypes->GetCellType(typeId);
    // Initiaze a definition for this particular cell type.
    vtkSmartPointer<vtkQuadratureSchemeDefinition> def = vtkSmartPointer<vtkQuadratureSchemeDefinition>::New();
    switch (cellType)
    {
      case VTK_TRIANGLE:
        def->Initialize(VTK_TRIANGLE, 3, 3, W_T_32_A);
        break;
      case VTK_QUADRATIC_TRIANGLE:
        def->Initialize(VTK_QUADRATIC_TRIANGLE, 6, 4, W_QT_43_A);
        break;
      case VTK_QUAD:
        def->Initialize(VTK_QUAD, 4, 4, W_Q_42_A);
        break;
      case VTK_QUADRATIC_QUAD:
        def->Initialize(VTK_QUADRATIC_QUAD, 8, 9, W_QQ_93_A);
        break;
      case VTK_TETRA:
        def->Initialize(VTK_TETRA, 4, 4, W_E_42_A);
        break;
      case VTK_QUADRATIC_TETRA:
        def->Initialize(VTK_QUADRATIC_TETRA, 10, 4, W_QE_42_A);
        break;
      default:
        cerr << "Error: Cell type " << cellType << " found "
            << "with no definition provided. Add a definition " << " in "
            << __FILE__ << ". Aborting." << endl;
        return 0;
    }

    // The definition must apear in the dictionary associated
    // with the offset array
    key->Set(info, def, cellType);
  }

  int dictSize = key->Size(info);
  vtkQuadratureSchemeDefinition **dict =
      new vtkQuadratureSchemeDefinition *[dictSize];
  key->GetRange(info, dict, 0, 0, dictSize);

  offsets->SetNumberOfTuples(usgOut->GetNumberOfCells());
  vtkIdType offset = 0;
  for (vtkIdType cellid = 0; cellid < usgOut->GetNumberOfCells(); cellid++)
  {
    offsets->SetValue(cellid, offset);
    vtkCell* cell = usgOut->GetCell(cellid);
    int cellType = cell->GetCellType();
    vtkQuadratureSchemeDefinition * celldef = dict[cellType];
    offset += celldef->GetNumberOfQuadraturePoints();
  }
  offsets->Delete();
  cellTypes->Delete();
  delete[] dict;
  return 1;
}

//-----------------------------------------------------------------------------
void vtkQuadratureSchemeDictionaryGenerator::PrintSelf(ostream& os,
    vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);

  os << indent << "No state." << endl;
}