f_gasMixtureConductivity = CFunction(
    Ccode=weightedAverageCode,
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 273,
            'max': 550
        },
        'x': {
            'index': gasConductivity.species,
            'min': 0,
            'max': 1
        },
        'gas_thermal_conductivity': {
            'index': gasConductivity.species,
            'min': 0,
            'max': 1
        },
    },
    outputs={
        'gasMixtureConductivity': {
            'min': 0,
            'max': +9e99,
            'argPos': 0
        },
    },
    parameters={
        'param0': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 0
        },
        'param1': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 1
        },
        'param2': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 2
        },
    },
)
Example #2
0
f_dummy = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"
#include <stdio.h>

void rheology_dummy_SM
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double lambda = parameters[0];
    const double alpha = parameters[1];
    const double n_rh = parameters[2];

    const double A_mu = 0.0387; // could be loaded from some library for consistence
    const double E_mu = 10000;
    const double R_rh = 8.314;
    const double mu_a = 1.5;
    const double mu_b = 1;
    const double mu_c = 0;
    const double mu_d = 0.001;
    const double X_gel = ''' + str(X_gel) + ''';
    const double mu_0_const = 0.195;
    const double mu_inf_const = 0.266;

    double mu_0, mu_inf;
    double mu_car;

    if (X<X_gel) {
        mu_0 = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2))) * mu_0_const;
        mu_inf = (log(X+mu_d) - log(mu_d) + pow(X_gel / ( X_gel - X ), mu_a + X*mu_b + mu_c*pow(X,2)))* mu_inf_const;

        mu_car = (mu_inf + (mu_0 - mu_inf)*pow(1 + pow(lambda*shear,alpha), (n_rh - 1) / alpha));
    } else {
        mu_car = 1e6;
    }
    //    printf("apparent viscosity car %f", mu_car);
    outputs[0] = mu_car;
}
''',
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 0,
            'max': 550
        },
        'shear': {
            'min': 0,
            'max': 9e99
        },
        'X': {
            'min': 0,
            'max': 1
        },
        'm0': {
            'min': 0,
            'max': 9e99
        },
        'm1': {
            'min': 0,
            'max': 9e99
        },
        'mu': {
            'min': 0,
            'max': 1000
        },
        'ST': {
            'min': 0,
            'max': 100
        },
    },
    outputs={
        'mu_car': {
            'min': 0,
            'max': 9e99,
            'argPos': 0
        },
    },
    parameters={
        'lamdba': {
            'min': 1.35,
            'max': 21.35,
            'argPos': 0
        },
        'alpha': {
            'min': 0,
            'max': 2,
            'argPos': 1
        },
        'n_rh': {
            'min': 0,
            'max': 2,
            'argPos': 2
        },
    },
)
Example #3
0
f = CFunction(
    Ccode= '''
#include "modena.h"
#include "math.h"

void idealGas
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double R = parameters[0];

    outputs[0] = p0/R/T0;
}
''',
    # These are global bounds for the function
    inputs={
        'p0': { 'min': 0, 'max': 9e99 },
        'T0': { 'min': 0, 'max': 9e99 },
    },
    outputs={
        'rho0': { 'min': 9e99, 'max': -9e99, 'argPos': 0 },
    },
    parameters={
        'R': { 'min': 0.0, 'max': 9e99, 'argPos': 0 }
    },
)
Example #4
0
f_polymerViscosity = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"

void viscosity_SM
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double Aeta = parameters[0];
    const double Eeta = parameters[1];
    const double AA = parameters[2];
    const double B = parameters[3];
    const double Xg = parameters[4];

    const double Rg = 8.31446218;

    if (X<Xg) {
        outputs[0] = Aeta*exp(Eeta/(Rg*T))*pow(Xg/(Xg-X),AA+B*X);
    } else {
        outputs[0] = 1e10;
    }
}
''',
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 200,
            'max': 550
        },
        'X': {
            'min': 0,
            'max': 1
        },
    },
    outputs={
        'mu': {
            'min': 0,
            'max': +9e99,
            'argPos': 0
        },
    },
    parameters={
        'param1': {
            'min': -1e9,
            'max': 1e9,
            'argPos': 0
        },
        'param2': {
            'min': -1e9,
            'max': 1e9,
            'argPos': 1
        },
        'param3': {
            'min': -1e9,
            'max': 1e9,
            'argPos': 2
        },
        'param4': {
            'min': -1e9,
            'max': 1e9,
            'argPos': 3
        },
        'param5': {
            'min': -1e9,
            'max': 1e9,
            'argPos': 4
        },
    },
)
Example #5
0
f = CFunction(
    Ccode= '''
#include "modena.h"
#include "math.h"
#include <stdio.h>

void Arrhenius
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double A_mu = 0.0387; // could be loaded from some library for consistence
    const double E_mu = 10000;
    const double R_rh = 8.314;

    double f_t, mu_ap;

    f_t = A_mu * exp(E_mu / R_rh / T );

    mu_ap = mu_car * f_t;
    // printf("apparent viscosity %f", mu_ap);
    outputs[0] = mu_ap;
}
''',
   inputs={
       'T': {'min': 0, 'max': 9e99 },
       'shear': {'min': 0, 'max': 9e99 },
       'X': {'min': 0, 'max': 1 },
       'm0' : {'min': 0, 'max' : 9e99},
       'm1' : {'min': 0, 'max' : 9e99},
       'mu' : {'min': 0, 'max' : 9e99},
       'ST' : {'min': 0, 'max' : 9e99},
       'mu_car' : {'min': 0, 'max' : 9e99},
   },
   outputs={
       'mu_ap': { 'min': 0, 'max': 9e99, 'argPos': 0 },
   },
   parameters={
       'Rgas' : {'min': 8.31, 'max': 8.32, 'argPos': 0},
   }
)
Example #6
0
f = CFunction(
    Ccode=r'''
#include "modena.h"
#include "math.h"

void surroSurfaceTension
(
const modena_model_t* model,
const double* inputs,
double *outputs
)
{
{% block variables %}{% endblock %}

const double P0 = parameters[0];
const double P1 = parameters[1];
const double P2 = parameters[2];

outputs[0] = P0 + T*P1 + P2*T*T;
}
''',
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 270.0,
            'max': 310.0
        },  #check if boundaries reasonable, from this range, the random values for the DOE are chosen!
    },
    outputs={
        'ST': {
            'min': 9e99,
            'max': -9e99,
            'argPos': 0
        },
    },
    parameters={
        'param0': {
            'min': -1E10,
            'max': 1E10,
            'argPos': 0
        },  #check if boundaries are reasonable!!!
        'param1': {
            'min': -1E10,
            'max': 1E10,
            'argPos': 1
        },
        'param2': {
            'min': -1E10,
            'max': 1E10,
            'argPos': 2
        },
    },
    species={
        'A': blowing_agents,
        'B': monomers
    })
Example #7
0
f_backward = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"
void two_tank_flowRate
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}


    const double C1 = parameters[0];
    const double C2 = parameters[1];

    const double E_PU = 2400;
    const double rho_PU = 1200;

    outputs[0] = E_PU*(C1*pow(strut_content*rho/rho_PU,2) + C2*(1-strut_content)*(rho/rho_PU));
}
''',
    # These are global bounds for the function
    inputs={
        'rho': {
            'min': 0,
            'max': 1e5
        },
        'strut_content': {
            'min': 0,
            'max': 1e5
        },
        'Mu': {
            'min': 0,
            'max': 1e5
        },
        'Sigma': {
            'min': 0,
            'max': 1e5
        },
    },
    outputs={
        'E': {
            'min': 9e99,
            'max': -9e99,
            'argPos': 0
        },
    },
    parameters={
        'C1': {
            'min': 0.0,
            'max': 10.0,
            'argPos': 0
        },
        'C2': {
            'min': 0.0,
            'max': 10.0,
            'argPos': 1
        },
    },
)
Example #8
0
f_polymer_thermal_conductivity = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"

void thermal_conductivity
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double a = parameters[0];
    const double b = parameters[1];

    outputs[0] = (a*T)+b;
}
''',
    # These are global bounds for the function
    inputs={
        'T': {'min': 273, 'max': 550},
    },
    outputs={
        'polymer_thermal_conductivity': {
            'min': 0, 'max': +9e99, 'argPos': 0
        },
    },
    parameters={
        'param0': {'min': -9e99, 'max': +9e99, 'argPos': 0},
        'param1': {'min': -9e99, 'max': +9e99, 'argPos': 1},
    },
)
Example #9
0
f = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"
#define MAX(a,b) ((a) > (b) ? a : b)
void strutContent
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double a = parameters[0];
    const double b = parameters[1];
    const double c = parameters[2];
    const double pi = 3.14159;

    outputs[0] = MAX(atan(a*rho + b)/pi*2,0.0);
}
''',
    # These are global bounds for the function
    inputs={
        'rho': {
            'min': 0,
            'max': 1e5
        },
    },
    outputs={
        'fs': {
            'min': 0,
            'max': 1,
            'argPos': 0
        },
    },
    parameters={
        'param0': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 0
        },
        'param1': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 1
        },
        'param2': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 2
        },
    },
)
f = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"
void densityreactionmixture
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}
    
    const double a_L0 = parameters[0];
    const double b_L0 = parameters[1];
    const double a_P0 = parameters[2];
    const double b_P0 = parameters[3];

    outputs[0] = ((a_L0*T + b_L0) + ((a_P0*T + b_P0) - (a_L0*T + b_L0))*XOH);
}
''',
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 273,
            'max': 450
        },
        'XOH': {
            'min': 0,
            'max': 1
        },
    },
    outputs={
        'density_polymer': {
            'min': 0,
            'max': 8000,
            'argPos': 0
        },
    },
    parameters={
        'param0': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 0
        },
        'param1': {
            'min': 0.0,
            'max': +9e99,
            'argPos': 1
        },
        'param2': {
            'min': -9e99,
            'max': +9e99,
            'argPos': 2
        },
        'param3': {
            'min': 0.0,
            'max': +9e99,
            'argPos': 3
        },
    },
)
Example #11
0
f = CFunction(Ccode=r'''
#include "modena.h"
#include "math.h"

void surroSurfaceTension
(
const modena_model_t* model,
const double* inputs,
double *outputs
)
{
{% block variables %}{% endblock %}

const double P0 = parameters[0];
const double P1 = parameters[1];
const double P2 = parameters[2];

outputs[0] = P0 + T*P1 + P2*T*T;
}
''',
              inputs={
                  'T': {
                      'min': 270.0,
                      'max': 550.0
                  },
              },
              outputs={
                  'ST': {
                      'min': 9e99,
                      'max': -9e99,
                      'argPos': 0
                  },
              },
              parameters={
                  'param0': {
                      'min': -1E10,
                      'max': 1E10,
                      'argPos': 0
                  },
                  'param1': {
                      'min': -1E10,
                      'max': 1E10,
                      'argPos': 1
                  },
                  'param2': {
                      'min': -1E10,
                      'max': 1E10,
                      'argPos': 2
                  },
              },
              species={
                  'A': blowing_agents,
                  'B': monomers,
                  'C': surfactant,
              })
Example #12
0
f = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"

void surroDensity
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{

    {% block variables %}{% endblock %}

    const double P0 = parameters[0];
    const double P1 = parameters[1];
    const double P2 = parameters[2];

    const double expo = 1.0 + (1.0 - T/P2);
    const double pwr  = pow(P1,expo);

    outputs[0] = P0 / pwr;
    //outputs[0] = P0 + T*P1 + P2*T*T;
}
''',
    # These are global bounds for the function
    inputs={
        'T': {
            'min': 270.0,
            'max': 550.0
        },
    },
    outputs={
        'rho': {
            'min': 9e99,
            'max': -9e99,
            'argPos': 0
        },
    },
    parameters={
        'param0': {
            'min': -1E10,
            'max': 1E10 + 2,
            'argPos': 0
        },  #check if boundaries are reasonable!!!
        'param1': {
            'min': -1E10,
            'max': 1E10 + 2,
            'argPos': 1
        },
        'param2': {
            'min': -1E10,
            'max': 1E10 + 2,
            'argPos': 2
        },
    },
    species={
        'A': blowing_agents,
        'B': monomers
    })
Example #13
0
f = CFunction(
    Ccode= '''
#include "modena.h"
#include "math.h"

