VTKFIG  0.20.20181114
Easy VTK based in situ visualization
int main ( void  )

Definition at line 31 of file example-rectquiver2d.cxx.

32 {
33  size_t nspin=vtkfig::NSpin();
34  const int Nx = 20;
35  const int Ny = 25;
36 
37  std::vector<double> x(Nx);
38  std::vector<double> y(Ny);
39  std::vector<double> z(Nx*Ny);
40  std::vector<double> u(Nx*Ny);
41  std::vector<double> v(Nx*Ny);
42 
43 
44  const double x_low = -2.5;
45  const double x_upp = 1.5;
46  const double y_low = -2.5;
47  const double y_upp = 4;
48  const double dx = (x_upp-x_low)/(Nx-1);
49  const double dy = (y_upp-y_low)/(Ny-1);
50 
51  auto frame=vtkfig::Frame::New();
52 
53  auto colors=vtkfig::RGBTable
54  {
55  {0.0, 0.3, 0.3, 1.0},
56  {0.5, 0.3, 1.0, 0.3},
57  {1.0, 1.0, 0.3, 0.3}
58  };
59  auto qcolors=vtkfig::RGBTable
60  {
61  {0.0, 0.0, 0.0, 0.0},
62  {1.0, 0.0, 0.0, 0.0}
63  };
64 
65  for (int i=0; i<Nx; i++)
66  x[i] = x_low+i*dx;
67 
68  for (int i=0; i<Ny; i++)
69  y[i] = y_low + i*dy;
70 
71 
72  double t=0;
73  double dt=0.1;
74  size_t ii=0;
75  double t0=(double)clock()/(double)CLOCKS_PER_SEC;
76  double i0=ii;
77 
78  auto griddata=vtkfig::DataSet::New();
79  griddata->SetRectilinearGrid(x,y);
80  griddata->SetPointScalar(z ,"v");
81  griddata->SetPointVector(u,v ,"grad");
82 
83  auto contour=vtkfig::ScalarView::New();
84  contour->SetData(griddata,"v");
85  contour->SetSurfaceRGBTable(colors,255);
86  contour->ShowIsolines(false);
87 
88  auto quiver=vtkfig::VectorView::New();
89  quiver->SetData(griddata,"grad");
90  quiver->SetQuiverGrid(10,10);
91 
92 
93 
94 
95  frame->AddFigure(contour);
96  frame->AddFigure(quiver);
97 
98 
99  while (ii<nspin)
100  {
101 
102  for (int i=0; i<Nx; i++)
103  for (int j=0; j<Ny; j++)
104  {
105  z[j*Nx+i] = G(x[i],y[j],t);
106  u[j*Nx+i] = dGdx(x[i],y[j],t);
107  v[j*Nx+i] = dGdy(x[i],y[j],t);
108  }
109 
110  griddata->SetPointScalar(z ,"v");
111  griddata->SetPointVector(u,v ,"grad");
112 
113  frame->Show();
114 
115  if (ii==3)
116  frame->WritePNG("example-quiver2d.png");
117 
118  t+=dt;
119  double t1=(double)clock()/(double)CLOCKS_PER_SEC;
120  double i1=ii;
121  if (t1-t0>4.0)
122  {
123  printf("Frame rate: %.2f fps\n",(double)(i1-i0)/4.0);
124  t0=(double)clock()/(double)CLOCKS_PER_SEC;
125  i0=ii;
126  }
127  ii++;
128  }
129 
130 }
size_t NSpin()
Definition: vtkfigTools.cxx:13
double dGdy(double x, double y, double t)
static std::shared_ptr< Frame > New()
Create frame with multiple subframes.
Definition: vtkfigFrame.h:54
static std::shared_ptr< ScalarView > New()
static std::shared_ptr< DataSet > New()
Static constructor of an empty instance.
Definition: vtkfigDataSet.h:40
double dGdx(double x, double y, double t)
std::vector< RGBPoint > RGBTable
Definition: vtkfigTools.h:26
static std::shared_ptr< VectorView > New()
double G(double x, double y, double t)

+ Here is the call graph for this function: