;;; -*- Mode:Common-Lisp; Package:DME-USER; Base:10 -*- 

;;; DME Domain Theory: 
;;;     SIMPLE ENGINEERING THERMODYNAMICS 
;;; 

(in-package "CML-USER") 


;;; Naming conventions: 
;;; 
;;;   In general, the names of variables (functions) will be as follows: 
;;;     [d-][specific-]<name>[-rate][-in|-out] 
;;;  They will also have short-names for display purpose and the short names 
;;;  will follow the standard thermal engineering notation as much as possible. 
;;;  energy                e,E      - this and a few others added by Ho 
;;;  enthalpy              h,H 
;;;  mass                  m 
;;;  pressure              p 
;;;  entropy               s,S 
;;;  Temperature           T 
;;;  internal energy       u,U 
;;;  volume                v,V 
;;;  availability          b,B 
;;;  velocity              V 
;;;  height                z 
;;;  Area                  A 
;;;  work                  w,W 
;;;  heat                  q,Q 
;;;  quality/dryness fraction    x 
;;;  kinetic energy        ke,KE 
;;;  potential energy      pe,PE 
;;;---------------------------------------------------------------------- 

;;;---------------------------------------------------------------------- 
;;; SI Basic dimensions 
;;;---------------------------------------------------------------------- 

(defDimension amount-dimension 
  :documentation "The SI dimension of amount, usually measured in moles.") 

(defDimension current-dimension 
  :documentation "The SI dimension of electric current.") 

(defDimension dimensionless 
  :documentation "The dimensionless dimension.") 

(defDimension length-dimension 
  :documentation "The SI dimension of length.") 

(defDimension luminosity-dimension 
  :documentation "The SI dimension of luminosity.") 

(defDimension mass-dimension 
  :documentation "The SI dimension of mass.") 

(defDimension temperature-dimension 
  :documentation "The SI dimension of temperature.") 

(defDimension time-dimension 
  :documentation "The SI dimension of time.") 

;;;---------------------------------------------------------------------- 
;;; SI Derived dimensions 
;;;---------------------------------------------------------------------- 

(defDimension mass-rate-dimension 
    := (/ mass-dimension time-dimension)) 

(defDimension velocity-dimension 
    := (/ length-dimension time-dimension)) 

(defDimension area-dimension 
    := (expt length-dimension 2)) 

(defDimension volume-dimension 
    := (expt length-dimension 3)) 

(defDimension specific-volume-dimension 
    := (/ volume-dimension mass-dimension)) 

(defDimension energy-dimension 
    := (/ (* mass-dimension (expt length-dimension 2)) 
	      (expt time-dimension 2))) 

(defDimension specific-energy-dimension 
    := (/ energy-dimension mass-dimension)) 

(defDimension energy-rate-dimension 
  := (/ energy-dimension time-dimension)) 

(defDimension work-dimension 
    := energy-dimension)  

(defDimension power-dimension 
    := (/ work-dimension time-dimension))  

(defDimension entropy-dimension 
    := (/ energy-dimension temperature-dimension)) 

(defDimension specific-entropy-dimension 
    := (/ entropy-dimension mass-dimension)) 

(defDimension entropy-rate-dimension 
    := (/ entropy-dimension time-dimension)) 

(defDimension pressure-dimension 
    := (/ mass-dimension 
	      (* length-dimension 
		 (expt time-dimension 2)))) 

;;;---------------------------------------------------------------------- 
;;; SI Basic Units 
;;;---------------------------------------------------------------------- 

(defUnit meter :dimension length-dimension :pname "m") 

(defUnit kilogram :dimension mass-dimension :pname "kg") 

(defUnit second :dimension time-dimension :pname "s") 

(defUnit ampere :dimension current-dimension :pname "A") 

(defUnit kelvin :dimension temperature-dimension :pname "K") 

(defUnit mole :dimension amount-dimension :pname "mol") 

(defUnit candela :dimension luminosity-dimension :pname "cd") 

;;---------------------------------------------------------------- 
; additional units and dimensions 
;;---------------------------------------------------------------- 

(defDimension molecular-weight-dimension 
    :documentation "the dimension of mass/mole" 
    := (/ mass-dimension amount-dimension)) 

(defUnit kg/mol :dimension molecular-weight-dimension :pname "kg/mole" 
	 := (/ kilogram mole)) 

(defDimension density-dimension 
    :documentation "the dimension of mass/volume" 
    := (/ mass-dimension volume-dimension)) 

(defUnit kg/m^3 :dimension density-dimension :pname "kg/m^3" 
	 := (/ kilogram (expt meter 3))) 

(defDimension acceleration-dimension 
    :documentation "the dimension of acceleration" 
    := (/ velocity-dimension time-dimension)) 

(defUnit m/s^2 :dimension acceleration-dimension :pname "m/s^2" 
	 := (/ meter (expt second 2))) 

(defDimension frequency-dimension  
    := (expt time-dimension -1)) 

;;;--------------------------------------------------------------------- 
;;; Mathematical functions specific to this domain 
;;;--------------------------------------------------------------------- 