void surroSolubility
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double P0 = parameters[0];
    const double P1 = parameters[1];
    const double P2 = parameters[2];

    const double term1 = P1*(1/T - 1/P2);
    const double term2 = exp(term1);

    outputs[0] = P0*term2;

    //outputs[0] = P0 + T*P1 + P2*T*T;
}
''',
    # These are global bounds for the function
    inputs={
        'T': { 'min': 200.0, 'max': 250.0 },        #check if boundaries reasonable, from this range, the random values for the DOE are chosen!
    },
    outputs={
        'H': { 'min': 9e99, 'max': -9e99, 'argPos': 0 },
    },
    parameters={
        'param0': { 'min': -1E10, 'max': 1E10, 'argPos': 0 },    #check if boundaries are reasonable!!!
        'param1': { 'min': -1E10, 'max': 1E10, 'argPos': 1 },
        'param2': { 'min': 1.0, 'max': 1E10, 'argPos': 2 },
    },
)
Example #14
0
f = CFunction(
    Ccode= '''
#include "modena.h"
#include "math.h"

void two_tank_flowRate
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double D = inputs[0];
    const double rho0 = inputs[1];
    const double p0 = inputs[2];
    const double p1 = p0*inputs[3];

    const double P0 = parameters[0];
    const double P1 = parameters[1];

    outputs[0] = M_PI*pow(D, 2.0)*P1*sqrt(P0*rho0*p0);
}
''',
    # These are global bounds for the function
    inputs={
        'D': { 'min': 0, 'max': 9e99 },
        'T0': { 'min': 0, 'max': 9e99 },
        'p0': { 'min': 0, 'max': 9e99 },
        'p1Byp0': { 'min': 0, 'max': 1.0 },
    },
    outputs={
        'flowRate': { 'min': 9e99, 'max': -9e99, 'argPos': 0 },
    },
    parameters={
        'param0': { 'min': 0.0, 'max': 10.0, 'argPos': 0 },
        'param1': { 'min': 0.0, 'max': 10.0, 'argPos': 1 },
    },
)
Example #15
0
f_diffusivity = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"

void diffusivityPol
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double a = parameters[0];
    const double b = parameters[1];

    outputs[0] = a*exp(-(b*(1/T)));
}
''',
    # These are global bounds for the function
    inputs={
        'T': {'min': 273, 'max': 450},
    },
    outputs={
        'diffusivity': {'min': 0, 'max': +9e99, 'argPos': 0},
    },
    parameters={
        'param0[A]': {'min': 0.0, 'max': +9e99, 'argPos': 0},
        'param1[A]': {'min': 0.0, 'max': +9e99, 'argPos': 1},
    },
    indices={
        'A': species,
    },
)
Example #16
0
f_foamConductivity = CFunction(
    Ccode='''
#include "modena.h"
#include "math.h"

void tcfoam_SM
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double alpha = parameters[1];
    const double beta = parameters[0];

    const double sigma=5.67e-8;

    double fs,Xs,Xw,X,kappa,kr;
    double kfoam;
    double kgas=gasMixtureConductivity;
    double kpol=polymer_thermal_conductivity;

    fs=alpha*fstrut;
    Xs=(1+4*kgas/(kgas+kpol))/3.0;
    Xw=2*(1+kgas/(2*kpol))/3.0;
    X=(1-fs)*Xw+fs*Xs;
    kappa=4.09*sqrt(1-eps)/dcell;
    kr=16*sigma*pow(T,3)/(3*kappa);
    kfoam = (kgas*eps+kpol*X*(1-eps))/(eps+(1-eps)*X)+beta*kr;

    outputs[0] = kfoam;
}
''',
    # These are global bounds for the function
    inputs={
        'eps': {
            'min': 0,
            'max': 0.995
        },
        'dcell': {
            'min': 0,
            'max': 1e-1
        },
        'fstrut': {
            'min': 0,
            'max': 1
        },
        'gasMixtureConductivity': {
            'min': 0,
            'max': 1e-1
        },
        'polymer_thermal_conductivity': {
            'min': 0,
            'max': 1e0
        },
        'T': {
            'min': 273,
            'max': 550
        },
        'x': {
            'index': gasConductivity.species,
            'min': 0,
            'max': 1
        },
    },
    outputs={
        'kfoam': {
            'min': 0,
            'max': 1e0,
            'argPos': 0
        },
    },
    parameters={
        'param1': {
            'min': -1e9,
            'max': 1e9 + 2,
            'argPos': 0
        },
        'param2': {
            'min': -1e9,
            'max': 1e9 + 2,
            'argPos': 1
        },
    },
)
Example #17
0
    'xl1': {
        'min': 0.0,
        'max': 1.0
    },
    'xl2': {
        'min': 0.0,
        'max': 1.0
    },
    'xl3': {
        'min': 0.0,
        'max': 1.0
    },
}
f2 = CFunction(Ccode=Ccode2,
               inputs=inputs2,
               outputs=outputs,
               parameters=parameters,
               indices=indices)
