NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
22-numcxx-vtkfigrect2D.cxx
Go to the documentation of this file.
1 #include <numcxx/numcxx.hxx>
2 #include <cstdio>
3 #include <cmath>
4 #include "vtkfig/vtkfigFrame.h"
5 #include "vtkfig/vtkfigDataSet.h"
6 #include "vtkfig/vtkfigScalarView.h"
7 
8 
9 int main(void)
10 {
11  const double x0=0.0;
12  const double x1=1.0;
13  double h=0.01;
14  double t0=0.0;
15  double t1=10.0;
16  double dt=0.01;
17 
18  const int N=1+ceil((x1-x0)/h);
19  h=(x1-x0)/(double)(N-1);
20 
21  numcxx::DArray1 X(N);
22  numcxx::DArray1 U(N*N );
23 
24  X(0)=x0;
25  for (int i=1;i<N;i++)
26  {
27  X(i)=X(i-1)+h;
28  }
29 
30 
31 
32  auto griddata=vtkfig::DataSet::New();
33  griddata->SetRectilinearGrid(X,X);
34 
35 
36  auto frame=vtkfig::Frame::New();
37  auto scview=vtkfig::ScalarView::New();
38  scview->SetData(griddata,"U");
39  frame->AddFigure(scview);
40 
41  double t=t0;
42 
43 
44  while (t<t1)
45  {
46  int ij=0;
47  for (int i=0; i<N; i++)
48  for (int j=0; j<N; j++,ij++)
49  {
50  U(ij)=sin(20.0*(X(i)-t))*cos(20.0*(X(j)-2*t));
51  }
52  char titlebuf[20];
53  snprintf(titlebuf,20,"t=%g",t);
54  griddata->SetPointScalar(U ,"U");
55  frame->Show();
56  t+=dt;
57  }
58 
59 }
Main header of the library.
int main(void)
One dimensional array class.
Definition: tarray1.hxx:31