(defRelation mutual-dependence (?p ?t ?s ?h ?e ?v) 
  :documentation 
  "mutual-dependence is an n-ary operator.  The meaning is not 
    well-defined right now.  Eg: (mutual-dependence (stream-pressure 
    2d-stream-1) (stream-temperature 2d-stream-1) (specific-entropy 
    2d-stream-1) (specific-enthalpy 2d-stream-1) 
    (specific-internal-energy 2d-stream-1) (specific-volume 
    2d-stream-1)) We don't know how to compute this yet.  It will be a 
    call to an outside routine or a table lookup." 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

(defRelation compute-air-thermodynamic-state (?t ?s) 
  :documentation 
  "Computes the specific enthalpy from the temperature.  Eg: 
    (compute-air-thermodynamic-state (stream-temperature 2d-stream-1)) 
    We don't know how to compute this yet.  It will be a call to an 
    outside routine or a table lookup." 
  :function t 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

(defRelation compute-saturated-vapor-enthalpy (?p ?x) 
  :documentation 
  "Computes the specific enthalpy of saturated vapor from the quality (0 
    or 1) and the pressure.  Eg: (compute-saturated-vapor-entropy 
    (stream-pressure (stream-involved ?self)) (quality 
    (stream-involved ?self))) We don't know how to compute this yet. 
    It will be a call to an outside routine or a table lookup." ; 
  :function t 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

(defRelation compute-saturated-vapor-enthalpy (?x ?y) 
  :documentation 
  "Computes the specific enthalpy of saturated vapor from the quality (0 
or 1) and the pressure.  Eg: (compute-saturated-vapor-entropy 
(stream-pressure (stream-involved ?self)) (quality (stream-involved 
?self))) We don't know how to compute this yet.  It will be a call to 
an outside routine or a table lookup." 
  :function t 
  :class q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translate-*-expr dme::qsim-translate-*-expr) 


(defRelation compute-saturated-vapor-entropy (?p ?x) 
  :documentation 
  "Computes the specific entropy of saturated vapor from the quality 
(0 or 1) and the pressure. 
    Eg: (compute-saturated-vapor-entropy 
	  (stream-pressure (stream-involved ?self)) 
	  (quality (stream-involved ?self))) 
    We don't know how to compute this yet.  It will be a call to an 
outside routine or a table lookup." 
  :function t 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

(defRelation compute-saturated-vapor-specific-volume (?p ?x) 
  :documentation 
  "Computes the specific volume of saturated vapor from the quality (0 
or 1) and the pressure.  
    Eg: (compute-saturated-vapor-specific-volume 
	  (stream-pressure (stream-involved ?self)) 
	  (quality (stream-involved ?self))) 
    We don't know how to compute this yet.  It will be a call to an 
outside routine or a table lookup." 
  :function t 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

(defRelation compute-enthalpy-pressure-specific-entropy (?p ?s) 
  :documentation 
  "Computes the enthalpy from pressure and specific entropy.  We don't 
    compute this yet.  It will be a call to an outside routine or a 
    table lookup." 
  :function t 
  :class  q-expression-operator 
  :partial-eval-function dme::partial-eval-math-op 
  :qsim-translation-function dme::qsim-translate-*-expr) 

 
;;;---------------------------------------------------------------------- 
;;; Entity Definitions 
;;;---------------------------------------------------------------------- 

;;; Physical Entities 
;;;------------------- 

(defEntity Thermal-system 
  :subclass-of (thing) 
  :documentation "thermodynamic system" 
  ) 

(defRelation component-cv (?x ?y) 
  :=> (and (thermal-system  ?x) (control-volume ?y) (connection component-cv)) 
  :documentation "the control-volume associated with the system") 


(defEntity thermal-cycle 
  :subclass-of (thermal-system) 
  :documentation "a thermodynamic system involving a cycle" 
  :quantities 
  ((net-heat-output-rate :dimension power-dimension 
		:documentation "the net heat output rate of the thermal cycle" 
		:the-*-the-object ("net heat output rate" "of") 
		:abbreviation "Qo") 
   (net-work-output-rate :dimension power-dimension 
		:documentation "the net work output rate of the thermal cycle" 
		:the-*-the-object ("net work output rate" "of") 
		:abbreviation "Wo") 
   (net-heat-input-rate 
    :dimension power-dimension 
    :documentation 
    "the net heat input rate into the cycle from outside including only 
actively added heat such as heat added to the boiler but not including 
heat such as heat lost from the condenser" 
		:the-*-the-object ("net heat input rate" "of") 
		:abbreviation "Qi") 
   (thermal-efficiency 
    :dimension dimensionless 
    :documentation 
    "thermal efficiency of the whole cycle defined as 'sum of work / 
heat input to the cycle'" 
		:the-*-the-object ("net thermal efficiency" "of") 
		:abbreviation "e") 
   (back-work-ratio :dimension dimensionless 
		    :documentation "the ratio of the pump work inut tot the work developed by the turbine" 
		:the-*-the-object ("back work ratio" "of") 
		:abbreviation "bwr") 
   (cycle-mass-rate :dimension mass-rate-dimension 
		:documentation "the mass flow rate of the main medium flowing through the thermal cycle" 
		:the-*-the-object ("mass flow rate of the main medium" "through") 
		:abbreviation "m'") 
   ) 
  :consequences 
  ( 
   (= (/ net-work-output-rate 1000000) 
      (- net-heat-input-rate 
	 net-heat-output-rate))) 
  :operating-modes 
  (thermal-cycle-op-mode  cycle-heat-input  cycle-work-output) 
  ) 

(defRelation cycle-processes (?x ?y) 
  :=> (and (thermal-cycle ?x) (thermal-process ?y) ) 
  :documentation "the set of all the processes that are part of the cycle" 
  ) 

(defModelFragment thermal-process-op-mode 
  :subclass-of (dme-user::operating-mode-model) 
  :documentation "the operating modes of thermal processes" 
  :participants 
  ((process-involved :type thermal-process 
		   :documentation "the thermal process involved in the operating mode" 
		   ) 
  )) 

(defModelFragment  thermal-cycle-op-mode 
  :subclass-of (dme-user::operating-mode-model) 
  :documentation "the operating modes of thermal cycles" 
  :participants 
  ((cycle-involved :type thermal-cycle 
		   :documentation "the thermal cycle involved in the operating mode" 
		   ) 
   )) 

(defModelFragment thermal-component-op-mode 
  :subclass-of (dme-user::operating-mode-model) 
  :documentation "the operating modes of thermal components" 
  :participants 
  ((component-involved :type thermal-component 
		       :documentation "the thermal components involved in the operating mode" 
		       ) 
   )) 

(defModelFragment  cycle-heat-input 
  :documentation "the operating mode of a thermal cycle for computing the net heat input rate" 
  :subclass-of (thermal-process-op-mode 
		thermal-cycle-op-mode 
		control-volume-op-mode thermal-component-op-mode) 
  :conditions 
  ( 
   (process-cv process-involved cv-involved) 
   (component-cv component-involved cv-involved) 
   (connected-to-external-heat-source-p component-involved true) 
   ) 
   
  :consequences 
  ((C+ (heat-rate (process-involved ?self)) 
       (net-heat-input-rate (cycle-involved ?self)))) 
  ) 

(defModelFragment  cycle-work-output 
  :documentation "the operating mode of a thermal cycle for computing the net work output rate" 
  :subclass-of ( thermal-process-op-mode thermal-cycle-op-mode 
					 control-volume-op-mode) 
  :conditions 
  ( 
   (process-cv process-involved cv-involved) 
   ) 
  :consequences 
  ((C+ (work-rate (process-involved ?self)) 
       (net-work-output-rate (cycle-involved ?self)))) 
  ) 

(defEntity Thermal-component 
  :documentation "a thermodynamic device" 
  :subclass-of (Thermal-system) 
  :quantities  
  ((efficiency :dimension dimensionless 
	       		:documentation "the efficiency of a thermal component, which is defined differently depending on the type of component" 
		:the-*-the-object ("efficiency" "of") 
		:abbreviation "e") 
   (capacity  
		:documentation "the capacity of a thermal component, which is defined differently depending on the type of the component" 
		:the-*-the-object ("capacity" "of") 
		:abbreviation "c") 

   (connected-to-external-heat-source-p  
     :range-class boolean 
    :non-numeric t 
    :documentation "the attribute indicating that the control volume 
is connected to an active external heat source" 
    :value-names ((true "being heated") (false "not being heated")) 
   :the-*-the-object ("predicate indicating whether the thermal component is actively being heated by an external source" "of") 
   )) 
  :operating-modes 
  (thermal-component-op-mode cycle-heat-input) 
  ) 

(defEntity Port 
  :subclass-of (thermal-component) 
  :documentation 
  "In the thermal domain, all the ports are fluid ports.   
   Unlike 'terminal' in DME, a port is independent of a component. 
   It is a combination of a 'joint' and a 'terminal'. 
   " 
  :quantities ((port-area :dimension area-dimension 
			  :documentation "the area of the cross section of the port" 
		:the-*-the-object ("cross sectional area" "of") 
		:abbreviation "a") 

	       (port-elevation :dimension length-dimension 
			       :documentation "the elevation of the port with respect to some reference point" 
		:the-*-the-object ("elevation" "of") 
		:abbreviation "z") 
	       ) 
  ) 

(defEntity 1-input-thermal-component 
  :subclass-of (thermal-component) 
  :documentation "the class of thermal components with one inlet" 
  :attributes 
  ((component-inlet :type port 
		    :abbreviation in 
		    :documentation "the inlet port" 
		:the-*-the-object ("inlet" "of") 
		) 

   ) 
  ) 

(defEntity  1-output-thermal-component 
  :subclass-of (thermal-component) 
  :documentation "the class of thermal components with one outlet" 
  :attributes 
  ( 
   (component-outlet :type port 
		     :abbreviation out 
		     :documentation "the outlet port" 
		     :the-*-the-object ("outlet" "of")) 
   ) 
  ) 

(defEntity  2-input-thermal-component 
  :subclass-of  (thermal-component) 
  :documentation "the class of thermal components with two inlets" 
  :attributes 
  ( 
   (component-inlet1 :type port 
		     :abbreviation out1 
		     :documentation "the first inlet port" 
		:the-*-the-object ("inlet #1" "of") 
		) 

   (component-inlet2 :type port 
		     :abbreviation out2 
		     :documentation "the second inlet port" 
		:the-*-the-object ("inlet #2" "of") 
		) 
   ) 
  ) 

(defEntity   3-input-thermal-component 
  :subclass-of  (2-input-thermal-component) 
  :documentation "the class of thermal components with three inlets" 
  :attributes 
  ( 
   (component-inlet3 :type port 
		     :abbreviation out3 
		     :documentation "the third inlet port" 
		     :the-*-the-object ("inlet #3" "of")) 
   ) 
  ) 

(defEntity   2-output-thermal-component 
  :subclass-of ( thermal-component) 
  :documentation "the class of thermal components with two outlets" 
  :attributes 
  ( 
   (component-outlet1 :type port 
		      :abbreviation out1 
		      :documentation "the first outlet port" 
		      :the-*-the-object ("outlet #1" "of")) 
   (component-outlet2 :type port 
		      :abbreviation out2 
		      :documentation "the second outlet port" 
		      		:the-*-the-object ("outlet #2" "of")) 
   ) 
  ) 



(defEntity 1-1-port-thermal-component 
  :subclass-of  (1-input-thermal-component 1-output-thermal-component) 
  :documentation 
  "The class of thermal components with one inlet and one outlet." 
  :graphical-representation 
    (:component-slots-not-to-display (component-inlet component-outlet)) 
  ) 

(defEntity 1-2-port-thermal-component 
  :subclass-of  (1-input-thermal-component 2-output-thermal-component) 
  :documentation 
  "The class of thermal components with one inlet and two outlets." 
  ) 

(defEntity 2-1-port-thermal-component 
  :subclass-of  (2-input-thermal-component 1-output-thermal-component) 
  :documentation 
  "the class of thermal components with two inlets and one outlet" 
  ) 

(defEntity  2-2-port-thermal-component 
  :subclass-of  (2-input-thermal-component 2-output-thermal-component) 
  :documentation 
  "the class of thermal components with two inlets and two outlets" 
  ) 

(defEntity  3-1-port-thermal-component 
  :subclass-of  (3-input-thermal-component 1-output-thermal-component) 
  :documentation 
  "the class of thermal components with three inlets and one outlet" 
  ) 

(defEntity fuel 
  :documentation "the fuel used in power systems" 
  :subclass-of (substance) 
  :quantities ((heating-value 
		:documentation "the magnitude of the enthalpy of combustion of the fuel" 
		:the-*-the-object ("heading value" "of") 
		:abbreviation "HV")) 
  :documentation 
  "A type of fuel that may be used in a fuel consuming component." 
  )   

(defEntity fuel-consuming-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which require fuel input" 
  :attribute ((fuel-used :type fuel)) 
  :quantities  
  ((fuel-supply-rate :dimension mass-dimension 
		:documentation "the rate at which fuel is supplied to the fuel-consuming component" 
		:the-*-the-object ("fuel supply rate" "of") 
		:abbreviation "m'F") 
   (heat-supply-rate :dimension power-dimension 
		:documentation "the rate at which heat is supplied to the fuel-consuming component" 
		:the-*-the-object ("heat supply rate" "of") 
		:abbreviation "Qi") 
   ) 
  :consequences 
  ((= (heat-supply-rate ?self) (* (fuel-supply-rate ?self)  
				  (Heating-value fuel))) 
   ) 
  ) 

(defEntity work-consuming-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which require work input" 
  :quantities ((power-input :dimension power-dimension 
			    :documentation "the power input into the work consuming component" 
		:the-*-the-object ("power input" "into") 
		:abbreviation "W'i") 
	       ) 
  ) 

(defEntity work-producing-component 
  :subclass-of (thermal-component) 
  :documentation 
  "This is the class of components which produce work output." 
  :quantities ((power-output :dimension power-dimension 
			     :documentation "the power output of the work producing component" 
			     :the-*-the-object ("power output" "of") 
		:abbreviation "W'o") 
	       ) 
  ) 

(defEntity heating-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which supply heat" 
  :quantities  
  ((heating-rate :dimension power-dimension 
		:documentation "the rate at which the component supplies heat" 
		:the-*-the-object ("heating rate" "of") 
		:abbreviation "Q'") 
   ) 
  :consequences () 
  ) 


(defEntity cooling-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which extract heat/provide cooling." 
  :quantities  
  ((cooling-rate :dimension power-dimension 
		:documentation "the rate at which the component extracts heat" 
		:the-*-the-object ("colling rate" "of") 
		:abbreviation "Q'") 
   ) 
  :consequences () 
  ) 



(defEntity rotating-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which are based on rotational motion" 
  :quantities  
  ((rotating-speed :dimension frequency-dimension 
		:documentation "the speed at which the rotary part of the component rotates" 
		:the-*-the-object ("rotating speed" "of") 
		:abbreviation "Vr") 
   ) 
  :consequences () 
  ) 

(defEntity positive-displacement-component 
  :subclass-of (thermal-component) 
  :documentation 
  "the class of components which are positive-displacement machines" 
  :quantities  
  ((displacement :dimension volume-dimension 
		:documentation "the displacement of the positive displacement machine" 
		:the-*-the-object ("displacement" "of") 
		:abbreviation "x") 
   (speed :dimension frequency-dimension 
		:documentation "the speed of the positive displacement machine" 
		:the-*-the-object ("speed" "of") 
		:abbreviation "V") 
   (cycles-rate :dimension frequency-dimension 
		:documentation "the cycle rate of the positive displacement machine" 
		:the-*-the-object ( "cycle rate" "of") 
		:abbreviation "Vr") 
   (mean-effective-pressure :dimension pressure-dimension 
		:documentation "the theoretical constant pressure that, if it acted on the piston during the power stroke, would produce the same net work as actually developed in one cycle" 
		:the-*-the-object ("mean effective pressure" "of") 
		:abbreviation "mep") 
   (volumetric-efficiency :dimension dimensionless 
		:documentation "the volumetric efficiency of the positive displacement machine" 
		:the-*-the-object ("volumetric efficiency" "of") 
		:abbreviation "eV") 
   (clearance-volume :dimension dimensionless 
		:documentation "the minimum cylinder volume of the positive displacement machine" 
		:the-*-the-object ("clearance volume" "of") 
		:abbreviation "v-clr") 
   (compression-ratio :dimension dimensionless 
		:documentation "the compression ratio of the positive displacement machine" 
		:the-*-the-object ("compression ratio" "of") 
		:abbreviation "r") 
   ) 
  :consequences 
  ((= (compression-ratio ?self) (/ (displacement ?self)  
				   (clearance-volume ?self))) 
   ) 
  ) 


(defEntity Internal-combustion-engine 
  :subclass-of (reciprocating-component work-producing-component) 
  :documentation 
  "the class of components which includes diesel and petrol engines" 
  :quantities  
  ((air-fuel-ratio  		 
    :documentation "the ratio of the amount of air in a reaction to the amount of ruel" 
		:the-*-the-object ("air-fuel ratio" "of") 
		:abbreviation "AF" 
		:dimension dimensionless) 
	 ; some kind of mass-ratio dimension?? 
   (emissions-index  
    :documentation "the emissions index of the internal combustion engine" 
		:the-*-the-object ("emissions index" "of") 
		:abbreviation "ei") 
   ) 
  :consequences () 
  ) 

(defEntity reciprocating-component 
  :subclass-of (positive-displacement-component) 
  :documentation 
  "the class of components which are based on reciprocating motion, 
   such as reciprocating pumps, compressors, expanders, engines" 
  :quantities  
  ((stroke :dimension length-dimension 
	   :documentation "the distance the piston moves in one direction" 
		:the-*-the-object ("stroke" "of") 
		:abbreviation "l") 
   (bore-area :dimension area-dimension 
	      :documentation "the cross sectional area of the inside of the cylinder" 
		:the-*-the-object ("bore area of the cylinder" "of") 
		:abbreviation "a") 
   (bore :dimension length-dimension 
	 :documentation "the diameter of the cylinder" 
		:the-*-the-object ("bore of the cylinder" "of") 
		:abbreviation "b") 
   (strokes-per-cycle :dimension dimensionless 
		      :documentation "the number of strokes executed by the piston for every two revolutions of the crankshaft" 
		:the-*-the-object ("strokes per cycle" "of") 
		:abbreviation "strokes/cycle") 
   ) 
  :consequences () 
  ) 




(defEntity Nozzle 
  :documentation "a flow passage of varying cross-sectional area in which the velocity of a gas of liquid increases in the direction of flow " 
  :subclass-of (1-1-port-thermal-component) 
  :quantities ((outlet-velocity  
		:dimension velocity-dimension 
		:documentation 
		"velocity of the fluid at the outlet" 
		:the-*-the-object ("outlet velocity" "of") 
		:abbreviation "v_o") 
	       ) 
  ) 

(defEntity Turbine 
  :documentation "a thermal component in which work is developed as a result of a gas or liquid passing through a set of blades attached to a shaft free to rotate" 
  :subclass-of (thermal-component work-producing-component) 
  ) 

(defEntity Simple-Turbine 
  :subclass-of (Turbine 1-1-port-thermal-component) 
  :documentation "a one-input one-output turbine" 
  ) 

(defEntity Extraction-turbine 
  :subclass-of (Turbine 1-2-port-thermal-component) 
  :documentation "a one-input two-output turbine" 
  ) 

(defEntity Heat-exchanger  
  :documentation "a device that transfer energy between fluids at different temperatures" 
  :subclass-of (Thermal-component) 
  :quantities  
  ((area :dimension area-dimension 
	 :documentation "the surface area through heat is exchanged" 
	 :the-*-the-object ("heat exchange surface area" "of") 
	 :abbreviation "a") 
   (overall-heat-transfer-coefficient  
    :dimension dimensionless 
    :documentation "the overall heat transfer coefficient of the heat exchanger" 
		:the-*-the-object ("net het transfer coefficient" "of") 
		:abbreviation "h") ; some complex dimension 
   (heat-transfer-rate :dimension power-dimension 
		       :documentation "the rate at which heat is transfered inside the heat exchanger" 
		:the-*-the-object ("heat transfer rate" "of") 
		:abbreviation "Q'") 
   (max-pressure :dimension pressure-dimension 
		 :documentation "the maximum pressure inside the heat exchanger" 
		:the-*-the-object ("maximum pressure" "in") 
		:abbreviation "pmax") 
   (max-temperature :dimension temperature-dimension 
		    :documentation "the maximum temperature inside the heat exchanger" 
		:the-*-the-object ("maximum temperature" "in") 
		:abbreviation "tmax") 
   (max-heat-rate :dimension power-dimension 
		  :documentation "the maximum heat transfer rate" 
		:the-*-the-object ("maximum heat transfer rate" "of") 
		:abbreviation "Q'max") 
   (ideal-heat-rate :dimension power-dimension 
		    :documentation "the ideal heat transfer rate" 
		:the-*-the-object ("ideal heat transfer rate" "of") 
		:abbreviation "Q'ideal") 
   ) 
  ) 

(defEntity 2-port-heat-exchanger 
  :documentation "a one-input one-output heat exchanger" 
  :subclass-of (Heat-exchanger 1-1-port-thermal-component) 
  ) 

(defEntity 4-port-heat-exchanger 
  :documentation 
  "a two-input two-output heat exchanger with two separate flows" 
  :subclass-of (Heat-exchanger) 
  :attributes 
  ((hot-flow :type 2-port-heat-exchanger 
	     :abbreviation hf 
	     :The-*-the-object "hot flow" 
	     :documentation "the hot flow side of a heat exchanger with two separate flows" 
             :graphical-representation (:Display-Class ()) 
	     ) 
   (cold-flow :type 2-port-heat-exchanger 
	      :abbreviation cf 
	      :The-*-the-object "cold flow" 
	      :documentation "the cold flow side of a heat exchanger with two separate flows" 
              :graphical-representation (:Display-Class ()) 
              )) 

  :quantities 
  ((effectiveness :dimension dimensionless 
		  :documentation "the ratio of the actual enthalpy increase of the compressor side of the regenerator to the maximum theoretical enthalpy increase when the heat exchanger is playing the role of a regenerator in a regenerative gas turbine cycle" 
		:the-*-the-object ("effectiveness" "of") 
		:abbreviation "e-reg") 
   (hot-flow-temperature-in :dimension temperature-dimension 
			    :documentation 
			    "the input temperature of the hot flow" 
		:the-*-the-object ("input temperature of the hot flow" "of") 
		:abbreviation "t-hot-in") 
   (cold-flow-temperature-out :dimension temperature-dimension 
			      :documentation 
			      "the output temperature of cold flow" 
		:the-*-the-object ("output temperature of the cold flow" "of") 
		:abbreviation "t-cold-out") 
   (d-log-mean-temperature :dimension temperature-dimension 
			   :documentation 
			   "log-mean temperature difference in the heat exchanger" 
		:the-*-the-object ("log mean temperature difference" "of") 
		:abbreviation "dt-mean") 
   (d-Pressure-hot 
    :dimension pressure-dimension 
    :documentation 
    "the pressure difference between inlet and outlet of hot flow" 
    :the-*-the-object ("pressure differential on the hot flow side" "of") 
		:abbreviation "dP-hot") 
   (d-Pressure-cold 
    :dimension pressure-dimension 
    :documentation 
    "the pressure difference between inlet and outlet of cold flow" 
    :the-*-the-object ("pressure differential on the cold flow side" "of") 
    :abbreviation "dP-cold") 
   ) 
  ) 

(defEntity Compressor 
  :documentation "a thermal component in which work is done on a gas passing through them in order to raise the pressure" 
  :subclass-of (work-consuming-component 1-1-port-thermal-component) 
  :quantities 
  ((pressure-ratio :dimension dimensionless 
		   :documentation "the pressure ratio of the compressor" 
		:the-*-the-object ("pressure ratio" "of") 
		:abbreviation "r")) 
  ) 

(defEntity pump 
  :documentation "a compressor in which the work input is used to change the state of a liquid passing through" 
  :subclass-of (1-1-port-thermal-component compressor) 
  :operating-modes 
  (pump-operating-mode pump-power-input-per-mass-approximation) 

  ) 

(defEntity boiler 
  :documentation "a thermal component in which a fluid changes its phase from liquid to vapor at constant temperature as a result of heat transfer from the hot reservoir" 
  :subclass-of ( 1-1-port-thermal-component) 
  ) 

(defEntity open-feedwater-heater 
  :documentation "a heat exchanger which is a vessel in which hot and cold streams are mixed directly" 
  :subclass-of (heat-exchanger) 
  ) 

(defEntity 2-1-open-feedwater-heater 
  :documentation "a two-input one-output open feedwater heater" 
  :subclass-of (2-1-port-thermal-component open-feedwater-heater) 
  ) 

(defEntity 2-2-open-feedwater-heater 
  :documentation "a two input two-output open feedwater heater" 
  :subclass-of (2-2-port-thermal-component open-feedwater-heater) 
  ) 

(defEntity 3-1-open-feedwater-heater 
  :documentation "a three-input one-output open feedwater heater" 
  :subclass-of (3-1-port-thermal-component open-feedwater-heater) 
  ) 

(defEntity 2-2-closed-feedwater-heater 
  :documentation "a two-input two-output closed heater, which is a shell-and-tube-type recuperators in which the feedwater temperature increases as the extracted stream condenses on the outside of the tubes carrying the feedwater" 
  :subclass-of (2-2-port-thermal-component heat-exchanger) 
  ) 

(defEntity steam-generator-with-reheat 
  :documentation "a steam generator (i.e. a boiler-superheater combination) which also reheats the steam exiting the first-stage turbine" 
  :subclass-of (2-2-port-thermal-component) 
  ) 

(defEntity substance-container 
  :subclass-of (structural-element-model) 
  :documentation 
  "any component containing some substance such as water, air, etc." 
  ) 

(defRelation  substance-in (?x ?y) 
  :=> (and (substance-container ?x) (substance ?y) (connection substance-in)) 
  :documentation 
  "the substance contained in the stream or control-volume" 
  ) 

;;; Conceptual Entities 
;;;------------------- 

;;; We use stream in a way similar to the use of fluid and flow streams 
;;; in text books dicussing control volumes and flow processes. Streams 
;;; are what crosses the boundaries (control surfaces) of control volumes 
;;; in a flow process. Often we are more interested in the (assumed single) 
;;; thermodynamic state of the stream rather than the stream itself - e.g.  
;;; in a SSSF process, hence the use of the 2-D stream 

(defentity stream 
  :documentation "the boundary (control surfaces) of control volumes in a flow process" 
  :subclass-of (substance-container) 
  :quantities 
  ( 
   (stream-elevation :dimension length-dimension 
		     :documentation "the elevation of the stream" 
		:the-*-the-object ("elevation" "of") 
		:abbreviation "z") 
   (enthalpy-rate :dimension power-dimension 
		  :documentation "the enthalpy rate through the stream" 
		:the-*-the-object ("enthalpy rate" "through") 
		:abbreviation "h'") 
   (entropy-rate :dimension entropy-rate-dimension 
		  :documentation "the entropy rate through the stream" 
		:the-*-the-object ("entropy rate" "through") 
		:abbreviation "s'") 
   (ke-rate :dimension power-dimension 
		  :documentation "the kinetic energy flow rate through the stream" 
		:the-*-the-object ("kinetic energy flow rate" "through") 
		:abbreviation "ke'") 
   (mass-rate :dimension mass-rate-dimension 
		  :documentation "the mass flow rate through the stream" 
		:the-*-the-object ("mass flow rate" "through") 
		:abbreviation "m'") 
   (pe-rate :dimension power-dimension 
		  :documentation "the potential energy flow rate through the stream" 
		:the-*-the-object ("potential energy flow rate" "through") 
		:abbreviation "pe'") 
   (stream-pressure :dimension pressure-dimension 
		  :documentation "the pressure of the fluid through the stream" 
		:the-*-the-object ("fluid pressure" "at") 
		:abbreviation "p") 
   (specific-enthalpy :dimension specific-energy-dimension 
		      :documentation "the enthalpy per unit of mass" 
		:the-*-the-object ("specific enthalpy of the fluid" "at") 
		:abbreviation "h") 
   (specific-entropy :dimension specific-entropy-dimension 
		  :documentation "the entropy per unit of mass" 
		:the-*-the-object ("specific entropy of the fluid" "at") 
		:abbreviation "s") 
   (specific-internal-energy :dimension specific-energy-dimension 
		  :documentation "the internal energy of the fluid per unit of mass" 
		:the-*-the-object ("specific internal energy of the fluid" "at") 
		:abbreviation "u") 
   (stream-temperature :dimension temperature-dimension 
		  :documentation "the temperature of the fluid through the stream" 
		:the-*-the-object ("temperature of the fluid" "at") 
		:abbreviation "t") 
   (velocity :dimension velocity-dimension 
		  :documentation "the velocity of the fluid through the stream" 
		:the-*-the-object ("velocity of the fluid" "through") 
		:abbreviation "v") 
   (quality :dimension dimensionless 
		  :documentation "the ratio of the mass of vapor present to the total mass of the vapor-liquid mixture" 
		:the-*-the-object ("fluid quality" "through") 
		:abbreviation "x") 
   (specific-volume :dimension specific-volume-dimension 
		  :documentation "the volume per unit mass of the fluid" 
		:the-*-the-object ("specific volume of the fluid" "through") 
		:abbreviation "v") 
   (saturated-p  
     :range-class boolean 
    :non-numeric t 
    :documentation 
    "the attribute indicating that the fluid in the stream is saturated" 
    :Value-Names ((true "saturated") (false "non-saturated")) 
		:the-*-the-object ("predicate indicating whether the fluid is saturated" "at") 
		) 
   ) 
  )		  



(defentity 2d-stream 
  :documentation "a 2-dimensional stream" 
  :subclass-of (stream terminal) 
  :quantities 
  ((stream-area :dimension area-dimension 
		:documentation "cross sectional area of the stream" 
		:the-*-the-object ("cross sectional area" "of") 
		:abbreviation "a")) 
  :operating-modes 
  (2d-stream-operating-mode non-saturated-water-stream-enthalpy 
			  saturated-water-stream-enthalpy 
			   saturated-water-stream-entropy 
			   saturated-water-stream-specific-volume 
			   2d-stream-mass-flow-rate 
			   2d-stream-enthalpy-rate 
			   2d-stream-potential-energy 
			   2d-stream-kinetic-energy) 
  ) 

;; 
;; A 2d stream *is* the representation of 'a' thermodynamic state. 
;; The state properties are uniquely defined only for 2d streams. 
;; 
;; In some sense, they are really defined for a location, and we make 
;; the simplifying assumption that the 2d stream has homogeneous state 
;; across its area. 
;; 

(defEntity stream-junction 
  :documentation "a junction between streams" 
  :subclass-of (junction) 
  :consequences  
  ( 
   (All= (setof terminal (connected-terminals ?self)  
		(mass-rate terminal))) 
   (All= (setof terminal (connected-terminals ?self)  
		(stream-pressure terminal))) 

   (All= (setof terminal (connected-terminals ?self)  
		(specific-enthalpy terminal))) 
    
   (All= (setof terminal (connected-terminals ?self)  
		(specific-entropy terminal))) 

   (All= (setof terminal (connected-terminals ?self)  
		(specific-internal-energy terminal))) 

   (All= (setof terminal (connected-terminals ?self)  
		(stream-temperature terminal))) 

   (All= (setof terminal (connected-terminals ?self)  
		(quality terminal))) 

   (All= (setof terminal (connected-terminals ?self)  
		(specific-volume terminal))) 
   ) 
  ) 

(defEntity Control-volume 
  :documentation "a region of space through which mass may flow" 
  :subclass-of (substance-container)   
  :quantities 
  ( 
   (enthalpy-rate-in 
    :dimension power-dimension 
    :documentation "the enthalpy flow rate into the control volume" 
    :the-*-the-object ("enthalpy flow rate" "into") 
    :abbreviation "H'in") 
   (enthalpy-rate-out 
    :dimension power-dimension 
    :documentation "the enthalpy flow rate out of the control volume" 
    :the-*-the-object ("enthalpy flow rate" "out of") 
    :abbreviation "H'out") 
   (entropy-rate-in 
    :dimension entropy-rate-dimension 
    :documentation "the entropy flow rate into the control volume" 
    :the-*-the-object ("entropy flow rate" "into") 
    :abbreviation "S'in") 
   (entropy-rate-out 
    :dimension entropy-rate-dimension 
    :documentation "the entropy flow rate out of the control volume" 
    :the-*-the-object ("entropy flow rate" "out of") 
    :abbreviation "S'out") 
   (d-entropy-rate 
    :dimension entropy-rate-dimension 
    :documentation "entropy differential across the control volume" 
    :the-*-the-object ("entropy flow rate differential" "across") 
    :abbreviation "d-S") 
   (ke-rate-in 
    :dimension power-dimension 
    :documentation "the kinetic energy flow rate into the control volume" 
    :the-*-the-object ("kinetic energy flow rate" "into") 
    :abbreviation "ke'-in") 
   (ke-rate-out 
    :dimension power-dimension 
    :documentation "the kinetic energy flow rate out of the control volume" 
    :the-*-the-object ("kinetic energy flow rate" "out of") 
    :abbreviation "ke'-out") 
   (mass-rate-in 
    :dimension mass-rate-dimension 
    :documentation "the mass flow rate into the control volume" 
    :the-*-the-object ("mass flow rate" "into") 
    :abbreviation "m'-in") 
   (mass-rate-out 
    :dimension mass-rate-dimension 
    :documentation "the mass flow rate out of the control volume" 
    :the-*-the-object ("mass flow rate" "out of") 
    :abbreviation "m'-out") 
   (pe-rate-in 
    :dimension power-dimension 
    :documentation "the potential energy flow rate into the control volume" 
    :the-*-the-object ("potential energy flow rate" "into") 
    :abbreviation "pe'-in") 
   (pe-rate-out 
    :dimension power-dimension 
    :documentation "the potential energy flow rate out of the control volume" 
    :the-*-the-object ("potential energy flow rate" "out of") 
    :abbreviation "pe'-out") 
   (cv-elevation 
    :dimension length-dimension 
    :documentation "the elevation of the control volume with respect to some reference position" 
    :the-*-the-object ("elevation" "of") 
    :abbreviation "z") 
   (cv-pe 
    :dimension energy-dimension 
    :documentation "the potential energy of the fluid in the control volume" 
    :the-*-the-object ("potential energy of the fluid" "in") 
    :abbreviation "pe") 
   (cv-ke 
    :dimension energy-dimension 
    :documentation "the kinetic energy of the fluid in the control volume" 
    :the-*-the-object ("kinetic energy of the fluid" "in") 
    :abbreviation "ke") 
   (cv-enthalpy 
    :dimension energy-dimension 
    :documentation "the enthalpy of the fluid in the control volume" 
    :the-*-the-object ("enthalpy of the fluid" "in") 
    :abbreviation "H") 
   (cv-entropy 
    :dimension entropy-dimension 
    :documentation "the entropy of the fluid in the control volume" 
    :the-*-the-object ("entropy of the fluid" "in") 
    :abbreviation "S") 
   (cv-internal-energy 
    :dimension energy-dimension 
    :documentation "the internal energy of the fluid in the control volume" 
    :the-*-the-object ("iternal energy of the fluid" "in") 
    :abbreviation "U") 
   (cv-energy 
    :dimension energy-dimension 
    :documentation "the total energy of the fluid in the control volume" 
    :the-*-the-object ("total energy of the fluid" "in") 
    :abbreviation "E") 
   (energy-rate 
    :dimension energy-rate-dimension	;***new 
    :documentation "the rate of change of the total energy of the fluid in the control volume" 
    :the-*-the-object ("rate of change of the total energy of the fluid" "in") 
    :abbreviation "E'") 
   (internal-energy-rate 
    :dimension energy-rate-dimension	;***new 
    :documentation "the rate of change in the internal energy o fthe fluid in the control volume" 
    :the-*-the-object ("rate of change in the internal energy of the fluid" "in") 
    :abbreviation "U'") 
   (cv-mass 
    :dimension mass-dimension 
    :documentation "the mass of the fluid in the control volume" 
    :the-*-the-object ("mass of the fluid" "in") 
    :abbreviation "M") 
   (cv-volume 
    :dimension volume-dimension 
    :documentation "the volume of the fluid in the control volume" 
    :the-*-the-object ("fluid volume" "in") 
    :abbreviation "V") 
   (d-pe-rate 
    :dimension power-dimension 
    :documentation "the potential energy differential of the fluid across the control volume" 
    :the-*-the-object ("change in the potential energy of the fluid" "across") 
    :abbreviation "d-pe") 
   (d-ke-rate 
    :dimension power-dimension 
    :documentation "the kinetic energy differential of the fluid across the control volume" 
    :the-*-the-object ("change in the kinetic energy of the fluid" "across") 
    :abbreviation "d-ke") 

   (even-pe 
    :non-numeric t 
    :range-class boolean 
    :documentation 
    "the predicate indicating that the change in pe-rate is negligible" 
    :Value-Names 
    ((true "negligible pe change") (false "significant pe change")) 
    ) 
   (even-ke 
    :non-numeric t 
    :range-class boolean 
    :documentation 
    "the predicate indicating that the change in ke-rate is negligible" 
    :Value-Names 
    ((true "negligible ke change") (false "significant ke change")) 
    ) 
   ) 

  :consequences 
  ( 
   (foreach ?x (inlets ?self) 
	    (C+ (pe-rate ?x)   (pe-rate-in ?self))  
	    (C+ (ke-rate ?x)   (ke-rate-in ?self)) ; 
	    (C+ (enthalpy-rate ?x)  (enthalpy-rate-in ?self)) 
	    (C+ (mass-rate ?x) (mass-rate-in ?self)) 
	    (C+ (entropy-rate ?x)  (entropy-rate-in ?self))) 

   (foreach ?x (outlets ?self) 
	    (C+ (pe-rate ?x)  (pe-rate-out ?self)) 
	    (C+ (ke-rate ?x)  (ke-rate-out ?self)) 
	    (C+ (enthalpy-rate ?x)  (enthalpy-rate-out ?self)) 
	    (C+ (mass-rate ?x)  (mass-rate-out ?self)) 
	    (C+ (entropy-rate ?x)  (entropy-rate-out ?self))) 
   (= d-entropy-rate (- entropy-rate-in entropy-rate-out)) 
   (= d-pe-rate (- pe-rate-out  pe-rate-in)) 
   (= d-ke-rate (- ke-rate-out  ke-rate-in )) 
   ) 
  ) 

(defRelation  inlets (?x ?y) 
  :=> (and (control-volume ?x) (2d-stream ?y)) 
  :documentation "the set of inlet streams of the control-volume" 
  ) 
(defRelation outlets  (?x ?y) 
  :=> (and (control-volume ?x) (2d-stream ?y)) 
  :documentation "the set of outlet streams of the control-volume") 
    
(defRelation undergoing (?x ?y) 
  :=> (and (control-volume ?x) (steady-state-steady-flow-process ?y)) 
  :documentation "the process the control-volume is undergoing") 

(defRelation cv-component  (?x ?y) 
  :=> (and (control-volume ?x) (thermal-component ?y) (connection cv-component)) 
  :documentation "the component associated with the control volume") 

(defModelFragment 1-1-control-volume-op-mode 
  :documentation "the class of model fragments about a 1-1-contol-volume" 
  :participants 
  ((1-1-cv-involved :type 1-1-control-volume 
		    :documentation "the control volume")) 
  ) 


(defModelFragment  internally-reversible-adiabatic-process 
  :subclass-of (1-1-control-volume-op-mode) 
  :documentation  
  "description of an internally reversible-process" 
  :participants 
  ((adiabatic-pr-involved 
    :type  steady-flow-adiabatic-process 
    :documentation "the internally reversible adiabatic process" 
		)) 
  :conditions 
  ((process-cv adiabatic-pr-involved 1-1-cv-involved ) 
   (internally-reversible-p adiabatic-pr-involved true)) 
  :consequences 
  ( 
   (= (specific-entropy 
       (outlet-stream (1-1-cv-involved ?self))) 
      (specific-entropy 
       (inlet-stream (1-1-cv-involved ?self)))) 
   ) 
  ) 

(defModelFragment CONTROL-VOLUME-op-mode 
  :documentation "the class of model fragments about a contol-volume" 
  :participants 
  ((cv-involved :type control-volume 
		:documentation "the control volume")) 
  ) 

(defModelFragment  control-volume-inlet-stream-ideal-gas-law 
  :documentation "the operating mode model of a control volume to describe the fluid in its inlet stream as ideal gas" 
  :subclass-of ( control-volume-op-mode) 
  :conditions 
  ((ideal-gas-p (substance-in cv-involved) true)) 
  :consequences 
  ((foreach ?x (inlets (cv-involved ?self)) 
	    (= (* (stream-pressure ?x) (specific-volume ?x)) 
	       (* (ideal-gas-constant (substance-in (cv-involved ?self))) 
		  (stream-temperature ?x)))) 
   ) 
  ) 

(defModelFragment   control-volume-outlet-stream-ideal-gas-law 
  :documentation "the operating mode model of a control volume to describe the fluid in its outlet stream as ideal gas" 
  :subclass-of ( control-volume-op-mode) 
  :conditions 
  ((ideal-gas-p (substance-in cv-involved ) true)) 
  :consequences 
  ((foreach ?x (outlets (cv-involved ?self)) 
	    (= (* (stream-pressure ?x) (specific-volume ?x)) 
	       (* (ideal-gas-constant (substance-in (cv-involved ?self))) 
		  (stream-temperature ?x)))) 
   ) 
  ) 

(defModelFragment   air-operating-mode 
  :documentation "the class of operating mode models of air" 
  :subclass-of (dme-user::operating-mode-model) 
  :participants  
  ((air-involved :type air 
		 :documentation "the air involved" 
		 ) 
   ) 
  ) 

(defModelFragment    water-operating-mode 
  :documentation "the class of operating mode models of water" 
  :subclass-of (dme-user::operating-mode-model) 
  :participants  
  ((water-involved :type water 
		   :documentation "the water involved" 
		   ) 
   ) 
  ) 

(defModelFragment  control-volume-inlet-stream-thermodynamic-state 
  :documentation "the operating mode model of a control volume containing air to compute the thermodynamic state of its inlet stream" 
  :subclass-of (air-operating-mode control-volume-op-mode ) 
  :conditions  
  ((substance-in (cv-involved ?self) (air-involved ?self))) 
  :consequences 
  ( 
   (foreach ?x (inlets (cv-involved ?self)) 
	    (= (specific-enthalpy ?x) 
	       (compute-air-thermodynamic-state (stream-temperature ?x)))) 
   ) 
  ) 

(defModelFragment control-volume-outlet-stream-thermodynamic-state 
  :documentation "the operating mode model of a control volume containing air to compute the thermodynamic state of its oiutlet stream" 
  :subclass-of   (air-operating-mode control-volume-op-mode ) 
  :conditions 
  ((substance-in (cv-involved ?self) (air-involved ?self))) 
  :consequences 
  ( 
   (foreach ?x (outlets (cv-involved ?self)) 
	    (= (specific-enthalpy ?x) 
	       (compute-air-thermodynamic-state (stream-temperature ?x)))) 
   ) 
  ) 


(defModelFragment  2d-stream-operating-mode 
  :documentation "the class of operating mode models of 2d streams" 
  :subclass-of (dme-user::operating-mode-model) 
  :participants  
  ((2d-stream-involved :type 2d-stream 
	      :documentation "the 2d stream involved" 
	      )) 
  ) 


;; The following model comes from the example 8.1. 
;; Computes the quality of a non-saturated vapor stream. 
;; h_fg is (- h_g h_f). 

(defModelFragment non-saturated-water-stream-enthalpy 
  :documentation "the operating mode model of a 2d stream containing non-saturated water to compute its enthalpy" 
  :subclass-of (water-operating-mode 2d-stream-operating-mode ) 
  :conditions 
  ((substance-in 2d-stream-involved water-involved) 
   (saturated-p 2d-stream-involved false)) 
  :consequences 
  ( 
   (= (specific-enthalpy (2d-stream-involved ?self)) 
      (+  
       (compute-saturated-vapor-enthalpy 
	(stream-pressure (2d-stream-involved ?self)) 
	0) 
       (*  
	(quality (2d-stream-involved ?self)) 
	(- (compute-saturated-vapor-enthalpy 
	    (stream-pressure (2d-stream-involved ?self)) 
	    1) 
	   (compute-saturated-vapor-enthalpy 
	    (stream-pressure (2d-stream-involved ?self)) 
	    0))))) 
   ) 
  ) 


(defModelFragment saturated-water-stream-enthalpy 
  :documentation "the operating mode model of a 2d stream containing saturated water to compute its enthalpy" 
  :subclass-of (2d-stream-operating-mode water-operating-mode) 
  :conditions 
  ((substance-in 2d-stream-involved water-involved) 
   (saturated-p 2d-stream-involved true)) 
  :consequences 
  ( 
   (= (specific-enthalpy (2d-stream-involved ?self)) 
      (compute-saturated-vapor-enthalpy 
       (stream-pressure (2d-stream-involved ?self)) 
       (quality (2d-stream-involved ?self)))))  
    
  ) 
   

(defModelFragment  saturated-water-stream-entropy 
  :documentation "the operating mode model of a 2d stream containing saturated water to compute its entropy" 
  :subclass-of (2d-stream-operating-mode water-operating-mode) 
  :conditions 
  ((substance-in 2d-stream-involved water-involved) 
   (saturated-p 2d-stream-involved true)) 
  :consequences 
  ( 
   (= (specific-entropy (2d-stream-involved ?self)) 
      (compute-saturated-vapor-entropy 
       (stream-pressure (2d-stream-involved ?self)) 
       (quality (2d-stream-involved ?self)))))  
    
  ) 

(defModelFragment  saturated-water-stream-specific-volume 
  :documentation "the operating mode model of a 2d stream containing saturated water to compute its specific volume" 
  :subclass-of (2d-stream-operating-mode water-operating-mode) 
  :conditions 
  ((substance-in 2d-stream-involved water-involved) 
   (saturated-p 2d-stream-involved true)) 
  :consequences 
  ( 
   (= (specific-volume (2d-stream-involved ?self)) 
      (compute-saturated-vapor-specific-volume 
       (stream-pressure (2d-stream-involved ?self)) 
       (quality (2d-stream-involved ?self)))))  
  ) 

(defModelFragment  control-volume-negligible-pe-change	 
  :subclass-of ( control-volume-op-mode) 
  :documentation 
  "operating mode of a control-volume that says that the change in pe 
rate is negligible" 
  :conditions 
  ((even-pe cv-involved true)) 
  :consequences 
  ( 
   (= (d-pe-rate (cv-involved ?self)) 
      0) 
   ) 
  ) 

(defModelFragment  control-volume-negligible-ke-change 
  :subclass-of ( control-volume-op-mode) 
  :documentation 
  "operating mode of a control-volume that says that the change in ke 
rate is negligible" 
  :conditions 
  ((even-ke cv-involved true)) 
  :consequences 
  ( 
   (= (d-ke-rate (cv-involved ?self)) 
      0) 
   ) 
  ) 

(defEntity 1-input-control-volume 
  :documentation "the control volume with one input stream" 
  :subclass-of (control-volume) 
  :attributes 
  ((inlet-stream :type 2d-stream  
		 :abbreviation in 
		 :the-*-the-object "inlet stream" 
		 :documentation "the inlet stream") 
   ) 
  :other-axioms 
  ((ek:<==  (inlets $m $stream) 
	    (ek:= (inlet-stream $m) $stream)) 

   ) 
  ) 
   
(defEntity  1-output-control-volume 
  :documentation "the control volume with one output stream" 
  :subclass-of (control-volume) 
  :attributes 
  ( 
   (outlet-stream :type 2d-stream 
		  :abbreviation out 
		  :the-*-the-object "outlet stream" 
		  :documentation "the outlet stream") 
   ) 
  :other-axioms 
  ( 
   (ek:<==  (outlets $m $stream) 
	    (ek:= (outlet-stream $m) $stream)) 
   ) 
  ) 

(defEntity 2-input-control-volume  
  :documentation "the control volume with two input streams" 
  :subclass-of (control-volume) 
  :attributes 
  ((inlet-stream1 :type 2d-stream  
		  :abbreviation in1 
		  :the-*-the-object "first inlet stream" 
		  :documentation "the first inlet stream") 
   (inlet-stream2 :type 2d-stream 
		  :abbrevation in2 
		  :the-*-the-object "second inlet stream" 
		  :documentation "the second inlet stream") 
   ) 
  :other-axioms 
  ((ek:<==  (inlets $m $stream) 
	    (ek:= (inlet-stream1 $m) $stream)) 
   (ek:<==  (inlets $m $stream) 
	    (ek:= (inlet-stream2 $m) $stream)) 
   ) 
  ) 

(defEntity 3-input-control-volume  
  :documentation "the control volume with three input streams" 
  :subclass-of (2-input-control-volume) 
  :attributes 
  ((inlet-stream3 :type 2d-stream  
		  :abbreviation in3 
		  :the-*-the-object "third inlet stream" 
		  :documentation "the first inlet stream") 
    
   ) 
   
  :other-axioms 
  ((ek:<==  (inlets $m $stream) 
	    (ek:= (inlet-stream3 $m) $stream)) 
    
   ) 
  ) 

(defEntity  2-output-control-volume  
  :documentation "the control volume with two output streams" 
  :subclass-of (control-volume) 
  :attributes 
  ((outlet-stream1 :type 2d-stream  
		   :abbreviation out1 
		   :the-*-the-object "first outlet stream" 
		   :documentation "the first outlet stream") 
   (outlet-stream2 :type 2d-stream 
		   :abbrevation out2 
		   :the-*-the-object "second outlet stream" 
		   :documentation "the second outlet stream") 
   ) 
  :other-axioms 
  ((ek:<==  (outlets $m $stream) 
	    (ek:= (outlet-stream1 $m) $stream)) 
   (ek:<==  (outlets $m $stream) 
	    (ek:= (outlet-stream2 $m) $stream)) 
   ) 
  ) 

(defEntity 1-1-control-volume  
  :documentation "the one-input, one-output control volume" 
  :subclass-of (1-input-control-volume 1-output-control-volume) 
  ) 


(defEntity 1-2-control-volume  
  :documentation "the one-input, two-output control volume" 
  :subclass-of (1-input-control-volume 2-output-control-volume) 
  ) 

(defEntity 2-1-control-volume  
  :documentation "the two-input, one-output control volume" 
  :subclass-of (2-input-control-volume 1-output-control-volume) 
  ) 

(defEntity 2-2-control-volume  
  :documentation "the two-input, two-output control volume" 
  :subclass-of (2-input-control-volume 2-output-control-volume) 
  ) 

(defEntity 3-1-control-volume 
  :documentation "the three-input, one-output control volume" 
  :subclass-of (3-input-control-volume 1-output-control-volume) 
  ) 


;;;---------------------------------------------------------------------- 
;;; Substance 
;;;---------------------------------------------------------------------- 

(defEntity substance 
  :documentation "the class of all types of matter" 
  :subclass-of (structural-element-model) 
  :quantities 
  ( 
   (saturation-pressure :dimension pressure-dimension 
			:documentation "the pressure at which a phase change takes place at a given temperature" 
		:the-*-the-object ("saturation pressure" "of") 
		:abbreviation "pc") 
   (saturation-temperature :dimension temperature-dimension 
	      :documentation "the temperature at which a phase change takes place at a given pressure" 
		:the-*-the-object ("saturation temperature" "of") 
		:abbreviation "Tc") 
   (ideal-specific-heat :dimension specific-energy-dimension 
	      :documentation "the specific heat of the substance when it is modeled as ideal gas" 
		:the-*-the-object ("ideal specific heat" "of") 
		:abbreviation "cp-ideal") 
   (molecular-weight :dimension amount-dimension 
	      :documentation "the molecular weight of the substance" 
		:the-*-the-object ("molecular weight" "of") 
		:abbreviation "M") 
   (critical-temperature :dimension temperature-dimension 
	      :documentation "the maximum temperature at which liquid and vapor phases can coexist in equilibrium" 
		:the-*-the-object ("critical temperature" "of") 
		:abbreviation "Tc") 
   (critical-pressure :dimension pressure-dimension 
	      :documentation "the pressure at the critical point of the substance" 
		:the-*-the-object ("critical pressure" "of") 
		:abbreviation "pc") 
   (critical-density :dimension density-dimension 
	      :documentation "the density of the substance at its critical point" 
		:the-*-the-object ("critical density" "of") 
		:abbreviation "dc") 
   (reference-temperature :dimension temperature-dimension 
	      :documentation "the temperature of the reference state, which is the thermodynamic state with respect to which the values of the state variables, internal energy, specific enthalpy, and specific entropy  in all other states are computed"  
		:the-*-the-object ("reference temperature" "of") 
		:abbreviation "Tref") 
   (ideal-gas-constant 
	      :documentation "the gas constant (universal gas constant / molecular weight) of the substance when it is modeled as ideal gas" 
		:the-*-the-object ("ideal gas constant" "of") 
		:abbreviation "R") 
   (ideal-gas-p 
     :range-class boolean 
    :non-numeric t 
    :documentation 
    "the attribute indicating that the particular instance of the 
substance can be regarded as ideal gas" 
    :value-names ((true "ideal gas") (false "not ideal gas")) 
    ) 
   ) 
  ) 

(defRelation contained-in (?x ?y) 
  :=> (and (substance ?x) (substance-container ?y)) 
  :documentation 
  "the thing that can contain a substance such as stream and control volume") 

(defEntity water 
  :documentation "the substance water" 
  :subclass-of (substance) 
  :consequences 
  ((= (molecular-weight water) 18.016 ) 
   (= (critical-temperature water) 647.286) 
   (= (critical-pressure water)  22.089) 
   (= (critical-density water) 317.0) 
   (= (reference-temperature water) 273.16) 
   (= (ideal-gas-constant water) 461.51) 
   ) 
  :operating-modes 
  (water-operating-mode non-saturated-water-stream-enthalpy 
		      saturated-water-stream-enthalpy 
		      saturated-water-stream-entropy 
		      saturated-water-stream-specific-volume) 
  ) 

;; cv = specific heat capacity at constant volume in joules/kg*K 

(defEntity air 
:documentation "the substance air" 
  :subclass-of (substance) 
  :consequences 
  ( 
   (= (molecular-weight ?self) 28.97) 

   (= (critical-temperature ?self)  133 ) 
   (= (critical-pressure ?self) 37.7 ) 
   (= (ideal-gas-constant ?self) 
      286.99)) 
  :operating-modes 
  (air-operating-mode control-volume-inlet-stream-thermodynamic-state) 
  ) 

 

;;;---------------------------------------------------------------------- 
;;; Definitional equations 
;;;---------------------------------------------------------------------- 
;;; 

(defModelFragment 2d-stream-mass-flow-rate 
  :documentation "the operating mode model of the 2d stream to express the relation between mass rate, specific volume, area, and velocity" 
  :subclass-of (2d-stream-operating-mode) 
  :consequences 
  ( 
   (= (* (mass-rate (2d-stream-involved ?self) ) 
	 (specific-volume (2d-stream-involved ?self))) 
      (* (stream-area (2d-stream-involved ?self)) 
	 (velocity (2d-stream-involved ?self))))) 
  ) 


(defModelFragment 2d-stream-enthalpy-rate 
:documentation "the operating mode model of the 2d stream to express the relation between enthalpy rate, mass rate and specific enthalpy" 
  :subclass-of (2d-stream-operating-mode) 
  :consequences 
  ( 
   (= (enthalpy-rate (2d-stream-involved ?self) ) 
      (* (mass-rate (2d-stream-involved ?self)) 
	 (specific-enthalpy (2d-stream-involved ?self))))) 
  ) 

(defModelFragment earth-bound-model 
  :documentation "an abstract class of model fragments whose sole purpose is to have the gravitational acceleration due to earth." 
  :quantities 
  ((acceleration-due-to-gravity 
    :dimension acceleration-dimension 
    :documentation "the gravitational acceleration on earth" 
    :the-*-the-object ("gravitational acceleration") 
    :abbreviation "g") 
   ) 
  :consequences 
  ( 
   (= acceleration-due-to-gravity 9.81)) 
  ) 

(defModelFragment 2d-stream-potential-energy 
:documentation "the operating mode model of the 2d stream to express the relation between the mass rate,  elevation and gravitational acceleration" 
  :subclass-of  (2d-stream-operating-mode earth-bound-model) 
  :consequences 
  ( 
   (= (pe-rate (2d-stream-involved ?self)) 
      (* (mass-rate (2d-stream-involved ?self)) 
	 (stream-elevation (2d-stream-involved ?self)) 
	 (acceleration-due-to-gravity ?self)))) 
  ) 

(defModelFragment 2d-stream-kinetic-energy 
:documentation " the operating mode model of the 2d stream to express the relation between kinetic energy rate, mass rate and velocity" 
  :subclass-of ( 2d-stream-operating-mode) 
  :consequences 
  ( 
   (= (ke-rate (2d-stream-involved ?self)) 
      (* 0.5 
	 (mass-rate (2d-stream-involved ?self)) 
	 (expt (velocity (2d-stream-involved ?self)) 2)))) 
  ) 

;;;---------------------------------------------------------------------- 
;;; Model Fragment Definitions 
;;;---------------------------------------------------------------------- 

;;; Steady state steady flow processes 

;;; We have put more of the "action" in processes rather than in CVs 
;;; on the basis that ultimately, processes rather than CV's determine 
;;; energy transfers, and also we use processes as the basis for 
;;; design and improvement of thermal systems rather than CVs, which 
;;; facilitate analysis of processes and cycles 

(defModelFragment thermal-process 
  :documentation 
  "the class of all thermal processes" 
  :quantities 
  ((work-rate :dimension power-dimension 
	      :documentation "the rate at which  energy is trasferred out across the system boundary by work" 
		:the-*-the-object ("work rate" "of") 
		:abbreviation "W'") 
   (heat-rate :dimension power-dimension 
	      :documentation "the rate at which energy is transferred in across the system boundary by heat transfer" 
		:the-*-the-object ("heat rate" "of") 
		:abbreviation "Q'") 
   (heat-transfer-temperature :dimension temperature-dimension 
	      :documentation "the temperatue at which energy is transferred in across the system boundary by heat transfer" 
		:the-*-the-object ("heat transfer temperature" "of") 
		:abbreviation "Ttr") 
   (entropy-generation-rate :dimension entropy-rate-dimension 
	      :documentation "the rate at which entropy is generated by the process" 
		:the-*-the-object ("entropy generation rate" "of") 
		:abbreviation "S'") 
   (irreversibility-rate :dimension power-dimension 
	      :documentation "the rate of the destruction of availability due to ierreversibilities within the process" 
		:the-*-the-object ("irreversibility rate" "of") 
		:abbreviation "I'") 
   (internally-reversible-p 
    :non-numeric t 
     :range-class boolean 
    :documentation 
    "the attribute indicating that the process is internally reversible" 
    :value-names 
    ((true "internally reversible") (false "internally irreversible")) 
    ) 
   ) 
  :operating-modes 
  (thermal-process-op-mode cycle-work-output pump-power-input-per-mass-approximation) 
  ) 

(defRelation process-cv (?x ?y) 
  :=> (and (thermal-process ?x) (control-volume ?y) 
	   (connection process-cv) 
	   ) 
  :abbreviation "cv" 
  ) 

(defModelFragment steady-state-steady-flow-process 
  :subclass-of (thermal-process) 
  :documentation 
  "the model of a steady flow in steady state employing the first law of 
thermodynamics (Energy conservation) and mass conservation" 
  :quantities 
  ( 
   (power-input-per-mass 
    :documentation 
    "the rate of power input per unit of mass passing through the cv 
associated with the process" 
		:the-*-the-object ("power input per unit mass" "of") 
		:abbreviation "w'in") 
   ) 
  :consequences 
  ( 
   (foreach ?cv (process-cv ?self) 
	    (= (- (heat-rate ?self) (work-rate ?self)) 
	       (+ (- (enthalpy-rate-out ?cv) 
		     (enthalpy-rate-in ?cv)) 
		  (d-pe-rate ?cv) 
		  (d-ke-rate ?cv)))) 

   (foreach ?cv  (process-cv ?self) 
	    (= (Entropy-generation-rate ?self) 
	       (+ (- (entropy-rate-out ?cv) (entropy-rate-in ?cv)) 
		  (- (/ (heat-rate ?self) (heat-transfer-temperature ?self)))) 
	       )) 

   (foreach ?cv (process-cv ?self) 
	    (= (mass-rate-in ?cv) (mass-rate-out ?cv))) 
   ) 
  ) 



(defModelFragment steady-flow-adiabatic-process 
  :documentation 
  "An adiabatic process is one for which there is no heat transfer with 
   the surroundings" 
  :subclass-of (steady-state-steady-flow-process) 
  :consequences ((= (heat-rate ?self) 0)) 
  ) 

(defModelFragment steady-flow-isentropic-process 
  :subclass-of (steady-flow-adiabatic-process) 
  :documentation 
  "An isentropic process is one for which there is no heat transfer with 
    the surroundings, and no change in entropy" 
   ;; actually second law can tell us the former based on the latter 
  :consequences 
  ( 
   (foreach ?cv (process-cv ?self) 
	    (= (d-entropy-rate ?cv) 0))) 
  ) 

(defModelFragment steady-flow-adiabatic-heat-exchange 
  :subclass-of (steady-flow-adiabatic-process) 
  :documentation 
  "This process model describes the process in a CV encompassing an 
   entire closed heat exchanger, from which there is no heat transfer with the 
   surroundings." 
  :subclass-of (steady-flow-adiabatic-process) 

  :consequences 
  ((= (work-rate ?self) 0) 
    
   (foreach ?cv (process-cv ?self) 
	    (= (d-ke-rate ?cv) 0 )) 
   (foreach ?cv (process-cv ?self) 
	    (= (d-pe-rate ?cv) 0)) 
   ) 
  ) 


(defModelFragment  steady-flow-isobaric-process 
  :documentation 
  "An isobaric process is a constant pressure process" 
  :subclass-of (steady-state-steady-flow-process) 
  :consequences 
  ((foreach ?cv (process-cv ?self) 
	    (= (stream-pressure (inlet-stream ?cv)) 
	       (stream-pressure (outlet-stream ?cv))))) 
  ) 

(defModelFragment  steady-flow-isothermal-process 
  :documentation 
  "An isothermal process is a constant temperature process" 
  :subclass-of (steady-state-steady-flow-process) 
  :consequences 
  ((foreach ?cv (process-cv ?self) 
	    (= (stream-temperature (inlet-stream ?cv)) 
	       (stream-temperature (outlet-stream ?cv))))) 
  ) 

(defModelFragment steady-flow-heat-transfer 
  :documentation 
  "Generic heat transfer process" 
  :subclass-of (steady-state-steady-flow-process) 
  :consequences 
  ( 
   (= (work-rate ?self) 0) 
   (foreach ?cv (process-cv ?self) 
	    (= (d-ke-rate ?cv) 0)) 
   (foreach ?cv (process-cv ?self) 
	    (= (d-pe-rate ?cv) 0)) 
    
   ) 
  ) 

(defModelFragment steady-flow-isobaric-heat-transfer 
  :documentation 
  " the isobaric process a single fluid stream undergoes within a heat exchanger" 
  :subclass-of (steady-flow-heat-transfer steady-flow-isobaric-process) 
  ) 

(defModelFragment steady-flow-expansion-or-compression 
    :subclass-of (steady-state-steady-flow-process) 
    :documentation  
    "the class of steady flow processes including expansion and compression" 
    :quantities 
    ((isentropic-efficiency :dimension dimensionless 
	      :documentation "the measure of comparison between the actual performance of a device and the performance that would be achieved under idealized circumstances for the same inlet state and the same exit pressure" 
		:the-*-the-object ("isentropic efficiency" "of") 
		:abbreviation "e") 
     (ideal-isentropic-enthalpy 
      :dimension energy-dimension 
      :documentation "the enthalpy of the ideal gas undergoing the process if the process is an isentropic process" 
      :the-*-the-object ("ideal isentropic enthalpy" "of") 
      :abbreviation "Hideal-is" 
    ))) 

(defModelFragment steady-flow-expansion 
  :documentation 
  "An expansion process involves decrease of pressure from inlet to outlet" 
  :subclass-of ( steady-flow-expansion-or-compression) 
  ) 

(defModelFragment steady-flow-adiabatic-expansion 
  :documentation "the class of steady flow expansion processes taking place without interacting thermally with the external world " 
  :subclass-of (steady-flow-expansion steady-flow-adiabatic-process) 
  :quantities 
  ((expansion-isentropic-efficiency :dimension dimensionless 
	      :documentation "the isentropic efficiency of the expansion process" 
		:the-*-the-object ("expansion isentropic efficiency" "of") 
		:abbreviation "e")) 
  :consequences 
  ( 
   (foreach ?cv (process-cv ?self) 
	    (= (quality (outlet-stream ?cv)) 
	       (/ (- (specific-entropy (outlet-stream ?cv)) 
		     (compute-saturated-vapor-entropy 
		       (stream-pressure (outlet-stream ?cv)) 0)) 
		  (- (compute-saturated-vapor-entropy 
		       (stream-pressure (outlet-stream ?cv)) 1) 
		     (compute-saturated-vapor-entropy 
		       (stream-pressure (outlet-stream ?cv)) 0)) 
		  ))) 
    
   (foreach ?cv (process-cv ?self) 
	    (= (isentropic-efficiency ?self) 
	       (/ (- (specific-enthalpy (inlet-stream ?cv)) 
		     (specific-enthalpy (outlet-stream ?cv))) 
		  (- (specific-enthalpy (inlet-stream ?cv)) 
		     (ideal-isentropic-enthalpy ?self))))) 
   (foreach ?cv (process-cv ?self) 
	    (= (expansion-isentropic-efficiency  ?self) 
	       (/ (- (specific-enthalpy (inlet-stream ?cv)) 
		     (specific-enthalpy (outlet-stream ?cv))) 
		  (- (specific-enthalpy (inlet-stream ?cv)) 
		     (ideal-isentropic-enthalpy ?self))))) 
   ) 
  ) 

(defModelFragment steady-flow-compression 
  :subclass-of ( steady-state-steady-flow-process) 
  :documentation 
  "A compression process involves increase of pressure from inlet to outlet" 
  ) 

(defModelFragment steady-flow-adiabatic-compression 
  :documentation "the class of steady flow compression processes taking place without interacting thermally with the external world" 
  :subclass-of (steady-flow-compression steady-flow-adiabatic-process) 
  :quantities 
  ((compression-isentropic-efficiency :dimension dimensionless 
	      :documentation "the isentropic efficiency of the compression process" 
	      :the-*-the-object ("compression isentropic efficiency" "of") 
		:abbreviation "e")) 
  :consequences 
  ( 
   (foreach ?cv (process-cv ?self) 
	    (= (compression-isentropic-efficiency  ?self);; Ho - corrected 
	       (/ (- (ideal-isentropic-enthalpy ?self) 
		     (specific-enthalpy (inlet-stream ?cv))) 
		  (- (specific-enthalpy (outlet-stream ?cv)) 
		     (specific-enthalpy (inlet-stream ?cv)))))) 
   (foreach ?cv (process-cv ?self) 
	    (= (isentropic-efficiency ?self) 
	       (/ (- (specific-enthalpy (outlet-stream ?cv)) 
		     (specific-enthalpy (inlet-stream ?cv))) 
		  (- (ideal-isentropic-enthalpy ?self) 
		     (specific-enthalpy (inlet-stream ?cv)))))) 
    ;; The following equation comes from the equation 8.3 on page 310. 
   (foreach ?cv (process-cv ?self) 
	    (= (power-input-per-mass ?self) 
	       (- (specific-enthalpy (outlet-stream ?cv)) 
		  (specific-enthalpy (inlet-stream ?cv))) 
	       )) 
   ) 
  ) 


(defModelFragment pump-operating-mode 
:documentation "the class of operating mode models of the pump" 
  :subclass-of (dme-user::operating-mode-model) 
  :participants  
  ((pump-involved :type pump 
	      :documentation "the pump involved in the operating mode" 
   )) 
  ) 

;; The following mf comes from the equation 8.7b on page 312 
;;  for approximating the W'_p/m'. 
(defModelFragment pump-power-input-per-mass-approximation 
  :documentation "the operating mode model of a pump expressing the relation among the power input per unit mass, specific volume, and the pressure differential across the pump" 
  :subclass-of (pump-operating-mode   
		1-1-control-volume-op-mode 
		thermal-process-op-mode) 
  :conditions  
  ((component-cv pump-involved 1-1-cv-involved) 
   (process-cv process-involved 1-1-cv-involved)) 
  :consequences 
  ( 
    ;; The following equation comes from equation 8.7b on page 312. 
    ;; The factor of 1e-3 is there to convert the numbers into MPa, which is not 
    ;; the standard unit we should be using.  We should convert the 
    ;; numbers in the saturated water table  
    ;; to use J instead of kJ, and all the numbers in example 8.1 to 
    ;; use Pa and J to get rid of the factor. 

   (= (power-input-per-mass (process-involved ?self)) 
      (* (specific-volume (inlet-stream (1-1-cv-involved ?self))) 
	 (/ (- (stream-pressure 
		(outlet-stream (1-1-cv-involved ?self))) 
	       (stream-pressure 
		(inlet-stream (1-1-cv-involved ?self)))) 
	    1000))) 
   ) 
  ) 

(defModelFragment steady-flow-throttling 
  :documentation "the steady flow process involving a reduction in pressure without enthalpy change such as flow through a valve" 
  :subclass-of (steady-flow-expansion steady-flow-adiabatic-process) 
  :conditions ((process-cv ?self ?cv)	;***not cml 
	       (undergoing adiabatic-throttling ?cv))  
  :consequences 
  ( 
   (= (work-rate ?self) 0) 
   (foreach ?cv (process-cv ?self) 
	    (= (pe-rate-out ?cv) (pe-rate-in ?cv))) 
   (foreach ?cv (process-cv ?self) 
	    (= (ke-rate-out ?cv) (ke-rate-in ?cv))) 

   ) 
  ) 

(defModelFragment steady-flow-adiabatic-mixing 
  :documentation 
  "Adiabatic Mixing of fluid streams into one outlet. Also used for 
   modeling of open heat exchangers" 
  :subclass-of (steady-flow-adiabatic-process) 
  :consequences 
  ( 
   (= (work-rate ?self) 0) 
   (foreach ?cv (process-cv ?self) 
	    (= (ke-rate-out ?cv) (ke-rate-in ?cv))) 
    
   (foreach ?cv (process-cv ?self) 
	    (= (pe-rate-out ?cv) (pe-rate-in ?cv))) 
    
   ) 
  ) 

(defModelFragment steady-flow-in-nozzle 
  :documentation 
  "Model of nozzle flow" 
  :subclass-of (steady-flow-expansion steady-flow-adiabatic-process) 
  :conditions () 
  :consequences 
  ( 
   (= (work-rate ?self) 0) 
   (foreach ?cv (process-cv ?self) 
	    (= (pe-rate-out ?cv) (pe-rate-in ?cv))) 
   ) 
  ) 

(defModelFragment steady-flow-in-diffuser 
  :documentation 
  "Model of diffuser flow" 
  :subclass-of (steady-flow-compression steady-flow-adiabatic-process);; Ho 
  :conditions () 
  :consequences 
  ( 
   (= (work-rate ?self) 0) 
   (foreach ?cv (process-cv ?self) 
	    (= (pe-rate-out ?cv) (pe-rate-in ?cv))) 
   ) 
  ) 

(defModelFragment steady-flow-combustion-process 
  :documentation 
  "Model of combustion, say in the furnace of a boiler, or the combustor 
   of a gas turbine plant" 
  :subclass-of (steady-flow-adiabatic-mixing) 
  :conditions () 
  :consequences () 
  ) 


;;;---------------------------------------------------------------------- 
;;; General (unsteady) flow processes 
;;;---------------------------------------------------------------------- 

;;; To make this more generic and useful for actual analysis of  
;;; transient behavior of thermal systems, need to be able to deal with 
;;; "complex" control volumes which includes solids, controllers etc. 

(defModelFragment non-steady-state-flow-process 
  :documentation 
  "the general (i.e. non-steady state) flow process model employing the 
first law of thermodynamics (Energy conservation) and mass 
conservation." 
  :subclass-of (thermal-process) 
  :consequences 
  ( 
    ;; First law.  Heat - Work = (dEnergy)cv + (Energy-out)cv - (Energy-in)cv 
    ;; in terms of d/dt - time differential form as per Moran  
   (foreach ?cv (process-cv ?self) 
	    (= (- (heat-rate ?self) (work-rate ?self)) 
	       (+ (- (enthalpy-rate-out ?cv) (enthalpy-rate-in ?cv)) 
		  (- (pe-rate-out ?cv) (pe-rate-in ?cv)) 
		  (- (ke-rate-out ?cv) (ke-rate-in ?cv)) 
		  (energy-rate ?cv)) 
	       )) 
   (foreach ?cv (process-cv ?self) 
	    (= (energy-rate ?cv) 
	       (+ (internal-energy-rate ?cv) 
		  (ke-rate ?cv) 
		  (pe-rate ?cv)))) 
    ;; pe and ke terms typically ignored (more so because CV almost 
    ;; always does not move). Exceptions include analysis involving 
    ;; accumulation of fluids in a tall column within the CV for 
    ;; example 

    ;; All the rate quantities are time-dependent rather than steady as 
    ;; assumed in sssf process 

    ;;Second law.  Entropy-generation = (dEntropy)cv + (Entropy-out)cv 
    ;;- (Entropy-in)cv - Qcv/T in terms of d/dt - time differential 
    ;;form as per Moran 

   (foreach ?cv (process-cv ?self) 
	    (= (Entropy-generation-rate ?self) 
	       (+ (- (entropy-rate-out ?cv) 
		     (entropy-rate-in ?cv)) 
		  (- (/ (heat-rate ?self) (heat-transfer-temperature ?self))) ;av. temp. 
		  (entropy-rate ?cv)) 
	       )) 
   (= (Irreversibility-rate ?self) 
      (* (entropy-generation-rate ?self) (state-temperature *dead-state*)) 
      ) 

    ;; Mass conservation 
   (foreach ?cv (process-cv ?self) 
	    (= (mass-rate ?cv) 
	       (- (mass-rate-in ?cv) 
		  (mass-rate-out ?cv)) 
	       )) 
    ;; last two terms can also be expressed in terms of V,A,v at inlet 
    ;; and outlet ports of CV if 1-dimensional flow is assumed at inlet 
    ;; and outlet ports 
   )) 

;; Is it useful to make ssfe a subclass of this process and just 
;; assert (energy-rate cv) and (mass-rate cv) = 0, and other rates do 
;; not change with respect to time?? 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;; system definitions 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

(defEntity compressor-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of a compressor, an associated 
control-volume, and a compression process." 
  :attributes 
  ((cmpsr :type compressor 
	  :abbreviation cmpsr 
	  :The-*-the-object "compressor" 
	  :documentation "the compressor" 
	  ) 
   (cmpsr-cv :type  1-1-control-volume 
	     :abbreviation cmp-cv 
	     :documentation 
	     "the control volume associated with the compressor in the compressor system" 
	     :the-*-the-object 
	     ("control volume associated with the compressor" "of")) 

   (cmpsn-prcs :type steady-flow-compression 
	       :abbreviation cmp-prss 
	       :The-*-the-object "compression process" 
	       :documentation "the compression process of the compressor system"	) 
   (air-in-cmpsr :type air 
		 :abbrevation air 
		 :documentation "the air flowing through the compressor" 
		 :the-*-the-object ("air in the compressor" "of") 
		 ) 
   ) 
   
  :consequences 

   ;;The control volume is associated with the compressor 
  ((cv-component cmpsr-cv  cmpsr) 
   (component-cv cmpsr cmpsr-cv) 
   (process-cv cmpsn-prcs cmpsr-cv) 
   (substance-in cmpsr-cv air-in-cmpsr) 
   ) 
  ) 

(defEntity 2-1-open-feedwater-heater-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of an open feedwater heater, 
an associated control-volume, and an adiabatic mixing process." 
  :attributes 
  ((opn-fwt-htr :type 2-1-open-feedwater-heater 
		:abbreviation fwt 
		:The-*-the-object "open feedwater heater" 
		:documentation "the open feedwater heater of the 2-1-open feedwater heater system" 
		) 
   (opn-fwt-htr-cv :type 2-1-control-volume 
	      :documentation "the control volume associated with the open feedwater heater" 
		:the-*-the-object ("control volume associate with the feedwater heater" "of") 
		:abbreviation "cv-fwt") 
   (adbtc-mxng-prcs :type steady-flow-adiabatic-mixing 
		    :abbreviation mxng-prcs 
		    :The-*-the-object "adiabatic mixing" 
		    :documentation "the adiabatic mixing process"	 
		    )) 
   
  :consequences 
   ;;The control volume is associated with the feedwater heater 
  ((cv-component  opn-fwt-htr-cv opn-fwt-htr) 
   (component-cv  opn-fwt-htr opn-fwt-htr-cv ) 
   (process-cv adbtc-mxng-prcs opn-fwt-htr-cv ) 
   ) 
  ) 


(defEntity 3-1-open-feedwater-heater-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of an open feedwater heater, 
an associated control-volume, and an adiabatic mixing process." 
  :attributes 
  ((fwt-htr :type 3-1-open-feedwater-heater 
	    :abbreviation fwt 
	    :The-*-the-object ("open feedwater heater" "of") 
	    :documentation "the open feedwater heater" 
	    ) 
   (fwt-htr-cv :type 3-1-control-volume 
	       :abbreviation fwt-cv 
	      :documentation "the control volume associated with the open feedwater heater" 
		:the-*-the-object ("control volume associated with the open feedwater heater" "in")) 

   (mxng-prcs :type steady-flow-adiabatic-mixing 
	      :abbreviation mxng-prcs 
	      :The-*-the-object "adiabatic mixing" 
	      :documentation "the adiabatic mixing process"	 
	      )) 
  :consequences 
   ;;The control volume is associated with the feedwater heater 
  ((cv-component fwt-htr-cv fwt-htr) 
   (component-cv  fwt-htr fwt-htr-cv) 
   (process-cv mxng-prcs fwt-htr-cv ) 
   ) 
  ) 

(defEntity 2-2-closed-feedwater-heater-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of an open feedwater heater, an associated control-volume, and an adiabatic mixing process." 
  :attributes 
  ((cls-fwt-htr :type 2-2-closed-feedwater-heater 
		:abbreviation cl-fwt 
		:The-*-the-object "closed feedwater heater" 
		:documentation "the closed feedwater heater" 
		) 
   (chtr-cv :type  2-2-control-volume 
	      :documentation "the control volume associated with the closed feedwater heater in the system" 
		:the-*-the-object ("control volume associated with the closed feedwater heater" "in") 
		) 
   (ht-xchg-prcs :type steady-flow-adiabatic-heat-exchange 
		 :abbreviation hxg-prcs		 
		 :The-*-the-object "adiabatic heat-exchange process in the closed feedwater heater" 
		 :documentation "the adiabatic heat-exchange" 
                 :graphical-representation (:Display-Class ()) 
		 )) 
  :consequences 
   ;;The control volume is associated with the feedwater heater 
  ((cv-component chtr-cv cls-fwt-htr) 
   (component-cv  cls-fwt-htr chtr-cv ) 
   (process-cv ht-xchg-prcs chtr-cv ) 
   ) 
  ) 

(defEntity steam-generator-with-reheat-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of a steam generator reheater, 
an associated control volume and a heat-transfer process" 
  :attributes 
  ((sgen :type steam-generator-with-reheat 
	 :abbreviation stmgen 
	 :The-*-the-object "steam generator with reheater" 
	 :documentation "steam generator with reheater" 
	 ) 
   (sgen-cv :type 2-2-control-volume 
	      :documentation "the control volume associated with the steam generator with reheat" 
		:the-*-the-object ("control volume associated with the steam generator with reheat" "in") 
		:abbreviation "sgen-cv") 
   (stmgen-htsr-prcs :type steady-flow-heat-transfer 
		     :abbreviation htfr-prcs 
		     :The-*-the-object "adiabatic heat transfer" 
		     :documentation "the adiabatic mixing process"	 
                     :graphical-representation (:Display-Class ()) 
		     )) 
  :consequences 
   ;;The control volume is associated with the compressor 
  ((cv-component sgen-cv sgen) 
   (component-cv  sgen sgen-cv) 
   (process-cv stmgen-htsr-prcs  sgen-cv) 
   ) 
  ) 

(defEntity pump-system 
  :subclass-of ( system-model) 
  :documentation "the system consisting of a pump, an associated 
control-volume, and an adiabatic compression process." 
  :attributes 
  ((pmp :type pump 
	:abbreviation pmp 
	:The-*-the-object "pump" 
	:documentation "the pump" 
        :graphical-representation (:position (0 0)) 
	) 
   (pmp-cv :type 1-1-control-volume 
	   :abbreviation pmp-cv 
	      :documentation "the control volume associated with the pump in the pump system" 
		:the-*-the-object ("control volume associated with the pump" "in") 
           :graphical-representation (:position (0 0)) 
           ) 
   (adbtc-cmpsn-prcs  
    :type  steady-flow-adiabatic-compression 
    :abbreviation pmp-prcs 
    :The-*-the-object "process" 
    :documentation "the adiabatic compression process"	 
    :graphical-representation (:Display-Class ()) 
    ) 
   (water-in-pmp :type water 
		 :abbreviation pmp-wtr 
		 :The-*-the-object "water" 
		 :documentation "the water flowing through the pump" 
		 ) 
   ) 
   
  :consequences 
   ;;The control volume is associated with the compressor 
  ((cv-component pmp-cv pmp) 
   (component-cv   pmp pmp-cv) 
   (process-cv adbtc-cmpsn-prcs  pmp-cv) 

   (substance-in pmp-cv water-in-pmp) 
   (substance-in (inlet-stream pmp-cv)  water-in-pmp) 
   (substance-in (outlet-stream pmp-cv)  water-in-pmp) 
   ) 
   
  ) 

(defEntity system-with-condensor 
  :subclass-of ( system-model ) 
  :documentation "the class of systems containing a condensor and an 
associated control volume" 
  :attributes 
  ((cnd :type 4-port-heat-exchanger 
	:abbreviation cndnsr 
	:The-*-the-object "condensor" 
	:documentation "the condensor" 
	) 
   ) 
  ) 

;;;Edited by IWASAKI               12 Dec 93  21:59 
(defEntity condensor-system 
  :subclass-of (system-with-condensor) 
  :documentation "the system consisting of a condensor, an associated 
control-volume, and an adiabatic heat-exchange process" 
  :quantities 
   ;; The following slot was created to represent the heat lost to the 
   ;; environment from the condensor. 
  ((condensor-heat-out-rate :dimension power-dimension)) 

  :attributes 
  ( 
   (cnd-cv :type control-volume 
	   :abbreviation cnd-cv 
	   :The-*-the-object "cv of the condensor" 
	   :documentation "the control volume of the condensor" 
           :graphical-representation (:Display-Class ()) 
	   ) 
   (adbtc-hxg-prcs 
    :type  steady-flow-adiabatic-heat-exchange 
    :abbreviation hxg-prcs 
    :The-*-the-object "heat exchange process" 
    :documentation "the aidiabatic heat exchange process"	 
    :graphical-representation (:Display-Class ()) 
    ) 
   (cf-cv :type 1-1-control-volume 
	  :abbreviation cf-cv 
	  :The-*-the-object "cv of the cold flow" 
	  :documentation "the control volume of the cold flow" 
	  :graphical-representation (:Display-Class ()) 
	  ) 
   (hf-cv :type 1-1-control-volume 
	  :abbreviation hf-cv 
	  :The-*-the-object "cv of the hot flow" 
	  :documentation "the control volume of the hot flow" 
	  :graphical-representation (:position (0 0)) 
	  ) 
   (water-in-cnd :type water 
		 :abbreviation cnd-wtr 
		 :The-*-the-object "water" 
		 :documentation "the water flowing through the condensor" 
		 ) 
   ) 
   
  :consequences 
  (    
   (cv-component cnd-cv (cnd ?self)) 
   (component-cv (cnd ?self) cnd-cv ) 
   (process-cv adbtc-hxg-prcs cnd-cv) 
    
   (cv-component (cf-cv ?self)  (cold-flow  (cnd ?self))) 
   (component-cv (cold-flow  (cnd ?self)) (cf-cv ?self)) 
    
   (cv-component (hf-cv ?self) (hot-flow (cnd ?self))) 
   (component-cv  (hot-flow (cnd ?self)) (hf-cv ?self)) 
    
   (substance-in cnd-cv  water-in-cnd) 

   (substance-in hf-cv  water-in-cnd) 
   (substance-in (inlet-stream hf-cv) water-in-cnd) 
   (substance-in (outlet-stream hf-cv)  water-in-cnd) 

   (substance-in cf-cv  water-in-cnd) 
   (substance-in (inlet-stream cf-cv) water-in-cnd) 
   (substance-in (outlet-stream cf-cv)  water-in-cnd) 

   (= (mass-rate-in hf-cv) (mass-rate-out hf-cv))) 
  ) 

(defEntity condensor-with-heat-transfer-system 
  :subclass-of (system-with-condensor ) 
  :documentation "the system consisting of a condensor, an associated 
control-volume, and a heat-transfer process." 
  :attributes 
  ( 
   (cndsr-cv :type 1-1-control-volume 
	      :documentation "the control volume associated with the condensor in the condensor-with-heat-transfer-system" 
		:the-*-the-object ("control volume associated with the condensor" "in") 
		) 
   (cnd-tfr-prcs 
    :type  steady-flow-heat-transfer 
    :abbreviation cnd-tfr-prcs 
    :The-*-the-object "heat transfer process" 
    :documentation "the heat transfer process in the condensor" 
    :graphical-representation (:Display-Class ()) 
    ) 
   ) 
  ) 

(defEntity nozzle-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of a nozzle, an associated 
control-volume, and a throttling process." 
  :attributes 
  ((Nzl :type nozzle 
	:abbreviation nzl 
	:The-*-the-object "nozzle" 
	:documentation "the nozzle" 
	) 
   (nzl-cv :type    1-1-control-volume 
	   :abbreviation nzl-cv 
	      :documentation "the control volume associated with the nozzle in the nozzle-system" 
		:the-*-the-object ("control volume associated with the nozzle" "in")) 
   (thrtlng-prcs 
    :type  steady-flow-throttling	 
    :abbreviation prss 
    :The-*-the-object "throttling process" 
    :documentation "the throttling process" 
    ) 
   ) 
   
  :consequences 
  ((cv-component (nzl-cv ?self) (nzl ?self)) 
   (component-cv (nzl ?self) (nzl-cv ?self)) 
   (process-cv thrtlng-prcs (nzl-cv ?self)) 
   ) 
  ) 

(defEntity turbine-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of a turbine, an associated 
control-volume, and a throttling process." 
  :attributes 
  ((Tbn :type simple-turbine 
	:abbreviation tbn 
	:The-*-the-object "turbine" 
	:documentation "the turbine" 
        :graphical-representation (:position (0 0)) 
	) 
   (tbn-cv :type  1-1-control-volume 
	   :abbreviation tbn-cv 
           :graphical-representation (:position (0 0)) 
	      :documentation "the control volume associated with the turbine in the turbine-system" 
		:the-*-the-object ("control volume associated with the turbine" "in")) 
   (expsn-prcs :type steady-flow-adiabatic-expansion 
	       :abbreviation xpn-prcs 
	       :The-*-the-object "expansion process" 
	       :documentation "the expansion process" 
               :graphical-representation (:Display-Class ()) 
	       ) 
   (water-in-tbn :type water 
		 :abbreviation tbn-wtr 
		 :The-*-the-object "water" 
		 :documentation "the water flowing through the turbine" 
                 :graphical-representation (:Display-Class ()) 
		 ) 
   ) 
   
  :consequences 
  ((cv-component (tbn-cv ?self) (tbn ?self)) 
   (component-cv (tbn ?self) (tbn-cv ?self) ) 
   (process-cv expsn-prcs (tbn-cv ?self)) 

   (substance-in tbn-cv water-in-tbn) 
   (substance-in (inlet-stream tbn-cv) water-in-tbn) 
   (substance-in (outlet-stream tbn-cv)  water-in-tbn) 
   ) 

  ) 

(defEntity extraction-turbine-system 
  :subclass-of (system-model) 
  :documentation "the system consisting of a turbine, an associated 
control-volume, and a throttling process." 
  :attributes 
  ((xTbn :type simple-turbine 
	 :abbreviation tbn 
	 :The-*-the-object "turbine" 
	 :documentation "the turbine" 
	 ) 
   (xtbn-cv :type 1-2-control-volume 
	      :documentation "the control volume associated with the extraction turbine in the extraction-turbine-system" 
		:the-*-the-object ("control volume associated with the extraction turbine" "in") 
		) 
   (expsn-prcs :type steady-flow-expansion 
	       :abbreviation xpn-prcs 
	       :The-*-the-object "expansion process" 
	       :documentation "the expansion process" 
               :graphical-representation (:Display-Class ()) 
	       ) 
   ) 
   
  :consequences 
  ((cv-component (xtbn-cv ?self) (xtbn ?self)) 
   (component-cv (xtbn ?self) (xtbn-cv ?self) ) 
   (process-cv expsn-prcs (xtbn-cv ?self)) 
   ) 
  ) 

(defEntity boiler-system  
  :subclass-of (system-model) 
  :documentation "the system consisting of a boiler, an associated 
control-volume, and a ?? process." 
  :attributes 
  ((Blr :type boiler 
	:abbreviation blr 
	:The-*-the-object "boiler" 
	:documentation "the boiler" 
        :graphical-representation (:position (0 0)) 
	) 
   (blr-cv :type 1-1-control-volume 
           :graphical-representation (:position (0 0)) 
	      :documentation "the control volume associated with the boiler in the boiler-system" 
		:the-*-the-object ("control volume associated with the boiler" "in") 
		) 
   (htfr-prcs :type steady-flow-heat-transfer 
	      :abbreviation htfr-prcs 
	      :The-*-the-object "heat transfer process" 
	      :documentation "the heat transfer process in the boiler" 
              :graphical-representation (:Display-Class ()) 
	      ) 
   (water-in-blr :type water 
		 :abbreviation blr-wtr 
		 :The-*-the-object "water" 
		 :documentation "the water flowing through the boiler" 
                 :graphical-representation (:Display-Class ()) 
		 ) 
   ) 

  :consequences 
  ((cv-component (blr-cv ?self) (blr ?self)) 
   (component-cv (blr ?self) (blr-cv ?self) ) 
   (process-cv htfr-prcs (blr-cv ?self)) 

   (substance-in blr-cv water-in-blr) 
   (substance-in (inlet-stream blr-cv) water-in-blr) 
   (substance-in (outlet-stream blr-cv)  water-in-blr) 
   ) 
  ) 

(defEntity power-system-eight-one 
  :subclass-of (thermal-cycle) 
   
  :documentation "the system consisting of a boiler, a simple turbine, a condenser, and a pump" 
  :attributes 
  ( 
   (blr-system :type boiler-system 
               :graphical-representation (:position (100 50)) 
	      :documentation "the boiler subsystem of power-system-eight-one power cycle" 
		:the-*-the-object ("boiler subsystem" "of") 
		:abbreviation "blr-sys") 
   (tbn-system :type turbine-system 
               :graphical-representation (:position (300 50)) 
	      :documentation "the turbine subsystem of power-system-eight-one power cycle" 
		:the-*-the-object ("turbine subsystem" "of") 
		:abbreviation "tbn-sys") 
		 
   (cdnsr-system :type condensor-system 
                 :graphical-representation (:position (300 250)) 
	      :documentation "the condensor subsystem of the power-system-eight-one power cycle" 
		:the-*-the-object ("condensor subsystem" "of") 
		:abbreviation "cdnsr-sys") 
   (pmp-system :type pump-system 
               :graphical-representation (:position (100 250)) 
	      :documentation "the pump subsystem of the power-system-eight-one power cycle" 
		:the-*-the-object ("pump subsystem" "of") 
		:abbreviation "pmp-sys") 
   (cnd-pmp-junction 
    :type stream-junction 
    :abbreviation j3 
    :The-*-the-object ("junction" "between the condenser and the pump of") 
    :documentation "a stream junction" 
    :graphical-representation (:position (250 300)) 
    ) 
   (blr-tbn-junction 
    :type stream-junction 
    :abbreviation j1 
    :The-*-the-object ("junction" "between the boiler and the turbine of") 
    :documentation "a stream junction" 
    :graphical-representation (:position (250 100)) 
    ) 
   (tbn-cnd-junction 
    :type stream-junction 
    :abbreviation j2 
    :The-*-the-object ("junction" "between the turbine and the condenser of") 
    :documentation "a stream junction" 
    :graphical-representation (:position (350 200)) 
    ) 
   (pmp-blr-junction 
    :type stream-junction 
    :abbreviation j4 
    :The-*-the-object ("junction" "between the pump and the boiler of") 
    :documentation "a stream junction" 
    :graphical-representation (:position (50 200)) 
    ) 
   (working-fluid-in-cycle 
    :type water 
    :abbreviation wtr 
    :The-*-the-object ("working fluid") 
    :documentation "water vapor" 
    :graphical-representation (:Display-Class ()) 
    ) 
   ) 

  :consequences 
  ( 
   (connected-terminals 
    blr-tbn-junction (outlet-stream (blr-cv blr-system)) 
    :graphical-representation (:articulations ((150 165) (250 165)))) 
   (connected-terminals 
    blr-tbn-junction (inlet-stream (tbn-cv tbn-system)) 
    :graphical-representation (:articulations ((350 25) (250 25)))) 

   (connected-terminals 
    tbn-cnd-junction (outlet-stream (tbn-cv tbn-system)) 
    :graphical-representation (:articulations ((350 150)))) 
   (connected-terminals 
    tbn-cnd-junction (inlet-stream (hf-cv cdnsr-system)) 
    :graphical-representation (:articulations ((350 250)))) 

   (connected-terminals 
    cnd-pmp-junction (outlet-stream (hf-cv cdnsr-system)) 
    :graphical-representation (:articulations ((350 350) (350 375) (250 375)))) 
   (connected-terminals 
    cnd-pmp-junction (inlet-stream (pmp-cv pmp-system)) 
    :graphical-representation (:articulations ((150 250) (150 235) (250 235)))) 

   (connected-terminals 
    pmp-blr-junction (outlet-stream (pmp-cv pmp-system)) 
    :graphical-representation (:articulations ((150 350) (150 375) (50 375)))) 
   (connected-terminals 
    pmp-blr-junction (inlet-stream (blr-cv blr-system)) 
    :graphical-representation (:articulations ((150 50) (150 25) (50 25)))) 

   (= (thermal-efficiency ?self) 
      (/ (- (- (specific-enthalpy (outlet-stream (blr-cv blr-system))) 
	       (specific-enthalpy (outlet-stream (tbn-cv tbn-system)))) 
	    (- (specific-enthalpy (outlet-stream (pmp-cv pmp-system))) 
	       (specific-enthalpy (outlet-stream (hf-cv cdnsr-system)) 
				     
				  ))) 
	 (- (specific-enthalpy (outlet-stream (blr-cv blr-system))) 
	    (specific-enthalpy (outlet-stream (pmp-cv pmp-system)))))) 

   (= (back-work-ratio ?self) 
      (/   
       (- (specific-enthalpy (outlet-stream (pmp-cv pmp-system))) 
	  (specific-enthalpy (outlet-stream (hf-cv cdnsr-system)) 
				 
			     )) 
       (- (specific-enthalpy (outlet-stream (blr-cv blr-system))) 
	  (specific-enthalpy (outlet-stream (tbn-cv tbn-system)))) 
       )) 

   (= (heat-rate (htfr-prcs blr-system)) 
      (* (mass-rate-in (blr-cv blr-system)) 
	 (- (specific-enthalpy (outlet-stream (blr-cv blr-system))) 
	    (specific-enthalpy (outlet-stream (pmp-cv pmp-system)))) 
	 (/ 1 3600000) 
	 ) 
      ) 

   (= (cycle-mass-rate ?self) 
      (* 3.6 
	  ;; This multiplication factor is to convert to the units of 
	  ;; measures used in 8.1, which are kJ and Mpa. 
	 (/ (net-work-output-rate ?self) 
	    (- (- (specific-enthalpy (outlet-stream (blr-cv blr-system))) 
		  (specific-enthalpy (outlet-stream (tbn-cv tbn-system)))) 
	       (- (specific-enthalpy (outlet-stream (pmp-cv pmp-system))) 
		  (specific-enthalpy (outlet-stream (hf-cv cdnsr-system)) 
				     )))))) 

   (= (cycle-mass-rate ?self) 
      (mass-rate-in (blr-cv blr-system))) 
    
   (= (cycle-mass-rate ?self) 
      (mass-rate-in (tbn-cv tbn-system))) 

   (= (condensor-heat-out-rate cdnsr-system) 
      (* (cycle-mass-rate (hf-cv cdnsr-system )) 
	 (- (specific-enthalpy (outlet-stream (tbn-cv tbn-system))) 
	    (specific-enthalpy (outlet-stream (hf-cv cdnsr-system)) 
			       ))) 
      ) 
   ) 
  ) 
    
(defEntity power-system-with-reheat 
  :subclass-of (thermal-cycle) 
  :documentation "the system consisting of a steam-generator/reheater, 
first-stage and second-stage turbines, a condenser, and a pump" 
  :attributes 
  ( 
   (sgen-sys :type steam-generator-with-reheat-system 
	     :documentation "the steam generator with reheat subsystem of the power-system-with-reheat power cycle" 
		:the-*-the-object ("steam generator subsystem" "of") 
		:abbreviation "sgen-sys") 
   (tbn-sys1 :type turbine-system 
	      :documentation  "the first-stage turbine subsystem of the power-system-with-reheat power cycle" 
		:the-*-the-object ("first-stage turbine subsystem" "of") 
		:abbreviation "tbn-sys1") 
   (tbn-sys2 :type turbine-system 
	      :documentation "the second-stage turbine subsystem of the power-system-with-reheat power cycle" 
		:the-*-the-object ("second-stage turbine subsystem" "of") 
		:abbreviation "tbn-sys2") 
   (cnd-sys :type condensor-with-heat-transfer-system 
	      :documentation "the condensor subsystem of the power-system-with-reheat power cycle" 
		:the-*-the-object ("condensor subsystem" "of") 
		:abbreviation "cnd-sys") 
   (pmp-sys :type pump-system 
	      :documentation "the pump subsystem of the power-system-with-reheat power cycle" 
		:the-*-the-object ("pump subsystem" "of") 
		:abbreviation "pmp-sys") 
       
   (sgen-tbn1-junction 
    :type stream-junction 
    :abbreviation j1 
    :The-*-the-object ("junction" "between the steam generator and the turbine of") 
    :documentation "a stream junction") 
   (tbn1-sgen-junction 
    :type stream-junction 
    :abbreviation j2 
    :The-*-the-object 
    ("junction" "between the first-stage turbine and the steam generator of") 
    :documentation "a stream junction" 
    ) 
       
   (sgen-tbn2-junction 
    :type stream-junction 
    :abbreviation j3 
    :The-*-the-object ("junction" "between the steam generator and the second-stage turbine of") 
    :documentation "a stream junction") 
   (tbn2-cnd-junction 
    :type stream-junction 
    :abbreviation j4 
    :The-*-the-object ("junction" "between the second-stage-turbine and the condensor of") 
    :documentation "a stream junction") 
   (cp-junction 
    :type stream-junction 
    :abbreviation j5 
    :The-*-the-object ("junction" "between the condenser and the pump of") 
    :documentation "a stream junction") 
   (pmp-sgen-junction 
    :type stream-junction 
    :abbreviation j6 
    :The-*-the-object ("junction" "between the pump and the steam generator of") 
    :documentation "a stream junction") 
   ) 
      
  :consequences 
  ((connected-terminals sgen-tbn1-junction (outlet-stream1 (sgen-cv sgen-sys))) 
   (connected-terminals sgen-tbn1-junction (inlet-stream (tbn-cv tbn-sys1))) 
       
   (connected-terminals tbn1-sgen-junction (outlet-stream (tbn-cv tbn-sys1))) 
   (connected-terminals tbn1-sgen-junction (inlet-stream2 (sgen-cv sgen-sys))) 
       
   (connected-terminals sgen-tbn2-junction (outlet-stream2 (sgen-cv sgen-sys))) 
   (connected-terminals sgen-tbn2-junction (inlet-stream (tbn-cv tbn-sys2))) 
       
   (connected-terminals tbn2-cnd-junction (outlet-stream (tbn-cv tbn-sys2))) 
   (connected-terminals tbn2-cnd-junction (inlet-stream (cndsr-cv cnd-sys))) 
       
   (connected-terminals cp-junction (outlet-stream (cndsr-cv cnd-sys))) 
   (connected-terminals cp-junction (inlet-stream (pmp-cv pmp-sys))) 
       
   (connected-terminals pmp-sgen-junction (outlet-stream (pmp-cv pmp-sys))) 
   (connected-terminals pmp-sgen-junction (inlet-stream1 (sgen-cv sgen-sys))) 
   ) 
  ) 
    
    
(defEntity power-system-with-extraction-turbines 
  :subclass-of (thermal-cycle  ) 
  :documentation "the system consisting of a steam-generator/reheater, 
first-stage and second-stage extraction turbines, a condenser, a pump, 
an open heater, a second pump, and a closed heater, and a trap, 
modeled as a nozzle" 
  :attributes 
  ( 
   (sgen-system :type steam-generator-with-reheat-system 
	      :documentation "the steam generator subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("steam generator subsystem" "of") 
		:abbreviation "sgen-sys") 
   (xtbn-system1 :type extraction-turbine-system 
	      :documentation "the first-stage extraction turbine subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("first-stage extraction turbine subsystem" "of") 
		:abbreviation "xtbn-sys1") 
   (xtbn-system2 :type extraction-turbine-system 
	      :documentation "the second-stage extraction turbine subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("second-stage extraction turbine subsystem" "of") 
		:abbreviation "xtbn-sys2") 
   (cnd-system :type condensor-with-heat-transfer-system 
	      :documentation "the condensor subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("condensor subsystem" "of") 
		:abbreviation "cnd-sys") 
   (pmp-system1 :type pump-system 
	      :documentation "the first pump subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("first pump subsystem" "of") 
		:abbreviation "pmp-sys1") 
   (ohtr-system :type 3-1-open-feedwater-heater-system 
	      :documentation "the open feedwater heater subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("open feedwater heater subsystem" "of") 
		:abbreviation "ofwt-sys") 
   (pmp-system2 :type pump-system 
	      :documentation "the second pump subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("second pump subsystem" "of") 
		:abbreviation "pmp-sys2") 
   (chtr-system :type 2-2-closed-feedwater-heater-system 
	      :documentation "the closed feedwater heater subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("closed feedwater heater subsystem" "of") 
		:abbreviation "cfwt-sys") 
   (trp-system :type nozzle-system 
	      :documentation "the trap subsystem of the power-system-with-extraction-turbine power cycle" 
		:the-*-the-object ("trap subsystem" "of") 
		:abbreviation "trp-sys") 

   (sgen-xtbn1-junction 
    :type stream-junction 
    :abbreviation j1 
    :The-*-the-object ("junction" "between the steam generator and the first-stage extraction turbine of") 
    :documentation "a stream junction" 
    ) 
   (xtbn1-chtr-junction 
    :type stream-junction 
    :abbreviation j2 
    :The-*-the-object ("junction" 
		       "between the first-stage extraction turbine and the closed heater of") 
    :documentation "a stream junction" 
    ) 
   (xtbn1-sgen-junction 
    :type stream-junction 
    :abbreviation j3 
    :The-*-the-object ("junction" 
		       "between the first-stage extraction turbine and the steam generator") 
    :documentation "a stream junction" 
    ) 
   (sgen-xtbn2-junction 
    :type stream-junction 
    :abbreviation j4 
    :The-*-the-object ("junction" 
		       "between the steam generator and the second-stage extraction turbine of") 
    :documentation "a stream junction" 
    ) 
   (xtbn2-ohtr-junction 
    :type stream-junction 
    :abbreviation j5		 
    :The-*-the-object ("junction" 
		       "between the second-stage extraction turbine and the open heater of") 
    :documentation "a stream junction" 
    ) 
   (xtbn2-cnd-junction 
    :type stream-junction 
    :abbreviation j6 
    :The-*-the-object ("junction" 
		       "between the second-stage extraction turbine and the condenser of") 
    :documentation "a stream junction" 
    ) 
   (cnd-pmp1-junction 
    :type stream-junction 
    :abbreviation j7 
    :The-*-the-object ("junction" 
		       "between the condenser and the first pump of") 
    :documentation "a stream junction" 
    ) 
   (pmp1-ohtr-junction 
    :type stream-junction 
    :abbreviation j8 
    :The-*-the-object ("junction" 
		       "between  the first pump and the open heater of") 
    :documentation "a stream junction" 
    ) 
   (ohtr-pmp2-junction 
    :type stream-junction 
    :abbreviation j9 
    :The-*-the-object ("junction" 
		       "between  the open heater and the second pump of") 
    :documentation "a stream junction" 
    ) 
   (pmp2-chtr-junction 
    :type stream-junction 
    :abbreviation j10 
    :The-*-the-object ("junction" 
		       "between the second pump and the closed heater of") 
    :documentation "a stream junction" 
    ) 
   (chtr-sgen-junction 
    :type stream-junction 
    :abbreviation j11 
    :The-*-the-object ("junction" 
		       "between the closed heater  and the steam generator of") 
    :documentation "a stream junction" 
    ) 
   (chtr-trp-junction 
    :type stream-junction 
    :abbreviation j12 
    :The-*-the-object ("junction" 
		       "between the closed heater and the trap of") 
    :documentation "a stream junction" 
    ) 
   (trp-ohtr-junction 
    :type stream-junction 
    :abbreviation j13 
    :The-*-the-object ("junction" 
		       "between the trap and the open heater of") 
    :documentation "a stream junction" 
    ) 
   ) 
  :consequences 
  ((connected-terminals sgen-xtbn1-junction  (outlet-stream1 (sgen-cv sgen-system))) 
   (connected-terminals sgen-xtbn1-junction  (inlet-stream (xtbn-cv xtbn-system1))) 

   (connected-terminals xtbn1-chtr-junction (outlet-stream2 (xtbn-cv xtbn-system1))) 
   (connected-terminals xtbn1-chtr-junction (inlet-stream2 (chtr-cv chtr-system))) 

   (connected-terminals xtbn1-sgen-junction (outlet-stream1 (xtbn-cv xtbn-system1))) 
   (connected-terminals xtbn1-sgen-junction (inlet-stream2 (sgen-cv sgen-system))) 

   (connected-terminals sgen-xtbn2-junction (outlet-stream2 (sgen-cv sgen-system))) 
   (connected-terminals sgen-xtbn2-junction (inlet-stream (xtbn-cv xtbn-system2))) 
						 
   (connected-terminals xtbn2-ohtr-junction (outlet-stream2 (xtbn-cv xtbn-system2))) 
   (connected-terminals xtbn2-ohtr-junction (inlet-stream2 (fwt-htr-cv ohtr-system))) 

   (connected-terminals xtbn2-cnd-junction (outlet-stream1 (xtbn-cv xtbn-system2))) 
   (connected-terminals xtbn2-cnd-junction (inlet-stream (cndsr-cv cnd-system))) 

   (connected-terminals cnd-pmp1-junction (outlet-stream (cndsr-cv cnd-system))) 
   (connected-terminals cnd-pmp1-junction (inlet-stream (pmp-cv pmp-system1))) 

   (connected-terminals pmp1-ohtr-junction (outlet-stream (pmp-cv pmp-system1))) 
   (connected-terminals pmp1-ohtr-junction (inlet-stream1 (fwt-htr-cv ohtr-system))) 
    
   (connected-terminals ohtr-pmp2-junction (outlet-stream (fwt-htr-cv ohtr-system))) 
   (connected-terminals ohtr-pmp2-junction (inlet-stream (pmp-cv pmp-system2))) 

   (connected-terminals pmp2-chtr-junction (outlet-stream (pmp-cv pmp-system2))) 
   (connected-terminals pmp2-chtr-junction (inlet-stream1 (chtr-cv chtr-system))) 

   (connected-terminals chtr-sgen-junction (outlet-stream1 (chtr-cv chtr-system))) 
   (connected-terminals chtr-sgen-junction (inlet-stream1 (sgen-cv sgen-system))) 

   (connected-terminals chtr-trp-junction (outlet-stream2 (chtr-cv chtr-system)))   
   (connected-terminals chtr-trp-junction (inlet-stream (nzl-cv trp-system))) 

   (connected-terminals trp-ohtr-junction (outlet-stream (nzl-cv trp-system))) 
   (connected-terminals trp-ohtr-junction (inlet-stream3 (fwt-htr-cv ohtr-system))) 
   ) 

  ) 

(cml::ontolingua-translation-on-load 
 thermodynamics (:DME :CML) 
 "A thermodynamics domain theory." 
 :io-package "CML-USER" 
 ) 

This Lisp-to-HTML translation was brought to you by
François Gerbaux and Tom Gruber