mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Added ForwardBlock operator* for scalars.
This commit is contained in:
@@ -242,7 +242,17 @@ namespace AutoDiff
|
||||
|
||||
V val_;
|
||||
std::vector<M> jac_;
|
||||
};
|
||||
|
||||
template <typename Sclr>
|
||||
friend
|
||||
ForwardBlock<Sclr> operator*(const ForwardBlock<Sclr> &lhs,
|
||||
const Sclr &rhs);
|
||||
|
||||
template <typename Sclr>
|
||||
friend
|
||||
ForwardBlock<Sclr> operator*(const Sclr &lhs,
|
||||
const ForwardBlock<Sclr> &rhs);
|
||||
};
|
||||
|
||||
|
||||
template <class Ostream, typename Scalar>
|
||||
@@ -333,6 +343,41 @@ namespace AutoDiff
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Operator for multiplication with a scalar on the right-hand side
|
||||
*
|
||||
* @param lhs The left-hand side AD forward block
|
||||
* @param rhs The scalar to multiply with
|
||||
* @return The product
|
||||
*/
|
||||
template <typename Scalar>
|
||||
ForwardBlock<Scalar> operator*(const ForwardBlock<Scalar> &lhs,
|
||||
const Scalar &rhs)
|
||||
{
|
||||
std::vector< Eigen::SparseMatrix<Scalar> > jac = lhs.jac_;
|
||||
for (int block=0; block<lhs.numBlocks(); block++) {
|
||||
jac[block] = lhs.jac_[block] * rhs;
|
||||
}
|
||||
auto val = lhs.val_ * rhs;
|
||||
return ForwardBlock<Scalar>::function(val, jac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Operator for multiplication with a scalar on the left-hand side
|
||||
*
|
||||
* @param lhs The scalar to multiply with
|
||||
* @param rhs The right-hand side AD forward block
|
||||
* @return The product
|
||||
*/
|
||||
template <typename Scalar>
|
||||
ForwardBlock<Scalar> operator*(const Scalar &lhs,
|
||||
const ForwardBlock<Scalar> &rhs)
|
||||
{
|
||||
return rhs * lhs; // Commutative operation.
|
||||
}
|
||||
|
||||
|
||||
} // namespace Autodiff
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user