Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Rusty

Active Coder
It seem the first for loop is not incrementing. Supposed to populate the x1 array with 0 to 1 in 0.01 increments.

Then seems like the second for loop is not terminating. Thanks for help/advice.

C:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define NUM_MIXTURE_PERCENTAGES 101

/************Function Prototypes************************************************/
double calc_gamma_e(double x1, double x2);
double calc_gamma_w(double x1, double x2);
double calc_psat (double Antoine_A, double Antoine_B, double Antoine_C, double seed_temp, double gamma, double x);

/****************************************************************************/

/*Antoine Coefficients (C)*/
double eA = 8.13484;
double eB = 1662.48;
double eC = 238.131;

double wA = 8.05573;
double wB = 1723.64;
double wC = 233.076;

/*******************************************************/
int main()
{

double boil_pt[NUM_MIXTURE_PERCENTAGES] = {0};
double x1[NUM_MIXTURE_PERCENTAGES] = {0};
double x2[NUM_MIXTURE_PERCENTAGES] = {0};

double p_sat1[NUM_MIXTURE_PERCENTAGES] = {0};
double p_sat2[NUM_MIXTURE_PERCENTAGES] = {0};

for(int i = 0; i < NUM_MIXTURE_PERCENTAGES; i++)//Initialize liquid mol fraction from 0 to 1
  {
    x1[i]= i * 0.01;
    x2[i] = 1 - x1[i];
  }
double atm_press = 760;
/****************************************/
for (int index = 0; index < NUM_MIXTURE_PERCENTAGES; index++)
{
    double seed_temp = 70;
    double gamma_e = calc_gamma_e(x1[index], x2[index]);
    double gamma_w = calc_gamma_w(x1[index], x2[index]);


    do {
        p_sat1[index] = calc_psat(eA, eB, eC, seed_temp, gamma_e, x1[index]);
        p_sat2[index] = calc_psat(wA, wB, wC, seed_temp, gamma_w, x2[index]);
        seed_temp = seed_temp + 0.0001;
        printf("\n %lf\t\t\t%lf,", p_sat1[index], p_sat2[index] );
    }
    while (p_sat1[index] + p_sat2[index] < atm_press);

    boil_pt[index] = seed_temp;

    printf("\n pressure = %.4lf\ttemp = %.2lf", p_sat1[index] + p_sat2[index], boil_pt[index]);

    index++;
    printf("\n %lf\t\t\t%lf,", x1[index], x2[index] );
}
 system("PAUSE");

return (0);
}
/**********************FUNCTIONS*****************************/

/*Calculate Van Laar activity coefficient for ethanol*/
double calc_gamma_e(double x1, double x2)
{
double const a12 = 1.68811;/*a12 and a21 are Van Laar activity model constants*/
double const a21 = 0.95268;
double result = exp((a12 * pow(x2, 2)) / (pow(((a12 * x1 / a21) + x2), 2)));
return (result);
}
/***************************************************/
/*Calculate Van Laar activity coefficient for water*/
double calc_gamma_w(double x1, double x2)
{
double const a12 = 1.68811;
double const a21 = 0.95268;
double result = exp((a21 * pow(x1, 2)) /  (pow(((a21 * x2 / a12) + x1), 2)));
return (result);
}
/***************************************************/

// Antoine Eq. to calculate saturated vapor pressure for water and ethanol
double calc_psat(double A, double B, double C, double st, double gamma, double x)
{
double psat = x*gamma*pow(10, (A-((B)/(C + st))));
return psat;
}
 
It seem the first for loop is not incrementing. Supposed to populate the x1 array with 0 to 1 in 0.01 increments.

Then seems like the second for loop is not terminating. Thanks for help/advice.

C:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define NUM_MIXTURE_PERCENTAGES 101

/************Function Prototypes************************************************/
double calc_gamma_e(double x1, double x2);
double calc_gamma_w(double x1, double x2);
double calc_psat (double Antoine_A, double Antoine_B, double Antoine_C, double seed_temp, double gamma, double x);

/****************************************************************************/

/*Antoine Coefficients (C)*/
double eA = 8.13484;
double eB = 1662.48;
double eC = 238.131;

double wA = 8.05573;
double wB = 1723.64;
double wC = 233.076;

/*******************************************************/
int main()
{

double boil_pt[NUM_MIXTURE_PERCENTAGES] = {0};
double x1[NUM_MIXTURE_PERCENTAGES] = {0};
double x2[NUM_MIXTURE_PERCENTAGES] = {0};

double p_sat1[NUM_MIXTURE_PERCENTAGES] = {0};
double p_sat2[NUM_MIXTURE_PERCENTAGES] = {0};

for(int i = 0; i < NUM_MIXTURE_PERCENTAGES; i++)//Initialize liquid mol fraction from 0 to 1
  {
    x1[i]= i * 0.01;
    x2[i] = 1 - x1[i];
  }
double atm_press = 760;
/****************************************/
for (int index = 0; index < NUM_MIXTURE_PERCENTAGES; index++)
{
    double seed_temp = 70;
    double gamma_e = calc_gamma_e(x1[index], x2[index]);
    double gamma_w = calc_gamma_w(x1[index], x2[index]);


    do {
        p_sat1[index] = calc_psat(eA, eB, eC, seed_temp, gamma_e, x1[index]);
        p_sat2[index] = calc_psat(wA, wB, wC, seed_temp, gamma_w, x2[index]);
        seed_temp = seed_temp + 0.0001;
        printf("\n %lf\t\t\t%lf,", p_sat1[index], p_sat2[index] );
    }
    while (p_sat1[index] + p_sat2[index] < atm_press);

    boil_pt[index] = seed_temp;

    printf("\n pressure = %.4lf\ttemp = %.2lf", p_sat1[index] + p_sat2[index], boil_pt[index]);

    index++;
    printf("\n %lf\t\t\t%lf,", x1[index], x2[index] );
}
system("PAUSE");

return (0);
}
/**********************FUNCTIONS*****************************/

/*Calculate Van Laar activity coefficient for ethanol*/
double calc_gamma_e(double x1, double x2)
{
double const a12 = 1.68811;/*a12 and a21 are Van Laar activity model constants*/
double const a21 = 0.95268;
double result = exp((a12 * pow(x2, 2)) / (pow(((a12 * x1 / a21) + x2), 2)));
return (result);
}
/***************************************************/
/*Calculate Van Laar activity coefficient for water*/
double calc_gamma_w(double x1, double x2)
{
double const a12 = 1.68811;
double const a21 = 0.95268;
double result = exp((a21 * pow(x1, 2)) /  (pow(((a21 * x2 / a12) + x1), 2)));
return (result);
}
/***************************************************/

// Antoine Eq. to calculate saturated vapor pressure for water and ethanol
double calc_psat(double A, double B, double C, double st, double gamma, double x)
{
double psat = x*gamma*pow(10, (A-((B)/(C + st))));
return psat;
}
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom