P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome ii P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome BUILDING SOFTWARE FOR SIMULATION i P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome ii P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome BUILDING SOFTWARE FOR SIMULATION Theory and Algorithms, with Applications in C++ JAMES J. NUTARO OakRidgeNationalLaboratory AJOHNWILEY&SONS,INC.,PUBLICATION iii P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome Copyright(cid:1)C 2011byJohnWiley&Sons,Inc.Allrightsreserved. PublishedbyJohnWiley&Sons,Inc.,Hoboken,NewJersey. PublishedsimultaneouslyinCanada. Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedinanyformor byanymeans,electronic,mechanical,photocopying,recording,scanning,orotherwise,exceptas permittedunderSection107or108ofthe1976UnitedStatesCopyrightAct,withouteithertheprior writtenpermissionofthePublisher,orauthorizationthroughpaymentoftheappropriateper-copyfeeto theCopyrightClearanceCenter,Inc.,222RosewoodDrive,Danvers,MA01923,(978)750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission shouldbeaddressedtothePermissionsDepartment,johnWiley&Sons,Inc.,111RiverStreet,Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission. LimitofLiability/DisclaimerofWarranty:Whilethepublisherandauthorhaveusedtheirbesteffortsin preparingthisbook,theymakenorepresentationsorwarrantieswithrespecttotheaccuracyor completenessofthecontentsofthisbookandspecificallydisclaimanyimpliedwarrantiesof merchantabilityorfitnessforaparticularpurpose.Nowarrantymaybecreatedorextendedbysales representativesorwrittensalesmaterials.Theadviceandstrategiescontainedhereinmaynotbesuitable foryoursituation.Youshouldconsultwithaprofessionalwhereappropriate.Neitherthepublishernor authorshallbeliableforanylossofprofitoranyothercommercialdamages,includingbutnotlimitedto special,incidental,consequential,orotherdamages. Forgeneralinformationonourotherproductsandservicesorfortechnicalsupport,pleasecontactour CustomerCareDepartmentwithintheUnitedStatesat(800)762-2974,outsidetheUnitedStatesat(317) 572-3993orfax(317)572-4002. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmay notbeavailableinelectronicformat.FormoreinformationaboutWileyproducts,visitourwebsiteat www.wiley.com. LibraryofCongressCataloging-in-PublicationData: Nutaro,JamesJ. Buildingsoftwareforsimulation:theoryandalgorithmswithapplicationsinC++/JamesJ.Nutaro p.cm. Includesbibliographicalreferencesandindex. ISBN978-0-470-41469-9(cloth) PrintedintheUnitedStatesofAmerica 10 9 8 7 6 5 4 3 2 1 iv P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome CONTENTS PREFACE ix 1 INTRODUCTION 1 1.1 ElementsofaSoftwareArchitecture / 2 1.2 SystemsConceptsasanArchitecturalFoundation / 4 1.3 Summary / 5 1.4 OrganizationoftheBook / 6 2 FIRSTEXAMPLE:SIMULATINGAROBOTICTANK 7 2.1 FunctionalModeling / 8 2.2 ARoboticTank / 9 2.2.1 EquationsofMotion / 11 2.2.2 Motors,Gearbox,andTracks / 13 2.2.3 CompleteModeloftheTank’sContinuousDynamics / 17 2.2.4 TheComputer / 18 2.2.5 CompleteModeloftheTank / 22 2.3 DesignoftheTankSimulator / 23 2.4 Experiments / 25 2.5 Summary / 30 3 DISCRETE-TIMESYSTEMS 32 3.1 AtomicModels / 33 v P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome vi CONTENTS 3.1.1 Trajectories / 33 3.1.2 TheStateTransitionandOutputFunction / 35 3.1.3 TwoExamplesofAtomic,Discrete-TimeModels / 39 3.1.4 SystemswithBagsforInputandOutput / 42 3.1.5 ASimulatorforAtomicModels / 42 3.2 NetworkModels / 53 3.2.1 ThePartsofaNetworkModel / 54 3.2.2 TheResultantofaNetworkModel / 55 3.2.3 AnExampleofaNetworkModelandItsResultant / 56 3.2.4 SimulatingtheResultant / 61 3.3 ASimulatorforDiscrete-TimeSystems / 77 3.4 Mealy/Moore-TypeSystems / 89 3.5 CellularAutomata / 91 3.6 Summary / 98 4 DISCRETE-EVENTSYSTEMS 100 4.1 AtomicModels / 101 4.1.1 TimeandTrajectories / 101 4.1.2 TheStateTransitionFunction / 103 4.1.3 TheOutputFunction / 105 4.1.4 LegitimateSystems / 106 4.1.5 AnExampleofanAtomicModel / 107 4.1.6 TheInterruptHandlerintheRoboticTank / 110 4.1.7 SystemswithBagsforInputandOutput / 114 4.1.8 ASimulatorforAtomicModels / 114 4.1.9 SimulatingtheInterruptHandler / 118 4.2 NetworkModels / 125 4.2.1 ThePartsofaNetworkModel / 125 4.2.2 TheResultantofaNetworkModel / 126 4.2.3 AnExampleofaNetworkModelandItsResultant / 128 4.2.4 SimulatingtheResultant / 132 4.3 ASimulatorforDiscrete-EventSystems / 143 4.3.1 TheEventSchedule / 144 4.3.2 TheBag / 153 4.3.3 TheSimulationEngine / 157 4.4 TheComputerintheTank / 170 4.5 CellularAutomataRevisited / 176 4.6 Summary / 180 P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome CONTENTS vii 5 HYBRIDSYSTEMS 182 5.1 AnElementaryHybridSystem / 185 5.2 NetworksofContinuousSystems / 186 5.3 HybridModelsasDiscrete-EventSystems / 187 5.4 NumericalSimulationofHybridSystems / 190 5.5 ASimulatorforHybridSystems / 198 5.6 InteractiveSimulationoftheRoboticTank / 211 5.6.1 CorrectingtheDynamicsofaTurn / 211 5.6.2 ASimplifiedModeloftheMotor / 213 5.6.3 UpdatingtheDisplay / 218 5.6.4 ImplementingtheTankPhysics / 219 5.7 ApproximatingContinuousInteractionBetweenHybridModels / 225 5.8 AFinalCommentonCellularAutomata / 229 5.8.1 DifferentialAutomatawithConstantDerivatives / 229 5.8.2 ModelingAsynchronousCellularAutomatawith DifferentialAutomata / 230 5.8.3 AHomomorphismfromDifferentialAutomatato AsynchronousCellularAutomata / 232 5.9 Summary / 236 6 APPLICATIONS 237 6.1 ControlThroughaPacket-SwitchedNetwork / 237 6.1.1 ModelofthePendulumandItsPIDController / 238 6.1.2 IntegrationwithanEthernetSimulator / 244 6.1.3 Experiments / 249 6.2 FrequencyRegulationinanElectricalPowerSystem / 255 6.2.1 Generation / 257 6.2.2 TransmissionNetworkandElectricalLoads / 259 6.2.3 FrequencyMonitoringandLoadActuation / 260 6.2.4 SoftwareImplementation / 261 6.2.5 Experiments / 262 6.3 Summary / 269 7 THEFUTURE 271 7.1 SimulationProgrammingLanguages / 271 7.2 ParallelComputingandDiscrete-EventSimulation / 273 7.3 TheManyFormsofDiscreteSystemsandTheirSimulators / 276 7.4 OtherFacetsofModelingandSimulation / 277 P1:OSO fm JWBS040-Nutaro August30,2010 14:35 PrinterName:YettoCome viii CONTENTS APPENDIXA DESIGNANDTESTOFSIMULATIONS 279 A.1 DecomposingaModel / 280 A.1.1 Bottom-UpTesting / 280 A.1.2 InvariantsandAssertions / 281 A.2 InputandOutputObjects / 281 A.2.1 SimpleStructures / 282 A.2.2 Unions / 282 A.2.3 PointersandHierarchiesofEvents / 284 A.2.4 MixingStrategieswithModelWrappers / 286 A.3 ReducingExecutionTime / 291 APPENDIXB PARALLELDISCRETEEVENTSIMULATION 296 B.1 AConservativeAlgorithm / 298 B.1.1 Lookahead / 300 B.1.2 TheAlgorithm / 303 B.2 ImplementingtheAlgorithmwithOpenMP / 304 B.2.1 Pragmas,Volatiles,andLocks / 304 B.2.2 OverviewoftheSimulator / 308 B.2.3 TheLogicalProcess / 309 B.2.4 TheMessageQ / 318 B.2.5 TheParSimulator / 321 B.3 DemonstrationofGustafson’sandAmdahl’sLaws / 325 APPENDIXC MATHEMATICALTOPICS 331 C.1 SystemHomomorphisms / 331 C.2 SinusoidalState-SteadyAnalysis / 333 REFERENCES 335 INDEX 345
Description: