OpenWAM
TControlK.cpp
1 /*--------------------------------------------------------------------------------*\
2 ==========================|
3  \\ /\ /\ // O pen | OpenWAM: The Open Source 1D Gas-Dynamic Code
4  \\ | X | // W ave |
5  \\ \/_\/ // A ction | CMT-Motores Termicos / Universidad Politecnica Valencia
6  \\/ \// M odel |
7  ----------------------------------------------------------------------------------
8  License
9 
10  This file is part of OpenWAM.
11 
12  OpenWAM is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenWAM is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenWAM. If not, see <http://www.gnu.org/licenses/>.
24 
25 
26  \*--------------------------------------------------------------------------------*/
27 
28 //---------------------------------------------------------------------------
29 #pragma hdrstop
30 
31 #include "TControlK.h"
32 
33 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
35 
36 TControlK::TControlK() {
37 
38 }
39 
40 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
42 
43 TControlK::~TControlK() {
44 
45 }
46 
47 //---------------------------------------------------------------------------
48 //---------------------------------------------------------------------------
49 
50 void TControlK::LeeDatosEntrada(char *Ruta, FILE *fich, double DiametroTubo) {
51  char *FileK_Re;
52  char *DatosK_Re;
53 
54  try {
55 
56  FDiametro = DiametroTubo;
57  for(int i = 0; i <= (int) strlen(Ruta); i++) {
58  DatosK_Re[i] = Ruta[i];
59  }
60 
61  fscanf(fich, "%s ", &FileK_Re);
62  strcat(DatosK_Re, FileK_Re);
63 
64  FichK_Re = fopen(DatosK_Re, "r");
65  if((FichK_Re = fopen(DatosK_Re, "r")) == NULL) {
66  std::cout << "ERROR: Fichero de K vs Re no cargado";
67  } else {
68  fscanf(FichK_Re, "%d ", &FNumeroDatos);
69  FVector_Re = new double[FNumeroDatos];
70  FVector_K = new double[FNumeroDatos];
71 
72  for(int i = 0; i < FNumeroDatos; i++) {
73  fscanf(FichK_Re, "%lf ", &FVector_Re[i]);
74  }
75 
76  for(int i = 0; i < FNumeroDatos; i++) {
77  fscanf(FichK_Re, "%lf ", &FVector_K[i]);
78  }
79 
80  fclose(FichK_Re);
81  }
82 
83  } catch(exception &N) {
84  std::cout << "ERROR: TControlK::LeeDatosEntrada (DLL)" << std::endl;
85  std::cout << "Tipo de error: " << N.what() << std::endl;
86  throw Exception(N.what());
87  }
88 }
89 
90 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
92 
93 void TControlK::CalculaK(double velocidad, double temperatura, double presion, double R_mezcla) {
94  try {
95  double viscgas = 0., rho = 0., deltaRe = 0., VariacionRe = 0., K_Actual = 0.;
96  int i = 0;
97 
98  viscgas = 1.4615e-6 * pow150(__units::degCToK(temperatura)) / (__units::degCToK(temperatura) + 110.4);
99  rho = __units::BarToPa(presion) / __units::degCToK(temperatura) / R_mezcla;
100  FRe = rho * velocidad * FDiametro / viscgas;
101 
102  FK = Interp1(FRe, FVector_Re, FVector_K, FNumeroDatos);
103 
104  } catch(exception &N) {
105  std::cout << "ERROR: TControlK::CalculaK (DLL)" << std::endl;
106  std::cout << "Tipo de error: " << N.what() << std::endl;
107  throw Exception(N.what());
108  }
109 }
110 
111 //---------------------------------------------------------------------------
112 //---------------------------------------------------------------------------
113 
114 #pragma package(smart_init)
115 
pow150
T pow150(T x)
Returns x to the power of 1.5.
Definition: Math_wam.h:140
Exception
Custom exception class.
Definition: Exception.hpp:39