Skip to content
Snippets Groups Projects
Commit 3362c84d authored by Ian Bell's avatar Ian Bell
Browse files

Restructure the rhoi derivatives

parent aed734f0
No related branches found
No related tags found
No related merge requests found
...@@ -15,17 +15,17 @@ derivT(const FuncType& f, TType T, const ContainerType& rho) { ...@@ -15,17 +15,17 @@ derivT(const FuncType& f, TType T, const ContainerType& rho) {
return f(std::complex<TType>(T, h), rho).imag() / h; return f(std::complex<TType>(T, h), rho).imag() / h;
} }
/// Given a function, use complex step derivatives to calculate the derivative with respect to the first composition variable /// Given a function, use complex step derivatives to calculate the derivative with respect to the given composition variable
template <typename TType, typename ContainerType, typename FuncType, typename Integer> template <typename TType, typename ContainerType, typename FuncType, typename Integer>
typename std::enable_if<is_container<ContainerType>::value, typename ContainerType::value_type>::type typename std::enable_if<is_container<ContainerType>::value, typename ContainerType::value_type>::type
derivrhoi(const FuncType& f, TType T, const ContainerType& rho, Integer j) { derivrhoi(const FuncType& f, TType T, const ContainerType& rho, Integer i) {
double h = 1e-100; double h = 1e-100;
using comtype = std::complex<ContainerType::value_type>; using comtype = std::complex<ContainerType::value_type>;
std::valarray<comtype> rhocom(rho.size()); std::valarray<comtype> rhocom(rho.size());
for (auto i = 0; i < rho.size(); ++i) { for (auto j = 0; j < rho.size(); ++j) {
rhocom[i] = comtype(rho[i], 0.0); rhocom[j] = comtype(rho[j], 0.0);
} }
rhocom[j] = comtype(rho[j], h); rhocom[i] = comtype(rho[i], h);
return f(T, rhocom).imag() / h; return f(T, rhocom).imag() / h;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment