├── LICENSE ├── README.md ├── capex.py ├── dsg.py ├── exampleruns.py └── opex.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChemEngDPpy 2 | Python code for mechanical design, sizing & capex/opex calculations 3 | 4 | The intention is to use these quickly as "black-box" functions for the purposes for TAC optimization in the 5 | detailed design of the main equipment (e.g. PFR wall thickness requirement, sizing of pumps/compressors etc.) 6 | 7 | - ***QUICK START***: 8 | 9 | - Download the required `.py` files directly to your project path; or 10 | 11 | - Use Git or checkout with SVN using the git URL. 12 | 13 | - Then, see `exampleruns.py` for usage examples (it's very intuitive) 14 | 15 | To use, download the required `.py` files into the same folder as your existing code, and call the following 16 | functions depending on your situation. 17 | 18 | Quick tips: 19 | 20 | - Always use the docstrings to check the required units to avoid unit conversion errors! 21 | 22 | - Use named arguments as far as possible to avoid ambiguities! 23 | 24 | ------------------------------------------------ 25 | 26 | ## Project Structure 27 | 28 | - dsg: For Mechanical Design & Ancillary Equipment Sizing 29 | 30 | - capex: For CAPEX Calculation and Reporting 31 | 32 | - opex: For OPEX Calculation and Reporting 33 | 34 | ------------------------------------------------ 35 | 36 | ## Implementation Methods 37 | 38 | Quick tip: Always use the docstrings to check the required units to avoid unit conversion errors, and use 39 | named arguments as far as possible to avoid ambiguities! 40 | 41 | Some definitions first: 42 | 43 | - ***Design inputs***: Properties that are critical and required to conduct equipment design/sizing 44 | 45 | - ***Design variables***: Properties that are determined after conducting equipment design/sizing 46 | 47 | - ***Additional tags***: Properties that are not critical to equipment design/sizing, 48 | but are important for the purposes of cost estimation. 49 | These can be supplied in the equipment object creation for ease of cost estimation later 50 | 51 | For example: 52 | 53 | - *Pressure* is a *design input* for vessels (to determine final shell thickness), 54 | a *design variable* for pumps/compressor (to determine power requirement), 55 | and is an *additional tag* for heat exchangers (to determine pressure factor) 56 | 57 | - *Volume* is a *design variable* for vessels, but is not relevant for other equipment categories 58 | 59 | - Operating temperature is a *design input* for vessels (to determine final shell thickness based on MOC properties), 60 | a *design input* for heat exchangers (to determine heat exchange area) 61 | a *design variable* for compressors (specifically the outlet temperature), 62 | and is not relevant to pumps (pump sizing in this library assumes negligible temperature change) 63 | 64 | There are two major methods for using this library: 65 | 66 | 1. ***Method 1 (scalar framework)***: Using scalar input - scalar output to retrieve only the key design variables; or 67 | 68 | 2. ***Method 2 (OOP framework)***: Using the library's object-oriented programming (OOP) framework. 69 | Generally, common chemical plant equipment (vessels, pumps, compressors, heat exchangers etc.) 70 | are also created as optional outputs and alternative inputs for the various functions. 71 | 72 | For example in equipment design, use: 73 | 74 | ```python 75 | # Method 1 (scalar framework) 76 | comppower, compeff, T2, _ = dsg.sizecompressor(m=1e5, P1=100, P2=300, T1=323.15, cp=1.02, cv=0.72, Z=0.99) 77 | ``` 78 | 79 | to just retrieve the power rating and temperature of the sized compressor as well as its estimated adiabatic efficiency 80 | (as in Method 1), or use: 81 | 82 | ```python 83 | # Method 2 (OOP framework) 84 | _, _, _, K100 = dsg.sizecompressor(m=1e5, P1=100, P2=300, T1=323.15, cp=1.02, cv=0.72, Z=0.99, 85 | etype='rotary', mat='CS', id='K400') 86 | ``` 87 | 88 | to create a `Compressor()` object containing all relevant design inputs (i.e. the inputs), design variables 89 | (i.e. `comppower`, `compeff` and `T2`) and additional tags. 90 | 91 | Additional tags can be supplied in the equipment object creation for ease of cost estimation later, such as: 92 | 93 | - `category` for **equipment category** (e.g. pumps, compressors etc. - automatically created when the respective 94 | `dsg.size(...)` or `dsg.design(...)` functions are called - see below or docstrings) 95 | 96 | - `etype` for **equipment type** (e.g. centrifugal pumps, rotary pumps etc. - see `capex` documentation below for 97 | list of supported chemical plant equipments) 98 | 99 | - `mat` for **material type** (e.g. carbon steel, stainless steel, cast iron etc. - see `capex` documentation 100 | below for list of supported material types) 101 | 102 | - `id` to specify an **equipment name** for semantic purposes 103 | 104 | - `P` to specify a designed operating pressure for equipment where pressure is neither a required design input 105 | nor a design variable. Most notably, this include heat exchangers whereby the pressure specification is only to 106 | determine the pressure factor `FP` for capital cost estimation of heat exchangers. 107 | 108 | Key exceptions to this include: 109 | 110 | - Mechanical design for pressure/vacuum vessels is *only* conducted using the OOP framework (Method 2), due the 111 | large number of critical design variables in the mechanical design. 112 | 113 | - For reactors and distillation columns, design the pressure/vacuum vessel and internals (e.g. distillation trays, 114 | mixers/impellers, packings) *separately* (i.e. as separate objects), as combined object support is not available yet (#TODO). 115 | 116 | - CAPEX reporting can *only* be conducted using the OOP framework (Method 2). 117 | 118 | As another example in capital cost estimation for equipment, use 119 | 120 | 1. *Method 1 (scalar framework)*: 121 | 122 | ```python 123 | # Method 1 (scalar framework) 124 | # manually supply cost coefficients, min/max capacity for validity range (optional), 125 | # exponential factor for extrapolation (optional)... 126 | capex.eqptpurcost(A=20, Ktuple=(3.5565, 0.3776, 0.0905, 0.1, 628., 0.5)) 127 | # ... or just retrieve from capex.eqptcostlib 128 | capex.eqptpurcost(A=20, Ktuple=capex.eqptcostlib['vessel']['horizontal']) 129 | ``` 130 | 131 | to size a horizontal vessel of volume `A` = 20 m^3, and then calling all the subsequent functions in order (see `capex` 132 | documentation). However, using 133 | 134 | 2. *Method 2 (OOP framework)*: 135 | 136 | ```python 137 | # Method 2 (OOP framework) 138 | capex.eqptpurcost(eqpt=V100) 139 | ``` 140 | 141 | , where `V100` is the output (a `MechDesign()` object in this context) retrieved from `dsg.designvertpres`, 142 | is so much easier. 143 | 144 | In fact, using the OOP framework (Method 2), we can just create a list of all the relevant 145 | equipment objects and perform the entire capex estimation directly: 146 | 147 | ```python 148 | eqptlist = [V100, V200, V300, K400, K500, P600, P700, HX800, HX900] 149 | FCI, capexreport = capex.econreport(eqptlist, planttype='green', pbp=3, year=2019, currency='SGD', \ 150 | reporttype='numpy', verbose=True) 151 | ``` 152 | 153 | See `exampleruns.py` for more sample implementations. 154 | 155 | Further possible uses of the OOP framework (Method 2) could be to: 156 | 157 | - Perform optimization on equipment type or material selection, 158 | using the tags `etype`, `mat` etc. as categorical decision variables for capex minimization 159 | 160 | - Determine the best type of heat exchanger and utilities to use by minizing both capex and opex. This is similar 161 | to above, with utilities selection being an additional categorical decision variable which influences both 162 | heat exchange area and cost of utilities. 163 | 164 | - Find the optimal configuration for multi-stage compression with minimal electricity consumption and stream cooling, 165 | using the number of compressors, compression ratios, heat exchange area for cooling etc. as decision variables. 166 | 167 | However, this implementation is left to the user to do. (#TODO add examples) 168 | 169 | ------------------------------------------------ 170 | 171 | ## Mechanical Design & Ancillary Equipment Sizing - dsg 172 | 173 | Constants: 174 | 175 | - `dsg.Patm` = 14.696 - standard atmospheric pressure (psi) 176 | 177 | - `dsg.Patmb` = 1.01325 - standard atmospheric pressure (bar) 178 | 179 | - `dsg.Troom` = 77 - ambient temperature (degF) 180 | 181 | - `dsg.tmin` = 1/4 - universal minimum allowable vessel thickness (in) 182 | 183 | - `dsg.tc` = 0.125 - corrosion allowance (in) for both corrosive and non-corrosive conditions (default is 1/8) 184 | 185 | - `dsg.rhosteel` = 0.2836 - density of SA-285C/SA-387B/carbon/low-alloy steels (lb/in^3) 186 | 187 | - `dsg.g` = 9.80665 - standard Earth gravitational acceleration (m/s^2) 188 | 189 | - `dsg.R` = 8.31446261815324 - universal ideal gas constant (J/(K.mol)) 190 | 191 | - `dsg.Ta` = 10. - minimum heat exchanger temperature approach (K) 192 | 193 | Functions: 194 | 195 | - `dsg.designhorzpres` - perform entire mechanical design for horizontal pressure vessels 196 | 197 | - `dsg.designvertpres` - perform entire mechanical design for vertical pressure vessels 198 | 199 | - `dsg.designvac` - perform entire mechanical design for vacuum vessels 200 | 201 | - `dsg.sizecompressor` - conducts compressor sizing 202 | 203 | - `dsg.sizepump` - conducts pump sizing 204 | 205 | - `dsg.sizeHE_heater` - conducts heat exchanger sizing for heating stream 206 | 207 | - `dsg.sizeHE_cooler` - conducts heat exchanger sizing for cooling stream 208 | 209 | To call intermediate functions (e.g. calculate shell thickness, calculate max. allowable stress, calculate wind 210 | allowance etc.), refer to documentation within code. 211 | 212 | ------------------------------------------------ 213 | 214 | ## CAPEX Calculation - capex 215 | 216 | Constants: 217 | 218 | - `capex.CEPCI[20yy]` - retrieves annual CEPCI index for 20yy (where yy = 01, 18 or 19) 219 | 220 | - `capex.USSG[20yy]` - retrieves USD:SGD forex rate for 20yy year-average (where yy = 01, 18 or 19) 221 | 222 | - `capex.CPI['zz'][20yy]` - retrieves country zz's consumer price index (CPI) for 20yy year-average 223 | (where yy = 01, 16, 18 or 19 and zz = 'SG' or 'US') 224 | 225 | - Reference year for CAPCOST = 2001 (as of Turton et al. 5th Ed.) 226 | 227 | - Reference year for utilities cost = 2016 (as of Turton et al. 5th Ed.) 228 | 229 | - `capex.eqptcostlib['eqptcategory']['eqpttype']` - retrieves a tuple of equipment cost correlation parameters 230 | `(K1, K2, K3, Amin, Amax, n)` where `(K1, K2, K3)` = cost correlation params, `(Amin, Amax)` = min/max capacity 231 | (range of validity), and `n` = cost exponent used in the exponential costing rule, from which the 232 | purchased equipment cost `Cpo` can then be calculated. 233 | 234 | - `capex.pressurefaclib['eqptcategory']['eqpttype']` - retrieves a tuple of equipment pressure factor correlation parameters 235 | `(C1, C2, C3, Pmin, Pmax)` where `(C1, C2, C3)` = pressure factor correlation params, and `(Pmin, Pmax)` = min/max pressure 236 | (range of validity), from which the pressure factor `FP` can then be calculated. 237 | 238 | - `capex.matfaclib['eqptcategory']['eqpttype']['mat']` - retrieves equipment material factor `FM` (a float) 239 | 240 | - `capex.baremodlib['eqptcategory']['eqpttype']` - retrieves a tuple of equipment bare module correlation parameters 241 | `(B1, B2)`, such that the bare module factor `FBM = B1 + B2 * FP * FM`. 242 | 243 | Supported equipment categories, types and materials (`mat`): 244 | 245 | - `compressor` 246 | - `centrifugal`, `axial`, `reciprocating`, `rotary` 247 | - `CS` (carbon steel) 248 | - `SS` (stainless steel) 249 | - `Ni` (nickel alloy) 250 | 251 | - `pump` 252 | - `reciprocating`, `positivedisp` 253 | - `Fe` (cast iron) 254 | - `CS` 255 | - `SS` 256 | - `Ni` 257 | - `Ti` (titanium alloy) 258 | - `centrifugal` 259 | - `Fe` 260 | - `CS` 261 | - `SS` 262 | - `Ni` 263 | 264 | - `heatexc` 265 | - `fixedtube`, `utube`, `kettle`, `doublepipe`, `multipipe` 266 | - `CS/CS` 267 | - `CS/SS` and `SS/CS` (shell/tube order does not matter) 268 | - `SS/SS` 269 | - `CS/Ni` and `Ni/CS` 270 | - `Ni/Ni` 271 | - `CS/Ti` and `Ti/CS` 272 | - `Ti/Ti` 273 | 274 | - `vessel` 275 | - `horizontal`, `vertical` 276 | - `CS` 277 | - `SS` 278 | - `Ni` 279 | - `Ti` 280 | 281 | - `trays` 282 | - `sieve`, `valve` 283 | - `CS` 284 | - `SS` 285 | - `Ni` 286 | - `demister` 287 | - `SS` 288 | - `FC` (fluorocarbon) 289 | - `Ni` 290 | 291 | Functions: 292 | 293 | - `capex.eqptpurcost` - calculates purchased equipment cost (`Cpo`) 294 | 295 | - `capex.pressurefacves` - calculates pressure factor for vessels (`FP`) 296 | 297 | - `capex.pressurefacanc` - calculates pressure factor for ancillary equipment (`FP`) 298 | 299 | - `capex.baremodfac` - calculates bare module factor (`FBM`) 300 | 301 | - `capex.baremodcost` - calculates bare module cost (`CBM`) 302 | 303 | - `capex.totmodcost` - calculates total module cost (`CTM`) 304 | 305 | - `capex.grasscost` - calculates grassroots cost (`CGR`) 306 | 307 | - `capex.annualcapex` - calculates total annualised capital cost estimated (`ACC`), 308 | based on an assumed payback period (`pbp`). If a value of pbp is assumed, note that this should only be 309 | used for ACC estimation for optimization purposes! Alternatively, calculate pbp based on projected revenue estimates. 310 | 311 | ------------------------------------------------ 312 | 313 | ## OPEX Calculation - opex 314 | 315 | Constants: 316 | 317 | - `opex.SF` - retrieves stream factor for plant operation 318 | 319 | - `opex.runtime` - retrieves operational runtime per annum 320 | 321 | - `opex.shiftdur` - retrieves duration of one workshift 322 | 323 | - `opex.shiftperweek` - retrieves number of shifts per year 324 | 325 | - `opex.yearww` - retrieves number of work weeks per year after leave entitlements 326 | 327 | - `opex.util['xxx']` - utility cost for xxx (USD/GJ basis), where xxx = 328 | 329 | - `"HPS"` for high-pressure steam (41 barg, 254 degC) 330 | 331 | - `"MPS"` for medium-pressure steam (10 barg, 184 degC) 332 | 333 | - `"LPS"` for low-pressure steam (5 barg, 160 degC) 334 | 335 | - `"CW"` for cooling water (30-45 degC) 336 | 337 | - `"ChW"` for chilled water (5 degC) 338 | 339 | - `"LTR"` for low temperature refrigerant (-20 degC) 340 | 341 | - `"VLTR"` for very low temperature refrigerant (-50 degC) 342 | 343 | - `"elec"` for electricity (110-440 V) 344 | 345 | Functions: 346 | 347 | - `opex.labourcost` - calculates annualised labour cost (`COL`) 348 | 349 | - `opex.costofraw` - calculates annualised cost of raw materials (`CRM`) 350 | 351 | - `opex.costofutil` - calculates annualised cost of utilities (`CUT`) 352 | 353 | - `opex.costofwaste` - (placeholder function for user's customised waste treatment calculation) 354 | 355 | - `opex.costofmanfc` - calculates all components of annualised total cost of manufacture (`COM`) 356 | 357 | To call intermediate functions (e.g. calculate number of operators per shift etc.), refer to documentation within code. -------------------------------------------------------------------------------- /capex.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import dsg 3 | import warnings 4 | import time 5 | from typing import Tuple, Any, List 6 | 7 | # CEPCI Index 8 | # To access, e.g. CEPCI[2019] 9 | CEPCI = { 10 | 2019: 607.5, 11 | 2018: 603.1, 12 | 2001: 394.3 13 | } 14 | 15 | # USD to SGD forex rate (annualised average) 16 | # To access, e.g. USSG[2019] 17 | USSG = { 18 | 2019: 1.3493, 19 | 2018: 1.3912, 20 | 2001: 1.7912 21 | } 22 | 23 | # Consumer price index 24 | # To access, e.g. CPI['SG'][2019] 25 | CPI = { 26 | 'SG': { # SG benchmark 2010 = 100 27 | 2019: 115.0, 28 | 2018: 113.8, 29 | 2016: 112.6, 30 | 2001: 86.05 31 | }, 32 | 'US': { # US benchmark 1983 = 100 33 | 2019: 257.0, 34 | 2018: 251.2, 35 | 2016: 240.0, 36 | 2001: 176.7 37 | } 38 | } 39 | 40 | 41 | # Equipment cost correlation parameters 42 | # A tuple of (K1, K2, K3, Amin, Amax, n) 43 | # where (K1, K2, K3) = cost correlation params, (Amin, Amax) = min/max capacity (range of validity), n = cost exponent 44 | # To access, e.g. eqptcostlib['pump']['centrifugal'] 45 | eqptcostlib = { 46 | 'compressor': { 47 | 'centrifugal': (2.2897, 1.3604, -0.1027, 450., 3000., 0.67), 48 | 'axial': (2.2897, 1.3604, -0.1027, 450., 3000., 0.67), 49 | 'reciprocating': (2.2897, 1.3604, -0.1027, 450., 3000., 0.84), 50 | 'rotary': (5.0355, -1.8002, 0.8253, 18., 950., 0.6) 51 | }, 52 | 'pump': { 53 | 'reciprocating': (3.8696, 0.3161, 0.1220, .1, 200., 0.6), 54 | 'positivedisp': (3.4771, 0.1350, 0.1438, 1., 100., 0.6), 55 | 'centrifugal': (3.3892, 0.0536, 0.1538, 1., 300., 0.67), 56 | }, 57 | 'heatexc': { 58 | 'fixedtube': (4.3247, -0.3030, 0.1634, 10., 1000., 0.62), 59 | 'utube': (4.1884, -0.2503, 0.1974, 10., 1000., 0.53), 60 | 'kettle': (4.4646, -0.5277, 0.3955, 10., 1000., 0.59), 61 | 'doublepipe': (3.3444, 0.2745, -0.0472, 1., 10., 0.59), 62 | 'multipipe': (2.7652, 0.7282,0.0783, 10., 100., 0.6) 63 | }, 64 | 'vessel': { 65 | 'horizontal': (3.5565, 0.3776, 0.0905, 0.1, 628., 0.5), 66 | 'vertical': (3.4974, 0.4485, 0.1074, 0.3, 520., 0.6) 67 | }, 68 | 'trays': { 69 | 'sieve': (2.9949, 0.4465, 0.3961, 0.7, 12.3, 0.86), 70 | 'valve': (3.3322, 0.4838, 0.3434, 0.7, 10.5, 1.0), 71 | 'demister': (3.2353, 0.4838, 0.3434, 0.7, 10.5, 1.0) 72 | }, 73 | 'mixer': { 74 | 'impeller': (3.8511, 0.7009, -0.0003, 5., 150., 0.6), 75 | 'propeller': (4.3207, 0.0359, 0.1346, 5., 500., 0.5), 76 | 'turbine': (3.4092, 0.4896, 0.0030, 5., 150., 0.3) 77 | } 78 | } 79 | 80 | 81 | # Equipment pressure factor correlation parameters 82 | # A tuple of (C1, C2, C3, Pmin, Pmax) 83 | # where (C1, C2, C3) = pressure factor correlation params, (Pmin, Pmax) = min/max pressure (range of validity) 84 | # To access, e.g. pressurefaclib['pump']['centrifugal'] 85 | pressurefaclib = { 86 | 'compressor': { 87 | 'centrifugal': (0., 0., 0., -np.inf, np.inf), 88 | 'axial': (0., 0., 0., -np.inf, np.inf), 89 | 'reciprocating': (0., 0., 0., -np.inf, np.inf), 90 | 'rotary': (0., 0., 0., -np.inf, np.inf) 91 | }, 92 | 'pump': { 93 | 'reciprocating': (-0.245382, 0.259016, -0.01363, 10., 100.), 94 | 'positivedisp': (-0.245382, 0.259016, -0.01363, 10., 100.), 95 | 'centrifugal': (-0.3935, 0.3957, -0.00226, 10., 100.), 96 | }, 97 | 'heatexc': { 98 | 'fixedtube': (0.03881, -0.11272, 0.08183, 5., 140.), 99 | 'utube': (0.03881, -0.11272, 0.08183, 5., 140.), 100 | 'kettle': (0.03881, -0.11272, 0.08183, 5., 140.), 101 | 'doublepipe': (0.6072, -0.9120, 0.3327, 40., 100.), 102 | 'multipipe': (0.6072, -0.9120, 0.3327, 40., 100.) 103 | }, # use the pressure factor equation for vessels instead 104 | 'trays': { 105 | 'sieve': (0., 0., 0., -np.inf, np.inf), 106 | 'valve': (0., 0., 0., -np.inf, np.inf), 107 | 'demister': (0., 0., 0., -np.inf, np.inf) 108 | }, 109 | 'mixer': { 110 | 'impeller': (0., 0., 0., -np.inf, np.inf), 111 | 'propeller': (0., 0., 0., -np.inf, np.inf), 112 | 'turbine': (0., 0., 0., -np.inf, np.inf) 113 | } 114 | } 115 | 116 | 117 | # Equipment material factors 118 | # To access, e.g. matfaclib['pump']['centrifugal']['SS'] 119 | matfaclib = { 120 | 'compressor': { 121 | 'centrifugal': { 122 | 'CS': 2.8, # CS = carbon steel 123 | 'SS': 5.8 / 2.8, # SS = stainless steel 124 | 'Ni': 11.5 / 2.8 # Ni = nickel alloy 125 | }, 126 | 'axial': { 127 | 'CS': 3.8, 128 | 'SS': 8.0 / 3.8, 129 | 'Ni': 15.9 / 3.8 130 | }, 131 | 'reciprocating': { 132 | 'CS': 3.4, 133 | 'SS': 7.0 / 3.4, 134 | 'Ni': 13.9 / 3.4 135 | }, 136 | 'rotary': { 137 | 'CS': 2.4, 138 | 'SS': 5.0 / 2.4, 139 | 'Ni': 9.9 / 2.4 140 | } 141 | }, 142 | 'pump': { 143 | 'reciprocating': { 144 | 'Fe': 1.0, # Fe = cast iron 145 | 'CS': 1.5, 146 | 'SS': 2.4, 147 | 'Ni': 4.0, 148 | 'Ti': 6.5 # Ti = titanium alloy 149 | }, 150 | 'positivedisp': { 151 | 'Fe': 1.0, 152 | 'CS': 1.4, 153 | 'SS': 2.7, 154 | 'Ni': 4.7, 155 | 'Ti': 10.7 156 | }, 157 | 'centrifugal': { 158 | 'Fe': 1.0, 159 | 'CS': 1.6, 160 | 'SS': 2.3, 161 | 'Ni': 4.4 162 | } 163 | }, 164 | 'heatexc': { 165 | HXtype: { 166 | 'CS/CS': 1.0, 167 | 'CS/SS': 1.8, 168 | 'SS/CS': 1.8, # duplicate 169 | 'SS/SS': 2.9, 170 | 'CS/Ni': 2.8, 171 | 'Ni/CS': 2.8, # duplicate 172 | 'Ni/Ni': 3.8, 173 | 'CS/Ti': 4.6, 174 | 'Ti/CS': 4.6, # duplicate 175 | 'Ti/Ti': 11.4 176 | } 177 | for HXtype in ['fixedtube', 'utube', 'kettle', 'doublepipe', 'multipipe'] 178 | }, 179 | 'vessel': { 180 | vestype: { 181 | 'CS': 1.0, 182 | 'SS': 3.1, 183 | 'Ni': 7.1, 184 | 'Ti': 9.4 185 | } 186 | for vestype in ['horizontal', 'vertical'] 187 | }, 188 | 'trays': { 189 | 'sieve': { 190 | 'CS': 1.0, 191 | 'SS': 1.8, 192 | 'Ni': 5.6 193 | }, 194 | 'valve': { 195 | 'CS': 1.0, 196 | 'SS': 1.8, 197 | 'Ni': 5.6 198 | }, 199 | 'demister': { 200 | 'SS': 1.0, 201 | 'FC': 1.8, # FC = fluorocarbon 202 | 'Ni': 5.6 203 | } 204 | } 205 | } 206 | 207 | # Equipment bare module correlation parameters 208 | # A tuple of (B1, B2) 209 | # where (B1, B2) = bare module correlation params 210 | # To access, e.g. baremodlib['pump']['centrifugal'] 211 | baremodlib = { 212 | 'compressor': { # FBM = (B2 for CS) * FM = (B2 for CS) * (B2 for material / B2 for CS) 213 | 'centrifugal': (0., 2.8), 214 | 'axial': (0., 3.8), 215 | 'reciprocating': (0., 3.4), 216 | 'rotary': (0., 2.4) 217 | }, 218 | 'pump': { # FBM = B1 + B2 * FM * FP 219 | 'reciprocating': (1.89, 1.35), 220 | 'positivedisp': (1.89, 1.35), 221 | 'centrifugal': (1.89, 1.35), 222 | }, 223 | 'heatexc': { # FBM = B1 + B2 * FM * FP 224 | 'fixedtube': (1.63, 1.66), 225 | 'utube': (1.63, 1.66), 226 | 'kettle': (1.63, 1.66), 227 | 'doublepipe': (1.74, 1.55), 228 | 'multipipe': (1.74, 1.55) 229 | }, 230 | 'vessel': { # FBM = B1 + B2 * FM * FP 231 | 'horizontal': (1.49, 1.52), 232 | 'vertical': (2.25, 1.82) 233 | }, 234 | 'trays': { # FBM = FM for trays. Assuming tray quantity factor Fq = 1. 235 | 'sieve': (0., 1.), 236 | 'valve': (0., 1.), 237 | 'demister': (0., 1.) 238 | }, 239 | 'mixer': { # FBM = 1.38 (constant) 240 | 'impeller': (1.38, 0.), 241 | 'propeller': (1.38, 0.), 242 | 'turbine': (1.38, 0.) 243 | } 244 | } 245 | 246 | 247 | def eqptpurcost(A: float=None, Ktuple: Tuple[float]=None, eqpt: Any=None) -> (float, Any): 248 | 249 | """ 250 | Calculate equipment purchased cost (Cp^o) cost at ambient pressure and using carbon steel as MOC 251 | Two methods of calculation: 252 | Method 1 - Specify A and Ktuple manually: 253 | :param A: equipment capacity (various units) 254 | :param Ktuple: tuple of cost correlation factors (K1, K2, K3, Amin [optional], Amax [optional], n [optional]) 255 | Optional inputs within Ktuple refer to minimum/maximum capacity and exponential factor respectively 256 | :return: Cpo: equipment purchased cost ($) 257 | Method 2 - Specify the equipment object directly 258 | :param eqpt: equipment object as generated by the dsg.size(...) or dsg.design(...) functions 259 | :return: Cpo: equipment purchased cost ($) 260 | :return: eqpt: the same equipment object with Cpo updated 261 | """ 262 | 263 | # Method 1 - Specify A and Ktuple manually 264 | if A is not None and Ktuple is not None: 265 | pass 266 | 267 | # Method 2 - Specify the equipment object directly 268 | elif eqpt is not None: 269 | # For vessel convert in^3 to m^3 270 | try: 271 | A = eqpt.comppower if eqpt.category is 'compressor' \ 272 | else eqpt.pumppower if eqpt.category is 'pump' \ 273 | else eqpt.area if eqpt.category is 'heatexc' \ 274 | else (eqpt.Vi*1.639e-5) if eqpt.category is 'vessel' \ 275 | else eqpt.area if eqpt.category is 'trays' \ 276 | else eqpt.mixerpower if eqpt.category is 'mixer' \ 277 | else None 278 | Ktuple = eqptcostlib[eqpt.category][eqpt.etype] 279 | except KeyError: 280 | raise KeyError('Equipment category and/or type (eqpt.category and/or eqpt.etype) not supported!') 281 | 282 | else: 283 | raise ValueError('Specify either (A + Ktuple) or eqpt!') 284 | 285 | if len(Ktuple) == 6: 286 | if A < Ktuple[3]: 287 | warnings.warn('Extrapolating {}={} below minimum capacity of {}! Switching to exponential rule!'.format(eqpt.id, A, Ktuple[3])) 288 | Cpo = pow(10., Ktuple[0] + Ktuple[1] * np.log10(Ktuple[3]) + Ktuple[2] * (np.log10(Ktuple[3])) ** 2) 289 | Cpo *= pow(A / Ktuple[3], Ktuple[5]) 290 | elif A > Ktuple[4]: 291 | warnings.warn('Extrapolating {}={} above maximum capacity of {}! Switching to exponential rule!'.format(eqpt.id, A, Ktuple[4])) 292 | Cpo = pow(10., Ktuple[0] + Ktuple[1] * np.log10(Ktuple[4]) + Ktuple[2] * (np.log10(Ktuple[4])) ** 2) 293 | Cpo *= pow(A / Ktuple[4], Ktuple[5]) 294 | else: 295 | Cpo = pow(10., Ktuple[0] + Ktuple[1] * np.log10(A) + Ktuple[2] * (np.log10(A)) ** 2) 296 | else: 297 | Cpo = pow(10., Ktuple[0] + Ktuple[1] * np.log10(A) + Ktuple[2] * (np.log10(A)) ** 2) 298 | 299 | if eqpt is None: 300 | return Cpo 301 | else: 302 | eqpt.Cpo = Cpo 303 | return Cpo, eqpt 304 | 305 | 306 | def pressurefacves(D: float=None, ts: float=None, P: float=None, eqpt: Any=None) -> (float, Any): 307 | 308 | """ 309 | Calculate pressure factor (F_P) for vessels 310 | Two methods of calculation: 311 | Method 1 - Specify D, ts and P manually: 312 | :param D: vessel internal diameter (m) 313 | :param ts: vessel thickness (in) 314 | :param P: pressure (barg) 315 | :return: FP: amplification factor for pressure 316 | Method 2 - Specify the equipment object directly: 317 | :param eqpt: equipment object as generated by the dsg.design(...) functions 318 | :return: FP: amplification factor for pressure 319 | :return: eqpt: the same equipment object with FP updated 320 | """ 321 | 322 | # Method 1 - Specify A and Ktuple manually 323 | if D is not None and ts is not None and P is not None: 324 | pass 325 | 326 | # Method 2 - Specify the equipment object directly 327 | elif eqpt is not None: 328 | 329 | if eqpt.category is not 'vessel': 330 | raise ValueError('Use pressurefacanc(P, Ctuple, eqpt) for ancillary equipment instead!') 331 | 332 | D = eqpt.Di / 39.37 # convert inch to m 333 | ts = eqpt.ts # in inch 334 | P = eqpt.Pd * 0.06895 # convert psig to barg 335 | 336 | if P < -0.5: 337 | FP = 1.25 338 | elif P > -0.5 and ts < dsg.tmin: 339 | FP = 1 340 | else: 341 | FP = max(((P+1)*D / (2*(850-0.6*(P+1))) + 0.00315) / 0.0063, 1) 342 | 343 | if eqpt is None: 344 | return FP 345 | else: 346 | eqpt.FP = FP 347 | return FP, eqpt 348 | 349 | 350 | def pressurefacanc(P: float=None, Ctuple: Tuple[float]=None, eqpt: Any=None) -> (float, Any): 351 | 352 | """ 353 | Calculate pressure factor (F_P) for ancillary equipment (e.g. pumps and exchangers) 354 | at specified elevated pressure and MOC 355 | Two methods of calculation: 356 | Method 1 - Specify P and Ctuple manually: 357 | :param P: pressure (barg) 358 | :param Ctuple: tuple of pressure correlation factors (C1, C2, C3, Pmin [optional], Pmax [optional]) 359 | Optional inputs within Ctuple refer to minimum/maximum pressure respectively 360 | :return: FP: amplification factor for pressure 361 | Method 2 - Specify the equipment object directly: 362 | :param eqpt: equipment object as generated by the dsg.design(...) functions 363 | :return: FP: amplification factor for pressure 364 | :return: eqpt: the same equipment object with FP updated 365 | """ 366 | 367 | # Method 1 - Specify P and Ctuple manually 368 | if P is not None and Ctuple is not None: 369 | pass 370 | 371 | # Method 2 - Specify the equipment object directly 372 | elif eqpt is not None: 373 | 374 | if eqpt.category is 'vessel': 375 | raise ValueError('Use pressurefacves(D, ts, P, eqpt) for vessels instead!') 376 | 377 | try: 378 | # Compressor: P2 in bar, but assume pressure doesn't affect bare module factor anyways 379 | # Pump: P2 in kPa 380 | # Heat Exchanger: P in bar 381 | # Vessel: Pd in psig, but vessel pressure calculations is not done here anyways 382 | # Trays: Assume 1 atm, dummy pressure because pressure doesn't affect bare module factor 383 | # Mixer: Assume 1 atm, dummy pressure because pressure doesn't affect bare module factor 384 | P = (eqpt.P2 - dsg.Patmb) if eqpt.category is 'compressor' \ 385 | else (eqpt.P2 - dsg.Patmb*100.)/100. if eqpt.category is 'pump' \ 386 | else (eqpt.P - dsg.Patmb) if eqpt.category is 'heatexc' \ 387 | else (eqpt.Pd * 0.06895) if eqpt.category is 'vessel' \ 388 | else dsg.Patmb if eqpt.category is 'trays' \ 389 | else dsg.Patmb if eqpt.category is 'mixer' \ 390 | else None 391 | Ctuple = pressurefaclib[eqpt.category][eqpt.etype] 392 | except KeyError: 393 | raise KeyError('Equipment category and/or type (eqpt.category and/or eqpt.etype) not supported!') 394 | 395 | else: 396 | raise ValueError('Specify either (P + Ctuple) or eqpt!') 397 | 398 | if len(Ctuple) == 5: 399 | if P < Ctuple[3]: 400 | warnings.warn('Equipment {} pressure={} below minimum pressure of {} for pressure factor correlation! Using FP = 1 instead!'.format(eqpt.id, P, Ctuple[3])) 401 | FP = 1. # borrowing quadratic-exponential relation 402 | elif P > Ctuple[4]: 403 | warnings.warn('Equipment {} pressure={} above maximum pressure of {} for pressure factor correlation! Using max P instead!'.format(eqpt.id, P, Ctuple[3])) 404 | FP = max(1., eqptpurcost(A=Ctuple[4], Ktuple=tuple(Ctuple[0:3]))) # borrowing quadratic-exponential relation 405 | else: 406 | FP = max(1., eqptpurcost(A=P, Ktuple=Ctuple[0:3])) # borrowing quadratic-exponential relation 407 | else: 408 | FP = max(1., eqptpurcost(A=P, Ktuple=Ctuple[0:3])) # borrowing quadratic-exponential relation 409 | 410 | if eqpt is None: 411 | return FP 412 | else: 413 | eqpt.FP = FP 414 | return FP, eqpt 415 | 416 | 417 | def baremodfac(Btuple: Tuple[float]=None, FM: float=None, FP: float=None, eqpt: Any=None) -> (float, Any): 418 | 419 | """ 420 | Calculate bare module factor (F_BM) at specified elevated pressure and MOC 421 | Two methods of calculation: 422 | Method 1 - Specify Btuple, FM and FP manually: 423 | :param Btuple: tuple of bare module correlation factors (B1, B2) 424 | :param FM: amplification factor for material of construction (MOC) 425 | :param FP: amplification factor for pressure 426 | :return: FBM: bare module factor (dimensionless) 427 | Method 2 - Specify the equipment object directly: 428 | :param eqpt: equipment object as generated by the dsg.design(...) or dsg.size(...) functions 429 | :return: FBM: bare module factor (dimensionless) 430 | :return: eqpt: the same equipment object with FBM updated 431 | """ 432 | 433 | # Method 1 - Specify Btuple, FM and FP manually 434 | if Btuple is not None and FM is not None and FP is not None: 435 | pass 436 | 437 | # Method 2 - Specify the equipment object directly 438 | elif eqpt is not None: 439 | try: 440 | Btuple = baremodlib[eqpt.category][eqpt.etype] 441 | FM = matfaclib[eqpt.category][eqpt.etype][eqpt.mat] 442 | if eqpt.category is 'vessel': 443 | FP, eqpt = pressurefacves(eqpt=eqpt) 444 | else: 445 | FP, eqpt = pressurefacanc(eqpt=eqpt) 446 | except KeyError: 447 | raise KeyError('Equipment category and/or type and/or material ' + 448 | '(eqpt.category and/or eqpt.etype and/or eqpt.mat) not supported!') 449 | 450 | else: 451 | raise ValueError('Specify either (Btuple + FM + FP) or eqpt!') 452 | 453 | FBM = max(1., Btuple[0] + Btuple[1] * FM * FP) 454 | 455 | if eqpt is None: 456 | return FBM 457 | else: 458 | eqpt.FBM = FBM 459 | eqpt.FM = FM 460 | return FBM, eqpt 461 | 462 | 463 | def baremodcost(Cpo=None, FBM=None, eqpt=None): 464 | 465 | """ 466 | Calculate bare module cost (CBM) at specified elevated pressure and MOC 467 | Two methods of calculation: 468 | Method 1 - Specify Cpo and FBM manually: 469 | :param Cpo: equipment purchased cost ($) 470 | :param FBM: bare module factor (dimensionless) 471 | :return: CBM: bare module cost ($) 472 | Method 2 - Specify the equipment object directly: 473 | :param eqpt: equipment object as generated by the dsg.design(...) or dsg.size(...) functions 474 | :return: CBM: bare module cost ($) 475 | :return: eqpt: the same equipment object with CBM updated 476 | """ 477 | 478 | # Method 1 - Specify Cpo and FBM manually: 479 | if Cpo is not None and FBM is not None: 480 | pass 481 | 482 | # Method 2 - Specify the equipment object directly: 483 | elif eqpt is not None: 484 | Cpo, eqpt = eqptpurcost(eqpt=eqpt) 485 | FBM, eqpt = baremodfac(eqpt=eqpt) 486 | 487 | else: 488 | raise ValueError('Specify either (Cpo + FBM) or eqpt!') 489 | 490 | CBM = FBM * Cpo 491 | 492 | if eqpt is None: 493 | return CBM 494 | else: 495 | eqpt.CBM = CBM 496 | return CBM, eqpt 497 | 498 | 499 | def totmodcost(CBM: float=None, eqpt: float=None) -> (float, Any): 500 | 501 | """ 502 | Calculate total module cost (CTM) at specified elevated pressure and MOC 503 | Two methods of calculation: 504 | Method 1 - Specify CBM manually: 505 | :param CBM: bare module cost ($) 506 | :return: CTM = total module cost ($) 507 | Method 2 - Specify the equipment object directly: 508 | :param eqpt: equipment object as generated by the dsg.design(...) or dsg.size(...) functions 509 | :return: CTM = total module cost ($) 510 | :return: eqpt: the same equipment object with CTM updated 511 | """ 512 | 513 | # Method 1 - Specify CBM manually: 514 | if CBM is not None: 515 | pass 516 | 517 | # Method 2 - Specify the equipment object directly: 518 | elif eqpt is not None: 519 | CBM, eqpt = baremodcost(eqpt=eqpt) 520 | 521 | else: 522 | raise ValueError('Specify either CBM or eqpt!') 523 | 524 | CTM = 1.18 * CBM 525 | 526 | if eqpt is None: 527 | return CTM 528 | else: 529 | eqpt.CTM = CTM 530 | return CTM, eqpt 531 | 532 | 533 | def grasscost(CTM: float=None, Cpo: float=None, eqpt: Any=None) -> (float, Any): 534 | 535 | """ 536 | Calculate grassroots cost (CGR) 537 | Two methods of calculation: 538 | Method 1 - Specify CTM and Cpo manually: 539 | :param CTM: total module cost ($) 540 | :param Cpo: purchased equipment cost at ambient pressure and carbon steel MOC ($) 541 | :return: CGR: grassroots cost ($) 542 | Method 2 - Specify the equipment object directly: 543 | :param eqpt: equipment object as generated by the dsg.design(...) or dsg.size(...) functions 544 | :return: CGR: grassroots cost ($) 545 | :return: eqpt: the same equipment object with CTM updated 546 | """ 547 | 548 | # Method 1 - Specify CTM and Cpo manually: 549 | if CTM is not None and Cpo is not None: 550 | pass 551 | 552 | # Method 2 - Specify the equipment object directly: 553 | elif eqpt is not None: 554 | CTM, eqpt = totmodcost(eqpt=eqpt) # this will update eqpt.Cpo too if all goes well 555 | Cpo = eqpt.Cpo 556 | 557 | else: 558 | raise ValueError('Specify either CBM or eqpt!') 559 | 560 | CGR = CTM + 0.5 * Cpo 561 | 562 | if eqpt is None: 563 | return CGR 564 | else: 565 | eqpt.CGR = CGR 566 | return CGR, eqpt 567 | 568 | 569 | def annualcapex(FCI: float=None, pbp: float=None, eqpt: Any=None, planttype: str='brown') -> (float, Any): 570 | 571 | """ 572 | Estimate total annualised capital cost based on assumed payback period 573 | Two methods of calculation: 574 | Method 1 - Specify FCI and pbp manually: 575 | :param FCI: fixed capital investment (= CTM or total module cost for brownfield projects, or =CGR or grassroots cost 576 | for greenfield projects) ($) 577 | :param pbp: payback period estimate (yr, default = 3). If a value of pbp is assumed, note that this should only be 578 | used for optimisation purposes! Alternatively, calculate pbp based on projected revenue estimates. 579 | :return: ACC: annualised capital cost estimate ($/yr) 580 | Method 2 - Specify eqpt directly, then pbp and planttype: 581 | :param eqpt: equipment object as generated by the dsg.design(...) or dsg.size(...) functions 582 | :param pbp: payback period estimate, as described in Method 1 583 | :param planttype: 'brown' for brownfield project (using CTM) or 'green' for greenfield project (using CGR) 584 | :return: ACC: annualised capital cost estimate ($/yr) 585 | """ 586 | 587 | if pbp is None: 588 | pbp = 3 589 | warnings.warn('Payback period (pbp) not specified - 3 years is assumed') 590 | 591 | if FCI is not None: 592 | pass 593 | 594 | elif eqpt is not None: 595 | if 'brown' in str.lower(planttype): 596 | _, eqpt = grasscost(eqpt=eqpt) 597 | FCI = eqpt.CTM 598 | elif 'green' in str.lower(planttype): 599 | FCI, eqpt = grasscost(eqpt=eqpt) 600 | else: 601 | raise ValueError('planttype should be \'brown\' for brownfield project (default) ' + 602 | 'or \'green\' for greenfield project!') 603 | 604 | ACC = FCI / pbp 605 | 606 | if eqpt is None: 607 | return ACC 608 | else: 609 | eqpt.ACC = ACC 610 | return ACC, eqpt 611 | 612 | 613 | def econreport(eqptlist: List[Any], planttype: str='green', reporttype: str='numpy', 614 | pbp: float=3., year: int=2019, currency: str='SGD', verbose: bool=False) -> (float, Any): 615 | 616 | """ 617 | Generates an economic capex report of the plant 618 | :param eqptlist: List of equipment objects as generated by the dsg.design(...) or dsg.size(...) functions 619 | :param planttype: Type of project ('green' for greenfield [default] or 'brown' for brownfield) 620 | :param reporttype: Data structure of report ('list' for 2D list, 'dict' for dictionary, or numpy for numpy array [default]) 621 | :param pbp: payback period estimate (yr, default = 3). If a value of pbp is assumed, note that this should only be 622 | used for optimisation purposes! Alternatively, calculate pbp based on projected revenue estimates. 623 | :param year: Year for CEPCI updating (integer, either 2001, 2018 or 2019 [default]) 624 | :param currency: Currency (string, either 'USD' or 'SGD' [default]) 625 | :param verbose: True to print economic capex report, False to print nothing [default] 626 | :return: report: The capex report formatted according to the reporttype input ('list', 'dict' or 'numpy') 627 | """ 628 | report_list = [['Equipment'], ['Purchased eqpt. cost (Cpo)'], ['Bare mod. cost (CBM)'], ['Total mod. cost (CTM)'], 629 | ['Grassroots cost (CGR)'], ['Annualised capital cost (ACC)']] 630 | report_dict = {eqpt.id: {'Cpo': None, 'CBM': None, 'CTM': None, 'CGR': None, 'ACC': None} for eqpt in eqptlist} 631 | report_dict['Total'] = {'Cpo': None, 'CBM': None, 'CTM': None, 'CGR': None, 'ACC': None} 632 | 633 | yearcurrfac = CEPCI[year] / CEPCI[2001] * (USSG[year] if currency is 'SGD' else 1.) 634 | 635 | for eqpt in eqptlist: 636 | ACC, eqpt = annualcapex(pbp=pbp, eqpt=eqpt, planttype=planttype) 637 | 638 | eqpt.Cpo = round(eqpt.Cpo * yearcurrfac, 2) 639 | eqpt.CBM = round(eqpt.CBM * yearcurrfac, 2) 640 | eqpt.CTM = round(eqpt.CTM * yearcurrfac, 2) 641 | eqpt.CGR = round(eqpt.CGR * yearcurrfac, 2) 642 | eqpt.ACC = round(eqpt.ACC * yearcurrfac, 2) 643 | 644 | i = list.index(eqptlist, eqpt) 645 | report_list[0].append(eqpt.id) 646 | report_list[1].append(eqpt.Cpo) 647 | report_list[2].append(eqpt.CBM) 648 | report_list[3].append(eqpt.CTM) 649 | report_list[4].append(eqpt.CGR) 650 | report_list[5].append(eqpt.ACC) 651 | 652 | report_dict[eqpt.id]['Cpo'] = eqpt.Cpo 653 | report_dict[eqpt.id]['CBM'] = eqpt.CBM 654 | report_dict[eqpt.id]['CTM'] = eqpt.CTM 655 | report_dict[eqpt.id]['CGR'] = eqpt.CGR 656 | report_dict[eqpt.id]['ACC'] = eqpt.ACC 657 | 658 | if verbose: 659 | time.sleep(0.1) 660 | print(eqpt.spec()) 661 | print(eqpt.econ()) 662 | 663 | report_list[0].append('Total') 664 | for i in range(1, 5+1): 665 | report_list[i].append(round(sum(report_list[i][1:len(eqptlist)+1]), 2)) 666 | 667 | report_numpy = np.array(report_list) 668 | 669 | report_dict['Total']['Cpo'] = round(sum([eqpt.Cpo for eqpt in eqptlist]), 2) 670 | report_dict['Total']['CBM'] = round(sum([eqpt.CBM for eqpt in eqptlist]), 2) 671 | report_dict['Total']['CTM'] = round(sum([eqpt.CTM for eqpt in eqptlist]), 2) 672 | report_dict['Total']['CGR'] = round(sum([eqpt.CGR for eqpt in eqptlist]), 2) 673 | report_dict['Total']['ACC'] = round(sum([eqpt.ACC for eqpt in eqptlist]), 2) 674 | 675 | FCI = round(report_dict['Total']['CGR'] if planttype is 'green' else report_dict['Total']['CTM'], 2) 676 | 677 | if verbose: 678 | time.sleep(0.1) 679 | print('----------------------------') 680 | print('TOTAL PLANT COST (' + str.upper(planttype) + 'FIELD): $' + str(FCI)) 681 | print('----------------------------') 682 | print('CAPEX REPORT:') 683 | print(report_list if reporttype is 'list' else report_dict if reporttype is 'dict' else report_numpy) 684 | print('----------------------------') 685 | 686 | return FCI, report_list if reporttype is 'list' else report_dict if reporttype is 'dict' else report_numpy 687 | -------------------------------------------------------------------------------- /dsg.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import warnings 3 | import capex 4 | 5 | Patm = 14.696 # Standard atmospheric pressure (psi) 6 | Patmb = 1.01325 # Standard atmospheric pressure (bar) 7 | Troom = 77. # Ambient temperature (degF) 8 | tmin = 1/4 # Universal minimum allowable vessel thickness (in) 9 | tc = 0.125 # Corrosion allowance (in) for both corrosive and non-corrosive conditions (default is 1/8) 10 | rhosteel = 0.2836 # Density of SA-285C/SA-387B/carbon/low-alloy steels (lb/in^3) 11 | 12 | g = 9.80665 # standard Earth gravitational acceleration (m/s^2) 13 | R = 8.31446261815324 # universal ideal gas constant (J/(K.mol)) 14 | Ta = 10. # minimum heat exchanger temperature approach (K) 15 | 16 | 17 | class MechDesign(object): 18 | def __init__(self, Po=Patm, To=Troom, Di=None, L=None, rho=rhosteel, 19 | Pd=None, Td=None, MOC=None, Smax=None, E=0.85, tp=tmin, tc=None, ts=None, tsfinal=None, 20 | tv=None, tw=None, 21 | Do=None, W=None, V=None, Vi=None, 22 | EM=None, tE=None, tEC=None, 23 | category='vessel', etype=None, mat=None, id=None, 24 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 25 | self.Po = Po 26 | self.To = To 27 | self.Di = Di 28 | self.L = L 29 | self.rho = rho 30 | self.Pd = Pd 31 | self.Td = Td 32 | self.MOC = MOC 33 | self.Smax = Smax 34 | self.E = E 35 | self.tp = tp 36 | self.tc = tc 37 | self.ts = ts 38 | self.tsfinal = tsfinal 39 | self.tv = tv 40 | self.tw = tw 41 | self.Do = Do 42 | self.W = W 43 | self.V = V 44 | self.Vi = Vi 45 | self.EM = EM 46 | self.tE = tE 47 | self.tEC = tEC 48 | self.category = category 49 | self.etype = etype 50 | self.mat = mat 51 | self.id = id 52 | self.Cpo = Cpo 53 | self.FP = FP 54 | self.FM = FM 55 | self.FBM = FBM 56 | self.CBM = CBM 57 | self.CTM = CTM 58 | self.CGR = CGR 59 | self.ACC = ACC 60 | 61 | def __repr__(self): 62 | return '%s: MechDesign(Pd=%spsig, Td=%sdegF, tsfinal=%sin, L=%sin, Do=%sin, W=%slb, V=%sin^3, etype=%s, mat=%s)' \ 63 | % (self.id, round(self.Pd, 2), self.Td, self.tsfinal, self.L, self.Do, int(self.W), int(self.V), self.etype, self.mat) 64 | 65 | def spec(self): 66 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 67 | 68 | def econ(self): 69 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 70 | 71 | 72 | class Mixer(object): 73 | def __init__(self, mixerpower=None, 74 | category='mixer', etype=None, mat=None, id=None, 75 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 76 | self.mixerpower = mixerpower 77 | self.category = category 78 | self.etype = etype 79 | self.mat = mat 80 | self.id = id 81 | self.Cpo = Cpo 82 | self.FP = FP 83 | self.FM = FM 84 | self.FBM = FBM 85 | self.CBM = CBM 86 | self.CTM = CTM 87 | self.CGR = CGR 88 | self.ACC = ACC 89 | 90 | def __repr__(self): 91 | return '%s: Mixer(mixerpower=%skW, etype=%s, mat=%s)' \ 92 | % (self.id, self.mixerpower, self.etype, self.mat) 93 | 94 | def spec(self): 95 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 96 | 97 | def econ(self): 98 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 99 | 100 | 101 | class Trays(object): 102 | def __init__(self, numtrays=None, area=None, 103 | category='trays', etype=None, mat=None, id=None, 104 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 105 | self.numtrays = numtrays 106 | self.area = area 107 | self.category = category 108 | self.etype = etype 109 | self.mat = mat 110 | self.id = id 111 | self.Cpo = Cpo 112 | self.FP = FP 113 | self.FM = FM 114 | self.FBM = FBM 115 | self.CBM = CBM 116 | self.CTM = CTM 117 | self.CGR = CGR 118 | self.ACC = ACC 119 | 120 | def __repr__(self): 121 | return '%s: Trays(numtrays=%s, area=%s, etype=%s, mat=%s)' \ 122 | % (self.id, self.numtrays, self.area, self.etype, self.mat) 123 | 124 | def spec(self): 125 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 126 | 127 | def econ(self): 128 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 129 | 130 | 131 | class Reactor(MechDesign, Mixer): 132 | def __init__(self): 133 | super().__init__(self) 134 | 135 | def __repr__(self): 136 | return super().__repr__(self) 137 | 138 | 139 | class Distillation(MechDesign, Trays): 140 | def __init__(self): 141 | super().__init__(self) 142 | 143 | def __repr__(self): 144 | return super().__repr__(self) 145 | 146 | 147 | class Compressor(object): 148 | def __init__(self, m=None, P1=Patm, P2=None, T1=Troom, T2=None, cp=None, cv=None, Z=None, 149 | compeff=None, comppower=None, 150 | category='compressor', etype=None, mat=None, id=None, 151 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 152 | self.m = m 153 | self.P1 = P1 154 | self.P2 = P2 155 | self.T1 = T1 156 | self.T2 = T2 157 | self.cp = cp 158 | self.cv = cv 159 | self.Z = Z 160 | self.compeff = compeff 161 | self.comppower = comppower 162 | self.category = category 163 | self.etype = etype 164 | self.mat = mat 165 | self.id = id 166 | self.Cpo = Cpo 167 | self.FP = FP 168 | self.FM = FM 169 | self.FBM = FBM 170 | self.CBM = CBM 171 | self.CTM = CTM 172 | self.CGR = CGR 173 | self.ACC = ACC 174 | 175 | def __repr__(self): 176 | return '%s: Compressor(P1=%sbar, P2=%sbar, compeff=%s, comppower=%skW, etype=%s, mat=%s)' \ 177 | % (self.id, self.P1, self.P2, round(self.compeff, 3), round(self.comppower, 3), self.etype, self.mat) 178 | 179 | def spec(self): 180 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 181 | 182 | def econ(self): 183 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 184 | 185 | 186 | class Pump(object): 187 | def __init__(self, Q=None, P1=None, P2=None, dP=None, rho=1000, 188 | pumpeff=0.75, pumppower=None, 189 | category='pump', etype=None, mat=None, id=None, 190 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 191 | self.Q = Q 192 | self.P1 = P1 193 | self.P2 = P2 194 | self.dP = dP 195 | self.rho = rho 196 | self.pumpeff = pumpeff 197 | self.pumppower = pumppower 198 | self.category = category 199 | self.etype = etype 200 | self.mat = mat 201 | self.id = id 202 | self.Cpo = Cpo 203 | self.FP = FP 204 | self.FM = FM 205 | self.FBM = FBM 206 | self.CBM = CBM 207 | self.CTM = CTM 208 | self.CGR = CGR 209 | self.ACC = ACC 210 | 211 | def __repr__(self): 212 | return '%s: Pump(P1=%skPa, P2=%skPa, pumpeff=%s, pumppower=%skW, etype=%s, mat=%s)' \ 213 | % (self.id, self.P1, self.P2, round(self.pumpeff, 3), round(self.pumppower, 3), self.etype, self.mat) 214 | 215 | def spec(self): 216 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 217 | 218 | def econ(self): 219 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 220 | 221 | 222 | class HeatExc(object): 223 | def __init__(self, mh=None, mc=None, cph=None, cpc=None, Thin=None, Thout=None, Tcin=None, Tcout=None, 224 | U=None, F=0.9, Ns=1, area=None, P=None, 225 | category='heatexc', etype=None, mat=None, id=None, 226 | Cpo=None, FP=None, FM=None, FBM=None, CBM=None, CTM=None, CGR=None, ACC=None): 227 | self.mh = mh 228 | self.mc = mc 229 | self.cph = cph 230 | self.cpc = cpc 231 | self.Thin = Thin 232 | self.Thout = Thout 233 | self.Tcin = Tcin 234 | self.Tcout = Tcout 235 | self.U = U 236 | self.F = F 237 | self.Ns = Ns 238 | self.area = area 239 | self.P = P 240 | self.category = category 241 | self.etype = etype 242 | self.mat = mat 243 | self.id = id 244 | self.Cpo = Cpo 245 | self.FP = FP 246 | self.FM = FM 247 | self.FBM = FBM 248 | self.CBM = CBM 249 | self.CTM = CTM 250 | self.CGR = CGR 251 | self.ACC = ACC 252 | 253 | def __repr__(self): 254 | return '%s: HeatExc(Thin=%sdegC, Thout=%sdegC, Tcin=%sdegC, Tcout=%sdegC, F=%s, Ns=%s, area=%sm^2, etype=%s, mat=%s)' \ 255 | % (self.id, self.Thin, self.Thout, self.Tcin, self.Tcout, round(self.F, 3), self.Ns, round(self.area, 2), self.etype, self.mat) 256 | 257 | def spec(self): 258 | return '---Design specs for {}:---\n{}\n----------------------------'.format(self.id, vars(self)) 259 | 260 | def econ(self): 261 | return '---Econ report for {}:---\nCpo=${}\nCBM=${}\nCTM=${}\nCGR=${}\nACC=${}\n----------------------------'.format(self.id, round(self.Cpo, 2), round(self.CBM, 2), round(self.CTM, 2), round(self.CGR, 2), round(self.ACC, 2)) 262 | 263 | 264 | def stepwise_leq(a, b, x): 265 | 266 | if len(b) != len(a) + 1: 267 | raise ValueError('len(b) should be len(a) + 1 !') 268 | 269 | a = (-np.inf,) + a + (np.inf,) 270 | 271 | for i in range(0, len(a)): 272 | if a[i] <= x < a[i + 1]: 273 | y = b[i] 274 | break 275 | 276 | if y == 'error': 277 | raise ValueError('Input out of supported range!') 278 | 279 | return y 280 | 281 | 282 | def stepwise_req(a, b, x): 283 | 284 | if len(b) != len(a) + 1: 285 | raise ValueError('len(b) should be len(a) + 1 !') 286 | 287 | a = (-np.inf,) + a + (np.inf,) 288 | 289 | for i in range(0, len(a)): 290 | if a[i] < x <= a[i + 1]: 291 | y = b[i] 292 | break 293 | 294 | if y == 'error': 295 | raise ValueError('Input out of supported range!') 296 | 297 | return y 298 | 299 | 300 | def designP(Po: float) -> float: 301 | 302 | """ 303 | Calculate design pressure for pressure and vacuum vessels 304 | :param Po: most deviated operating pressure (psig) 305 | :return: Pd design pressure (psig) 306 | """ 307 | 308 | expo = np.exp(0.60608 + 0.91615 * np.log(Po) + 0.0015655 * pow((np.log(Po)), 2.)) 309 | a = (0., 5., 10., 10.e3) 310 | b = (Po, 10., max(10., expo), expo, 'error') 311 | Pd = stepwise_leq(a, b, Po) 312 | 313 | return Pd 314 | 315 | 316 | def designT(To: float, heuristic: str='towler') -> float: 317 | 318 | """ 319 | Calculate design temperature for pressure and vacuum vessels 320 | :param To: most deviated operating temperature (degF) 321 | :param heuristic: either 'Towler' or 'Turton' (optional) 322 | :return: Td design temperature (degF) 323 | """ 324 | 325 | if 'towler' in str.lower(heuristic): 326 | if To < Troom: 327 | Td = To - 25 328 | else: 329 | Td = To + 50 330 | elif 'turton' in str.lower(heuristic): 331 | if -22 <= To <= 644: 332 | Td = To + 45 333 | else: 334 | raise ValueError('To temperature input out of supported range using Turton heuristic!') 335 | else: 336 | raise ValueError('Heuristic not supported! Please check heuristic input!') 337 | return Td 338 | 339 | 340 | def maxstress(Td: float, MOC: str='387B') -> (float, float): 341 | 342 | """ 343 | Calculate maximum allowable stress for pressure vessel material 344 | :param Td: design temperature (degF) 345 | :param MOC: user-specified material of construction (optional input) 346 | :return: Smax maximum allowable stress for pressure vessel MOC (psi) 347 | :return: MOC prescribed material of construction which is in stainless steel family (string, optional). 348 | If MOC is not user-specified, the returned MOC will be a default value (SA-285C or SA-387B). 349 | """ 350 | 351 | if '317L' in str.upper(MOC): 352 | 353 | MOC = '317L' 354 | a = (-20., 68., 200., 400., 600., 800., 1000., 1200., 1400., 1600.) 355 | b = ('error', 25286., 22957., 20957., 19400., 17633., 16733., 15767., 12857., 8300., 'error') 356 | 357 | elif '316Ti' in str.upper(MOC): 358 | 359 | MOC = '316Ti' 360 | a = (-22., 302., 392., 482., 572., 617., 662., 707., 752., 797., 842., 887., 361 | 932., 977., 1022., 1067., 1112.) 362 | b = ('error', 20015., 19435., 18130., 16969., 16824., 16534., 16244., 16099., 15954., 15809., 15664., 15519., 363 | 15374., 15229., 14475., 11647., 'error') 364 | 365 | elif '316L' in str.upper(MOC): 366 | 367 | MOC = '316L' 368 | a = (-22., 302., 392., 482., 572., 617., 662., 707., 752., 797., 842., 887.) 369 | b = ('error', 16679., 15809., 14939., 14214., 13880., 13648., 13460., 13184., 12908., 12734., 12560., 'error') 370 | 371 | elif '304' in str.upper(MOC): 372 | 373 | MOC = '304' 374 | a = (-22., 149., 212., 257., 302., 392., 482., 572., 617., 662., 707., 752., 797., 842., 887., 375 | 932., 977., 1022., 1067., 1112.) 376 | b = ('error', 20015., 19870., 19435., 18855., 18275., 17695., 16824., 16534., 16099., 15809., 15519., 377 | 15229., 14939., 14649., 14402., 14214., 13532., 11545., 9485., 'error') 378 | 379 | else: # use default MOCs 380 | 381 | a = (-20., 650., 750., 800., 850., 900.) 382 | b = ('error', 13750., 15000., 14750., 14200., 13100., 'error') 383 | c = ('error', '285C', '387B', '387B', '387B', '387B', 'error') 384 | MOC = stepwise_leq(a, c, Td) 385 | 386 | Smax = stepwise_leq(a, b, Td) 387 | 388 | return Smax, MOC 389 | 390 | 391 | def elasmod(Td: float, MOC :str='carbon') -> (float, float): 392 | 393 | """ 394 | Calculate modulus of elasticity for vacuum vessel material 395 | :param Td: design pressure (degF) 396 | :param MOC: material of construction (only either 'carbon' or 'low-alloy', string) 397 | :return: EM modulus of elasticity for vacuum vessel MOC (psi) 398 | :return: MOC returns the input MOC for consistency with the equivalent computation for pressure vessels (optional string) 399 | """ 400 | 401 | if 'carbon' in str.lower(MOC): 402 | MOC = 'carbon' 403 | a = (-20., 200., 400., 650.) 404 | b = (30.2e6, 29.5e6, 28.3e6, 26.0e6, 'error') 405 | EM = stepwise_req(a, b, Td) 406 | 407 | elif 'low' in str.lower(MOC) and 'alloy' in str.lower(MOC): 408 | MOC = 'low-alloy' 409 | a = (-20., 200., 400., 650., 700., 800., 900.) 410 | b = (30.2e6, 29.5e6, 28.6e6, 27.0e6, 26.6e6, 25.7e6, 24.5e6, 'error') 411 | EM = stepwise_req(a, b, Td) 412 | 413 | else: 414 | raise ValueError('Specified MOC not found! Please check MOC input!') 415 | 416 | return EM, MOC 417 | 418 | 419 | def wallthk(Pd: float, Di: float, Smax: float) -> (float, float): 420 | 421 | """ 422 | Calculate cylindrical shell wall thickness for pressure vessels, including minimum thickness check for structural rigidity 423 | :param Pd: design pressure (psig) 424 | :param Di: internal diameter (in) 425 | :param Smax: maximum allowable stress (psi) 426 | :return: tp: cylindrical shell wall thickness for pressure 427 | :return: E: fractional weld efficiency used (string, optional) 428 | """ 429 | 430 | E = 0.85 # first assume 10% X-ray spot check 431 | tp = Pd * Di / (2*Smax*E - 1.2*Pd) 432 | 433 | if tp > 1.25: # tp not large enough, 100% X-ray check needed 434 | E = 1 435 | tp = Pd * Di / (2*Smax*E - 1.2*Pd) 436 | 437 | # Check if minimum wall thickness to provide rigidity satisfied 438 | 439 | a = (48., 72., 96., 120., 144.) 440 | b = (max(1/4, tp), max(5/16, tp), max(3/8, tp), max(7/16, tp), max(1/2, tp), 'error') 441 | tp = stepwise_leq(a, b, tp) 442 | 443 | return tp, E 444 | 445 | 446 | def wallthkvac(Pd: float, Do: float, Di: float, L: float, EM: float) -> (float, float, float): 447 | 448 | """ 449 | Calculate cylindrical shell wall thickness for vacuum vessels 450 | :param Pd: design pressure (psig) 451 | :param Do: external diameter (in) 452 | :param Di: internal diameter (in) 453 | :param L: vessel length (in) 454 | :param EM: modulus of elasticity (psi) 455 | :return: tp: cylindrical shell wall thickness for vacuum vessels (in) 456 | :return: tE: necessary thickness for vacuum vessels (in, optional) 457 | :return: tEC: correction factor for vacuum vessels (in, optional) 458 | """ 459 | 460 | tE = pow(1.3 * Do * (Pd * L / (EM * Do)), 0.4) 461 | if tE / Do > 0.05: 462 | warnings.warn('tE is > 0.05*Do, which is' + 463 | ' outside the validity range for tE computation!' + 464 | ' Nevertheless carrying on with calculation - beware!') 465 | 466 | tEC = L * (0.18*Di - 2.2)*1e-5 - 0.19 467 | tp = tE + tEC 468 | 469 | return tp, tE, tEC 470 | 471 | 472 | def shellthkhorz(tp: float) -> float: 473 | 474 | """ 475 | Calculate shell thickness for horizontal vessels 476 | :param tp: wall thickness (in) 477 | :return: ts: shell thickness with corrosion allowance for horizontal vessels (in) 478 | """ 479 | 480 | ts = tp + tc 481 | 482 | return ts 483 | 484 | 485 | def windalw(Do: float, L: float, Smax: float) -> float: 486 | 487 | """ 488 | Calculate wind/earthquake allowance for vertical vessels 489 | Caution: Using WINDALW requires an assumed value of Do 490 | which is dependent on tw. If Do is unknown, use 491 | SHELLTHKVERT directly instead which internally calls WINDALW. 492 | :param Do: external diameter (in) 493 | :param L: internal tangent-to-tangent height (in) 494 | :param Smax: maximum allowable stress (psi) 495 | :return: tw: wind/earthquake allowance for vertical vessels (in) 496 | """ 497 | 498 | tw = 0.22 * (Do + 18.) * (L ** 2.) / (Smax * Do ** 2.) 499 | 500 | return tw 501 | 502 | 503 | def shellthkvert(tp: float, Di: float, L: float, Smax: float) -> (float, float, float): 504 | 505 | """ 506 | Calculate shell thickness for vertical vessels 507 | :param tp: wall thickness (in) 508 | :param Di: internal diameter (in) 509 | :param L: internal tangent-to-tangent height (in) 510 | :param Smax: maximum allowable stress of MOC (psi) 511 | :return: ts: shell thickness with wind allowance after adding corrosion allowance for vertical vessels (in) 512 | :return: tv: shell thickness with wind allowance before adding corrosion allowance for vertical vessels (in) 513 | :return: tw: wind allowance (in, optional) 514 | """ 515 | 516 | ts0 = 2. * tp # dummy initialisation 517 | Do = Di + 2. * ts0 518 | tw = windalw(Do, L, Smax) 519 | tv = (tp + (tp+tw)) / 2. 520 | ts1 = tv + tc # add corrosion allowance 521 | 522 | reltol = 1e-9 523 | i = 0 524 | while abs(ts1 - ts0) / ts0 > reltol and i < 1e3: 525 | ts0 = ts1 526 | i += 1 527 | Do = Di + 2. * ts0 528 | tw = windalw(Do, L, Smax) 529 | tv = (tp + (tp+tw)) / 2. 530 | ts1 = tv + tc # add corrosion allowance 531 | 532 | if i == 1e3: 533 | warnings.warn('Vertical vessel thickness failed to converge!' + 534 | ' Nevertheless carrying on with calculation - beware!') 535 | 536 | ts = ts1 537 | 538 | return ts, tv, tw 539 | 540 | 541 | def ceilplatethk(ts: float) -> float: 542 | 543 | """ 544 | Round up metal plate thickness to nearest increment 545 | :param ts: shell wall thickness before before rounding to nearest increment (in) 546 | :return: tsfinal: final shell wall thickness after rounding to nearest increment (in) 547 | """ 548 | 549 | if ts > 3.: 550 | warnings.warn('Calculated ts not in supported range.' + 551 | ' Assuming metal plate thickness in increments' + 552 | ' of 1/4 inches above 3 inches!') 553 | 554 | a = (3/16, 1/2, 2., 3.) 555 | b = ('error', 1/16, 1/8, 1/4, 1/4) 556 | acc = stepwise_req(a, b, ts) 557 | 558 | tsfinal = np.ceil(ts / acc) * acc 559 | 560 | return tsfinal 561 | 562 | 563 | def vesselweight(Di: float, tsfinal: float, L: float, rho: float=rhosteel) -> float: 564 | 565 | """ 566 | Calculate final weight of vessel of the vessel with the shell and two 2:1 elliptical heads 567 | :param Di: internal diameter (in) 568 | :param tsfinal: shell thickness with corrosion allowance, rounded to nearest thickness increment for metal plates (in) 569 | :param L: internal tangent-to-tangent length/height (in) 570 | :param rho: density of material of construction (MOC) (lb/in^3) 571 | :return: W: weight of vessel (lb) 572 | """ 573 | 574 | W = np.pi * (Di+tsfinal) * (L+0.8*Di) * tsfinal * rho 575 | 576 | return W 577 | 578 | 579 | def vesselvol(Do: float, L: float) -> float: 580 | 581 | """ 582 | Calculate final external volume of vessel with the shell and two 2:1 elliptical heads 583 | :param Do: external diameter (in) 584 | :param L: internal tangent-to-tangent length/height (in) 585 | :return: volume of vessel (in^3) 586 | """ 587 | 588 | Vcyl = np.pi * pow(Do, 2.) / 4. * L 589 | H = Do / 4. 590 | Vheads = 4. / 3. * np.pi * H * pow((Do / 2.), 2.) 591 | V = Vcyl + Vheads 592 | 593 | return V 594 | 595 | 596 | def designhorzpres(Di: float, L: float, Po: float=Patm, To: float=Troom, rho: float=rhosteel, MOC: str='387B', 597 | mat: str='SS', id: str='UnnamedVessel') -> MechDesign(): 598 | 599 | """ 600 | The main function to be called for designing horizontal pressure vessels 601 | Example implementation: 602 | md = designhorzpres(Di=78, L=480, Po=470, To=850) 603 | :param Di: internal diameter (in) 604 | :param L: tangent-to-tangent horizontal length (in) 605 | :param Po: most deviated operating pressure from ambient pressure (psig) 606 | :param To: most deviated operating temperature from ambient temperature (degF) 607 | :param rho: density of material of construction (lb/in^3, optional) 608 | :param MOC: material of construction (string e.g. '387B' [default] or '317L' etc., optional) 609 | :param mat: category of material of construction (string e.g. 'CS' or 'SS' [default] etc., optional) 610 | :param id: id/name of equipment (string, e.g. V100, optional) 611 | :return: md: MechDesign object (optional) consisting of: 612 | Pd = design pressure (psig) 613 | Td = design pressure (degF) 614 | MOC = material of construction to use (string) 615 | Smax = maximum allowable stress of MOC used (psi) 616 | E = weld efficiency to use (dimensionless) 617 | tp = wall thickness (in) 618 | tc = corrosion allowance used (= 1/8 in) 619 | ts = tp with tc (in) 620 | tsfinal = ts rounded up to next increment in metal plate thickness (in) 621 | Do = external diameter (in) 622 | W = total vessel weight (lb) 623 | V = total vessel external volume (in^3) 624 | Vi = total vessel internal volume (in^3) 625 | """ 626 | 627 | md = MechDesign() 628 | md.Po = Po 629 | md.To = To 630 | md.Di = Di 631 | md.L = L 632 | md.rho = rho 633 | 634 | md.Pd = designP(Po) 635 | md.Td = designT(To) 636 | md.Smax, md.MOC = maxstress(md.Td, MOC) 637 | md.tp, md.E = wallthk(md.Pd, Di, md.Smax) 638 | md.tc = tc 639 | md.ts = shellthkhorz(md.tp) 640 | md.tsfinal = ceilplatethk(md.ts) 641 | md.Do = Di + 2. * md.tsfinal 642 | md.W = vesselweight(Di, md.tsfinal, L, rho) 643 | md.V = vesselvol(md.Do, L) 644 | md.Vi = np.pi * (Di ** 2.) / 4. * L 645 | 646 | md.id = id 647 | md.category = 'vessel' 648 | md.etype = 'horizontal' 649 | if mat is not None: 650 | md.mat = mat if mat in capex.matfaclib['vessel']['horizontal'].keys() else None 651 | else: 652 | md.mat = 'SS' if MOC in ['317L', '316L', '304'] else 'CS' if MOC in ['285C', '387B', 'low-alloy', 'carbon'] else 'Ti' if MOC in ['316Ti'] else None 653 | if md.mat is None: 654 | md.mat = 'SS' 655 | warnings.warn('Type of MOC (mat variable) cannot be identified and is assumed to be stainless steel! ' + 656 | 'You can specify a mat input (mat=' + capex.matfaclib['vessel']['horizontal'].keys()) 657 | 658 | return md 659 | 660 | 661 | def designvertpres(Di: float, L: float, Po: float=Patm, To: float=Troom, rho: float=rhosteel, 662 | MOC: str='387B', mat: str='SS', id: str='UnnamedVessel') -> MechDesign(): 663 | 664 | """ 665 | The main function to be called for designing vertical pressure vessels 666 | Example implementation: 667 | md = designhorzpres(Di=120, L=2544, Po=95.5, To=150) 668 | :param Di: internal diameter (in) 669 | :param L: tangent-to-tangent horizontal height (in) 670 | :param Po: most deviated operating pressure from ambient pressure (psig) 671 | :param To: most deviated operating temperature from ambient temperature (degF) 672 | :param rho: density of material of construction (lb/in^3, optional) 673 | :param MOC: material of construction (string e.g. '387B' [default] or '317L' etc., optional) 674 | :param mat: category of material of construction (string e.g. 'CS' or 'SS' [default] etc., optional) 675 | :param id: id/name of equipment (string, e.g. V100, optional) 676 | :return: md: MechDesign object (optional) consisting of: 677 | Pd = design pressure (psig) 678 | Td = design pressure (degF) 679 | MOC = material of construction to use (string) 680 | Smax = maximum allowable stress of MOC used (psi) 681 | E = weld efficiency to use (dimensionless) 682 | tp = wall thickness (in) 683 | tc = corrosion allowance used (= 1/8 in) 684 | tw = wind/earthquake allowance for vertical vessels (in) 685 | tv = tp with tw without tc (in) 686 | ts = tp with tc (in) 687 | tsfinal = ts rounded up to next increment in metal plate thickness (in) 688 | Do = external diameter (in) 689 | W = total vessel weight (lb) 690 | V = total vessel external volume (in^3) 691 | Vi = total vessel internal volume (in^3) 692 | """ 693 | 694 | md = MechDesign() 695 | md.Po = Po 696 | md.To = To 697 | md.Di = Di 698 | md.L = L 699 | md.rho = rho 700 | 701 | md.Pd = designP(Po) 702 | md.Td = designT(To) 703 | md.Smax, md.MOC = maxstress(md.Td, MOC) 704 | md.tp, md.E = wallthk(md.Pd, Di, md.Smax) 705 | md.tc = tc 706 | md.ts, md.tv, md.tw = shellthkvert(md.tp, Di, L, md.Smax) 707 | md.tsfinal = ceilplatethk(md.ts) 708 | md.Do = Di + 2. * md.tsfinal 709 | md.W = vesselweight(Di, md.tsfinal, L, rho) 710 | md.V = vesselvol(md.Do, L) 711 | md.Vi = np.pi * (Di ** 2.) / 4. * L 712 | 713 | md.id = id 714 | md.category = 'vessel' 715 | md.etype = 'vertical' 716 | if mat is not None: 717 | md.mat = mat if mat in capex.matfaclib['vessel']['horizontal'].keys() else None 718 | else: 719 | md.mat = 'SS' if MOC in ['317L', '316L', '304'] else 'CS' if MOC in ['285C', '387B', 'low-alloy', 'carbon'] else 'Ti' if MOC in ['316Ti'] else None 720 | if md.mat is None: 721 | md.mat = 'SS' 722 | warnings.warn('Type of MOC (mat variable) cannot be identified and is assumed to be stainless steel! ' + 723 | 'You can specify a mat input (mat=' + capex.matfaclib['vessel']['vertical'].keys()) 724 | 725 | return md 726 | 727 | 728 | def designvac(Di: float, L: float, Po: float=Patm, To: float=Troom, rho: float=rhosteel, 729 | MOC: str='carbon', etype: str=None, mat: str='CS', id: str='UnnamedVessel') -> MechDesign(): 730 | 731 | """ 732 | The main function to be called for designing vacuum vessels 733 | Example implementation: 734 | md = dsg.designvac(Di=168., L=1080., Po=7.977, To=257.) 735 | :param Di: internal diameter (in) 736 | :param L: tangent-to-tangent horizontal length/height (in) 737 | :param Po: most deviated operating pressure from ambient pressure (psig) 738 | :param To: most deviated operating temperature from ambient temperature (degF) 739 | :param rho: density of material of construction (lb/in^3, optional) 740 | :param MOC: material of construction (string e.g. 'carbon' as default, optional) 741 | :param etype: type of vessel ('horizontal' or 'vertical') 742 | :param mat: category of material of construction (string e.g. 'CS' [default] or 'SS' etc., optional) 743 | :param id: id/name of equipment (string, e.g. V100, optional) 744 | :return: md: MechDesign object (optional) consisting of: 745 | Pd = design pressure (psig) 746 | Td = design pressure (degF) 747 | MOC = material of construction to use (string) 748 | EM = modulus of elasticity of MOC used (psi) 749 | tE = vacuum wall thickness (in) 750 | tEC = vacuum wall correction factor (in) 751 | tp = tE with tEC (in) 752 | tc = corrosion allowance used (= 1/8 in) 753 | ts = tp with tc (in) 754 | tsfinal = ts rounded up to next increment in metal plate thickness (in) 755 | Do = external diameter (in) 756 | W = total vessel weight (lb) 757 | V = total vessel external volume (in^3) 758 | Vi = total vessel internal volume (in^3) 759 | """ 760 | 761 | md = MechDesign() 762 | md.Po = Po 763 | md.To = To 764 | md.Di = Di 765 | md.L = L 766 | md.rho = rho 767 | 768 | md.Pd = Patm - Po 769 | md.Td = designT(To) 770 | if -20 < md.Td <= 650: 771 | [md.EM, md.MOC] = elasmod(md.Td, 'carbon') 772 | elif 650 < md.Td < 900: 773 | [md.EM, md.MOC] = elasmod(md.Td, 'low-alloy') 774 | else: 775 | raise ValueError('Td out of supported range for both carbon and low-alloy steel!') 776 | 777 | ts0 = 1 # dummy initialisation 778 | md.Do = Di + 2. * ts0 779 | md.tp, md.tE, md.tEC = wallthkvac(md.Pd, md.Do, Di, L, md.EM) 780 | md.tc = tc 781 | ts1 = shellthkhorz(md.tp) # horz/vert orientation does not matter for vacuum 782 | 783 | reltol = 1.e-9 784 | i = 0 785 | while abs(ts1 - ts0) / ts0 > reltol and i < 1e3: 786 | ts0 = ts1 787 | i += 1 788 | md.Do = Di + 2. * ts0 789 | md.tp, md.tE, md.tEC = wallthkvac(md.Pd, md.Do, Di, L, md.EM) 790 | md.tc = tc 791 | ts1 = shellthkhorz(md.tp) 792 | 793 | if i == 1e3: 794 | warnings.warn('Vacuum vessel thickness failed to converge! ' + 795 | 'Nevertheless carrying on with calculation - beware!') 796 | 797 | md.ts = ts1 798 | md.tsfinal = ceilplatethk(md.ts) 799 | md.Do = Di + 2. * md.tsfinal 800 | md.W = vesselweight(Di, md.tsfinal, L, rho) 801 | md.V = vesselvol(md.Do, L) 802 | md.Vi = np.pi * (Di ** 2.) / 4. * L 803 | 804 | md.id = id 805 | md.category = 'vessel' 806 | if etype is None: 807 | etype = 'vertical' 808 | warnings.warn('Assuming vacuum vessel is vertical! ' + 809 | 'You can specify a etype input (etype=' + str(capex.eqptcostlib['vessel'].keys())) 810 | md.etype = str.lower(etype) if (str.lower(etype) in capex.eqptcostlib['vessel'].keys()) else None 811 | 812 | if mat is not None: 813 | md.mat = mat if mat in capex.matfaclib['vessel']['horizontal'].keys() else None 814 | else: 815 | md.mat = 'SS' if MOC in ['317L', '316L', '304'] else 'CS' if MOC in ['285C', '387B', 'low-alloy', 'carbon'] else 'Ti' if MOC in ['316Ti'] else None 816 | if md.mat is None: 817 | md.mat = 'CS' 818 | warnings.warn('Type of MOC (mat variable) cannot be identified and is assumed to be carbon steel! ' + 819 | 'You can specify a mat input (mat=' + str(capex.matfaclib['vessel']['vertical'].keys())) 820 | 821 | return md 822 | 823 | 824 | def sizecompressor(m: float, P1: float, P2: float, T1: float, cp: float, cv: float, Z: float=1., 825 | etype: str=None, mat: str=None, id: str='UnnamedCompressor') -> (float, float, float, Compressor()): 826 | 827 | """ 828 | Conducts compressor sizing by determining required compressor power 829 | based on its flow rate and inlet/outlet pressures 830 | Example implementation: 831 | comppower, compeff, T2, compressor = dsg.sizecompressor(m=1e5, P1=100, P2=300, T1=323.15, cp=1.02, cv=0.72, Z=0.99) 832 | :param m: mass flow rate through compressor (kg/h) 833 | :param P1: gas inlet pressure (bar) 834 | :param P2: gas inlet pressure (bar) 835 | :param T1: gas inlet temperature (K) 836 | :param cp: constant-pressure heat capacity of gas 837 | :param cv: constant-volume heat capacity of gas 838 | :param Z: gas compressibility factor (optional, default = 1) 839 | :param etype: type of equipment (string, e.g. 'centrifugal' [default] or 'axial' etc., optional) 840 | :param mat: category of material of construction (string e.g. 'CS' or 'SS' [default] etc., optional) 841 | :param id: id/name of equipment (string, e.g. K100, optional) 842 | :return: comppower: required compressor power (kW) 843 | :return: compeff: compressor efficiency (optional, dimensionless) 844 | :return: gas outlet temperature (optional, K) 845 | :return: compressor: Compressor object (optional) 846 | """ 847 | 848 | if P2/P1 > 4.: 849 | warnings.warn('Compression ratio > 4 is too large -' + 850 | ' check that outlet temperature is not too high!' + 851 | ' Nevertheless continuing calculation...') 852 | elif P2/P1 < 1.: 853 | raise ValueError('Outlet pressure smaller than inlet pressure!') 854 | 855 | m = m / 3600. 856 | k = cp / cv 857 | a = (k - 1) / k 858 | power = (m * Z * R * T1) * (pow((P2 / P1), a) - 1.) / a # useful power 859 | power /= 1000. # convert Pa to kPa 860 | 861 | compeff = np.interp(P2 / P1, [1., 1.5, 2., 3., 6., 10.], 862 | [0.65-np.spacing(1), 0.65, 0.75, 0.8, 0.85, 0.85+np.spacing(1)]) 863 | 864 | comppower = power / compeff 865 | 866 | T2 = T1 * pow(P2 / P1, a) 867 | 868 | if T2 > 273.15 + 200: 869 | warnings.warn('Gas outlet temperature too high! ' + 870 | 'Consider reducing compression ratio P2/P1! ' + 871 | 'Nevertheless continuing calculation...') 872 | 873 | compressor = Compressor() 874 | compressor.m = m 875 | compressor.P1 = P1 876 | compressor.P2 = P2 877 | compressor.T1 = T1 878 | compressor.T2 = T2 879 | compressor.cp = cp 880 | compressor.cv = cv 881 | compressor.Z = Z 882 | compressor.compeff = compeff 883 | compressor.comppower = comppower 884 | 885 | compressor.id = id 886 | compressor.category = 'compressor' 887 | if etype is None: 888 | etype = 'centrifugal' 889 | warnings.warn('Assuming compressor is centrifugal! ' + 890 | 'You can specify a etype input (etype=' + str(capex.eqptcostlib['compressor'].keys())) 891 | compressor.etype = str.lower(etype) if (str.lower(etype) in capex.eqptcostlib['compressor'].keys()) else None 892 | 893 | if mat is None: 894 | mat = 'SS' 895 | warnings.warn('Assuming compressor material is stainless steel! ' + 896 | 'You can specify a mat input (mat=' + str(capex.matfaclib['compressor']['centrifugal'].keys())) 897 | compressor.mat = mat if (mat in capex.matfaclib['compressor']['centrifugal'].keys()) else None 898 | 899 | return comppower, compeff, T2, compressor 900 | 901 | 902 | def sizepump(Q: float, dP: float=None, P1: float=None, P2: float=None, rho: float=1000., pumpeff: float=None, 903 | etype: str=None, mat: str=None, id: str='UnnamedPump') -> (float, float, Pump()): 904 | 905 | """ 906 | Conducts pump sizing by determining required pump power 907 | based on its flow rate and pressure differential (discharge - suction pressure) 908 | Example implementation: 909 | pumppower, pumpeff, pump = dsg.sizepump(Q=35, dP=500) 910 | :param Q: volumetric flow rate through pump (m^3/h) 911 | :param P1: suction/inlet pressure (kPa) 912 | :param P2: discharge/outlet pressure (kPa) 913 | :param rho: stream density (kg/m^3) (optional, default = 1000) 914 | :param pumpeff: pump efficiency (optional, default = 0.75) 915 | :param etype: type of equipment (string, e.g. 'centrifugal' [default] or 'reciprocating' etc., optional) 916 | :param mat: category of material of construction (string e.g. 'CS' or 'SS' [default] etc., optional) 917 | :param id: id/name of equipment (string, e.g. P100, optional) 918 | :return: pumppower = required pump power (kW) 919 | :return: pumpeff = pump efficiency (optional output - if it is not specified in input, it will be calculated) 920 | :return: pump: Pump object (optional) 921 | """ 922 | 923 | if dP is None: 924 | if P1 is None or P2 is None: 925 | raise ValueError('dP, P1 or P2 not specified!') 926 | elif P2 > P1: 927 | dP = P2 - P1 928 | else: 929 | raise ValueError('Outlet pressure lower than inlet pressure!') 930 | 931 | power = (Q / 3600.) * dP # useful power in kW 932 | 933 | H = dP / (rho * g) # required head in m 934 | H_ft = H * 3.281 # required head in ft 935 | Q_gpm = Q * 4.403 # flowrate in gal/min (gpm) 936 | 937 | if pumpeff is None: 938 | if 50 <= H_ft <= 300 and 100 <= Q_gpm <= 1000: 939 | a = np.array([80., -0.2855, 3.78e-4, -2.38e-7, 5.39e-4, -6.39e-7, 4.e-10]) 940 | b = np.array([1, H_ft, H_ft*Q_gpm, H_ft*pow(Q_gpm, 2), 941 | pow(H_ft, 2), pow(H_ft, 2)*Q_gpm, pow(H_ft, 2)*pow(Q_gpm, 2)]) 942 | pumpeff = (a @ b.T) / 100. 943 | elif 0 <= power <= 300: 944 | # Maximum useful power for centrifugal pumps = 300 kW 945 | pumpeff = np.interp(power, [0., 2., 5., 10., 30., 55., 300.], 946 | [0.55-np.spacing(1), 0.55, 0.6, 0.65, 0.7, 0.75, 0.75+np.spacing(1)]) 947 | else: 948 | pumpeff = 0.75 949 | 950 | pumppower = power / pumpeff 951 | 952 | pump = Pump() 953 | pump.Q = Q 954 | pump.P1 = P1 955 | pump.P2 = P2 956 | pump.dP = dP 957 | pump.rho = rho 958 | pump.pumpeff = pumpeff 959 | pump.pumppower = pumppower 960 | 961 | pump.id = id 962 | pump.category = 'pump' 963 | if etype is None: 964 | etype = 'centrifugal' 965 | warnings.warn('Assuming pump is centrifugal! ' + 966 | 'You can specify a type einput (etype=' + str(capex.eqptcostlib['pump'].keys())) 967 | pump.etype = str.lower(etype) if (str.lower(etype) in capex.eqptcostlib['pump'].keys()) else None 968 | 969 | if mat is None: 970 | mat = 'SS' 971 | warnings.warn('Assuming pump material is stainless steel! ' + 972 | 'You can specify a mat input (mat=' + str(capex.matfaclib['pump']['centrifugal'].keys())) 973 | pump.mat = mat if (mat in capex.matfaclib['pump']['centrifugal'].keys()) else None 974 | 975 | return pumppower, pumpeff, pump 976 | 977 | 978 | def sizeHE_heater(mc: float, cpc: float, Tcin: float, Tcout: float, Thin: float, Thout: float, 979 | U: float, F: float=None, Ns: int=1, etype: str=None, mat: str=None, 980 | P: float=None, id: str='UnnamedHX') -> (float, float, HeatExc()): 981 | 982 | """ 983 | Conducts shell-and-tube heat exchanger sizing (counterflow arrangement), where cold process stream is heated, 984 | by determining required heat exchange area 985 | Example implementation: 986 | area, F, HX = dsg.sizeHE_heater(mc=31715, cpc=3246, Tcin=89, Tcout=101, Thin=160, Thout=156, U=850) 987 | :param mc: cold stream mass flow rate (kg/h) 988 | :param cpc: heat capacity of cold stream % J/(kg.K) 989 | :param Tcin: cold stream inlet temperature (degC) 990 | :param Tcout: cold stream outlet temperature (degC) 991 | :param Thin: hot stream inlet temperature (degC) 992 | :param Thout: hot stream outlet temperature (degC) 993 | :param U: heat transfer coefficient (W/(m^2.degC)) 994 | :param F: user-specified correction factor (if not specified, F will be calculated) 995 | :param Ns: number of shell passes (default = 1) 996 | :param etype: type of equipment (string, e.g. 'utube' [default] or 'doublepipe' etc., optional) 997 | :param mat: category of material of construction (string e.g. 'CS/CS' or 'SS/CS' [default] etc., optional) 998 | :param id: id/name of equipment (string, e.g. HX100, optional) 999 | :param P: operating pressure, for cost calculation purposes only (bar, optional) 1000 | :return: area: required heat exchange area (m^2) 1001 | :return: F: correction factor (optional output - if F is not specified in input, F will be calculated) 1002 | :return: HX: HeatExc object (optional) 1003 | """ 1004 | 1005 | if Thout > Thin: 1006 | raise ValueError('Hot stream outlet cannot be hotter than inlet!') 1007 | elif Tcout < Tcin: 1008 | raise ValueError('Cold stream outlet cannot be colder than inlet!') 1009 | elif Tcout > Thout: 1010 | warnings.warn('Potential temperature cross - Cold stream outlet is hotter than hot stream inlet! Nevertheless continuing with calculations...') 1011 | elif Thout - Tcin < Ta: 1012 | raise ValueError('Minimum temperature not fulfilled for hot outlet / cold inlet side!') 1013 | elif Thin - Tcout < Ta: 1014 | raise ValueError('Minimum temperature not fulfilled for hot inlet / cold outlet side!') 1015 | 1016 | mc /= 3600. # convert kg/h to kg/s 1017 | 1018 | Q = mc * cpc * (Tcout - Tcin) # calculate heat transfer rate in W 1019 | 1020 | if (Thout - Tcin) == (Thin - Tcout): 1021 | LMTD = Thout - Tcin 1022 | else: 1023 | LMTD = ((Thin-Tcout) - (Thout-Tcin)) / np.log((Thin-Tcout) / (Thout-Tcin)) 1024 | 1025 | if F is None: 1026 | r = (Thin - Thout) / (Tcout - Tcin) 1027 | p = (Tcout - Tcin) / (Thin - Tcin) 1028 | if r == 1: 1029 | w = (Ns - Ns * p) / (Ns - Ns * p + p) 1030 | F = (np.sqrt(2) * (1 - w) / w) / \ 1031 | (np.log(w / (1 - w) + 1 / np.sqrt(2)) / np.log(w / (1 - w) - 1 / np.sqrt(2))) 1032 | else: 1033 | w = pow((1 - p * r) / (1 - p), 1 / Ns) 1034 | s = np.sqrt(r ** 2 + 1) / (r - 1) 1035 | F = s * np.log(w) / np.log((1 + w - s + s * w) / (1 + w + s - s * w)) 1036 | 1037 | area = Q / (U * F * LMTD) 1038 | 1039 | HX = HeatExc() 1040 | HX.mh = None 1041 | HX.mc = mc 1042 | HX.cph = None 1043 | HX.cpc = cpc 1044 | HX.Thin = Thin 1045 | HX.Thout = Thout 1046 | HX.Tcin = Tcin 1047 | HX.Tcout = Tcout 1048 | HX.U = U 1049 | HX.F = F 1050 | HX.Ns = Ns 1051 | HX.area = area 1052 | HX.P = P 1053 | 1054 | HX.id = id 1055 | HX.category = 'heatexc' 1056 | if etype is None: 1057 | etype = 'utube' 1058 | warnings.warn('Assuming heat exchanger is U-tube! ' + 1059 | 'You can specify a etype input (etype=' + str(capex.eqptcostlib['heatexc'].keys())) 1060 | HX.etype = str.lower(etype) if (str.lower(etype) in capex.eqptcostlib['heatexc'].keys()) else None 1061 | 1062 | if mat is None: 1063 | mat = 'CS/SS' 1064 | warnings.warn('Assuming hext exchanger material is carbon steel/stainless steel (or vice versa)! ' + 1065 | 'You can specify a mat input (mat=' + str(capex.matfaclib['heatexc']['utube'].keys())) 1066 | HX.mat = mat if (mat in capex.matfaclib['heatexc']['utube'].keys()) else None 1067 | 1068 | return area, F, HX 1069 | 1070 | 1071 | def sizeHE_cooler(mh: float, cph: float, Thin: float, Thout: float, Tcin: float, Tcout: float, 1072 | U: float, F: float=None, Ns: int=1, etype: str=None, mat: str=None, 1073 | P: float=None, id: str='UnnamedHX') -> (float, float, HeatExc()): 1074 | 1075 | """ 1076 | Conducts shell-and-tube heat exchanger sizing (counterflow arrangement), where hot process stream is cooled, 1077 | by determining required heat exchange area 1078 | Example implementation: 1079 | area, F, HX = dsg.sizeHE_cooler(mh=31715, cph=3246, Thin=89, Thout=60, Tcin=5, Tcout=10, U=850) 1080 | :param mh: hot stream mass flow rate (kg/h) 1081 | :param cph: heat capacity of hot stream % J/(kg.K) 1082 | :param Thin: hot stream inlet temperature (degC) 1083 | :param Thout: hot stream outlet temperature (degC) 1084 | :param Tcin: cold stream inlet temperature (degC) 1085 | :param Tcout: cold stream outlet temperature (degC) 1086 | :param U: heat transfer coefficient (W/(m^2.degC)) 1087 | :param F: user-specified correction factor (if not specified, F will be calculated) 1088 | :param Ns: number of shell passes (default = 1) 1089 | :param etype: type of equipment (string, e.g. 'utube' [default] or 'doublepipe' etc., optional) 1090 | :param mat: category of material of construction (string e.g. 'CS/CS' or 'SS/CS' [default] etc., optional) 1091 | :param id: id/name of equipment (string, e.g. HX100, optional) 1092 | :param P: operating pressure, for cost calculation purposes only (bar, optional) 1093 | :return: area: required heat exchange area (m^2) 1094 | :return: F: correction factor (optional output - if F is not specified in input, F will be calculated) 1095 | :return: HX: HeatExc object (optional) 1096 | """ 1097 | 1098 | if Thout > Thin: 1099 | raise ValueError('Hot stream outlet cannot be hotter than inlet!') 1100 | elif Tcout < Tcin: 1101 | raise ValueError('Cold stream outlet cannot be colder than inlet!') 1102 | elif Tcout > Thout: 1103 | warnings.warn('Potential temperature cross - Cold stream outlet is hotter than hot stream inlet! Nevertheless continuing with calculations...') 1104 | elif Thout - Tcin < Ta: 1105 | raise ValueError('Minimum temperature not fulfilled for hot outlet / cold inlet side!') 1106 | elif Thin - Tcout < Ta: 1107 | raise ValueError('Minimum temperature not fulfilled for hot inlet / cold outlet side!') 1108 | 1109 | mh /= 3600. # convert kg/h to kg/s 1110 | 1111 | Q = mh * cph * (Thin - Thout) # calculate heat transfer rate 1112 | 1113 | if (Thout - Tcin) == (Thin - Tcout): 1114 | LMTD = Thout - Tcin 1115 | else: 1116 | LMTD = ((Thin - Tcout) - (Thout - Tcin)) / np.log((Thin - Tcout) / (Thout - Tcin)) 1117 | 1118 | if F is None: 1119 | r = (Thin - Thout) / (Tcout - Tcin) 1120 | p = (Tcout - Tcin) / (Thin - Tcin) 1121 | if r == 1: 1122 | w = (Ns - Ns * p) / (Ns - Ns * p + p) 1123 | F = (np.sqrt(2) * (1 - w) / w) / \ 1124 | (np.log(w / (1 - w) + 1 / np.sqrt(2)) / np.log(w / (1 - w) - 1 / np.sqrt(2))) 1125 | else: 1126 | w = pow((1 - p * r) / (1 - p), 1 / Ns) 1127 | s = np.sqrt(r ** 2 + 1) / (r - 1) 1128 | F = s * np.log(w) / np.log((1 + w - s + s * w) / (1 + w + s - s * w)) 1129 | 1130 | area = Q / (U * F * LMTD) 1131 | 1132 | HX = HeatExc() 1133 | HX.mh = mh 1134 | HX.mc = None 1135 | HX.cph = cph 1136 | HX.cpc = None 1137 | HX.Thin = Thin 1138 | HX.Thout = Thout 1139 | HX.Tcin = Tcin 1140 | HX.Tcout = Tcout 1141 | HX.U = U 1142 | HX.F = F 1143 | HX.Ns = Ns 1144 | HX.area = area 1145 | HX.P = P 1146 | 1147 | HX.id = id 1148 | HX.category = 'heatexc' 1149 | if etype is None: 1150 | etype = 'utube' 1151 | warnings.warn('Assuming heat exchanger is U-tube! ' + 1152 | 'You can specify a etype input (etype=' + str(capex.eqptcostlib['heatexc'].keys())) 1153 | HX.etype = str.lower(etype) if (str.lower(etype) in capex.eqptcostlib['heatexc'].keys()) else None 1154 | 1155 | if mat is None: 1156 | HX.mat = 'CS/SS' 1157 | warnings.warn('Assuming hext exchanger material is carbon steel/stainless steel (or vice versa)! ' + 1158 | 'You can specify a mat input (mat=' + str(capex.matfaclib['heatexc']['utube'].keys())) 1159 | HX.mat = mat if (mat in capex.matfaclib['heatexc']['utube'].keys()) else None 1160 | 1161 | return area, F, HX 1162 | -------------------------------------------------------------------------------- /exampleruns.py: -------------------------------------------------------------------------------- 1 | import dsg 2 | import capex 3 | import opex 4 | import time 5 | 6 | """Note: It is best to always use keyword (named) arguments for this ChemEngDPpy library to avoid ambiguity""" 7 | 8 | """Step 1: Design and size all equipment""" 9 | 10 | # Example 1: Horizontal pressure vessel V100 11 | # Di = 78 in, L = 480 in, Po = 470 psig, To = 800 degF, MOC = '317L', 12 | V100 = dsg.designhorzpres(Di=78., L=480., Po=470., To=800., MOC='317L', id='V100') 13 | print(V100) 14 | 15 | # Example 2: Vertical pressure vessel V200 16 | # Di = 120 in, L = 2544 in, Po = 95.5 psig, To = 150 degF, auto-select a suitable MOC 17 | V200 = dsg.designhorzpres(Di=120., L=2544., Po=95.5, To=150, id='V200') 18 | print(V200) 19 | 20 | # Example 3: Vacuum vessel V300 21 | # Di = 168 in, L = 1080 in, Po = 7.977 psig, To = 257 degF, specify vertical for costing purposes 22 | V300 = dsg.designvac(Di=168., L=1080., Po=7.977, To=257., etype='vertical', id='V300') 23 | print(V300) 24 | 25 | # Example 4: Compressor K400 sizing for required power and outlet temperature 26 | # m = 1e5 kg/h, P1 = 2 bar, P2 = 6 bar, T1 = 323.15 K, 27 | # cp = 1.02, cv = 0.72, Z = 0.99 28 | # Specify rotary compressor using carbon steel for costing purposes 29 | K400_comppower, K400_compeff, K400_T2, K400 = \ 30 | dsg.sizecompressor(m=1e5, P1=2, P2=6, T1=323.15, cp=1.02, cv=0.72, Z=0.99, etype='rotary', mat='CS', id='K400') 31 | print(K400) 32 | 33 | # Example 5: Compressor K400 sizing for required power and outlet temperature 34 | # m = 4e5 kg/h, P1 = 1.5 bar, P2 = 6.5 bar, T1 = 290 K, 35 | # cp = 1.02, cv = 0.72, Z = 0.99 36 | # Specify rotary compressor using carbon steel for costing purposes 37 | K500_comppower, K500_compeff, K500_T2, K500 = \ 38 | dsg.sizecompressor(m=4e5, P1=1.5, P2=6., T1=290, cp=1.02, cv=0.72, Z=0.99, etype='centrifugal', mat='SS', id='K500') 39 | print(K500) 40 | 41 | # Example 6: Pump sizing for required power 42 | # Q = 40 m^3/h, P1 = 200 kPa, P2 = 700 kPa, rho = 1200 kg/m^3 43 | # Specify positive displacement pump using stainless steel for costing purposes 44 | P600_pumppower, P600_pumpeff, P600 = \ 45 | dsg.sizepump(Q=40, P1=200, P2=700, rho=1200, etype='positivedisp', mat='SS', id='P600') 46 | print(P600) 47 | 48 | # Example 7: Pump sizing for required power 49 | # Q = 100 m^3/h, P1 = 180 kPa, P2 = 800 kPa, rho = 990 kg/m^3 50 | # Specify positive displacement pump using stainless steel for costing purposes 51 | P700_pumppower, P700_pumpeff, P700 = \ 52 | dsg.sizepump(Q=100, P1=180, P2=800, rho=990, etype='centrifugal', mat='Ni', id='P700') 53 | print(P700) 54 | 55 | # Example 8: Heat exchanger sizing for required heat exchange area (for 56 | # heating process stream) 57 | # mc = 31715 kg/h, cpc = 3246 J/(kg.K), Tcin = 89 degC, Tcout = 101 degC, 58 | # Thin = 160 degC, Thout = 156 degC, U = 850 W/(m^2.degC), Ns = 2 59 | # Specify pressure = 2 bar, double pipe HX using CS (shell) and Ni (tube) for costing purposes 60 | HX800_area, HX800_F, HX800 = dsg.sizeHE_heater(mc=31715, cpc=3246, Tcin=89, Tcout=101, Thin=160, Thout=156, U=850, P=2, \ 61 | Ns=2, etype='doublepipe', mat='CS/Ti', id='HX800') 62 | print(HX800) 63 | 64 | # Example 9: Heat exchanger sizing for required heat exchange area (for 65 | # cooling process stream) 66 | # mc = 31715 kg/h, cph = 3246 J/(kg.K), Thin = 89 degC, Thout = 60 degC, 67 | # Tcin = 5 degC, Tcout = 10 degC, U = 850 W/(m^2.degC), Ns = 1 (default) 68 | # Specify pressure = 4 bar, kettle reboiler HX using CS (shell) and SS (tube) for costing purposes 69 | HX900_area, HX900_F, HX900 = dsg.sizeHE_cooler(mh=31715, cph=3246, Thin=89, Thout=60, Tcin=5, Tcout=10, U=850, P=4, \ 70 | etype='kettle', mat='CS/SS', id='HX900') 71 | print(HX900) 72 | 73 | """Step 2: Calculate all equipment capital""" 74 | 75 | time.sleep(0.1) 76 | 77 | # Example 8: Calculating capital of equipment, assuming greenfield project 78 | eqptlist = [V100, V200, V300, K400, K500, P600, P700, HX800, HX900] 79 | FCI, capexreport = capex.econreport(eqptlist, planttype='green', pbp=3, year=2019, currency='SGD', \ 80 | reporttype='numpy', verbose=True) 81 | 82 | """Step 3: Calculate all manufacturing costs""" 83 | 84 | time.sleep(0.1) 85 | 86 | # Example 9: Calculating cost of manufacturing 87 | 88 | COL, Nop = opex.labourcost(wage=42750., eqptlist=eqptlist) 89 | 90 | print('Number of workers required : ' + str(int(Nop))) 91 | 92 | CRM = opex.costofraw(rawmaterialtuple=(19779., 12606., 325., 240.), unitpricetuple=(89.94, 0.25, 477.74, 1512.39)) 93 | 94 | CUT = opex.costofutil(utiltuple=(0., 671069., 30815., 889354., 105723., 0., 0., 30643.), year=2019, currency='SGD') 95 | 96 | CWT = 0. # Waste treatment cost has to be calculated manually 97 | 98 | COMd, d, COM, DMC, FMC, GE, report_dict = opex.costofmanfc(FCI=FCI, COL=COL, CRM=CRM, CWT=CWT, CUT=CUT, verbose=True) -------------------------------------------------------------------------------- /opex.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import capex 3 | import time 4 | from typing import List, Tuple, Any 5 | 6 | runtime = 8000 # Operational runtime (h/yr) 7 | shiftdur = 8 # Duration per workshift (h/shift) 8 | shiftperwk = 5 # Number of workshifts per week 9 | yearww = 49 # Number of work weeks per year 10 | SF = runtime / (365*24) # Stream factor 11 | 12 | 13 | # Utility Costs (per GJ basis) 14 | # From "Analysis, Synthesis & Design of Chemical Processes, 5th Ed. by Turton et al.", year=2016 15 | utilprice = { 16 | 'LPS': 4.54, # Utility cost for LPS (5 barg, 160 degC) ($/GJ) 17 | 'MPS': 4.77, # Utility cost for MPS (10 barg, 184 degC) ($/GJ) 18 | 'HPS': 5.66, # Utility cost for HPS (41 barg, 254 degC) ($/GJ) 19 | 'CW': 0.378, # Utility cost for cooling water (30-45 degC) ($/GJ) 20 | 'ChW': 4.77, # Utility cost for chilled water (5 degC) ($/GJ) 21 | 'LTR': 8.49, # Utility cost for low temperature refrigerant (-20 degC) ($/GJ) 22 | 'VLTR': 14.12, # Utility cost for very low temperature refrigerant (-50 degC) ($/GJ) 23 | 'elec': 18.72 # Utility cost for electricity (110-440 V) ($/GJ) 24 | } 25 | 26 | 27 | def operatorspershift(P: int=0, Nnp: int=0): 28 | 29 | """ 30 | Calculate number of operators per shift 31 | :param P: number of processing steps involving particulate solids (P=0 for fluid-processing plants) 32 | :param Nnp: number of non-particulate/fluid handling equipment/steps (include compressors, towers, reactors, 33 | heaters and exchangers; exclude pumps, vessels and tanks) 34 | :return: NOL: number of operators required per shift 35 | """ 36 | 37 | NOL = round(np.sqrt(6.29 + 31.7 * P ** 2. + 0.23 * Nnp)) 38 | 39 | return NOL 40 | 41 | 42 | def labourcost(P: int=None, Nnp: int=None, wage: float=42750., eqptlist: List[Any]=None) -> (float, float): 43 | 44 | """ 45 | Calculate annualised labour cost 46 | Two methods of calculation: 47 | Method 1 - Specify P, Nnp and wage manually: 48 | :param P: number of processing steps involving particulate solids (P=0 for fluid-processing plants) 49 | :param Nnp: number of non-particulate/fluid handling equipment/steps (include compressors, towers, reactors, 50 | heaters and exchangers; exclude pumps, vessels and tanks) 51 | :param wage: annualised per-operator wage ($/yr, using the desired currency and year) 52 | Method 2 - Specify the list of equipment objects directly, then specify wage: 53 | :param eqptlist: list of equipment objects as generated by the dsg.design(...) or dsg.size(...) functions 54 | :param wage: annualised per-operator wage ($/yr, using the desired currency and year) 55 | :return: COL: annualised labour cost ($/yr) 56 | :return: NOL: total number of operators required 57 | """ 58 | 59 | if eqptlist is None: 60 | pass 61 | 62 | elif P is None and Nnp is None: 63 | P = 0 64 | Nnp = 0 65 | for eqpt in eqptlist: 66 | P += 1 if eqpt.category in ['crystallizer'] else 0 67 | Nnp += 1 if eqpt.category in ['compressor', 'vessel', 'heatexc'] else 0 68 | 69 | else: 70 | raise ValueError('Specify either (P + Nnp) or eqptlist!') 71 | 72 | NOL = operatorspershift(P, Nnp) 73 | shiftperyr = runtime / shiftdur 74 | shiftperopperyr = yearww * shiftperwk 75 | Nop = round(shiftperyr / shiftperopperyr * NOL) 76 | COL = Nop * wage 77 | 78 | return COL, Nop 79 | 80 | 81 | def costofutil(utiltuple: Tuple[float]=None, HPS: float=0., MPS: float=0., LPS: float=0., 82 | CW: float=0., ChW: float=0., LTR: float=0., VLTR: float=0., elec: float=0., 83 | year: int=2019, currency: str='SGD'): 84 | 85 | """ 86 | Calculates the annualised cost of utilities 87 | Either key in utilities as a tuple, or as separate numerical inputs (see param): 88 | :param utiltuple: tuple containing annual consumption of each type of utility (GJ/yr), in the following order: 89 | HPS, MPS, LPS, CW, ChW, LTR, VLTR, elec 90 | :param HPS: annual consumption of high-pressure steam (GJ/yr) 91 | :param MPS: annual consumption of medium-pressure steam (GJ/yr) 92 | :param LPS: annual consumption of low-pressure steam (GJ/yr) 93 | :param CW: annual consumption of cooling water (GJ/yr) 94 | :param ChW: annual consumption of chilled water (GJ/yr) 95 | :param LTR: annual consumption of low-temperature refrigerant (GJ/yr) 96 | :param VLTR: annual consumption of very low-temperature refrigerant (GJ/yr) 97 | :param elec: annual consumption of electricity (GJ/yr) 98 | :param year: Year for CPI updating (integer, either 2001, 2018 or 2019 [default]) 99 | :param currency: Currency (string, either 'USD' or 'SGD' [default]) 100 | :return: CUT: annualised cost of utilities ($/yr) 101 | """ 102 | 103 | a = np.array([utilprice['HPS'], utilprice['MPS'], utilprice['LPS'], 104 | utilprice['CW'], utilprice['ChW'], 105 | utilprice['LTR'], utilprice['VLTR'], utilprice['elec']]) 106 | 107 | if utiltuple is not None: 108 | b = np.array(utiltuple) 109 | else: 110 | b = np.array([HPS, MPS, LPS, CW, ChW, LTR, VLTR, elec]) 111 | 112 | yearcurrfac = capex.CPI['US'][year] / capex.CPI['US'][2016] * (capex.USSG[year] if currency is 'SGD' else 1.) 113 | 114 | CUT = (a @ b.T) * yearcurrfac 115 | 116 | return CUT 117 | 118 | 119 | def costofraw(rawmaterialtuple: Tuple[float]=(0.,), unitpricetuple: Tuple[float]=(0.,)) -> float: 120 | 121 | """ 122 | Calculates the annualised cost of raw materials 123 | :param rawmaterialtuple: annual flow of raw materials, in a tuple (flow/yr) 124 | :param unitpricetuple: per-flow unit cost price of raw materials, in a tuple in the same order as rawmaterials 125 | ($/flow, using the desired currency and year) 126 | :return: CRM: annualised cost of raw materials ($/yr) 127 | """ 128 | 129 | if type(rawmaterialtuple) is tuple: 130 | a = np.array(rawmaterialtuple) 131 | else: 132 | raise TypeError('rawmaterials should be of type tuple') 133 | 134 | if type(unitpricetuple) is tuple: 135 | b = np.array(unitpricetuple) 136 | else: 137 | raise TypeError('rawmaterials should be of type tuple') 138 | 139 | if a.size != b.size: 140 | raise ValueError('Number of unit prices do not match number of raw materials!') 141 | 142 | CRM = a @ b.T 143 | 144 | return CRM 145 | 146 | 147 | def costofwaste(): 148 | # TODO User has to create this function on his/her own if necessary, 149 | # because there are many possible sources of waste treatment 150 | raise NotImplementedError 151 | 152 | 153 | def costofmanfc(FCI: float=0., COL: float=0., CRM: float=0., CWT: float=0., CUT: float=0., 154 | verbose: bool=False) -> (float, float, float, float, float, float, dict): 155 | 156 | """ 157 | Estimate annualised cost of manufacture. 158 | :param FCI: fixed capital investment (= CTM or total module cost for brownfield projects, or =CGR or grassroots cost 159 | for greenfield projects) ($) 160 | :param COL: annualised labour cost ($/yr) 161 | :param CRM: annualised cost of raw materials ($/yr) 162 | :param CWT: annualised cost of waste treatment ($/yr) 163 | :param CUT: annualised cost of utilities ($/yr) 164 | :return: COMd: annualised cost of manufacturing without depreciation ($/yr) 165 | :return: d: annualised depreciation ($/yr) 166 | :return: COM: annualised cost of manufacturing with depreciation ($/yr) 167 | :return: DMC: annualised direct manufacturing costs ($/yr) 168 | :return: FMC: annualised fixed manufacturing costs ($/yr) 169 | :return: GE: annualised general expenses ($/yr) 170 | :param verbose: True to print economic capex report, False to print nothing [default] 171 | :return: report: The opex report 172 | """ 173 | 174 | report_dict = dict() 175 | 176 | COMd = 0.18 * FCI + 2.73 * COL + 1.23 * (CRM + CWT + CUT) 177 | d = 0.1 * FCI 178 | COM = COMd + d 179 | DMC = CRM + CWT + CUT + 1.33 * COL + 0.069 * FCI + 0.03 * COM 180 | FMC = 0.708 * COL + 0.068 * FCI 181 | GE = 0.177 * COL + 0.009 * FCI + 0.16 * COM 182 | 183 | report_dict['COMd'] = round(COMd, 2) 184 | report_dict['d'] = round(d, 2) 185 | report_dict['COM'] = round(COM, 2) 186 | report_dict['DMC'] = round(DMC, 2) 187 | report_dict['FMC'] = round(FMC, 2) 188 | report_dict['GE'] = round(GE, 2) 189 | report_dict['FCI'] = round(FCI, 2) 190 | report_dict['COL'] = round(COL, 2) 191 | report_dict['CRM'] = round(CRM, 2) 192 | report_dict['CWT'] = round(CWT, 2) 193 | report_dict['CUT'] = round(CUT, 2) 194 | 195 | if verbose: 196 | time.sleep(0.1) 197 | print('----------------------------') 198 | print('OPEX REPORT:') 199 | print(str(report_dict)) 200 | print('----------------------------') 201 | 202 | return COMd, d, COM, DMC, FMC, GE, report_dict 203 | --------------------------------------------------------------------------------