#include <RcppArmadillo.h>

#ifndef HYDRAULICS_H
#define HYDRAULICS_H
using namespace Rcpp;

NumericVector K2Psi(NumericVector K, NumericVector psi_extract, double exp_extract= 3.0);
NumericVector Psi2K(double psi, NumericVector psi_extract, double exp_extract= 3.0);


double averagePsi(NumericVector psi, NumericVector v, double exp_extract, double psi_extract);
double averagePsiPool(NumericMatrix Psi, NumericMatrix RHOPcoh, double exp_extract, double psi_extract);


NumericVector rootxylemConductanceProportions(NumericVector V, NumericVector L);

NumericVector psi2Weibull(double psi50, double psi88 = NA_REAL, double psi12 = NA_REAL);


NumericVector regulatedPsiTwoElements(double Emax, double psiSoil, double krhizomax, double kxylemmax, double n, double alpha, double c, double d, double dE = 0.1, double psiMax = -10.0);

double maximumSoilPlantConductance(NumericVector krhizomax, NumericVector krootmax, 
                                   double kstemmax, double kleafmax);



List E2psiBelowground(double E, List hydraulicNetwork,
                      NumericVector psiIni = NumericVector::create(0));

List E2psiAboveground(double E, double psiRootCrown, List hydraulicNetwork);


List E2psiNetwork(double E, List hydraulicNetwork,
                  NumericVector psiIni = NumericVector::create(0));


List supplyFunctionAboveground(NumericVector Erootcrown, NumericVector psiRootCrown, 
                               List hydraulicNetwork);


List supplyFunctionBelowground(List hydraulicNetwork,
                              double minFlow = 0.0,
                              double pCrit = 0.001);

List supplyFunctionNetwork(List hydraulicNetwork,
                           double minFlow = 0.0,
                           double pCrit = 0.001);
#endif
