Skip to content

Commit

Permalink
Add transport properties. (IDAES#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
John Eslick authored Feb 23, 2023
1 parent fab11c5 commit db3d29c
Show file tree
Hide file tree
Showing 29 changed files with 2,148 additions and 440 deletions.
8 changes: 4 additions & 4 deletions petsc/petsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,17 @@ int ScaleEqsUser(Solver_ctx *sol_ctx){
}

int ScaleVarsUser(Solver_ctx *sol_ctx){
//Use scalling factors set in the scaling_factor suffix, for DAEs ignore
//scaling on the derivatives and use scaling from the differntial vars
//instead varaibles and there derivatives should be scaled the same
//Use scaling factors set in the scaling_factor suffix, for DAEs ignore
//scaling on the derivatives and use scaling from the differential vars
//instead variables and there derivatives should be scaled the same
int i=0, j=0, err=0;
real s;
ASL *asl = sol_ctx->asl;
if (sol_ctx->scaling_factor_var->u.r == NULL) return 0; //no scaling factors
if (sol_ctx->opt.dae_solve){ //dae variable scaling
for(i=0;i<n_var;++i){ //n_var is asl vodoo
if (sol_ctx->dae_suffix_var->u.i[i] == 2) {
j = sol_ctx->dae_link[i]; //use differntial var scale
j = sol_ctx->dae_link[i]; //use differential var scale
s = sol_ctx->scaling_factor_var->u.r[j];
if(s != 0.0) varscale(i, 1.0/s, &err);
}
Expand Down
49 changes: 0 additions & 49 deletions src/functions/functions.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "functions.h"
#include <math.h>
#include <string.h>

#undef printf

Expand All @@ -12,56 +11,8 @@ void funcadd(AmplExports *ae){
* 4) Number of arguments (the -1 is variable arg list length)
* 5) Void pointer to function info */
addfunc("cbrt", (rfunc)scbrt, FUNCADD_REAL_VALUED, 1, NULL);
addfunc("testing_only", (rfunc)testing_only, FUNCADD_REAL_VALUED|FUNCADD_STRING_ARGS, -1, NULL);
}


extern real testing_only(arglist *al){
const char* sarg = al->sa[-(al->at[0]+1)];
int i, j;
real s=0;
char inv=0;

if(!strcmp("inv", sarg)){
inv = 1;
}
if(!inv){
for(i=0;i<al->nr;++i){
s += al->ra[i];
}
}
else{
for(i=0;i<al->nr;++i){
s += 1.0/al->ra[i];
}
}

if(al->derivs!=NULL){
for(i=0;i<al->nr;++i){
if(!inv){
al->derivs[i] = 1.0;
}
else{
al->derivs[i] = -1.0/(al->ra[i]*al->ra[i]);
}
}
if(al->hes!=NULL){
for(i=0;i<(al->nr*al->nr - al->nr)/2 + al->nr;++i){
al->hes[i] = 0;
}
if(inv){
j = -1;
for(i=0;i<al->nr;++i){
j = j + (i+1);
al->hes[j] = 2.0/(al->ra[i]*al->ra[i]*al->ra[i]);
}
}
}
}
return s;
}


extern real scbrt(arglist *al){
// al is the argument list data structure
// al->ra is an array of real arguments
Expand Down
4 changes: 0 additions & 4 deletions src/functions/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
#ifndef _INCLUDE_FUNCTIONS_H_
#define _INCLUDE_FUNCTIONS_H_

#include <time.h>
#include <math.h>


real scbrt(arglist *al);
real testing_only(arglist *al);

#endif
6 changes: 5 additions & 1 deletion src/general_helmholtz/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ namespace expr_idx{
const long phir_dt = 11;
const long delta_v_sat_approx = 12;
const long delta_l_sat_approx = 13;
const long viscosity_idx = 14;
const long thermal_conductivity_idx = 15;
const long surface_tension_idx = 16;
}
const long expr_map_size = 17;

// Structure for unary function value and 1st order derivatives
struct f11_struct {
Expand Down Expand Up @@ -116,7 +120,7 @@ struct f24_struct {
// Structure for parameters and expressions for specific component
struct parameters_struct {
void *asl = nullptr;// expressions in ASL (cast to ASL*)
long expr_map[14]; // index of expressions in NL file
long expr_map[expr_map_size]; // index of expressions in NL file
long var_map[3]; // index of variables in NL file
double R; // specific ideal gas constant [kJ/kg/K]
double MW; // molecular weight [g/mol]
Expand Down
220 changes: 217 additions & 3 deletions src/general_helmholtz/param_data/co2_expressions.nl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
g3 1 1 0 # problem unknown
2 0 14 0 0 # vars, constraints, objectives, ranges, eqns
0 13 0 0 0 0 # nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
2 0 16 0 0 # vars, constraints, objectives, ranges, eqns
0 15 0 0 0 0 # nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
0 0 # network constraints: nonlinear, linear
0 2 0 # nonlinear vars in constraints, objectives, both
0 0 0 1 # linear network variables; functions; arith, flags
0 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o)
0 20 # nonzeros in Jacobian, obj. gradient
0 24 # nonzeros in Jacobian, obj. gradient
0 0 # max name lengths: constraints, variables
0 0 0 0 0 # common exprs: b,c,o,c1,o1
O0 0
Expand Down Expand Up @@ -4688,6 +4688,214 @@ v1
n1
n11.0
O13 0
o54
5
o2
n1e-06
o3
o2
n1.00697
o39
o3
n304.1282
v1
o44
o54
5
o2
n-0.491266
o43
o2
n0.003980955110750172
o3
n304.1282
v1
o2
n0.05211155
o5
o43
o2
n0.003980955110750172
o3
n304.1282
v1
n2
o2
n0.05347906
o5
o43
o2
n0.003980955110750172
o3
n304.1282
v1
n3
o2
n-0.01537102
o5
o43
o2
n0.003980955110750172
o3
n304.1282
v1
n4
n0.235156
o2
n1.57384906252112e-05
o5
v0
n2
o3
o2
n2.520982077166146e-07
o5
v0
n6
o5
o2
n0.003980955110750172
o3
n304.1282
v1
n3
o2
n6.79061637521279e-08
o5
v0
n8
o3
o2
n-3.7206647667281035e-08
o5
v0
n8
o2
n0.003980955110750172
o3
n304.1282
v1
O14 0
o2
n0.001
o54
4
o3
o2
o2
n0.475598
o39
o3
n304.1282
v1
o0
o2
n0.4
o2
o44
o3
n-183.5
o3
n304.1282
v1
o54
5
o2
n0.0002387869
o3
n304.1282
v1
o2
n-10.33404
o5
o2
n0.01
o3
n304.1282
v1
n-1
o2
n7.98159
o5
o2
n0.01
o3
n304.1282
v1
n-2
o2
n-1.940558
o5
o2
n0.01
o3
n304.1282
v1
n-3
n4.350794
n1.4
o54
6
o3
n0.6280115
o2
n0.003980955110750172
o3
n304.1282
v1
o3
n-0.5387661
o5
o2
n0.003980955110750172
o3
n304.1282
v1
n2
o3
n0.6735941
o5
o2
n0.003980955110750172
o3
n304.1282
v1
n3
o3
n-0.4362677
o5
o2
n0.003980955110750172
o3
n304.1282
v1
n6
o3
n0.2255388
o5
o2
n0.003980955110750172
o3
n304.1282
v1
n7
n0.4226159
o2
n8.705605e-08
o5
v0
n2
o2
n-6.54795e-11
o5
v0
n3
o2
n6.594919e-14
o5
v0
n4
O15 0
n0.0
x0
r
Expand Down Expand Up @@ -4729,3 +4937,9 @@ G11 1
1 0
G12 1
1 0
G13 2
0 1.9036552444000002e-06
1 0
G14 2
0 2.447164e-08
1 0
Loading

0 comments on commit db3d29c

Please sign in to comment.