18 #include "vtkfigFrame.h" 19 #include "vtkfigDataSet.h" 20 #include "vtkfigGridView.h" 21 #include "vtkfigScalarView.h" 22 #include "vtkfigXYPlot.h" 53 auto frame=vtkfig::Frame::New();
54 frame->SetSize(800,800);
55 frame->SetLayout(2,2);
57 auto gridview=vtkfig::GridView::New();
58 frame->AddFigure(gridview,0);
60 auto solview=vtkfig::ScalarView::New();
61 frame->AddFigure(solview,1);
63 auto errplot=vtkfig::XYPlot::New();
64 frame->AddFigure(errplot,2);
65 errplot->SetXTitle(
"log10(h)");
66 errplot->SetYTitle(
"log10(error)");
68 auto timeplot=vtkfig::XYPlot::New();
69 frame->AddFigure(timeplot,3);
70 timeplot->SetXTitle(
"log10(N)");
71 timeplot->SetYTitle(
"log10(time)");
76 std::vector<double> H;
77 std::vector<double> Cond;
78 std::vector<double> N;
79 std::vector<double> TAsm;
80 std::vector<double> TGen;
81 std::vector<double> TJac;
82 std::vector<double> TCG;
85 std::vector<double> L2Error;
86 std::vector<double> H1Error;
89 for (
int iref=0;iref<maxref;iref++)
92 double h_intended=0.5*pow(2.0,-iref);
93 double vol= h_intended*h_intended*0.25;
102 printf(
"h_intended: %8.3g h_max: %8.3g\n",h_intended,hmax);
127 for (
int i=0; i<nnodes;i++)
131 exact[i]=sin(M_PI*x)*sin(M_PI*y);
132 source[i]=2.0*M_PI*M_PI*exact[i];
152 unsigned long max_iter=10000000;
155 unsigned long nsteps=0;
156 for (;nsteps<max_iter;nsteps++)
159 Precon.
solve(Upd,Res);
162 if (norm<1.0e-10)
break;
165 double rho=pow(res/res0,1.0/nsteps);
166 double cond=(1.0+rho)/(1.0-rho);
167 printf(
"ILU contr: %g, per step: %g, kappa: %g\n", res/res0, rho,cond);
175 int max_iter_cg=100000;
176 netlib::CG(SGlobal,Sol, Rhs,Precon,max_iter_cg,eps);
178 rho=pow(res/res0,1.0/max_iter_cg);
179 printf(
"CG contr: %g, per step: %g\n", res/res0, rho);
190 printf(
"h: %8.3e l2: %8.3e h1: %8.3e\n",hmax,l2error,h1error);
191 H.push_back(log10(hmax));
192 H1Error.push_back(log10(h1error));
193 L2Error.push_back(log10(l2error));
194 Cond.push_back(log10(cond));
196 printf(
"time/ms gen: %8.3f asm: %8.3f ilu: %8.3f cg: %8.3f\n",
197 t_gen*1000.0, t_asm*1000.0, t_jac*1000.0,t_cg*1000.0);
199 N.push_back(log10(grid.
npoints()));;
200 TAsm.push_back(log10(t_asm));
201 TJac.push_back(log10(t_jac));
202 TCG.push_back(log10(t_cg));
203 TGen.push_back(log10(t_gen));
207 auto griddata=numcxx::vtkfigDataSet(grid);
208 griddata->SetPointScalar(Sol ,
"Sol");
210 gridview->SetData(griddata);
211 solview->SetData(griddata,
"Sol");
213 frame->SetFrameTitle(
"iref="+std::to_string(iref));
226 errplot->SetLegendPosition(0.3,0.4);
227 errplot->SetXRange(x0,x1);
228 errplot->SetYRange(-5,5);
231 errplot->SetPlotLineType(
"-");
232 errplot->SetPlotMarkerType(
"o");
233 errplot->SetMarkerSize(2);
236 errplot->SetPlotColor(0.2,0.5,0.2);
237 errplot->SetPlotLegend(
"O(h**2)");
238 errplot->AddPlot(X,OH2);
239 errplot->SetPlotColor(0.5,0.2,0.2);
240 errplot->SetPlotLegend(
"O(h)");
241 errplot->AddPlot(X,OH1);
243 errplot->SetPlotColor(0.0,0.5,0);
244 errplot->SetPlotLegend(
"L2");
245 errplot->AddPlot(H,L2Error);
247 errplot->SetPlotLegend(
"H1");
248 errplot->SetPlotColor(0.5,0,0);
249 errplot->AddPlot(H,H1Error);
251 errplot->SetPlotLegend(
"Cond");
252 errplot->SetPlotColor(0,0,0.5);
253 errplot->AddPlot(H,Cond);
254 errplot->SetPlotLegend(
"O(1/h**2)");
255 errplot->AddPlot(X,OHM2);
273 timeplot->SetLegendPosition(0.3,0.6);
274 timeplot->SetLegendSize(0.15,0.3);
275 timeplot->SetXRange(n0,n1);
276 timeplot->SetYRange(t0,t1);
280 timeplot->SetPlotLineType(
"-");
281 timeplot->SetPlotMarkerType(
"o");
282 timeplot->SetMarkerSize(2);
293 timeplot->SetPlotLegend(
"ILU");
294 timeplot->SetPlotColor(0.0,0.0,0.5);
295 timeplot->AddPlot(N,TJac);
297 timeplot->SetPlotLegend(
"CG");
298 timeplot->SetPlotColor(0.0,0.5,0.5);
299 timeplot->AddPlot(N,TCG);
301 timeplot->SetPlotLegend(
"O(N**2))");
302 timeplot->SetPlotColor(0.0,0.0,1.0);
303 timeplot->AddPlot(XN2,ON2);
305 timeplot->SetPlotLegend(
"O(N**(3/2))");
306 timeplot->SetPlotColor(1.0,0.0,0.0);
307 timeplot->AddPlot(XN1,ON32);
Class collecting data for the description of piecewise linear geometries.
Sparse matrix class using CRS storage scheme.
void set_regionpoints(const std::initializer_list< std::initializer_list< double >> &il)
Set member via intializer list.
void set_regionvolumes(const std::initializer_list< double > &il)
Set member via intializer list.
int CG(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)
Iterative template routine – CG.
Header for simple grid data class.
A::value_type norm2(const A &a)
Euklidean norm of array or expression.
const TArray2< double > & get_points() const
Get array of point coordinates.
void assemble_heat_problem(const numcxx::SimpleGrid &Grid, const numcxx::DArray1 &BCfac, const numcxx::DArray1 &BCval, const numcxx::DArray1 &Source, const numcxx::DArray1 &Kappa, numcxx::DSparseMatrix &SGlobal, numcxx::DArray1 &Rhs)
Main header of the library.
double h1norm(const numcxx::SimpleGrid &grid, const numcxx::DArray1 &u)
void set_points(const std::initializer_list< std::initializer_list< double >> &il)
Set member via intializer list.
void set_regionnumbers(const std::initializer_list< int > &il)
Set member via intializer list.
const double Dirichlet
BC value marking Dirichlet boundary condition.
ILU preconditioner class.
void update(TSparseMatrix< T > &A)
Perform actual computation preconditioner.
void set_bfaces(const std::initializer_list< std::initializer_list< int >> &il)
Set member via intializer list.
void solve(TArray< T > &Sol, const TArray< T > &Rhs) const
Solve preconditioning system.
void set_bfaceregions(const std::initializer_list< int > &il)
Set member via intializer list.
One dimensional array class.
Class containing data for simple grid data structure.
Header for adapter beteween vtkfig dataset and simple grid.
double cpu_clock()
cpu time in seconds
void calc_hminmax(double &hmin, double &hmax) const
Calculate some grid data.
const int npoints() const
Return number of points.
A::value_type norm(const A &a)
Euklidean norm of array or expression.
double l2norm(const numcxx::SimpleGrid &grid, const numcxx::DArray1 &u)