Exemple #1
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderSparse3LTO ) {
    success = true;
    ordinal_type dim = setup.d;
    ordinal_type order = setup.p;
    // ordinal_type dim = 2;
    // ordinal_type order = 3;

    // 1-D bases
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(dim);
    for (ordinal_type i=0; i<dim; i++)
      bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(order, true));

    // Product basis
    typedef Stokhos::MultiIndex<ordinal_type> coeff_type;
    typedef Stokhos::LexographicLess<coeff_type> less_type;
    Stokhos::TotalOrderBasis<ordinal_type,value_type,less_type> basis(
      bases);

    // Build Cijk tensor
    typedef Stokhos::Sparse3Tensor<ordinal_type,value_type> Cijk_type;
    Teuchos::RCP<Cijk_type> Cijk =
      Stokhos::computeTripleProductTensorLTO(basis, true);

    // Build Cijk tensor using original approach
    Teuchos::RCP<Cijk_type> Cijk2 =
      basis.computeTripleProductTensor();
    
    // Check sizes
    TEUCHOS_TEST_EQUALITY(Cijk->num_k(), Cijk2->num_k(), out, success);
    TEUCHOS_TEST_EQUALITY(Cijk->num_entries(), Cijk2->num_entries(), out, success);
    
    // Check tensors match
    for (Cijk_type::k_iterator k_it=Cijk2->k_begin(); 
	 k_it!=Cijk2->k_end(); ++k_it) {
      int k = Stokhos::index(k_it);
      for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it); 
	   j_it != Cijk2->j_end(k_it); ++j_it) {
	int j = Stokhos::index(j_it);
	for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it);
	     i_it != Cijk2->i_end(j_it); ++i_it) {
	  int i = Stokhos::index(i_it);
	  double c = Cijk->getValue(i,j,k);
	  double c2 = Stokhos::value(i_it);
	  double tol = setup.atol + c2*setup.rtol;
	  double err = std::abs(c-c2);
	  bool s = err < tol;
	  if (!s) {
	    out << std::endl
		<< "Check: rel_err( C(" << i << "," << j << "," << k << ") )"
		<< " = " << "rel_err( " << c << ", " << c2 << " ) = " << err 
		<< " <= " << tol << " : ";
	    if (s) out << "Passed.";
	    else out << "Failed!";
	    out << std::endl;
	  }
	  success = success && s;
	}
      }
    }
  }
TEUCHOS_UNIT_TEST(MatrixTraits, FillableMat_1)
{
  fei::FillableMat fm;

  fm.putCoef(0, 0, 0.0);
  fm.putCoef(1, 1, 1.1);
  fm.putCoef(1, 2, 1.2);
  fm.putCoef(2, 2, 2.2);

  int numRows = 0;
  fei::MatrixTraits<fei::FillableMat>::getNumLocalRows(&fm, numRows);
  TEUCHOS_TEST_EQUALITY(numRows, 3, out, success);

  std::vector<int> indices1(2);
  std::vector<double> coefs1(2);

  fei::MatrixTraits<fei::FillableMat>::copyOutRow(&fm, 1, 2, &coefs1[0], &indices1[0]);

  TEUCHOS_TEST_EQUALITY(indices1[0], 1, out, success);
  TEUCHOS_TEST_EQUALITY(indices1[1], 2, out, success);

  const double eps = std::numeric_limits<double>::epsilon();

  TEUCHOS_TEST_EQUALITY(std::abs(coefs1[0] - 1.1) < eps, true, out, success);
  TEUCHOS_TEST_EQUALITY(std::abs(coefs1[1] - 1.2) < eps, true, out, success);
}
Exemple #3
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderBasis ) {
    success = true;

    // Build index set of dimension d and order p
    typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type;
    typedef index_set_type::multiindex_type multiindex_type;
    typedef index_set_type::iterator iterator;
    index_set_type indexSet(setup.d, 0, setup.p);

    // Build total-order basis from index set
    typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type;
    typedef Stokhos::TotalOrderLess<coeff_type> less_type;
    typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
    typedef basis_set_type::iterator basis_set_iterator;
    typedef Teuchos::Array<coeff_type> basis_map_type;
    basis_set_type basis_set;
    basis_map_type basis_map;
    Stokhos::ProductBasisUtils::buildProductBasis(
      indexSet, basis_set, basis_map);

    // Build total-order basis directly
    ordinal_type sz;
    Teuchos::Array< Stokhos::MultiIndex<ordinal_type> > terms;
    Teuchos::Array<ordinal_type> num_terms;
    Stokhos::CompletePolynomialBasisUtils<ordinal_type,value_type>::
      compute_terms(setup.p, setup.d, sz, terms, num_terms);

    // Check sizes
    TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), 
			  static_cast<ordinal_type>(basis_map.size()), 
			  out, success);
    TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), 
			  static_cast<ordinal_type>(terms.size()), 
			  out, success);
    TEUCHOS_TEST_EQUALITY(sz, static_cast<ordinal_type>(terms.size()), 
			  out, success);

    std::ostream_iterator<ordinal_type> out_iterator(out, " ");
    for (ordinal_type i=0; i<sz; i++) {

      // Verify terms match
      out << "term " << basis_map[i] << " == " << terms[i] << " : ";
      bool is_equal = true;
      for (ordinal_type j=0; j<setup.d; j++)
	is_equal = is_equal && terms[i][j] == basis_map[i][j];
      if (is_equal)
	out << "passed" << std::endl;
      else {
	out << "failed" << std::endl;
	success = false; 
      }

      // Verify global index mapping matches
      TEUCHOS_TEST_EQUALITY(basis_set[basis_map[i]], i, out, success);
    }

  }