f3 = CFunction(Ccode=Ccode3,
               inputs=inputs3,
               outputs=outputs,
               parameters=parameters4,
               indices=indices)

outOfBoundsStrategy = Strategy.ExtendSpaceStochasticSampling(nNewPoints=4)
parameterFittingStrategy = Strategy.NonLinFitWithErrorContol(
    testDataPercentage=0.2,
    maxError=0.1,
    improveErrorStrategy=Strategy.StochasticSampling(nNewPoints=2),
    maxIterations=5  # Currently not used
)
Example #18
0
f = CFunction(
    inputs={
        'T': { 'min': 0, 'max': 9e99 },
        'p': { 'min': 0, 'max': 9e99 },
    },
    outputs={
        'D[A]': { 'min': 0, 'max': 9e99, 'argPos': 0 },
    },
    parameters={
        'W[A]': { 'min': 0, 'max': 9e99, 'argPos': 0 },
        'V[A]': { 'min': 0, 'max': 9e99, 'argPos': 1 },
        'W[B]': { 'min': 0, 'max': 9e99, 'argPos': 2 },
        'V[B]': { 'min': 0, 'max': 9e99, 'argPos': 3 },
    },
    indices={
        'A': species,
        'B': species,
    },
    Ccode= '''
#include "modena.h"
#include "math.h"

void fullerEtAlDiffusion
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    const double WA = parameters[0];
    const double VA = parameters[1];
    const double WB = parameters[2];
    const double VB = parameters[3];

    outputs[0] = 1.011e-4*pow(T, 1.75)*pow(1.0/WA + 1.0/WB, 1.0/2.0);
    outputs[0] /= p*(pow(pow(VA, 1.0/3.0) + pow(VB, 1.0/3.0), 2.0));
}
''',
)
Example #19
0
f_gasMixtureConductivity = CFunction(
    Ccode=r'''
#include "modena.h"
#include "math.h"
#include "stdio.h"

void gasMixtureConductivity
(
    const modena_model_t* model,
    const double* inputs,
    double *outputs
)
{
    {% block variables %}{% endblock %}

    double kgasmix=0; // gas mixture conductivity
    int i;

    //printf("temp = %g\n", T);
    //printf("x = ");
    //for (i=0;i<x_size;i++) {
    //    printf("%g ", x[i]);
    //}
    //printf("\n");
    //printf("k = ");
    //for (i=0;i<x_size;i++) {
    //    printf("%g ", gas_thermal_conductivity[i]);
    //}
    //printf("\n");

    for (i=0;i<x_size;i++) {
        kgasmix = kgasmix + parameters[i]*gas_thermal_conductivity[i]*x[i];
    }
    outputs[0] = kgasmix;
}
''',
    # These are global bounds for the function
    inputs={
        'T': {'min': 273, 'max': 450},
        'x': {'index': gasConductivity.species, 'min': 0, 'max': 1},
        'gas_thermal_conductivity': {'index': gasConductivity.species, 'min': 0, 'max': 1},
    },
    outputs={
        'gasMixtureConductivity': {'min': 0, 'max': +9e99, 'argPos': 0},
    },
    parameters={
        'param0': {'min': -9e99, 'max': +9e99, 'argPos': 0},
        'param1': {'min': -9e99, 'max': +9e99, 'argPos': 1},
        'param2': {'min': -9e99, 'max': +9e99, 'argPos': 2},
    },
)