/************************************************************************** ** Title: demo program for linear solver test ** Date: 8.1.2009 ** Copyright: Bernard Haasdonk **************************************************************************/ #include"config.h" #include // include mpi helper class #include #include #include #include #include // load sgrid definition #include // collect some consts and typedefs in order to keep the main-program readable const int dim = 2; const int dimworld = 2; const int polOrder = 0; const int dimrange = 1; typedef Dune::SGrid GridType; typedef double DomainFieldType; typedef double RangeFieldType; typedef Dune::FunctionSpace FunctionSpaceType; typedef Dune::LeafGridPart GridPartType; typedef Dune::DiscontinuousGalerkinSpace DiscreteFunctionSpaceType; typedef Dune::AdaptiveDiscreteFunction DiscreteFunctionType; typedef DiscreteFunctionType::DofIteratorType DofIteratorType; class MyOperatorType; //typedef Dune::OEMCGOp // InverseOperatorType; //typedef Dune::OEMBICGSTABOp // InverseOperatorType; typedef Dune::OEMBICGSQOp InverseOperatorType; //typedef Dune::OEMGMRESOp // InverseOperatorType; class MyOperatorType //: // public Dune::Operator { public: MyOperatorType(int n): A_(0), size_(n) { A_ = new double* [n]; for (int j=0; j N(2);; /*@\label{gs:par0}@*/ N[1] = 1; Dune::FieldVector L(-1.0); Dune::FieldVector H(1.0);; /*@\label{gs:par1}@*/ GridType grid(N,L,H); /*@\label{gs:grid}@*/ // generate Lagrange function on LeafGridPart GridPartType gridpart(grid); DiscreteFunctionSpaceType dfspace(gridpart); int n = dfspace.size(); std::cout << "size of df-space: " << n << "\n"; // generate p0 function and set DOF-indices as function value DiscreteFunctionType b("b",dfspace); for (DofIteratorType it=b.dbegin(); it!=b.dend(); ++it) *it = 1.0; // generate p0 function and set DOF-indices as function value DiscreteFunctionType x("x",dfspace); for (DofIteratorType it=x.dbegin(); it!=x.dend(); ++it) *it = 1.0; // set matrix A as mapping MyOperatorType myOp(dfspace.size()); double** A = myOp.matrix(); for (int sys=0;sys<4;sys++) { x.clear(); // try to use dune-fem solvers double redEps = 0.0; double absLimit = 1e-15; int maxIter = 20000; bool verbose = true; InverseOperatorType solver(myOp, redEps, absLimit, maxIter, verbose); switch(sys) { case 0: std::cout << "----------------\nindefinite, non-symmetric: \n"; A[0][0] = 2.0; A[0][1] = 6.0; A[1][0] = 4.0; A[1][1] = 2.0; break; case 1: std::cout << "----------------\nindefinite, symmetric: \n"; A[0][0] = 2.0; A[0][1] = 4.0; A[1][0] = 4.0; A[1][1] = 2.0; break; case 2: std::cout << "----------------\npositive definite, non-symmetric: \n"; A[0][0] = 2.0; A[0][1] = 2.0; A[1][0] = 0.0; A[1][1] = 4.0; break; case 3: std::cout << "----------------\npositive definite, symmetric: \n"; A[0][0] = 2.0; A[0][1] = 1.0; A[1][0] = 1.0; A[1][1] = 2.0; break; } solver(b,x); // output solution vector: std::cout << "x = \n"; for (DofIteratorType it=x.dbegin(); it!=x.dend(); ++it) std::cout << *it << " "; std::cout << "\n"; } // end sys loop // for (int i = 0; i