bool
checkVectorView(const ViewType& v,
                Teuchos::FancyOStream& out) {
  typedef ViewType view_type;
  typedef typename view_type::size_type size_type;
  typedef typename view_type::HostMirror host_view_type;
  typedef typename host_view_type::array_type host_array_type;
  typedef typename host_array_type::value_type scalar_type;

  // Copy to host
  host_view_type h_v = Kokkos::create_mirror_view(v);
  Kokkos::deep_copy(h_v, v);
  host_array_type h_a = h_v;

  size_type num_rows, num_cols;

  // For static, layout left, sacado dimension becomes first dimension
  // instead of last
  bool is_right = Kokkos::Impl::is_same< typename ViewType::array_layout,
                                         Kokkos::LayoutRight >::value;
  if (is_right) {
    num_rows = h_a.dimension_0();
    num_cols = h_a.dimension_1();
  }
  else {
    num_rows = h_a.dimension_1();
    num_cols = h_a.dimension_0();
  }
  bool success = true;
  if (is_right) {
    for (size_type i=0; i<num_rows; ++i) {
      for (size_type j=0; j<num_cols; ++j) {
        scalar_type val = h_a(i,j);
        scalar_type val_expected =
          generate_vector_coefficient<scalar_type>(
            num_rows, num_cols, i, j);
        TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
      }
    }
  }
  else {
    for (size_type i=0; i<num_rows; ++i) {
      for (size_type j=0; j<num_cols; ++j) {
        scalar_type val = h_a(j,i);
        scalar_type val_expected =
          generate_vector_coefficient<scalar_type>(
            num_rows, num_cols, i, j);
        TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
      }
    }
  }

  return success;
}
Exemple #5
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TensorProductBasis ) {
    success = true;

    // Build index set of dimension d and order p
    typedef Stokhos::TensorProductIndexSet<ordinal_type> index_set_type;
    typedef index_set_type::multiindex_type multiindex_type;
    typedef index_set_type::iterator iterator;
    index_set_type indexSet(setup.d, 0, setup.p);

    // Build total-order basis from index set
    typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type;
    typedef Stokhos::TotalOrderLess<coeff_type> less_type;
    typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
    typedef basis_set_type::iterator basis_set_iterator;
    typedef Teuchos::Array<coeff_type> basis_map_type;
    basis_set_type basis_set;
    basis_map_type basis_map;
    Stokhos::ProductBasisUtils::buildProductBasis(
      indexSet, basis_set, basis_map);

    // Compute expected size
    ordinal_type sz = 1;
    for (ordinal_type i=0; i<setup.d; ++i)
      sz *= setup.p+1;

    // Check sizes
    TEUCHOS_TEST_EQUALITY(static_cast<ordinal_type>(basis_set.size()), 
			  static_cast<ordinal_type>(basis_map.size()), 
			  out, success);
    TEUCHOS_TEST_EQUALITY(sz, static_cast<ordinal_type>(basis_set.size()), 
			  out, success);

    std::ostream_iterator<ordinal_type> out_iterator(out, " ");
    for (ordinal_type i=0; i<sz; i++) {

      // Verify terms match
      out << "term " << basis_map[i] << " <= " << setup.p << " : ";
      bool is_less = true;
      for (ordinal_type j=0; j<setup.d; j++)
	is_less = is_less && basis_map[i][j] <= setup.p;
      if (is_less)
	out << "passed" << std::endl;
      else {
	out << "failed" << std::endl;
	success = false; 
      }

      // Verify global index mapping matches
      TEUCHOS_TEST_EQUALITY(basis_set[basis_map[i]], i, out, success);
    }

  }
