17 if (coefficients.size() == n){
20 throw ValueError(
format(
"The number of coefficients %d does not match with %d. ",coefficients.size(),n));
26 if (coefficients.size() == rows){
28 for(
unsigned int i=0; i<rows; i++) {
33 throw ValueError(
format(
"The number of rows %d does not match with %d. ",coefficients.size(),rows));
52 double IncompressibleClass::simplePolynomial(std::vector<double>
const& coefficients,
double T){
54 std::cout <<
"Running simplePolynomial(std::vector, " << T <<
"): ";
56 bool db = this->
DEBUG;
59 for(
unsigned int i=0; i<coefficients.size();i++) {
60 result += coefficients[i] * pow(T,(
int)i);
64 std::cout << result << std::endl;
68 double IncompressibleClass::simplePolynomial(std::vector<std::vector<double> >
const& coefficients,
double x,
double T){
70 std::cout <<
"Running simplePolynomial(std::vector, " << x <<
", " << T <<
"): ";
72 bool db = this->
DEBUG;
75 for(
unsigned int i=0; i<coefficients.size();i++) {
76 result += pow(x,(
int)i) * simplePolynomial(coefficients[i], T);
80 std::cout << result << std::endl;
90 double IncompressibleClass::simplePolynomialInt(std::vector<double>
const& coefficients,
double T){
93 std::cout <<
"Running simplePolynomialInt(std::vector, " << T <<
"): ";
95 bool db = this->
DEBUG;
98 for(
unsigned int i=0; i<coefficients.size();i++) {
99 result += 1./(i+1.) * coefficients[i] * pow(T,(
int)(i+1.));
103 std::cout << result << std::endl;
108 double IncompressibleClass::simplePolynomialInt(std::vector<double>
const& coefficients,
double T1,
double T0){
110 std::cout <<
"Running simplePolynomialInt(std::vector, " << T1 <<
", " << T0 <<
"): ";
112 bool db = this->
DEBUG;
115 for(
unsigned int i=0; i<coefficients.size();i++) {
116 result += 1./(i+1.) * coefficients[i] * ( pow(T1,(
int)(i+1.)) - pow(T0,(
int)(i+1.)) );
120 std::cout << result << std::endl;
125 double IncompressibleClass::simplePolynomialInt(std::vector<std::vector<double> >
const& coefficients,
double x,
double T){
127 std::cout <<
"Running simplePolynomialInt(std::vector, " << x <<
", " << T <<
"): ";
129 bool db = this->
DEBUG;
132 for(
unsigned int i=0; i<coefficients.size();i++) {
133 result += pow(x,(
int)i) * simplePolynomialInt(coefficients[i], T);
137 std::cout << result << std::endl;
142 double IncompressibleClass::simplePolynomialInt(std::vector<std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
144 std::cout <<
"Running simplePolynomialInt(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
146 bool db = this->
DEBUG;
149 for(
unsigned int i=0; i<coefficients.size();i++) {
150 result += pow(x,(
int)i) * simplePolynomialInt(coefficients[i], T1, T0);
154 std::cout << result << std::endl;
164 double IncompressibleClass::simpleFracInt(std::vector<double>
const& coefficients,
double T){
166 std::cout <<
"Running simpleFracInt(std::vector, " << T <<
"): ";
168 double result = coefficients[0] * log(T);
169 if (coefficients.size() > 1) {
170 for (
unsigned int i=1; i<coefficients.size(); i++){
171 result += 1./(i) * coefficients[i] * pow(T,(
int)(i));
175 std::cout << result << std::endl;
179 double IncompressibleClass::simpleFracInt(std::vector<double>
const& coefficients,
double T1,
double T0){
181 std::cout <<
"Running simpleFracInt(std::vector, " << T1 <<
", " << T0 <<
"): ";
183 double result = coefficients[0] * log(T1/T0);
184 if (coefficients.size() > 1) {
185 for (
unsigned int i=1; i<coefficients.size(); i++){
186 result += 1./(i) * coefficients[i] * (pow(T1,(
int)(i))-pow(T0,(
int)(i)));
190 std::cout << result << std::endl;
194 double IncompressibleClass::simpleFracInt(std::vector< std::vector<double> >
const& coefficients,
double x,
double T){
196 std::cout <<
"Running simpleFracInt(std::vector, " << x <<
", " << T <<
"): ";
198 bool db = this->
DEBUG;
201 for (
unsigned int i=0; i<coefficients.size(); i++){
202 result += pow(x,(
int)i) *
polyfracint(coefficients[i],T);
206 std::cout << result << std::endl;
210 double IncompressibleClass::simpleFracInt(std::vector< std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
212 std::cout <<
"Running simpleFracInt(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
214 bool db = this->
DEBUG;
217 for (
unsigned int i=0; i<coefficients.size(); i++){
218 result += pow(x,(
int)i) *
polyfracint(coefficients[i],T1,T0);
222 std::cout << result << std::endl;
253 double IncompressibleClass::factorial(
double nValue){
255 for(
int i = 2; i <= nValue; i++){
260 double IncompressibleClass::binom(
double nValue,
double nValue2){
262 if(nValue2 == 1)
return nValue;
263 result = (factorial(nValue)) / (factorial(nValue2)*factorial((nValue - nValue2)));
268 std::vector<double> IncompressibleClass::fracIntCentralDvector(
int m,
double T,
double Tbase){
269 std::vector<double> D;
271 if (m<1)
throw ValueError(
format(
"You have to provide coefficients, a vector length of %d is not a valid. ",m));
272 for (
int j=0; j<m; j++){
273 tmp = pow(-1.0,j) * log(T) * pow(Tbase,(
int)j);
274 for(
int k=0; k<j; k++) {
275 tmp += binom(j,k) * pow(-1.0,k) / (j-k) * pow(T,j-k) * pow(Tbase,k);
281 std::vector<double> IncompressibleClass::fracIntCentralDvector(
int m,
double T1,
double T0,
double Tbase){
282 std::vector<double> D;
284 if (m<1)
throw ValueError(
format(
"You have to provide coefficients, a vector length of %d is not a valid. ",m));
285 for (
int j=0; j<m; j++){
286 tmp = pow(-1.0,(
int)j) * log(T1/T0) * pow(Tbase,(
double)j);
287 for(
int k=0; k<j; k++) {
288 tmp += binom(j,k) * pow(-1.0,(
int)k) / (j-k) * (pow(T1,(
int)(j-k))-pow(T0,(
int)(j-k))) * pow(Tbase,(
int)k);
295 double IncompressibleClass::fracIntCentral(std::vector<double>
const& coefficients,
double T,
double Tbase){
297 std::cout <<
"Running fracIntCentral(std::vector, " << T <<
", " << Tbase <<
"): ";
299 bool db = this->
DEBUG;
301 int m = coefficients.size();
302 std::vector<double> D = fracIntCentralDvector(m, T, Tbase);
304 for(
int j=0; j<m; j++) {
305 result += coefficients[j] * D[j];
309 std::cout << result << std::endl;
314 double IncompressibleClass::fracIntCentral(std::vector<double>
const& coefficients,
double T1,
double T0,
double Tbase){
316 std::cout <<
"Running fracIntCentral(std::vector, " << T1 <<
", " << T0 <<
", " << Tbase <<
"): ";
318 bool db = this->
DEBUG;
320 int m = coefficients.size();
321 std::vector<double> D = fracIntCentralDvector(m, T1, T0, Tbase);
323 for(
int j=0; j<m; j++) {
324 result += coefficients[j] * D[j];
328 std::cout << result << std::endl;
338 double IncompressibleClass::baseHorner(std::vector<double>
const& coefficients,
double T){
340 std::cout <<
"Running baseHorner(std::vector, " << T <<
"): ";
343 for(
int i=coefficients.size()-1; i>=0; i--) {
345 result += coefficients[i];
348 std::cout << result << std::endl;
352 double IncompressibleClass::baseHorner(std::vector< std::vector<double> >
const& coefficients,
double x,
double T){
354 std::cout <<
"Running baseHorner(std::vector, " << x <<
", " << T <<
"): ";
356 bool db = this->
DEBUG;
359 for(
int i=coefficients.size()-1; i>=0; i--) {
361 result += baseHorner(coefficients[i], T);
365 std::cout << result << std::endl;
370 double IncompressibleClass::baseHornerInt(std::vector<double>
const& coefficients,
double T){
372 std::cout <<
"Running baseHornerInt(std::vector, " << T <<
"): ";
375 for(
int i=coefficients.size()-1; i>=0; i--) {
377 result += coefficients[i]/(i+1.);
381 std::cout << result << std::endl;
386 double IncompressibleClass::baseHornerInt(std::vector<double>
const& coefficients,
double T1,
double T0){
388 std::cout <<
"Running baseHornerInt(std::vector, " << T1 <<
", " << T0 <<
"): ";
390 bool db = this->
DEBUG;
395 for(
int i=coefficients.size()-1; i>=0; i--) {
397 result1 += coefficients[i]/(i+1.);
399 result0 += coefficients[i]/(i+1.);
408 std::cout << result1 << std::endl;
413 double IncompressibleClass::baseHornerInt(std::vector<std::vector<double> >
const& coefficients,
double x,
double T){
415 std::cout <<
"Running baseHornerInt(std::vector, " << x <<
", " << T <<
"): ";
417 bool db = this->
DEBUG;
420 for(
int i=coefficients.size()-1; i>=0; i--) {
422 result += baseHornerInt(coefficients[i], T);
426 std::cout << result << std::endl;
431 double IncompressibleClass::baseHornerInt(std::vector<std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
433 std::cout <<
"Running baseHornerInt(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
435 bool db = this->
DEBUG;
438 for(
int i=coefficients.size()-1; i>=0; i--) {
440 result += baseHornerInt(coefficients[i], T1, T0);
444 std::cout << result << std::endl;
458 double IncompressibleClass::baseHornerFra(std::vector<double>
const& coefficients,
double T){
460 std::cout <<
"Running baseHornerFra(std::vector, " << T <<
"): ";
462 bool db = this->
DEBUG;
465 if (coefficients.size() > 1) {
466 for(
int i=coefficients.size()-1; i>=1; i--) {
468 result += coefficients[i]/(i);
472 result += coefficients[0] * log(T);
475 std::cout << result << std::endl;
480 double IncompressibleClass::baseHornerFra(std::vector<double>
const& coefficients,
double T1,
double T0){
482 std::cout <<
"Running baseHornerFra(std::vector, " << T1 <<
", " << T0 <<
"): ";
484 bool db = this->
DEBUG;
488 if (coefficients.size() > 1) {
490 for(
int i=coefficients.size()-1; i>=1; i--) {
492 result += coefficients[i]/(i);
494 result0 += coefficients[i]/(i);
500 result += coefficients[0] * log(T1/T0);
503 std::cout << result << std::endl;
508 double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> >
const& coefficients,
double x,
double T){
510 std::cout <<
"Running baseHornerFra(std::vector, " << x <<
", " << T <<
"): ";
512 bool db = this->
DEBUG;
516 for(
int i=coefficients.size()-1; i>=0; i--) {
518 result += baseHornerFra(coefficients[i], T);
523 std::cout << result << std::endl;
528 double IncompressibleClass::baseHornerFra(std::vector<std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
530 std::cout <<
"Running baseHornerFra(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
532 bool db = this->
DEBUG;
536 for(
int i=coefficients.size()-1; i>=0; i--) {
538 result += baseHornerFra(coefficients[i], T1, T0);
543 std::cout << result << std::endl;
554 std::vector<double> IncompressibleClass::integrateCoeffs(std::vector<double>
const& coefficients){
555 std::vector<double> newCoefficients;
556 unsigned int sizeX = coefficients.size();
557 if (sizeX<1)
throw ValueError(
format(
"You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
559 newCoefficients.push_back(0.0);
560 for(
unsigned int i=0; i<coefficients.size(); i++) {
561 newCoefficients.push_back(coefficients[i]/(i+1.));
563 return newCoefficients;
567 std::vector< std::vector<double> > IncompressibleClass::integrateCoeffs(std::vector< std::vector<double> >
const& coefficients,
bool axis){
568 std::vector< std::vector<double> > newCoefficients;
569 unsigned int sizeX = coefficients.size();
570 if (sizeX<1)
throw ValueError(
format(
"You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
573 std::vector< std::vector<double> > tmpCoefficients;
574 tmpCoefficients =
transpose(coefficients);
575 unsigned int sizeY = tmpCoefficients.size();
576 for(
unsigned int i=0; i<sizeY; i++) {
577 newCoefficients.push_back(integrateCoeffs(tmpCoefficients[i]));
580 }
else if (axis==
false){
581 for(
unsigned int i=0; i<sizeX; i++) {
582 newCoefficients.push_back(integrateCoeffs(coefficients[i]));
584 return newCoefficients;
586 throw ValueError(
format(
"You can only use x-axis (0) and y-axis (1) for integration. %d is not a valid input. ",axis));
588 return newCoefficients;
594 std::vector<double> IncompressibleClass::deriveCoeffs(std::vector<double>
const& coefficients){
595 std::vector<double> newCoefficients;
596 unsigned int sizeX = coefficients.size();
597 if (sizeX<1)
throw ValueError(
format(
"You have to provide coefficients, a vector length of %d is not a valid. ",sizeX));
599 for(
unsigned int i=1; i<coefficients.size(); i++) {
600 newCoefficients.push_back(coefficients[i]*i);
602 return newCoefficients;
635 double IncompressibleClass::integrateIn2Steps(std::vector<double>
const& coefficients,
double T){
638 std::cout <<
"Running integrateIn2Steps(std::vector, " << T <<
"): ";
640 bool db = this->
DEBUG;
642 double result =
polyval(integrateCoeffs(coefficients),T);
645 std::cout << result << std::endl;
650 double IncompressibleClass::integrateIn2Steps(std::vector<double>
const& coefficients,
double T1,
double T0){
652 std::cout <<
"Running integrateIn2Steps(std::vector, " << T1 <<
", " << T0 <<
"): ";
654 bool db = this->
DEBUG;
656 std::vector<double> coefficientsInt(integrateCoeffs(coefficients));
657 double result =
polyval(coefficientsInt,T1)-
polyval(coefficientsInt,T0);
660 std::cout << result << std::endl;
665 double IncompressibleClass::integrateIn2Steps(std::vector< std::vector<double> >
const& coefficients,
double x,
double T,
bool axis){
667 std::cout <<
"Running integrateIn2Steps(std::vector, " << x <<
", " << T <<
"): ";
669 bool db = this->
DEBUG;
671 double result =
polyval(integrateCoeffs(coefficients,axis),x,T);
674 std::cout << result << std::endl;
679 double IncompressibleClass::integrateIn2Steps(std::vector< std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
681 std::cout <<
"Running integrateIn2Steps(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
683 bool db = this->
DEBUG;
685 std::vector< std::vector<double> > coefficientsInt(integrateCoeffs(coefficients,
false));
686 double result =
polyval(coefficientsInt,x,T1)-
polyval(coefficientsInt,x,T0);
689 std::cout << result << std::endl;
694 double IncompressibleClass::fracIntIn2Steps(std::vector<double>
const& coefficients,
double T){
696 std::cout <<
"Running fracIntIn2Steps(std::vector, " << T <<
"): ";
698 bool db = this->
DEBUG;
700 double result = coefficients[0] * log(T);
701 if (coefficients.size() > 1) {
702 std::vector<double> newCoeffs(coefficients.begin() + 1, coefficients.end());
703 result +=
polyint(newCoeffs,T);
707 std::cout << result << std::endl;
712 double IncompressibleClass::fracIntIn2Steps(std::vector<double>
const& coefficients,
double T1,
double T0){
714 std::cout <<
"Running fracIntIn2Steps(std::vector, " << T1 <<
", " << T0 <<
"): ";
716 bool db = this->
DEBUG;
718 double result = coefficients[0] * log(T1/T0);
719 if (coefficients.size() > 1) {
720 std::vector<double> newCoeffs(coefficients.begin() + 1, coefficients.end());
721 result +=
polyint(newCoeffs,T1,T0);
725 std::cout << result << std::endl;
730 double IncompressibleClass::fracIntIn2Steps(std::vector<std::vector<double> >
const& coefficients,
double x,
double T){
732 std::cout <<
"Running fracIntIn2Steps(std::vector, " << x <<
", " << T <<
"): ";
734 bool db = this->
DEBUG;
736 std::vector<double> newCoeffs;
737 for (
unsigned int i=0; i<coefficients.size(); i++){
738 newCoeffs.push_back(
polyfracint(coefficients[i],T));
740 double result =
polyval(newCoeffs,x);
743 std::cout << result << std::endl;
748 double IncompressibleClass::fracIntIn2Steps(std::vector<std::vector<double> >
const& coefficients,
double x,
double T1,
double T0){
750 std::cout <<
"Running fracIntIn2Steps(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
"): ";
752 bool db = this->
DEBUG;
754 std::vector<double> newCoeffs;
755 for (
unsigned int i=0; i<coefficients.size(); i++){
756 newCoeffs.push_back(
polyfracint(coefficients[i],T1,T0));
758 double result =
polyval(newCoeffs,x);
761 std::cout << result << std::endl;
766 double IncompressibleClass::fracIntCentral2Steps(std::vector<std::vector<double> >
const& coefficients,
double x,
double T,
double Tbase){
768 std::cout <<
"Running fracIntCentral2Steps(std::vector, " << x <<
", " << T <<
", " << Tbase <<
"): ";
770 bool db = this->
DEBUG;
772 std::vector<double> newCoeffs;
773 for (
unsigned int i=0; i<coefficients.size(); i++){
774 newCoeffs.push_back(fracIntCentral(coefficients[i], T, Tbase));
776 double result =
polyval(newCoeffs,x);
779 std::cout << result << std::endl;
784 double IncompressibleClass::fracIntCentral2Steps(std::vector<std::vector<double> >
const& coefficients,
double x,
double T1,
double T0,
double Tbase){
786 std::cout <<
"Running fracIntCentral2Steps(std::vector, " << x <<
", " << T1 <<
", " << T0 <<
", " << Tbase <<
"): ";
788 bool db = this->
DEBUG;
790 std::vector<double> newCoeffs;
791 for (
unsigned int i=0; i<coefficients.size(); i++){
792 newCoeffs.push_back(fracIntCentral(coefficients[i], T1, T0, Tbase));
794 double result =
polyval(newCoeffs,x);
797 std::cout << result << std::endl;
816 result = exp(coefficients[0]/(T+coefficients[1]) - coefficients[2]);
818 result = exp(
polyval(coefficients, T));
820 throw ValueError(
format(
"There is no function defined for this input (%d). ",n));
833 result = exp(
polyval(coefficients, x, T));
835 throw ValueError(
format(
"There is no function defined for this input (%d). ",n));
std::vector< std::vector< double > > transpose(std::vector< std::vector< double > > const &in)
double polyfracint(std::vector< double > const &coefficients, double T)
double polyint(std::vector< double > const &coefficients, double T)
std::vector< double > x(ncmax, 0)
double expval(std::vector< double > const &coefficients, double T, int n)
bool checkCoefficients(std::vector< double > const &coefficients, unsigned int n)
Basic checks for coefficient vectors.
double polyval(std::vector< double > const &coefficients, double x)