11/* !
2- * \file CMLPGas_Template .cpp
2+ * \file CMLPGas .cpp
33 * \brief Source of the data-driven fluid model class using
44 * multilayer perceptrons for data regression
55 * \author E.Bunschoten
2626 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
2727 */
2828
29- #include " ../../include/fluid/CMLPGas_Template .hpp"
29+ #include " ../../include/fluid/CMLPGas .hpp"
3030
31- CMLPGas_Template::CMLPGas_Template (su2double gamma, su2double R, bool CompEntropy) : CFluidModel() {
32- Gamma = gamma;
33- Gamma_Minus_One = Gamma - 1.0 ;
34- Gas_Constant = R;
35- Cp = Gamma / Gamma_Minus_One * Gas_Constant;
36- Cv = Cp - R;
37-
38- ComputeEntropy = CompEntropy;
31+ CMLPGas::CMLPGas (const CConfig* config) : CFluidModel() {
3932
4033 /* Define a CLookUp_ANN object to allow for data regression */
41- ann_input_filename = " MLP_collection.mlp " ;
34+ ann_input_filename = config-> GetMLP_FileName () ;
4235 lookup_ann = new MLPToolbox::CLookUp_ANN (ann_input_filename);
4336
4437 /* Map MLP inputs to outputs for each look-up operation*/
4538 MapInputs_to_Outputs ();
4639}
4740
48- CMLPGas_Template ::~CMLPGas_Template (){
41+ CMLPGas ::~CMLPGas (){
4942 delete iomap_rhoe;
5043 delete iomap_PT;
5144 delete iomap_Prho;
5245 delete lookup_ann;
5346}
54- void CMLPGas_Template ::MapInputs_to_Outputs (){
47+ void CMLPGas ::MapInputs_to_Outputs (){
5548
56- input_names_rhoe.push_back (" rho " );
57- input_names_rhoe.push_back (" e " );
49+ input_names_rhoe.push_back (" Density " );
50+ input_names_rhoe.push_back (" Energy " );
5851
5952 output_names_rhoe.push_back (" Temperature" );
6053 outputs_rhoe.push_back (&Temperature);
@@ -75,49 +68,87 @@ void CMLPGas_Template::MapInputs_to_Outputs(){
7568
7669 iomap_rhoe = new MLPToolbox::CIOMap (lookup_ann, input_names_rhoe, output_names_rhoe);
7770
78- input_names_PT.push_back (" P " );
79- input_names_PT.push_back (" T " );
71+ input_names_PT.push_back (" Pressure " );
72+ input_names_PT.push_back (" Temperature " );
8073
81- output_names_PT.push_back (" rho " );
74+ output_names_PT.push_back (" Density " );
8275 outputs_PT.push_back (&Density);
83- output_names_PT.push_back (" e " );
76+ output_names_PT.push_back (" Energy " );
8477 outputs_PT.push_back (&StaticEnergy);
8578
8679 iomap_PT = new MLPToolbox::CIOMap (lookup_ann, input_names_PT, output_names_PT);
8780
88- input_names_Prho.push_back (" P " );
89- input_names_Prho.push_back (" rho " );
81+ input_names_Prho.push_back (" Pressure " );
82+ input_names_Prho.push_back (" Density " );
9083
91- output_names_Prho.push_back (" e " );
84+ output_names_Prho.push_back (" Energy " );
9285 outputs_Prho.push_back (&StaticEnergy);
9386 iomap_Prho = new MLPToolbox::CIOMap (lookup_ann, input_names_Prho, output_names_Prho);
9487}
9588
96- void CMLPGas_Template::SetTDState_rhoe (su2double rho, su2double e) {
89+ void CMLPGas::SetTDState_rhoe (su2double rho, su2double e) {
90+ Density = rho;
91+ StaticEnergy = e;
9792 vector<su2double> ann_inputs;
9893 ann_inputs.push_back (rho);
9994 ann_inputs.push_back (e);
10095 lookup_ann->Predict_ANN (iomap_rhoe, ann_inputs, outputs_rhoe);
101- }
96+ Cp = (Pressure / (R_u * Density * Temperature)) * 1 / (dTde_rho);
97+ Cv = (1 /dTde_rho);
98+ Gamma = Cp / Cv;
99+ Gamma_Minus_One = Gamma - 1 ;
100+ Gas_Constant = Cp * Gamma_Minus_One;
102101
103- void CMLPGas_Template::SetTDState_PT (su2double P, su2double T) {
104- vector<su2double> ann_inputs;
105- ann_inputs.push_back (P);
106- ann_inputs.push_back (T);
107- lookup_ann->Predict_ANN (iomap_PT, ann_inputs, outputs_PT);
102+ }
108103
109- SetTDState_rhoe (Density, StaticEnergy);
104+ void CMLPGas::SetTDState_PT (su2double P, su2double T) {
105+ // vector<su2double> ann_inputs;
106+ // ann_inputs.push_back(P);
107+ // ann_inputs.push_back(T);
108+ // lookup_ann->Predict_ANN(iomap_PT, ann_inputs, outputs_PT);
109+
110+ su2double rho = 0.5 *(6.9682399336300005e-01 + 2.4896548789900002e+00 );
111+ su2double e = 0.5 *(3.2562734877400001e+05 +4.8566089128400001e+05 );
112+ rho = 1.0 ;
113+ e = 3.2562734877400001e+05 ;
114+ su2double delta_P, delta_T, delta_rho, delta_e, tolerance_P = 10 , tolerance_T = 1.0 ;
115+ su2double determinant, relaxation = 0.1 ;
116+ unsigned long iter = 0 , iter_max = 1000 ;
117+ bool converged= false ;
118+ cout << " Target PT: " << P << " " << T << endl;
119+ while (!converged && (iter < iter_max)){
120+ SetTDState_rhoe (rho, e);
121+ delta_P = (P - Pressure);
122+ delta_T = (T - Temperature);
123+ cout << delta_P << " " << delta_T << endl;
124+ if ((abs (delta_P)<tolerance_P) && (abs (delta_T) < tolerance_T)){
125+ converged = true ;
126+ cout << " Converged PT: " << Pressure << " " << Temperature << endl;
127+ return ;
128+ }else {
129+ determinant = dPdrho_e * dTde_rho - dPde_rho * dTdrho_e;
130+ delta_rho = (dTde_rho * delta_P - dPde_rho * delta_T) / determinant;
131+ delta_T = (-dTdrho_e * delta_P + dPdrho_e * delta_T) / determinant;
132+
133+ rho -= relaxation * delta_rho;
134+ e -= relaxation * delta_e;
135+ }
136+ iter++;
137+ }
138+
139+ SetTDState_rhoe (rho, e);
140+ cout << " Final(nonconverged) PT: " << Pressure << " " << Temperature << endl;
110141}
111142
112- void CMLPGas_Template ::SetTDState_Prho (su2double P, su2double rho) {
143+ void CMLPGas ::SetTDState_Prho (su2double P, su2double rho) {
113144 vector<su2double> ann_inputs;
114145 ann_inputs.push_back (P);
115146 ann_inputs.push_back (rho);
116147 lookup_ann->Predict_ANN (iomap_Prho, ann_inputs, outputs_Prho);
117148 SetTDState_rhoe (rho, StaticEnergy);
118149}
119150
120- void CMLPGas_Template ::SetEnergy_Prho (su2double P, su2double rho) {
151+ void CMLPGas ::SetEnergy_Prho (su2double P, su2double rho) {
121152 vector<su2double> ann_inputs;
122153 ann_inputs.push_back (P);
123154 ann_inputs.push_back (rho);
0 commit comments