Keenan

/********************************************/
/*  Name:  Keenan Witmer  Date:  02/26/16   */
/*  Seat:  N/A  File:  FluidMechanicsV2.cp  */
/*  Instructor:  DMG   12:40                */
/********************************************/

#include <stdio.h>
#include <cmath>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

int main ()
{
 printf(“********************************************\n”);
 printf(“*  Name:  Keenan Witmer  Date:  02/26/16   *\n”);
 printf(“*  Seat:  N/A  File:  FluidMechanicsV1.cpp *\n”);
 printf(“*  Instructor:  DMG       12:40PM          *\n”);
 printf(“********************************************\n”);

 /*This program calculates the nth parameter, average velocity, shear stress along the wall, reynold’s number, and entrance length from the given volumetric flow rate, width, height, length of channel, delta p, and viscosity.*/

 /*Instructions: run program, enter inputs as requested (0 for missing), indicate missing parameter, receive output. From there, if you want to plot, run the matlab program FluidMechanicsPlotter.m and make sure that the output file FluidMechanicsResult.txt is where it needs to be for matlab to open it too. Titles, axis labels, etc. were added in post.*/

 //Variables
 float vflow = 0; float width = 0; float height = 0; float length = 0; float deltaP = 0; float viscosity = 0; float vavg = 0; float shear = 0; float Re = 0; float elength = 0;
 int n = 0;
 
 std::cout << std::fixed << std::setprecision(4);

 //Receive input (vflow, width, height, length, deltaP, viscosity)
 cout << endl << “Enter inputs now. Enter 0 for missing parameter.” << endl << “Volumetric flow rate: “;
 cin >> vflow;
 cout << endl << “Width: “;
 cin >> width;
 cout << endl << “Height: “;
 cin >> height;
 cout << endl << “Length: “;
 cin >> length;
 cout << endl << “Delta P: “;
 cin >> deltaP;
 cout << endl << “Viscosity: “;
 cin >> viscosity;

 //Determine nth parameter
 cout << endl << “Choose nth parameter” << endl << “—————————-” << endl << “(1) Volumetric flow rate” << endl << “(2) Width” << endl << “(3) Height” << endl << “(4) Length” << endl << “(5) Delta P” << endl << “(6) Viscosity” << endl;
 cin >> n;
 cout << endl;

 //Calculate nth parameter
 switch (n){
 case 1:
   vflow = width * height * height * height * deltaP / (12 * viscosity * length);
   cout << “Volumetric flow rate: ” << vflow << ” cm^3/s” << endl;
   break;
 case 2:
   width = 12 * viscosity * length * vflow / (height * height * height * deltaP);
   cout << “Width:                ” << width << ” cm” << endl;
   break;
 case 3:
   height = pow(12 * viscosity * length * vflow / (width * deltaP), 1/3);
   cout << “Height:               ” << height << ” cm” << endl;
   break;
 case 4:
   length = width * height * height * height * deltaP / (12 * viscosity * vflow);
   cout << “Length:               ” << length << ” cm” << endl;
 case 5:
   deltaP = 12 * viscosity * length * vflow / (height * height * height * width);
   cout << “Delta P:              ” << deltaP << ” dynes/cm^2″ << endl;
   break;
 case 6:
   viscosity = width * height * height * height * deltaP / (12 * length * vflow);
   cout << “Viscosity:            ” << viscosity << ” g/cm*s” << endl;
   break;}
 
 //Calculate remaining variables
 vavg = height * height * deltaP / (12 * viscosity * length);
 cout << “Average Velocity:     ” << vavg << ” cm/s” << endl;
 shear = height * deltaP / (2 * length);
 cout << “Shear Stress at Wall: ” << shear << ” dynes/cm^2″ << endl;
 Re = vavg * 4 * width * height / (2 * viscosity * (width + height));
 cout << “Reynold’s Number:     ” << Re << endl;
 elength = 0.06 * Re * 4 * width * height / (2 * (width + height));
 cout << “Entrance Length:      ” << elength << ” cm” << endl;

 float x[10];
 float v[10];
 float ss[10];
 ofstream fout;
 fout.open(“FluidMechanics_Result.txt”);
 //Create matrices for velocity & shear stress plots and export to text
 for (int i = -5; i < 6; i++){
   x[i+5] = (height / 5) * i;}
 for (int j = 0; j < 11; j++){
   v[j] = deltaP * (height * height – 4 * x[j] * x[j]) / (8 * viscosity * length);
   ss[j] = deltaP * abs(x[j]) / length;
   fout << x[j] << ”   ” << v[j] << ”   ” << ss[j] << endl;}}