Exemple #6
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, LexographicFloatingPointLess ) {
    success = true;
    
    typedef Stokhos::TensorProductElement<ordinal_type,value_type> term_type;
    typedef Stokhos::FloatingPointLess<value_type> comp_type;
    term_type a(2), b(2);
    Stokhos::LexographicLess<term_type,comp_type> less;
    a[0] = -0.774597; a[1] = -0.774597;
    b[0] = -0.774597; b[1] = 0.0;

    TEUCHOS_TEST_EQUALITY(less(a,b), true, out, success);
    TEUCHOS_TEST_EQUALITY(less(b,a), false, out, success);
  }
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Traits, ScalarType, ad_type, scalar_type )
{
  const bool is_same =
    Sacado::mpl::is_same< typename Sacado::ScalarType<ad_type>::type, scalar_type >::value;

  TEUCHOS_TEST_EQUALITY(is_same, true, out, success);
}
bool
checkConstantVectorView(const ViewType& v,
                        const typename ViewType::value_type& v_expected,
                        Teuchos::FancyOStream& out) {
  typedef ViewType view_type;
  typedef typename view_type::size_type size_type;
  typedef typename view_type::HostMirror host_view_type;
  typedef typename host_view_type::array_type::value_type scalar_type;

  // Copy to host
  host_view_type h_v = Kokkos::create_mirror_view(v);
  Kokkos::deep_copy(h_v, v);

  const size_type num_rows = h_v.dimension_0();
  const size_type num_cols = Kokkos::dimension_scalar(h_v);
  bool success = true;
  for (size_type i=0; i<num_rows; ++i) {
    for (size_type j=0; j<num_cols; ++j) {
      scalar_type val = h_v(i).fastAccessCoeff(j);
      scalar_type val_expected = v_expected.fastAccessCoeff(j);
      TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
    }
  }

  return success;
}
//this macro declares the test-class:
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Ifpack2Group0, Ifpack2Test0, T)
{
//we are now in a class method declared by the above macro, and
//that method has these input arguments:
//Teuchos::FancyOStream& out, bool& success

  std::string version = Ifpack2::Version();
  bool empty_version = version.empty();
  TEUCHOS_TEST_EQUALITY(empty_version, false, out, success);

  T input = 5;
  T result = my_trivial_function(input);
  T expected_result = input*input;

  TEUCHOS_TEST_EQUALITY(result, expected_result, out, success);
}
Exemple #10
0
  TEUCHOS_UNIT_TEST( Coefficients, Anisotropic ) {
    success = true;

    // Build anisotropic total order basis of dimension d
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(setup.d);
    for (ordinal_type i=0; i<setup.d; i++)
      bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(i+1, true));
    Teuchos::RCP<const Stokhos::TotalOrderBasis<ordinal_type,value_type> > basis = Teuchos::rcp(new Stokhos::TotalOrderBasis<ordinal_type,value_type>(bases));

    // Compute expected size
    // Need to figure out how to do this
    ordinal_type sz = basis->size();

    // Check sizes
    TEUCHOS_TEST_EQUALITY(sz, basis->size(), out, success);

    std::ostream_iterator<ordinal_type> out_iterator(out, " ");
    for (ordinal_type i=0; i<sz; i++) {
      const Stokhos::MultiIndex<ordinal_type>& term = basis->term(i);

      // Verify terms match
      out << "term " << term << " <= " << setup.p << " : ";
      bool is_less = true;
      for (ordinal_type j=0; j<setup.d; j++)
        is_less = is_less && term[j] <= j+1;
      if (is_less)
        out << "passed" << std::endl;
      else {
        out << "failed" << std::endl;
        success = false;
      }

    }

  }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_View_MP, DeepCopy_Subview_Range, Storage )
{
  typedef typename Storage::execution_space Device;
  typedef typename Storage::value_type Scalar;
  typedef Sacado::MP::Vector<Storage> Vector;
  typedef typename ApplyView<Vector**,Kokkos::LayoutLeft,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;
  typedef typename ViewType::HostMirror host_view_type;

  const size_type num_rows1 = global_num_rows;
  const size_type num_rows2 = global_num_rows*2;
  const size_type num_cols = 5;
  const size_type num_vec =
    Storage::is_static ? Storage::static_size : global_num_cols;
  ViewType v1("view1", num_rows1, num_cols, num_vec);
  ViewType v2("view2", num_rows2, num_cols, num_vec);

  for (size_type j=0; j<num_cols; ++j) {
    std::pair<size_type,size_type> rows( 0, num_rows1 );
    ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (j,j+1) );
    ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (j,j+1) );
    Kokkos::deep_copy( v1s, Scalar(j+1) );
    Kokkos::deep_copy( v2s, v1s );
  }

  // Check
  success = true;
  host_view_type hv2 = Kokkos::create_mirror_view( v2 );
  Kokkos::deep_copy( hv2, v2 );
  for (size_type j=0; j<num_cols; ++j) {
    for (size_type i=0; i<num_rows1; ++i) {
      for (size_type k=0; k<num_vec; ++k) {
        Scalar val = hv2(i,j).fastAccessCoeff(k);
        Scalar val_expected = j+1;
        TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
      }
    }
    for (size_type i=num_rows1; i<num_rows2; ++i) {
      for (size_type k=0; k<num_vec; ++k) {
        Scalar val = hv2(i,j).fastAccessCoeff(k);
        Scalar val_expected = 0;
        TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
      }
    }
  }
}
bool checkFads(const FadType1& x, const FadType2& x2,
               Teuchos::FancyOStream& out, double tol = 1.0e-15)
{
  bool success = true;

  // Check sizes match
  TEUCHOS_TEST_EQUALITY(x.size(), x2.size(), out, success);

  // Check values match
  TEUCHOS_TEST_EQUALITY(x.val(), x2.val(), out, success);

  // Check derivatives match
  for (int i=0; i<x.size(); ++i)
    TEUCHOS_TEST_FLOATING_EQUALITY(x.dx(i), x2.dx(i), tol, out, success);

  return success;
}
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_SG_SpMv, SimpleTiledCrsProductTensorCijk, Scalar, Device ) {
  success = true;

  typedef Scalar value_type;
  typedef Stokhos::SimpleTiledCrsProductTensor< value_type , Device > tensor_type ;

  Teuchos::ParameterList params;
  params.set("Tile Size",10);

  tensor_type tensor =
    Stokhos::create_simple_tiled_product_tensor<Device>(
      *setup.basis, *setup.Cijk, params);

  int num_entry = 0;
  const size_t n_i_tile = tensor.num_i_tiles();
  for (size_t i_tile = 0; i_tile<n_i_tile; ++i_tile) {
    const size_t i_begin = tensor.i_begin(i_tile);
    const size_t i_size  = tensor.i_size(i_tile);

    const size_t n_j_tile = tensor.num_j_tiles(i_tile);
    for (size_t j_tile = 0; j_tile<n_j_tile; ++j_tile) {
      const size_t j_begin = tensor.j_begin(i_tile, j_tile);
      //const size_t j_size  = tensor.j_size(i_tile, j_tile);

      const size_t n_k_tile = tensor.num_k_tiles(i_tile, j_tile);
      for (size_t k_tile = 0; k_tile<n_k_tile; ++k_tile) {
        const size_t k_begin = tensor.k_begin(i_tile, j_tile, k_tile);
        //const size_t k_size  = tensor.k_size(i_tile, j_tile, k_tile);

        for (size_t i=0; i<i_size; ++i) {
          const size_t iEntryBeg = tensor.entry_begin(i_tile,j_tile,k_tile,i);
          const size_t iEntryEnd = tensor.entry_end(i_tile,j_tile,k_tile,i);
          for (size_t iEntry = iEntryBeg ; iEntry < iEntryEnd ; ++iEntry ) {
            const size_t j = tensor.coord(iEntry,0);
            const size_t k = tensor.coord(iEntry,1);
            value_type c2 = tensor.value(iEntry);
            int ii = i + i_begin;
            int jj = j + j_begin;
            int kk = k + k_begin;
            ++num_entry;
            if (jj == kk)
              c2 *= 2.0;
            else
              ++num_entry;
            value_type c = setup.Cijk->getValue(ii,jj,kk);

            if (std::abs(c-c2) > std::abs(c)*setup.rel_tol + setup.abs_tol) {
              out << "(" << ii << "," << jj << "," << kk << "):  " << c
                  << " == " << c2 << " failed!" << std::endl;
              success = false;
            }
          }
        }
      }
    }
  }
  TEUCHOS_TEST_EQUALITY( num_entry, setup.Cijk->num_entries(), out, success );
}
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(
  Kokkos_View_Fad, Subview, FadType, Layout, Device )
{
  typedef typename ApplyView<FadType**,Layout,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;
  typedef typename ViewType::HostMirror host_view_type;

  const size_type num_rows = global_num_rows;
  const size_type num_cols = global_num_cols;
  const size_type fad_size = global_fad_size;

  // Create and fill view
  ViewType v("view", num_rows, num_cols, fad_size+1);
  host_view_type h_v = Kokkos::create_mirror_view(v);
  for (size_type i=0; i<num_rows; ++i) {
    for (size_type j=0; j<num_cols; ++j) {
      FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
      h_v(i,j) = f;
    }
  }
  Kokkos::deep_copy(v, h_v);

  // Create subview of first column
  size_type col = 1;
  auto s = Kokkos::subview(v, Kokkos::ALL(), col);

  // Copy back
  typedef decltype(s) SubviewType;
  typedef typename SubviewType::HostMirror HostSubviewType;
  HostSubviewType h_s = Kokkos::create_mirror_view(s);
  Kokkos::deep_copy(h_s, s);

  // Check
  success = true;
#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
#endif
  for (size_type i=0; i<num_rows; ++i) {
    FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
    success = success && checkFads(f, h_s(i), out);
  }
}
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, Size, Storage, Layout )
{
  typedef typename Storage::execution_space Device;
  typedef Sacado::MP::Vector<Storage> Vector;
  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;

  const size_type num_rows = global_num_rows;
  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
  ViewType v("view", num_rows, num_cols);
  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
}
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(
  Kokkos_View_Fad, Size, FadType, Layout, Device )
{
  typedef typename ApplyView<FadType*,Layout,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;

  const size_type num_rows = global_num_rows;
  const size_type fad_size = global_fad_size;

  // Create and fill view
  ViewType v("view", num_rows, fad_size+1);
  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
}
TEUCHOS_UNIT_TEST(Pattern, Pattern_test1)
{
  int numIDs = 6;
  std::vector<int> idTypes(numIDs);
  std::vector<int> fieldsPerID(numIDs);
  std::vector<int> fieldIDs(3);
  std::vector<int> fieldSizes(3, 1);

  idTypes[0] = 0;
  idTypes[1] = 0;
  idTypes[2] = 0;
  idTypes[3] = 1;
  idTypes[4] = 1;
  idTypes[5] = 1;

  fieldsPerID[0] = 0;
  fieldsPerID[1] = 0;
  fieldsPerID[2] = 0;
  fieldsPerID[3] = 1;
  fieldsPerID[4] = 1;
  fieldsPerID[5] = 1;

  fieldIDs[0] = 0;
  fieldIDs[1] = 0;
  fieldIDs[2] = 0;

  fei::Pattern pattern1(numIDs, 0, &fieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);

  TEUCHOS_TEST_EQUALITY(pattern1.getTotalNumFields(), 3, out, success);
  TEUCHOS_TEST_EQUALITY(pattern1.getNumIndices(), 3, out, success);

  fei::Pattern pattern2(numIDs, &idTypes[0], &fieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);

  TEUCHOS_TEST_EQUALITY(pattern2.getTotalNumFields(), 3, out, success);
  TEUCHOS_TEST_EQUALITY(pattern2.getNumIndices(), 3, out, success);
}
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(
  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device )
{
  typedef typename ApplyView<FadType**,Layout,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;
  typedef typename ViewType::HostMirror host_view_type;

  const size_type num_rows = global_num_rows;
  const size_type num_cols = global_num_cols;
  const size_type fad_size = global_fad_size;

  // Create and fill view
  ViewType v("view", num_rows, num_cols);
  host_view_type h_v = Kokkos::create_mirror_view(v);
  for (size_type i=0; i<num_rows; ++i) {
    for (size_type j=0; j<num_cols; ++j) {
      FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
      h_v(i,j) = f;
    }
  }
  Kokkos::deep_copy(v, h_v);

  // Copy back
  Kokkos::deep_copy(h_v, v);

  // Check
  success = true;
  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v), fad_size+1, out, success);
  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v), fad_size+1, out, success);
  for (size_type i=0; i<num_rows; ++i) {
    for (size_type j=0; j<num_cols; ++j) {
      FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
      success = success && checkFads(f, h_v(i,j), out);
    }
  }
}
Exemple #19
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, FloatingPointLess ) {
    success = true;

    value_type tol=1e-12;
    Stokhos::FloatingPointLess<value_type> less(tol);

    TEUCHOS_TEST_EQUALITY(less(-0.774597,-0.774597), false, out, success);
    TEUCHOS_TEST_EQUALITY(less(-0.774597+tol/2.0,-0.774597), false, out, success);
    TEUCHOS_TEST_EQUALITY(less(-0.774597-tol/2.0,-0.774597), false, out, success);
    TEUCHOS_TEST_EQUALITY(less(-0.774597,-0.774597+tol/2.0), false, out, success);
    TEUCHOS_TEST_EQUALITY(less(-0.774597,-0.774597-tol/2.0), false, out, success);
    TEUCHOS_TEST_EQUALITY(less(-0.774597,0.0), true, out, success);
    TEUCHOS_TEST_EQUALITY(less(0.0,-0.774597), false, out, success);
  }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(
  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
{
  typedef typename ApplyView<FadType**,Layout,Device>::type ViewType;
  typedef typename ViewType::size_type size_type;

  const size_type num_rows = global_num_rows;
  const size_type num_cols = global_num_cols;

  // Compute shared memory size for View
  const size_type shmem_size =
    ViewType::shmem_size(num_rows, num_cols);

  // Check
  static const size_type align = 8;
  static const size_type mask  = align - 1;
  const size_type shmem_size_expected =
    ( sizeof(FadType) * global_num_rows * global_num_cols + mask ) & ~mask;
  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
}
Exemple #21
0
 TEUCHOS_UNIT_TEST( Stokhos_NormalizedHermiteBasis, Size ) {
   int size = setup.basis.size();
   TEUCHOS_TEST_EQUALITY(size, setup.p+1, out, success);
 }
Exemple #22
0
 TEUCHOS_UNIT_TEST( Stokhos_NormalizedHermiteBasis, Order ) {
   int order = setup.basis.order();
   TEUCHOS_TEST_EQUALITY(order, setup.p, out, success);
 }
Exemple #23
0
  TEUCHOS_UNIT_TEST( Stokhos_ProductBasisUtils, TotalOrderSparse3TensorNew ) {
    success = true;
    // ordinal_type dim = setup.d;
    // ordinal_type order = setup.p;
    ordinal_type dim = 2;
    ordinal_type order = 3;

    // Build index set of dimension d and order p
    typedef Stokhos::TotalOrderIndexSet<ordinal_type> index_set_type;
    typedef index_set_type::multiindex_type multiindex_type;
    typedef index_set_type::iterator iterator;
    index_set_type indexSet(dim, 0, order);

    // Build total-order basis from index set
    typedef Stokhos::TensorProductElement<ordinal_type,ordinal_type> coeff_type;
    typedef Stokhos::TotalOrderLess<coeff_type> less_type;
    typedef std::map<coeff_type, ordinal_type, less_type> basis_set_type;
    typedef basis_set_type::iterator basis_set_iterator;
    typedef Teuchos::Array<coeff_type> basis_map_type;
    basis_set_type basis_set;
    basis_map_type basis_map;
    Stokhos::ProductBasisUtils::buildProductBasis(
      indexSet, basis_set, basis_map);

    // 1-D bases
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(dim);
    for (ordinal_type i=0; i<dim; i++)
      bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(order, true));

    // Build Cijk tensor
    typedef Stokhos::Sparse3Tensor<ordinal_type,value_type> Cijk_type;
    total_order_predicate<ordinal_type> pred(dim, order);
    //general_predicate<basis_set_type> pred(basis_set);
    Teuchos::RCP<Cijk_type> Cijk =
      Stokhos::ProductBasisUtils::computeTripleProductTensorNew<ordinal_type,value_type>(bases, basis_set, basis_map, pred, pred, false);

    // Build Cijk tensor using original approach
    Teuchos::RCP<const Stokhos::CompletePolynomialBasis<ordinal_type,value_type> > basis = Teuchos::rcp(new Stokhos::CompletePolynomialBasis<ordinal_type,value_type>(bases));
    Teuchos::RCP<Cijk_type> Cijk2 =
      basis->computeTripleProductTensor();
    
    // Check sizes
    TEUCHOS_TEST_EQUALITY(Cijk->num_k(), Cijk2->num_k(), out, success);
    TEUCHOS_TEST_EQUALITY(Cijk->num_entries(), Cijk2->num_entries(), out, success);
    
    // Check tensors match
    for (Cijk_type::k_iterator k_it=Cijk2->k_begin(); 
	 k_it!=Cijk2->k_end(); ++k_it) {
      int k = Stokhos::index(k_it);
      for (Cijk_type::kj_iterator j_it = Cijk2->j_begin(k_it); 
	   j_it != Cijk2->j_end(k_it); ++j_it) {
	int j = Stokhos::index(j_it);
	for (Cijk_type::kji_iterator i_it = Cijk2->i_begin(j_it);
	     i_it != Cijk2->i_end(j_it); ++i_it) {
	  int i = Stokhos::index(i_it);
	  double c = Cijk->getValue(i,j,k);
	  double c2 = Stokhos::value(i_it);
	  double tol = setup.atol + c2*setup.rtol;
	  double err = std::abs(c-c2);
	  bool s = err < tol;
	  if (!s) {
	    out << std::endl
		<< "Check: rel_err( C(" << i << "," << j << "," << k << ") )"
		<< " = " << "rel_err( " << c << ", " << c2 << " ) = " << err 
		<< " <= " << tol << " : ";
	    if (s) out << "Passed.";
	    else out << "Failed!";
	    out << std::endl;
	  }
	  success = success && s;
	}
      }
    }
  }
