Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_DivisionOperatorUnitTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #include "Stokhos.hpp"
21 
22 namespace DivisionOperatorUnitTest {
23 
24  // Common setup for unit tests
25  template <typename OrdinalType, typename ValueType>
26  struct UnitTestSetup {
27  ValueType rtol, atol;
28  ValueType crtol, catol;
29  OrdinalType sz;
36  ValueType a;
38 
39 
41  rtol = 1e-10;//4
42  atol = 1e-10;//5
43  crtol = 1e-12;
44  catol = 1e-12;
45  a = 3.1;
46  const OrdinalType d = 2;
47  const OrdinalType p = 7;
48 
49  // Create product basis
51  for (OrdinalType i=0; i<d; i++)
52  bases[i] =
54  basis =
56 
57  // Tensor product quadrature
58  quad =
60 
61  // Triple product tensor
64 
65  // Algebraic expansion
66  exp =
68  exp_linear =
70 
71  // Quadrature expansion
72  qexp =
74  //Dense Direct Division Operator
77 
78 
79  // Create approximation
80 // sz = basis->size();
81  x.reset(basis);
82  y.reset(basis);
83  u.reset(basis);
84  u2.reset(basis);
85  cx.reset(basis, 1);
86  x.term(0, 0) = 1.0;
87 // y.term(0, 0) = 1.0:
88  cx.term(0, 0) = a;
89  cu.reset(basis);
90 // cu2.reset(basis, 1);
91 // sx.reset(basis, d+1);
92 // su.reset(basis, d+1);
93 // su2.reset(basis, d+1);
94  for (OrdinalType i=0; i<d; i++) {
95  x.term(i, 1) = 1.0;
96 // y.term(i, 1) = 0.1;
97  }
98 // y.term(0, 0) = 2.0;
99 // for (OrdinalType i=0; i<d; i++)
100 // y.term(i, 1) = 0.25;
101 
102  c1.reset(basis);
103  c1.term(0,0)=1;
104  exp->exp(cu, x);
105 
106  }
107 };
108 
110 
111 
112 
113  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Divide ) {
115  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 0, 100, 0, 0,1));
116  cg_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
117  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
118  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
119  setup.rtol, setup.atol, out);
120  }
121  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Jacobi_Divide ) {
123  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 2, 100, 0, 0,1));
124  cg_diag_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
125  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
126  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
127  setup.rtol, setup.atol, out);
128  }
129  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_SymGaussSeidel_Divide ) {
131  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 3, 100, 0, 0,1));
132  cg_jacobi_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
133  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
134  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
135  setup.rtol, setup.atol, out);
136  }
137  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Schur_Divide ) {
139  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 0, 0,1));
140  cg_schur_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
141  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
142  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
143  setup.rtol, setup.atol, out);
144  }
145 
146  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Nonlin_Divide ) {
148  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 0, 100, 0, 0,1));
149  cg_nonlin_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
150  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
151  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
152  setup.rtol, setup.atol, out);
153  }
154  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Nonlin_Jacobi_Divide ) {
156  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 2, 100, 0, 0,1));
157  cg_nonlin_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
158  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
159  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
160  setup.rtol, setup.atol, out);
161  }
162  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Nonlin_SymGaussSeidel_Divide ) {
164  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 3, 100, 0, 0,1));
165  cg_nonlin_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
166  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
167  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
168  setup.rtol, setup.atol, out);
169  }
170 
171  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Nonlin_Schur_Divide ) {
173  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 0, 0,1));
174  cg_nonlin_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
175  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
176  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
177  setup.rtol, setup.atol, out);
178  }
179  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, CG_Nonlin_Schur_linearprec_Divide ) {
181  Teuchos::rcp(new Stokhos::CGDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 1, 0,1));
182  cg_nonlin_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
183  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
184  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
185  setup.rtol, setup.atol, out);
186  }
187  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Divide ) {
189  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 0, 100, 0, 0,1));
190  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
191  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
192  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
193  setup.rtol, setup.atol, out);
194  }
195 
196  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Jacobi_Divide ) {
198  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 2, 100, 0, 0,1));
199  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
200  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
201  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
202  setup.rtol, setup.atol, out);
203  }
204  TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_GaussSeidel_Divide ) {
206  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 3, 100, 0, 0,1));
207  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
208  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
209  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
210  setup.rtol, setup.atol, out);
211  }
212 
213 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Schur_Divide ) {
215  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 0, 0,1));
216  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.x, 0.0);
217  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.x, 0.0);
218  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
219  setup.rtol, setup.atol, out);
220  }
221 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Nonlin_Divide ) {
223  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 0, 100, 0, 0,1));
224  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
225  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
226  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
227  setup.rtol, setup.atol, out);
228  }
229 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Nonlin_Jacobi_Divide ) {
231  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 2, 100, 0, 0,1));
232  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
233  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
234  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
235  setup.rtol, setup.atol, out);
236 
237  }
238 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Nonlin_GaussSeidel_Divide ) {
240  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 1, 1e-12, 3, 100, 0, 0,1));
241  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
242  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
243  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
244  setup.rtol, setup.atol, out);
245 
246  }
247 
248 
249 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Nonlin_Schur_Divide ) {
251  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 0, 0,1));
252  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
253  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
254  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
255  setup.rtol, setup.atol, out);
256  }
257 TEUCHOS_UNIT_TEST( Stokhos_DivisionOperator, GMRES_Nonlin_Schur_linearprec_Divide ) {
259  Teuchos::rcp(new Stokhos::GMRESDivisionExpansionStrategy<int,double,Stokhos::StandardStorage<int, double> >(setup.basis, setup.Cijk, 0, 1e-12, 4, 100, 1, 0,1));
260  gmres_division_strategy->divide(setup.u, 1.0, setup.c1, setup.cu, 0.0);
261  setup.direct_division_strategy->divide(setup.u2, 1.0, setup.c1, setup.cu, 0.0);
262  success = Stokhos::comparePCEs(setup.u, "u", setup.u2, "u2",
263  setup.rtol, setup.atol, out);
264  }
265 
266 
267 
268 
269 
270 }
271 int main( int argc, char* argv[] ) {
272  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
274 }
275 
276 
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > cu
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > cu2
Strategy interface for computing PCE of a/b using only b[0].
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > c1
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeLinearTripleProductTensor() const
Compute linear triple product tensor where k = 0,1,..,d.
Teuchos::RCP< const Stokhos::CompletePolynomialBasis< OrdinalType, ValueType > > basis
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > sx
void exp(OrthogPolyApprox< ordinal_type, value_type, node_type > &c, const OrthogPolyApprox< ordinal_type, value_type, node_type > &a)
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > su2
bool comparePCEs(const PCEType &a1, const std::string &a1_name, const Stokhos::OrthogPolyApprox< OrdinalType, ValueType > &a2, const std::string &a2_name, const ValueType &rel_tol, const ValueType &abs_tol, Teuchos::FancyOStream &out)
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > u
Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > > qexp
Teuchos::RCP< const Stokhos::Quadrature< OrdinalType, ValueType > > quad
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > su
TEUCHOS_UNIT_TEST(Stokhos_DivisionOperator, CG_Divide)
Teuchos::RCP< Stokhos::DenseDirectDivisionExpansionStrategy< int, double, Stokhos::StandardStorage< int, double > > > direct_division_strategy
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > x
static int runUnitTestsFromMain(int argc, char *argv[])
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > &new_basis, ordinal_type sz=0)
Reset to a new basis.
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > y
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > cx
Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > > exp
virtual Teuchos::RCP< Stokhos::Sparse3Tensor< ordinal_type, value_type > > computeTripleProductTensor() const
Compute triple product tensor.
Teuchos::RCP< Stokhos::Sparse3Tensor< int, double > > Cijk_linear
Strategy interface for computing PCE of a/b using only b[0].
int main(int argc, char **argv)
Teuchos::RCP< Stokhos::Sparse3Tensor< int, double > > Cijk
Strategy interface for computing PCE of a/b using only b[0].
Defines quadrature for a tensor product basis by tensor products of 1-D quadrature rules...
Teuchos::RCP< Stokhos::QuadOrthogPolyExpansion< OrdinalType, ValueType > > exp_linear
Stokhos::OrthogPolyApprox< OrdinalType, ValueType > u2
reference term(ordinal_type dimension, ordinal_type order)
Get coefficient term for given dimension and order.