File: FEAdaptor.cxx

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (121 lines) | stat: -rw-r--r-- 3,241 bytes parent folder | download
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
#include "FEAdaptor.h"
#include <iostream>

#include <vtkCPDataDescription.h>
#include <vtkCPInputDataDescription.h>
#include <vtkCPProcessor.h>
#include <vtkCPPythonScriptPipeline.h>
#include <vtkCompositeDataIterator.h>
#include <vtkNew.h>
#include <vtkNonOverlappingAMR.h>
#include <vtkUniformGrid.h>

namespace
{
vtkCPProcessor* Processor = nullptr;
vtkNonOverlappingAMR* VTKGrid;

void BuildVTKGrid()
{
  if (VTKGrid == nullptr)
  {
    // The grid structure isn't changing so we only build it
    // the first time it's needed. If we needed the memory
    // we could delete it and rebuild as necessary.
    VTKGrid = vtkNonOverlappingAMR::New();
  }

  // Note that all of the vtkUniformGrids in the vtkNonOverlappingAMR
  // grid can use independent spacing, origin and extents. This is
  // shown in the mid-level grids in that they don't share an
  // origin. The highest level grid and lowest level grid do share
  // the same origin of (0,0,0) and thus need to have appropriate
  // extents and spacings as well.
  int numberOfLevels = 3;
  int blocksPerLevel[3] = { 1, 2, 1 };
  VTKGrid->Initialize(numberOfLevels, blocksPerLevel);

  // the highest level grid
  vtkNew<vtkUniformGrid> level0Grid;
  level0Grid->SetSpacing(4, 4, 4);
  level0Grid->SetOrigin(0, 0, 0);
  level0Grid->SetExtent(0, 10, 0, 20, 0, 20);
  VTKGrid->SetDataSet(0, 0, level0Grid);

  // the first mid-level grid
  vtkNew<vtkUniformGrid> level1Grid0;
  level1Grid0->SetSpacing(2, 2, 2);
  level1Grid0->SetOrigin(40, 0, 0);
  level1Grid0->SetExtent(0, 8, 0, 20, 0, 40);
  VTKGrid->SetDataSet(1, 0, level1Grid0);

  // the second mid-level grid
  vtkNew<vtkUniformGrid> level1Grid1;
  level1Grid1->SetSpacing(2, 2, 2);
  level1Grid1->SetOrigin(40, 40, 0);
  level1Grid1->SetExtent(0, 40, 0, 20, 0, 40);
  VTKGrid->SetDataSet(1, 1, level1Grid1);

  // the lowest level grid
  vtkNew<vtkUniformGrid> level2Grid;
  level2Grid->SetSpacing(1, 1, 2);
  level2Grid->SetOrigin(0, 0, 0);
  level2Grid->SetExtent(56, 120, 0, 40, 0, 40);
  VTKGrid->SetDataSet(2, 0, level2Grid);
}
}

namespace FEAdaptor
{
void Initialize(int numScripts, char* scripts[])
{
  if (Processor == nullptr)
  {
    Processor = vtkCPProcessor::New();
    Processor->Initialize();
  }
  else
  {
    Processor->RemoveAllPipelines();
  }
  for (int i = 0; i < numScripts; i++)
  {
    vtkNew<vtkCPPythonScriptPipeline> pipeline;
    pipeline->Initialize(scripts[i]);
    Processor->AddPipeline(pipeline);
  }
}

void Finalize()
{
  if (Processor)
  {
    Processor->Delete();
    Processor = nullptr;
  }
  if (VTKGrid)
  {
    VTKGrid->Delete();
    VTKGrid = nullptr;
  }
}

void CoProcess(double time, unsigned int timeStep, bool lastTimeStep)
{
  vtkNew<vtkCPDataDescription> dataDescription;
  dataDescription->AddInput("input");
  dataDescription->SetTimeData(time, timeStep);
  if (lastTimeStep == true)
  {
    // assume that we want to all the pipelines to execute if it
    // is the last time step.
    dataDescription->ForceOutputOn();
  }
  if (Processor->RequestDataDescription(dataDescription) != 0)
  {
    BuildVTKGrid();
    dataDescription->GetInputDescriptionByName("input")->SetGrid(VTKGrid);
    Processor->CoProcess(dataDescription);
  }
}
} // end of Catalyst namespace