Full Document - LTH, Lunds Tekniska Högskola

Transcription

Industrial Electrical Engineering and CHMARKING the STARController using MatlabJosep Carrasco MartínezDept. of Industrial Electrical Engineering and AutomationLund University

BENCHMARKING the STAR Controllerusing MatlabA MSC THESIS PRESENTED AT THE DEPARTMENT OF Industrial ElectricalEngineering and Automation (IEA) of LTH at LUND UNIVERSITYAuthor:For the Degree of:Supervisor:Examiner:Date:Josep Carrasco MartínezMaster of ScienceDr Christian RosenDr Ulf JeppssonSeptember 2006

ii

iii

iv

ABSTRACTAbstractAlong the years there have been large advances in Wastewater Treatment Plants(WWTP since now), from the basic treatment until applying the last technologies inautomatic control systems, concentration measurements and mathematical modelling ofwastewater treatments. About the last technologies it has to be stood out the fastadvanced of computer systems, that let not only implement the most complex models ofWWTP to check the evolution of the system in a short time, but also the possibility ofintegrating more complex controls, and it has to be stood the advanced of electronicsystems too, that let apply the last sensor technologies, increasing the reliability and thedevice life in the abrasive ambient as it is the waste water.The difficulty in WWTP is the biological processes that take part within the vessels.Principally the growth of biological microorganisms that are the responsible ofremoving the organic matter dissolved in the wastewater. The main organic matter thatis removed from wastewater is the carbon, the nitrogen and the phosphorus, althoughthe phosphorus can be removed sometimes by chemistry processes, which are fasterthan biological processes. The problem in biological processes is its slow dynamic andthe external perturbations, which can affect considerably the growth of biologicalmicroorganisms.Currently, the companies involved in WWTP offer automation tools and packages thatlet to apply automation techniques in WWTP easily. One of the most important devicesoffered is the controller, which will try to lead the progress of the wastewater by theright values and to ensure the process is getting the goals. It means that the controller isgoing to control the biological processes that take part in wastewater treatment applyingthe different control strategies programmed.Here there are three concepts all together; the controller, the biological process and thecontrol strategy. First, the control strategy is tested using a model of the WWTP. After,it is implemented in the controller to apply it to the real WWTP to control the biologicalprocess. The problem appears when the control strategy is applied to the real process. Itis impossible to predict all that is going to happen in WWTP, because there areunpredictable external disturbances (rain, storms, temperature, dry weather, snow, ice,etc) that can affect the biological processes. The biological processes are sensible to theexternal changes of the weather. It means that a control strategy tested in a simulationwithin ideal conditions can not be the suitable.The problem rises when the control strategy is not the suitable. The biological processesdynamic is really slow, a time constant of days, even weeks some times. Hence, it ispossible to know when a control strategy is wrong after days or weeks, and then, is toolate to try to control the process and one more week is needed to test another controlstrategy. All this time checking the control strategy means to spend a lot of resources.There is one possible solution that would save a lot time and would let to test morecontrol strategies using less resources. The solution consists in building a completemodel of the WWTP that is going to be controlled (it would be necessary a particularmodel for each WWTP), and to simulate it in real time at the same time as the evolutionof the real WWTP. It would let the controller to have two kinds of data, the datav

measured in the WWTP and the data from the simulation of the model. With these datathe controller or the operator can compare and test the control strategies, so that if thedata measured in the WWTP are far from the data calculated in the simulation, it ispossible to guess that there is something wrong with the control strategy.Of course, this solution forces to implement a perfect model of the WWTP because thecontroller is comparing the data of the simulation of the model and the data of theWWTP, considering that the data calculated with the model are always right.vi

PREFACEPrefaceBefore has been introduced one of the current problems in WWTP, a problemresponsible of spending a lot of resources and time when testing control strategies toimprove the efficiency in WWTP.The realization of the present thesis is one of the results of a task group work of the“krüger” (in Copenhagen, Denmark, from “Veolia Water Systems” group,http://www.kruger.dk) in collaboration with the department of “Industrial ElectricalEngineering and Automation” (IEA, at Lund University, Sweden). There has beencreated a research group with workers of the company and researchers of the IEAdepartment, which purposes are to improve modelling WWTP and the control strategiesminimizing the necessary resources.Acknowledgements:At last, the finalization of this thesis was possible not only to the work realized by theauthor, but also to the IEA department and the krüger company. There were involvedmore people, directly and indirectly related with the thesis.I would like to express my special gratitude to all the people that have helped me in oneor another way finishing the thesis.Thank you to Christian Rosen (research associated of the IEA department), he hasfollowed and supervised the progress of the thesis, despite of all the work that he had.He is part of the research group in collaboration with the company “Veolia WaterSystems”. It was inestimable his help to introduce me in the topic of waste watertreatment; it was absolutely new for me at the beginning of the thesis.Thank you to Ulf Jeppsson, the responsible of the IEA department, who has supervisedthe thesis too, specially the part of modelling batch process. His work about modellingsettling and clarification and the model programmed in Matlab by Krist V. Gernaey(CAPEC, Dept. of Chemical Engineering, DTU, Denmark) and him, are the key modelimplemented in this thesis.Thank you to Eric Login from “Veolia Water System” (krüger, in Copenhagen,Denmark). The communication of the main application was developed and discussed incollaboration with him.Thank you to Sergey Litvinov too. I never met him personally, but his help wasessential to resolve the creation of XML files with Matlab.Finally, my gratitude to Dalius Misiunas, Fredrick Roos, Carlos Álbarez, DanielAguado, Jon Bolmstedt, Gunnar Lindstedt and all the department of “IndustrialElectrical Engineering and Automation” (IEA, LTH, Lund, Sweden), and specially toLunds Universitet and the Polytechnic University of Valencia (Universidad Politécnicade Valencia –UPV-, Valencia, Spain) who gave me the possibility of taking part in thisforeign experience and realise the final degree thesis abroad.vii

viii

CONTENTSContentsABSTRACTvPREFACEviiPART I: Introduction1Chapter 1: Introduction31.1 Motivation41.2 Objectives51.3 Contribution61.4 Outline of the thesis7Chapter 2: Wastewater Treatment Processes92.1 Process description102.2 Automation in wastewater treatment plants132.3 Modelling of wastewater treatment processes17Modelling mass transfer17Modelling biological nutrient removal (ASM1)18Modelling hydraulics21Modelling settling and clarification22Modelling batch processes25PART II: Modelling the wastewater treatment plant with MatlabChapter 3: Application Design27293.1 Introduction303.2 Main flow-sheet313.3 Structure of the program323.3.1 Initialization353.3.2 Main loop353.4 Application Implemented383.4.1 Application Interface383.4.2 Program Code40ix

CONTENTSChapter 4: Data Exchange454.1 Introduction464.1.1 What SOAP is474.1.2 XML communication files484.2 Data-flux in the communication504.3 Data-exchange with the database524.3.1 Write the data in “results.XML”524.3.2 Read the data from “database.XML”544.4 Synchronization4.4.1 Read the data from “synchro.XML”Chapter 5: Modelling Batch Processes with Matlab5656595.1 Introduction605.2 Model developed605.2.1 Model diagram635.2.2 Model equations705.3 Implementation of the model5.3.1 S-function programmed5.4 Comments727579PART III: Appendixes (included papers)APPENDIX I: Appendixes to CHAPTER 28183I.1 Appendixes for MODELLING WASTEWATERTREATMENT PROCESSESI.1.1 Tabular form for “simple biological kinetics”8484I.1.2 Tabular form for “simple biological kinetics” and“carbon removal kinetics”84I.1.3 Tabular form for “simple biological kinetics”,“carbon removal kinetics” and “nitrogen removal kinetics”I.1.4 Tabular form for “phosphorus removal kinetics”APPENDIX II: Appendixes to CHAPTER 3II.1 STAR emulator to check the synchronization codeII.1.1 “writeXML synchro” codeII.2 Control functions8687888989II.2.1 “controlloop” code90II.2.2 “control check” code90II.3 Processing data with Matlabx8592II.3.1 “read data” function92II.3.2 “wirte data” function93

CONTENTSII.4 GUIDE application93II.4.1 What’s GUIDE93II.4.2 Application GUIDE code93APPENDIX III: Appendixes to CHAPTER 495III.1 Web Services96III.2 SOAP protocol97III.3 “org.apache.xerces.dom.DocumetImpl” class98APPENDIX IV: Appendixes to CHAPTER 5IV.1 S-function “settlerB batchM.c” codePART IV: Bibliography101102111xi

CONTENTSxii

PART ITITLE: Introduction1

2

CHAPTER 1IntroductionThis chapter is a brief sight of the thesis; motivations, contributions, structureand objectives.After reading this chapter the reader knows the contents of each point in thisthesis, so it’s important to know how to read it and where is each topicstudied.3

CHAPTER 1: Introduction1.1 MOTIVATIONThe treatment of the waste water is a complex process, process compound of severalbiological processes sensitive to the external disturbances, as can be the storm, the rain,the snow, the ice; all the climatological changes can affect the wastewater treatmentprocess. The sensitive biological processes and the disturbances of the weather makedifficult the control of the wastewater treatment process.Through the new technologies the most avant-garde companies have tried to solve theproblem of the complex control needed and the existing disturbances within the process.With the new sensors it is easier to measure the state of the process and try to designsuitable control strategies. The possibilities of the new computers let this and more, butthere is still one restriction: the dynamic of the biological processes.With the new advances of the techniques sometimes it is forgot that the new techniquescant change the process, they are only developed to control it, to get a stable andcontrollable process. The dynamic of some biological process are so slow, it means thatthe results of an action control will be observed a long time after applying it. Thisdifficult the control of the process more than it seems at the beginning, because whenthe controller tries to solve the mistakes of the strategies or the effect of the disturbancesit is too late, and the process need double time to became stable again.The task group formed by “Veolia Water System” (krüger, in Copenhagen, Denmark)and the department of “Industrial Electrical Engineering and Automation (LTH, Lund,Sweden) was formed to improve the wastewater treatment processes using sophisticatetechniques to model the whole process including the sensors model, the controllermodel and the plant model. Within the group rose the idea of simulating the wastewaterprocess plant in real time. What does this idea mean? How can the real time simulationof the WWTP improve the behaviour or the control of the plant?The answer to these questions is the motivation of this thesis. If it is possible toimplement a perfect model of the WWTP and the controller that is being applied in thereal WWTP, and to start the simulation of the process from the values of the datameasured in the real plant, it would be possible to have the progress of the WWTP atthe same time as the progress of the model implemented, and it would be easy tocompare the values of the state variables of the simulation and the state variables of thereal process. Comparing these values would be suitable to find disturbances in theprocess or important features of the plant that are not included in the model used usuallyto check the control strategies in simulation time. By the other side, the values of thesimulation in real time would let to see the progress of some state variables that the realmeasurements can not let due to the characteristics of the sensor: the noise, the error, theprecision, etc.4

Josep Carrasco Martínez1.2 OBJECTIVESIn the point before has been discussed the motivation of the present thesis, but there isnot enough with motivations to developed a thesis. The motivation is the beginning, themain idea to solve a problem, to improve a process, to do anything.The motivation says that it would be a good idea to simulate the model of the WWTP atthe same time that the plant is working, with the same conditions, the same value of thestate variables, the same control strategy, and after, to compare the results of thesimulation and the measurements of the process. But now the motivation has to betranslated to objectives, which will represent a concrete aims.If we start to analyze the motivation, the purpose is to simulate a model while theWWTP is working. So the first objective will be the implementation of an application tosimulate the model of the WWTP.The controller has to compare the results of the simulation and the measurements of theWWTP. It points that it is need a communication between the application developedand the controller of the WWTP.The application is simulating the model of the WWTP at the same time that the realplant is working, and the controller is transferring data from the real process to ensurethe model of the simulation and the real plant have the same conditions. So not is onlyneeded a communication between the application and the controller, the synchronizationis needed too.At last, the most important is the model. The model of the WWTP has to be developed.There are a lot of possibilities to implement a model of the WWTP, and only to modelone part of the plant can be a master thesis. Here in this thesis in implemented themodel of the batch process (see chapter 2 to know what a batch process is) in onevessel. From the model exposed is possible to implement the full model of thesecondary treatment in WWTP, but it will not be the aim of this thesis.Summarising, the objectives of the present thesis are: Implementation of an automatic application to simulate a model of the WWTPin real time.To program the communication and the synchronization with the controller.To model batch process in one simple vessel and implement it.5

CHAPTER 1: Introduction1.3 CONTRIBUTIONSThere have been named the objectives of the thesis to get improve the control inwastewater treatment plants. To get these objectives is join to the techniques andapplications that are going to be used for getting them.The whole code programmed in this thesis and the user interface of the application hasbeen programmed within Matlab package toolbox. Matlab is a powerful application thatlet the researchers to implement, simulate, check, program, control near all the things.There are a big number of packages to complement Matlab and let the user to executedifferent things or processes sharing the same workspace, thing that allows interconnectimplemented applications in Matlab and simulations that are running at the same time,without translating the data from one application to another.The thesis has each chapter divided in two virtual parts; the first one explain the abstractdiscussion of the topic that is going to be developed. After the abstract discussion, thesecond part is the implementation of the topic discussed in a real and operative code.Starting from the paragraphs before, the contributions can be understood as: The design of an automatic application that simulate the model of the realWWTP in real time.The implementation of the automatic application in Matlab.The communication of the application with the controller through the Ethernetnetwork. The basis and the implementation in Matlab.The synchronization of the controller and the implemented application, thedesign of several possibilities and the posterior implementation of it.The design of the batch process model, with the evolution of the equations alongall the phases, and the translation of the equations into code to implement themodel.The contributions have been presented as independent works, but they can be read as amain big contribution, the contribution of implementing an application to get thecombination between the abstract part of the control and the real part of the control inthe process working together.The abstract part would be the implementation of the model of the process that is goingto be controlled, all the part of the code programmed dedicated to model and simulatethe WWTP plants. And the real part would represent all the structures and devises thatform the WWTP, the controller, the sensors, the actuators.The implementation of this application is not the substitute for the first simulation andtesting of the control strategies before applying it, it is like an automatic test of thecontrol strategy in real time, a test to verify the control of the WWTP while it isworking.6

Josep Carrasco Martínez1.4 OUTLINE OF THE THESISThe distribution of the thesis try to get the better way to understand the topic developedin. It tries to introduced and explain all the concepts used along the thesis, and to givethe necessary bibliography to look for extra information if it is necessary for the reader,not only to better understanding the thesis, but also to increase the given information inthe present work.The thesis is divided in four parts:1.2.3.4.Introduction.Modelling the Wastewater Treatment Plant in Matlab.Appendixes.Bibliography.Each part is divided in chapters that expose the topics developed along the thesis. Thefirst and the second part form the work of the thesis, and the third and fourth part arecomplementary to read more about the topics developed in the first and second part.The first part is an introduction about wastewater treatment processes, what they are,how to model, the parts of a WWTP plant, the previous knowledge to better understandthe thesis. This part is divided in two chapters: chapter 1 and chapter 2. The chapter 1is the current chapter. The chapter 2 is an introduction about wastewater treatmentplants, the description of the process, automation in WWTP and the basis of modellingWWTP.The second part is that we can call the work developed. There are three chapters:chapter 3, chapter 4 and chapter 5. The chapter 3 contains the design andimplementation of the main application and the user interface. In chapter 4 is discussedand programmed the communication with the controller and the database and thesynchronization with the controller. In chapter 5 is designed and programmed the batchprocess model in Matlab.The third part contains the appendixes to the chapters of the first and second part, andthe last part is the bibliography used to develope the thesis.7

CHAPTER 1: Introduction8

CHAPTER 2Wastewater Treatment ProcessesPrevious to the full report of the project presented in this thesis it is essentiala brief explanation about wastewater treatment processes, what is that,basic modelling and automation within it.In the pages below it is made a description about wastewater treatmentprocesses, giving more details of the second treatment in the plant. After it, abrief introduction about automation in wastewater treatment and finally thebasic modelling in wastewater treatment plants is presented.In this chapter is presented only a basic idea about description, automationand modelling wastewater treatment, for further knowledge it is the possibilityof checking the chapter 7 (“Appendix of CHAPTER 2”) and the bibliography.9

CHAPTER 2: Wastewater Treatment Processes2.1 PROCESS DESCRIPTIONThere are four disciplines involved in wastewater treatment processes, and we need allof them to make work the wastewater plant. In the figure below there is a schema ofthese disciplines:ChemistryHydraulicsBiologyWater distributionandwastewater collectionHydrologyWater processingWater qualityandpollutionWastewater processingAdvanced wastewater treatmentand water reclamationWater reusefigure 1: disciplines involved in wastewater treatmentThe process starts when wastewater is collected in a sewer system and transported to aplant for treatment prior to disposal (hydraulic discipline). Once the wastewater arrivesto the treatment plant it has to pass through three main ARYTREATMENTfigure 2: main treatments in wastewater treatment plantsThe primary treatment is the simplest one, and the most of times it consists in a groupof screens and primary settler to remove the largest rejects (plastic bags, food andanother solid products) and to skims off floating greases and oils. After this firsttreatment it is the secondary treatment, where it takes part the biological reactions,chemical precipitation, nutrient mass transfer, biomass growth and settling andclarification; it is called Biological Nutrient Removal (BNR). The last treatment,tertiary treatment, is a group of filters and membrane techniques and, this part of theplant can change considerably, it depends of the final use of the e-fluent water (humanconsume, industry use, river recirculation, etc); this treatment attempts to limit themicro-organisms and other pathogens in the treated water.10

Josep Carrasco MartínezAll the work of this thesis has been developed about modelling of secondary treatment,and below it is showed the scheme of this treatment:Secondary treatmentSecondary settlerBiological reactorsPrimarytreatmentTertiarytretamentClear waterSludgeReturn activated sludgefigure 3: Layout for the secondary treatment in a continuous wastewater treatment plantWe can find in the secondary treatment the following mechanisms: HYDRAULICS: Wastewater flows through the treatment plant by the force ofgravity if it is possible, and pumping the wastewater to lift it from the sewer tothe plant inlet. The mechanisms which take part are the vessels, which areusually concrete tanks of various shapes and sizes with controlled levels, andpumps which are almost used to recycle mixed liquor and sludge and the smallsludge wastage streams.NUTRIENT REACTIONS: The biological reactions involved are: removal oforganic carbon, removal of nitrogen (nitrification and denitrification) andremoval of phosphorus. The reactions are showed below:Insoluble Carbonfigure 4: Nutrient ygenSoluble SNitrites / NitratesSoluble CarbonNitrogen GasHETEROTROPBIOMASSNITROGENREMOVALCarbon ATIONSoluble PhosphatesPolyphosphatnodulesSoluble CarbonDissolved P: Organismswhich have theremoved PHAnodules insidePAO: PhosphorusAccumulationgOrganismsPHA: PolyHidroxyAlkanoatesVFA: Volatile FattyAcidsPAO BiomassANAEROBIC PROCESS(PO4 release)AEROBIC PROCESS(PO4 uptake)PHOSPHORUSREMOVAL11

CHAPTER 2: Wastewater Treatment ProcessesCarbon removal and nitrogen removal are the most common process modelledand used in wastewater treatment. The first one is easily understood, but thecomplexity of nitrogen removal makes it was necessary a brief explanation of it.Predenitrification AS processMany modern treatment plants utilising AS have biological nitrogen removal.Biological nitrogen removal relies on nitrifying and denitrifying bacteria forremoval of nitrogen in two steps (as it is showed in figure 4): nitrification anddenitrification. Two different types of bacteria cultures are used to achievenitrification and denitrification:¾ autotrophic bacteria uses inorganic carbon as carbon source.¾ heterotrophic bacteria uses organic carbon as carbon source.In the nitrification step, ammonium is oxidised to nitrite and then nitrate(nitrification) by autotrophs. In the second step, nitrate is reduced to nitrogen gas(denitrification) by heterotrophs. A difficulty with this procedure is that the twosteps require different ambient conditions to function effectively. Thenitrification step needs dissolved oxygen, whereas the denitrification steprequires an oxygen free environment. A solution to this is to divide the reactionvolume into separate compartments in which the conditions are different.A relatively common configuration for nitrogen removal is the predenitrificationprocess. The first reactor is anoxic, that is no dissolved oxygen is present, and isfollowed by an aerated volume. This may appear somewhat backwards as thenitrification is done after the denitrification. However, the denitrification processrequires readily biodegradable organic substrate and this is normally present inthe influent wastewater. If the denitrificaiton has to take place after thenitrification (i.e. a post-denitrification configuration), most of the organicsubstrate will have been consumed and external carbon will have to be added.Thus, to provide the anoxic reactor with nitrate, a recirculation stream isintroduced from the last reactor to the first reactor (sometimes the sludgerecirculation is sufficient and no internal recirculation is needed).Internal nitrate recirculationAEROBICANOXICSludge recirculation12figure 5: Basic principle of thepredenitrificationconfiguration

Josep Carrasco Martínez CHEMICAL PRECIPITATION: Sometimes it is possible to remove the phosphorususing chemical precipitation instead of nutrient reactions; it is faster and moreeconomically favourable. This mechanism is made by the addition of aluminiumor iron compounds such as alum, pickle liquor, ferric hydroxide or ferricchloride. NUTRIENT MASS TRANSFER: this mechanism occurs in biological reactions andthe purpose is to get oxygen from gaseous air into water, and it is promoted instirred vessels. BIOMASS GROWTH: It means the maintenance of the right proportions ofdifferent species of organisms within the sludge in an active state. The aim is toavoid the growth of harmful organisms. SETTLING AND CLARIFICATION: Finally it takes part the separation of insolubleparticles form water. It is used the gravity force, thus the insoluble particleswhich are denser than the water go down the settler and they form the sludge(see figure 3).2.2 AUTOMATION IN WASTEWATER TREATMENT PLANTSOnline measuring and data collection systemsThe number of measurable entities increases as research on and development ofinstrumentation and sensors progress. A difficulty in online measuring is the aggressiveenvironment in which the sensors must function and that many of the interesting entitiesmust be derived from reaction analysis in batch or continuous experiments.Interesting development in the sensor area involves new types of sensors such as sensorarrays or soft sensors, where variables are deduced from a number of measurements,biosensors that utilise (immobilised) cultures of bacteria, and microbial sensors formeasuring inhibitors and substrates.In the last few years, a wide variety of biosensors have been developed. Within thislarge field, microbial sensors stand out because of their multi-receptor behaviour. Infact, these results in rather poor selectivity, but a great variety of substances can bedetected simultaneously with one sensor. It is for this reason that microbial sensors arepreferred for measuring environmentally relevant summary parameters (such asBiochemical Oxygen Demand) or for detecting inhibiting and toxic effects.Compared to enzyme sensors, their higher stability and lower production costs areadditional arguments for using microbial sensors for environmental analyses.With rapid, direct, and exact detection of these parameters with microbial sensors, itwill be possible to make the momentary situation in a water or wastewater streamvisible. This results in new possibilities for the control of sewage plants.The data collecting systems differ from plant to plant and from supplier to supplier butcommon sampling rates (in Sweden) are 10 and 12 per hour, i.e. every sixth and fifthminute, respectively. The sample values are often an average over the sampling period,during which some sensors continuously deliver values and others perhaps only once a13

CHAPTER 2: Wastewater Treatment Processesminute. All sensors are afflicted with time lags, but normally these are short incomparison to the dominant time constants of the process.The most often measurements in wastewater treatment are aerobic growth ofheterotrophs, anoxic growth of heterotrophs, aerobic growth of autotrophs, ‘decay’ ofheterotrophs, ‘decay’ of autotrophs, ammonification of soluble organic nitrogen,‘hydrolysis’ of entrapped organics and ‘hydrolysis’ of entrapped organic nitrogen inbiological processes, and settler velocity, suspend solids concentration, feed volumetricflow rate, effluent volumetric flow rate and underflow volumetric flow rate in settlerprocesses.Control handlesThere are limitations to what can be controlled in a wastewater treatment plant. This isdue to a lack of powerful control handles in comparison to the relatively severedisturbances that varying influent wastewater characteristics impose on the system.A majority of the manipulated variables are macro variables (DO and some of thechemical additions excepted) whereas some of the major

The problem rises when the control strategy is not the suitable. The biological processes dynamic is really slow, a time constant of days, even weeks some times. Hence, it is possible to know when a control strategy is wrong after days or weeks, and then, is too late to try to control the process and one more week is needed to test another control