THERMOPTIM®
REFERENCE
MANUAL
VOLUME III
USE AND DESIGN OF EXTERNAL CLASSES SUBSTANCES, PROCESSES AND EXTERNAL NODES DRIVERS
JAVA VERSIONS 1.5 AND 2.5
© R. GICQUEL JANUARY 2012
2
CONTENTS
1 Foreword ............................................................................................................................................................. 6 Thermoptim documentation ................................................................................................................................ 6 Access the documentation via hypertext links ................................................................................................ 6 DIAPASON, ONLINE E-LEARNING MODULES WITH AUDIO ................................................................ 7 2 Extension system for Thermoptim by adding external classes....................................................................... 7 2.1 Software implementation................................................................................................................................ 8 2.2 Programming issues ........................................................................................................................................ 9 2.3 Using the external classes ............................................................................................................................... 9 2.4 Three categories of interface methods ......................................................................................................... 10 2.5 Using external components........................................................................................................................... 11 2.5.1 VIEWING THE AVAILABLE EXTERNAL CLASSES ....................................................................... 11 2.5.2 Representation of an external component in the diagram editor........................................................... 11 2.5.3 LOADING AN EXTERNAL CLASS ....................................................................................................... 11 2.5.4 Thermocouplers ......................................................................................................................................... 12 2.5.5 External Nodes ..................................................................................................................................... 13 2.5.6 Miscellaneous comments ..................................................................................................................... 14 2.6 Representation of real fluid mixtures in Thermoptim.................................................................................. 15 2.6.1 Link between Thermoptim and thermodynamic properties servers ..................................................... 15 2.6.2 Creating an external mixture ................................................................................................................ 15 3 PROGRAMMING EXTERNAL COMPONENTS ....................................................................................... 17 3.1 External Substances .................................................................................................................................... 17 3.1.1 Construction of pure external substances ............................................................................................. 17 3.1.2 CALCULATIONS ON THE PURE EXTERNAL SUBSTANCES ....................................................... 19 3.1.2.1 Principles of correspondence.................................................................................................................. 19 3.1.2.2 Examples of implementation .................................................................................................................. 19 3.1.3 Constructing external mixtures ................................................................................................................ 20
Thermoptim reference manual volume 3
January 2012
3 3.1.3.1 Special issues............................................................................................................................................ 20 3.1.3.2 Files associated with external mixtures ................................................................................................. 21 3.1.3.3 Example of external mixture: The system LiBr-H2O .......................................................................... 21 3.1.4 Instantiation from external classes ....................................................................................................... 23 3.1.5 Coupling class with the properties server TEP ThermoSoft ................................................................ 23 3.2 External Processes ...................................................................................................................................... 28 3.2.1 Construction ......................................................................................................................................... 28 3.2.2 Updating and calculating the process ................................................................................................... 29 3.2.3 Moist calculations ................................................................................................................................ 32 3.2.4 Managing Energy Types ...................................................................................................................... 32 3.2.5 Access to other elements of the simulator ............................................................................................ 32 3.2.6 SAVING AND LOADING THE PARAMETERS OF THE MODEL .................................................. 34 3.3 EXTERNAL NODES .................................................................................................................................... 35 3.3.1 Construction ............................................................................................................................................... 35 3.3.2 UPDATING AND CALCULATING A NODE........................................................................................ 35 3.3.3 Managing energy types .............................................................................................................................. 39 3.3.4 SAVING AND LOADING THE PARAMETERS OF THE MODEL .................................................. 39 3.4 Access to instances of external nodes and processes .................................................................................. 39 3.5 External Driving of Thermoptim ................................................................................................................. 40 3.5.1 Facilitating the development of external classes ...................................................................................... 40 3.5.2 PROVIDING ACCESS TO THE UNPROTECTED LIBRARIES ....................................................... 41 3.6 INTEGRATING EXTERNAL CLASSES IN THE LIBRARY extUser.zip ............................................ 43 3.6.1 USING THE EXTERNAL CLASS MANAGER ..................................................................................... 43 3.6.2 USING A STANDARD COMPRESSOR ................................................................................................. 44 3.6.3 MODIFYING THE CLASSPATH FOR ADDING JAVA LIBRARIES .............................................. 45 3.6.4 VIEWING EXTERNAL CLASSES ......................................................................................................... 45 4 EXTERNAL CLASS DEVELOPMENT ENVIRONMENT ........................................................................ 45 4.1 PRESENTATION OF THE WORKSPACE .............................................................................................. 46 4.2 Installing JCreator ........................................................................................................................................ 46 Thermoptim reference manual volume 3 January 2012
4 4.3 Emulating Thermoptim from JCreator ...................................................................................................... 48 Appendix 1 : Thermoptim methods which can be called by external classes ................................................ 49 package rg.corps ............................................................................................................................................... 49 In Corps ......................................................................................................................................................... 49 In CorpsExt ................................................................................................................................................... 50 package rg.thopt ............................................................................................................................................... 51 In Projet ......................................................................................................................................................... 51 In PilotFrame................................................................................................................................................. 53 In ComposantExt........................................................................................................................................... 53 In TransfoExterne ......................................................................................................................................... 54 In DividerExterne .......................................................................................................................................... 54 In MixerExterne ............................................................................................................................................ 55 In ComprExt.................................................................................................................................................. 55 Annex 2 : THERMOPTIM METHODS COdE................................................................................................ 57 We give here the code of certain Project and Corps methods whose structure must be faithfully reproduced if they are to be used in subclasses....................................................................................................................... 57 Method getProperties() of Projet ...................................................................................................................... 57 Method updatePoint () of Projet ....................................................................................................................... 59 Method getSubstProperties() of Corps .............................................................................................................. 61 Method getExternalClassInstances () of Projet ................................................................................................ 61 Method setupChart () of Projet ......................................................................................................................... 62 Annex 3 : utility methods of class Util ............................................................................................................... 63 Annexe 4 : TEP ThermoSoft - Interface Java / Delphi Application à Thermoptim ................................... 64 (par F. Rivollet) ................................................................................................................................................... 64 Structure de dialogue entre les deux programmes ............................................................................................ 64 Exécuter un calcul en java ................................................................................................................................ 64 Définition des méthodes de dialogue avec TEP ThermoSoft ........................................................................ 64 Chargement/Libération des modèles thermodynamiques en mémoire .......................................................... 65 Définition d'un système ................................................................................................................................ 65 Modifier / Lire des variables de TEP ThermoSoft ........................................................................................ 66 Lancer un calcul ............................................................................................................................................ 66 Exemple d'écriture d'un calcul complet ....................................................................................................... 67 Variables et méthodes de calcul disponibles ..................................................................................................... 67 Variables classiques ...................................................................................................................................... 67 Méthodes de calcul........................................................................................................................................ 68 Annex 5 : UML Diagrams of external classes ................................................................................................... 69
© R. GICQUEL 1997 - 2012. All Rights Reserved. This document may not be reproduced in part or in whole without the author's express written consent, except for the licensee's personal use and solely in accordance with the contractual terms indicated in the software license agreement. Information in this document is subject to change without notice and does not represent a commitment on the part of the author. Thermoptim reference manual volume 3 January 2012
5
Thermoptim reference manual volume 3
January 2012
6
1 FOREWORD THERMOPTIM DOCUMENTATION
Thermoptim's documentation is comprised of several complementary parts: a short documentation named Quick Reference available through menu Help: it gives access to tab frames introducing the main concepts used a printable documentation, mainly as pdf files on line e-learning modules with sound tracks
-
Printable documentation
The printable documentation is comprised of several parts which can be displayed through the Help menu of the simulator: four Getting Started brochures allow one to quickly (less than half an hour) get used to Thermoptim. The first one presents an electricity steam cycle, the second one a combustion gas turbine, the third one a refrigeration cycle and the fourth one an air conditioning system the reference manual, itself comprised of three volumes and of the interactive charts manuals. The first volume introduces the software, the diagram editor, the use of the post-processing Excel macro and the optimization method, the second one deals with the simulator (screens of the different primitive types and advanced tools available in the modeling environment), and lastly the third volume explains how to use and build external classes a Frequenly Asked Questions file is also available
-
Several examples with detailed explanations allow a user to get acquainted with the software thanks to a detailed presentation of how projects can be built. Three of the examples extend the Getting Started brochures. The present document is the third volume of the reference manual. It is dedicated to the design of external classes. After a brief overview of the extension mechanism that has been adopted, it explains how to use and design external classes, and it introduces a freely distributed development environment.
Access the documentation via hypertext links
Hyperliens to the documentation
Thermoptim reference manual volume 3
January 2012
7 Windows versions 1.5 and later include hypertext links that provide direct access to the documentation and the FAQ. In order for the links to work, the file paths must be identical to what was entered in Thermoptim, otherwise they will not appear on the list. The documentation in English must therefore be structured as shown in the figure above. If you have an older installer, rename the files accordingly.
Hyperlinks to the documentation
DIAPASON, AUDIO
ONLINE
E-LEARNING
MODULES
WITH
We have developed DIAPASON e-learning modules, which are online instructional modules with audio and animation allowing users to work on their own, at their own pace, with access at all times to oral explanations in addition to the written materials provided. The Diapason modules use a Flash player that runs in most browsers. An online presentation of these modules in English can be viewed at: http://www-cep.ensmp.fr/cours/Diapason/seances/PresDiapasonEn/seance.html. The list of sessions available in English if given in: http://www.thermoptim.org/sections/logiciels/divers-portail/seances-disponibles The following session is dedicated to being introduced to Thermoptim (in English): http://www.thermoptim.org/sections/enseignement/cours-en-ligne/seances-diapason/session-s07en_init-first There is also a special unit specifically on how to use and program external classes (in English): http://www.thermoptim.org/sections/enseignement/cours-en-ligne/seances-diapason/s07en_ext-introduction The purpose of these sessions is to introduce users to Thermoptim and enable them to become familiar with using it by building models using examples of simple energy systems (gas turbine, steam power plant, compression refrigeration system). We recommend that you refer to these sessions if you can.
2 EXTENSION SYSTEM FOR THERMOPTIM BY ADDING EXTERNAL CLASSES
One great advantage of Thermoptim is that its graphic environment can be used to visually build models for a large number of energy systems, from the most simple refrigerator to complex integrated gasification combined cycle electric power plants using several hundred elements. Not only does this greatly simplify the modeling process and facilitate subsequent use and maintenance of the model, but it also makes the models more reliable. The connections between the different elements are made automatically, thus ensuring consistency. Through version 1.4, only the components available in the Thermoptim primitive type set could be assembled in this manner, which limited the potential of the software. A number of users wished to be able to define their own elements and/or their own substances. Thermoptim reference manual volume 3
List of substances January 2012
8
Thermoptim's interface with external classes (Java code elements) provides the solution and facilitates the interoperability of the software with the outside world, especially with other applications developed using Java. The benefits are two-fold: - create Thermoptim extensions from common primitive type set, by adding external modules that define the elements that automatically appear on the screens in a seamless fashion. Thus users can add their own substances or components not available in the basic set. - drive Thermoptim from another application, either to guide a user (smart tutorial) or to check the code (driver or regulation, access to thermodynamic libraries). The previous and opposite figures show how the external substances are added to Thermoptim's list of substances, and then replace an internal substance on the point screen. They are just as easy to use as if they were part of the software. The figure opposite shows how an external component representing a solar collector appears in the diagram editor, and the figure below shows the screen of the corresponding process, composed partly of Thermoptim internal code and partly of external code (lower third on the right). Substance screen
2.1 SOFTWARE IMPLEMENTATION
Practically speaking, adding a new external process is quite easy. Simply create a specific class, which inherits from the abstract parent class extThopt.ExtProcess. The interaction with Thermoptim is ensured on two levels:
External process
by general methods for performing the required calculations; by a JPanel that is built in to the external process screen. Thus, the class designer can create his External process screen own graphic interface, which is then inserted into the Thermoptim screen.
Thermoptim reference manual volume 3
January 2012
9
2.2 PROGRAMMING ISSUES
To protect the Thermoptim code, its classes are "obfuscated", i.e. all of its elements are renamed, making it extremely difficult to decompile. However, this makes it impossible to access the Thermoptim content from the outside. The solution is not to obfuscate the methods that we want to be accessible. Thus there we must find a compromise between accessibility and code protection, which means providing as few accesses as possible. For the moment, only two Thermoptim packages out of five are partially accessible: rg.thopt and rg.corps. The first contains the simulator classes and the second the substance classes. The solution consists of adding a non-obfuscated package (extThopt), in which there are classes (for example extThopt.CorpsExterne), recognized by Thermoptim, which are subclasses of Thermoptim classes, through interface classes (extThopt.CorpsExterne is a subclass of rg.corps.CorpsExt, which in turn is a subclass of rg.corps.Corps). These classes have methods that establish the correspondence with their obfuscated internal equivalent. We recommend that you refer to the API of the package extThopt to learn about the syntax and functions of all of the methods available. This API is part of the development environment of the external classes available (in the folder api_extThopt).
2.3 USING THE EXTERNAL CLASSES
In version 1.5, there are four types of external classes: substances, processes, dividers, and external nodes. The same principle applies to all: in the external package (extThopt), an input class is simply an extension of one of the Thermoptim classes (CorpsExterne for substances, TransfExterne for processes, etc.). All of the external overloaded Thermoptim methods are located in this class. ExtThopt simply acts as the input point in its package. Its role is to instantiate the various classes representing the elements added to Thermoptim and to interface with the software using overloaded methods. External classes inherit from an abstract parent class. For example, ExtSubstance for substances, ExtProcess for components. In practice, the interaction with Thermoptim is ensured at one or two levels, depending: parent classes define all of the general methods useful for performing the required calculations with the exception of ExtSubstance, they also define a JPanel that is incorporated into the screen of the external component. In this way, the designer can create his own graphic interface, which then appears on the Thermoptim screen. The designer can define his own graphic elements (buttons, fields, labels, etc.) and process specific actions in his methods. For the components, two methods, saveCompParameters() and readCompParameters(String ligne_data), save the parameter settings in the Thermoptim project file, for use when the project is loaded. In short, external classes, such as CorpsExterne or TransfExterne, inherit directly from Thermoptim classes and ensure the interface with the software. They call abstract classes, such as ExtSubstance or ExtProcess, whose subclasses may be freely designed by the users via interface methods and JPanel. The diagram below illustrates the structure used for external processes. For substances, the diagram is the same, but simpler. Since there is no graphic interface, there is no need for the right-hand part of the diagram. People familiar with UML notation will find the class diagrams for external substances and processes in Appendix 5. The top part of the diagram corresponds to classes present in Thermoptim's basic set, and the lower part corresponds to the extThopt package that can be modified by the external class designer. SourceSink is a default implementation of ComponentType to be able to instantiate a TransfoExterne, even in the absence of external classes of this type, and SolarCollector and LiBrAbsorption are examples of external classes. The dotted blue and red lines symbolize the relays of the parts of the code relating to the calculations and the graphic interface, made from TransfoExterne to the other classes, either internal classes (SourceSink) or external classes (subclasses of ExtProcess).
Thermoptim reference manual volume 3
January 2012
10
Structure of external processes Thermoptim selects directly from the external classes as follows: When it is launched, the software analyzes the archives extThopt.zip and extUser.zip, which contain all of the external classes. It finds all of the classes added by default and by the users and sorts them by parent class, loads them in the various types of arrays, and adds the external elements to its own lists so that they are seamlessly accessible. Subsequently, if one of these elements is selected, Thermoptim sends its class to the appropriate constructor, which instantiates it. The line External Class Viewer in the Special menu shows the external classes available (see section 3.6). Once an external component is instantiated, it is possible to change it by double-clicking on its type as it appears on the screen. For now, there is no consistency test on the class names and element types, but this feature will be added shortly. For the development of external classes, an emulation system makes it possible to launch Thermoptim from an external application, and to dynamically load the classes under development, providing acces to the debugging tools in the usual working environment (see section 6). Moreover, the package extThopt includes a Util class that provides a number of utility methods for formatting numbers, reading them onscreen, saving and reading values, finding roots using the bisection method, etc. (see Appendix 3).
2.4 THREE CATEGORIES OF INTERFACE METHODS
The classes used in Thermoptim, CorpsExterne, TransfExterne and the other, define the interface methods, which fall into three additional categories: Internal Thermoptim methods designed to be obfuscated Non-obfuscated internal methods that are directly used by the external classes: These methods are used to execute the Thermoptim methods with external parameter settings, and must not be overloaded. Their
Thermoptim reference manual volume 3
January 2012
11 signature must be strictly respected: in particular, the structure of the Vectors of Objects used as arguments must correspond exactly to what Thermoptim expects, or a ClassCastException will be generated. External methods corresponding to Thermoptim's obfuscated methods: These methods are used to execute the external methods from within Thermoptim, and must be overloaded.
-
The non-obfuscated methods falling into the last two categories are listed in Appendix 1, for all of the accessible classes. For more information, please see the html documentation for these classes provided in the folder api_Thermoptim.
2.5 USING COMPONENTS
EXTERNAL
2.5.1 VIEWING THE AVAILABLE EXTERNAL CLASSES
To help you use and manage the external classes, the line External Class Viewer from the Special menu displays all of the external classes available. They are sorted by type (substances, processes, mixers, dividers, drivers) with a short description of the class selected and where it comes from (extThopt.zip and extUser.zip archives as well as classes under development). This screen can be consulted while you are developing your model.
2.5.2 REPRESENTATION OF AN EXTERNAL COMPONENT IN THE DIAGRAM EDITOR
Specific icons were added to represent the external components ( for processes, for mixers, and External class viewer
for dividers). The external component is then selected when the simulator is updated from the diagram as indicated below.
2.5.3 LOADING AN EXTERNAL CLASS
To load an external process (for an external node, the process is the same), you can either: - from the simulator screen click on the column header of the process array, then choose External and finally select the type of external process you want from the list; - or, from the diagram editor, build the external component graphically then update the simulator from the diagram. In the case of an external process, by default it is a "heat source / sink" type, as shown in the
Default screen of an external process
Thermoptim reference manual volume 3
January 2012
12 screen opposite. Once this default process is created, double click on the label "source / sink" to access the list of all external processes available. Choose the one you want and it will be loaded.
2.5.4 THERMOCOUP LERS
The thermocoupler system completes the heat exchanger system by allowing components other than exchange processes to connect to one or more exchange processes to represent a thermal coupling. This system does not encompass the exchanger system: two exchange processes cannot be connected by a thermocoupler. This system has a number of External component with two thermocouplers benefits, because it can be used to represent many thermocouplers that do not constitute a heat exchange in the traditional sense, like for example cooling the walls of the combustion chamber of a reciprocating engine, cooled compression, and above all supply or removal of heat from the multi-functional external components. The figure above is an illustration of this: An absorption refrigeration cycle, whose absorption-desorption system is defined and integrated in an external process, is supplied with the steam that exits the evaporator then enters the condenser. This cycle involves the mixture LiBr-H2O, whose properties are modeled either directly in the external process, or in an external substance, and requires high temperature heat supply to the desorber and medium temperature heat removal from the absorber. The representation of these thermocouplers is possible thanks to the thermocoupler system: the external process calculates the thermal energies that must be exchanged, and the thermocoupler recalculates the corresponding "exchange" process, which updates its downstream point. The types of thermocouplers used by an external component appear in the lower right hand corner of the screen. Double click on one of the types to open the screen of the corresponding thermocoupler. Given that thermocouplers are a type of heat exchanger, it is valuable to define them by values such as effectiveness , UA, NTU or LMTD, that can be calculated using similar equations. The component sends to each of its thermocouplers the equivalent values for flow rates, inlet and outlet temperature and thermal energy transferred, which they must take into account in their calculations. External process Specific methods are provided in the external class code and are not user-modifiable.
Thermoptim reference manual volume 3
January 2012
13 However, there are limits to the similarities with exchangers: for example, temperature crossovers unacceptable in an exchanger may occur in a thermocoupler, leading to absurd values. So it is best to transmit values that are unlikely to lead to this type of situation. One possible solution is to assume that the thermocoupler is isothermal for calculations of characteristics that are similar to exchanger characteristics. For example, a combustion chamber may be assumed to be at mean temperature between its upstream and downstream points when calculating cooling. This assumption is not absurd and may prevent a temperature crossover between the cooling fluid and the gases that cross the component. In the case of the absorption machine presented above, we assumed that the absorber and desorber were isothermal. Both lead to the screens below. If we had not taken the temperature of the absorber as a reference for the exchange calculations, keeping the temperatures of the steam entering and exiting the external process, we would have ended up with a temperature crossover. For external processes that accept several thermocouplers and for external nodes, the potential complexity of the calculations prevents the exchange process from driving the thermocoupler. Its load is always set by the external component. This is why there are Absorber fewer options for calculating a thermocoupler than for a heat exchanger: The user can only choose between calculating the outlet temperature of the exchange process (at a given flow rate) and the flow rate, when the temperature is known. Note that on the thermocoupler screen, the external component fluid can be selected as a pinch fluid and a minimum pinch value can be entered (see optimization method, volume 1).
2.5.5 External Nodes
The nodes of Thermoptim's basic set are extremely simple components used to complete the description of the fluid circuits. They are always adiabatic, and they ensure the conservation of the mass flow rate and enthalpy
Desorber However, there is one somewhat special component, considered as a process, but which is in fact a node in most cases: combustion, which receives a oxidizer and a fuel, and from which burned gases exit. In the LiBr-H2O absorption example, a number of energy systems are involved, as well as components of varying complexity, which can have a number of input and outlet fluids, after various internal calculations, with or without thermocoupling with external heat sources. External nodes allow a user to define these components. Only external mixers and dividers are defined: no component simultaneously performs both functions (receiving and emitting several fluids), but you need only couple an external mixer with an external diffuser to do so. Thermoptim reference manual volume 3 January 2012
14
In many respects, we encounter the same problems in implementing these external nodes as with thermocouplers: the potential complexity of the calculations to be made in the node makes it necessary for the node to take over and control both the main vein and the branches, since no default calculation is possible. The verification and consistency problems are even more critical than for thermocouplers: only the node designer knows which processes it must be connected to in inlet and outlet. The user LiBr-H2O mixture desorber must refer to the documentation of the class to know how to use it. The figure above shows the diagram of a desorber for an absorption machine using the LiBr-H2O mixture whose properties must in this case be provided by an external substance. The external node screen is shown opposite. As with external processes, it contains a general part defined in the Thermoptim basic set, completed by a part defined by the user (here the lower left zone). In the model shown here, the only parameter defined in the node is the temperature of the desorber. The properties of the rich solution (mass fraction and flow rate) and the state of the refrigerant are obtained from their respective processes. The node calculates the flow rates of the refrigerant and the poor solution, its state, and heat supply required.
LiBr-H2O mixture desorber screen
The thermocoupler then calculates the final state of the steam used. Before each recalculation, the node checks that its structure is correct and loads the values that it needs to be calculated. Then it updates the thermocoupler that can in turn be recalculated. In this example, we assumed that the desorber was isothermal, and we took the flow rate of the poor solution as the reference flow rate.
2.5.6 Miscellaneous comments
You may have noticed that the screens of the external processes represented here are composed partly of Thermoptim internal code and partly of external code (lower right section in the processes, lower left in the nodes.). This is because the character strings used in the external components have not been "internationalized" the way the Thermoptim basic set has.
Thermoptim reference manual volume 3
January 2012
15 But this does not affect their use in any way. However, you can see that the number display has not been internationalized either, so the decimal separator is not the same: it is a period and not a comma. Of course, this can be modified, but it has not yet been done. This means that the figures must be entered with a point in the part defined in the external component, and with a comma in the rest of the screen. It is important to pay close attention to this issue, otherwise number formatting errors will be detected by Java.
Thermocoupler
2.6 Representation of real fluid mixtures in Thermoptim
Until 2005, the only Thermoptim substances whose composition could be defined by the user were compound gases. It was impossible to represent real fluid mixtures. The external substance system was reworked to be able to do so, via the introduction of a new type of substance, called "external mixture", and substances formerly known as external substances were renamed "pure external substances". An external mixture is made from a system, i.e. from a given set of pure substances, and its composition is specified in a new editor. The distinctive characteristic of these external mixtures is that they can be used to generate a set of substances from the same system of pure substances. In this way, they are similar to compound gases. The difference is that the interactions among real fluids are much more complex than among ideal gases, so you must specify not only the pure substances used, but also their models, mixture rules and a number of additional parameters.
2.6.1 Link between Thermoptim and thermodynamic properties servers
The system makes it possible not only to define external mixtures by completely writing their external classes, but also to calculate them using thermodynamic properties servers (TPS), software packages that have specialized libraries, such as TEP ThermoSoft developed by the Centre Energétique et Procédés of Ecole des Mines de Paris and Simulis Thermodynamics made by ProSim. This link is a very valuable extension of Thermoptim, since it means that many new fluids can be used in the software, with extremely accurate models. The trade-off is that it is somewhat complex and especially, calculation times can be long.
2.6.2 Creating an external mixture
The point calculation screen has been modified slightly: an "external mixture" option has been added. To create a new external mixture, select this option then enter a new substance name and press Enter. The external mixture editor can Point calculation screen for an external mixture then be opened by clicking on "display". By default, the external mixture created is of the type "LiBr-H2O external mixture" whose class is presented as an example in the programming documentation. If this is the desired substance, enter its composition, then click "Save". The Thermoptim reference manual volume 3 January 2012
16 expected composition type (molar or mass fraction) is displayed above the component names column, and corresponds to the first column of figures from the left.
External mixture editor In the title of the external mixture editor the following items appear: - the mixture name (here LiBrH2O) - the corresponding external class identifier (here LiBr-H2O external mixture) - the name of the software used (either a TPS, or as in this example (rg) a family of external classes). - the system used (here LiBr-H2O) This information is used to characterize the mixture by referring to the documentation. The same TPS may propose several systems, and may be used in several external classes. From the pop-up menu located in the lower right of the editor screen you can display all of the systems available. If the one proposed by default is not the one you want, select one from the list and click "load the mixture". The editor is then updated, and you can enter the composition and click "save". In a Thermoptim project file (.prj), the data for external mixtures are saved in the same way as for compound gases.
COMPOUND SUBSTANCES 2 Name of gas / Components gaz_brulés 5 CO2 0.0309766336 H2O 0.0619532671 O2 0.14154164 N2 0.756807249 Ar 0.0087212103 molar fraction mass fraction
0.0477375785 0.0390824699 0.158596897 0.74238276 0.0122002945 classe=LiBr-H2O external mixture syst=LiBr-H2O
LiBrH2O 2 extMixture=true lithium bromide 0.35 0 water 0.65 0
Thermoptim reference manual volume 3
January 2012
17 extMixture=true indicates that it is an external mixture, and the rest of the line specifies the class and the system selected. The next lines give the molar or mass compositions (for the time being, for a given mixture, the input can be done only in the manner selected by the designer of the external class, either in molar fractions, or in mass fractions). Note that the order in which the components appears is not random: it is defined in the corresponding external class. Consequently, if you edit a project file manually, you must keep the same order for the system components. The substance selection screen has been modified to distinguish between two categories of external substances. In this example, the three external mixtures on the bottom of the list correspond to different compositions of the same system. Once the external mixture has been defined or loaded from the substance selection screen, its composition can be modified in the editor, and as we saw above, the system can also be changed by selecting one from the available libraries (pop-up menu on the lower right).
Substance selection screen
3 PROGRAMMING EXTERNAL COMPONENTS
This section presents the basic notions needed to program external components, with some illustrations taken from the examples provided with the development environment. Once again, however, we would like to stress how important it is to properly prepare the documentation of your classes. The documentation must include at least two sections: the programming file and the user documentation. A poorly documented class will be difficult to use or modify, and the easiest time to document an external class is when it is created. Unfortunately experience has shown that this is only rarely the case... Since the external class represents a component model that has a physical sense, it is important to write a note describing the model, both for the programming file and the user documentation. The code itself must include enough comments to make the links to the model as clear as possible (in particular it is best if the notations are uniform). Finally, the user documentation must specifically indicate the component constraints and requirements, with a thorough description of which inlet and outlet fluids can be connected to it, (name, nature, etc.) and how the thermocouplers, if any, must be constructed. The method getClassDescription () can be used to enter a brief description of the class, which can be consulted from a special Thermoptim screen. We recommend including the documentation references and the main constraints and requirements of the class in this method. Practically speaking, you can proceed as follows: gather the following elements in an archive that has the same name as the class: the java code of the component, its class file, a modeling note, instructions for use with a short example of how it is used, and the .prj and .dia files for the example. A model library containing all of these archives can easily be created and updated.
3.1 External Substances 3.1.1 Construction of pure external substances
The structure of external classes was defined above. The class extThopt.CorpsExterne inherits from the rg.corps.CorpsExt class of Thermoptim and performs the interface, relaying the calculations to an abstract class (extThopt.ExtSubstance). This class defines the basic methods and is subclassed by the different classes introduced (for example extThopt.GlycolWater25, extThopt.GlycolWater40, etc.). We recommend that you refer
Thermoptim reference manual volume 3
January 2012
18 to the API of extThopt.CorpsExterne and extThopt.ExtSubstance to learn about the syntax and functions of all of the methods available. This API is part of the development environment of the external classes available. Since Thermoptim knows only the external interface class extThopt.CorpsExterne and the abstract class extThopt.ExtSubstance, the instantiations can use only these two classes. The synchronization between the internal and external methods must be done carefully, but it is the only way to make sure that the classes used are working properly. We will begin by explaining the construction procedure implemented in Thermoptim, then we will show how to create a new external class, by subclassing extThopt.ExtSubstance.
3.1.1.1 Construction of a pure external substance in Thermoptim
The construction procedure is as follows: 1) the user selects an external substance from the list, which shows the index in the arrays of external classes loaded in Thermoptim. 2) you load this class, which you transtype in ExtSubstance, and encapsulate in an Object. Class c=(Class)rg.util.Util.substClasses[i];//load the class of the external substance Constructor ct=c.getConstructor(null);//carefully instantiate it with its constructor without an argument. extThopt.ExtSubstance ec=(extThopt.ExtSubstance)ct.newInstance(null); Object ob=ec;//encapsulate it in an Object (otherwise the argument will not go through!) corps=(Corps)new CorpsExterne(ob);//instantiate the external substance which is done by the following constructor: public CorpsExterne(Object obj){ subst=(ExtSubstance)obj; setNom(subst.getType()); setComment(subst.chemForm); initCorpsExt(subst.M, subst.PC, subst.TC, subst.VC, subst.Tmini, subst.Tmaxi, subst.Pmini, subst.Pmaxi, subst.typeCorps); }
3.1.1.2 Creating a pure external substance
To create an external substance, simply subclass extThopt.ExtSubstance. Let us take the example of the class DowThermA. The constructor is as follows: public DowThermA (){ super(); type=getType();//type of substance M=166; PC=31.34; TC=752.15; //initializations (molar mass, critical pressure and temperatures) Tmini=293.15; Tmaxi=523.15; //minimum and maximum temperatures of the substance definition chemForm="(C6H5)2O (73.5% vol), (C6H5)2 (26.5% vol)"; //chemical composition of the substance } The method getType() sends the type of substance as it appears on the Thermoptim screens: public String getType(){ return "Dowtherm A"; } The method getClassDescription () can be used to enter a brief description of the class, which will appear in the external class viewer (see section 3.6). Provide a short explanation of the model, and if possible cross-reference to more detailed documentation.
Thermoptim reference manual volume 3
January 2012
19 public String getClassDescription(){ return "data from FLUIDFILE software by Dow Chemical\n\nauthor : R. Gicquel April 2003"; } The methods for calculating the properties of the substance are presented later in the manual.
3.1.2 CALCULATIONS SUBSTANCES
ON
THE
PURE
EXTERNAL
3.1.2.1 PRINCIPLES OF CORRESPONDENCE
For the calculations, the arguments are passed by the non-obfuscated methods. Please see Appendix 1 for details on existing methods. For example, the enthalpy equation is inverted to solve for T in extThopt.CorpsExterne by: public double getT_from_hP(double hv,double P){ return subst.getT_from_hP(hv,P); } The interface class rg.corps.CorpsExt ensures the correspondence between inv_hp_T (obfuscated) and getT_from_hP (non-obfuscated) : public double inv_hp_T(double hv,double P){ return getT_from_hP(hv, P); } Thus, any time inv_hp_T by is called by a method internal to Thermoptim for an external substance, the call is relayed to getT_from_hP by rg.corps.CorpsExt. Going in the other direction, rg.corps.Corps or rg.corps.CorpsExt contains the following method: public double getT_from_hP(double hv,double P){ return inv_hp_T(hv, P); } When getT_from_hP is called by an external method for an internal substance, the call is relayed to inv_hp_T.
3.1.2.2 EXAMPLES OF IMPLEMENTATION
The class DowThermA defines a heat transfer fluid used in the exchangers. The substance remains in the liquid state at all times, and the calculations are simple: For example enthalpy, which is a function only of temperature (and its inversion). public double calcH (double T, double P,double x) { double a=0.00281914712153519,b=1.51937611940298; double TT=T-273.15; return b*TT+a/2.*TT*TT; } because h is given by a second degree polynomial to solve for T, its inversion is explicit: public double getT_from_hP(double $hv,double $P){ double a=0.00281914712153519,b=1.51937611940298; double c=-$hv; a=a/2.; Thermoptim reference manual volume 3 January 2012
20 double delta=b*b-4.*a*c; double TT = (-b+Math.pow(delta,0.5))/2./a; return TT+273.15; } The calculations here are very simple. If we were dealing with a condensable vapor, they would be much more complex. The class LiBrH2Omixture is a somewhat more complicated example.
3.1.3 CONSTRUCTING EXTERNAL MIXTURES 3.1.3.1 SPECIAL ISSUES
Like pure external substances, external mixtures are extThopt. ExtSubstance type, even if their calculations are performed in the TPS. To differentiate them, external mixtures must implement the interface extThopt.ExternalMixture, which specifies which methods they must define (see below). The names of the pure external substances are listed on the substance selection screen, where they are used to instantiate classes. For external mixtures, things are much more complex, because the same external class can define several systems, and each system generates as many compositions as the user wants, except of course if you are dealing with a pure substance, in which case the molar fraction and the mass fraction are both 1. Each external class defines all of the systems it proposes, and these systems cannot be modified by the user from within Thermoptim. The class rg.corps.ExtMixture is used to instantiate the mixtures. It has a Substance called refExternalSubstance, which corresponds to the external class where the calculations are done, and with which it exchanges the system name and the selected compositions, using the method CorpsExterne (which must not be obfuscated, of course): public void CalcPropCorps (double T, double p, double x, String systType, double[] fract_mol) { //we start by updating the system composition subst.updateComp(systType, fract_mol); double U=20., H=10., S=0.5, V=0.01, Cv=0., Xh=0.; if((T>=subst.Tmini)&&(T<=subst.Tmaxi)){ //we call the method CalcPropCorps of the external mixture double[]val=subst.CalcPropCorps (T, p, x); //we load the values calculated H=val[0]; V=val[1]; Cv=val[2]; x=val[3]; U=val[4]; S=val[5]; } else{ String message=resIntTh_fr.getString("mess_116"); JOptionPane.showMessageDialog(new JFrame(),message); } //update of the substance variables (hidden) setState(p, T, x,//in arguments U, H, S, V, Cv, Xh);//to be recalculated } This method relays the system selected (systType) and its molar or mass fraction (fract_mol) to the external substance (subst), then calculates the point.
Thermoptim reference manual volume 3
January 2012
21 In order to return the value of the vapor quality or the composition at liquid-vapor equilibrium, we defined the method getQuality(), which returns an array of doubles corresponding to the variable X of ExtSubstance, which must be correctly updated when inversion calculations are performed. Any external mixture must return three methods defined in the interface extThopt.ExternalMixture, used to initialize ExtMixture when it is instantiated: - public String getSoftware(), which defines the thermodynamic properties server used - public Vector getMixtures(), which defines the names of the different systems, and the substances they contain - public boolean isMolarFraction(), which is true if the composition must be entered in molar variables, and otherwise it is false. The structure of the Vector vMixtures is as follows: String[] system={"lithium bromide","water"}; vMixtures= new Vector(); Object[]obj=new Object[2]; obj[0]="LiBr-H2O"; obj[1]= system; vMixtures.addElement(obj); Note that isMolarFraction() serves only to define the mixture editor display: In all cases the composition transits via the array fract_mol.
3.1.3.2 FILES MIXTURES
ASSOCIATED
WITH
EXTERNAL
As in the case of compound gases, the list of external mixtures is saved in a file called "mel_ext.txt", which is updated each time a new mixture is created, and is used to initialize the substance selection screen. external mixtures file
CO2_TEP liqu pauvre vap riche mel pauvre LiBrH2O Fin Fin TEPThermoSoft mixtures TEPThermoSoft mixtures TEPThermoSoft mixtures TEPThermoSoft mixtures LiBr-H2O external mixture water;0.65;0.0 CO2 NH3-H2O NH3-H2O NH3-H2O LiBr-H2O CO2;1.0;0.0 ammonia;0.25;0.0 water;0.75;0.0 ammonia;0.75;0.0 water;0.25;0.0 ammonia;0.1;0.0 water;0.9;0.0 lithium bromide;0.35;0.0
3.1.3.3 EXAMPLE SYSTEM LIBR-H2O
OF
EXTERNAL
MIXTURE:
THE
The system provides a simple example of how to define an external mixture. Later in the manual we will give a more complex example on linking up with the Thermosoft TEP thermodynamic properties server, taking into account the characteristics of the ThermoSoft database. Another example is the coupling with the TEP Lib SPT which is detailed on the Thermoptim UNIT portal1. As the latter is itself written in Java, the coupling is particularly simple. In machines using the LiBr-H2O mixture, the difference in the vapor pressure between the solvent (LiBr) and the solute (H2O) is such that we can set aside the mass fraction of the solvent in the vapor phase, which simplifies the calculations. Note that it is common practice to define the parameters of the diagram of the LiBr-H2O mixture as a function of the mass concentration in solvent (LiBr) and not in solute. Since water is likely to crystallize at low temperatures, the mixture crystallization curve is often shown on the diagram, corresponding to a lower operating limit for the machines. For this pair, the ASHRAE2 proposes equations (1) and (2), set up by generalizing the refrigerant (water) saturation pressure law to the mixture, in which the water temperature t' (°C) is replaced by a linear function of
1 2
http://www.thermoptim.org/sections/logiciels/thermoptim/ressources/serveur-proprietes/ ASHRAE, Fundamentals Handbook (SI), Thermophysical properties of refrigerants, 2001. January 2012
Thermoptim reference manual volume 3
22 the solution temperature t (°C). P, expressed based on a decimal logarithm, is the pressure in kPa, and X is the mass fraction of the mixture in LiBr. These equations are valid in the following value intervals: -15 < t' < 110 °C, 5 < t < 175 °C, 45 < X < 70 %. D, log(P) = C + t' + 273,15 + E ( t' + 273,15)2 (1)
tt' =
Bi Xi
i=0 3 (2)
3
Ai Xi
i=0
TABLE 1 COEFFICIENTS OF EQUATIONS 1 AND 2
A0 A1 A2 A3
-2.00755 0.16976 -3.13E-03 1.98E-05
B0 B1 B2 B3
124.937 -7.71649 0.152286 -7.95E-04
C D E
7.05 -1596.49 -104095.5
The constructor initializes the validity limits of the class and the Vector vMixtures, which in this case includes just one system: public H2OLiBrMixture (){ super(); type=getType(); M=29;PC=10;TC=350; //Attention: initialisations without physical sense Tmini=278.15; Tmaxi=448.15; chemForm="LiBr-H2O mixture"; typeCorps=6;//external susbstance type isMixture vMixtures= new Vector(); Object[]obj=new Object[2]; obj[0]="LiBr-H2O"; obj[1]=system; vMixtures.addElement(obj); } String[] system={"lithium bromide","water"}; The following methods define the class description, the software used (since it is not a TPS, the name is not important in this case), the unit to be used to express the composition (in this case mass), the system proposed, and the identifier of the class. public String getClassDescription(){ return "external mixture class\nWatch out! the LiBr composition is to be expressed as mass fractions"; } public String getSoftware(){ return "rg"; } public boolean isMolarFraction(){ return false; } public Vector getMixtures(){ return vMixtures; } Thermoptim reference manual volume 3 January 2012
23
public String getType(){ return "LiBr-H2O external mixture"; } The composition is updated based on the following method, which uses the intermediate variable x, equal to X/100. public void updateComp(String systType, double[] fract_mass){ //attention: x represents the mass fraction, even if it goes through fract_mol in ExtMixture selectedSyst=systType; x=fract_mass[0]; } The other methods (not presented here) define the calculations to be performed to solve equations (1) and (2).
3.1.4 Instantiation from external classes
It is possible to directly instantiate an external mixture from the external classes, for example in a driver. The syntax is provided below. You simply have to indicate the system selected (here "LiBr-H2O"), and update the composition (particularly simple in this case). The calculation and inversion functions can then be used directly, and the results can be written in the output file, for example. H2OLiBrMixture monCorps=new H2OLiBrMixture ();//instantiation of the substance double[]fractmass={0.35,0.65}; monCorps.updateComp("LiBr-H2O",fractmass); System.out.println("Enthalpie du mélange externe LiBr-H2O pour la composition massique : "+fractmass[0]+" LiBr"); for(int i=0;i<10;i++){ double T=280+10*i; double[] val=monCorps.CalcPropCorps(T, 5, 0); System.out.println("T :\t"+T+" h : \t"+val[0]); } which gives: Enthalpy of the external misture LiBr-H2O for the mass composition: 0.35 LiBr T: 280.0 h: -5.2873148226108775 T: 290.0 h: 21.108948694345447 T: 300.0 h: 47.56170686221427 T: 310.0 h: 74.07095968099561 T: 320.0 h: 100.63670715068943 T: 330.0 h: 127.25894927129576 T: 340.0 h: 153.9376860428146 T: 350.0 h: 180.67291746524594 T: 360.0 h: 207.46464353858977 T: 370.0 h: 234.3128642628461
3.1.5 Coupling class with the properties server TEP ThermoSoft
Coupling with a thermodynamic properties server (TPS) such as TEP ThermoSoft is much more complex, on the one hand because this TPS is composed of calculation modules that are separate from Thermoptim, and what's more they are developed in another language, and on the other hand because the calculable thermodynamic systems can vary greatly from case to case. We will illustrate the procedure using the example of the class TEPThermoSoft.java.
3.1.5.1 Interface between Java and Delphi
Thermoptim reference manual volume 3 January 2012
24
The following method is used to load the library "TEPThermoSoftJava.dll" which constitutes the interface with the Delphi environment in which TEP ThermoSoft was developed:
Next you must declare the Delphi methods callable from Java that serve to dialog between the two environments (please refer to Appendix 1 for details on their function and syntax)
3.1.5.2 Definition of mixtures proposed by the TPS
Each TPS should define a list of the systems proposed, which is placed in the "mixtures" folder of the installation directory. The standard format is as follows: External mixture file
NH3-H2O NH3-H2O.mel 2 Tmaxi=1100 Tmini=216.7 CO2 CO2.mel 1 CO2 Tmini=216.7 T0=273.15 ammonia water M=44 T0=293.15 P0=1. M=44 PC=73.77 TC=304.128 P0=36.59027 PC=200 TC=404.128 Tmaxi=1100
Fin Fin Each line contains: the name of the system as it appears on the Thermoptim selection screens (for example NH3-H2O) the mixture definition file, in the format of the properties server (for example NH3-H2O.mel) the number of components the name of the components as they appear on the Thermoptim selection screens the molar mass, the critical temperature and pressure, maximum and minimum temperatures for the fluid, and the reference temperature and pressure values (for which h=u=s=0)
It is basically via the mixture definition file that the properties server is initialized. Thermoptim simply modifies the composition and the state variables. Note that this list contains the system "CO2" with just one component, i.e., a pure substance. The external mixture mechanism also makes it possible to emulate a TPS to represent a pure substance by a more precise model than the one used in Thermoptim. In this specific case, it is a dedicated equation that can be used in the neighborhood of the critical point3. The arborescence of the properties server directories can be set up at the user's discretion. The only requirements are that the dll links be placed in the installation directory and the list of systems proposed in the "mixtures" folder. In the case of TEP ThermoSoft, this list in contained in the file "TEPThSoft.mix". The constructor of the class TEPThermoSoft.java is very similar to the class considered above:
W. Wagner, R. Span, A new equation of state for carbon dioxide covering the fluid region from the triple-point temperature to 1100 K at pressures up to 800 MPa. J. Phys. Chem. Ref. Data, 25(6):1509, 1996.
3
Thermoptim reference manual volume 3
January 2012
25
It introduces a Hashtable to be able to easily reference the existing external mixtures, and executes the method getMixtures() which constructs the Vector of existing mixtures and the Hashtable, by analyzing the mixture file "TEPThSoft.mix" using the method lect_data(). The same class can be used with various sets of mixtures depending on the applications. The three methods of the ExternalMixture interface are then defined, which does not pose any particular problem. The method updateComp must be able both to initialize the system correctly and update its composition. To do so, it calls the Hashtable created by the constructor.
An example of how to calculate the saturation temperature is given below (bubble if x = 0, dew if x = 1). It provides a good illustration of the call sequence to the TEP ThermoSoft methods documented in Appendix 1. Schematically, we start by initializing the session and we load in the system in question, then we initialize the pressure, converted from bars to Pascals, and the composition of the mixture. Depending on whether it is a pure substance or a true mixture, the execution of the calculation differs slightly. The work session is closed to free up resources, and the saturation temperature is returned to Thermoptim. In order to accelerate the calculations, it is better to avoid opening and closing a session whenever possible. Consequently, variants of certain methods utilizable only when a session is open have been implemented. They differ from the others in that the term Session is added to their name. In both cases, we have created two sister methods: getSatTemperature() and getSatTemperatureSession(). The first manages the opening and closing of sessions, and second performs the calculations. This makes it possible to directly call the second without reinitializing the system.
Thermoptim reference manual volume 3
January 2012
26
The other calculation methods implemented are more complex, specifically those that use functions involving finding roots using the bisection method, but the principle is the same. We will refer to the comments documenting the class for additional information.
3.1.5.3 Inversion of functions
The example below is for the method inverting the enthalpy equation to solve for T, when pressure is known. Overall the procedure is similar: Upon initialization, a session is opened, and the system is loaded. The inversion calculation can then be performed in this session, since the function f_dicho calls the version of CalcPropCorps that does not open its own session. When the calculations are done, the session is closed.
There is one particularity of this inversion method: during a liquid-vapor equilibrium, for a pure substance, the temperature determination is not enough. The vapor quality x must also be determined. It is calculated in f_dicho, then loaded in X[0], which Thermoptim can access using the method getQuality() of ExtSubstance.
Thermoptim reference manual volume 3
January 2012
27 For the time being, only the vapor quality of pure substances is used by the Thermoptim internal classes, but, as shown in the following section, the mechanism implemented in TEPThermoSoft.java is generic and allows the external classes to access the composition of multi-component mixtures.
3.1.5.4 Example of calculating the external mixture (NH3-H2O)
TEP ThermoSoft proposes the pair NH3-H2O as a mixture. In order to illustrate the calculations possible, we have created a small class called NH3_Absorption.java, which displays a screen of the principal properties useful for calculating absorption systems that use this mixture. As usual for this application, the composition is entered in mass variables. In the example opposite, at 140° C for a mass fraction of NH3 equal to 0.7, the point is located inside the isobaric lens at 20 bars, the bubble and dew temperatures are respectively 66.8 °C and 162.4 °C. TEP ThermoSoft sends the liquid and vapor molar fractions of NH3, as well as the mean vaporization rate. Their values are sent by the array double[] X, which, in the case of a pure substance, contains only the vapor quality. The code for performing the calculations in the class NH3_Absorption.java illustrates the use of the array X by an external class:
Property calculator for the mixture NH3-H2O
3.1.6 Thermodynamic charts of external mixtures
External mixtures not being included in Thermoptim, the software does not provide their thermodynamic charts. To overcome this limitation, we added a new chart type, called external mixture chart, which allows the use of simplified entropy and (h,P) charts. The preparation of the chart background can be made thanks to a special external class called CreateMixtureCharts.java. You should refer to its documentation for further details on this topic. The new charts are simplified compared to the others in that they show only the bubble and dew curves, as well as a single set of isovalues, i.e. the isobars for the entropy chart, and the isotherms for the (h, P) chart. These charts being a variation of vapor charts, their use is explained in the documentation of these.
Thermoptim reference manual volume 3
January 2012
28
3.2 External Processes
The structure of external classes was defined earlier in this manual: The class extThopt.TransfExterne inherits from rg.corps.TransfoExt of Thermoptim and performs the interface, relaying the calculations at the level of an abstract class (extThopt.ExtProcess) defining the basic methods, and subclassed by the different classes introduced (for example extThopt.SolarCollector). We recommend that you refer to the API of extThopt.TransfExterne and extThopt. ExtProcess to learn the syntax and function of the methods available. This API is part of the development environment of the external classes available (in the folder api_extThopt). We will begin by explaining the construction procedure implemented in Thermoptim, then we will show how to create a new external component, by subclassing extThopt. ExtProcess.
3.2.1 Construction 3.2.1.1 Construction of an external process in Thermoptim
The construction procedure is as follows: 1) the user selects an external process from the list, which shows the index in the arrays of external classes loaded in Thermoptim. 2) you load this class, which you transtype in ExtProcess, and encapsulate in an Object. Class c=(Class)rg.util.Util.componentClasses[i];//you load the class of the external component Constructor ct=c.getConstructor(null);//you carefully instantiate it with its constructor without an argument. extThopt.ExtProcess ec=(extThopt.ExtProcess)ct.newInstance(null); Object ob=ec;//you encapsulated it in an Object 3) you then instantiate the class TransfExterne, which inherits from ComposantExt, i.e., it is in fact a JPanel containing the user interface defined in the external process. JPanel1.remove(cType); cType=new TransfExterne((Projet)Proj,ob, this);//we instantiate the external component setupCType();//sets up the external user interface which is done by the following constructor: public TransfExterne(Projet proj, Object obj, TransfoExterne te){ this.proj=proj; this.te=te;//we pass the ference to the TransfoExterne internal to Thermoptim ep= (ExtProcess)obj;//retrieves the external class instantiated in TransfoExterne ep.proj=proj;//retrieves the reference of the project Vector vSetUp=new Vector(); vSetUp.addElement(te);//sends the reference to the TransfoExterne vSetUp.addElement(ep.JPanel1);//loads the interface vSetUp.addElement(ep.thermoCouplerTypes);//definition of the types of thermocouplers required setUpFrame(vSetUp);//execution of setCompFrame(); ep.tfe=this; } 4) if the construction is done while the project file is being read, the process parameters are updated 5) when a project is completely loaded, Thermoptim executes in each external component a special method called init() which performs initializations by referencing other instantiated external components (see section 3.4). This makes it possible to synchronize their methods.
3.2.1.2 Creating an external process
Thermoptim reference manual volume 3
January 2012
29 To create an external process, simply subclass extThopt.ExtProcess. Let us look at the example of the class SolarCollector (we have provided only part of the construction of the graphic interface here). public SolarCollector (){ super(); JPanel1.setLayout(null);//Layout of the JPanel JPanel1.setBounds(0,0,400,300);//dimensions of the JPanel (generally standard) JLabel1.setText("glass transmittivity");//definition of the first label JPanel1.add(JLabel1); JLabel1.setBounds(0,0,164,24); JPanel1.add(tau_value);//definition of the first editable text field for entering the glass transmittivity tau_value.setBounds(164,0,124,24); tau_value.setText("0.8"); type=getType();//type of process thermoCouplerTypes=new String[0];//no thermocoupler connected } public String getType(){ return "solar collector"; } public String getClassDescription(){ return "flat plate solar collector (without thermocoupler)\n\nauthor : R. Gicquel january 2003\n\nRef : note MODÉLISATION D'UN CAPTEUR SOLAIRE THERMIQUE"; }
3.2.2 Updating and calculating the process
Here we refer to the example of the class SolarCollector, whose model is presented in the note "SolarCollector.doc" The sequence of operations is as follows: 1) 2) 3) 4) 5) update the component before calculation by loading the values of the process and the upstream point read the parameters on the external component screen calculate the power used and the state of the downstream point calculate the thermal loads of the thermocouplers update the external component screen
Let us now look at the practical problems encountered during each of these steps. A few portions of the code are provided below, but we recommend reading the rest of this note while referring to the entire class SolarCollector.java. 1) update the component by loading the values of the process and the upstream point The problem here is that an external component does not have direct access to the simulator variables: these values are obtained by very general methods, which construct Vectors with different structures depending on the desired object. The procedure is not complicated, but it must be followed carefully: String[] args=new String[2]; //array of arguments args[0]="process";//type of element desired (a process in this case) args[1]=tfe.getCompName();//name of the process (obtained by the reference tfe) Vector vProp=proj.getProperties(args);//Project method given in Appendix 2 Double f=(Double)vProp.elementAt(3); double flow=f.doubleValue();//flow rate value, automatically propagated from the upstream process String amont=(String)vProp.elementAt(1);//name of the upstream point Thermoptim reference manual volume 3 January 2012
30 getPointProperties(amont);//automatic decoding of the Vector (method of the ExtProcess class) Tamont=Tpoint;//here T1 The method getPointProperties() of ExtProcess automatically loads the state of a point in easily manipulable values, called Tpoint, Point, lecorps... The method is given below. public void getPointProperties(String nom){ String[] args=new String[2]; args[0]="point";//type of the element (see method getProperties(String[] args)) args[1]=nom;//name of the process (see method getProperties(String[] args)) Vector vProp=proj.getProperties(args); lecorps=(Corps)vProp.elementAt(0); nomCorps=(String)vProp.elementAt(1); Double y=(Double)vProp.elementAt(2); Tpoint=y.doubleValue(); y=(Double)vProp.elementAt(3); Ppoint=y.doubleValue(); y=(Double)vProp.elementAt(4); Xpoint=y.doubleValue(); y=(Double)vProp.elementAt(5); Vpoint=y.doubleValue(); y=(Double)vProp.elementAt(6); Upoint=y.doubleValue(); y=(Double)vProp.elementAt(7); Hpoint=y.doubleValue(); y=(Double)vProp.elementAt(9); DTsatpoint=y.doubleValue(); String dum=(String)vProp.elementAt(8); isTsatSet=Util.lit_b(Util.extr_value(dum)); dum=(String)vProp.elementAt(10); isPsatSet=Util.lit_b(Util.extr_value(dum)); } 2) read the parameters on the external component screen The package extThopt provides a number of simple but robust methods for converting the Strings displayed in the JTextField fields used on the graphic interface to doubles, and vice versa for displaying the doubles in these fields. They are implemented as static methods of the extThopt.Util class (see Appendix 3): P=Util.lit_d(P_value.getText()); A=Util.lit_d(A_value.getText()); tau=Util.lit_d(tau_value.getText()); K=Util.lit_d(K_value.getText()); Tex=Util.lit_d(Tex_value.getText())+273.15; 3) calculate the power used and the state of the downstream point We begin by estimating the Cp of the heat-conducting fluid by making a limited development of the enthalpy function, which means we use the method CalcPropCorps() of the package Corps and the method getSubstProperties() of ExtProcess, which automatically loads the state of a point in easily manipulable values, called Tsubst, Psubst, etc. : public void getSubstProperties(String nom){ String[] args=new String[2]; args[0]="subst";//type of the element (see method getProperties(String[] args)) args[1]=nom;//name of the process (see method getProperties(String[] args)) Vector vProp=proj.getProperties(args); Double y=(Double)vProp.elementAt(0); Tsubst=y.doubleValue();//temperature y=(Double)vProp.elementAt(1); Thermoptim reference manual volume 3 January 2012
31 Psubst=y.doubleValue();//pressure y=(Double)vProp.elementAt(2); Xsubst=y.doubleValue();//value y=(Double)vProp.elementAt(3); Vsubst=y.doubleValue();//mass volume y=(Double)vProp.elementAt(4); Usubst=y.doubleValue();//internal mass energy y=(Double)vProp.elementAt(5); Hsubst=y.doubleValue();//mass enthalpy y=(Double)vProp.elementAt(6); Ssubst=y.doubleValue();mass entropy y=(Double)vProp.elementAt(7); Msubst=y.doubleValue();//molar mass Integer i=(Integer)vProp.elementAt(8); typeSubst=i.intValue();//type of substance (1 for water, 2 for a vapor, 3 for a pure gas, 4 for a compound gas, 5 for an external substance) } Then we can calculate the Cp as follows: double H=Hpoint;//enthalpy of the upstream point lecorps.CalcPropCorps(Tpoint+1, Ppoint, Xpoint);// recalculates the upstream substance by a Thermoptim function getSubstProperties(nomCorps);//retrieves the recalculation values (method of the ExtSubstance class) double Cp=(Hsubst-H);//estimated value of Cp We then calculate an estimated Taval value to be able to determine the absorbed thermal power Qex: double DT0=tau*P/K-Tamont+Tex; double T=Tamont+(DT0)*(1-Math.exp(-K*A/flow/Cp)); double DT=T-Tpoint; double Qex=Cp*DT*flow; We determine the value of the mass enthalpy of the downstream point, then we invert this equation to determine the exact value of Taval (method of the Corps class) double hAval=Qex/flow+Hpoint; Tpoint=lecorps.getT_from_hP(hAval,Ppoint); getSubstProperties(nomCorps);//retrieves the recalculation values (method of the ExtProcess class) Xpoint=Xsubst;//updates the value of the vapor quality in case the state is diphasic 4) calculate the thermal loads of the thermocouplers In this simple example, there is no problem, since the component does not use a thermocoupler. Brief instructions are given later in the manual, as well as in the section on external nodes. 5) update the external component screen The Thermoptim method setupPointAval() updates the downstream point from the values loaded in a Vector constructed here by the method getProperties() of ExtProcess: tfe.setupPointAval(getProperties()); The solar collector yield value is then determined and displayed. eff_value.setText(Util.aff_d(Qex/P/A, 4)); For this example, the updates before and after recalculation are very simple. In other cases, it may be necessary to access other data from the simulator. We will explain how to do this below. Thermoptim reference manual volume 3 January 2012
32
3.2.3 Moist calculations
To perform the calculations for moist gases from external classes, the method getPointProperties() of ExtProcess retrieves the moist properties values of a point by the following variables: Wpoint for the absolute humidity w, Epsipoint for relative humidity , Qprimepoint for specific enthalpy q', Tprimepoint for adiabatic temperature t' (in °C), Trpoint for dew point temperature tr (in °C), VPrimepoint for specific volume vs, Condpoint for condensates, and M_secpoint for the molar mass of the dry gas. The method updatePoint given in the appendix forces the following moist calculations: "setW and calculate all", sets w and calculates all of the moist properties "setW and calculate q'", sets w and calculates all of the moist properties except t' "setEpsi", which sets "setEpsi and calculate", sets and calculates all of the moist properties "calcWsat", calculates wsat and all of the moist properties except t' "modHum", modifies the composition of the gas
3.2.4 Managing Energy Types
It may first be necessary to manage the assignment of energy types in a more complex manner than in the processes of Thermoptim's basic set, which are basically mono-functional. For the processes, the energies used are either purchased, useful, or other. In an external process, things may be different, with for example a thermal load in purchased energy and a power in useful energy. The method updateProcess() of ComposantExt assigns the desired values to the different types of energy. It is easily used with the method setEnergyTypes of ExtThopt: tfe.updateProcess(setEnergyTypes(tfe.getCompName(),useful,purchased,other)); public Vector setEnergyTypes(String process, double useful,double purchased, double other){ Vector vEner=new Vector(); vEner.addElement(process);//process name vEner.addElement(new Double(useful));//useful energy vEner.addElement(new Double(purchased));//purchased energy vEner.addElement(new Double(other));//other energy return vEner; }
3.2.5 Access to other elements of the simulator
Access to upstream and downstream processes The names of the upstream and downstream processes are accessible by the elements 9 and 10 of the Properties Vector of the external process. String[] args=new String[2]; args[0]="process";//type of the element (see method getProperties(String[] args)) args[1]=tfe.getCompName();//name of the process (see method getProperties(String[] args)) Vector vProp=proj.getProperties(args); String transfoAmont=(String)vProp.elementAt(9);//name of the upstream process (or "null" if none) String transfoAval=(String)vProp.elementAt(10);//name of the downstream process (or "null" if none) Once the name has been obtained, we access its properties by sending it to args[1] in proj.getProperties(args). In this way we can recursively run through the upstream and downstream processes directly connected to a process.
Thermoptim reference manual volume 3
January 2012
33 This is the mechanism used to update the processes upstream and downstream of the external nodes in the method public void updateStraightlyConnectedProcess(String startProcess, String name, boolean downstream, boolean inletPoint, boolean outletPoint, boolean updateT, double T, boolean updateP, double P, boolean updateX, double x) of ExtNode. The example provided in the note "CycleLiBrH2O.doc" that is partially reprinted as an illustration of external nodes shows how to use these mechanisms. Let us note in passing that vProp=proj.getProperties(args) also gives access to certain global properties of the project if args[0]="project" (see Appendix 2), and specifically the flow unit. This is a way to verify that the flow and power units implicitly or explicitly used in the external class are compatible with those of the project, and to send a message otherwise. Thermocouplers Given that thermocouplers are a type of heat exchanger, it is valuable to define them by values such as effectiveness , UA, NTU or LMTD, that can be calculated using similar equations. The external component must send to each of its thermocouplers the equivalent values for flow rates, inlet and outlet temperature and thermal energy transferred, which they must take into account in their calculations. Specific methods were placed in the interface for this purpose. However, the analogy with exchanges has certain limits: for example, temperature crossovers unacceptable in an exchanger may occur in a thermocoupler, leading to absurd values. So it is best to transmit values that are unlikely to lead to this type of situation. One possible solution is to assume that the thermocoupler is isothermal for calculations of characteristics that are similar to exchanger characteristics, as in the model selected from the absorber and the desorber in the example presented in the note "TrigenMicroTAG.doc". To be able to accept multiple couplings, all the heatConnectable define an array of acceptable thermocoupler types (in the example above: String[]thermoCouplerTypes={"absorber","desorber"}). The calls are then done using the type of thermocoupler as the identifier, as in: public double getInletTemperature(String thermoCouplerType); When the array has dimension 1 and the heatConnectable is a process, the management can be simplified (see below). Otherwise, the heatConnectable has to be able to distinguish which thermocoupler is calling it, in order to know what to send it back by the interface methods. It must therefore register with each thermocoupler when the thermocoupler is created. This assumes that a consistency check is performed during the initial construction, and this check must be repeated for each subsequent reconstruction. For any external component there are also additional difficulties, given that its access to internal values is limited (the cases mentioned here are relative to process, but the problems also arise for nodes): the dimension of the array of acceptable thermocoupler types and those that are associated to it is not necessarily known, which means it must be initialized specifically in the method setCompFrame(Object obj) of ComposantExt, which is the pivot class where a large part of the exchanges between the internal part of the code and the external components are performed. the thermocoupler updates are done by the non-obfuscated method of TransfoExterne updateThermoCouplers(Vector vTC) the exchanges of information between the heatConnectable and its thermocouplers pass through Vectors, and it must be able to distinguish the different values depending on the role of each thermocoupler.
-
The method updateThermoCoupler() of ExtProcess performs the updates: updateThermoCoupler(String type, double Tin, double Tout, double Q, double flow) It sends the update elements to the thermocoupler via a Vector constructed by the methods of the ExtProcess class:
Thermoptim reference manual volume 3
January 2012
34 protected Vector getThermoCouplerVector(String type, double Tin, double Tout, double Q, double flow){ Vector vTC=new Vector(); vTC.addElement(type); Double d=new Double(Tin); vTC.addElement(d); d=new Double(Tout); vTC.addElement(d); d=new Double(Q); vTC.addElement(d); d=new Double(flow); vTC.addElement(d); return vTC; } Though it is not recommended, we can avoid using the method updateThermoCoupler() for a simple external process, with just one thermocoupler and for which the inlet and outlet temperatures, thermal load and flow rate values can be directly obtained from the values of the process. However, if there are more than one thermocouplers connected to the same process, each one must be updated after each recalculation. Note that a thermocoupler can be initialized only by the external component that it depends on. When a project is loaded, the state of the thermocouplers is updated only when the external components are calculated. To avoid problems during the first automatic recalculation of a project, we recommend performing a calculation of the external components equipped with thermocouplers using the method init() (see section 3.2.1.1). Nodes To identify the nodes to which a process can be connected, it is necessary to get the project nodes using the method proj.getNodeList(), retrieve the structure of each one by calling proj.getProperties() with the right arguments, and see if the name of the process appears among the names of the branches or the main process of the node. It's a bit laborious, but even from within Thermoptim, this is how it has to be done. Accessing the diagram editor It is also possible to access the content of the diagram editor from the following Project methods, which are somewhat difficult to use, especially the second one: getEditorComponentList(): provides the list of components present in the diagram editor, in the form "name"=componentName+tab+"type"=componentType. This list can be extracted easily using Util.extr_value("name") and Util.extr_value("type"). getConnectionCode(String[] args): sends a code showing whether two components of the editor are connected or not: 1 if the component 1 is upstream of component 2, -1 if it is downstream, and 0 if they are not connected. The structure of the arguments is as follows: String[] args=new String[4]; args[0]="Expansion";//type of component 1 args[1]="turbine";//name of component 1 args[2]="Exchange";//type of component 2 args[3]="régen gaz";//name of component 2 The type codes are those used in the saved project files.
3.2.6 SAVING THE MODEL
AND
LOADING
THE
PARAMETERS
OF
It is possible to save the parameters of the external components in the usual Thermoptim project files, and subsequently read them. public String saveCompParameters() public void readCompParameters(String ligne_data) Thermoptim reference manual volume 3 January 2012
35
The only constraint is that all of the parameters of the external component must fit on one line, in a format compatible with that used in the software basic set: the different save fields are separated by tabs. ExtThopt.Util provides a generic method for associating an identifying code to the value of a parameter: public static String extr_value(String ligne_data, String search) The save is done in the form "parameter-value" and the search is done in the same way: valeur=Util.lit_d(Util.extr_value(ligne_data, "parameter")); If the parameters of the component are too complex to be saved in this way, the user can use this mechanism to save the name of a specific parameter file and then read that file as necessary.
3.3 EXTERNAL NODES
We recommend that you refer to the API of extThopt.MixerExterne, extThopt.DividerExterne, extThopt.ExtMixer, extThopt.ExtDivider and extThopt.ExtNode to learn about the syntax and functions of all of the methods available. This API is part of the external class development environment available to you (in the folder api_extThopt).
3.3.1 CONSTRUCTION
The construction of an external node is identical to that of an external process.
3.3.2 UPDATING AND CALCULATING A NODE
Here we refer to the example of the class Absorber, a model of which is presented in the specific note called "CycleLiBrH2O.doc" presenting the internal model of an absorption cycle. The sequences of operations is as follows: 1) 2) 3) 4) 5) 6) consistency check and updating of the node before calculation reading the parameters on the external component screen updating the processes connected to the external node updating and calculating the associated thermocouplers updating the screen of the external component saving and loading the parameters of the model
Let us now look at the practical problems encountered during each of these steps. A few portions of the code are provided below, but we recommend reading the rest of this note while referring to the entire class Absorber.java. 1) consistency check and updating of the node before calculation There are several difficulties involved: first, it is highly important to make sure that the node is correctly constructed, i.e. that the branches and main process are indeed what the model designer expects. Since there is no consistency check for this in the diagram editor, a user can very easily make a mistake in describing the diagram. next, an external component has no direct access to the variables of the simulator: these values are obtained by very general methods, which construct Vectors with different structures depending on the desired object.
Consequently, the first step consists of checking the consistency of the node construction. To do this, the designer has a method of the ExtNode class, getNodeStructure(), which decodes the structure of the node, by loading in a String called mainProcess the name of the main process, and in a String Array called nomBranches[] the names of the processes of the different branches, the number of which corresponds to the dimension of the array.
Thermoptim reference manual volume 3
January 2012
36 The designer must program a method (called checkConsistency() in our example) in which he runs through the various processes of the node, performing all the tests he wants, and at the same time updating the inlet parameters of his model.
External mixer representing an absorber, with its connections For example, for the absorber, the method is as follows (to facilitate subsequent processing, we decided to load the names of the processes into easily identifiable Strings called richSolutionProcess, refrigerantProcess and poorSolutionProcess, and the names of the points into richSolutionPoint, refrigerantPoint and poorSolutionPoint): private void checkConsistency(){ String[] args=new String[2]; Vector[] vBranch=new Vector[2]; isBuilt=true; poorSolutionProcess=""; refrigerantProcess=""; if(nBranches!=2){//first test to check the number of branches String msg = "Error on the number of branches which is "+nBranches+" instead of 2"; JOptionPane.showMessageDialog(me, msg); isBuilt=false; } else{ for(int j=0;j<nBranches;j++){ args[0]="process";//type of the element (see method getProperties(String[] args)) args[1]=nomBranche[j];//name of the process (see method getProperties(String[] args)) vBranch[j]=proj.getProperties(args);//loads the corresponding process String aval=(String)vBranch[j].elementAt(2);//gets the downstream point name getPointProperties(aval);//direct parsing of point property vector String nom=nomCorps; Thermoptim reference manual volume 3 January 2012
37 //Check the substance at inlet //checks the name of the substance System.out.println(" ligne "+j+" nomCorps "+nomCorps); if(nom.equals("LiBr-H2O mixture")){//if it is a mixture, the poor solution was detected poorSolutionProcess=nomBranche[j]; poorSolutionPoint=aval; //initialise the inlet variables Tsp=Tpoint; Psp=Ppoint; Hsp=Hpoint; Xsp=Xpoint; Double f=(Double)vBranch[j].elementAt(3); msp=f.doubleValue(); } if(nom.equals("eau")){// if it is water, refrigerant was detected refrigerantProcess=nomBranche[j]; refrigerantPoint=aval; //initialise the inlet variables Prefr=Ppoint; Hrefr=Hpoint; Trefr=Tpoint; Double f=(Double)vBranch[j].elementAt(3); mr=f.doubleValue(); } } if((refrigerantProcess.equals(""))||(poorSolutionProcess.equals(""))){//otherwise there is an error String msg = "Error on at least one of the branch substances"; JOptionPane.showMessageDialog(me, msg); isBuilt=false; } } richSolutionProcess=mainProcess; args[0]="process";//type of the element (see method getProperties(String[] args)) args[1]=richSolutionProcess;//name of the process (see method getProperties(String[] args)) Vector vPropMain=proj.getProperties(args); Double f=(Double)vPropMain.elementAt(3); msr=f.doubleValue(); String amont=(String)vPropMain.elementAt(1);//gets the upstream point name getPointProperties(amont);//direct parsing of point property vector richSolutionPoint=amont; Tsr=Tpoint; Psr=Ppoint; Hsr=Hpoint; Xsr=Xpoint; String nom=nomCorps; //Check the substance at inlet if(!(nom.equals("LiBr-H2O mixture"))){//also check that the main process has the right substance String msg = "Error on main process substance,which is "+nomCorps+" instead of LiBr-H2O mixture"; JOptionPane.showMessageDialog(me, msg); isBuilt=false; } } 2) reading the parameters on the external component screen The package extThopt provides a number of simple but robust methods for converting to doubles the Strings displayed in the JtestField fields used on the graphic interface, and vice versa for displaying the doubles in these fields. They are implemented as static methods of the extThopt.Util class:
Thermoptim reference manual volume 3
January 2012
38 Tabs=Util.lit_d(Tabs_value.getText())+273.15; 3) updating the processes connected to the external node The processes associated with the node are updated in Thermoptim by the methods updateMixer(Vector vTC) and updateDivider(Vector vTC), which, in order to account for all possible cases, update the node and the process flow rates, as well as the upstream points of the outlet processes and the downstream points of the inlet processes. The designer of the external node must therefore correctly configure the Vector which passes as an argument. To do so, he can use two generic methods of ExtMixer and ExtDivider classes: updateMixer(Vector[]vTransfo,Vector[]vPoints, double TGlobal, double hGlobal) updateDivider(Vector[]vTransfo,Vector[]vPoints, double TGlobal, double hGlobal)
to which he must provide Vector arrays for the processes and points of each branch and the main vein, as well as the global temperature and enthalpy values. To set up the Vectors, ExtNode has a generic method: void setupVector(String process, String point, int i, double m, double T, double P, double X) i is the index of the two Vectors, process and point are the names of the process and the point, m is the flow rate of the process, T is the temperature, P is the pressure and X is the vapor quality of the process point closest to the node. In our example, the solution was to use three intermediate methods to set up the Vectors: - setupRichSolution(double m, double T, double P, double X) - setupPoorSolution(double m, double T, double P, double X) - setupRefrigerant(double m, double T, double P, double X) Then size the Vector arrays defined in ExtMixer and run updateMixer(): vTransfo= new Vector[nBranches+1]; vPoints= new Vector[nBranches+1]; setupRichSolution(msr,Tabs,Psr,Xsr); setupPoorSolution(msp,Tsp,Psp,Xsp); setupRefrigerant(mr,Trefr,Prefr,1); updateMixer(vTransfo,vPoints,Tsr,Hsr); For routine cases, once the flow rates and the upstream or downstream points of the processes linked to the node have been updated, Thermoptim propagates the recalculation of the various elements using the automatic recalculation engine. However, this may not suffice and the node designer may have to propagate the updates himself. In fact, this is true in our example for the propagation of the refrigerant concentration value of the mixture LiBr-H2O. This value is stored in what is normally the vapor quality, which is never propagated automatically. In this case, the designer must look at all the points downstream and upstream of the one whose composition was modified, to make sure that they have been correctly updated as well. He can use the method updateStraightlyConnectedProcess() of the ExtNode class, which recursively runs through the processes connected upstream and downstream of the node: updateStraightlyConnectedProcess(richSolutionProcess, richSolutionProcess, false,//boolean downstream, true,//boolean inletPoint, true,//boolean outletPoint, false,//boolean updateT, 0,//double T, false,//boolean updateP, 0,//double P, true,//boolean updateX, Thermoptim reference manual volume 3 January 2012
39 Xsr); 4) updating and calculating the associated thermocouplers Refer to section 3.2.3 on external processes for a general explanation on updating thermocouplers. The objective is for the component to send to each of its thermocouplers the equivalent values for flow rates, inlet and outlet temperature and thermal energy transferred, which they must take into account in their calculations. The method updateThermoCoupler() of the ExtMixer or ExtDivider classes performs the updates: updateThermoCoupler("absorber", Tabs, Tabs, Qabs, msr); For example, here we assumed that the absorber is at temperature Tabs, that it is receiving thermal load Qabs and that it is supplied with a flow rate msr. If we had not taken the temperature of the absorber as a reference for the exchange calculations, keeping the temperatures of the steam entering and exiting the external process, we would have ended up with an unacceptable temperature crossover resulting in an error diagnosis by Thermoptim. Unlike external processes, the update should always be done with the method updateThermoCoupler(), even for external nodes using only one thermocoupler. 5) updating the screen of the external component Refer to the section on external processes.
3.3.3 MANAGING ENERGY TYPES
As in the case of external processes, it may be necessary to manage the assignment of energy types of an external node, whereas this problem does not arise for the nodes of the Thermoptim basic set. To avoid making the existing system more cumbersome, the solution is to artificially assign the desired values to the different types of energy of the main vein of the external node (see section 3.2.3). The method updateProcess() of the ComposantExt class can do this, provided that the main vein is a process point. Otherwise, the energy types set will be reinitialized each time a recalculation is performed. For example the Desorber class could set its thermocoupler load as purchased energy by: de.updateProcess(setEnergyTypes(richSolutionProcess,0,Qgen,0));
3.3.4 SAVING THE MODEL
AND
LOADING
THE
PARAMETERS
OF
Refer to the section on external processes.
3.4 ACCESS TO AND PROCESSES
INSTANCES
OF
EXTERNAL
NODES
The preceding sections and Appendix 1 explain how to access the various unprotected instances of Thermoptim. The procedures, which are relatively cumbersome, are limited due to the internal consistency constraints of the software. However, an external component developer may wish to have full access to the classes he creates, in order to synchronize the calculations among them. He can do this with the getExternalClassInstances() method of the Project class, which builds a Vector provided in Appendix 2, containing the various instantiated external nodes and processes, with an identifying description. Thermoptim reference manual volume 3 January 2012
40
As an example, the external node of the main vein "myProcess" and of the type "myType" can be obtained by the following code: MaClasse monInstance ; Vector vExt=proj.getExternalClassInstances(); for(int i=0;i<vExt.size();i++){ Object[] obj=new Object[6]; obj=(Object[])vExt.elementAt(i); String type=(String)obj[0]; if(type.equals("node")){ String main=(String)obj[4]; String nodeType=(String)obj[3]; if((main.equals(myProcess))&&((nodeType.equals("myType ")))){ myInstance=(MyClasse)obj[1]; myInstanceName=(String)obj[2]; } } } Once the instance is found, its members can be accessed under Java rules, according to their access modifiers (public, protected, etc.)
3.5 EXTERNAL DRIVING OF THERMOPTIM
External driving of Thermoptim has two main applications: to facilitate the development of external classes by testing them as they are being defined to give access to all of the non-protected libraries for various purposes (perform external calculations between recalculations, guide a user in a training module, etc.).
To make external driving possible, the main class of the simulator, Projet, can be subclassed, and a number of non-protected methods can be overloaded to define specific calculations in addition to those of the basic set. The details of these methods are provided in the Appendix. In the examples below, the class ProjetThopt inherits from Projet, while the class Pilot is used to manage the driver. To avoid confusion, these two classes have been defined in a separate package called "pilot".
3.5.1 FACILITATING EXTERNAL CLASSES
THE
DEVELOPMENT
OF
The principle consists of instantiating Thermoptim from the external class Pilot, then launching it using the appropriate methods of the class ProjetThopt. Windows users should refer to section 6 "External Class Development Environment" which explains how to use the freeware JCreator to set up a small user-friendly working environment. In the example below, Pilot instantiates Thermoptim using the following code; only the first two methods are necessary, and the other are given to illustrate certain possibilities: runThopt(); loadProject(); listProcesses(); printProperties(); recalcProperties(); The mandatory methods are: public void runThopt(){ proj=new ProjetThopt();//instantiate Thermoptim Thermoptim reference manual volume 3 January 2012
41 proj.show();//display the simulator screen proj.openEditor();//display the diagram editor } public void loadProject(){ String[] args=new String[4]; args[0]="complet.prj";//project file name args[1]="complet.dia";//diagram file name args[2]=".";//working directory args[3]="noTest";//no save test if a project is already open proj.loadSelection(args);//load the example defined in args[] } In order for the external classes under development to be taken into account in Thermoptim, they must be declared in the method getInternalClasses() of the ProjetThopt class. The figure below shows how to proceed.
Method getInternalClasses() to load the tested classes in Thermoptim The package extThopt includes a Util class that provides a number of utility methods for formatting numbers, reading them onscreen, saving and reading values, finding roots using the bisection method, etc. (see Appendix 3). Once the classes are defined, compile them, then launch the driver by typing F5. The example defined in the method loadProject() of the Pilot class will be loaded when you click on the button "Run Thermoptim and load example" on the driver screen.
3.5.2 PROVIDING LIBRARIES
ACCESS
TO
THE
UNPROTECTED
There are two ways to drive Thermoptim: either completely from an external application that instantiates and sets parameters for the software, or partially, for a given project. In the first case, the principle consists of instantiating Thermoptim from the external class Pilot, then accessing its libraries using the appropriate methods of the class ProjetThopt as explained in the previous section. For example, you can instantiate a substance and calculate its thermodynamic properties, or display a thermodynamic diagram and plot a pre-recorded cycle. The driver acts as an independent application that can launch Thermoptim, which it considers as a library of external classes, and build projects by instantiating Thermoptim classes. Since it knows these instances, it can learn their state at any time. For the time being, it is impossible to access the driver from inside Thermoptim. When the driver is launched, a window appears with buttons for launching Thermoptim and loading an example. The corresponding class (Pilot) has a few basic methods for: launching Thermoptim: runThopt() loading an example: loadProject() Thermoptim reference manual volume 3 January 2012
42 accessing the properties of the simulator elements: proj.getProperties(args) simplifying the parsing of the properties vectors: getSubstProperties(String nom), getPointProperties(String nom), extr_value(String s), lit_b(String s) In the second case, a specific driver class is assigned to a given project, and this class is instantiated when the project is loaded. This class can coordinate the recalculations of the project according to specific rules. The driver class is an extension of extThopt.ExtPilot, which derives from rg.thopt.PilotFrame. To be able to link it to a project, it must first be made into an external class so that it can be loaded in Thermoptim when it is launched. Once the project is open, select the driver class linked to it via the line "Pilot frame" in the Special menu. If the project is saved, the name of the driver class is saved so that it can be instantiated when the project is loaded. Driving Thermoptim calcThopt(): launches a recalculation in Thermoptim setupThopt(): instantiates the diagram editor and disables certain functions of Thermoptim openEditor(): instantiates the diagram editor setControls(): enables to take control between two recalculations, to modify certain parameters of Thermoptim, for example loadSelection(String[] args): loads the examples Accessing the simulator String[] getHxList (): list of the exchangers of the project String[] getNodeList (): list of the nodes of the project String[] getPointList (): list of the points of the project String[] getProcessList(): list of the processes of the project String[] getSubstanceList (): list of the substances of the project Vector getProperties(String[] args): properties Vector. Its structure, which depends on the type of element in question, is provided in the Appendix void notifyElementCalculated(String[] element) : this method is executed in Thermoptim each time an element (point, process, node, exchanger) is calculated. Argument element is constructed as follows: if(pt instanceof Transfo) element[0]="process"; else if(pt instanceof PointCorps) element[0]="point"; else if(pt instanceof Node) element[0]="node"; else if(pt instanceof HeatEx) element[0]="heatEx"; element[1]=pt.getName(); element[2]=pt.getType(); Thus, element can be directly used as an argument in getProperties(): getProperties(element) gives the state of the element at stake. Another access point is the Class Corps, which has a number of public methods accessible from the driver, including: CalcPropCorps (double T, double p, double x) : calculates the complete state of a substance getSubstProperties() : properties Vector a number of methods for inverting the state functions. Accessing the diagram editor getEditorComponentList() : provides the list of components present in the diagram editor, in the form name="componentName"+tab+type="componentType". This list can be extracted easily using extr_value("name") and extr_value("type"). getConnectionCode(String[] args) : sends a code showing whether two components of the editor are connected or not: 1 if the component 1 is upstream of component 2, -1 if it is downstream, and 0 if they are not connected. The structure of the arguments is as follows: String[] args=new String[4]; args[0]="Expansion";//type of component 1 args[1]="turbine";//name of component 1 args[2]="Exchange";//type of component 2 args[3]="régen gaz";//name of component 2
Thermoptim reference manual volume 3
January 2012
43
3.6 INTEGRATING EXTERNAL LIBRARY EXTUSER.ZIP
CLASSES
IN
THE
Once the external classes are developed, they must be integrated into the library extUser.zip so that they can be automatically recognized in the purely executable version of Thermoptim. As indicated by its extension, file extUser.zip is a compressed archive which must be built in a specific format. You can do it by using either a utility named "external class manager" or a standard compressor such as Winzip, as indicated in the next sections.
3.6.1 USING THE EXTERNAL CLASS MANAGER
In the JCreator environment (see section 4), the "external class manager" utility is installed in a directory next to Thermoptim, on the same level as folder "jre", which contains the libraries it needs. Copy the archive "extUser.zip" from the installation directory of Thermoptim into the external class manager directory, and launch the application. The window below appears. In the upper left hand part, it displays all of the classes available in the class library directory, with the file path indicated in the file ExtLib.ini (by default the directory "externalClassLibrary"). These classes are arranged by type (substances, external processes, external mixtures, external dividers, drivers). On the right hand side, the content of the "extUser.zip" archive is displayed, arranged in the same manner. Thus it is easy to compare the two sets of classes. If you select one class in either of the lists, a description appears in the window below. You can also select multiple classes, in which case nothing is displayed. You can transfer one or more classes from the class library (on the left) to the "extUser.zip" archive by clicking on the arrow in the middle.
External class manager
Thermoptim reference manual volume 3
January 2012
44 If a class selected exists already in the archive, a message is displayed showing the creation dates of the two classes, and asking you if you want to replace or keep the existing one.
You can remove one or more classes from the archive "extUser.zip" by clicking on the button "Remove from extUser.zip". A message asks you to confirm the deletion for each class selected, with the option to save the class in the class library. If you want to save a class that exists already in the library, a message is displayed showing the creation dates of the two classes, and asking you if you want to replace or keep the existing one.
With the two buttons called "export info", you can create text files called "zipList.txt" or "libraryList.txt" which contain the name, type and description of each class. When the left and right windows are loaded, a test is performed to check that the classes are not of the same type, which could cause errors in Thermoptim. If they are the same type, you must differentiate them and recompile the modified classes. Finally, the button "update" updates the two windows once all transfers and removals have been completed. Once you have finished modifying the archive "extUser.zip", copy it to the installation directory of Thermoptim. If a problem arises and the archive extUser.zip is damaged (the applications won't open), the file "extUser_sauv.zip" contains the latest version. Rename it and launch the application.
3.6.2 USING A STANDARD COMPRESSOR
It is also possible to use a standard compressor such as WinZip by adding the new class in the archive. However, problems have been reported with certain versions of WinZip. With WinZip, you can proceed as follows: - create a new directory and call it "zip", then create a sub-directory in that directory called "extThopt"; - copy all the classes that you want to load in extUser.zip into this directory (the classes are located in the class creation directory of your development environment (/extThopt/); - Don't forget to quit Thermoptim, otherwise you will not be able to write to the archive extUser.zip; - Open extUser.zip, click on "Add" and go to the directory "zip". Select the option "Recurse folders" then click on "Add With Wildcards", which will add the entire contents of the sub-directory extThopt (the file path to the classes in the archive must be correct, otherwise Thermoptim will not be able to load them). Thermoptim reference manual volume 3
Loading extUser.zip with Winzip
January 2012
45
If you encounter difficulties, send an e-mail to thermoptim.cenerg.fr, and attach the class you want to add to extUser.zip. The new archive will be returned to you promptly.
3.6.3 MODIFYING JAVA LIBRARIES
THE
CLASSPATH
FOR
ADDING
If you want to add other Java libraries that your classes call, you have to indicate their file path in the classpath. In Windows, open the Thermoptim configuration file "Thopt.cfg" in a text editor, and add their file paths after "cp", separated by semicolons. Use a similar procedure for Unix and Macintosh.
Thermoptim configuration file
3.6.4 VIEWING EXTERNAL CLASSES
To help you use and manage the external classes, the line External Class Viewer from the Special menu of the simulator displays all of the external classes available. They are sorted by type (substances, processes, mixers, dividers, drivers) with a short description of the class selected and where it comes from (extThopt.zip and extUser.zip archives as well as classes under development). This screen can be consulted while you are developing your model. The more careful you are in writing the description of your classes, the more helpful this screen will be to users. Remember that it is very important to document your classes thoroughly, and you can include the documentation reference in your description. The documentation is composed of two parts, one for users and one for class designers. A poorly documented class will be difficult to use or modify.
Viewing the available external classes
4 EXTERNAL CLASS DEVELOPMENT ENVIRONMENT
Thermoptim reference manual volume 3
January 2012
46 To develop external classes, if you do not already have a Java development environment and if you work in Windows, you can use a freeware application called JCreator. Developed by Xinox Software, JCreator can be downloaded from http://www.jcreator.com/. With JCreator, you can write your classes in Java, and compile and test their integration in Thermoptim. To make things easier, a start-up workspace is provided. It is called ThoptExterne or ThoptExterneEdu.
4.1 PRESENTATION OF THE WORKSPACE
The workspace consists of the following: in the left part of the screen there is a list of Java files, including a small class called Starter, which launches the driver, and the classes under development (external files). in the right part you have the various tabs containing the code of the classes. the bottom window is for messages.
JCreator workspace
4.2 INSTALLING JCREATOR
To install the development environment, you need the following files: the Java Development Kit JDK installer, jdk-1_1_8_009-win.exe the JCreator installer, jcrea350.zip or a more recent version The archive ThoptEdu.jar or Thopt.jar of Thermoptim and your license keys the external libraries, JCreatorWorkspaceEdu.ZIP
In the following section, we are assuming that the reader is familiar with the basics of Java. Otherwise, we suggest reading a beginner's manual before trying to use the development environment. We recommend the manual "Introduction to Java" by Borland, which can be downloaded from Thermoptim reference manual volume 3 January 2012
47 http://www.borland.com/techpubs/jbuilder. It is also best to install the documentation of the JDK (jdk118doc.zip) as well as the documentation for Swing classes (SWING103.ZIP), which we consult regularly when developing in Java. Before installing JCreator, you have to install the Java development environment distributed by Sun, called the Java Development Kit, or JDK, which it uses to perform the compilations and execute the code that you develop. Java has evolved considerably in recent years, and it exists in several versions. There are three versions with major differences: version 1.0, which is hardly used anymore, version 1.1, supported by almost all systems and web browsers, and versions 1.2 to 1.5, also called Java 2, the most recent and most powerful, but also the most resource-consuming. For each of these versions, there are variants, indicated by a third digit (the latest version 1.1 is referenced 1.1.8). Because versions 1.0 and 1.1 are relatively rudimentary in terms of interfaces, Sun has developed a series of libraries called Swing or JFC (Java Foundation Classes), which are totally integrated into version 2, and of which several versions exist as well. To save system resources, Thermoptim uses JDK version 1.1.8, as well as the Swing classes 1.0.3. Consequently, you must install this version of the JDK. As indicated above, you should also install the JDK documentation. This will enable you to consult the API of the Java classes from JCreator. Start by installing the JDK and its documentation, then JCreator. When you run JCreator for the first time, the software gives you the option of linking the extensions of certain files. Click OK unless you have a good reason not to. Then choose the file paths to the directories containing the JDK and its documentation. Decompress the file JCreatorWorkspaceEdu.ZIP and place the folder ThoptExterneEdu in the folder named "myProjects" of the JCreator installation directory. This is a workspace containing all the files you need to work with Thermoptim. Add the archive ThoptEdu.jar or Thopt.jar of Thermoptim and inth.zip (version 1.5 or higher), as well as your license files (all of these files are located in the Thermoptim installation directory). Launch JCreator, select "File/Open Workspace" and choose "ThoptExterne.jcw". The application cannot run correctly because it is not fully configured. Open the menu Projects/Project settings. You will see a screen like the one below on the left. Verify which JDKs appear and which one is checked. If only JDK 1.1.8 is installed on your machine, go on to the next step. Otherwise, if JDK 1.1.8 appears but another JDK is checked, check JDK 1.1.8. If it is not listed, click "New" then select the installation directory of JDK 1.1.8 and click "OK", then make sure it is checked.
Configuration of JDK
Configuration of libraries
Next you have to indicate the libraries required by your application, in this case all of the libraries Thermoptim needs to work, plus Thermoptim itself. Click on the tab "Required Libraries" then on "New" then "Add" and select from the "ThoptExterne" directory the files that appear on the screen below on the right: ThoptEdu.jar or Thopt.jar, extUser.zip, im.zip, inth.zip, extThopt.zip, gef060.jar, swingall.jar. Once the archives are selected, click "OK". You can now start developing your external classes as indicated in section 3.
Thermoptim reference manual volume 3
January 2012
48 The API (Application Programming Interface) for the Thermoptim methods accessible from external classes is defined in the JavaDoc located in the folder "api_Thermoptim" of the development environment. The source code of the base classes of the package extThopt is given in the form of a JCreator Workspace called ClassesExternes. These classes are already contained in the archive extThopt.zip and should not be loaded in the development environment. You can modify them, but they may no longer be compatible with the "official" versions of the Thermoptim external classes. Appendix 1 describes how they are used and gives a number of examples. Appendix 2 gives the code for the Thermoptim methods that return Vectors whose details it is useful to know for programming external classes. Appendix 3 contains a brief description of the methods in the Util class.
4.3 EMULATING THERMOPTIM FROM JCREATOR
To be able to emulate Thermoptim in order to test a class under development, we created a special workspace in JCreator, in which three classes that we present here play a key role: Starter is the class launched when JCreator starts up. It initializes the output files ("output.txt" and "error.txt") and instantiates the Pilot class of the pilot package; Pilot is the class that launches Thermoptim, instantiating the class ProjetThopt of the same package and running the method runThopt(). Next, the method loadProject() displayed on the screen of the figure presenting the workspace loads a project and a diagram for testing the external classes under development. In the JCreator workspace figure, we have entered different examples, since only the last one loaded in the array args[] is taken into account (this enables us to change examples easily, by moving the two lines involved); ProjetThopt, which inherits from the class Projet of Thermoptim, has a method called getInternalClasses() in which the external classes to be loaded in Thermoptim are defined.
-
Once the methods loadProject() and getInternalClasses() have been modified, simply recompile the project and run it so that the load window of Thermoptim and its project appear. By clicking on "Run Thermoptim and load example", you load the example you want. You can use all the features of the software, including the ability to modify and save your example. If a project or diagram file is missing, a message will alert you. In this way, you can develop your class and directly test it in Thermoptim, which will save a lot of time. Once the class is developed simply archive it in extUser.zip so that it can be distributed and used outside the development environment. Practically speaking, the procedure is as follows: Following the instructions given in chapter 3, start by creating your external class, either by modifying one of the ones provided (the java files are in the directory "src" of the Workspace) or from the JCreator assistant (menu Project/New Class), and compile it (menu Build/Compile file) Declare your class in the method getInternalClasses() of the class ProjetThopt, following the instructions provided, so that it is loaded in Thermoptim when the software is loaded, and recompile ProjetThopt To test your class, duplicate a project and diagram example, enter the new names on the last lines of the array args[] in the method loadProject() of Pilot, and recompile Pilot. Launch execute (menu Build/Execute Project, or F5) and click on "Run Thermoptim and load example"
Driver class screen
The screen of the Pilot class has another button allowing you to instantiate another class if you want to. Simply write the corresponding code in the method bOtherClass_actionPerformed(). Thermoptim reference manual volume 3 January 2012
49
APPENDIX 1 : THERMOPTIM METHODS BE CALLED BY EXTERNAL CLASSES
WHICH
CAN
In this appendix, we present Thermoptim methods which can be called by external classes, indicating what is their purpose and giving a number of implementation examples. Their API is itself defined in the JavaDoc that is in the directory api_Thermoptim of the development environment
package rg.corps
Two class names are not obfuscated: rg.corps.Corps, mother class of all substances and rg.corps.CorpsExt, mother class of all external substances. The following methods can be called by external classes:
In Corps
To calculate a substance state public void CalcPropCorps (double T, double p, double x) To instantiate a substance whose name is known public static Object createSubstance(String nomCorps) example : Object obj=Corps.createSubstance("eau");//instantiation of the substance, wrapped in an Object Corps leau=(Corps)obj;//transtyping of the Object double T=leau.getT_from_hP(3400,50);// Reverse calculation inT of the enthalpy the pressure being known System.out.println("T eau : "+T); To get the Cp of a substance knowing its Cv public double getCp(double Cv) Reverse calculation of state functions public double getP_from_hT(double hv,double T) public double getP_from_sT(double sv,double T) public double getP_from_sT(double sv,double T, double pmin, double pmax) public double getP_from_vT(double v,double T ) public double getT_from_hP(double hv,double P) public double getT_from_sP(double sv,double P) public double getT_from_sv(double s,double v) public double getT_from_uv(double u,double v) public double[] getQuality(), used with all previous methods, gives the the vapor-liquid equilibrium composition. In particular, for pure substances, getQuality() [0] is the steam quality. Methods for calculating the saturation pressure or temperature public double getSatPressure(double T, double x) public double getSatTemperature(double P, double x) To get a substance state public Vector getSubstProperties() method getSubstProperties() of extProcess indirectly uses this method to load the values of the double Tsubst,Psubst,Xsubst,Vsubst,Usubst,Hsubst,Ssubst,Msubst,typeSubst; example : lecorps.CalcPropCorps(Tpoint+1, Ppoint, Xpoint);//calculates the substance state Thermoptim reference manual volume 3 January 2012
50 getSubstProperties(nomCorps);// retrieves the calculated values and loads them in particular in Hsubst double Cp=(Hsubst-H); typeSubst is 1 for water, 2for steam, 3 for a pure gas, 4 for a compound gas, 5 for a single external substance, and 6 for an external substance of the Mixture type. Initialization of an external substance public void initCorpsExt(double M, double PC, double TC, double VC, double Tmini, double Tmaxi, double Pmini, double Pmaxi, int typeCorps) Defines a comment for an external substance (chemical formula, composition ...) public void setComment(String comment) Gives a name to an external substance public void setNom(String name) Loads values of calculations made by the external substance public void setState(double P, double T, double xx, double U, double H, double S, double V, double Cv, double Xh) To get a gas composition public Vector getGasComposition() example : getPointProperties(cO2Point);// retrieves the properties of point cO2Point Vector nouvComp=lecorps.getGasComposition();//retrieves the gas composition updateGasComp(nouvComp, cO2Process);//updates the gas composition To update a gas composition public void updateGasComp(Vector vComp) The Vector structure is as follows: public void updateGasComp(Vector vComp){ Integer i=(Integer)vComp.elementAt(0); int nComp=i.intValue(); String[] Comp= new String[nComp]; double[]fractmol= new double[nComp],fractmass= new double[nComp]; Double[]fracMol= new Double[nComp],fracMass= new Double[nComp]; Comp=(String[])vComp.elementAt(1); fracMol=(Double[])vComp.elementAt(2); fracMass=(Double[])vComp.elementAt(3); for(int j=0;j<nComp;j++){ Double f=(Double)fracMol[j]; fractmol[j]=f.doubleValue(); f=(Double)fracMass[j]; fractmass[j]=f.doubleValue(); } updateSubstComp(Comp,fractmol,fractmass); }
In CorpsExt
public double getLiquidConductivity(double T) public double getLiquidViscosity(double T) public double getVaporConductivity(double T) public double getVaporViscosity(double T)
Thermoptim reference manual volume 3
January 2012
51
package rg.thopt
The following class names are not obfuscated: - rg.thopt.Projet, simulator class, - rg.thopt.TransfoExterne, rg.thopt.DividerExterne, rg.thopt.MixerExterne et rg.thopt.ComposantExt, used to define the external components - rg.thopt.Compression and rg.thopt.ComprExt, used to define the external compressors. The following methods can be called
In Projet
Launches Thermoptim recalculation from the driver public void calcThopt() returns a code that allows the driver to know if two components of the editor are connected or not: public int getConnectionCode(String[] args) 1 if component 1 is the upstream component 2, -1 otherwise, and 0 if not connected. The argument structure is the following : String[] args=new String[4]; args[0]="Expansion";//type of component 1 args[1]="turbine";//name of component 1 args[2]="Exchange";//type of component 2 args[3]="régen gaz";// name of component 2 Lists the components in the diagram editor public String[] getEditorComponentList() edited as name="nomComposant"+tab+type="typeComposant". This list can be broken easily with extr_value("name") and extr_value("type") Lists of elements public String[] getHxList () public String[] getNodeList () public String[] getPointList () public String[] getProcessList() public String[] getSubstanceList () Vector of properties whose structure depends on the type of element considered public Vector getProperties(String[] args) type=args[0]; "subst" / "point" / "process" / "heatEx" nomType=args[1]; This method is fundamental: it allows access to all data related to a primitive type once one the type and name known. It is widely used by generic methods of extThopt package. The corresponding Thermoptim internal code is given in annex 2. It lets you know the structure of the Vector returned (depending on the type of primitive called). Loading of examples by the Thermoptim driver public void loadSelection(String[] args) method executed in Thermoptim each time an item (point, process, node, exchanger) is calculated public void notifyElementCalculated(String[] element)
Thermoptim reference manual volume 3
January 2012
52 element is constructed as follows: if(pt instanceof Transfo) element[0]="process"; else if(pt instanceof PointCorps) element[0]="point"; else if(pt instanceof Node) element[0]="node"; else if(pt instanceof HeatEx) element[0]="heatEx"; element[1]=pt.getName(); element[2]=pt.getType(); Thus, it can directly be used as an argument in getProperties(): getProperties(element) provides the state of the element. allows the driver to take control between two recalculations, to modify certain Thermoptim parameters public void setControls() instantiates the diagram editor and used to disable certain functions by the Thermoptim driver public void setupThopt() instantiates the diagram editor public void openEditor() loading external classes in the Thermoptim driver public Vector getInternalClasses() Operations on the charts from the Thermoptim driver public void setupChart (Vector v) example of opening chart, choice of substance and drawing of two cycles if(proj!=null)proj.calcThopt();//if necessarye instantiation of Thermoptim Vector v=new Vector(); v.addElement("openDiag");//opening of a chart v.addElement("1");// chart type (1 for vapors, 2 for ideal gas, 3 for psychrometric) proj.setupChart(v); v=new Vector(); v.addElement("selectSubstance");//selection of a substance v.addElement("R134a");//name of the substance proj.setupChart(v); v=new Vector(); v.addElement("readCycle");//loading a cycle v.addElement("frigoR134aFin.txt");//file name proj.setupChart(v); v=new Vector(); v.addElement("readCycle");// loading a cycle v.addElement("frigoR134a.txt");// file name proj.setupChart(v); updates a point or a process public void updatePoint(Vector v) example : method updateStraightlyConnectedProcess() of ExtNode includes: Vector vPoint=new Vector(); vPoint.addElement(outletPointName); vPoint.addElement(Util.aff_b(updateT)); vPoint.addElement(Util.aff_d(T)); vPoint.addElement(Util.aff_b(updateP)); vPoint.addElement(Util.aff_d(P)); vPoint.addElement(Util.aff_b(updateX)); Thermoptim reference manual volume 3 January 2012
53 vPoint.addElement(Util.aff_d(x)); proj.updatePoint(vPoint);
In PilotFrame
To get a handle on the Projet calling public void getProjet ()
In ComposantExt
To calculate the component public void calcProcess() To get the component's name public String getCompName() To get the component's type public String getCompType() To read the component settings saved in the project file public void readCompParameters(String ligne_data) To save the component settings in the project file public String saveCompParameters() To initialize the component screen and its internal logical configuration public void setCompFrame(Object obj) public void setDivFrame (Object obj) public void setMixFrame (Object obj) to update the process (flow, inlet point, outlet point, energy types) public void setupFlow(double flow) public void setupPointAmont(Vector vProp) public void setupPointAval (Vector vProp) public void updateProcess(Vector vEner) To construct the Vector vProp, ExtProcess has a generic method, which wraps the point state: public Vector getProperties(){ Vector vProp=new Vector(); vProp.addElement(lecorps);//Corps vProp.addElement(nomCorps);//Corps vProp.addElement(new Double(Tpoint)); vProp.addElement(new Double(Ppoint)); vProp.addElement(new Double(Xpoint)); vProp.addElement(new Double(Vpoint)); vProp.addElement(new Double(Upoint)); vProp.addElement(new Double(Hpoint)); return vProp; } example : tfe.setupPointAval(getProperties()); method updateProcess() of ComposantExt can assign values to different types of energy. It is easily implemented with the method setEnergyTypes() ExtThopt (see Section 3.2.3). example : Thermoptim reference manual volume 3 January 2012
54
tfe.updateProcess(setEnergyTypes(useful,purchased,other));
In TransfoExterne
To update a thermocoupler public void updateThermoCouplers(Vector vTC) To construct the Vector vTC, ExtProcess has a generic method, which wraps the values: protected void updateThermoCoupler(String type, double Tin, double Tout, double Q, double flow){ Vector vTC=new Vector(); vTC.addElement(type);//type du thermocoupleur considéré Double d=new Double(Tin); vTC.addElement(d); d=new Double(Tout); vTC.addElement(d); d=new Double(Q); vTC.addElement(d); d=new Double(flow); vTC.addElement(d); tfe.te.updateThermoCouplers(vTC); } Provides the values of the thermocoupler of the type called public Vector getThermoCouplerData(String thermoCouplerType) The Vector returned contains only for the moment the thermocoupler name, but this should evolve.
In DividerExterne
Updates the divider public void updateDivider (Vector vTC) To construct the Vector vTC, ExtProcess has a generic method, which wraps the values: protected Vector getUpdateVector (Vector[]vTransfo,Vector[]vPoints, double TGlobal, double hGlobal){ Vector vTC=new Vector(); for(int j=0;j<vTransfo.length;j++){ vTC.addElement(vTransfo[j]); } for(int j=0;j<vPoints.length;j++){ vTC.addElement(vPoints[j]); } Vector vGlobal=new Vector(); vGlobal.addElement(new Double(TGlobal)); vGlobal.addElement(new Double(hGlobal)); vTC.addElement(vGlobal); de.de.updateDivider(vTC); } In ExtDivider the call is made as follows : protected void updateDivider(Vector[]vTransfo,Vector[]vPoints, double TGlobal, double hGlobal){ Vector vTC=getUpdateVector(vTransfo,vPoints, TGlobal, hGlobal); de.de.updateDivider(vTC); } Thermoptim reference manual volume 3 January 2012
55
These methods make use of tables of Vector vTransfo and vPoint representing the main vein and branches, which may be useful to automate the construction, as in the Desorber class, where generic methods called by a name with a physical sense are used to build the Vector: private void setupRichSolution(double m, double T, double P, double X){ vTransfo[0]=new Vector(); vPoints[0]=new Vector(); vTransfo[0].addElement(richSolutionProcess); vTransfo[0].addElement(new Double(m)); vPoints[0].addElement(richSolutionPoint); vPoints[0].addElement(new Double(T)); vPoints[0].addElement(new Double(P)); vPoints[0].addElement(new Double(X)); } example : update of external divider Desorber after calculation : vTransfo= new Vector[nBranches+1]; vPoints= new Vector[nBranches+1]; setupRichSolution(msr,Tsr,Psr,Xsr); setupPoorSolution(msp,Tgen,P,Xsp); setupRefrigerant(mr,Trefr,Prefr,1); updateDivider(vTransfo,vPoints,Tsr,Hsr); Gives the divider values public Vector getDividerData() Currently not used, because duplicating getProperties() Project executed for a node. ExtDivider it provides method public void getDividerStructure() which loads the structure of the node. To update a thermocoupler (see TransfoExterne) public void updateThermoCouplers(Vector vTC) Provides the values of the thermocoupler of the type called (see TransfoExterne) public Vector getThermoCouplerData(String thermoCouplerType)
In MixerExterne
Updates the mixer (see DividerExterne) public void updateMixer (Vector vTC) Gives the mixer values (see DividerExterne) public Vector getMixerData () Pour mettre à jour un thermocoupleur (voir TransfoExterne) public void updateThermoCouplers(Vector vTC) Provides the values of the thermocoupler of the type called (see TransfoExterne) public Vector getThermoCouplerData(String thermoCouplerType)
In ComprExt
public double getComprFlow() public double getComprIsentropicEfficiency() public String getComprName() Thermoptim reference manual volume 3 January 2012
56 public double getComprRatio() public double getComprRelaxValue() public double getComprRotationSpeed() public double getComprSweptVolume() public String getComprType() public double getComprVolumetricEfficiency() public double getComprVolumetricFlow() public double getPumpFanVolumetricFlow() public Vector getSupplyPointProperties() public void makeComprDesign() public void readComprParameters(String line) public String saveComprParameters() public void setComprFrame(Object ob)
Thermoptim reference manual volume 3
January 2012
57
ANNEX 2 : THERMOPTIM METHODS CODE
We give here the code of certain Project and Corps methods whose structure must be faithfully reproduced if they are to be used in subclasses.
Method getProperties() of Projet
/** * Fournit les valeurs thermodynamiques des divers types primitifs *<p> * Gives thermodynamic values for the various element * @param args String[] * @param type=args[0]; "project" / "subst" / "point" / "process" / "heatEx" * @param nomType=args[1]; **/ public Vector getProperties(String[] args){ String type, nomType; type=args[0]; nomType=args[1]; Vector vProp=new Vector(); if(type.equals("project")){ vProp.addElement(Util.unit_m);//unité des débits //flow rate unit vProp.addElement(Util.unitT);//unité des températures //temperature unit vProp.addElement(new Double(Util.T0Exer)); } else if(type.equals("subst")){ Corps pt=getCorps(nomType); if(pt!=null){ vProp=pt.getSubstProperties(); } } else if(type.equals("point")){ PointCorps pt=getPoint(nomType); if(pt!=null){ vProp.addElement(pt.lecorps);//Substance vProp.addElement(pt.lecorps.getNom());//Substance name vProp.addElement(new Double(pt.getT()));//Temperature vProp.addElement(new Double(pt.getP()));//Pressure vProp.addElement(new Double(pt.getXx()));//Quality vProp.addElement(new Double(pt.getV()));//Volume vProp.addElement(new Double(pt.getU()));//Internal energy vProp.addElement(new Double(pt.getH()));//Enthalpy vProp.addElement(new Double(pt.getS()));//Entropy String setTsat="set_Tsat="+Util.aff_b(pt.JCheckSetTsat.isSelected()); vProp.addElement(setTsat);//setTsat vProp.addElement(new Double(pt.dTsat_value.getValue()));//DTsat String setpsat="set_psat="+Util.aff_b(pt.JCheckSetPsat.isSelected()); vProp.addElement(setpsat);//setpsat //wet gas values vProp.addElement(new Double(pt.w_value.getValue()));//specific humidity vProp.addElement(new Double(pt.epsi_value.getValue()));//relative humidity vProp.addElement(new Double(pt.qprime_value.getValue()));//specific enthalpy vProp.addElement(new Double(pt.tprime_value.getValue()));//adiabatic temperature vProp.addElement(new Double(pt.tr_value.getValue()));//dew point temperature vProp.addElement(new Double(pt.v_spec_value.getValue()));//specific volume vProp.addElement(new Double(pt.cond_value.getValue()));//condensates vProp.addElement(new Double(pt.lecorps.M_sec));//Dry gas molar mass Thermoptim reference manual volume 3 January 2012
58
} } else if(type.equals("process")){ Transfo tf=getTransfo(nomType); vProp.addElement(tf.getType()); if(tf!=null){ vProp.addElement(tf.getPointAmont().getName()); vProp.addElement(tf.getPointAval().getName()); vProp.addElement(new Double(tf.getFlow()));//flow rate vProp.addElement(new Double(tf.DeltaH));//Enthalpy vProp.addElement(tf.ener_type_value.getText());//Energy type String direct="calcDirect="+Util.aff_b(tf.IcalcDirect); vProp.addElement(direct);//true if direct calculation String ouvert="openSyst="+Util.aff_b(tf.JCheckOuvert.isSelected()); vProp.addElement(ouvert);//true for open system String setflow="setFlow="+Util.aff_b(tf.JCheckSetFlow.isSelected()); vProp.addElement(setflow);//true for set flow String inletProcess="null"; if(tf.isInletStrConnected())inletProcess=tf.getTransfoAmontName();//inlet process name (if exits) vProp.addElement(inletProcess); String outletProcess="null"; if(tf.isOutletStrConnected())outletProcess=tf.getTransfoAvalName();//outlet process name (if exits) vProp.addElement(outletProcess); if(tf instanceof Combustion){ Combustion cb=(Combustion)tf; String fuel="null"; if(cb.getFuel()!=null)fuel=cb.getFuel().getName(); vProp.addElement(fuel); vProp.addElement(new Double(cb.lambda_value.getValue()));//lambda vProp.addElement(new Double(cb.Tfluegas));//combustion temperature vProp.addElement(new Double(cb.tfig_value.getValue()));//quenching temperature vProp.addElement(new Double(cb.t_diss_value.getValue()));//dissociation rate String calcLambda="calcLambda="+Util.aff_b(cb.JCheckCalcLambda.isSelected()); vProp.addElement(calcLambda);//true if calculate lambda set String calcT="calcT="+Util.aff_b(cb.JCheckCalcT.isSelected()); vProp.addElement(calcT);//true if calculate T set String setFuelFlow="setFuelFlow="+Util.aff_b(cb.JCheckFuelFlow.isSelected()); vProp.addElement(setFuelFlow);//true if calculate with set fuel flow String dissoc="setDissoc="+Util.aff_b(cb.Check_dissoc.isSelected()); vProp.addElement(dissoc);//true if dissociation set String premix="setPremix="+Util.aff_b(cb.JCheckPremix.isSelected()); vProp.addElement(premix);//true if premix set String setV="setV="+Util.aff_b(cb.JChecksetV.isSelected()); vProp.addElement(setV);//true if set volume String setP="setP="+Util.aff_b(cb.JChecksetP.isSelected()); vProp.addElement(setP);//true if set pressure String setT="setT="+Util.aff_b(cb.JChecksetT.isSelected()); vProp.addElement(setT);//true if set temperature } } } else if(type.equals("node")){ Node the_node=getNode(nomType); if(the_node!=null){ vProp.addElement(the_node.mainProcess.getName());//main process name vProp.addElement(the_node.getClassType());//node type Thermoptim reference manual volume 3 January 2012
59 vProp.addElement(the_node.getEffNode());//node effectiveness vProp.addElement(Util.aff_b(the_node.isoBaric));//is node isobaric? vProp.addElement(new Integer(the_node.vBranch.size()));//number of branches for(int j=0;j<the_node.vBranch.size();j++){ Object[] branch=(Object[])the_node.vBranch.elementAt(j); Transfo the_process=(Transfo)branch[0]; vProp.addElement(the_process.getName());//branch process name } } } else if(type.equals("heatEx")){ HeatExDemo hX=getHX(nomType); if(hX!=null){ String coldFluid="",hotFluid=""; if(hX instanceof ThermoCoupler){ ThermoCoupler tc=(ThermoCoupler)hX; coldFluid=tc.getHcName(); hotFluid=tc.getExchange().getName(); } else { coldFluid=hX.getColdFluid().getName(); hotFluid=hX.getHotFluid().getName(); } vProp.addElement(hotFluid);//hot fluid process name vProp.addElement(coldFluid);//cold fluid process name vProp.addElement(hX.getHxType());//heat exchanger type (counterflow, parallel flow...) vProp.addElement(Util.aff_b(hX.JCheckTceImp.isSelected()));//set Tce vProp.addElement(Util.aff_b(hX.JCheckTcsImp.isSelected()));//set Tcs vProp.addElement(Util.aff_b(hX.JCheckMcImp.isSelected()));//set mc vProp.addElement(Util.aff_b(hX.JCheckTfeImp.isSelected()));//set Tfe vProp.addElement(Util.aff_b(hX.JCheckTfsImp.isSelected()));//set Tfs vProp.addElement(Util.aff_b(hX.JCheckMfImp.isSelected()));//set mf vProp.addElement(Util.aff_b(hX.JCheckMinPinch.isSelected()));//set minimum pinch vProp.addElement(Util.aff_b(hX.JCheckSetEff.isSelected()));//set effectiveness vProp.addElement(Util.aff_b(hX.IcalcDirect));//set direct calculation (not used I think) vProp.addElement(Util.aff_b(hX.JCheckDesign.isSelected()));//set design mode vProp.addElement(new Double(hX.R));//R value vProp.addElement(new Double(hX.NUT));//NUT value vProp.addElement(new Double(hX.UA));//UA value vProp.addElement(new Double(hX.DTML));//DTML value vProp.addElement(new Double(hX.epsi_value.getValue()));//effectiveness value vProp.addElement(new Double(hX.DTmin_value.getValue()));//pinch value } } return vProp; }
Method updatePoint () of Projet
/** * met à jour un point, avec recalcul éventuel * valable pour calculs humides *<p> * updates a point, possibly with recalculation * valid for moist gas calculations */ public void updatePoint(Vector properties){ String nomPoint=(String)properties.elementAt(0); PointCorps point=getPoint(nomPoint); Thermoptim reference manual volume 3 January 2012
60 if(point!=null){ String test=(String)properties.elementAt(1); boolean updateT=Util.lit_b(test); String value=(String)properties.elementAt(2); double T=Util.lit_d(value); test=(String)properties.elementAt(3); boolean updateP=Util.lit_b(test); value=(String)properties.elementAt(4); double P=Util.lit_d(value); test=(String)properties.elementAt(5); boolean updateX=Util.lit_b(test); value=(String)properties.elementAt(6); double x=Util.lit_d(value); //pour mélanges humides if(properties.size()>7){ test=(String)properties.elementAt(7); boolean melHum=Util.lit_b(test); if(!melHum){//calculs à effectuer dans le cas général //general case if(updateT)point.setT(T); if(updateP)point.setP(P); if(updateX)point.setX(x); point.CalculeUnPoint(); } else{//calculs humides //wet point calculations String task=(String)properties.elementAt(8); value=(String)properties.elementAt(9); if(task.equals("setW and calculate all")){//sets w and calculates moist properties double w=Util.lit_d(value); point.setW(w); point.calcHum(); } if(task.equals("setW and calculate q'")){//sets w and calculates moist properties except t' double w=Util.lit_d(value); point.setW(w); point.calcQprime(); } if(task.equals("setEpsi")){//sets epsilon double epsi=Util.lit_d(value); point.setEpsi(epsi); point.impHumRel(); } if(task.equals("setEpsi and calculate")){//sets epsilon and calculates moist properties double epsi=Util.lit_d(value); point.setEpsi(epsi); point.impHumRel(); point.calcQprime(); } if(task.equals("calcWsat")){//calculates saturation properties and moist properties except t' T=Util.lit_d(value); double wsat=point.wsat(T); point.setW(wsat); point.calcQprime(); } if(task.equals("modHum")){//modifies the gas composition point.modGasHum(false); } Thermoptim reference manual volume 3 January 2012
61 } } else{//calculs à effectuer dans le cas général if(updateT)point.setT(T); if(updateP)point.setP(P); if(updateX)point.setX(x); point.CalculeUnPoint(); } } }
Method getSubstProperties() of Corps
/** * donne les fonctions d'état du substance * <p> * gives the substance state functions * @return Vector *<p> * do not override */ public Vector getSubstProperties(){ Vector vProp=new Vector(); vProp.addElement(new Double(T));//Temperature vProp.addElement(new Double(P));//Pressure vProp.addElement(new Double(xx));//Quality vProp.addElement(new Double(V));//Volume vProp.addElement(new Double(U));//Internal energy vProp.addElement(new Double(H));//Enthalpy vProp.addElement(new Double(S));//Entropy vProp.addElement(new Double(M));//Molar mass vProp.addElement(new Integer(typeCorps));//Substance type return vProp; }
Method getExternalClassInstances () of Projet
/** * Provides the external class instances * * @return a Vector containing the instances and their type */ public Vector getExternalClassInstances(){ Vector vInstances=new Vector(); Primtype pt; int nbProcess=vProcess.size(); for(int i=0;i<nbProcess;i++){ pt=(Primtype)vProcess.elementAt(i); if(pt instanceof TransfoExterne){ Object[] obj=new Object[6]; TransfoExterne te=(TransfoExterne)pt; obj[0]="process"; obj[1]=te.cType.externalInstance;//instance de la classe externe obj[2]=te.getName(); obj[3]=te.cType.externalInstance.getType();//type de la classe externe obj[4]=te.getPointAmont().getName(); obj[5]=te.getPointAval().getName(); vInstances.addElement(obj); } } Thermoptim reference manual volume 3 January 2012
62 int nbNode=vNode.size(); for(int i=0;i<nbNode;i++){ pt=(Primtype)vNode.elementAt(i); if((pt instanceof MixerExterne)||(pt instanceof DividerExterne)){ Node nd=(Node)pt; Object[] obj=new Object[6]; obj[0]="node"; obj[1]=nd.cType.externalInstance;//instance de la classe externe obj[2]=nd.getName(); obj[3]=nd.cType.externalInstance.getType();//type de la classe externe obj[4]=nd.getMainProcess().getName(); obj[5]=new Integer(nd.getBranches().size()); vInstances.addElement(obj); } } return vInstances; }
Method setupChart () of Projet
public void setupChart(Vector properties){ String task=(String)properties.elementAt(0); String value=(String)properties.elementAt(1); if(task.equals("openDiag")){ int i=Util.lit_i(value); setupChart(false); cm.setupChart(i); } else if(task.equals("selectSubstance")&& cm!=null){ Graph graph=cm.getChart(); graph.getDiagIni().setSelectedSubstance(value); graph.select_vap(); } else if(task.equals("readCycle")&& cm!=null){ Graph graph=cm.getChart(); graph.litCycle(value,""); graph.setConnectedCycle(); } else if(task.equals("unSelectCycle")&& cm!=null){ Graph graph=cm.getChart(); graph.setupCycleManager(); CycleManager cM=graph.getCycleManager(); cM.unSelect(value); graph.repaint(); } else if(task.equals("removeCycle")&& cm!=null){ Graph graph=cm.getChart(); graph.setupCycleManager(); CycleManager cM=graph.getCycleManager(); cM.removeCycle(value); graph.repaint(); } else if(task.equals("setChartType")&& cm!=null){ Graph graph=cm.getChart(); graph.setChartType(value); } } Thermoptim reference manual volume 3 January 2012
63
ANNEX 3 : UTILITY METHODS OF CLASS UTIL
Class ExtThopt.Util provides a number of utility methods to facilitate the programming of external classes: Display methods · · · · public static String aff_i(int i) : affiche un entier public static String aff_b(boolean b) : affiche un booléen public static String aff_d(double d) : affiche un double public static String aff_d(double d, int dec) : affiche un double avec dec décimales
Conversion methods · · · public static int lit_i(String s ) : lit un entier public static boolean lit_b(String s) : lit un booléen public static double lit_d(String s ) : lit un double
Methods extracting values from a String · · public static String extr_value(String s) public static String extr_value(String ligne_data, String search)
The first method extracts "3.4" from "value = 3.4", whatever the text to the left of the equal sign. It can be used with a StringTokeniser separating couples "value = xxx". The second combines with StringTokeniser separator tab and the previous method, searching for the couple "search = xxx". Both methods return null in case of failure. Function inversion methods · public static double dicho_T (Inversable inv, double value,double param, String function, double valMin, double valMax,double epsilon )
This generic method allows the inversion of a function by dichotomy. The class must implement the Inversable interface, which requires to define method f_dicho: public double f_dicho(double x, double param, String function) value is the objective value for the method returned by f_dicho, the variable x varies between valMin and valMax, epsilon is the accuracy criterion, and function is a String allowing to identify a particular method in f_dicho: if (function.equals("P_LiBr"))return getP(x,T); After 50 iterations, dicho_T returns 0 if no convergence. Methods for handling a pure gas in a gas composition Vector · · · public static double molarComp(Vector vComp,String pureGas) : gives the molar fraction of pureGas public static boolean contains(Vector vComp,String pureGas) : gives true if pureGas exists public static void updateMolarComp(Vector vComp,String pureGas, double newFractMol) : updates the molar fraction of pureGas
Thermoptim reference manual volume 3
January 2012
64
ANNEXE 4 : TEP THERMOSOFT - INTERFACE JAVA / DELPHI APPLICATION À THERMOPTIM (PAR F. RIVOLLET)
Ce document explique le principe de passerelle entre TEP ThermoSoft et Thermoptim. Ces deux programmes sont écrits respectivement en Pascal sous environnement Delphi et en Java. L'objectif est le calcul des propriétés thermodynamiques nécessaires sous Thermoptim à partir des modèles développés pour TEP ThermoSoft.
Structure de dialogue entre les deux programmes
Le schéma ci-dessous reprend le principe de dialogue entre les deux programmes et les fichiers nécessaire à un calcul. TEP ThermoSoft - Calcul (TEPThermoSoftCalc.dll)
Thermoptim
Interface de liaison entre les deux programme (TEPThermoSoftJava.dll) Fig. 1 : Relations entre les fichiers Fichier système (fichier .mel)
Ensemble des modèles de calcul. (fichiers .dll)
La principale difficulté est la compatibilité des fonctions appelées du Java vers le Pascal. Pour ce faire, une librairie spécifique (TEPThermoSoftJava.dll) permet d'assurer le passage des variables entre les deux entités. La définition et l'exécution des calculs au sein de TEP ThermoSoft nécessitent : · La routine principale (TEPThermoSoftCalc.dll) · un fichier système (fichier .mel) qui rassemble l'ensemble des propriétés de calcul. · les modèles thermodynamiques écrits sous forme de librairies (.dll) et contenus dans un répertoire spécifique. Remarque : Les deux fichiers TEPThermoSoftCalc.dll et TEPThermoSoftJava.dll doivent se situer dans le même répertoire.
Exécuter un calcul en java Définition des méthodes de dialogue avec TEP ThermoSoft
Les méthodes suivantes doivent être définies en Java comme faisant référence à la librairie externe « Delphi2Java.dll ». Leur fonction et leur syntaxe sont expliquées dans les paragraphes 2.2 à 2.5 et un exemple est donné en 2.6. public native int InitSession(String RepMODELES); public native void FermerSession(); public native int ChargerSysteme (String FichierMEL); public native double Lire(String Symbole); public native void Ecrire(String Symbole, double valeur); Thermoptim reference manual volume 3 January 2012
65
public native void Calculer(String code);
Chargement/Libération des modèles thermodynamiques en mémoire
Avant tout calcul, la méthode « InitSession » doit être appelée afin d'initialiser l'ensemble des paramètres et de spécifier le répertoire contenant les modèles thermodynamiques « .dll ». InitSession(System.getProperty("user.dir")+File.separator+"TEPThermoSoft_DLL"+File.separator); Cette fonction retourne un entier qui détermine un code d'état : 0 -1 Pas d'erreur Erreur inconnue
Une fois que les fonctions de calcul ne sont plus nécessaires, il est souhaitable de libérer la mémoire en appelant « FermerSession » FermerSession() ; Une utilisation répétée de ces deux méthodes peut ralentir les calculs. Il est ainsi préférable de regrouper les calculs quand cela est possible.
Définition d'un système
Un « système » représente soit un substance pur, soit un mélange de plusieurs composés. Toutes les informations relatives au calcul de ses propriétés (Modèles thermodynamiques, valeurs des paramètres de calcul, ...), sont regroupées dans un fichier unique dont l'extension est « .mel ». Ce fichier peut être ouvert avec un simple éditeur de texte. Sa structure reprend celle d'un fichier « .ini » sous Windows. Cela signifie que des catégories sont définies entre crochets : [GENERAL] NOM = Melange DATE = 25/04/2005 HEURE = 08:17:56 [CPS] 994 1000
Propriétés générales sur le système
AMMONIA WATER
Informations sur les composés
[ELV] S S // ... // P P P // .. // P P P P P P // .. //
CAlpha AlphaMC.dll CCPGP CPGP107.dll a(1) a(2) ALPHA(1) CP107(2)[0] 33363 CP107(2)[1] 26790 P Pa Pc(1) 11280005.625 Pc(2) 22055007.45 Pa PHI|l(1)
Modèles thermodynamiques à utiliser
Symboles et Valeurs des paramètres de calcul Pa
Thermoptim reference manual volume 3
January 2012
66 Au sein de TEP ThermoSoft, tout calcul se réfère à un système donné. Pour cela, il faut, à partir de l'application Java, charger les paramètres de calcul en mémoire à l'aide de la fonction « ChargerSysteme » en spécifiant le fichier système voulu : ChargerCalcul(System.getProperty("user.dir")+File.separator+"mixtures"+File.separator+"TEPThermoSoft_ MEL"+File.separator+selectedFile); Cette méthode retourne un entier qui spécifie le numéro du mélange chargé en mémoire. Ce numéro sera utile lors de l'utilisation de plusieurs mélanges en parallèle. Dans un premier temps un seul mélange sera pris en considération. De plus, ce numéro, s'il est négatif, indique une erreur lors du chargement du fichier. Pour le moment les codes d'erreur sont les suivants : -1 -2 -3 Erreur inconnue Fichier introuvable Aucun composé défini dans le fichier.
Modifier / Lire des variables de TEP ThermoSoft
Une fois un fichier de mélange chargé en mémoire, deux méthodes ont été écrites pour permettre de modifier et de lire les valeurs des variables se référant au système. Toute variable intervenant dans les calculs peut être modifiée ou lue. Pour cela il suffit de respecter la typographie suivante : SYMB(cps)[vecteur]|phase SYMB cps vecteur phase symbole de la variable à modifier (Ex. T : Température Cf. 0) composé ou interaction entre composés (Ex. (1) , (2), (1_2)). La numérotation des composés commence à 1. numéro du vecteur (ex. [0], [1], ...). La numérotation des vecteurs commence à 0. lors de données multiphasiques, la barre | suivi d'une lettre (l ou v) permet de définir la phase recherchée (ex. |l ou |v).
Par exemple, la lecture de la température peut se faire par la méthode : double temperature = Lire("T"); De même la modification du premier paramètre de la fonction Alpha de Mathias-Copeman pour le composé 2 s'écrit : Ecrire("MC(2)[0]", 0.152);
Lancer un calcul
Pour lancer un calcul, il suffit d'écrire la valeur des paramètres de calcul au moyen de la méthode « Ecrire » vue précédemment, puis de lancer le calcul par la méthode « Calculer » : Calculer("Tx"); La méthode « Calculer » attend un paramètre qui définit le type de calcul souhaité (cf. 0) Dans l'exemple cidessus, il s'agit d'un calcul d'équilibre LV en mélange en spécifiant la température et la composition liquide. Ainsi, avant d'exécuter cette fonction il est nécessaire de bien définir les variables T et x comme par exemple pour un binaire : Ecrire("T",280); Ecrire("x(1)",0.1); Thermoptim reference manual volume 3 January 2012
67 Ecrire("x(2)",0.9);
Exemple d'écriture d'un calcul complet
Voici un exemple de lignes de commande permettant un calcul à l'équilibre LV du système « NH3-H2O» défini dans le fichier système « NH3-H2O.mel » : InitSession(System.getProperty("user.dir")+File.separator+"TEPThermoSoft_DLL"+File.separator); // ChargerSysteme(System.getProperty("user.dir")+File.separator+"mixtures"+File.separator+"TEPThermoSoft_M EL"+File.separator+"NH3-H2O.mel"); // Ecrire("T",280); Ecrire("x(1)",0.1); Ecrire("x(2)",0.9); // Calculer("Tx"); // P = Lire("P"); y[0] = Lire("y(1)"); y[1] = Lire("y(2)"); // FermerSession() ;
Variables et méthodes de calcul disponibles Variables classiques
Voici une liste des symboles les plus utilisés dans les méthodes « Lire » et « Ecrire ». Symbole Unité Description
T P x(i) y(i) z(i) h, h|l, h|v s, s|l, s|v TauVap h0 s0 Mw(i)
K Pa
J/mol J/mol/ K
Température Pression Composition liquide du composé « i » Composition gaz du composé « i » Composition globale du composé « i » Enthalpie
Taux de vaporisation (= -1 lors d'un calcul ELV Px, Tx, Ty ou Py). J/mol Enthalpie de référence. J/mol Entropie de référence kg/mo Masse molaire du composé « i » l
Thermoptim reference manual volume 3
January 2012
68
Méthodes de calcul
Voici une liste des symboles des méthodes disponibles (elle sera complétée au fur et à mesure des besoins). Symbole Type de calcul4 Description
Tx Ty Px Py PTz
MEL MEL MEL MEL MEL
Calcul à l'équilibre LV en spécifiant la température et la composition liquide. Calcul à l'équilibre LV en spécifiant la température et la composition gaz. Calcul à l'équilibre LV en spécifiant la pression et la composition liquide. Calcul à l'équilibre LV en spécifiant la pression et la composition gaz. Calcul en spécifiant la composition globale, la pression et la température (données à l'équilibre ou hors équilibre LV).
Pour le moment la méthode PTz semble pouvoir suffire car valable en substance purs et en mélange (suivant les valeurs de z). De plus elle est continue à et hors ELV. Ainsi une méthode numérique simple devrait permettre d'estimer les valeurs à h et s constant.
4
MEL concerne les mélanges et CP, les corps purs. January 2012
Thermoptim reference manual volume 3
69
ANNEX 5 : UML DIAGRAMS OF EXTERNAL CLASSES
Substance class diagram
Thermoptim reference manual volume 3
January 2012
70 External component class diagram
Thermoptim reference manual volume 3
January 2012