diff --git a/include/pressio/ops.hpp b/include/pressio/ops.hpp index 03b9317..0e55e91 100644 --- a/include/pressio/ops.hpp +++ b/include/pressio/ops.hpp @@ -158,6 +158,27 @@ template struct matching_extents; #include "ops/tpetra_block/ops_multi_vector_update.hpp" #include "ops/tpetra_block/ops_level2.hpp" #include "ops/tpetra_block/ops_level3.hpp" + +#ifdef PRESSIO_ENABLE_EPETRA +// Epetra +#include "ops/epetra/ops_clone.hpp" +#include "ops/epetra/ops_extent.hpp" +#include "ops/epetra/ops_deep_copy.hpp" +#include "ops/epetra/ops_set_zero.hpp" +#include "ops/epetra/ops_scale.hpp" +#include "ops/epetra/ops_fill.hpp" +#include "ops/epetra/ops_abs.hpp" +#include "ops/epetra/ops_dot.hpp" +#include "ops/epetra/ops_min_max.hpp" +#include "ops/epetra/ops_norms.hpp" +#include "ops/epetra/ops_pow.hpp" +#include "ops/epetra/ops_rank1_update.hpp" +#include "ops/epetra/ops_elementwise_multiply.hpp" +#include "ops/epetra/ops_multi_vector_update.hpp" +#include "ops/epetra/ops_level2.hpp" +#include "ops/epetra/ops_level3.hpp" +#endif // PRESSIO_ENABLE_EPETRA + #endif //PRESSIO_ENABLE_TPL_TRILINOS // keep this last diff --git a/include/pressio/ops/epetra/ops_abs.hpp b/include/pressio/ops/epetra/ops_abs.hpp new file mode 100644 index 0000000..311ae76 --- /dev/null +++ b/include/pressio/ops/epetra/ops_abs.hpp @@ -0,0 +1,68 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_abs.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_ABS_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_ABS_HPP_ + +namespace pressio{ namespace ops{ + +// y= abs(x) +template +std::enable_if_t< + ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + > +abs(T1 & y, const T2 & x) +{ + assert(::pressio::ops::extent(y, 0) == ::pressio::ops::extent(x, 0)); + + y.Abs(x); +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_ABS_HPP_ diff --git a/include/pressio/ops/epetra/ops_clone.hpp b/include/pressio/ops/epetra/ops_clone.hpp new file mode 100644 index 0000000..84d3694 --- /dev/null +++ b/include/pressio/ops/epetra/ops_clone.hpp @@ -0,0 +1,65 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_clone.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_CLONE_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_CLONE_HPP_ + +namespace pressio{ namespace ops{ + + +template +std::enable_if_t< + (::pressio::is_vector_epetra::value + || ::pressio::is_multi_vector_epetra::value), T> +clone(const T & clonable) +{ + return T(clonable); +} + +}} +#endif // PRESSIOOPS_OPS_EPETRA_OPS_CLONE_HPP_ diff --git a/include/pressio/ops/epetra/ops_deep_copy.hpp b/include/pressio/ops/epetra/ops_deep_copy.hpp new file mode 100644 index 0000000..4b4cddb --- /dev/null +++ b/include/pressio/ops/epetra/ops_deep_copy.hpp @@ -0,0 +1,66 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_deep_copy.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_DEEP_COPY_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_DEEP_COPY_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + // TPL/container specific + ::pressio::is_vector_epetra::value or + ::pressio::is_multi_vector_epetra::value + > +deep_copy(T & dest, const T & src){ + assert((matching_extents::compare(dest, src))); + dest = src; +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_DEEP_COPY_HPP_ diff --git a/include/pressio/ops/epetra/ops_dot.hpp b/include/pressio/ops/epetra/ops_dot.hpp new file mode 100644 index 0000000..6171953 --- /dev/null +++ b/include/pressio/ops/epetra/ops_dot.hpp @@ -0,0 +1,98 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_dot.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_DOT_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_DOT_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + // TPL/container specific + ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible< + typename ::pressio::Traits::scalar_type, + DotResult>::value + > +dot(const T1 & a, + const T2 & b, + DotResult & result) +{ + assert(a.MyLength() == b.MyLength()); + using sc_t = typename ::pressio::Traits::scalar_type; + sc_t ret; + a.Dot(b, &ret); + result = static_cast(ret); +} + +template +std::enable_if_t< + // TPL/container specific + ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value), + typename ::pressio::Traits::scalar_type + > +dot(const T1 & a, const T2 & b) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + sc_t result = {}; + dot(a, b, result); + return result; +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_DOT_HPP_ diff --git a/include/pressio/ops/epetra/ops_elementwise_multiply.hpp b/include/pressio/ops/epetra/ops_elementwise_multiply.hpp new file mode 100644 index 0000000..e5eae78 --- /dev/null +++ b/include/pressio/ops/epetra/ops_elementwise_multiply.hpp @@ -0,0 +1,85 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_elementwise_multiply.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_ELEMENTWISE_MULTIPLY_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_ELEMENTWISE_MULTIPLY_HPP_ + +namespace pressio{ namespace ops{ + +//---------------------------------------------------------------------- +// computing elementwise: y = beta * y + alpha * x * z +//---------------------------------------------------------------------- +template +std::enable_if_t< + // common elementwise_multiply constraints + ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && std::is_convertible::value + && std::is_convertible::value + > +elementwise_multiply(alpha_t alpha, const T & x, const T1 & z, beta_t beta, T2 & y) +{ + assert(x.MyLength()==z.MyLength()); + assert(z.MyLength()==y.MyLength()); + + const double alpha_(alpha); + const double beta_(beta); + const auto has_beta = beta_ != 0.0; + for (int i=0; i +std::enable_if_t< + ::pressio::is_vector_epetra::value, std::size_t> +extent(const T & oIn, const IndexType i) +{ + return (i == 0) ? std::size_t(oIn.GlobalLength()) : std::size_t(1); +} + +template +std::enable_if_t< + ::pressio::is_multi_vector_epetra::value, std::size_t > +extent(const T & oIn, const IndexType i) +{ + if (i == 0) { + return std::size_t(oIn.GlobalLength()); + } + else if (i == 1) { + return std::size_t(oIn.NumVectors()); + } + else { + return std::size_t(1); + } +} + +}} +#endif // PRESSIOOPS_OPS_EPETRA_OPS_EXTENT_HPP_ diff --git a/include/pressio/ops/epetra/ops_fill.hpp b/include/pressio/ops/epetra/ops_fill.hpp new file mode 100644 index 0000000..5529a59 --- /dev/null +++ b/include/pressio/ops/epetra/ops_fill.hpp @@ -0,0 +1,67 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_fill.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_FILL_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_FILL_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + (::pressio::is_vector_epetra::value || + ::pressio::is_multi_vector_epetra::value) + && std::is_convertible::scalar_type>::value + > +fill(T & o, const ScalarType & value) +{ + const typename ::pressio::Traits::scalar_type v(value); + impl::get_native(o).PutScalar(v); +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_FILL_HPP_ diff --git a/include/pressio/ops/epetra/ops_level2.hpp b/include/pressio/ops/epetra/ops_level2.hpp new file mode 100644 index 0000000..438bbab --- /dev/null +++ b/include/pressio/ops/epetra/ops_level2.hpp @@ -0,0 +1,338 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_level2.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_LEVEL2_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_LEVEL2_HPP_ + +namespace pressio{ namespace ops{ + +/* + * y = beta * y + alpha*op(A)*x +*/ + +// begin namespace pressio::ops::impl +namespace impl{ + +template +void _product_epetra_mv_sharedmem_vec(const scalar_type alpha, + const A_type & A, + const x_type & x, + const scalar_type beta, + Epetra_Vector & y) +{ + ::pressio::ops::scale(y, beta); + if (alpha == static_cast(0)) { + return; + } + + const int numVecs = A.NumVectors(); + for (int i=0; i< A.MyLength(); i++) + { + for (int j=0; j< (int)numVecs; j++){ + y[i] += alpha * A[j][i] * x(j); + } + } +} +}//end namespace pressio::ops::impl + +// ------------------------------- +// y = beta * y + alpha*A*x +// +// y : epetra vector +// A : epetra MultiVector +// x : Teuchos Vector +// ------------------------------- +template < + typename alpha_t, + typename A_type, + typename x_type, + typename y_type, + typename beta_t + > +std::enable_if_t< + // level2 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_dense_vector_teuchos::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + > +product(::pressio::nontranspose /*unused*/, + const alpha_t alpha, + const A_type & A, + const x_type & x, + const beta_t beta, + y_type & y) +{ + ::pressio::ops::impl::_product_epetra_mv_sharedmem_vec(alpha, A, x, beta, y); +} + +// ------------------------------- +// y = beta * y + alpha*A^T*x +// +// y : Teuchos vector +// A : epetra MultiVector +// x : epetra Vector +// ------------------------------- +template < + typename alpha_t, + typename A_type, + typename x_type, + typename y_type, + typename beta_t + > +std::enable_if_t< + // level2 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_dense_vector_teuchos::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + > +product(::pressio::transpose /*unused*/, + const alpha_t alpha, + const A_type & A, + const x_type & x, + const beta_t beta, + y_type & y) +{ + + const int numVecs = A.NumVectors(); + assert( (std::size_t)y.length() == (std::size_t)numVecs ); + + using sc_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + auto tmp = zero; + for (int i=0; iDot(x, &tmp); + y(i) += alpha * tmp; + } + } +} + +#ifdef PRESSIO_ENABLE_TPL_EIGEN +// ------------------------------- +// y = beta * y + alpha*A*x +// +// y : epetra vector +// A : epetra MultiVector +// x : eigen Vector +// ------------------------------- +template < + typename alpha_t, + typename A_type, + typename x_type, + typename y_type, + typename beta_t + > +std::enable_if_t< + // level2 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && (::pressio::is_vector_eigen::value + || ::pressio::is_expression_acting_on_eigen::value) + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + > +product(::pressio::nontranspose /*unused*/, + const alpha_t alpha, + const A_type & A, + const x_type & x, + const beta_t beta, + y_type & y) +{ + ::pressio::ops::impl::_product_epetra_mv_sharedmem_vec(alpha, A, x, beta, y); +} + +// ------------------------------- +// y = beta * y + alpha*A^T*x +// +// y : eigen vector +// A : epetra MultiVector +// x : epetra Vector +// ------------------------------- +template < + typename alpha_t, + typename A_type, + typename x_type, + typename y_type, + typename beta_t + > +std::enable_if_t< + // level2 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_vector_epetra::value + && (::pressio::is_vector_eigen::value + || ::pressio::is_expression_acting_on_eigen::value) + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + > +product(::pressio::transpose /*unused*/, + const alpha_t alpha, + const A_type & A, + const x_type & x, + const beta_t beta, + y_type & y) +{ + + const int numVecs = A.NumVectors(); + assert( (std::size_t)::pressio::ops::extent(y, 0) == (std::size_t)numVecs ); + + using sc_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + auto tmp = zero; + for (int i=0; iDot(x, &tmp); + y(i) += alpha * tmp; + } + } +} +#endif + + +// #ifdef PRESSIO_ENABLE_TPL_EIGEN +// /* ------------------------------------------------------------------- +// * y = beta * y + alpha*A*x +// * x is a eigen +// * A = Eigen::MultiVector +// * y = Epetra Vector +// * this covers the case where the matrix A acts locally to x +// while y is distributed, so A*x only fills the corresponding part of y +// *-------------------------------------------------------------------*/ +// template < typename A_type, typename x_type, typename scalar_type> +// std::enable_if_t< +// ::pressio::containers::predicates::is_multi_vector_wrapper_eigen::value and +// ::pressio::containers::predicates::is_vector_wrapper_eigen::value +// > +// product(::pressio::nontranspose mode, +// const scalar_type alpha, +// const A_type & A, +// const x_type & x, +// const scalar_type beta, +// ::pressio::containers::Vector & y) +// { +// static_assert +// (std::is_same< +// scalar_type, typename ::pressio::containers::details::traits::scalar_t>::value, +// "Scalar compatibility broken"); + +// using eig_mapping_t = Eigen::Map< Eigen::Matrix >; +// eig_mapping_t yMapped(y.data()->Values(), y.extentLocal(0), 1); +// const auto & AE = *A.data(); +// const auto & xE = *x.data(); +// yMapped = beta * yMapped + alpha * AE * xE; +// } +// #endif + +// #ifdef PRESSIO_ENABLE_TPL_EIGEN +// /* ------------------------------------------------------------------- +// * y = beta * y + alpha*A^T*x +// * x is a distributed Epetra vector wrapper +// * A is an Eigen MV +// * y is vector wrapper Eigen +// *-------------------------------------------------------------------*/ +// template +// std::enable_if_t< +// ::pressio::containers::predicates::is_multi_vector_wrapper_eigen::value and +// ::pressio::containers::predicates::is_vector_wrapper_eigen::value +// > +// product(::pressio::transpose mode, +// const scalar_type alpha, +// const A_type & A, +// const ::pressio::containers::Vector & x, +// const scalar_type beta, +// y_type & y) +// { +// using eig_mapping_t = const Eigen::Map< const Eigen::Matrix >; +// eig_mapping_t xMapped(x.data()->Values(), x.extentLocal(0), 1); +// const auto & AE = *A.data(); +// auto & yE = *y.data(); +// yE = beta * yE + alpha * AE.transpose() * xMapped; +// } +// #endif + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_LEVEL2_HPP_ diff --git a/include/pressio/ops/epetra/ops_level3.hpp b/include/pressio/ops/epetra/ops_level3.hpp new file mode 100644 index 0000000..23b7cbd --- /dev/null +++ b/include/pressio/ops/epetra/ops_level3.hpp @@ -0,0 +1,255 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_level3.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_LEVEL3_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_LEVEL3_HPP_ + +namespace pressio{ namespace ops{ + +/* + * C = beta * C + alpha*op(A)*op(B) +*/ + + +/* ------------------------------------------------------------------- +C = beta * C + alpha * A^T * B +A = epetra multivector +B = epetra multivector +C is an Eigen dense matrix +*-------------------------------------------------------------------*/ +template < + typename A_type, typename B_type, typename alpha_type, typename beta_type, typename C_type + > +std::enable_if_t< + // level3 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_dense_matrix_eigen::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +product(::pressio::transpose /*unused*/, + ::pressio::nontranspose /*unused*/, + const alpha_type alpha, + const A_type & A, + const B_type & B, + const beta_type beta, + C_type & C) +{ + + const auto numVecsA = A.NumVectors(); + const auto numVecsB = B.NumVectors(); + assert( (std::size_t)::pressio::ops::extent(A,0) == (std::size_t)::pressio::ops::extent(B,0)); + assert( (std::size_t)::pressio::ops::extent(C,0) == (std::size_t)numVecsA ); + assert( (std::size_t)::pressio::ops::extent(C,1) == (std::size_t)numVecsB ); + + using sc_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + const sc_t alpha_(alpha); + const sc_t beta_(beta); + auto tmp = zero; + // compute dot between every column of A with every col of B + for (std::size_t i=0; i<(std::size_t)numVecsA; i++) + { + for (std::size_t j=0; j<(std::size_t)numVecsB; j++) + { + A(i)->Dot( *(B(j)), &tmp ); + tmp *= alpha_; + C(i,j) = beta_ == zero ? zero : beta_ * C(i,j); + C(i,j) += tmp; + } + } +} + +/* ------------------------------------------------------------------- +C = beta * C + alpha * A^T * B +A = multivector +B = multivector +C is an Eigen dense matrix returned by the function +*-------------------------------------------------------------------*/ +template < + typename C_type, typename A_type, typename B_type, typename alpha_type + > +std::enable_if_t< + // level3 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_dynamic_dense_matrix_eigen::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value, + C_type + > +product(::pressio::transpose modeA, + ::pressio::nontranspose modeB, + const alpha_type alpha, + const A_type & A, + const B_type & B) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + + const auto numVecsA = A.NumVectors(); + const auto numVecsB = B.NumVectors(); + C_type C(numVecsA, numVecsB); + product(modeA, modeB, alpha, A, B, static_cast(0), C); + return C; +} + + +/* ------------------------------------------------------------------- +special case A==B +C = beta * C + alpha * A^T * A +A = epetra multivector +C is an Eigen dense matrix +*-------------------------------------------------------------------*/ +template < + typename A_type, typename alpha_type, typename beta_type, typename C_type + > +std::enable_if_t< + // level3 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_dense_matrix_eigen::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +product(::pressio::transpose /*unused*/, + ::pressio::nontranspose /*unused*/, + const alpha_type alpha, + const A_type & A, + const beta_type beta, + C_type & C) +{ + + assert( ::pressio::ops::extent(C, 0) == ::pressio::ops::extent(A, 1) ); + assert( ::pressio::ops::extent(C, 1) == ::pressio::ops::extent(A, 1) ); + + // how many vectors are in A and B + const int numVecsA = A.NumVectors(); + assert(C.rows() == numVecsA); + assert(C.cols() == numVecsA); + + using sc_t = typename ::pressio::Traits::scalar_type; + constexpr auto zero = static_cast(0); + sc_t tmp = zero; + const sc_t alpha_(alpha); + const sc_t beta_(beta); + const auto apply_beta = [beta_](sc_t c) -> sc_t { + return beta_ == zero ? zero : beta_ * c; + }; + + // A dot A = A^T*A, which yields a symmetric matrix + // only need to compute half and fill remaining entries accordingly + for (int i=0; i< numVecsA; i++) + { + C(i,i) = apply_beta(C(i,i)); + A(i)->Dot( *(A(i)), &tmp ); + C(i,i) += alpha_*tmp; + + for (int j=i+1; jDot( *(A(j)), &tmp ); + C(i,j) += alpha_*tmp; + C(j,i) += alpha_*tmp; + } + } +} + +template < + typename C_type, typename A_type, typename alpha_type + > +std::enable_if_t< + // level3 common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_dynamic_dense_matrix_eigen::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value, + C_type + > +product(::pressio::transpose modeA, + ::pressio::nontranspose modeB, + const alpha_type alpha, + const A_type & A) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + C_type C(A.NumVectors(), A.NumVectors()); + product(modeA, modeB, alpha, A, static_cast(0), C); + return C; +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_LEVEL3_HPP_ diff --git a/include/pressio/ops/epetra/ops_min_max.hpp b/include/pressio/ops/epetra/ops_min_max.hpp new file mode 100644 index 0000000..d716cc3 --- /dev/null +++ b/include/pressio/ops/epetra/ops_min_max.hpp @@ -0,0 +1,107 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_min_max.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_MIN_MAX_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_MIN_MAX_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + // TPL/container specific + (::pressio::is_vector_epetra::value + || ::pressio::is_multi_vector_epetra::value) + // scalar compatibility + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value), + typename ::pressio::Traits::scalar_type + > +max(T & obj) +{ + assert(::pressio::ops::extent(obj, 0) > 0); + assert(!::pressio::is_multi_vector_epetra::value + || ::pressio::ops::extent(obj, 1) > 0); + + using sc_t = typename ::pressio::Traits::scalar_type; + std::vector x(obj.NumVectors()); + obj.MaxValue(x.data()); + const auto i = std::max_element(x.begin(), x.end()); + if (i == x.end()) { + throw std::runtime_error("Can't take max() of no elements"); + } + return *i; +} + +template +std::enable_if_t< + // TPL/container specific + (::pressio::is_vector_epetra::value + || ::pressio::is_multi_vector_epetra::value) + // scalar compatibility + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value), + typename ::pressio::Traits::scalar_type + > +min(const T & obj) +{ + assert(::pressio::ops::extent(obj, 0) > 0); + assert(!::pressio::is_multi_vector_epetra::value + || ::pressio::ops::extent(obj, 1) > 0); + + using sc_t = typename ::pressio::Traits::scalar_type; + std::vector x(obj.NumVectors()); + obj.MinValue(x.data()); + const auto i = std::min_element(x.begin(), x.end()); + if (i == x.end()) { + throw std::runtime_error("Can't take min() of no elements"); + } + return *i; +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_MIN_MAX_HPP_ diff --git a/include/pressio/ops/epetra/ops_multi_vector_update.hpp b/include/pressio/ops/epetra/ops_multi_vector_update.hpp new file mode 100644 index 0000000..41c288c --- /dev/null +++ b/include/pressio/ops/epetra/ops_multi_vector_update.hpp @@ -0,0 +1,110 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_multi_vector_update.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_MULTI_VECTOR_UPDATE_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_MULTI_VECTOR_UPDATE_HPP_ + +namespace pressio{ namespace ops{ + +//---------------------------------------------------------------------- +// overloads for computing: MV = a * MV + b * MV1 +//---------------------------------------------------------------------- +template +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_multi_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +update(T & mv, const alpha_t &a, + const T1 & mv1, const beta_t &b) +{ + assert(::pressio::ops::extent(mv, 0) == ::pressio::ops::extent(mv1, 0)); + assert(::pressio::ops::extent(mv, 1) == ::pressio::ops::extent(mv1, 1)); + + using scalar_t = typename ::pressio::Traits::scalar_type; + const scalar_t a_(a); + const scalar_t b_(b); + + if (b_ == static_cast(0)) { + ::pressio::ops::scale(mv, a_); + } else { + mv.Update(b_, mv1, a_); + } +} + +template +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 2 + && ::pressio::Traits::rank == 2 + // TPL/container specific + && ::pressio::is_multi_vector_epetra::value + && ::pressio::is_multi_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + > +update(T & mv, const T1 & mv1, const beta_t & b) +{ + using scalar_t = typename ::pressio::Traits::scalar_type; + ::pressio::ops::update(mv, b, mv1, static_cast(0)); +} + +}}//end namespace ::pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_MULTI_VECTOR_UPDATE_HPP_ diff --git a/include/pressio/ops/epetra/ops_norms.hpp b/include/pressio/ops/epetra/ops_norms.hpp new file mode 100644 index 0000000..dcebe9f --- /dev/null +++ b/include/pressio/ops/epetra/ops_norms.hpp @@ -0,0 +1,93 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_norms.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_NORMS_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_NORMS_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + // norm-1 common constraints + ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + // scalar compatibility + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value), + typename ::pressio::Traits::scalar_type + > +norm1(const T & a) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + sc_t result = 0.0; + a.Norm1(&result); + return result; +} + +template +std::enable_if_t< + // norm-1 common constraints + ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + // scalar compatibility + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value), + typename ::pressio::Traits::scalar_type + > +norm2(const T & a) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + sc_t result = 0.0; + a.Norm2(&result); + return result; +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_NORMS_HPP_ diff --git a/include/pressio/ops/epetra/ops_pow.hpp b/include/pressio/ops/epetra/ops_pow.hpp new file mode 100644 index 0000000..b3641a8 --- /dev/null +++ b/include/pressio/ops/epetra/ops_pow.hpp @@ -0,0 +1,117 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_pow.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_POW_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_POW_HPP_ + +namespace pressio{ namespace ops{ + +// y = |x|^exponent, expo>0 +template +std::enable_if_t< + ::pressio::is_vector_epetra::value and + ::pressio::is_vector_epetra::value + > +abs_pow(T1 & y, + const T2 & x, + const typename ::pressio::Traits::scalar_type & exponent) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + + assert(x.GlobalLength() == y.GlobalLength()); + assert(x.MyLength() == y.MyLength()); + + if (exponent <= static_cast(0)) + throw std::runtime_error("this overload is only for exponent > 0"); + + for (int i=0; i< x.MyLength(); ++i){ + y[i] = std::pow( std::abs(x[i]), exponent); + } +} + +// y = |x|^exponent, expo<0 +template +std::enable_if_t< + ::pressio::is_vector_epetra::value and + ::pressio::is_vector_epetra::value + > +abs_pow(T1 & y, + const T2 & x, + const typename ::pressio::Traits::scalar_type & exponent, + const typename ::pressio::Traits::scalar_type & eps) +{ + + using sc_t = typename ::pressio::Traits::scalar_type; + + assert(x.GlobalLength() == y.GlobalLength()); + assert(x.MyLength() == y.MyLength()); + + if (exponent >= static_cast(0)){ + throw std::runtime_error("this overload is only for exponent < 0"); + } + + const auto expo = -exponent; + for (int i=0; i(1) / std::max(eps, std::pow(std::abs(x[i]), expo)); + } +} + +template +std::enable_if_t< + ::pressio::is_vector_epetra::value + > +pow(T & x, + const typename ::pressio::Traits::scalar_type & exponent) +{ + for (int i=0; i +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +update(T & v, const a_Type a, + const T1 & v1, const b_Type b) +{ + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v1, 0)); + + using scalar_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + const scalar_t a_(a); + const scalar_t b_(b); + + if (b_ == zero) { + ::pressio::ops::scale(v, a_); + return; + } + + for (int i=0; i +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +update(T & v, const a_Type &a, + const T1 & v1, const b_Type &b, + const T2 & v2, const c_Type &c) +{ + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v1, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v2, 0)); + + using scalar_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + const scalar_t a_(a); + const scalar_t b_(b); + const scalar_t c_(c); + + if (b_ == zero) { + ::pressio::ops::update(v, a, v2, c); + } else if (c_ == zero) { + ::pressio::ops::update(v, a, v1, b); + } else { + for (int i=0; i +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +update(T & v, const a_Type &a, + const T1 & v1, const b_Type &b, + const T2 & v2, const c_Type &c, + const T3 & v3, const d_Type &d) +{ + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v1, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v2, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v3, 0)); + + using scalar_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + const scalar_t a_(a); + const scalar_t b_(b); + const scalar_t c_(c); + const scalar_t d_(d); + + if (b_ == zero) { + ::pressio::ops::update(v, a, v2, c, v3, d); + } else if (c_ == zero) { + ::pressio::ops::update(v, a, v1, b, v3, d); + } else if (d_ == zero) { + ::pressio::ops::update(v, a, v1, b, v2, c); + } else { + for (int i=0; i +std::enable_if_t< + // rank-1 update common constraints + ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + && ::pressio::Traits::rank == 1 + // TPL/container specific + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + && ::pressio::is_vector_epetra::value + // scalar compatibility + && ::pressio::all_have_traits_and_same_scalar::value + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + && std::is_convertible::scalar_type>::value + > +update(T & v, const a_Type &a, + const T1 & v1, const b_Type &b, + const T2 & v2, const c_Type &c, + const T3 & v3, const d_Type &d, + const T4 & v4, const e_Type &e) +{ + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v1, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v2, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v3, 0)); + assert(::pressio::ops::extent(v, 0) == ::pressio::ops::extent(v4, 0)); + + using scalar_t = typename ::pressio::Traits::scalar_type; + const auto zero = static_cast(0); + const scalar_t a_(a); + const scalar_t b_(b); + const scalar_t c_(c); + const scalar_t d_(d); + const scalar_t e_(e); + + if (b_ == zero) { + ::pressio::ops::update(v, a, v2, c, v3, d, v4, e); + } else if (c_ == zero) { + ::pressio::ops::update(v, a, v1, b, v3, d, v4, e); + } else if (d_ == zero) { + ::pressio::ops::update(v, a, v1, b, v2, c, v4, e); + } else if (e_ == zero) { + ::pressio::ops::update(v, a, v1, b, v2, c, v3, d); + } else { + for (int i = 0; i < v.MyLength(); ++i) { + if (a_ == zero) { + v[i] = b_*v1[i] + c_*v2[i] + d_*v3[i] + e_*v4[i]; + } else { + v[i] = a_*v[i] + b_*v1[i] + c_*v2[i] + d_*v3[i] + e_*v4[i]; + } + } + } +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_RANK1_UPDATE_HPP_ diff --git a/include/pressio/ops/epetra/ops_scale.hpp b/include/pressio/ops/epetra/ops_scale.hpp new file mode 100644 index 0000000..faf6b1f --- /dev/null +++ b/include/pressio/ops/epetra/ops_scale.hpp @@ -0,0 +1,81 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_scale.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_SCALE_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_SCALE_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + // rank-1 update common constraints + (::pressio::Traits::rank == 1 + || ::pressio::Traits::rank == 2) + // TPL/container specific + && (::pressio::is_vector_epetra::value + || ::pressio::is_multi_vector_epetra::value) + // scalar compatibility + && (std::is_floating_point::scalar_type>::value + || std::is_integral::scalar_type>::value) + && std::is_convertible::scalar_type>::value + > +scale(T & objectIn, const ScalarType value) +{ + using sc_t = typename ::pressio::Traits::scalar_type; + const sc_t v(value); + if (v == static_cast(0)) { + ::pressio::ops::set_zero(objectIn); + } else { + if (0 != objectIn.Scale(v)) { + throw std::runtime_error("Epetra scaling failed"); + } + } +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_SCALE_HPP_ diff --git a/include/pressio/ops/epetra/ops_set_zero.hpp b/include/pressio/ops/epetra/ops_set_zero.hpp new file mode 100644 index 0000000..f5e1ada --- /dev/null +++ b/include/pressio/ops/epetra/ops_set_zero.hpp @@ -0,0 +1,66 @@ +/* +//@HEADER +// ************************************************************************ +// +// ops_set_zero.hpp +// Pressio +// Copyright 2019 +// National Technology & Engineering Solutions of Sandia, LLC (NTESS) +// +// Under the terms of Contract DE-NA0003525 with NTESS, the +// U.S. Government retains certain rights in this software. +// +// Pressio is licensed under BSD-3-Clause terms of use: +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact Francesco Rizzi (fnrizzi@sandia.gov) +// +// ************************************************************************ +//@HEADER +*/ + +#ifndef PRESSIOOPS_OPS_EPETRA_OPS_SET_ZERO_HPP_ +#define PRESSIOOPS_OPS_EPETRA_OPS_SET_ZERO_HPP_ + +namespace pressio{ namespace ops{ + +template +std::enable_if_t< + ::pressio::is_vector_epetra::value or + ::pressio::is_multi_vector_epetra::value + > +set_zero(T & v) +{ + using value_t = typename ::pressio::Traits::scalar_type; + v.PutScalar( static_cast(0) ); +} + +}}//end namespace pressio::ops +#endif // PRESSIOOPS_OPS_EPETRA_OPS_SET_ZERO_HPP_