TEUCHOS_UNIT_TEST(MatGraph, MatGraph_test1)
{
  int numprocs = fei::numProcs(MPI_COMM_WORLD);
  if (numprocs > 1) return;

  //two id-types: 0, 1:
  int idT[] = {0, 1};
  snl_fei::RecordCollection* recColls[] = {NULL,NULL};

  //set up a pattern for an element that has 6 ids: 3 nodes and 3 edges.
  const int numIDs = 6;

  //assume 0 is the node-type and 1 is the edge-type:
  int idTypes[] = {0, 0, 0, 1, 1, 1};

  //for the first pattern, only the edge ids will have a field attached:
  int fieldsPerID[] = {0, 0, 0, 1, 1, 1};

  int fieldID = 0;
  int fieldSize = 1;

  int fieldIDs[] = {fieldID, fieldID, fieldID};
  int fieldSizes[] = {fieldSize, fieldSize, fieldSize};

  fei::Pattern pattern1(numIDs, &idTypes[0], &recColls[0], &fieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);

  //declare a vector-space, do some rudimentary initializations:

  fei::SharedPtr<fei::VectorSpace> rowspace(new fei::VectorSpace(MPI_COMM_WORLD));
  rowspace->defineIDTypes(2, &idT[0]);
  rowspace->defineFields(1, &fieldID, &fieldSize);

  fei::SharedPtr<fei::VectorSpace> colspace;

  //declare a matrix-graph:
  fei::MatrixGraph_Impl2 mgraph(rowspace, colspace);

  int patternID1 = mgraph.definePattern(numIDs, &idTypes[0], &fieldsPerID[0], &fieldIDs[0]);

  //unit-test: make sure the matrix-graph's pattern is the same as our
  //explicitly-declared pattern:
  fei::Pattern* pttn1 = mgraph.getPattern(patternID1);

  TEUCHOS_TEST_EQUALITY(pattern1 == *pttn1, true, out, success);

  //now declare a second pattern which is the same except now fields are
  //attached to nodes instead of edges:
  fieldsPerID[0] = 1; fieldsPerID[1] = 1; fieldsPerID[2] = 1;
  fieldsPerID[3] = 0; fieldsPerID[4] = 0; fieldsPerID[5] = 0;

  fei::Pattern pattern2(numIDs, &idTypes[0], &recColls[0], &fieldsPerID[0], &fieldIDs[0], &fieldSizes[0]);

  int patternID2 = mgraph.definePattern(numIDs, &idTypes[0], &fieldsPerID[0], &fieldIDs[0]);
  fei::Pattern* pttn2 = mgraph.getPattern(patternID2);
  TEUCHOS_TEST_EQUALITY(pattern2 == *pttn2, true, out, success);

  //declare two element-blocks, one for each pattern. each element block will have
  //just one element:
  mgraph.initConnectivityBlock(0, 1, patternID1);
  mgraph.initConnectivityBlock(1, 1, patternID2);

//Two-element mesh, each element has 3 vertex-nodes, and 3 edges:
/*
   0      1
   o---4--o
    \     | \
     \    |  \
      5   6   7
       \  |    \
        \ |     \
          o---8--o
          2      3
*/

  //the first element has nodes 0, 1, 2 and edges 4, 5, 6:
  int ids0[] = {0, 1, 2, 4, 5, 6};

  mgraph.initConnectivity(0, 0, &ids0[0]);

  //the second element has nodes 1, 2, 3 and edges 6, 7, 8:
  int ids1[] = {1, 2, 3, 6, 7, 8};

  mgraph.initConnectivity(1, 0, &ids1[0]);

  mgraph.initComplete();

  fei::SharedPtr<fei::SparseRowGraph> srg = mgraph.createGraph(false);

//The way we set things up, the graph should have 6 rows,
//with 3 nonzeros per row:

  TEUCHOS_TEST_EQUALITY(srg->rowNumbers.size(), 6, out, success);
  TEUCHOS_TEST_EQUALITY(srg->packedColumnIndices.size(), 18, out, success);
}
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Traits, ScalarValue, ad_type, scalar_type )
{
  scalar_type v(1.0);
  ad_type a(v);
  TEUCHOS_TEST_EQUALITY(Sacado::ScalarValue<ad_type>::eval(a), v, out, success);
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Traits, IsScalarType, ad_type )
{
  const bool is_scalar = Sacado::IsScalarType<ad_type>::value;
  TEUCHOS_TEST_EQUALITY(is_scalar, false, out, success);
}
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Traits, IsADType, ad_type )
{
  const bool is_ad = Sacado::IsADType<ad_type>::value;
  TEUCHOS_TEST_EQUALITY(is_ad, true, out, success);
}
Exemple #28
0
TEUCHOS_UNIT_TEST(DirBC, DirBCManager_finalizeBCEqns)
{
  MPI_Comm comm = MPI_COMM_WORLD;

  int numProcs = 1;
#ifndef FEI_SER
  MPI_Comm_size(comm, &numProcs);
#endif

  if (numProcs > 1) {
    FEI_COUT << "skipping test of fei::DirichletBCManager::finalizeBCEqn, which only"
     << " runs on 1 proc." << FEI_ENDL;
    return;
  }

  int idtype = 0;
  int fieldID = 0;
  int fieldSize = 2;
  int offsetIntoField = 1;
  std::vector<int> ids(5);
  std::vector<double> vals(5);

  ids[0] = 2; vals[0] = 2.0;
  ids[1] = 1; vals[1] = 1.0;
  ids[2] = 3; vals[2] = 3.0;
  ids[3] = 4; vals[3] = 4.0;
  ids[4] = 0; vals[4] = 0.0;


  fei::SharedPtr<fei::VectorSpace> vspace(new fei::VectorSpace(comm));

  vspace->defineFields(1, &fieldID, &fieldSize);
  vspace->defineIDTypes(1, &idtype);

  fei::SharedPtr<fei::MatrixGraph> mgraph(new fei::MatrixGraph_Impl2(vspace, vspace));

  int numIDs = 1;

  int patternID = mgraph->definePattern(numIDs, idtype);

  int blockID = 0;

  mgraph->initConnectivityBlock(blockID, ids.size(), patternID);

  for(size_t i = 0; i<ids.size(); ++i) {
    mgraph->initConnectivity(blockID, i, &ids[i]);
  }

  mgraph->initComplete();


  fei::DirichletBCManager bcmgr(mgraph->getRowSpace());

  bcmgr.addBCRecords(5, idtype, fieldID, offsetIntoField,
                     &ids[0], &vals[0]);
 
  fei::SharedPtr<fei::FillableMat> inner(new fei::FillableMat);
  fei::SharedPtr<fei::Matrix_Impl<fei::FillableMat> > feimat(new fei::Matrix_Impl<fei::FillableMat>(inner, mgraph, ids.size()));

  TEUCHOS_TEST_EQUALITY(bcmgr.finalizeBCEqns(*feimat, false), 0, out, success);

  TEUCHOS_TEST_EQUALITY(feimat->getGlobalNumRows(), feimat->getLocalNumRows(),out,success);
  TEUCHOS_TEST_EQUALITY(feimat->getGlobalNumRows(), (int)ids.size(), out, success);
}
 TEUCHOS_UNIT_TEST( Stokhos_LegendreBasis, Size ) {
   int size = setup.basis.size();
   TEUCHOS_TEST_EQUALITY(size, setup.p+1, out, success);
 }
 TEUCHOS_UNIT_TEST( Stokhos_LegendreBasis, Order ) {
   int order = setup.basis.order();
   TEUCHOS_TEST_EQUALITY(order, setup.p, out, success);
 }