/* Copyright Renaud GICQUEL 2026 renaud.gicquel@s4e2.com Ce logiciel est un programme informatique servant à modéliser des systèmes énergétiques. Ce logiciel est régi par la licence CeCILL soumise au droit français et respectant les principes de diffusion des logiciels libres. Vous pouvez utiliser, modifier et/ou redistribuer ce programme sous les conditions de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur le site "http://www.cecill.info". En contrepartie de l'accessibilité au code source et des droits de copie, de modification et de redistribution accordés par cette licence, il n'est offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, seule une responsabilité restreinte pèse sur l'auteur du programme, le titulaire des droits patrimoniaux et les concédants successifs. A cet égard l'attention de l'utilisateur est attirée sur les risques associés au chargement, à l'utilisation, à la modification et/ou au développement et à la reproduction du logiciel par l'utilisateur étant donné sa spécificité de logiciel libre, qui peut le rendre complexe à manipuler et qui le réserve donc à des développeurs et des professionnels avertis possédant des connaissances informatiques approfondies. Les utilisateurs sont donc invités à charger et tester l'adéquation du logiciel à leurs besoins dans des conditions permettant d'assurer la sécurité de leurs systèmes et ou de leurs données et, plus généralement, à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la licence CeCILL, et que vous en avez accepté les termes. This software is a computer program whose purpose is to model energy systems. This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. */ package extThopt; import javax.swing.*; import java.awt.*; import java.util.*; import rg.corps.*; /** * Classe pour calculer un cycle de réfrigération en régime non-nominal * * @author Renaud GICQUEL */ public class RefrigControllerMinPack extends ExtPilot implements optimization.Lmdif_fcn,optimization.Lmdif_fcn2 { boolean isInitialized=false; boolean isBuilt=false; String[]composant,nomComposant,nomNozz; String compressorName="",evaporatorName,condenserName, evapSettings="", condSettings=""; TechnoHx technoEvap, technoCond; VolumCompr technoCompr; double DeltaHcond,Te,Tf,massFlow, DTsurch, DTssrefr, Aevap, Acond, AevapReel, AcondReel, UAevap, UAcond; double tauCompr, DeltaHevap, mCpmin, mCpmax, NUT,R,epsilon, AdesignEvap, AdesignCond, lambdaVol; double TamontCompr, PamontCompr, DeltaH0,T2,Tevap, Pevap,Vevap,Hevap,DeltaH_NH3, Tair, rotationSpeed, Pcond, mCpRefrigEvap, mCpRefrigCond, mCpCalopEvap, mCpCalopCond, Tcond; double a0_value=0.96, alpha_value=0.038, N_value=872.7969721981, Vs_value=0.0199; PointThopt amontEvap, avalEvap, amontCond, avalCond, waterInlet, inAir, waterOutlet, outAir; String tab=new String("\t"); String ligne=new String("\n"); Corps refrig; boolean debug=false; // epsmch is the machine precision static final double epsmch = 2.22044604926e-16; int nfev = 0; int njev = 0; int nfev2 = 0; int njev2 = 0; public RefrigControllerMinPack() { //{{INIT_CONTROLS setTitle("Refrigeration controller"); getContentPane().setLayout(null); setSize(640,600); setVisible(false); bInitialSettings.setText("Initial settings"); bInitialSettings.setActionCommand("load"); getContentPane().add(bInitialSettings); bInitialSettings.setBounds(420,12,156,36); JLabel6.setText("evaporation pressure"); getContentPane().add(JLabel6); JLabel6.setForeground(java.awt.Color.red); JLabel6.setBounds(12,396,156,24); getContentPane().add(Pevap_value); Pevap_value.setBounds(180,396,120,24); Pevap_value.setSelectionColor(new java.awt.Color(204,204,255)); Pevap_value.setSelectedTextColor(java.awt.Color.black); Pevap_value.setCaretColor(java.awt.Color.black); Pevap_value.setDisabledTextColor(new java.awt.Color(153,153,153)); Pevap_value.setEditable(false); JLabel4.setText("condensation pressure"); getContentPane().add(JLabel4); JLabel4.setForeground(java.awt.Color.red); JLabel4.setBounds(12,360,156,24); Pcond_value.setSelectionColor(new java.awt.Color(204,204,255)); Pcond_value.setSelectedTextColor(java.awt.Color.black); Pcond_value.setCaretColor(java.awt.Color.black); Pcond_value.setDisabledTextColor(new java.awt.Color(153,153,153)); Pcond_value.setEditable(false); getContentPane().add(Pcond_value); Pcond_value.setBounds(180,360,120,24); AdesignCond_value.setSelectionColor(new java.awt.Color(204,204,255)); AdesignCond_value.setSelectedTextColor(java.awt.Color.black); AdesignCond_value.setCaretColor(java.awt.Color.black); AdesignCond_value.setDisabledTextColor(new java.awt.Color(153,153,153)); getContentPane().add(AdesignCond_value); AdesignCond_value.setBounds(480,96,100,24); JLabel5.setText("set condenser area"); getContentPane().add(JLabel5); JLabel5.setForeground(new java.awt.Color(102,102,153)); JLabel5.setBounds(312,96,156,24); bCalculate.setText("Calculate "); bCalculate.setActionCommand("Calculate "); getContentPane().add(bCalculate); bCalculate.setBounds(432,324,156,60); JLabel10.setText("Design settings"); getContentPane().add(JLabel10); JLabel10.setForeground(java.awt.Color.blue); JLabel10.setFont(new Font("Dialog", Font.BOLD, 18)); JLabel10.setBounds(12,12,553,25); UAcond_value.setSelectionColor(new java.awt.Color(204,204,255)); UAcond_value.setSelectedTextColor(java.awt.Color.black); UAcond_value.setCaretColor(java.awt.Color.black); UAcond_value.setDisabledTextColor(new java.awt.Color(153,153,153)); UAcond_value.setEditable(false); getContentPane().add(UAcond_value); UAcond_value.setBounds(480,60,100,24); JLabel12.setText("condenser UA"); getContentPane().add(JLabel12); JLabel12.setBounds(312,60,156,24); JLabel13.setText("set evaporator area"); getContentPane().add(JLabel13); JLabel13.setForeground(new java.awt.Color(102,102,153)); JLabel13.setBounds(12,96,161,22); getContentPane().add(AdesignEvap_value); AdesignEvap_value.setBounds(180,96,100,24); JLabel14.setText("Rotation speed"); getContentPane().add(JLabel14); JLabel14.setBounds(12,192,150,23); getContentPane().add(Nref_value); Nref_value.setBounds(180,192,100,24); JLabel16.setText("DeltaH evap"); getContentPane().add(JLabel16); JLabel16.setForeground(java.awt.Color.red); JLabel16.setBounds(12,468,144,24); DeltaHevap_value.setEditable(false); getContentPane().add(DeltaHevap_value); DeltaHevap_value.setBounds(180,468,120,24); JLabel15.setText("evaporator UA"); getContentPane().add(JLabel15); JLabel15.setBounds(12,60,156,24); UAevap_value.setSelectionColor(new java.awt.Color(204,204,255)); UAevap_value.setSelectedTextColor(java.awt.Color.black); UAevap_value.setCaretColor(java.awt.Color.black); UAevap_value.setDisabledTextColor(new java.awt.Color(153,153,153)); UAevap_value.setEditable(false); getContentPane().add(UAevap_value); UAevap_value.setBounds(180,60,100,24); JLabel1.setText("flow rate"); getContentPane().add(JLabel1); JLabel1.setForeground(java.awt.Color.red); JLabel1.setBounds(324,396,156,24); massFlow_value.setSelectionColor(new java.awt.Color(204,204,255)); massFlow_value.setSelectedTextColor(java.awt.Color.black); massFlow_value.setCaretColor(java.awt.Color.black); massFlow_value.setDisabledTextColor(new java.awt.Color(153,153,153)); massFlow_value.setEditable(false); getContentPane().add(massFlow_value); massFlow_value.setBounds(492,396,120,24); JLabel2.setText("air temperature (°C)"); getContentPane().add(JLabel2); JLabel2.setBounds(312,192,156,24); Ta_value.setText("0"); Ta_value.setSelectionColor(new java.awt.Color(204,204,255)); Ta_value.setSelectedTextColor(java.awt.Color.black); Ta_value.setCaretColor(java.awt.Color.black); Ta_value.setDisabledTextColor(new java.awt.Color(153,153,153)); getContentPane().add(Ta_value); Ta_value.setBounds(480,192,100,24); JLabel3.setText("compression power"); getContentPane().add(JLabel3); JLabel3.setForeground(java.awt.Color.red); JLabel3.setBounds(324,468,156,24); tauCompr_value.setSelectionColor(new java.awt.Color(204,204,255)); tauCompr_value.setSelectedTextColor(java.awt.Color.black); tauCompr_value.setCaretColor(java.awt.Color.black); tauCompr_value.setDisabledTextColor(new java.awt.Color(153,153,153)); tauCompr_value.setEditable(false); getContentPane().add(tauCompr_value); tauCompr_value.setBounds(492,468,120,24); JLabel7.setText("DeltaH cond"); getContentPane().add(JLabel7); JLabel7.setForeground(java.awt.Color.red); JLabel7.setBounds(12,432,156,24); DeltaHcond_value.setSelectionColor(new java.awt.Color(204,204,255)); DeltaHcond_value.setSelectedTextColor(java.awt.Color.black); DeltaHcond_value.setCaretColor(java.awt.Color.black); DeltaHcond_value.setDisabledTextColor(new java.awt.Color(153,153,153)); DeltaHcond_value.setEditable(false); getContentPane().add(DeltaHcond_value); DeltaHcond_value.setBounds(180,432,120,24); JLabel8.setText("Simulation results"); getContentPane().add(JLabel8); JLabel8.setForeground(java.awt.Color.red); JLabel8.setFont(new Font("Dialog", Font.BOLD, 18)); JLabel8.setBounds(12,324,553,25); JLabel9.setText("calculated evaporator area"); getContentPane().add(JLabel9); JLabel9.setBounds(12,132,156,24); AcalculatedEvap_value.setSelectionColor(new java.awt.Color(204,204,255)); AcalculatedEvap_value.setSelectedTextColor(java.awt.Color.black); AcalculatedEvap_value.setCaretColor(java.awt.Color.black); AcalculatedEvap_value.setDisabledTextColor(new java.awt.Color(153,153,153)); AcalculatedEvap_value.setEditable(false); getContentPane().add(AcalculatedEvap_value); AcalculatedEvap_value.setBounds(180,132,100,24); JLabel11.setText("calculated A Cond"); getContentPane().add(JLabel11); JLabel11.setBounds(312,132,156,24); AcalculatedCond_value.setSelectionColor(new java.awt.Color(204,204,255)); AcalculatedCond_value.setSelectedTextColor(java.awt.Color.black); AcalculatedCond_value.setCaretColor(java.awt.Color.black); AcalculatedCond_value.setDisabledTextColor(new java.awt.Color(153,153,153)); AcalculatedCond_value.setEditable(false); getContentPane().add(AcalculatedCond_value); AcalculatedCond_value.setBounds(480,132,100,24); JLabel17.setText("COeff of Performance"); getContentPane().add(JLabel17); JLabel17.setForeground(java.awt.Color.red); JLabel17.setBounds(324,432,156,24); COP_value.setSelectionColor(new java.awt.Color(204,204,255)); COP_value.setSelectedTextColor(java.awt.Color.black); COP_value.setCaretColor(java.awt.Color.black); COP_value.setDisabledTextColor(new java.awt.Color(153,153,153)); COP_value.setEditable(false); getContentPane().add(COP_value); COP_value.setBounds(492,432,120,24); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); bInitialSettings.addActionListener(lSymAction); bCalculate.addActionListener(lSymAction); //}} //{{INIT_MENUS //}} type="refrigeration controller"; } /** * returns the component type public String getCompType(){ return type; } **/ public String getClassDescription(){ return "refrigeration controller\n\n\nauthor : R. Gicquel march 2011"; } void setupProject(){ //on récupère ici les instances des transfos externes dont on a besoin //afin d'accéder à leurs différents paramètres pour les calculs ultérieurs } public void setVisible(boolean b) { if(b) { setLocation(50, 50); } super.setVisible(b); } public void addNotify() { // Record the size of the window prior to calling parents addNotify. Dimension d = getSize(); super.addNotify(); if (fComponentsAdjusted) return; // Adjust components according to the insets Insets ins = getInsets(); setSize(ins.left + ins.right + d.width, ins.top + ins.bottom + d.height); Component components[] = getContentPane().getComponents(); for (int i = 0; i < components.length; i++) { Point p = components[i].getLocation(); p.translate(ins.left, ins.top); components[i].setLocation(p); } fComponentsAdjusted = true; } // Used for addNotify check. boolean fComponentsAdjusted = false; class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == RefrigControllerMinPack.this) Thrust_WindowClosing(event); } } void Thrust_WindowClosing(java.awt.event.WindowEvent event) { dispose(); // dispose of the Frame. } //{{DECLARE_CONTROLS javax.swing.JButton bInitialSettings = new javax.swing.JButton(); javax.swing.JLabel JLabel6 = new javax.swing.JLabel(); javax.swing.JTextField Pevap_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel4 = new javax.swing.JLabel(); javax.swing.JTextField Pcond_value = new javax.swing.JTextField(); javax.swing.JTextField AdesignCond_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel5 = new javax.swing.JLabel(); javax.swing.JButton bCalculate = new javax.swing.JButton(); javax.swing.JLabel JLabel10 = new javax.swing.JLabel(); javax.swing.JTextField UAcond_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel12 = new javax.swing.JLabel(); javax.swing.JLabel JLabel13 = new javax.swing.JLabel(); javax.swing.JTextField AdesignEvap_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel14 = new javax.swing.JLabel(); javax.swing.JTextField Nref_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel16 = new javax.swing.JLabel(); javax.swing.JTextField DeltaHevap_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel15 = new javax.swing.JLabel(); javax.swing.JTextField UAevap_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel1 = new javax.swing.JLabel(); javax.swing.JTextField massFlow_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel2 = new javax.swing.JLabel(); javax.swing.JTextField Ta_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel3 = new javax.swing.JLabel(); javax.swing.JTextField tauCompr_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel7 = new javax.swing.JLabel(); javax.swing.JTextField DeltaHcond_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel8 = new javax.swing.JLabel(); javax.swing.JLabel JLabel9 = new javax.swing.JLabel(); javax.swing.JTextField AcalculatedEvap_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel11 = new javax.swing.JLabel(); javax.swing.JTextField AcalculatedCond_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel17 = new javax.swing.JLabel(); javax.swing.JTextField COP_value = new javax.swing.JTextField(); //}} //{{DECLARE_MENUS //}} class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == bInitialSettings) bInitialSettings_actionPerformed(event); else if (object == bCalculate) bCalculate_actionPerformed(event); } } public void init(){ isInitialized=true; proj=getProjet(); setupProject(); //initialisations des PointThopt et des TechnoDesign amontEvap=new PointThopt(proj,"4"); avalEvap=new PointThopt(proj,"1"); amontCond=new PointThopt(proj,"2"); avalCond=new PointThopt(proj,"3"); waterInlet=new PointThopt(proj,"water inlet"); waterOutlet=new PointThopt(proj,"water outlet"); inAir=new PointThopt(proj,"air inlet"); outAir=new PointThopt(proj,"air outlet"); avalCond.getProperties(); refrig=(rg.corps.Corps)avalCond.lecorps; evaporatorName="evaporator"; condenserName="condenser"; compressorName="compressor"; technoEvap=new TechnoEvaporator(proj, evaporatorName, waterInlet, waterOutlet, amontEvap, avalEvap); addTechnoVector(technoEvap); technoCond=new TechnoCondensor(proj, condenserName, amontCond, avalCond, inAir, outAir); addTechnoVector(technoCond); technoCompr=new VolumCompr(proj, compressorName, avalEvap, amontCond); addTechnoVector(technoCompr); setupTechnoDesigns(vTechno); } void bInitialSettings_actionPerformed(java.awt.event.ActionEvent event){ if(!isInitialized)init();//la première fois, on initialise, car il faut un constructeur sans argument //pour instancier la classe par le RMI if(!evaporatorName.equals("")){//initialisation de l'évaporateur String[] args=new String[2]; args[0]="heatEx"; args[1]=evaporatorName; Vector vProp=proj.getProperties(args); Double f=(Double)vProp.elementAt(15); UAevap=f.doubleValue(); String fluideChaud=(String)vProp.elementAt(0); args[0]="process"; args[1]=fluideChaud; vProp=proj.getProperties(args); f=(Double)vProp.elementAt(4); double DeltaH=-f.doubleValue(); amontEvap.getProperties(); avalEvap.getProperties(); DTsurch=avalEvap.DTsat; waterInlet.getProperties(); waterOutlet.getProperties(); Tf=waterInlet.T; mCpCalopEvap=DeltaH/(waterInlet.T-waterOutlet.T); mCpRefrigEvap=DeltaH/(avalEvap.T-amontEvap.T); DeltaHevap=DeltaH; UAevap_value.setText(Util.aff_d(UAevap,4)); //initialisations du TechnoDesign technoEvap.makeDesign(); AevapReel=Util.lit_d(technoEvap.ADesign_value.getText()); AcalculatedEvap_value.setText(technoEvap.ADesign_value.getText()); } if(!condenserName.equals("")){//initialisation du Condenseur String[] args=new String[2]; args[0]="heatEx"; args[1]=condenserName; Vector vProp=proj.getProperties(args); Double f=(Double)vProp.elementAt(15); UAcond=f.doubleValue(); String fluideFroid=(String)vProp.elementAt(1); args[0]="process"; args[1]=fluideFroid; vProp=proj.getProperties(args); f=(Double)vProp.elementAt(4); double DeltaH=f.doubleValue(); avalCond.getProperties(); amontCond.getProperties(); DTssrefr=avalCond.DTsat; inAir.getProperties(); outAir.getProperties(); Tair=inAir.T; Ta_value.setText(Util.aff_d(Tair-273.15,4)); mCpCalopCond=DeltaH/(outAir.T-inAir.T); mCpRefrigCond=DeltaH/(amontCond.T-avalCond.T); UAcond_value.setText(Util.aff_d(UAcond,4)); //initialisations du TechnoDesign technoCond.makeDesign(); AcondReel=Util.lit_d(technoCond.ADesign_value.getText()); AcalculatedCond_value.setText(technoCond.ADesign_value.getText()); } if(!compressorName.equals("")){//initialisation de la turbine H2O String[] args=new String[2]; args[0]="process"; args[1]=compressorName; Vector vProp=proj.getProperties(args); String amont=(String)vProp.elementAt(1); String aval=(String)vProp.elementAt(2); Double f=(Double)vProp.elementAt(3); massFlow=f.doubleValue(); lambdaVol=technoCompr.getLambdaVol(); N_value=massFlow*60*avalEvap.V/Vs_value/lambdaVol; technoCompr.N_value.setText(Util.aff_d(N_value,4)); Nref_value.setText(Util.aff_d(N_value,4)); } } void bCalculate_actionPerformed(java.awt.event.ActionEvent event){ calculatePilot(); } public void calculatePilot(){ if(!isInitialized)init();//la première fois, on initialise, car il faut un constructeur sans argument //pour instancier la classe par le RMI AdesignEvap=Util.lit_d(AdesignEvap_value.getText()); AdesignCond=Util.lit_d(AdesignCond_value.getText()); N_value=Util.lit_d(Nref_value.getText()); technoCompr.N_value.setText(Util.aff_d(N_value,4)); UAevap=Util.lit_d(UAevap_value.getText()); UAcond=Util.lit_d(UAcond_value.getText()); Tair=Util.lit_d(Ta_value.getText())+273.15; inAir.T=Tair; inAir.update(UPDATE_T,!UPDATE_P,!UPDATE_X); inAir.getProperties(); amontEvap.getProperties(); avalEvap.getProperties(); amontCond.getProperties(); avalCond.getProperties(); DTsurch=avalEvap.DTsat; DTssrefr=avalCond.DTsat; Tcond= Tair+10;// Tevap = Tf-10;// System.out.println("UAevap : \t"+UAevap+"\t Aréel \t"+Util.lit_d(technoEvap.ADesign_value.getText())+"\t technoEvap.UA \t"+technoEvap.UA); System.out.println("UAcond : \t"+UAcond+"\t Aréel \t"+Util.lit_d(technoCond.ADesign_value.getText())+"\t technoCond.UA \t"+technoCond.UA); int m = 2; int n = 2; double fvec[] = new double[m+1]; double x[] = new double[n+1]; int info[] = new int[2]; int iflag[] = new int[2]; x[1] = UAevap;//UAevap=x[4]; x[2] = UAcond;//UAcond=x[5]; double residu0; double residu1; fcn2(m,n,x,fvec,iflag); residu0 = optimization.Minpack2_f77.enorm_f77(m,fvec); nfev2 = 0; njev2 = 0; double epsi=0.0005; optimization.Minpack2_f77.lmdif1_f77(this, m, n, x, fvec, epsi, info); residu1 = optimization.Minpack2_f77.enorm_f77(m,fvec); System.out.println(); System.out.println(" Initial L2 norm of the residuals: " + residu0); System.out.println("Final L2 norm of the residuals: " + residu1); System.out.println("Number of function evaluations: " + nfev); System.out.println("Number of Jacobian evaluations: " + njev); System.out.println("Info value: " + info[1]); System.out.println("Final approximate solution: " + x[1] + ", " + x[2]); System.out.println(); /**/ UAevap_value.setText(Util.aff_d(UAevap,4)); UAcond_value.setText(Util.aff_d(UAcond,4)); AcalculatedEvap_value.setText(technoEvap.ADesign_value.getText()); AcalculatedCond_value.setText(technoCond.ADesign_value.getText()); COP_value.setText(Util.aff_d(DeltaHevap/tauCompr,4)); DeltaHevap_value.setText(Util.aff_d(DeltaHevap,4)); massFlow_value.setText(Util.aff_d(massFlow,4)); DeltaHcond_value.setText(Util.aff_d(DeltaHcond,4)); Pevap_value.setText(Util.aff_d(Pevap,4)); Pcond_value.setText(Util.aff_d(avalCond.P,4)); tauCompr_value.setText(Util.aff_d(tauCompr,4)); } void calcFrigo(double UA[]){ UAevap=UA[1]; UAcond=UA[2]; double residu0; double residu1; int m = 3; int n = 3; double fvec[] = new double[m+1]; double x[] = new double[n+1]; int info[] = new int[2]; int iflag[] = new int[2]; x[1] = Tcond; x[2] = Tevap; x[3] = massFlow;//1.3;//massFlow iflag[1] = 0; fcn(m,n,x,fvec,iflag); residu0 = optimization.Minpack_f77.enorm_f77(m,fvec); nfev = 0; njev = 0; optimization.Minpack_f77.lmdif1_f77(this, m, n, x, fvec, epsmch, info); residu1 = optimization.Minpack_f77.enorm_f77(m,fvec); System.out.println(); System.out.println(" Initial L2 norm of the residuals: " + residu0); System.out.println("Final L2 norm of the residuals: " + residu1); System.out.println("Number of function evaluations: " + nfev); System.out.println("Number of Jacobian evaluations: " + njev); System.out.println("Info value: " + info[1]); System.out.println("Final approximate solution: " + x[1] + ", " + x[2]+ ", " + x[3] ); System.out.println(); if(info[1]<=0){ String msg="No solution found"; JOptionPane.showMessageDialog(this, msg); } else{ for(int j=0;j<3;j++)proj.calcThopt(); updateHx(evaporatorName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); updateHx(condenserName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); updateHx(evaporatorName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); updateHx(condenserName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); updateHx(evaporatorName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); updateHx(condenserName, RECALCULATE, !UPDATE_UA, 0, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0); amontEvap.getProperties(); avalEvap.getProperties(); amontCond.getProperties(); avalCond.getProperties(); waterInlet.getProperties(); waterOutlet.getProperties(); inAir.getProperties(); outAir.getProperties(); technoEvap.makeDesign(); technoCond.makeDesign(); } } public void fcn(int m, int n, double x[], double fvec[], int iflag[]) { if (iflag[1]==1) this.nfev++; if (iflag[1]==2) this.njev++; //mise à jour des variables "physiques" pour une meilleure compréhension du code Tcond=x[1]; Tevap=x[2]; massFlow=x[3]; //mise à jour du point aval du condenseur Pcond=refrig.getSatPressure(Tcond, 1); avalCond.T=Tcond+DTssrefr;// DTssrefr est négatif avalCond.P=Pcond; avalCond.update(UPDATE_T,UPDATE_P,!UPDATE_X); avalCond.getProperties(); //mise à jour du point aval de l'évaporateur Pevap=refrig.getSatPressure(Tevap, 1); avalEvap.P=Pevap; avalEvap.T=Tevap+DTsurch; avalEvap.update(UPDATE_T,UPDATE_P,!UPDATE_X); avalEvap.getProperties(); //mise à jour de la pression du point aval du compresseur Pcond=refrig.getSatPressure(Tcond, 1); amontCond.P=Pcond; amontCond.update(!UPDATE_T,UPDATE_P,!UPDATE_X); amontCond.getProperties(); //mise à jour de l'état du point amont de l'évaporateur //le recalcul du titre est fait après convergence amontEvap.P=Pevap; amontEvap.T=Tevap; amontEvap.update(UPDATE_T,UPDATE_P,!UPDATE_X); //mise à jour des variables liées DeltaHevap=getDeltaHEvap();//directement déterminé à partir de x DeltaHcond=DeltaHevap+getTauCompr();//modifie la température de sortie compresseur //calcul des résidus fvec[1] = resEvap(); fvec[2] = resCond(); fvec[3] = 50*resFlow(); return; } public void fcn2(int m, int n, double x[], double fvec[], int iflag[]) { if (iflag[1]==1) this.nfev2++; if (iflag[1]==2) this.njev2++; calcFrigo(x); fvec[1] = resAevap(); fvec[2] = resAcond(); return; } double resAevap(){//renvoie le résidu de la surface de l'évaporateur AevapReel=technoEvap.A; double z= AevapReel-AdesignEvap; System.out.println("resAevap: " + z + ", "+ UAevap + ", " + UAcond); System.out.println(); return z; } double resAcond(){//renvoie le résidu de la surface du condenseur AcondReel=technoCond.A; double z= AcondReel-AdesignCond; System.out.println("resAcond: " + z + ", "+ UAevap + ", " + UAcond); return z; } double getDeltaHEvap(){//calcule la puissance thermique de l'évaporateur return massFlow*(avalEvap.H-avalCond.H); } double resEvap(){//équation 17.4.3 //renvoie la différence entre la température d'évaporation, //recalculée à partir de la méthode du NUT et Tevap=x[2] mCpRefrigEvap=DeltaHevap/DTsurch; double[]res=Util.epsi_NUT(mCpRefrigEvap,mCpCalopEvap,UAevap); epsilon=res[0]; mCpmin=res[1]; double z=Tevap-Tf+DeltaHevap/epsilon/mCpmin;//résidu if(debug)System.out.println("resEvap: " + z + ", "+ Tcond + ", " + Tevap+ ", " + massFlow ); return z; } double getTauCompr(){//équation 17.4.4 //calcule la puissance consommée par le compresseur // recalcul du compresseur double eta_is=technoCompr.getRisentr(); updateprocess(compressorName, "Compression",RECALCULATE,IS_SET_FLOW, UPDATE_FLOW, massFlow, UPDATE_ETA, eta_is); amontCond.getProperties(); //ce qui permet de connaître la puissance consommée String[] args=new String[2]; args[0]="process"; args[1]=compressorName; Vector vProp=proj.getProperties(args); Double f=(Double)vProp.elementAt(4); tauCompr=f.doubleValue(); return tauCompr; } double resFlow(){//équations 17.4.1 et 17.4.2 //renvoie le résidu du débit-masse Vevap=avalEvap.V; double rCompr=Pcond/Pevap; double z= massFlow-technoCompr.getMassFlow(Vevap, rCompr); if(debug)System.out.println("resFlow: " + z + ", "+ Tcond + ", " + Tevap+ ", " + massFlow ); return z; } double resCond(){//équation 17.4.5 //renvoie la différence entre la température de condensation //recalculée à partir de la méthode du NUT et Tcond=x[1] mCpRefrigCond=DeltaHcond/(amontCond.T-(Tcond+DTssrefr)); double[]res=Util.epsi_NUT(mCpRefrigCond,mCpCalopCond,UAcond); epsilon=res[0]; mCpmin=res[1]; double Tentree_refrig=Tair+DeltaHcond/epsilon/mCpmin; double Tsortie_refrig=Tentree_refrig-DeltaHcond/mCpRefrigCond; //le résidu est l'écart entre les deux températures de condensation double z= Tcond-(Tsortie_refrig-DTssrefr);// DTssrefr est négatif if(debug)System.out.println("resCond: " + z + ", "+ Tcond + ", " + Tevap+ ", " + massFlow ); return z; } public void readCompParameters(String ligne_data){ String value=""; value=Util.extr_value(ligne_data, "mCpRefrigEvap"); if(!(value==null)){ mCpRefrigEvap=Util.lit_d(value); } value=Util.extr_value(ligne_data, "mCpRefrigCond"); if(!(value==null)){ mCpRefrigCond=Util.lit_d(value); } value=Util.extr_value(ligne_data, "N_value"); if(!(value==null)){ N_value=Util.lit_d(value); Nref_value.setText(Util.aff_d(N_value,4)); } value=Util.extr_value(ligne_data, "UAevap"); if(!(value==null)){ UAevap=Util.lit_d(value); UAevap_value.setText(Util.aff_d(UAevap,4)); } value=Util.extr_value(ligne_data, "UAcond"); if(!(value==null)){ UAcond=Util.lit_d(value); UAcond_value.setText(Util.aff_d(UAcond,4)); } value=Util.extr_value(ligne_data, "mCpCalopEvap"); if(!(value==null)){ mCpCalopEvap=Util.lit_d(value); // AcalculatedEvap_value.setText(Util.aff_d(mCpCalopEvap,4)); } value=Util.extr_value(ligne_data, "mCpCalopCond"); if(!(value==null)){ mCpCalopCond=Util.lit_d(value); AcalculatedCond_value.setText(Util.aff_d(mCpCalopCond,4)); } value=Util.extr_value(ligne_data, "DeltaHevap"); if(!(value==null)){ DeltaHevap=Util.lit_d(value); DeltaHevap_value.setText(Util.aff_d(DeltaHevap,4)); } value=Util.extr_value(ligne_data, "DeltaHcond"); if(!(value==null)){ DeltaHcond=Util.lit_d(value); DeltaHcond_value.setText(Util.aff_d(DeltaHcond,4)); } value=Util.extr_value(ligne_data, "tauCompr"); if(!(value==null)){ tauCompr=Util.lit_d(value); tauCompr_value.setText(Util.aff_d(tauCompr,4)); } value=Util.extr_value(ligne_data, "AdesignEvap"); if(!(value==null)){ AdesignEvap=Util.lit_d(value); AdesignEvap_value.setText(Util.aff_d(AdesignEvap,4)); } value=Util.extr_value(ligne_data, "AdesignCond"); if(!(value==null)){ AdesignCond=Util.lit_d(value); AdesignCond_value.setText(Util.aff_d(AdesignCond,4)); } value=Util.extr_value3(ligne_data, "technoEvap"); if(!(value==null)){ evapSettings=value; if(technoEvap!=null)technoEvap.readCaract(value); } value=Util.extr_value3(ligne_data, "technoCond"); if(!(value==null)){ condSettings=value; if(technoCond!=null)technoCond.readCaract(value); } } public String saveCompParameters(){ String h="mCpRefrigEvap="+Util.aff_d(mCpRefrigEvap)+tab +"mCpRefrigCond="+Util.aff_d(mCpRefrigCond)+tab +"N_value="+Util.aff_d(N_value)+tab +"UAevap="+Util.aff_d(UAevap)+tab +"UAcond="+Util.aff_d(UAcond)+tab +"mCpCalopEvap="+Util.aff_d(mCpCalopEvap)+tab +"mCpCalopCond="+Util.aff_d(mCpCalopCond)+tab +"DeltaHevap="+Util.aff_d(DeltaHevap)+tab +"DeltaHcond="+Util.aff_d(DeltaHcond)+tab +"tauCompr="+Util.aff_d(tauCompr)+tab +"AdesignEvap="+AdesignEvap_value.getText()+tab +"AdesignCond="+AdesignCond_value.getText()+tab +"#technoEvap="+technoEvap.saveCaract()+"#"+tab +"#technoCond="+technoCond.saveCaract()+"#"+tab ; return h; } }