NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
21-numcxx-vtkfigrect1D.cxx File Reference
+ Include dependency graph for 21-numcxx-vtkfigrect1D.cxx:

Go to the source code of this file.

Functions

int main (void)
 

Function Documentation

int main ( void  )

Definition at line 9 of file 21-numcxx-vtkfigrect1D.cxx.

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);
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 frame=vtkfig::Frame::New();
33  auto xyplot=vtkfig::XYPlot::New();
34  xyplot->SetPlotColor(1.0,0.0,0.0);
35  xyplot->SetPlotLineType("-");
36  xyplot->SetXAxisLabelFormat("%3.1f");
37  xyplot->SetYAxisLabelFormat("%3.1f");
38  frame->AddFigure(xyplot);
39 
40  double t=t0;
41 
42 
43  while (t<t1)
44  {
45  for (int i=0; i<N; i++)
46  {
47  U(i)=sin(20.0*(X(i)-t));
48  }
49 
50  char titlebuf[20];
51  snprintf(titlebuf,20,"t=%g",t);
52  xyplot->Clear();
53  xyplot->SetTitle(titlebuf);
54  xyplot->AddPlot(X,U);
55  frame->Show();
56  t+=dt;
57  }
58 
59 }
One dimensional array class.
Definition: tarray1.hxx:31