/* 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.*; /** * Classe pour calculer un compresseur d'air en régime non-nominal * * Cette classe illustre la manière dont une classe externe peut piloter des reparamétrages * variés d'un projet de structure donnée * * @author Renaud GICQUEL */ public class VsCompressorController extends ExtPilot { boolean isInitialized=false; boolean isBuilt=false; String[]composant,nomComposant; String hxName, echSettings="",compressorName=""; TechnoHx technoExchanger; VolumCompr technoCompr; double Te,Tf,massFlow, DTsurch, DTssrefr, Aech, Uech, AechReel, U_ech, Preservoir; double tauTurb, DeltaHech, mCpmin, mCpmax, NUT,R,epsilon, AdesignEch, DeltaH; double UAech, T2,Tech, Pech,Vech,Hech, mCpEau, mCpAir, lambdaVol, N_value, Vs; PointThopt hotUpstream, hotDownstream, coldUpstream, coldDownstream, comprUpstream; String tab=new String("\t"); String ligne=new String("\n"); public VsCompressorController() { //{{INIT_CONTROLS setTitle("Compressor with heat exchanger controller"); getContentPane().setLayout(null); setSize(640,590); setVisible(false); bInitialSettings.setText("Initial settings"); bInitialSettings.setActionCommand("load"); getContentPane().add(bInitialSettings); bInitialSettings.setBounds(216,24,156,36); JLabel10.setText("Design settings"); getContentPane().add(JLabel10); JLabel10.setForeground(java.awt.Color.blue); JLabel10.setFont(new Font("Dialog", Font.BOLD, 18)); JLabel10.setBounds(12,24,553,25); JLabel13.setText("set exchanger area"); getContentPane().add(JLabel13); JLabel13.setForeground(new java.awt.Color(102,102,153)); JLabel13.setBounds(12,132,161,22); getContentPane().add(AdesignEch_value); AdesignEch_value.setBackground(java.awt.Color.white); AdesignEch_value.setBounds(180,132,100,24); JLabel15.setText("heat exchanger UA"); getContentPane().add(JLabel15); JLabel15.setBounds(12,96,156,24); UAech_value.setSelectionColor(new java.awt.Color(204,204,255)); UAech_value.setSelectedTextColor(java.awt.Color.black); UAech_value.setCaretColor(java.awt.Color.black); UAech_value.setDisabledTextColor(new java.awt.Color(153,153,153)); getContentPane().add(UAech_value); UAech_value.setBackground(java.awt.Color.white); UAech_value.setBounds(180,96,100,24); JLabel9.setText("calculated exchanger area"); getContentPane().add(JLabel9); JLabel9.setBounds(12,168,156,24); AcalculatedEch_value.setSelectionColor(new java.awt.Color(204,204,255)); AcalculatedEch_value.setSelectedTextColor(java.awt.Color.black); AcalculatedEch_value.setCaretColor(java.awt.Color.black); AcalculatedEch_value.setDisabledTextColor(new java.awt.Color(153,153,153)); AcalculatedEch_value.setEditable(false); getContentPane().add(AcalculatedEch_value); AcalculatedEch_value.setBounds(180,168,100,24); JLabel1.setText("heat exchanger U"); getContentPane().add(JLabel1); JLabel1.setForeground(new java.awt.Color(102,102,153)); JLabel1.setBounds(12,228,190,22); U_value.setEditable(false); getContentPane().add(U_value); U_value.setBounds(180,228,100,24); JLabel2.setText("isentropic efficiency"); getContentPane().add(JLabel2); JLabel2.setForeground(new java.awt.Color(102,102,153)); JLabel2.setBounds(312,264,190,22); eta_is_value.setEditable(false); getContentPane().add(eta_is_value); eta_is_value.setBounds(480,264,100,24); JLabel3.setText("swept volume"); getContentPane().add(JLabel3); JLabel3.setBounds(312,96,156,24); Vs_value.setText("0.01"); Vs_value.setSelectionColor(new java.awt.Color(204,204,255)); Vs_value.setSelectedTextColor(java.awt.Color.black); Vs_value.setCaretColor(java.awt.Color.black); Vs_value.setDisabledTextColor(new java.awt.Color(153,153,153)); getContentPane().add(Vs_value); Vs_value.setBounds(480,96,100,24); JLabel5.setText("air storage pressure"); getContentPane().add(JLabel5); JLabel5.setBounds(312,132,156,24); P_value.setText("8"); P_value.setSelectionColor(new java.awt.Color(204,204,255)); P_value.setSelectedTextColor(java.awt.Color.black); P_value.setCaretColor(java.awt.Color.black); P_value.setDisabledTextColor(new java.awt.Color(153,153,153)); getContentPane().add(P_value); P_value.setBounds(480,132,100,24); bCalc.setText("Calculate"); bCalc.setActionCommand("Calculate"); getContentPane().add(bCalc); bCalc.setBackground(new java.awt.Color(204,204,204)); bCalc.setForeground(java.awt.Color.red); bCalc.setBounds(408,168,143,36); JLabel4.setText("volumetric efficiency"); getContentPane().add(JLabel4); JLabel4.setForeground(new java.awt.Color(102,102,153)); JLabel4.setBounds(312,228,190,22); lambdaVol_value.setEditable(false); getContentPane().add(lambdaVol_value); lambdaVol_value.setBounds(480,228,100,24); JLabel6.setText("flow rate"); getContentPane().add(JLabel6); JLabel6.setForeground(new java.awt.Color(102,102,153)); JLabel6.setBounds(12,264,190,22); flow_value.setEditable(false); getContentPane().add(flow_value); flow_value.setBounds(180,264,100,24); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); bInitialSettings.addActionListener(lSymAction); bCalc.addActionListener(lSymAction); //}} //{{INIT_MENUS //}} type="Vs compressor controller"; } /** * returns the component type public String getType(){ return type; } **/ public String getClassDescription(){ return "controller for an air compressor with heat exchanger\n\n\nauthor : R. Gicquel october 2010"; } 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 == VsCompressorController.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 JLabel10 = new javax.swing.JLabel(); javax.swing.JLabel JLabel13 = new javax.swing.JLabel(); javax.swing.JTextField AdesignEch_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel15 = new javax.swing.JLabel(); javax.swing.JTextField UAech_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel9 = new javax.swing.JLabel(); javax.swing.JTextField AcalculatedEch_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel1 = new javax.swing.JLabel(); javax.swing.JTextField U_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel2 = new javax.swing.JLabel(); javax.swing.JTextField eta_is_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel3 = new javax.swing.JLabel(); javax.swing.JTextField Vs_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel5 = new javax.swing.JLabel(); javax.swing.JTextField P_value = new javax.swing.JTextField(); javax.swing.JButton bCalc = new javax.swing.JButton(); javax.swing.JLabel JLabel4 = new javax.swing.JLabel(); javax.swing.JTextField lambdaVol_value = new javax.swing.JTextField(); javax.swing.JLabel JLabel6 = new javax.swing.JLabel(); javax.swing.JTextField flow_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 == bCalc) bCalc_actionPerformed(event); } } public void init(){ isInitialized=true; proj=getProjet(); setupProject(); //initializations for the simulation //watch out: the names of points and components must be correct, otherwise an error will occur and prevent the TechnoDesign to be instanciated hxName="Exchanger"; compressorName="compressor"; hotDownstream=new PointThopt(proj,"storage inlet"); hotUpstream=new PointThopt(proj,"compressor outlet"); comprUpstream=new PointThopt(proj,"air inlet"); coldUpstream=new PointThopt(proj,"water inlet"); coldDownstream=new PointThopt(proj,"water outlet"); //instantiation of the TechnoDesign in the external classes technoExchanger=new TechnoHx(proj, hxName, hotUpstream, hotDownstream, coldUpstream, coldDownstream); addTechnoVector(technoExchanger); technoCompr=new VolumCompr(proj, compressorName, comprUpstream, hotUpstream); addTechnoVector(technoCompr); //initialization of the TechnoDesign in Thermoptim setupTechnoDesigns(vTechno); P_value.setText(Util.aff_d(hotUpstream.P/comprUpstream.P));//affichage du rapport de compression initial } 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 String[] args=new String[2]; args[0]="project"; args[1]=""; Vector vProp=proj.getProperties(args); String flowUnit=(String)vProp.elementAt(0); if(!flowUnit.equals("kg/s")){ String msg = "Watch out! the flow rate unit should be\"kg/s\".\nYou may have discrepancies between your units \nand those used for heat exchanger design"; JOptionPane.showMessageDialog(this, msg); } if(!hxName.equals("")){//initialisation de l'évaporateur args=new String[2]; args[0]="heatEx"; args[1]=hxName; vProp=proj.getProperties(args); Double f=(Double)vProp.elementAt(15); UAech=f.doubleValue(); String fluideChaud=(String)vProp.elementAt(0); args[0]="process"; args[1]=fluideChaud; vProp=proj.getProperties(args); f=(Double)vProp.elementAt(4); DeltaH=-f.doubleValue(); DeltaHech=DeltaH; hotUpstream.getProperties(); hotDownstream.getProperties(); coldUpstream.getProperties(); coldDownstream.getProperties(); mCpEau=DeltaH/(coldDownstream.T-coldUpstream.T); mCpAir=DeltaH/(hotUpstream.T-hotDownstream.T); UAech_value.setText(Util.aff_d(UAech,4)); //initialisations du TechnoDesign technoExchanger.UA=UAech; technoExchanger.makeDesign(); AechReel=Util.lit_d(technoExchanger.ADesign_value.getText()); U_ech=UAech/AechReel; AcalculatedEch_value.setText(Util.aff_d(AechReel,4)); AdesignEch_value.setText(technoExchanger.ADesign_value.getText()); } // technoCompr.makeDesign(); if(!compressorName.equals("")){//initialization of the compressor args=new String[2]; args[0]="process"; args[1]=compressorName; 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(); N_value=Util.lit_d(technoCompr.N_value.getText()); lambdaVol=technoCompr.getLambdaVol(); Vs=massFlow*60*comprUpstream.V/N_value/lambdaVol; Vs_value.setText(Util.aff_d(Vs,8)); technoCompr.setVs(Vs); technoCompr.setN(N_value); } } void bCalc_actionPerformed(java.awt.event.ActionEvent event) { Vs=Util.lit_d(Vs_value.getText());//reads the compressor swept volume technoCompr.setVs(Vs); Preservoir=Util.lit_d(P_value.getText()); double UA_ech=Util.lit_d(UAech_value.getText()); hotUpstream.P=Preservoir;// updates the compressor outlet pressure hotUpstream.update(!UPDATE_T,UPDATE_P,!UPDATE_X); hotUpstream.getProperties(); massFlow=technoCompr.getMassFlow(comprUpstream.V); double eta_is=technoCompr.getRisentr();// calculates compressor isentropic efficiency lambdaVol=technoCompr.getLambdaVol(); //recalculates the compressor and the downstream process updateprocess(compressorName, "Compression",RECALCULATE,IS_SET_FLOW, UPDATE_FLOW, massFlow, UPDATE_ETA, eta_is); hotUpstream.getProperties(); updateprocess("refroidissement", "Exchange",RECALCULATE,IS_SET_FLOW, UPDATE_FLOW, massFlow, UPDATE_ETA, eta_is); updateprocess("entree air", "Exchange",RECALCULATE,IS_SET_FLOW, UPDATE_FLOW, massFlow, UPDATE_ETA, eta_is); hotUpstream.getProperties();//updates heat exchanger inlets and outlets hotDownstream.getProperties(); coldUpstream.getProperties(); coldDownstream.getProperties(); //calculates the heat exchanger (several iterations) for(int i=0;i<5;i++){ updateHx(hxName, RECALCULATE, UPDATE_UA, UA_ech, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0, UPDATE_CALC_MODE, OFF_DESIGN_MODE); coldDownstream.getProperties(); hotDownstream.getProperties(); technoExchanger.UA=UA_ech;//calculates U technoExchanger.makeDesign(); double U=technoExchanger.getU(); UAech=U*AechReel/1000.;//updates UA and recalculates the heat exchanger UAech_value.setText(Util.aff_d(UAech,4)); updateHx(hxName, RECALCULATE, UPDATE_UA, UAech, !UPDATE_EPSI, 0, !UPDATE_DTMIN, 0, UPDATE_CALC_MODE, OFF_DESIGN_MODE); coldDownstream.getProperties(); hotDownstream.getProperties(); U_value.setText(Util.aff_d(U,4)); UA_ech=UAech; } //updates the simulator and displays for(int j=0;j<3;j++)proj.calcThopt(); flow_value.setText(Util.aff_d(massFlow,4)); eta_is_value.setText(Util.aff_d(eta_is,4)); lambdaVol_value.setText(Util.aff_d(lambdaVol,4)); AcalculatedEch_value.setText(technoExchanger.ADesign_value.getText()); } }