├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── analyze_results.jl ├── data └── README.md ├── docs ├── SPEAR_Functions.md ├── SPEAR_Postprocessing.md ├── index.md ├── paper.md └── refs.bib ├── install_dependencies.jl ├── output.jl ├── par.jl ├── plots ├── README.md └── example │ ├── Vfmax01.png │ └── cumulative_slip.png ├── post ├── README.md ├── event_details.jl ├── plotting_script.jl └── rough_script.jl ├── run.jl ├── src ├── .ipynb_checkpoints │ ├── Assemble-checkpoint.jl │ ├── damageEvol-checkpoint.jl │ └── untitled-checkpoint.txt ├── Assemble.jl ├── BoundaryMatrix.jl ├── FindNearestNode.jl ├── GetGLL.jl ├── Kassemble.jl ├── MaterialProperties.jl ├── MeshBox.jl ├── NRsearch.jl ├── PCG.jl ├── damageEvol.jl ├── dtevol.jl ├── dump.jl ├── faultZoneGeometry │ ├── gaussianFaultZoneAssembly.jl │ └── trapezoidFaultZoneAssembly.jl ├── gll_xwh │ ├── gll_03.tab │ ├── gll_04.tab │ ├── gll_05.tab │ ├── gll_06.tab │ ├── gll_07.tab │ ├── gll_08.tab │ ├── gll_09.tab │ ├── gll_10.tab │ ├── gll_11.tab │ ├── gll_12.tab │ ├── gll_13.tab │ ├── gll_14.tab │ ├── gll_15.tab │ ├── gll_16.tab │ ├── gll_17.tab │ ├── gll_18.tab │ ├── gll_19.tab │ └── gll_20.tab ├── initialConditions │ └── defaultInitialConditions.jl ├── main.jl ├── otherFunctions.jl └── untitled.txt ├── tests ├── README.md └── basic_test_01.jl └── xfer ├── xfer_dizhi ├── xfer_down ├── xfer_up └── xfer_wozhi /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore files with these extensions 2 | *.swp 3 | *.out 4 | *.DS_Store 5 | 6 | !plots/ 7 | !data/ 8 | 9 | plots/* 10 | data/* 11 | 12 | !plots/README.md 13 | !data/README.md 14 | !plots/example/ 15 | 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: julia 2 | os: 3 | - linux 4 | - osx 5 | julia: 6 | - 1.1 7 | - nightly 8 | branches: 9 | only: 10 | - master 11 | - /^release-.*$/ 12 | - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /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 | # SPEAR: SPectral element based EARthquake cycle simulator 2 | 3 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Build Status](https://travis-ci.com/thehalfspace/Spear.svg?branch=master)](https://travis-ci.com/thehalfspace/Spear) 4 | 5 | Numerical simulation of long-term earthquake cycles on a two-dimensional vertical strike-slip fault with dynamic treatment of inertial effects. Written in [Julia](https://julialang.org). 6 | 7 | ## Current Status 8 | v1.0 9 | 10 | ## Features 11 | - Antiplane strain deformation on planar fault with SH waves 12 | - Fully dynamic treatment of seismic events 13 | - Rate-and-state-dependent friction with aging laws 14 | - Adaptive time-stepping to switch between interseismic and seismic events 15 | - Customizable to include off-fault and on-fault heterogeneities 16 | - Complex geometry of fault damage zones including gaussian and trapezoid fault damage zones 17 | - Time-dependent healing of fault damage zones constrained by observations 18 | 19 | ## Dependencies 20 | - [Julia version >= 1.1](https://julialang.org) 21 | - [Algebraic Mulltigrid](https://github.com/JuliaLinearAlgebra/AlgebraicMultigrid.jl) 22 | - [Iterative Solvers](https://github.com/JuliaMath/IterativeSolvers.jl) 23 | - [FEMSparse](https://github.com/ahojukka5/FEMSparse.jl) 24 | 25 | ## Quickstart guide 26 | 1. Install Julia >= 1.1 (preferably the latest version). 27 | 2. Run `install_dependencies.jl` script to install the specific packages. 28 | 3. Open `run.jl` and edit the output file name and the resolution of the problem. 29 | 4. Run `run.jl` from the terminal or IDE of your choice. 30 | 5. The output files are saved in `data/$(simulation_name)`. 31 | 6. You can look at the output file from `analyze_results.jl`. 32 | 7. For basic testing run `julia tests/basic_test_01.jl` to look at two plots saved in the `plots/$(simulation_name)` directory. 33 | 34 | ## Documentation 35 | - Coming soon 36 | 37 | ## Screenshots 38 | drawing 39 | drawing 40 | 41 | 42 | ## References 43 | Please cite the following if using this code: 44 | 45 | [Thakur, P., Huang, Y., & Kaneko, Y. Effects of low‐velocity fault damage zones on long‐term earthquake behaviors on mature strike‐slip faults. Journal of Geophysical Research: Solid Earth, e2020JB019587.](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2020JB019587) 46 | 47 | [Kaneko, Y., Ampuero, J. P., & Lapusta, N. (2011). Spectral‐element simulations of long‐term fault slip: Effect of low‐rigidity layers on earthquake‐cycle dynamics. Journal of Geophysical Research: Solid Earth, 116(B10).](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2011JB008395) 48 | -------------------------------------------------------------------------------- /analyze_results.jl: -------------------------------------------------------------------------------- 1 | using DelimitedFiles 2 | 3 | include("$(@__DIR__)/post/event_details.jl") 4 | include("$(@__DIR__)/post/plotting_script.jl") 5 | 6 | # path to save files 7 | global path = "$(@__DIR__)/plots/test_01/" 8 | mkpath(path) 9 | 10 | global out_path = "$(@__DIR__)/data/test_01/" 11 | 12 | 13 | #= If any of these files don't exist, or you want more information, check lines 153-158 in src/main.jl and uncomment. 14 | Also remember to uncomment the corresponding `end` statements for each of these in lines 418-427 in src/main.jl. 15 | =# 16 | 17 | # Global variables 18 | yr2sec = 365*24*60*60 19 | 20 | # Read data 21 | event_time = readdlm(string(out_path, "event_time.out"), header=false) 22 | tStart = event_time[:,1] # List of start times for all earthquakes (in seconds) 23 | tEnd = event_time[:,2] # List of end times for all earthquakes (in seconds) 24 | hypo = event_time[:,3] # List of hypocenters for all earthquakes (in meters depth) 25 | 26 | event_stress = readdlm(string(out_path, "event_stress.out"), header=false) 27 | indx = Int(length(event_stress[1,:])/2) 28 | taubefore = event_stress[:,1:indx] # List of shear stress along depth before each earthquake 29 | tauafter = event_stress[:,indx+1:end] # List of shear stress along depth after each earthquake 30 | 31 | delfafter = readdlm(string(out_path, "coseismic_slip.out"), header=false) # Coseismic slip = (slip_after - slip_before) each earthquake along depth 32 | 33 | 34 | # These are slip and sliprate stored at every certain timestep (e.g. every 10 or 100 timesteps) 35 | # These are very big files, so I usually only store them when necessary 36 | # slip = readdlm(string(out_path, "slip.out"), header=false) 37 | # sliprate = readdlm(string(out_path, "sliprate.out"), header=false) 38 | 39 | # Order of storage: Seff, tauo, FltX, cca, ccb, xLf 40 | params = readdlm(string(out_path, "params.out"), header=false) 41 | 42 | Seff = params[1,:] # Effective normal stress 43 | tauo = params[2,:] # Initial shear stress 44 | FltX = params[3,:] # Fault location along depth 45 | cca = params[4,:] # Rate-state-friction parameter 'a' 46 | ccb = params[5,:] # Rate-state-friction parameter 'b' 47 | Lc = params[6,:] # Rate-state-friction parameter 'Lc' 48 | 49 | # Index (location) of fault from 0 to 18 km 50 | flt18k = findall(FltX .<= 18)[1] 51 | 52 | time_vel = readdlm(string(out_path, "time_velocity.out"), header=false) 53 | t = time_vel[:,1] # timesteps 54 | Vfmax = time_vel[:,2] # Max. slip rate 55 | Vsurface = time_vel[:,3] # Surface slip rate 56 | 57 | 58 | rho1 = 2670 59 | vs1 = 3464 60 | rho2 = 2500 61 | vs2 = 0.6*vs1 62 | mu = rho2*vs2^2 63 | 64 | delfsec = readdlm(string(out_path, "delfsec.out")) # slip along depth of fault plotted every 0.1 second (edit line 84 in src/main.jl to change) 65 | delfyr = readdlm(string(out_path, "delfyr.out")) # slip along depth plotted every 2 years (edit line 81 to change) 66 | #stress = readdlm(string(out_path, "stress.out"), header=false) # this is shear stress along depth and time: again, very large file so I typically don't save this 67 | 68 | #start_index = get_index(stress', taubefore') 69 | stressdrops = taubefore .- tauafter 70 | 71 | # Mw = moment magnitude 72 | # del_sigma = stress drop 73 | # fault_slip = average slip for one rupture 74 | # rupture_len = length of the rupture 75 | 76 | Mw, del_sigma, fault_slip, rupture_len = 77 | moment_magnitude_new(mu, FltX, delfafter', stressdrops', t); 78 | 79 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | ## Directoory to store the output from simulations 2 | 3 | ## Output file details: 4 | -------------------------------------------------------------------------------- /docs/SPEAR_Functions.md: -------------------------------------------------------------------------------- 1 | # SPEAR: SPectral Element EARthquake Simulator - Function Reference 2 | 3 | ## Overview 4 | 5 | SPEAR is a spectral element method simulator for earthquake cycle dynamics on a 2D vertical strike-slip fault with fully dynamic treatment of seismic events. The code implements rate-and-state friction laws with adaptive time-stepping for both interseismic and coseismic periods. 6 | 7 | ## Setup and Entry Point 8 | 9 | ### `run.jl` - Main execution script 10 | - Entry point for simulations 11 | - Sets simulation resolution and output directory 12 | - Calls `setParameters()` to initialize simulation parameters 13 | - Executes `main()` function to run the simulation 14 | 15 | ### `par.jl` - Parameter setup 16 | - **`setParameters(FZdepth, resolution)`** - Main setup function that initializes all simulation parameters 17 | - Sets domain dimensions (LX=48km depth, LY=30km width) 18 | - Configures mesh resolution and element sizes 19 | - Defines time parameters (150 years total simulation time) 20 | - Sets up material properties and fault parameters 21 | - Returns structured parameter sets for simulation 22 | 23 | ## Initial Conditions and Material Properties 24 | 25 | ### `src/initialConditions/defaultInitialConditions.jl` 26 | - **`fricDepth(FltX)`** - Sets rate-state friction parameters (a, b) as functions of depth 27 | - **`SeffDepth(FltX)`** - Defines effective normal stress profile with depth 28 | - **`tauDepth(FltX)`** - Sets initial shear stress distribution along fault 29 | - **`Int1D(P1, P2, val)`** - Linear interpolation utility function 30 | 31 | ### `src/MaterialProperties.jl` 32 | - **`material_properties(NelX, NelY, NGLL, dxe, dye, ThickX, ThickY, wgll2, rho1, vs1, rho2, vs2)`** - Sets up rectangular fault damage zone with reduced rigidity 33 | - **`rigid(x, y)`** - Defines material properties for trapezoidal damage zone geometry 34 | - **`mat_trap(NelX, NelY, NGLL, iglob, M, dxe, dye, x, y, wgll2)`** - Assembles mass matrix for trapezoidal damage zones 35 | - **`line(x, y)`** - Geometric function defining trapezoid damage zone boundaries 36 | 37 | ## Mesh Generation and Assembly 38 | 39 | ### `src/MeshBox.jl` 40 | - **`MeshBox!(NGLL, Nel, NelX, NelY, FltNglob, dxe, dye)`** - Generates 2D spectral element mesh 41 | - Creates global node connectivity (iglob) 42 | - Generates global coordinates for all GLL nodes 43 | - Handles element-to-element connectivity for rectangular domain 44 | 45 | ### `src/GetGLL.jl` 46 | - **`GetGLL(ngll)`** - Loads precomputed Gauss-Legendre-Lobatto (GLL) quadrature points, weights, and derivative matrices from tabulated data files 47 | 48 | ### `src/Assemble.jl` 49 | - **`Massemble!(NGLL, NelX, NelY, dxe, dye, ThickX, ThickY, rho1, vs1, rho2, vs2, iglob, M, x, y, jac)`** - Assembles global mass matrix and computes stable time step 50 | 51 | ### `src/Kassemble.jl` 52 | - **`stiffness_assembly(NGLL, NelX, NelY, dxe, dye, nglob, iglob, W)`** - Assembles global sparse stiffness matrix 53 | - **`K_element(W, dxe, dye, NGLL, H, Nel)`** - Computes element-level stiffness matrices 54 | - **`FEsparse(Nel, Ke, iglob)`** - Converts local element matrices to global sparse format 55 | 56 | ### `src/BoundaryMatrix.jl` 57 | - **`BoundaryMatrix!(NGLL, NelX, NelY, rho1, vs1, rho2, vs2, dy_deta, dx_dxi, wgll, iglob, side)`** - Creates absorbing boundary condition matrices for domain edges ('L', 'R', 'T', 'B') 58 | 59 | ## Core Simulation Engine 60 | 61 | ### `src/main.jl` 62 | - **`main(P)`** - Main simulation loop 63 | - Initializes kinematic fields (displacement, velocity, acceleration) 64 | - Implements adaptive solver switching between quasi-static (isolver=1) and dynamic (isolver=2) regimes 65 | - Handles fault boundary conditions with rate-state friction 66 | - Manages output at specified time intervals 67 | - Controls earthquake event detection and recording 68 | 69 | ## Fault Mechanics and Solver Functions 70 | 71 | ### `src/NRsearch.jl` - Newton-Raphson Search 72 | - **`FBC!(IDstate, P, NFBC, FltNglob, psi1, Vf1, tau1, psi2, Vf2, tau2, psi, Vf, FltVfree, dt)`** - Fault boundary condition solver using two-step Newton-Raphson iterations 73 | - **`NRsearch!(fo, Vo, cca, ccb, Seff, tau, tauo, psi, FltZ, FltVfree)`** - Core Newton-Raphson algorithm for fault slip velocity computation 74 | 75 | ### `src/otherFunctions.jl` - Rate-State Utilities 76 | - **`slrFunc!(P, NFBC, FltNglob, psi, psi1, Vf, Vf1, IDstate, tau1, dt)`** - Computes slip rates for quasi-static regime 77 | - **`IDS!(xLf, Vo, psi, dt, Vf, cnd, IDstate)`** - Integrates state variable evolution (aging law) 78 | - **`IDS2!(xLf, Vo, psi, psi1, dt, Vf, Vf1, IDstate)`** - Second-order state variable integration 79 | - **`exp1(x)` / `log1(x)`** - Optimized exponential/logarithm functions 80 | 81 | ### `src/dtevol.jl` - Time Step Control 82 | - **`dtevol!(dt, dtmin, XiLf, FaultNglob, NFBC, Vf, isolver)`** - Adaptive time step computation based on CFL condition and fault velocities 83 | - Maximum time step: 50 days 84 | - Time step increase factor: 1.2 85 | - CFL constraint: dt < XiLf/|Vf| 86 | 87 | ## Linear Algebra and Solvers 88 | 89 | ### `src/PCG.jl` - Preconditioned Conjugate Gradient 90 | - **`PCG!(P, Nel, diagKnew, dnew, F, iFlt, FltNI, H, Ht, iglob, nglob, W, a_elem, Conn)`** - Preconditioned conjugate gradient solver for large sparse systems 91 | - **`element_computation!(P, iglob, F_local, H, Ht, W, Nel)`** - Multi-threaded element-level computations 92 | 93 | ## Utilities and Analysis 94 | 95 | ### `src/FindNearestNode.jl` 96 | - **`FindNearestNode(xin, yin, X, Y)`** - Finds nearest mesh nodes to specified coordinates for output locations 97 | 98 | ### `src/damageEvol.jl` 99 | - **`damage_indx!(ThickX, ThickY, dxe, dye, NGLL, NelX, NelY, iglob)`** - Identifies damage indices for fault zone evolution 100 | 101 | ### `src/dump.jl` 102 | - **`stiff_element(NGLL, NelX, NelY, nglob, iglob, dxe, dye)`** - Test function for element stiffness validation (development use only) 103 | 104 | ## Key Parameters and Setup 105 | 106 | ### Material Properties (in `par.jl`): 107 | - **Host rock**: ρ₁ = 2670 kg/m³, vs₁ = 3464 m/s 108 | - **Damage zone**: ρ₂ = 2670 kg/m³, vs₂ = 3464 m/s (adjustable) 109 | - **Domain**: 48 km (depth) × 30 km (width) 110 | 111 | ### Fault Parameters: 112 | - **Plate loading**: Vpl = 1×10⁻⁹ m/s 113 | - **Reference friction**: f₀ = 0.6 114 | - **Reference velocity**: V₀ = 1×10⁻⁶ m/s 115 | - **Characteristic slip**: Dc = 8 mm 116 | - **Rate-state parameters**: a, b values vary with depth 117 | 118 | ### Time Control: 119 | - **Total simulation**: 150 years 120 | - **CFL number**: 0.6 121 | - **Velocity threshold**: 0.001 m/s (earthquake detection) 122 | - **State evolution**: IDstate = 2 (aging law) 123 | 124 | ## Output Files 125 | 126 | The simulation generates several output files in `data/$(simulation_name)/`: 127 | - `stress.out` - Shear stress evolution 128 | - `sliprate.out` - Fault slip rate time series 129 | - `slip.out` - Cumulative slip 130 | - `event_time.out` - Earthquake start/end times and hypocenters 131 | - `coseismic_slip.out` - Slip during individual events 132 | - `params.out` - Simulation parameters 133 | 134 | ## Usage 135 | 136 | 1. Edit `par.jl` to set desired parameters 137 | 2. Edit `src/initialConditions/defaultInitialConditions.jl` for custom initial conditions 138 | 3. Set resolution and output directory in `run.jl` 139 | 4. Run: `julia run.jl` 140 | 5. Analyze results using provided scripts in the analysis directory -------------------------------------------------------------------------------- /docs/SPEAR_Postprocessing.md: -------------------------------------------------------------------------------- 1 | # SPEAR Postprocessing Scripts - Function Reference 2 | 3 | ## Overview 4 | 5 | The `post/` directory contains Julia scripts for analyzing and visualizing earthquake simulation results from SPEAR. These scripts process the output data files to extract earthquake event details, compute seismic parameters, and generate publication-quality plots. 6 | 7 | ## Main Postprocessing Scripts 8 | 9 | ### `post/event_details.jl` - Event Analysis and Calculations 10 | 11 | **Description**: Core analysis functions for extracting earthquake event characteristics from simulation output data. 12 | 13 | #### Main Functions 14 | 15 | **`get_index(seismic_stress, taubefore)`** 16 | - **Purpose**: Finds the index of rupture initiation for each earthquake event 17 | - **Input**: 18 | - `seismic_stress` - stress time series during seismic events 19 | - `taubefore` - stress before each event 20 | - **Method**: Uses L2 norm to match stress patterns between event start and seismic time series 21 | - **Returns**: Array of starting indices for each earthquake event 22 | 23 | **`Coslip(S, Slip, SlipVel, Stress, time_)`** 24 | - **Purpose**: Computes coseismic slip, stress drops, and event timing for all earthquake events 25 | - **Input**: 26 | - `S` - simulation parameters structure 27 | - `Slip` - cumulative slip time series 28 | - `SlipVel` - slip velocity time series 29 | - `Stress` - shear stress time series 30 | - `time_` - simulation time vector 31 | - **Parameters**: 32 | - Event threshold: `Vthres = 0.001` m/s (earthquake detection) 33 | - Event start: max slip rate > 1.01 × threshold 34 | - Event end: max slip rate < 0.99 × threshold 35 | - **Returns**: 36 | - `delfafter` - coseismic slip for each event 37 | - `stressdrops` - stress drop for each event 38 | - `tStart, tEnd` - event start and end times 39 | - `vhypo, hypo` - hypocenter velocity and location 40 | 41 | **`moment_magnitude_new(mu, FltX, delfafter, stressdrops, time_)`** 42 | - **Purpose**: Calculates moment magnitude and rupture characteristics for each earthquake 43 | - **Input**: 44 | - `mu` - shear modulus 45 | - `FltX` - fault depth coordinates 46 | - `delfafter` - coseismic slip from `Coslip()` 47 | - `stressdrops` - stress drops from `Coslip()` 48 | - `time_` - time vector 49 | - **Method**: 50 | - Slip threshold: 1% of maximum slip per event 51 | - Assumes square rupture area (depth dimension = along-strike dimension) 52 | - Seismic moment: M₀ = μ × Area × Depth 53 | - Moment magnitude: Mw = (2/3)×log₁₀(M₀×10⁷) - 10.7 54 | - **Returns**: 55 | - `Mw` - moment magnitude 56 | - `del_sigma` - average stress drop 57 | - `fault_slip` - average coseismic slip 58 | - `rupture_len` - rupture length along depth 59 | 60 | ### `post/plotting_script.jl` - Visualization Functions 61 | 62 | **Description**: Comprehensive plotting functions for creating publication-quality figures from simulation results. 63 | 64 | #### Plot Configuration 65 | 66 | **`plot_params()`** 67 | - **Purpose**: Sets default matplotlib parameters for consistent publication-style plots 68 | - **Settings**: 69 | - Font: STIXGeneral (scientific publication standard) 70 | - Fontsize: 15-17 pt for labels, 13 pt for legends 71 | - Line width: 2.0, axis width: 1.5 72 | - Tick directions: inward 73 | - Auto layout enabled 74 | 75 | #### Main Plotting Functions 76 | 77 | **`slipPlot(delfafter2, rupture_len, FltX, Mw, tStart)`** 78 | - **Purpose**: Creates horizontal bar plots of coseismic slip vs time at multiple depths 79 | - **Features**: 80 | - 4-panel subplot showing slip at 60m, 4km, 6km, and 8km depths 81 | - Color-coded by moment magnitude (inferno_r colormap) 82 | - Filters events with Mw > 2.8 83 | - Time axis inverted (older events at top) 84 | - **Output**: `coseismic_slip.png` (300 DPI) 85 | 86 | **`eqCyclePlot(sliprate, FltX)`** 87 | - **Purpose**: Creates 2D heatmap of slip rate evolution with depth and time 88 | - **Features**: 89 | - Logarithmic color scale (1e-9 to 1e0 m/s) 90 | - Shows earthquake cycles from 16 km depth to surface 91 | - Interpolated color mapping using bicubic interpolation 92 | - Inferno colormap for slip rate visualization 93 | - **Output**: `interpolated_sliprate.png` (300 DPI) 94 | 95 | **`VfmaxPlot(Vfmax, t, yr2sec)`** 96 | - **Purpose**: Plots maximum fault slip rate over simulation time 97 | - **Features**: 98 | - Logarithmic y-axis for slip rate 99 | - Time in years on x-axis 100 | - Shows transition between interseismic and coseismic periods 101 | - **Output**: `Vfmax01.png` (300 DPI) 102 | 103 | **`Vfmaxcomp(Vfmax1, t1, Vfmax2, t2, yr2sec)`** 104 | - **Purpose**: Comparison plot of maximum slip rates from two different simulations 105 | - **Features**: 106 | - Overlay plots with labels ("Thakur", "Abdelmeguid") 107 | - Useful for validation and parameter studies 108 | - **Output**: `Vfmax01.png` (300 DPI) 109 | 110 | **`alphaaPlot(alphaa, t, yr2sec)`** 111 | - **Purpose**: Plots shear modulus contrast evolution over time 112 | - **Application**: For simulations with time-dependent material properties 113 | - **Output**: `alpha_01.png` (300 DPI) 114 | 115 | **`cumSlipPlot(delfsec, delfyr, FltX)`** 116 | - **Purpose**: Shows cumulative slip profiles with depth 117 | - **Features**: 118 | - Two datasets: annual slip (blue) and seismic slip (brown) 119 | - Depth range: 0-24 km 120 | - Inverted y-axis (depth increases downward) 121 | - **Output**: `cumulative_slip.png` (300 DPI) 122 | 123 | **`icsPlot(a_b, Seff, tauo, FltX)`** 124 | - **Purpose**: Plots initial conditions - friction parameters and stress with depth 125 | - **Features**: 126 | - Left axis: Normal and shear stress (MPa) 127 | - Right axis: Rate-state friction parameter (a-b) 128 | - Twin x-axes with different colors 129 | - Depth range: 0-80 km 130 | - **Output**: `ics_02.png` (300 DPI) 131 | 132 | ### `post/rough_script.jl` - Development and Testing Functions 133 | 134 | **Description**: Experimental scripts for testing new analysis approaches and detailed event visualization. 135 | 136 | #### Main Functions 137 | 138 | **`event_indx(tStart, tEnd, time_)`** 139 | - **Purpose**: Finds array indices corresponding to earthquake start and end times 140 | - **Input**: Event times and simulation time vector 141 | - **Returns**: Start and end indices for each event 142 | - **Use**: Facilitates detailed analysis of individual earthquake events 143 | 144 | **`test1(S, O, evno)`** 145 | - **Purpose**: Creates detailed slip rate evolution plot for a specific earthquake event 146 | - **Features**: 147 | - High temporal resolution (0.1 second intervals) 148 | - Slip rate vs depth profile during single event 149 | - Multiple time snapshots overlaid 150 | - Depth range: 0-24 km 151 | - **Input**: 152 | - `S` - simulation parameters 153 | - `O` - output data structure 154 | - `evno` - event number to analyze 155 | - **Output**: `slipvel.pdf` (300 DPI) 156 | 157 | ## Data Processing Workflow 158 | 159 | ### Typical Analysis Sequence: 160 | 161 | 1. **Load simulation output files:** 162 | ```julia 163 | # From data/simulation_name/ 164 | stress = readdlm("stress.out") 165 | sliprate = readdlm("sliprate.out") 166 | slip = readdlm("slip.out") 167 | delfsec = readdlm("delfsec.out") 168 | delfyr = readdlm("delfyr.out") 169 | ``` 170 | 171 | 2. **Extract event characteristics:** 172 | ```julia 173 | include("post/event_details.jl") 174 | delfafter, stressdrops, tStart, tEnd, vhypo, hypo = Coslip(S, slip, sliprate, stress, time_) 175 | Mw, del_sigma, fault_slip, rupture_len = moment_magnitude_new(mu, FltX, delfafter, stressdrops, time_) 176 | ``` 177 | 178 | 3. **Generate visualizations:** 179 | ```julia 180 | include("post/plotting_script.jl") 181 | path = "plots/simulation_name/" # Set output directory 182 | plot_params() # Set plot styling 183 | 184 | # Create plots 185 | slipPlot(delfafter, rupture_len, FltX, Mw, tStart) 186 | VfmaxPlot(Vfmax, time_, yr2sec) 187 | cumSlipPlot(delfsec, delfyr, FltX) 188 | icsPlot(a_b, Seff, tauo, FltX) 189 | ``` 190 | 191 | ## Output Files and Analysis 192 | 193 | ### Key Metrics Computed: 194 | - **Earthquake catalogs**: Mw, rupture length, stress drop, recurrence intervals 195 | - **Slip distributions**: Coseismic vs interseismic slip partitioning 196 | - **Rupture dynamics**: Hypocenter locations, rupture velocities 197 | - **Stress evolution**: Pre- and post-event stress states 198 | 199 | ### Visualization Outputs: 200 | - **Event catalogs**: Slip vs time plots colored by magnitude 201 | - **Spatiotemporal evolution**: 2D heatmaps of slip rate 202 | - **Time series**: Maximum slip rate evolution 203 | - **Depth profiles**: Cumulative slip and initial conditions 204 | - **Individual events**: Detailed rupture progression 205 | 206 | ## Dependencies 207 | 208 | **Required Packages:** 209 | - `PyPlot` - Python matplotlib interface 210 | - `StatsBase` - Statistical functions 211 | - `LaTeXStrings` - LaTeX formatting for labels 212 | - `PyCall` - Python integration 213 | - `LinearAlgebra` - Matrix operations 214 | 215 | **Python Dependencies:** 216 | - `matplotlib` - Plotting backend 217 | - Scientific color maps (inferno, etc.) 218 | 219 | ## Usage Notes 220 | 221 | 1. **Set output path**: Define `path` variable before calling plotting functions 222 | 2. **Color normalization**: Magnitude-based coloring automatically scales to data range 223 | 3. **Resolution**: All plots save at 300 DPI for publication quality 224 | 4. **Filtering**: Event analysis typically filters by magnitude thresholds 225 | 5. **Memory**: Large datasets may require chunked processing for memory efficiency 226 | 227 | This postprocessing suite provides comprehensive tools for earthquake cycle analysis, from basic event detection to detailed rupture characterization and publication-ready visualization. -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # List of functions used in the package 2 | -------------------------------------------------------------------------------- /docs/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'SPEAR: A Julia package for 2D earthquake cycle simulations' 3 | tags: 4 | - Julia 5 | - geophysics 6 | - seismology 7 | - earthquake cycle 8 | - numerical simulations 9 | authors: 10 | - name: Prithvi Thakur 11 | orcid: 0000-0000-0000-0000 12 | equal-contrib: true 13 | affiliation: "1, 2" # (Multiple affiliations must be quoted) 14 | - name: Yihe Huang 15 | equal-contrib: true # (This is how you can denote equal contributions between multiple authors) 16 | affiliation: 2 17 | - name: Yoshihiro Kaneko 18 | equal-contrib: true # (This is how you can denote equal contributions between multiple authors) 19 | affiliation: 3 20 | - name: Peng Zhai 21 | equal-contrib: true # (This is how you can denote equal contributions between multiple authors) 22 | affiliation: 2 23 | affiliations: 24 | - name: Center for Computation and Visualization, Brown University 25 | index: 1 26 | - name: Department of Earth and Environmental Sciences, Uniersity of Michigan 27 | index: 2 28 | - name: Department of Geophysics, Kyoto University 29 | index: 3 30 | date: 10 October 2025 31 | bibliography: paper.bib 32 | 33 | # Optional fields if submitting to a AAS journal too, see this blog post: 34 | # https://blog.joss.theoj.org/2018/12/a-new-collaboration-with-aas-publishing 35 | #aas-doi: 10.3847/xxxxx <- update this with the DOI from AAS once you know it. 36 | #aas-journal: Astrophysical Journal <- The name of the AAS journal. 37 | --- 38 | 39 | # Summary 40 | Simulating long-term earthquake sequences numerically is a topical problem in the earth sciences. Such simulations encompass a wide range of spatial and temporal scales, with spatial scales ranging from millimeters along frictional contact to kilometers of fault-length, and temporal scales ranging from milliseconds during earthquake ruptures to decades during the aseismic period. Existing methods to simulate such multi-scale, nonlinear problem can be broadly classified into boundary-based methods (Rice, 1993; Lapusta et al., 2000; Barbot, 2019), volume-based methods (Kaneko et al., 2011; Erickson and Dunham2014; Thakur et al., 2020), and hybrid methods (Ma and Elbanna, 2015; Abdelmeguid et al., 2019). The boundary-based methods are very efficient in terms of time complexity and are suitable to study fault-friction and slip history in two and three dimensions. However, such methods cannot capture the heterogeneities in the bulk domain, and the effects of fault zone structures commonly observed in natural faults. Volume-based methods, like finite- or spectral-element are more suitable for such problems, at the cost of computation time. Additionally, several boundary and volume based methods employ a damping approximation to emulate the wave propagation using a quasi-dynamic approach. 41 | 42 | This package contains a Julia implementation of spectral element method to solve two-dimensional fault-slip problem with linear elasticity, accounting for the dynamic inertial 43 | effects and bulk heterogeneities. 44 | 45 | 46 | # Statement of need 47 | Spear is a Julia package for 2D simulations of long-term fault-slip on strike-slip fault systems. Julia enables high-performance speeds while writing at a high-level programming interface, and is suitable for complex numerical simulations. Our package helps us perform complex numerical simulations with off-fault material heterogeneities and full inertial effects of seismic waves. Written in easy-to-use language Julia, and with minimal dependencies, our package is designed for users familiar with computational seismology, and users with minimal Julia or programming experience should be able to get started. 48 | 49 | The purpose of this package is for scientists conducting research in long-term fault-slip dynamics with a focus on off-fault material heterogeneities and fault friction. We can study a wide variety of scientific problems like the effects of dynamic wave reflections due to the low-velocity fault zones, asymmetrical and complex fault zone structures, and time-dependent bulk property changes during the seismic cycle using our package. We have also performed benchmarks for our code in comparison to the other community softwares (Erickson et al., 2023). 50 | 51 | # Features 52 | - Antiplane strain deformation on planar fault with SH waves 53 | - Fully dynamic treatment of seismic events 54 | - Rate-and-state-dependent friction with aging laws 55 | - Adaptive time-stepping to switch between interseismic and seismic events 56 | - Customizable to include off-fault and on-fault heterogeneities 57 | - Complex geometry of fault damage zones including gaussian and trapezoid fault damage zones 58 | - Time-dependent healing of fault damage zones constrained by observations 59 | - Precursory seismic velocity changes in the fault zone 60 | 61 | 62 | # Methodology 63 | We consider a two‐dimensional strike‐slip fault embedded in an elastic medium with Mode III rupture (Figure 1). This implies that the fault motion is out of the plane and only the depth variations of parameters are considered. The top boundary is stress‐free and represents Earth's free surface. The other three boundaries are absorbing boundaries that allow the waves to pass through. Since our model is symmetric across the fault, we restrict the computational domain to only one side of the fault. We model the fault damage zone as an elastic layer with lower seismic wave velocities compared to the host rock. On the fault boundary, we consider a rate- and state-dependent friction law that relates the shear strength on the fault to the 64 | fault slip rate (Dieterich, 1979; Ruina, 1983; Scholz, 1998). We use the regularized form for the shear strength interpreted as a thermally activated creep model (Lapusta et al., 2000; Rice & Ben‐Zion, 1996). 65 | 66 | We use a spectral element method to simulate dynamic ruptures and aseismic creep on the fault (Kaneko et al., 2011). Full inertial effects are considered during earthquake rupture and an adaptive time stepping technique is used to switch from interseismic to seismic events based on a threshold maximum slip velocity of 5 mm s−1 on the fault. This fully dynamic modeling approach can simulate interseismic slip, earthquake nucleation, rupture propagation, and postseismic deformation during multiple seismic cycles in a single computational framework. We use a two-dimensional quadrilateral mesh with five Gauss-Lobatto-Legendre interpolation points inside each spectral-element. We implement Kaneko et al.'s (2011) algorithm in Julia (Bezanson et al., 2017) using a more efficient linear solver based on the Algebraic Multigrid scheme (Ruge & Stüben, 1987) for the elliptic (interseismic) part of the earthquake sequence. We use the Algebraic Multigrid as a preconditioner while solving the sparse linear system using the conjugate gradient method. This combines the superior convergence properties of the Algebraic Multigrid with the stability of Krylov methods and is very well suited for symmetric, positive definite matrices. This iterative technique uses a fixed number of iterations independent of the mesh size. Landry and Barbot (2016, 2019) have derived the equations to solve elliptic equations using the Geometric Multigrid in 2‐D and 3‐D. While the Geometric Multigrid has superior convergence properties, the Algebraic Multigrid is better suited for more complicated meshes and is scalable to a wide variety of problems as the solver works with the numerical coefficients of the linear system as opposed to the mesh structure. The detailed algorithm is described in Tatebe (1993). In addition, we use the built‐in multithreading feature of Julia. 67 | 68 | The software is open-source and available on Github under GNU license, and can be accessed at: https://github.com/thehalfspace/Spear. The instructions to run the simulations are provided in the README. Open source contributions are welcome from users and can be added under github issues and pull-requests. 69 | 70 | # Citations 71 | 72 | Citations to entries in paper.bib should be in 73 | [rMarkdown](http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html) 74 | format. 75 | 76 | If you want to cite a software repository URL (e.g. something on GitHub without a preferred 77 | citation) then you can do it with the example BibTeX entry below for @fidgit. 78 | 79 | For a quick reference, the following citation commands can be used: 80 | - `@author:2001` -> "Author et al. (2001)" 81 | - `[@author:2001]` -> "(Author et al., 2001)" 82 | - `[@author1:2001; @author2:2001]` -> "(Author1 et al., 2001; Author2 et al., 2002)" 83 | 84 | # Figures 85 | 86 | Figures can be included like this: 87 | ![Caption for example figure.\label{fig:example}](figure.png) 88 | and referenced from text using \autoref{fig:example}. 89 | 90 | Figure sizes can be customized by adding an optional second parameter: 91 | ![Caption for example figure.](figure.png){ width=20% } 92 | 93 | # Acknowledgements 94 | 95 | We acknowledge contributions from Brigitta Sipocz, Syrtis Major, and Semyeong 96 | Oh, and support from Kathryn Johnston during the genesis of this project. 97 | 98 | # References 99 | -------------------------------------------------------------------------------- /docs/refs.bib: -------------------------------------------------------------------------------- 1 | @article{Rice1993, 2 | author = {Rice, J. R.}, 3 | year = {1993}, 4 | title = {Spatio-temporal complexity of slip on a fault}, 5 | journal = {Journal of Geophysical Research: Solid Earth}, 6 | volume = {98}, 7 | number = {B6}, 8 | pages = {9885--9907}, 9 | doi = {10.1029/93JB00191} 10 | } 11 | 12 | @article{Lapusta2000, 13 | author = {Lapusta, N. and Rice, J. R. and Ben-Zion, Y. and Zheng, G.}, 14 | year = {2000}, 15 | title = {Elastodynamic analysis for slow tectonic loading with spontaneous rupture episodes on faults with rate- and state-dependent friction}, 16 | journal = {Journal of Geophysical Research: Solid Earth}, 17 | volume = {105}, 18 | number = {B10}, 19 | pages = {23765--23789}, 20 | doi = {10.1029/2000JB900250} 21 | } 22 | 23 | @article{Barbot2019, 24 | author = {Barbot, S.}, 25 | year = {2019}, 26 | title = {Slow-slip, slow earthquakes, period-two cycles, full and partial ruptures, and deterministic chaos in a single asperity fault}, 27 | journal = {Tectonophysics}, 28 | volume = {768}, 29 | pages = {228171}, 30 | doi = {10.1016/j.tecto.2019.228171} 31 | } 32 | 33 | @article{Kaneko2011, 34 | author = {Kaneko, Y. and Lapusta, N. and Ampuero, J. P.}, 35 | year = {2011}, 36 | title = {Spectral-element modeling of spontaneous earthquake rupture on rate and state faults: Effect of velocity-strengthening friction at shallow depths}, 37 | journal = {Journal of Geophysical Research: Solid Earth}, 38 | volume = {116}, 39 | number = {B10}, 40 | doi = {10.1029/2011JB008197} 41 | } 42 | 43 | @article{Erickson2014, 44 | author = {Erickson, B. A. and Dunham, E. M.}, 45 | year = {2014}, 46 | title = {An efficient numerical method for earthquake cycles in heterogeneous media with realistic rheologies}, 47 | journal = {Journal of Geophysical Research: Solid Earth}, 48 | volume = {119}, 49 | number = {4}, 50 | pages = {3290--3316}, 51 | doi = {10.1002/2013JB010732} 52 | } 53 | 54 | @article{Thakur2020, 55 | author = {Thakur, P. and Huang, Y. and Kaneko, Y.}, 56 | year = {2020}, 57 | title = {Effects of low-velocity fault damage zones on long-term earthquake behaviors on mature strike-slip faults}, 58 | journal = {Journal of Geophysical Research: Solid Earth}, 59 | volume = {125}, 60 | number = {8}, 61 | doi = {10.1029/2020JB019418} 62 | } 63 | 64 | @article{Thakur2021, 65 | author = {Thakur, P. and Huang, Y.}, 66 | year = {2021}, 67 | title = {Influence of fault zone maturity on fully dynamic earthquake cycles}, 68 | journal = {Geophysical Research Letters}, 69 | volume = {48}, 70 | number = {16}, 71 | doi = {10.1029/2021GL094032} 72 | } 73 | 74 | @article{Thakur2024, 75 | author = {Thakur, P. and Huang, Y.}, 76 | year = {2024}, 77 | title = {The effects of precursory velocity changes on earthquake nucleation and stress evolution in dynamic earthquake cycle simulations}, 78 | journal = {Earth and Planetary Science Letters}, 79 | volume = {640}, 80 | pages = {118480}, 81 | doi = {10.1016/j.epsl.2024.118480} 82 | } 83 | 84 | @inproceedings{Zhai2023, 85 | author = {Zhai, P. and Huang, Y.}, 86 | year = {2023}, 87 | title = {The effects of characteristic slip distance on earthquake nucleation styles in fully dynamic seismic cycles}, 88 | booktitle = {2023 AGU Annual Meeting}, 89 | address = {San Francisco, CA} 90 | } 91 | 92 | @article{Abdelmeguid2019, 93 | author = {Abdelmeguid, M. and Ma, X. and Barall, M. and Dunham, E. M. and Elbanna, A. E.}, 94 | year = {2019}, 95 | title = {A hybrid numerical method for modeling dynamic earthquake rupture with off-fault plasticity}, 96 | journal = {Journal of Geophysical Research: Solid Earth}, 97 | volume = {124}, 98 | number = {10}, 99 | pages = {10564--10588}, 100 | doi = {10.1029/2019JB018036} 101 | } 102 | 103 | @article{Ma2015, 104 | author = {Ma, X. and Elbanna, A. E.}, 105 | year = {2015}, 106 | title = {A hybrid numerical scheme for modeling dynamic rupture and off-fault plasticity}, 107 | journal = {Journal of Geophysical Research: Solid Earth}, 108 | volume = {120}, 109 | number = {9}, 110 | pages = {6363--6388}, 111 | doi = {10.1002/2015JB012200} 112 | } 113 | 114 | @article{Dieterich1979, 115 | author = {Dieterich, J. H.}, 116 | year = {1979}, 117 | title = {Modeling of rock friction: 1. Experimental results and constitutive equations}, 118 | journal = {Journal of Geophysical Research}, 119 | volume = {84}, 120 | number = {B5}, 121 | pages = {2161--2168}, 122 | doi = {10.1029/JB084iB05p02161} 123 | } 124 | 125 | @article{Ruina1983, 126 | author = {Ruina, A.}, 127 | year = {1983}, 128 | title = {Slip instability and state variable friction laws}, 129 | journal = {Journal of Geophysical Research: Solid Earth}, 130 | volume = {88}, 131 | number = {B12}, 132 | pages = {10359--10370}, 133 | doi = {10.1029/JB088iB12p10359} 134 | } 135 | 136 | @article{Scholz1998, 137 | author = {Scholz, C. H.}, 138 | year = {1998}, 139 | title = {Earthquakes and friction laws}, 140 | journal = {Nature}, 141 | volume = {391}, 142 | number = {6662}, 143 | pages = {37--42}, 144 | doi = {10.1038/34097} 145 | } 146 | 147 | @incollection{Ruge1987, 148 | author = {Ruge, J. W. and St{\"u}ben, K.}, 149 | year = {1987}, 150 | title = {Algebraic multigrid (AMG)}, 151 | booktitle = {Multigrid methods}, 152 | editor = {McCormick, S. F.}, 153 | pages = {73--130}, 154 | publisher = {SIAM} 155 | } 156 | 157 | @article{Tatebe1993, 158 | author = {Tatebe, O.}, 159 | year = {1993}, 160 | title = {The multigrid preconditioned conjugate gradient method}, 161 | journal = {Computer Physics Communications}, 162 | volume = {74}, 163 | number = {2}, 164 | pages = {233--244}, 165 | doi = {10.1016/0010-4655(93)90066-V} 166 | } 167 | 168 | @article{Bezanson2017, 169 | author = {Bezanson, J. and Edelman, A. and Karpinski, S. and Shah, V. B.}, 170 | year = {2017}, 171 | title = {Julia: A fresh approach to numerical computing}, 172 | journal = {SIAM Review}, 173 | volume = {59}, 174 | number = {1}, 175 | pages = {65--98}, 176 | doi = {10.1137/141000671} 177 | } 178 | 179 | @article{RiceBenZion1996, 180 | author = {Rice, J. R. and Ben-Zion, Y.}, 181 | year = {1996}, 182 | title = {Slip complexity in earthquake fault models}, 183 | journal = {Proceedings of the National Academy of Sciences}, 184 | volume = {93}, 185 | number = {9}, 186 | pages = {3811--3818}, 187 | doi = {10.1073/pnas.93.9.3811} 188 | } 189 | 190 | @article{Landry2016, 191 | author = {Landry, W. and Barbot, S.}, 192 | year = {2016}, 193 | title = {The role of viscoelasticity on fault stress evolution and earthquake interactions}, 194 | journal = {Geophysical Journal International}, 195 | volume = {204}, 196 | number = {3}, 197 | pages = {1322--1336}, 198 | doi = {10.1093/gji/ggv527} 199 | } 200 | 201 | @article{Landry2019, 202 | author = {Landry, W. and Barbot, S.}, 203 | year = {2019}, 204 | title = {Thermomechanical effects of shear heating in the lower crust}, 205 | journal = {Geophysical Journal International}, 206 | volume = {219}, 207 | number = {1}, 208 | pages = {442--463}, 209 | doi = {10.1093/gji/ggz291} 210 | } 211 | 212 | -------------------------------------------------------------------------------- /install_dependencies.jl: -------------------------------------------------------------------------------- 1 | import Pkg 2 | Pkg.add(["Printf", "LinearAlgebra", "DelimitedFiles", "SparseArrays", 3 | "AlgebraicMultigrid","StaticArrays", "IterativeSolvers", 4 | "FEMSparse", "PyPlot", "StatsBase", "LaTeXStrings", "PyCall"]) 5 | 6 | -------------------------------------------------------------------------------- /output.jl: -------------------------------------------------------------------------------- 1 | ################################# 2 | # READ OUTPUT FROM SIMULATION 3 | ################################# 4 | 5 | mutable struct results 6 | seismic_stress::Array{Float64,2} 7 | seismic_slipvel::Array{Float64,2} 8 | seismic_slip::Array{Float64,2} 9 | index_eq::Array{Float64} 10 | is_stress::Array{Float64,2} 11 | is_slipvel::Array{Float64,2} 12 | is_slip::Array{Float64,2} 13 | dSeis::Matrix{Float64} 14 | vSeis::Matrix{Float64} 15 | aSeis::Matrix{Float64} 16 | tStart::Array{Float64} 17 | tEnd::Array{Float64} 18 | taubefore::Array{Float64,2} 19 | tauafter::Array{Float64,2} 20 | delfafter::Array{Float64,2} 21 | hypo::Array{Float64} 22 | time_::Array{Float64} 23 | Vfmax::Array{Float64} 24 | end 25 | 26 | struct params_int{T<:Int} 27 | # Domain size 28 | Nel::T 29 | FltNglob::T 30 | 31 | # Time parameters 32 | yr2sec::T 33 | Total_time::T 34 | IDstate::T 35 | 36 | # Fault setup parameters 37 | nglob::T 38 | 39 | end 40 | 41 | struct params_float{T<:AbstractFloat} 42 | # Jacobian for global -> local coordinate conversion 43 | # jac::T 44 | # coefint1::T 45 | # coefint2::T 46 | ETA::T 47 | 48 | # Earthquake parameters 49 | Vpl::T 50 | Vthres::T 51 | Vevne::T 52 | 53 | # Setup parameters 54 | dt0::T 55 | end 56 | 57 | struct params_farray{T<:Array{Float64}} 58 | fo::T 59 | Vo::T 60 | xLf::T 61 | 62 | M::T 63 | 64 | BcLC::T 65 | BcTC::T 66 | 67 | FltB::T 68 | FltZ::T 69 | FltX::T 70 | 71 | cca::T 72 | ccb::T 73 | Seff::T 74 | tauo::T 75 | XiLf::T 76 | # diagKnew::T 77 | 78 | xout::T 79 | yout::T 80 | end 81 | 82 | struct params_iarray{T<:Array{Int}} 83 | iFlt::T 84 | iBcL::T 85 | iBcT::T 86 | FltIglobBC::T 87 | FltNI::T 88 | out_seis::T 89 | end 90 | -------------------------------------------------------------------------------- /par.jl: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | # PARAMETER FILE: SET THE PHYSICAL PARAMETERS FOR THE SIMULATION 3 | ####################################################################### 4 | include("$(@__DIR__)/src/GetGLL.jl") # Polynomial interpolation 5 | include("$(@__DIR__)/src/MeshBox.jl") # Build 2D mesh 6 | include("$(@__DIR__)/src/MaterialProperties.jl") # Build 2D mesh 7 | include("$(@__DIR__)/src/Assemble.jl") # Assemble mass and stiffness matrix 8 | include("$(@__DIR__)/src/Kassemble.jl") # Assemble mass and stiffness matrix 9 | # include("$(@__DIR__)/trapezoidFZ/Assemble.jl") # Gaussian fault zone assemble 10 | include("$(@__DIR__)/src/BoundaryMatrix.jl") # Boundary matrices 11 | include("$(@__DIR__)/src/FindNearestNode.jl") # Nearest node for output 12 | include("$(@__DIR__)/src/initialConditions/defaultInitialConditions.jl") 13 | include("$(@__DIR__)/src/damageEvol.jl") # Stiffness index of damaged medium 14 | 15 | 16 | function setParameters(FZdepth, res) 17 | 18 | LX::Int = 48e3 # depth dimension of rectangular domain 19 | LY::Int = 30e3 # off fault dimenstion of rectangular domain 20 | 21 | NelX::Int = 30*res # no. of elements in x 22 | NelY::Int = 20*res # no. of elements in y 23 | 24 | dxe::Float64 = LX/NelX # Size of one element along X 25 | dye::Float64 = LY/NelY # Size of one element along Y 26 | Nel::Int = NelX*NelY # Total no. of elements 27 | 28 | println("dxe = ", dxe) 29 | println("dye = ", dye) 30 | 31 | P::Int = 4 # Lagrange polynomial degree 32 | NGLL::Int = P + 1 # No. of Gauss-Legendre-Lobatto nodes 33 | FltNglob::Int = NelX*(NGLL - 1) + 1 34 | 35 | # Jacobian for global -> local coordinate conversion 36 | dx_dxi::Float64 = 0.5*dxe 37 | dy_deta::Float64 = 0.5*dye 38 | jac::Float64 = dx_dxi*dy_deta 39 | coefint1::Float64 = jac/dx_dxi^2 40 | coefint2::Float64 = jac/dy_deta^2 41 | 42 | #.................. 43 | # TIME PARAMETERS 44 | #.................. 45 | 46 | yr2sec::Int = 365*24*60*60 47 | 48 | Total_time::Int = 150*yr2sec # Set the total time for simulation here 49 | 50 | CFL::Float64 = 0.6 # Courant stability number 51 | 52 | IDstate::Int = 2 # State variable equation type 53 | 54 | # Some other time variables used in the loop 55 | dtincf::Float64 = 1.2 56 | gamma_::Float64 = pi/4 57 | dtmax::Int = 400 * 24 * 60*60 # 100 days 58 | 59 | 60 | #................... 61 | # MEDIUM PROPERTIES 62 | #................... 63 | 64 | # default 65 | rho1::Float64 = 2670 66 | vs1::Float64 = 3464 67 | 68 | # The entire medium has low rigidity 69 | # rho1::Float64 = 2500 70 | # vs1::Float64 = 0.6*3464 71 | 72 | rho2::Float64 = 2670 73 | vs2::Float64 = 1.00*vs1 74 | 75 | ETA = 0. 76 | 77 | # Low velocity layer dimensions 78 | ThickX::Float64 = LX - 0*ceil(FZdepth/dxe)*dxe # ~FZdepth m deep 79 | ThickY::Float64 = 0.0*ceil(0.0e3/dye)*dye # ~ 0.25*2 km wide 80 | 81 | #....................... 82 | # EARTHQUAKE PARAMETERS 83 | #....................... 84 | 85 | Vpl::Float64 = 1e-9 # Plate loading 86 | 87 | fo::Vector{Float64} = repeat([0.6], FltNglob) # Reference friction coefficient 88 | Vo::Vector{Float64} = repeat([1e-6], FltNglob) # Reference velocity 'Vo' 89 | xLf::Vector{Float64} = repeat([0.008], FltNglob) # Dc (Lc) = 8 mm 90 | 91 | Vthres::Float64 = 0.001 92 | Vevne::Float64 = Vthres 93 | 94 | #-----------# 95 | #-----------# 96 | # SETUP 97 | #-----------# 98 | #-----------# 99 | 100 | #.................... 101 | # 2D Mesh generation 102 | #.................... 103 | iglob::Array{Int,3}, x::Vector{Float64}, y::Vector{Float64} = 104 | MeshBox!(NGLL, Nel, NelX, NelY, FltNglob, dxe, dye) 105 | x = x .- LX 106 | #return x 107 | nglob::Int = length(x) 108 | 109 | # The derivatives of the Lagrange Polynomials were pre-tabulated 110 | # xgll = location of the GLL nodes inside the reference segment [-1,1] 111 | xgll::Vector{Float64}, wgll::Vector{Float64}, H::Matrix{Float64} = GetGLL(NGLL) 112 | wgll2::SMatrix{NGLL,NGLL,Float64} = wgll*wgll' 113 | 114 | #............................. 115 | # OUTPUT RECEIVER LOCATIONS 116 | #............................. 117 | # For now, it saves slip, sliprate, and stress at the nearest node specified. 118 | # My coordinates are weird, might change them later. 119 | # x coordinate = along dip fault length (always -ve below the free surface) 120 | # y coordinate = off-fault distance (+ve) 121 | 122 | 123 | x_out = [48.0, 48.0, 48.0, 48.0, 48.0, 48.0].*(-1e3) # x coordinate of receiver 124 | y_out = [0.0, 150.0, 300.0, 0.0, 0.0, 0.0] # y coordinate of receiver 125 | # n_receiver = length(x_receiver) # number of receivers 126 | 127 | x_out, y_out, out_seis, dist = FindNearestNode(x_out, y_out, x, y) 128 | 129 | 130 | #................. 131 | # Initialization 132 | #................. 133 | 134 | # For internal forces 135 | # W::Array{Float64,3} = zeros(NGLL, NGLL, Nel) 136 | 137 | # Global Mass Matrix 138 | M::Vector{Float64} = zeros(nglob) 139 | 140 | # Mass+Damping matrix 141 | # MC::Vector{Float64} = zeros(nglob) 142 | 143 | # Assemble mass and stiffness matrix 144 | M, dt::Float64, muMax = Massemble!(NGLL, NelX, NelY, dxe, dye, 145 | ThickX,ThickY, rho1, vs1, rho2, vs2, iglob,M, x, y, jac) 146 | 147 | # Material properties for a narrow rectangular damaged zone of 148 | # half-thickness ThickY and depth ThickX 149 | W = material_properties(NelX, NelY,NGLL,dxe, dye, ThickX, ThickY, wgll2, rho1, vs1, rho2, vs2) 150 | 151 | # Material properties for trapezoid damaged zone 152 | # M, W = mat_trap(NelX, NelY,NGLL, iglob, M, dxe, dye, x,y, wgll2) 153 | 154 | # Stiffness Assembly 155 | Ksparse::SparseMatrixCSC{Float64} = stiffness_assembly(NGLL, NelX, NelY, dxe,dye, nglob, iglob, W) 156 | 157 | # Damage Indexed Kdam 158 | did = damage_indx!(ThickX, ThickY, dxe, dye, NGLL, NelX, NelY, iglob) 159 | 160 | # return Ksparse, Kdam, iglob 161 | # Kdam[Kdam .> 1.0] .= 1.0 162 | 163 | # Time solver variables 164 | dt = CFL*dt 165 | dtmin = dt 166 | half_dt = 0.5*dtmin 167 | half_dt_sq = 0.5*dtmin^2 168 | 169 | #...................... 170 | # Boundary conditions : 171 | #...................... 172 | 173 | # Left boundary 174 | BcLC::Vector{Float64}, iBcL::Vector{Int} = BoundaryMatrix!(NGLL, NelX, NelY, rho1, vs1, rho2, vs2, dy_deta, dx_dxi, wgll, iglob, 'L') 175 | 176 | # Right Boundary = free surface: nothing to do 177 | # BcRC, iBcR = BoundaryMatrix(P, wgll, iglob, 'R') 178 | 179 | # Top Boundary 180 | BcTC::Vector{Float64}, iBcT::Vector{Int} = BoundaryMatrix!(NGLL, NelX, NelY, rho1, vs1, rho2, vs2, dy_deta, dx_dxi, wgll, iglob, 'T') 181 | 182 | # Mass matrix at boundaries 183 | # Mq = M[:] 184 | M[iBcL] .= M[iBcL] .+ half_dt*BcLC 185 | M[iBcT] .= M[iBcT] .+ half_dt*BcTC 186 | # M[iBcR] .= M[iBcR] .+ half_dt*BcRC 187 | 188 | 189 | # Dynamic fault at bottom boundary 190 | FltB::Vector{Float64}, iFlt::Vector{Int} = BoundaryMatrix!(NGLL, NelX, NelY, rho1, vs1, rho2, vs2, dy_deta, dx_dxi, wgll, iglob, 'B') 191 | 192 | FltZ::Vector{Float64} = M[iFlt]./FltB /half_dt * 0.5 193 | FltX::Vector{Float64} = x[iFlt] 194 | 195 | #...................... 196 | # Initial Conditions 197 | #...................... 198 | cca::Vector{Float64}, ccb::Vector{Float64} = fricDepth(FltX) # rate-state friction parameters 199 | Seff::Vector{Float64} = SeffDepth(FltX) # effective normal stress 200 | tauo::Vector{Float64} = tauDepth(FltX) # initial shear stress 201 | 202 | # Kelvin-Voigt Viscosity 203 | Nel_ETA::Int = 0 204 | if ETA !=0 205 | Nel_ETA = NelX 206 | x1 = 0.5*(1 .+ xgll') 207 | eta_taper = exp.(-pi*x1.^2) 208 | eta = ETA*dt*repeat([eta_taper], NGLL) 209 | 210 | else 211 | Nel_ETA = 0 212 | end 213 | 214 | # Compute XiLF used in timestep calculation 215 | XiLf::Vector{Float64} = XiLfFunc!(LX, FltNglob, gamma_, xLf, muMax, cca, ccb, Seff) 216 | 217 | # Find nodes that do not belong to the fault 218 | FltNI::Vector{Int} = deleteat!(collect(1:nglob), iFlt) 219 | 220 | # Compute diagonal of K 221 | # diagKnew::Vector{Float64} = KdiagFunc!(FltNglob, NelY, NGLL, Nel, coefint1, coefint2, iglob, W, H, Ht, FltNI) 222 | 223 | # Fault boundary: indices where fault within 24 km 224 | fbc = reshape(iglob[:,1,:], length(iglob[:,1,:])) 225 | idx = findall(fbc .== findall(x .== -24e3)[1] - 1)[1] 226 | FltIglobBC::Vector{Int} = fbc[1:idx] 227 | 228 | # Display important parameters 229 | println("Total number of nodes on fault: ", FltNglob) 230 | println("Average node spacing: ", LX/(FltNglob-1), " m") 231 | println("ThickY: ", ThickY, " m") 232 | @printf("dt: %1.09f s\n", dt) 233 | 234 | 235 | return params_int(Nel, FltNglob, yr2sec, Total_time, IDstate, nglob), 236 | params_float(ETA, Vpl, Vthres, Vevne, dt), 237 | params_farray(fo, Vo, xLf, M, BcLC, BcTC, FltB, FltZ, FltX, cca, ccb, Seff, tauo, XiLf, x_out, y_out), 238 | params_iarray(iFlt, iBcL, iBcT, FltIglobBC, FltNI, out_seis), Ksparse, iglob, NGLL, wgll2, nglob, did 239 | 240 | end 241 | 242 | 243 | 244 | struct params_int{T<:Int} 245 | # Domain size 246 | Nel::T 247 | FltNglob::T 248 | 249 | # Time parameters 250 | yr2sec::T 251 | Total_time::T 252 | IDstate::T 253 | 254 | # Fault setup parameters 255 | nglob::T 256 | 257 | end 258 | 259 | struct params_float{T<:AbstractFloat} 260 | # Jacobian for global -> local coordinate conversion 261 | # jac::T 262 | # coefint1::T 263 | # coefint2::T 264 | 265 | ETA::T 266 | 267 | # Earthquake parameters 268 | Vpl::T 269 | Vthres::T 270 | Vevne::T 271 | 272 | # Setup parameters 273 | dt0::T 274 | end 275 | 276 | struct params_farray{T<:Vector{Float64}} 277 | fo::T 278 | Vo::T 279 | xLf::T 280 | 281 | M::T 282 | 283 | BcLC::T 284 | BcTC::T 285 | 286 | FltB::T 287 | FltZ::T 288 | FltX::T 289 | 290 | cca::T 291 | ccb::T 292 | Seff::T 293 | tauo::T 294 | 295 | XiLf::T 296 | # diagKnew::T 297 | 298 | xout::T 299 | yout::T 300 | end 301 | 302 | struct params_iarray{T<:Vector{Int}} 303 | iFlt::T 304 | iBcL::T 305 | iBcT::T 306 | FltIglobBC::T 307 | FltNI::T 308 | out_seis::T 309 | end 310 | 311 | # Calculate XiLf used in computing the timestep 312 | function XiLfFunc!(LX, FltNglob, gamma_, xLf, muMax, cca, ccb, Seff) 313 | 314 | hcell = LX/(FltNglob-1) 315 | Ximax = 0.5 316 | Xithf = 1 317 | 318 | Xith:: Vector{Float64} = zeros(FltNglob) 319 | XiLf::Vector{Float64} = zeros(FltNglob) 320 | 321 | # @inbounds for j = 1:FltNglob 322 | @inbounds for j = 1:FltNglob 323 | 324 | # Compute time restricting parameters 325 | expr1 = -(cca[j] - ccb[j])/cca[j] 326 | expr2 = gamma_*muMax/hcell*xLf[j]/(cca[j]*Seff[j]) 327 | ro = expr2 - expr1 328 | 329 | if (0.25*ro*ro - expr2) >= 0 330 | Xith[j] = 1/ro 331 | else 332 | Xith[j] = 1 - expr1/expr2 333 | end 334 | 335 | # For each node, compute slip that node cannot exceed in one timestep 336 | if Xithf*Xith[j] > Ximax 337 | XiLf[j] = Ximax*xLf[j] 338 | else 339 | XiLf[j] = Xithf*Xith[j]*xLf[j] 340 | end 341 | end 342 | 343 | 344 | return XiLf 345 | end 346 | -------------------------------------------------------------------------------- /plots/README.md: -------------------------------------------------------------------------------- 1 | ### Directory for saving plots from the output 2 | -------------------------------------------------------------------------------- /plots/example/Vfmax01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thehalfspace/Spear/0b7dc5671761d1a06fe2f700e0ef39557eb67cda/plots/example/Vfmax01.png -------------------------------------------------------------------------------- /plots/example/cumulative_slip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thehalfspace/Spear/0b7dc5671761d1a06fe2f700e0ef39557eb67cda/plots/example/cumulative_slip.png -------------------------------------------------------------------------------- /post/README.md: -------------------------------------------------------------------------------- 1 | ## Postprocessing folder 2 | 3 | ### Scripts for plotting etc. 4 | 5 | -------------------------------------------------------------------------------- /post/event_details.jl: -------------------------------------------------------------------------------- 1 | ################################# 2 | # MODULE FOR SOME CALCULATIONS 3 | # FROM SIMULATION OUTPUT 4 | ################################# 5 | using LinearAlgebra 6 | 7 | # get index of start of rupture 8 | function get_index(seismic_stress, taubefore) 9 | 10 | len = length(taubefore[:,1]) 11 | index_start = zeros(Int, length(taubefore[1,:])) 12 | for i in 1:length(taubefore[1,:]) 13 | temp = zeros(length(seismic_stress[1,:])) 14 | # index_start[i] = findall(seismic_stress[len,:] .== taubefore[len,i])[1] 15 | for j in 1:length(seismic_stress[1,:]) 16 | temp[j] = norm(seismic_stress[:,j] .- taubefore[:,i]) 17 | end 18 | 19 | index_start[i] = findmin(temp)[2] 20 | end 21 | 22 | index_start 23 | end 24 | 25 | #................................................. 26 | # Compute the final Coseismic slip for each event 27 | #................................................. 28 | function Coslip(S, Slip, SlipVel, Stress, time_=zeros(1000000)) 29 | Vfmax = maximum(SlipVel, dims = 1)[:] 30 | 31 | delfafter::Array{Float64,2} = zeros(size(Slip)) 32 | tStart::Array{Float64} = zeros(size(Slip[1,:])) 33 | tEnd::Array{Float64} = zeros(size(Slip[1,:])) 34 | 35 | taubefore::Array{Float64,2} = zeros(size(Slip)) 36 | tauafter::Array{Float64,2} = zeros(size(Slip)) 37 | 38 | hypo::Array{Float64} = zeros(size(Slip[1,:])) # Hypocenter 39 | vhypo::Array{Float64} = zeros(size(Slip[1,:])) # Velocity at hypocenter 40 | 41 | Vthres = 0.001 # event threshold 42 | slipstart = 0 43 | it = 1; it2 = 1 44 | delfref = zeros(size(Slip[:,1])) 45 | 46 | for i = 1:length(Slip[1,:]) 47 | 48 | # Start of each event 49 | if Vfmax[i] > 1.01*Vthres && slipstart == 0 50 | delfref = Slip[:,i] 51 | slipstart = 1 52 | tStart[it2] = time_[i] 53 | 54 | taubefore[:,it2] = Stress[:,i] 55 | vhypo[it2], indx = findmax(SlipVel[:,i]) 56 | 57 | hypo[it2] = S.FltX[indx] 58 | 59 | it2 = it2+1 60 | end 61 | 62 | # End of each event 63 | if Vfmax[i] < 0.99*Vthres && slipstart == 1 64 | delfafter[:,it] = Slip[:,i] - delfref 65 | tauafter[:,it] = Stress[:,i] 66 | tEnd[it] = time_[i] 67 | slipstart = 0 68 | it = it + 1 69 | end 70 | end 71 | 72 | return delfafter[:,1:it-1], (taubefore-tauafter)[:,1:it-1], tStart[1:it2-1], tEnd[1:it-1], vhypo[1:it2-1], hypo[1:it2-1] 73 | end 74 | 75 | #.......................................................... 76 | # Compute the moment magnitude: 77 | # Assumed the rupture area to be square; the rupture 78 | # dimension along depth is the same as the rupture 79 | # dimension perpendicular to the plane 80 | #.......................................................... 81 | function moment_magnitude_new(mu, FltX, delfafter, stressdrops ,time_) 82 | # Final coseismic slip of each earthquake 83 | # delfafter, stressdrops = Coslip(S, Slip, SlipVel, Stress, time_) 84 | FltNglob = length(FltX) 85 | 86 | iter = length(delfafter[1,:]) 87 | seismic_moment = zeros(iter) 88 | rupture_len = zeros(iter) 89 | fault_slip = zeros(iter) 90 | temp_sigma = 0 91 | iter2 = 1 92 | 93 | del_sigma = zeros(iter) 94 | 95 | dx = diff(FltX).*1e3 96 | 97 | for i = 1:iter 98 | 99 | # slip threshold = 1% of maximum slip 100 | slip_thres = 0.01*maximum(delfafter[:,i]) 101 | 102 | # area = slip*(rupture dimension along depth) 103 | # zdim = rupture along z dimension = depth rupture dimension 104 | area = 0; zdim = 0; temp_sigma = 0; temp_slip = 0 105 | 106 | for j = 1:FltNglob 107 | if delfafter[j,i] >= slip_thres 108 | area = area + delfafter[j,i]*dx[j-1] 109 | zdim = zdim + dx[j-1] 110 | temp_slip = temp_slip + delfafter[j,i] 111 | 112 | # Avg. stress drops along rupture area 113 | temp_sigma = temp_sigma + stressdrops[j,i]*dx[j-1] 114 | end 115 | end 116 | 117 | seismic_moment[i] = mu*area*zdim 118 | del_sigma[i] = temp_sigma/zdim 119 | fault_slip[i] = temp_slip/zdim 120 | 121 | rupture_len[i] = zdim 122 | 123 | 124 | end 125 | # seismic_moment = filter!(x->x!=0, seismic_moment) 126 | # del_sigma = filter!(x->x!=0, del_sigma) 127 | Mw = (2/3)*log10.(seismic_moment.*1e7) .- 10.7 128 | 129 | return Mw, del_sigma, fault_slip, rupture_len 130 | end 131 | -------------------------------------------------------------------------------- /post/plotting_script.jl: -------------------------------------------------------------------------------- 1 | ############################## 2 | # PLOTTING SCRIPTS 3 | ############################## 4 | 5 | using PyPlot 6 | using StatsBase 7 | using LaTeXStrings 8 | using PyCall 9 | mpl = pyimport("matplotlib") 10 | 11 | # Default plot params 12 | function plot_params() 13 | plt.rc("xtick", labelsize=16) 14 | plt.rc("ytick", labelsize=16) 15 | plt.rc("xtick", direction="in") 16 | plt.rc("ytick", direction="in") 17 | plt.rc("font", size=15) 18 | plt.rc("figure", autolayout="True") 19 | plt.rc("axes", titlesize=16) 20 | plt.rc("axes", labelsize=17) 21 | plt.rc("xtick.major", width=1.5) 22 | plt.rc("xtick.major", size=5) 23 | plt.rc("ytick.major", width=1.5) 24 | plt.rc("ytick.major", size=5) 25 | plt.rc("lines", linewidth=2) 26 | plt.rc("axes", linewidth=1.5) 27 | plt.rc("legend", fontsize=13) 28 | plt.rc("mathtext", fontset="stix") 29 | plt.rc("font", family="STIXGeneral") 30 | 31 | # Default width for Nature is 7.2 inches, 32 | # height can be anything 33 | #plt.rc("figure", figsize=(7.2, 4.5)) 34 | end 35 | 36 | # Plot slip vs event number 37 | function slipPlot(delfafter2, rupture_len, FltX, Mw, tStart) 38 | plot_params() 39 | fig, ax = PyPlot.subplots(nrows=1, ncols=4, sharex="all", sharey="all", figsize=(9.2, 5.00)) 40 | 41 | xaxis = tStart[Mw .>2.8] 42 | delfafter = delfafter2[:,Mw .> 2.8] 43 | Mw2 = Mw[Mw .> 2.8] 44 | 45 | # Normalize colorbar 46 | norm = matplotlib.colors.Normalize(vmin = minimum(Mw2), 47 | vmax=maximum(Mw2)) 48 | colors = matplotlib.cm.inferno_r(norm(Mw2)) 49 | 50 | ax[1].barh(xaxis, delfafter[end-1,:], height=6, 51 | color=colors, align="center"); 52 | ax[1].set_ylabel("Time (yr)") 53 | ax[1].invert_yaxis() 54 | ax[1].set_title("At 60 m depth") 55 | 56 | trench_depth1 = findall(abs.(FltX) .< 4.0e3)[1] 57 | trench_depth2 = findall(abs.(FltX) .< 6.0e3)[1] 58 | trench_depth3 = findall(abs.(FltX) .< 8.0e3)[1] 59 | 60 | ax[2].barh(xaxis, delfafter[trench_depth1,:], height=6, 61 | color=colors, align="center"); 62 | ax[2].invert_yaxis() 63 | ax[2].set_title("At 4 km depth") 64 | 65 | ax[3].barh(xaxis, delfafter[trench_depth2,:], height=6, 66 | color=colors, align="center"); 67 | ax[3].invert_yaxis() 68 | ax[3].set_title("At 6 km depth") 69 | 70 | ax[4].barh(xaxis, delfafter[trench_depth3,:], height=6, 71 | color=colors, align="center"); 72 | ax[4].invert_yaxis() 73 | ax[4].set_title("At 8 km depth") 74 | 75 | sm = matplotlib.cm.ScalarMappable(norm=norm, cmap="inferno_r") 76 | sm.set_array([]) 77 | fig.colorbar(sm, shrink=0.9, label="Mw") 78 | plt.xlabel("Coseismic Slip (m)") 79 | plt.tight_layout() 80 | show() 81 | 82 | figname = string(path, "coseismic_slip.png") 83 | fig.savefig(figname, dpi = 300) 84 | end 85 | 86 | # Cumulative sliprate plot 87 | function eqCyclePlot(sliprate, FltX) 88 | indx = findall(abs.(FltX) .<= 16e3)[1] 89 | value = sliprate[indx:end,10000:end] 90 | 91 | depth = -FltX[indx:end]./1e3 92 | 93 | plot_params() 94 | fig = PyPlot.figure(figsize=(9.2, 4.45)) 95 | ax = fig.add_subplot(111) 96 | 97 | c = ax.imshow(value, cmap="inferno", aspect="auto", 98 | norm=matplotlib.colors.LogNorm(vmin=1e-9, vmax=1e0), 99 | interpolation="bicubic", 100 | extent=[0,length(sliprate[1,:]), 0,16]) 101 | 102 | # for stress 103 | # c = ax.imshow(value, cmap="inferno", aspect="auto", 104 | # vmin=22.5, vmax=40, 105 | # interpolation="bicubic", 106 | # extent=[0,length(seismic_slipvel[1,:]), 0,16]) 107 | 108 | ax.set_xlabel("Timesteps") 109 | ax.set_ylabel("Depth (km)") 110 | 111 | ax.invert_yaxis() 112 | cbar = fig.colorbar(c) 113 | # cbar.set_ticks(cbar.get_ticks()[1:2:end]) 114 | 115 | show() 116 | figname = string(path, "interpolated_sliprate.png") 117 | fig.savefig(figname, dpi = 300) 118 | 119 | end 120 | 121 | # Plot Vfmax 122 | function VfmaxPlot(Vfmax, t, yr2sec) 123 | plot_params() 124 | fig = PyPlot.figure(figsize=(7.2, 3.45)) 125 | ax = fig.add_subplot(111) 126 | 127 | ax.plot(t./yr2sec, Vfmax, lw = 2.0) 128 | ax.set_xlabel("Time (years)") 129 | ax.set_ylabel("Max. Slip rate (m/s)") 130 | ax.set_yscale("log") 131 | # ax.set_xlim([230,400]) 132 | show() 133 | 134 | figname = string(path, "Vfmax01.png") 135 | fig.savefig(figname, dpi = 300) 136 | end 137 | 138 | function Vfmaxcomp(Vfmax1, t1, Vfmax2, t2, yr2sec) 139 | plot_params() 140 | fig = PyPlot.figure(figsize=(7.2, 3.45)) 141 | ax = fig.add_subplot(111) 142 | 143 | ax.plot(t1./yr2sec, Vfmax1, lw = 2.0, label="Thakur") 144 | ax.plot(t2./yr2sec, Vfmax2, lw = 2.0, alpha=0.7, label="Abdelmeguid") 145 | ax.set_xlabel("Time (years)") 146 | ax.set_ylabel("Max. Slip rate (m/s)") 147 | # ax.set_yscale("log") 148 | plt.legend() 149 | # ax.set_xlim([230,400]) 150 | show() 151 | 152 | figname = string(path, "Vfmax01.png") 153 | fig.savefig(figname, dpi = 300) 154 | end 155 | 156 | # Plot alpha 157 | function alphaaPlot(alphaa, t, yr2sec) 158 | plot_params() 159 | fig = PyPlot.figure(figsize=(7.2, 3.45)) 160 | ax = fig.add_subplot(111) 161 | 162 | ax.plot(t./yr2sec, alphaa, lw = 2) 163 | ax.set_xlabel("Time (years)") 164 | ax.set_ylabel("Shear Modulus Contrast (%)") 165 | # ax.set_xlim([230,400]) 166 | show() 167 | 168 | 169 | figname = string(path, "alpha_01.png") 170 | fig.savefig(figname, dpi = 300) 171 | end 172 | 173 | # Plot cumulative slip 174 | function cumSlipPlot(delfsec, delfyr, FltX) 175 | indx = findall(abs.(FltX) .<= 18)[1] 176 | 177 | delfsec2 = transpose(delfsec[:,indx:end]) 178 | delfyr2 = transpose(delfyr) 179 | 180 | plot_params() 181 | fig = PyPlot.figure(figsize=(7.2, 4.45)) 182 | ax = fig.add_subplot(111) 183 | plt.rc("font",size=12) 184 | 185 | ax.plot(delfyr2, FltX, color="royalblue", lw=1.0) 186 | ax.plot(delfsec2, FltX[indx:end], color="chocolate", lw=1.0) 187 | ax.set_xlabel("Accumulated Slip (m)") 188 | ax.set_ylabel("Depth (km)") 189 | ax.set_ylim([0,24]) 190 | # ax.set_xlim([1,20]) 191 | 192 | ax.invert_yaxis() 193 | 194 | show() 195 | 196 | figname = string(path, "cumulative_slip.png") 197 | fig.savefig(figname, dpi = 300) 198 | 199 | end 200 | 201 | # Plot friction parameters 202 | function icsPlot(a_b, Seff, tauo, FltX) 203 | plot_params() 204 | fig = PyPlot.figure(figsize=(7.2, 4.45)) 205 | ax = fig.add_subplot(111) 206 | 207 | ax.plot(Seff, FltX, "k-", label="Normal Stress") 208 | ax.plot(tauo, FltX, "k--", label="Shear Stress") 209 | ax.set_xlabel("Stresses (MPa)") 210 | ax.set_ylabel("Depth (km)") 211 | plt.legend(loc="lower right") 212 | 213 | col="tab:blue" 214 | ax2 = ax.twiny() 215 | ax2.plot(a_b, FltX, label="(a-b)") 216 | ax2.set_xlabel("Rate-state friction value", color=col) 217 | ax2.get_xaxis().set_tick_params(color=col) 218 | ax2.tick_params(axis="x", labelcolor=col) 219 | 220 | ax.set_ylim([0,80]) 221 | ax.invert_yaxis() 222 | show() 223 | 224 | figname = string(path, "ics_02.png") 225 | fig.savefig(figname, dpi = 300) 226 | end 227 | -------------------------------------------------------------------------------- /post/rough_script.jl: -------------------------------------------------------------------------------- 1 | ################################# 2 | # SOME ROUGH SCRIPTS 3 | # FOR TRYING OUT STUFF 4 | ################################# 5 | 6 | using StatsBase 7 | using PyPlot 8 | 9 | # Get index for each event 10 | function event_indx(tStart, tEnd, time_) 11 | start_indx = zeros(size(tStart)) 12 | end_indx = zeros(size(tEnd)) 13 | 14 | for i = 1:length(tStart) 15 | 16 | start_indx[i] = findall(time_ .== tStart[i])[1] 17 | end_indx[i] = findall(time_ .== tEnd[i])[1] 18 | end 19 | 20 | return start_indx, end_indx 21 | end 22 | 23 | # Plot sliprates for each event with depth 24 | function test1(S, O, evno) 25 | start_indx = zeros(size(O.tStart)) 26 | end_indx = zeros(size(O.tEnd)) 27 | 28 | for i = 1:length(O.tStart) 29 | 30 | start_indx[i] = findall(O.time_ .== O.tStart[i])[1] 31 | end_indx[i] = findall(O.time_ .== O.tEnd[i])[1] 32 | end 33 | 34 | start_indx = Int.(start_indx)[evno] 35 | end_indx = Int.(end_indx)[evno] 36 | sv = zeros(size(O.seismic_slipvel)) 37 | 38 | inc = 0.1 # time interval = 0.1 sec for plotting 39 | to = O.time_[start_indx] # start time 40 | j = 1 41 | for i=start_indx:end_indx 42 | if O.time_[i] >= to 43 | sv[:,j] = O.seismic_slipvel[:,i] 44 | to = to + inc 45 | j = j+1 46 | end 47 | end 48 | 49 | sv = sv[:,1:j] 50 | 51 | fig = PyPlot.figure(figsize=(8,6)) 52 | ax = fig.add_subplot(111) 53 | 54 | ax.plot(sv, S.FltX/1e3, ".--", label="a", lw = 1) 55 | ax.set_xlabel("Slip rate (m/s)") 56 | ax.set_ylabel("Depth (km)") 57 | ax.set_title("Slip rate for one event") 58 | # ax.set_xlim([0, 0.02]) 59 | ax.set_ylim([-24, 0]) 60 | show() 61 | 62 | figname = string(path, "slipvel.pdf") 63 | fig.savefig(figname, dpi = 300) 64 | end 65 | 66 | -------------------------------------------------------------------------------- /run.jl: -------------------------------------------------------------------------------- 1 | ################################# 2 | # Run the simulations from here 3 | ################################# 4 | 5 | # 1. Go to par.jl and change as needed 6 | # 2. Go to src/initialConditions/defaultInitialConditions and change as needed 7 | # 3. Change the name of the simulation in this file 8 | # 4. Run the simulation from terminal. (julia run.jl) 9 | # 5. Plot results from the scripts folder 10 | 11 | using Printf, LinearAlgebra, DelimitedFiles, SparseArrays, 12 | AlgebraicMultigrid, StaticArrays, IterativeSolvers, FEMSparse 13 | using Base.Threads 14 | # BLAS.set_num_threads(1) 15 | 16 | include("$(@__DIR__)/par.jl") # Set Parameters 17 | 18 | # Put the resolution for the simulation here: should be an integer 19 | resolution = 4 20 | 21 | # Output directory to save data 22 | out_dir = "$(@__DIR__)/data/test_01/" 23 | mkpath(out_dir) 24 | 25 | P = setParameters(0e3,resolution) # args = fault zone depth, resolution 26 | 27 | include("$(@__DIR__)/src/dtevol.jl") 28 | include("$(@__DIR__)/src/NRsearch.jl") 29 | include("$(@__DIR__)/src/otherFunctions.jl") 30 | 31 | include("$(@__DIR__)/src/main.jl") 32 | 33 | simulation_time = @elapsed @time main(P) 34 | 35 | println("\n") 36 | 37 | @info("Simulation Complete!"); 38 | -------------------------------------------------------------------------------- /src/.ipynb_checkpoints/Assemble-checkpoint.jl: -------------------------------------------------------------------------------- 1 | ################################################### 2 | # ASSEMBLE THE MASS AND THE STIFFNESS MATRICES 3 | ################################################### 4 | 5 | 6 | 7 | function Massemble!(NGLL, NelX, NelY, dxe, dye, ThickX, 8 | ThickY, rho1, vs1, rho2, vs2, iglob, 9 | M, x, y, jac) 10 | 11 | 12 | xgll, wgll, H = GetGLL(NGLL) 13 | wgll2 = wgll*wgll'; 14 | 15 | rho::Matrix{Float64} = zeros(NGLL, NGLL) 16 | mu::Matrix{Float64} = zeros(NGLL, NGLL) 17 | 18 | vso = zeros(NGLL, NGLL) 19 | vs = zeros(NGLL-1, NGLL) 20 | dx = zeros(NGLL-1, NGLL) 21 | muMax = 0 22 | dt = Inf 23 | 24 | # damage zone index 25 | damage_idx = zeros(Int, NelX*NelY) 26 | 27 | @inbounds @fastmath for ey = 1:NelY 28 | @inbounds @fastmath for ex = 1:NelX 29 | 30 | eo = (ey-1)*NelX + ex 31 | ig = iglob[:,:,eo] 32 | 33 | # Properties of heterogeneous medium 34 | if ex*dxe >= ThickX && (dye <= ey*dye <= ThickY) 35 | damage_idx[eo] = eo 36 | rho[:,:] .= rho2 37 | mu[:,:] .= rho2*vs2^2 38 | else 39 | rho[:,:] .= rho1 40 | mu[:,:] .= rho1*vs1^2 41 | end 42 | 43 | if muMax < maximum(maximum(mu)) 44 | muMax = maximum(maximum(mu)) 45 | end 46 | 47 | # Diagonal Mass Matrix 48 | M[ig] .+= wgll2.*rho*jac 49 | 50 | # Local contributions to the stiffness matrix 51 | # W[:,:,eo] .= wgll2.*mu; 52 | 53 | # Set timestep 54 | vso .= sqrt.(mu./rho) 55 | 56 | if dxe 0] 71 | end 72 | -------------------------------------------------------------------------------- /src/.ipynb_checkpoints/damageEvol-checkpoint.jl: -------------------------------------------------------------------------------- 1 | ##################################### 2 | # DAMAGE EVOLUTION IN TIME 3 | ##################################### 4 | 5 | function damage_indx!(ThickX, ThickY, Wid, dxe, dye, NGLL, NelX, NelY, iglob) 6 | 7 | ww::Matrix{Float64} = zeros(NGLL, NGLL) 8 | Ke2::Array{Float64,4} = zeros(NGLL,NGLL,NGLL,NGLL) 9 | Ke::Array{Float64,3} = zeros(NGLL*NGLL,NGLL*NGLL, Nel) 10 | 11 | @inbounds for eo in 1:Nel 12 | Ke2 .= 0. 13 | 14 | for i in 1:NGLL, j in 1:NGLL 15 | for k in 1:NGLL, l in 1:NGLL 16 | Ke2[i,j,k,l] = 1 17 | end 18 | end 19 | Ke[:,:,eo] = reshape(Ke2,NGLL*NGLL,NGLL*NGLL) 20 | end 21 | 22 | return FEsparse(NelX*NelY, Ke, iglob) 23 | 24 | end 25 | -------------------------------------------------------------------------------- /src/.ipynb_checkpoints/untitled-checkpoint.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thehalfspace/Spear/0b7dc5671761d1a06fe2f700e0ef39557eb67cda/src/.ipynb_checkpoints/untitled-checkpoint.txt -------------------------------------------------------------------------------- /src/Assemble.jl: -------------------------------------------------------------------------------- 1 | ################################################### 2 | # ASSEMBLE THE MASS AND THE STIFFNESS MATRICES 3 | ################################################### 4 | 5 | 6 | 7 | function Massemble!(NGLL, NelX, NelY, dxe, dye, ThickX, 8 | ThickY, rho1, vs1, rho2, vs2, iglob, 9 | M, x, y, jac) 10 | 11 | 12 | xgll, wgll, H = GetGLL(NGLL) 13 | wgll2 = wgll*wgll'; 14 | 15 | rho::Matrix{Float64} = zeros(NGLL, NGLL) 16 | mu::Matrix{Float64} = zeros(NGLL, NGLL) 17 | 18 | vso = zeros(NGLL, NGLL) 19 | vs = zeros(NGLL-1, NGLL) 20 | dx = zeros(NGLL-1, NGLL) 21 | muMax = 0 22 | dt = Inf 23 | 24 | # # damage zone index 25 | # damage_idx = zeros(Int, NelX*NelY) 26 | 27 | @inbounds @fastmath for ey = 1:NelY 28 | @inbounds @fastmath for ex = 1:NelX 29 | 30 | eo = (ey-1)*NelX + ex 31 | ig = iglob[:,:,eo] 32 | 33 | # Properties of heterogeneous medium 34 | if ex*dxe >= ThickX && (dye <= ey*dye <= ThickY) 35 | # damage_idx[eo] = eo 36 | rho[:,:] .= rho2 37 | mu[:,:] .= rho2*vs2^2 38 | else 39 | rho[:,:] .= rho1 40 | mu[:,:] .= rho1*vs1^2 41 | end 42 | 43 | if muMax < maximum(maximum(mu)) 44 | muMax = maximum(maximum(mu)) 45 | end 46 | 47 | # Diagonal Mass Matrix 48 | M[ig] .+= wgll2.*rho*jac 49 | 50 | # Local contributions to the stiffness matrix 51 | # W[:,:,eo] .= wgll2.*mu; 52 | 53 | # Set timestep 54 | vso .= sqrt.(mu./rho) 55 | 56 | if dxe= ThickX && (dye <= ey*dye <= ThickY) 15 | mu .= rho2*vs2^2 16 | # damage_idx[eo] = eo 17 | else 18 | mu .= rho1*vs1^2 19 | end 20 | W[:,:,eo] = wgll2.*mu 21 | end 22 | end 23 | W 24 | end 25 | 26 | #= 27 | FZ-oute FZ-inner Fault 28 | V V V 29 | ------P1--------------| 30 | \ | | 31 | \ | | 32 | \ | | 33 | P2 -------| | 34 | | | 35 | | | 36 | =# 37 | 38 | 39 | 40 | # Material properties for a trapezium damage zone 41 | # Linear function: shape of trapezoid 42 | function line(x,y) 43 | P1 = [0 3e3] # Top point of the outer damage zone in flower structure 44 | P2 = [-8e3 1.5e3] # Bottom point 45 | 46 | f = (y - P2[2]) - ((P1[2]-P2[2])/(P1[1]-P2[1]))*(x - P2[1]) 47 | 48 | return f 49 | end 50 | 51 | # Set up trapezoidal rigidity 52 | function rigid(x,y) 53 | # Rigidity: host rock and fault zone 54 | rho1::Float64 = 2670 55 | vs1::Float64 = 3464 56 | 57 | rho2 = 0.6*rho1 # Inner damage zone 58 | vs2 = 0.6*vs1 # Inner damage zone 59 | rho3 = 0.8*rho1 # outer damage zone 60 | vs3 = 0.8*vs1 # outer damage zone 61 | 62 | rhoglob::Array{Float64} = zeros(length(x)) 63 | vsglob::Array{Float64} = zeros(length(x)) 64 | 65 | for i = 1:length(x) 66 | if x[i] > -8e3 # Depth of the outer damage zone 67 | if line(x[i],y[i]) < 0 68 | rhoglob[i] = rho3 69 | vsglob[i] = vs3 70 | else 71 | rhoglob[i] = rho1 72 | vsglob[i] = vs1 73 | end 74 | else 75 | rhoglob[i] = rho1 76 | vsglob[i] = vs1 77 | end 78 | 79 | end 80 | 81 | for i = 1:length(x) 82 | if y[i]<0.25e3 # Thickness of the inner damage zone 83 | rhoglob[i] = rho2 84 | vsglob[i] = vs2 85 | end 86 | end 87 | 88 | 89 | return rhoglob, vsglob 90 | end 91 | 92 | function mat_trap(NelX, NelY, NGLL, iglob, M, dxe, dye, x,y, wgll2) 93 | dx_dxi::Float64 = 0.5*dxe 94 | dy_deta::Float64 = 0.5*dye 95 | jac::Float64 = dx_dxi*dy_deta 96 | 97 | mu::Matrix{Float64} = zeros(NGLL, NGLL) 98 | rho::Matrix{Float64} = zeros(NGLL, NGLL) 99 | W::Array{Float64,3} = zeros(NGLL, NGLL, NelX*NelY) 100 | rhoglob, vsglob = rigid(x,y) 101 | muglob = rhoglob.*(vsglob.^2) 102 | 103 | @inbounds for ey in 1:NelY 104 | @inbounds for ex in 1:NelX 105 | eo = (ey-1)*NelX + ex 106 | ig = iglob[:,:,eo] 107 | 108 | mu[:,:] = muglob[ig] 109 | rho[:,:] = rhoglob[ig] 110 | 111 | W[:,:,eo] = wgll2.*mu 112 | M[ig] .+= wgll2.*rho*jac 113 | end 114 | end 115 | return M,W 116 | end 117 | -------------------------------------------------------------------------------- /src/MeshBox.jl: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Spectral Element Mesh for Rectangular Box, with internal 3 | # Gauss-Legendre-Lobatto (GLL) dub-grids. 4 | # 5 | # INPUT: LX = x-dimension 6 | # LY = y-dimension 7 | # NELX = no. of elements in x 8 | # NELY = no. of elements in y 9 | # NGLL = no. of GLL nodes 10 | 11 | 12 | # OUTPUT: iglob[ngll, ngll, NELX, NELY] = maps local to global 13 | # numbering 14 | # I = iglob[i,j,e] is the global node index of the 15 | # (i,j)th GLL node internal to the 16 | # e-th element. 17 | 18 | # Elements are numbered row by row from from bottom-left 19 | # to top-right. The table iglob is needed to assemble 20 | # global data from local data. 21 | 22 | # x[:] = global x coordinates of GLL nodes, starting at 0 23 | # y[:] = global y coordinates of GLL nodes, starting at 0 24 | ############################################################################### 25 | 26 | 27 | function MeshBox!(NGLL, Nel, NelX, NelY, FltNglob, dxe, dye) 28 | 29 | XGLL = GetGLL(NGLL)[1] 30 | 31 | iglob = zeros(Int, NGLL, NGLL, Nel) 32 | nglob = FltNglob*(NelY*(NGLL-1) + 1) 33 | 34 | x::Vector{Float64} = zeros(nglob) 35 | y::Vector{Float64} = zeros(nglob) 36 | 37 | et = 0 38 | last_iglob = 0 39 | 40 | ig = reshape(collect(1:NGLL*NGLL), NGLL, NGLL) 41 | igL = reshape(collect(1:NGLL*(NGLL-1)), NGLL-1, NGLL) # Left edge 42 | igB = reshape(collect(1:NGLL*(NGLL-1)), NGLL, NGLL-1) # Bottom edge 43 | igLB = reshape(collect(1:(NGLL-1)*(NGLL-1)), NGLL-1, NGLL-1) # rest of the elements 44 | 45 | xgll = repeat(0.5*(1 .+ XGLL), 1, NGLL) 46 | ygll = dye*xgll' 47 | xgll = dxe*xgll 48 | 49 | 50 | @inbounds for ey = 1:NelY # number of x elements 51 | @inbounds for ex = 1:NelX # number of y elements 52 | 53 | et = et + 1 54 | 55 | # Redundant nodes at element edges 56 | 57 | # NGLL = number of GLL nodes per element 58 | 59 | if et == 1 60 | ig = reshape(collect(1:NGLL*NGLL), NGLL, NGLL) 61 | else 62 | if ey ==1 # Bottom Row 63 | ig[1,:] = iglob[NGLL, :, et-1] # Left edge 64 | ig[2:end, :] = last_iglob .+ igL # The rest 65 | 66 | elseif ex == 1 # Left Column 67 | ig[:,1] = iglob[:,NGLL,et-NelX] # Bottom edge 68 | ig[:,2:end] = last_iglob .+ igB # The rest 69 | 70 | else # Other Elements 71 | ig[1,:] = iglob[NGLL, :, et-1] # Left edge 72 | ig[:,1] = iglob[:, NGLL, et-NelX]# Bottom edge 73 | ig[2:end, 2:end] = last_iglob .+ igLB 74 | end 75 | end 76 | 77 | iglob[:,:,et] = ig 78 | last_iglob = ig[NGLL, NGLL] 79 | 80 | # Global coordinates of computational nodes 81 | @inbounds x[ig] .= dxe*(ex-1) .+ xgll 82 | @inbounds y[ig] .= dye*(ey-1) .+ ygll 83 | 84 | end 85 | end 86 | 87 | return iglob, x, y 88 | end 89 | 90 | -------------------------------------------------------------------------------- /src/NRsearch.jl: -------------------------------------------------------------------------------- 1 | #################################### 2 | # NEWTON RHAPSON SEARCH METHOD 3 | #################################### 4 | 5 | # Fault Boundary function 6 | function FBC!(IDstate, P::params_farray, NFBC, FltNglob, psi1, Vf1, tau1, psi2, Vf2, tau2, psi, Vf, FltVfree, dt) 7 | 8 | # tauNR::Vector{BigFloat} = zeros(FltNglob) 9 | tauNR::BigFloat = 0. 10 | 11 | for j = NFBC:FltNglob 12 | 13 | tauNR = 0. 14 | psi1[j] = IDS!(P.xLf[j], P.Vo[j], psi[j], dt, Vf[j], 1e-5, IDstate) 15 | 16 | Vf1[j], tau1[j] = NRsearch!(P.fo[j], P.Vo[j], P.cca[j], P.ccb[j], P.Seff[j], 17 | tauNR, P.tauo[j], psi1[j], P.FltZ[j], FltVfree[j]) 18 | 19 | if Vf[j] > 1e10 || isnan(Vf[j]) == 1 || isnan(tau1[j]) == 1 20 | 21 | println("Fault Location = ", j) 22 | println(" Vf = ", Vf[j]) 23 | println(" tau1 = ", tau1[j]) 24 | 25 | println("psi =", psi[j]) 26 | println("psi1 =", psi1[j]) 27 | # Save simulation results 28 | #filename = string(dir, "/data", name, "nrfail.jld2") 29 | #@save filename results(Stress,SlipVel, Slip, time_) 30 | @error("NR SEARCH FAILED!") 31 | return 32 | end 33 | 34 | psi2[j] = IDS2!(P.xLf[j], P.Vo[j], psi[j], psi1[j], dt, Vf[j], Vf1[j], IDstate) 35 | 36 | # NRsearch 2nd loop 37 | Vf2[j], tau2[j] = NRsearch!(P.fo[j], P.Vo[j], P.cca[j], P.ccb[j], P.Seff[j], 38 | tau1[j], P.tauo[j], psi2[j], P.FltZ[j], FltVfree[j]) 39 | 40 | end 41 | 42 | return psi1, Vf1, tau1, psi2, Vf2, tau2 43 | end 44 | 45 | 46 | # Newton Rhapson search method 47 | function NRsearch!(fo, Vo, cca, ccb, Seff, tau, tauo, psi, FltZ, FltVfree) 48 | 49 | Vw = 1e10 50 | fact = 1. + (Vo/Vw)*exp(-psi) 51 | fa::BigFloat = 0. 52 | help1::BigFloat = 0. 53 | help2::BigFloat = 0. 54 | delta::BigFloat = 0. 55 | 56 | # NR search point by point for tau if Vf < Vlimit 57 | eps = 0.001*cca*Seff 58 | k = 0 59 | delta = Inf 60 | 61 | while abs(delta) > eps 62 | fa = fact*tau/(Seff*cca) 63 | help = -(fo + ccb*psi)/cca 64 | 65 | help1 = exp(help + fa) 66 | help2 = exp(help - fa) 67 | 68 | Vf = Vo*(help1 - help2) 69 | 70 | Vfprime = fact*(Vo/(cca*Seff))*(help1 + help2) 71 | 72 | delta = (FltZ*FltVfree - FltZ*Vf + tauo - tau)/(1 + FltZ*Vfprime) 73 | 74 | tau = tau + delta 75 | k = k + 1 76 | 77 | if abs(delta) > 1e10 || k == 1000 78 | println("k = ", k) 79 | # Save simulation results 80 | #filename = string(dir, "/data", name, "nrfail.jld2") 81 | #@save filename 82 | # @error("NR search fails to converge") 83 | 84 | return Float64(Vf), Float64(tau) 85 | end 86 | end 87 | 88 | fa = fact*tau/(Seff*cca) 89 | 90 | help = -(fo + ccb*psi)/cca 91 | 92 | help1 = exp(help + fa) 93 | help2 = exp(help - fa) 94 | 95 | Vf = Vo*(help1 - help2) 96 | 97 | return Float64(Vf), Float64(tau) 98 | end 99 | -------------------------------------------------------------------------------- /src/PCG.jl: -------------------------------------------------------------------------------- 1 | ################################################ 2 | # 3 | # SOLVE FOR DISPLACEMENT USING PRECONDITIONED 4 | # CONJUGATE GRADIENT METHOD 5 | # 6 | ################################################ 7 | 8 | function PCG!(P::params_float, Nel::Int, diagKnew::Array{Float64}, dnew::Array{Float64}, F::Array{Float64}, iFlt::Array{Int},FltNI::Array{Int}, H::Array{Float64,2}, Ht::Array{Float64,2}, iglob::Array{Int,3}, nglob::Int, W::Array{Float64,3}, a_elem::Array{Float64}, Conn) 9 | 10 | a_local::Array{Float64} = zeros(nglob) 11 | dd_local::Array{Float64} = zeros(nglob) 12 | p_local::Array{Float64} = zeros(nglob) 13 | 14 | a_elem = element_computation!(P, iglob, F, H, Ht, W, Nel) 15 | Fnew = -mul!(a_local, Conn, a_elem[:])[FltNI] 16 | 17 | dd_local[FltNI] .= dnew 18 | dd_local[iFlt] .= 0. 19 | 20 | a_local[:] .= 0. 21 | 22 | a_elem = element_computation!(P, iglob, dd_local, H, Ht, W, Nel) 23 | 24 | anew = mul!(a_local, Conn, a_elem[:])[FltNI] 25 | 26 | # Initial residue 27 | rnew = Fnew - anew 28 | znew = rnew./diagKnew 29 | pnew = znew 30 | p_local[:] .= 0. 31 | p_local[FltNI] = pnew 32 | 33 | @inbounds for n = 1:8000 34 | anew[:] .= 0. 35 | a_local[:] .= 0. 36 | 37 | a_elem = element_computation!(P, iglob, p_local, H, Ht, W, Nel) 38 | anew = mul!(a_local, Conn, a_elem[:])[FltNI] 39 | 40 | alpha_ = znew'*rnew/(pnew'*anew) 41 | dnew .+= alpha_*pnew 42 | rold = rnew 43 | zold = znew 44 | rnew = rold - alpha_*anew 45 | znew = rnew./diagKnew 46 | beta_ = znew'*rnew/(zold'*rold) 47 | pnew = znew + beta_*pnew 48 | p_local[:] .= 0. 49 | p_local[FltNI] = pnew 50 | 51 | if norm(rnew)/norm(Fnew) < 1e-5 52 | break; 53 | end 54 | 55 | if n == 8000 || norm(rnew)/norm(Fnew) > 1e10 56 | print(norm(rnew)/norm(Fnew)) 57 | println("\nn = ", n) 58 | 59 | #filename = string(dir, "/data", name, "pcgfail.jld2") 60 | #@save filename dnew rnew Fnew 61 | @error("PCG did not converge") 62 | return 63 | end 64 | end 65 | 66 | return dnew 67 | end 68 | 69 | 70 | # Multi-threading 71 | function element_computation!(P::params_float, iglob::Array{Int,3}, F_local::Array{Float64}, H::Array{Float64,2}, Ht::Array{Float64,2}, W::Array{Float64,3}, Nel) 72 | a_local = zeros(size(F_local)) 73 | a_elem = zeros(size(iglob)) 74 | Threads.@threads for tid in 1:Threads.nthreads() 75 | len = div(Nel, Threads.nthreads()) 76 | domain = ((tid-1)*len + 1):tid*len 77 | 78 | @inbounds @simd for eo in domain 79 | ig = iglob[:,:,eo] 80 | Wlocal = W[:,:,eo] 81 | locall = F_local[ig] 82 | a_elem[:,:,eo] = P.coefint1*H*(Wlocal.*(Ht*locall)) + P.coefint2*(Wlocal.*(locall*H))*Ht 83 | end 84 | end 85 | return a_elem 86 | end 87 | 88 | -------------------------------------------------------------------------------- /src/damageEvol.jl: -------------------------------------------------------------------------------- 1 | ##################################### 2 | # DAMAGE EVOLUTION IN TIME 3 | ##################################### 4 | 5 | function damage_indx!(ThickX, ThickY, dxe, dye, NGLL, NelX, NelY, iglob) 6 | 7 | ww::Matrix{Float64} = zeros(NGLL, NGLL) 8 | Ke2::Array{Float64,4} = zeros(NGLL,NGLL,NGLL,NGLL) 9 | Ke3::Array{Float64,4} = zeros(NGLL,NGLL,NGLL,NGLL) 10 | Ke_d::Array{Float64,3} = zeros(NGLL*NGLL,NGLL*NGLL, NelX*NelY) 11 | Ke_und::Array{Float64,3} = ones(NGLL*NGLL,NGLL*NGLL, NelX*NelY) 12 | 13 | @inbounds @fastmath for ey = 1:NelY 14 | @inbounds @fastmath for ex = 1:NelX 15 | eo = (ey-1)*NelX + ex 16 | ig = iglob[:,:,eo] 17 | 18 | # Properties of heterogeneous medium 19 | for i in 1:NGLL, j in 1:NGLL 20 | for k in 1:NGLL, l in 1:NGLL 21 | 22 | if ex*dxe >= ThickX && (dye <= ey*dye <= ThickY) 23 | Ke2[i,j,k,l] = 1000.0 24 | # Ke3[i,j,k,l] = 0.0 25 | 26 | else 27 | Ke2[i,j,k,l] = -1000 28 | end 29 | end 30 | end 31 | Ke_d[:,:,eo] = reshape(Ke2,NGLL*NGLL,NGLL*NGLL) 32 | # Ke_und[:,:,eo] = reshape(Ke3,NGLL*NGLL,NGLL*NGLL) 33 | end 34 | end 35 | 36 | Kdam = FEsparse(NelX*NelY, Ke_d, iglob) 37 | # Kdam[Kdam .> 1.0] .= 1.0 38 | 39 | # Kudam = FEsparse(NelX*NelY, Ke_und, iglob) 40 | # Kudam[Kudam .> 1.0] .= 1.0 41 | 42 | return findall(Kdam .> 0) 43 | 44 | end 45 | -------------------------------------------------------------------------------- /src/dtevol.jl: -------------------------------------------------------------------------------- 1 | ############################################ 2 | # Compute the timestep for next iteration 3 | ############################################ 4 | 5 | function dtevol!(dt, dtmin, XiLf, FaultNglob, NFBC, Vf, isolver) 6 | 7 | dtmax::Int = 50 * 24 * 60*60 # 5 days 8 | dtincf::Float64 = 1.2 9 | 10 | if isolver == 1 11 | 12 | # initial value of dt 13 | dtnx = dtmax 14 | 15 | # Adjust the timestep according to cell velocities and slip 16 | for i = NFBC:FaultNglob 17 | 18 | if abs(Vf[i])*dtmax > XiLf[i] 19 | dtcell = XiLf[i]/abs(Vf[i]) 20 | 21 | if dtcell < dtnx 22 | dtnx = dtcell 23 | end 24 | end 25 | end 26 | 27 | if dtmin > dtnx 28 | dtnx = dtmin 29 | end 30 | 31 | if dtnx > dtincf*dt 32 | dtnx = dtincf*dt 33 | end 34 | 35 | dt = dtnx 36 | 37 | elseif isolver == 2 38 | 39 | dt = dtmin 40 | end 41 | 42 | return dt 43 | 44 | end 45 | -------------------------------------------------------------------------------- /src/dump.jl: -------------------------------------------------------------------------------- 1 | ########################################## 2 | ## trying out stuff here. this file is not 3 | ## important for simulations 4 | ########################################## 5 | 6 | 7 | ## Testing elemental k matrix 8 | # Single element stiffness 9 | function stiff_element(NGLL, NelX, NelY, nglob, iglob, dxe, dye) 10 | xgll, wgll, H = GetGLL(NGLL) 11 | Ht = H' 12 | wgll2 = wgll*wgll' 13 | 14 | # Jacobians 15 | dx_dxi::Float64 = 0.5*dxe 16 | dy_deta::Float64 = 0.5*dye 17 | jac::Float64 = dx_dxi*dy_deta 18 | c1::Float64 = jac/dx_dxi^2 19 | c2::Float64 = jac/dy_deta^2 20 | 21 | rho1::Float64 = 2500 22 | vs1::Float64 = 0.6*3464 23 | mu = 20 24 | Nel = 600; 25 | Ke2 = zeros(NGLL,NGLL,NGLL,NGLL) 26 | 27 | u = rand(5,5) 28 | 29 | W = wgll2.*mu 30 | del = Matrix{Float64}(I,NGLL,NGLL) # identity matrix 31 | nn = 1 32 | n = 0; q=0; w=0 # iterator 33 | term1 = 0; term2 = 0 34 | for i in 1:5 35 | for j in 1:5 36 | term1 = 0; term2 = 0 37 | for k in 1:5 38 | for l in 1:5 39 | term1 = 0; term2 = 0 40 | for p in 1:5 41 | term1 += del[i,k]*W[k,p]*(jac/dy_deta^2)*H[j,p]*H[l,p] 42 | term2 += del[j,l]*W[p,j]*(jac/dx_dxi^2)*H[i,p]*H[k,p] 43 | end 44 | Ke2[i,j,k,l] = term1 + term2 45 | end 46 | end 47 | end 48 | end 49 | 50 | 51 | Ke = reshape(Ke2,NGLL*NGLL,NGLL*NGLL) 52 | 53 | 54 | # Calculate Ku for one element 55 | wloc = wgll2.*mu 56 | d_xi = Ht*u 57 | d_eta = u*H 58 | 59 | d_xi = H*(wloc.*d_xi) 60 | d_eta = (wloc.*d_eta)*Ht 61 | 62 | Ku = c1*d_xi + c2*d_eta 63 | 64 | return Ku, reshape(Ke*u[:],NGLL,NGLL) 65 | 66 | end 67 | 68 | -------------------------------------------------------------------------------- /src/faultZoneGeometry/gaussianFaultZoneAssembly.jl: -------------------------------------------------------------------------------- 1 | ################################################### 2 | # ASSEMBLE THE MASS AND THE STIFFNESS MATRICES 3 | ################################################### 4 | 5 | # Gaussian function 6 | function gauss(x, mu, sigma) 7 | return ((x .- mu)./(2*sigma)).^2 8 | end 9 | 10 | # Debug the setup 11 | function rigid(x,y) 12 | 13 | # Rigidity: host rock and fault zone 14 | muhost = P.rho1*P.vs1^2 15 | mufz = P.rho2*P.vs2^2 16 | 17 | # Gaussian fault zone mean and std 18 | meanx = 0 19 | meany = 0 20 | sigx = (P.LX - P.ThickX)/3 21 | sigy = P.ThickY/3 22 | 23 | muglob = (mufz-muhost)*exp.(-(gauss(x, meanx, sigx) .+ 24 | gauss(y, meany, sigy))) .+ muhost 25 | 26 | vsglob = (P.vs2-P.vs1)*exp.(-(gauss(x, meanx, sigx) .+ 27 | gauss(y, meany, sigy))) .+ P.vs1 28 | rhoglob = (P.rho2-P.rho1)*exp.(-(gauss(x, meanx, sigx) .+ 29 | gauss(y, meany, sigy))) .+ P.rho1 30 | 31 | return muglob, vsglob, rhoglob 32 | end 33 | 34 | function assemble(P::parameters, iglob, M, W, x, y) 35 | 36 | 37 | xgll, wgll, H = GetGLL(P.NGLL) 38 | wgll2 = wgll*wgll'; 39 | 40 | rho::Matrix{Float64} = zeros(P.NGLL, P.NGLL) 41 | mu::Matrix{Float64} = zeros(P.NGLL, P.NGLL) 42 | 43 | vso = zeros(P.NGLL, P.NGLL) 44 | vs = zeros(P.NGLL-1, P.NGLL) 45 | dx = zeros(P.NGLL-1, P.NGLL) 46 | muMax = 0 47 | dt = Inf 48 | 49 | muglob, vsglob, rhoglob = rigid(x,y) 50 | 51 | # # Rigidity: host rock and fault zone 52 | # muhost = P.rho1*P.vs1^2 53 | # mufz = P.rho2*P.vs2^2 54 | 55 | # # Gaussian fault zone mean and std 56 | # meanx = -P.LX 57 | # meany = 0 58 | # sigx = (P.LX - P.ThickX)/3 59 | # sigy = P.ThickY/3 60 | 61 | for ey = 1:P.NelY 62 | for ex = 1:P.NelX 63 | 64 | eo = (ey-1)*P.NelX + ex 65 | ig = iglob[:,:,eo] 66 | 67 | mu[:,:] = muglob[ig] 68 | rho[:,:] = rhoglob[ig] 69 | 70 | if muMax < maximum(maximum(mu)) 71 | muMax = maximum(maximum(mu)) 72 | end 73 | 74 | # Diagonal Mass Matrix 75 | M[ig] .+= wgll2.*rho*P.jac 76 | 77 | # Local contributions to the stiffness matrix 78 | W[:,:,eo] .= wgll2.*mu; 79 | 80 | # Set timestep 81 | vso .= sqrt.(mu./rho) 82 | 83 | if P.dxe -8e3 28 | if line(x[i],y[i]) < 0 29 | rhoglob[i] = rho3 30 | vsglob[i] = vs3 31 | else 32 | rhoglob[i] = P.rho1 33 | vsglob[i] = P.vs1 34 | end 35 | else 36 | rhoglob[i] = P.rho1 37 | vsglob[i] = P.vs1 38 | end 39 | 40 | end 41 | 42 | for i = 1:length(x) 43 | if y[i]<0.25e3 44 | rhoglob[i] = rho2 45 | vsglob[i] = vs2 46 | end 47 | end 48 | 49 | 50 | return rhoglob, vsglob 51 | end 52 | 53 | function assemble(P::parameters, iglob, M, W, x, y) 54 | 55 | xgll, wgll, H = GetGLL(P.NGLL) 56 | wgll2 = wgll*wgll'; 57 | 58 | rhoglob, vsglob = rigid(x,y) 59 | muglob = rhoglob.*(vsglob.^2) 60 | 61 | rho::Matrix{Float64} = zeros(P.NGLL, P.NGLL) 62 | mu::Matrix{Float64} = zeros(P.NGLL, P.NGLL) 63 | 64 | vso = zeros(P.NGLL, P.NGLL) 65 | vs = zeros(P.NGLL-1, P.NGLL) 66 | dx = zeros(P.NGLL-1, P.NGLL) 67 | muMax = 0 68 | dt = Inf 69 | 70 | # Rigidity: host rock and fault zone 71 | 72 | for ey = 1:P.NelY 73 | for ex = 1:P.NelX 74 | 75 | eo = (ey-1)*P.NelX + ex 76 | ig = iglob[:,:,eo] 77 | 78 | mu[:,:] = muglob[ig] 79 | rho[:,:] = rhoglob[ig] 80 | 81 | if muMax < maximum(maximum(mu)) 82 | muMax = maximum(maximum(mu)) 83 | end 84 | 85 | # Diagonal Mass Matrix 86 | M[ig] .+= wgll2.*rho*P.jac 87 | 88 | # Local contributions to the stiffness matrix 89 | W[:,:,eo] .= wgll2.*mu; 90 | 91 | # Set timestep 92 | vso .= sqrt.(mu./rho) 93 | 94 | if P.dxe abs(fP5[2])) 29 | 30 | a_b[fric_depth1] .= Int1D(fP1, fP2, FltX[fric_depth1]) 31 | a_b[fric_depth2] .= Int1D(fP2, fP3, FltX[fric_depth2]) 32 | a_b[fric_depth3] .= Int1D(fP3, fP4, FltX[fric_depth3]) 33 | a_b[fric_depth4] .= Int1D(fP4, fP5, FltX[fric_depth4]) 34 | a_b[fric_depth5] .= 0.0047 35 | 36 | # cca[fric_depth4] .= Int1D(fP4, fP5, FltX[fric_depth4]) .+ 0.0001 37 | cca .= ccb .+ a_b 38 | # ccb .= cca .- a_b 39 | 40 | return cca, ccb 41 | end 42 | 43 | 44 | 45 | # Effective normal stress 46 | function SeffDepth(FltX) 47 | 48 | FltNglob = length(FltX) 49 | 50 | Seff::Array{Float64} = repeat([50e6], FltNglob) 51 | sP1 = [10e6 0] 52 | sP2 = [50e6 -2e3] 53 | Seff_depth = findall(abs.(FltX) .<= abs(sP2[2])) 54 | Seff[Seff_depth] = Int1D(sP1, sP2, FltX[Seff_depth]) 55 | 56 | return Seff 57 | end 58 | 59 | 60 | # Shear stress 61 | function tauDepth(FltX) 62 | 63 | FltNglob = length(FltX) 64 | 65 | tauo::Array{Float64} = repeat([22.5e6], FltNglob) 66 | tP1 = [0.01e6 0] 67 | tP2 = [30e6 -2e3] 68 | # tP2 = [30e6 -0.5e3] 69 | tP3 = [30e6 -14e3] 70 | tP4 = [22.5e6 -17e3] 71 | tP5 = [22.5e6 -24e3] 72 | 73 | tau_depth1 = findall(abs.(FltX) .<= abs(tP2[2])) 74 | tau_depth2 = findall(abs(tP2[2]) .< abs.(FltX) .<= abs(tP3[2])) 75 | tau_depth3 = findall(abs(tP3[2]) .< abs.(FltX) .<= abs(tP4[2])) 76 | tau_depth4 = findall(abs(tP4[2]) .< abs.(FltX) .<= abs(tP5[2])) 77 | 78 | tauo[tau_depth1] = Int1D(tP1, tP2, FltX[tau_depth1]) 79 | tauo[tau_depth2] = Int1D(tP2, tP3, FltX[tau_depth2]) 80 | tauo[tau_depth3] = Int1D(tP3, tP4, FltX[tau_depth3]) 81 | tauo[tau_depth4] = Int1D(tP4, tP5, FltX[tau_depth4]) 82 | 83 | return tauo 84 | end 85 | -------------------------------------------------------------------------------- /src/main.jl: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # SPECTRAL ELEMENT METHOD FOR EARTHQUAKE CYCLE SIMULATION 4 | # 5 | # Written in: Julia 1.0 6 | # 7 | # Created: 09/18/2022 8 | # Author: Prithvi Thakur (Original code by Kaneko et al. 2011) 9 | # 10 | # Adapted from Kaneko et al. (2011) 11 | # and J.P. Ampuero's SEMLAB 12 | # 13 | ############################################################################### 14 | 15 | function main(P) 16 | 17 | # P[1] = integer 18 | # P[2] = float 19 | # P[3] = float array 20 | # P[4] = integer array 21 | # P[5] = ksparse 22 | # P[6] = damage_idx 23 | 24 | 25 | 26 | # Time solver variables 27 | dt::Float64 = P[2].dt0 28 | dtmin::Float64 = dt 29 | half_dt::Float64 = 0.5*dtmin 30 | half_dt_sq::Float64 = 0.5*dtmin^2 31 | 32 | # dt modified slightly for damping 33 | if P[2].ETA != 0 34 | dt = dt/sqrt(1 + 2*P[2].ETA) 35 | end 36 | 37 | # Initialize kinematic field: global arrays 38 | d::Vector{Float64} = zeros(P[1].nglob) 39 | v::Vector{Float64} = zeros(P[1].nglob) 40 | v .= 0.5e-3 41 | a::Vector{Float64} = zeros(P[1].nglob) 42 | 43 | #..................................... 44 | # Stresses and time related variables 45 | #..................................... 46 | tau::Vector{Float64} = zeros(P[1].FltNglob) 47 | FaultC::Vector{Float64} = zeros(P[1].FltNglob) 48 | Vf::Vector{Float64} = zeros(P[1].FltNglob) 49 | Vf1::Vector{Float64} = zeros(P[1].FltNglob) 50 | Vf2::Vector{Float64} = zeros(P[1].FltNglob) 51 | Vf0::Vector{Float64} = zeros(length(P[4].iFlt)) 52 | FltVfree::Vector{Float64} = zeros(length(P[4].iFlt)) 53 | psi::Vector{Float64} = zeros(P[1].FltNglob) 54 | psi0::Vector{Float64} = zeros(P[1].FltNglob) 55 | psi1::Vector{Float64} = zeros(P[1].FltNglob) 56 | psi2::Vector{Float64} = zeros(P[1].FltNglob) 57 | tau1::Vector{Float64} = zeros(P[1].FltNglob) 58 | tau2::Vector{Float64} = zeros(P[1].FltNglob) 59 | tau3::Vector{Float64} = zeros(P[1].FltNglob) 60 | 61 | 62 | # Initial state variable 63 | psi = P[3].tauo./(P[3].Seff.*P[3].ccb) - P[3].fo./P[3].ccb - (P[3].cca./P[3].ccb).*log.(2*v[P[4].iFlt]./P[3].Vo) 64 | psi0 .= psi[:] 65 | 66 | isolver::Int = 1 67 | 68 | # Some more initializations 69 | r::Vector{Float64} = zeros(P[1].nglob) 70 | beta_::Vector{Float64} = zeros(P[1].nglob) 71 | alpha_::Vector{Float64} = zeros(P[1].nglob) 72 | 73 | F::Vector{Float64} = zeros(P[1].nglob) 74 | dPre::Vector{Float64} = zeros(P[1].nglob) 75 | vPre::Vector{Float64} = zeros(P[1].nglob) 76 | dd::Vector{Float64} = zeros(P[1].nglob) 77 | dnew::Vector{Float64} = zeros(length(P[4].FltNI)) 78 | 79 | 80 | # Save output variables at certain timesteps: define those timesteps 81 | tvsx::Float64 = 2e-0*P[1].yr2sec # 2 years for interseismic period 82 | tvsxinc::Float64 = tvsx 83 | 84 | tevneinc::Float64 = 0.1 # 0.1 second for seismic period 85 | delfref = zeros(P[1].FltNglob) 86 | 87 | # Iterators 88 | idelevne::Int= 0 89 | tevneb::Float64= 0. 90 | tevne::Float64= 0. 91 | ntvsx::Int= 0 92 | nevne::Int= 0 93 | slipstart::Int= 0 94 | idd::Int = 0 95 | it_s = 0; it_e = 0 96 | rit = 0 97 | 98 | v = v[:] .- 0.5*P[2].Vpl 99 | Vf = 2*v[P[4].iFlt] 100 | iFBC::Vector{Int64} = findall(abs.(P[3].FltX) .> 24e3) 101 | NFBC::Int64 = length(iFBC) + 1 102 | Vf[iFBC] .= 0. 103 | 104 | 105 | v[P[4].FltIglobBC] .= 0. 106 | 107 | # on fault and off fault stiffness 108 | Ksparse = P[5] 109 | 110 | # Intact rock stiffness 111 | Korig = copy(Ksparse) # K original 112 | 113 | # Linear solver stuff 114 | kni = -Ksparse[P[4].FltNI, P[4].FltNI] 115 | nKsparse = -Ksparse 116 | 117 | # algebraic multigrid preconditioner 118 | ml = ruge_stuben(kni) 119 | p = aspreconditioner(ml) 120 | tmp = copy(a) 121 | 122 | 123 | # faster matrix multiplication 124 | # Ksparse = Ksparse' 125 | # nKsparse = nKsparse' 126 | # kni = kni' 127 | 128 | # Ksparse = ThreadedMul(Ksparse) 129 | # nKsparse = ThreadedMul(nKsparse) 130 | # kni = ThreadedMul(kni) 131 | 132 | 133 | # Save parameters to file 134 | open(string(out_dir,"params.out"), "w") do io 135 | write(io, join(P[3].Seff/1e6, " "), "\n") 136 | write(io, join(P[3].tauo/1e6, " "), "\n") 137 | write(io, join(-P[3].FltX/1e3, " "), "\n") 138 | write(io, join(P[3].cca, " "), "\n") 139 | write(io, join(P[3].ccb, " "), "\n") 140 | write(io, join(P[3].xLf, " "), "\n") 141 | end 142 | 143 | 144 | # Open files to begin writing 145 | open(string(out_dir,"stress.out"), "w") do stress 146 | open(string(out_dir,"sliprate.out"), "w") do sliprate 147 | open(string(out_dir,"slip.out"), "w") do slip 148 | open(string(out_dir,"delfsec.out"), "w") do dfsec 149 | open(string(out_dir,"delfyr.out"), "w") do dfyr 150 | open(string(out_dir,"event_time.out"), "w") do event_time 151 | open(string(out_dir,"event_stress.out"), "w") do event_stress 152 | open(string(out_dir,"coseismic_slip.out"), "w") do dfafter 153 | open(string(out_dir,"time_velocity.out"), "w") do Vf_time 154 | 155 | #.................... 156 | # Start of time loop 157 | #.................... 158 | it = 0 159 | t = 0. 160 | Vfmax = 0. 161 | 162 | tStart2 = dt 163 | tStart = dt 164 | tEnd = dt 165 | taubefore = P[3].tauo 166 | tauafter = P[3].tauo 167 | delfafter = 2*d[P[4].iFlt] .+ P[2].Vpl*t 168 | hypo = 0. 169 | 170 | while t < P[1].Total_time 171 | it = it + 1 172 | t = t + dt 173 | 174 | if isolver == 1 175 | 176 | vPre .= v 177 | dPre .= d 178 | 179 | Vf0 .= 2*v[P[4].iFlt] .+ P[2].Vpl 180 | Vf .= Vf0 181 | 182 | for p1 = 1:2 183 | 184 | # Compute the on-Fault displacement 185 | F .= 0. 186 | F[P[4].iFlt] .= dPre[P[4].iFlt] .+ v[P[4].iFlt]*dt 187 | 188 | # Assign previous displacement field as initial guess 189 | dnew .= d[P[4].FltNI] 190 | 191 | 192 | # Solve d = K^-1F by MGCG 193 | rhs = (mul!(tmp,Ksparse,F))[P[4].FltNI] 194 | # rhs = (Ksparse*F)[P[4].FltNI] 195 | 196 | # direct inversion 197 | # dnew = -(kni\rhs) 198 | 199 | # mgcg 200 | dnew = cg!(dnew, kni, rhs, Pl=p, reltol=1e-6) 201 | 202 | # update displacement on the medium 203 | d[P[4].FltNI] .= dnew 204 | 205 | # make d = F on the fault 206 | d[P[4].iFlt] .= F[P[4].iFlt] 207 | 208 | # Compute on-fault stress 209 | a .= 0. 210 | mul!(a,Ksparse,d) 211 | # a = Ksparse*d 212 | 213 | # Enforce K*d to be zero for velocity boundary 214 | a[P[4].FltIglobBC] .= 0. 215 | 216 | tau1 .= -a[P[4].iFlt]./P[3].FltB 217 | 218 | # Function to calculate on-fault sliprate 219 | psi1, Vf1 = slrFunc!(P[3], NFBC, P[1].FltNglob, psi, psi1, Vf, Vf1, P[1].IDstate, tau1, dt) 220 | 221 | Vf1[iFBC] .= P[2].Vpl 222 | Vf .= (Vf0 + Vf1)/2 223 | v[P[4].iFlt] .= 0.5*(Vf .- P[2].Vpl) 224 | 225 | end 226 | 227 | psi .= psi1[:] 228 | tau .= tau1[:] 229 | tau[iFBC] .= 0. 230 | Vf1[iFBC] .= P[2].Vpl 231 | 232 | v[P[4].iFlt] .= 0.5*(Vf1 .- P[2].Vpl) 233 | v[P[4].FltNI] .= (d[P[4].FltNI] .- dPre[P[4].FltNI])/dt 234 | 235 | # Line 731: P_MA: Omitted 236 | a .= 0. 237 | d[P[4].FltIglobBC] .= 0. 238 | v[P[4].FltIglobBC] .= 0. 239 | 240 | 241 | # If isolver != 1, or max slip rate is < 10^-2 m/s 242 | else 243 | 244 | dPre .= d 245 | vPre .= v 246 | 247 | # Update 248 | d .= d .+ dt.*v .+ (half_dt_sq).*a 249 | 250 | # Prediction 251 | v .= v .+ half_dt.*a 252 | a .= 0. 253 | 254 | # Internal forces -K*d[t+1] stored in global array 'a' 255 | mul!(a,nKsparse,d) 256 | # a = nKsparse*d 257 | 258 | # Enforce K*d to be zero for velocity boundary 259 | a[P[4].FltIglobBC] .= 0. 260 | 261 | # Absorbing boundaries 262 | a[P[4].iBcL] .= a[P[4].iBcL] .- P[3].BcLC.*v[P[4].iBcL] 263 | a[P[4].iBcT] .= a[P[4].iBcT] .- P[3].BcTC.*v[P[4].iBcT] 264 | 265 | ###### Fault Boundary Condition: Rate and State ############# 266 | FltVfree .= 2*v[P[4].iFlt] .+ 2*half_dt*a[P[4].iFlt]./P[3].M[P[4].iFlt] 267 | Vf .= 2*vPre[P[4].iFlt] .+ P[2].Vpl 268 | 269 | 270 | # Sliprate and NR search 271 | psi1, Vf1, tau1, psi2, Vf2, tau2 = FBC!(P[1].IDstate, P[3], NFBC, P[1].FltNglob, psi1, Vf1, tau1, psi2, Vf2, tau2, psi, Vf, FltVfree, dt) 272 | 273 | tau .= tau2 .- P[3].tauo 274 | tau[iFBC] .= 0. 275 | psi .= psi2 276 | a[P[4].iFlt] .= a[P[4].iFlt] .- P[3].FltB.*tau 277 | ########## End of fault boundary condition ############## 278 | 279 | 280 | # Solve for a_new 281 | a .= a./P[3].M 282 | 283 | # Correction 284 | v .= v .+ half_dt*a 285 | 286 | v[P[4].FltIglobBC] .= 0. 287 | a[P[4].FltIglobBC] .= 0. 288 | 289 | #### Line 861: Omitting P_Ma 290 | 291 | 292 | end # of isolver if loop 293 | 294 | Vfmax = 2*maximum(v[P[4].iFlt]) .+ P[2].Vpl 295 | 296 | #----- 297 | # Output the variables before and after events 298 | #----- 299 | if Vfmax > 1.01*P[2].Vthres && slipstart == 0 300 | it_s = it_s + 1 301 | delfref = 2*d[P[4].iFlt] .+ P[2].Vpl*t 302 | 303 | slipstart = 1 304 | 305 | tStart = t 306 | taubefore = (tau +P[3].tauo)./1e6 307 | 308 | vhypo, indx = findmax(2*v[P[4].iFlt] .+ P[2].Vpl) 309 | hypo = P[3].FltX[indx] 310 | 311 | end 312 | if Vfmax < 0.99*P[2].Vthres && slipstart == 1 313 | it_e = it_e + 1 314 | delfafter = 2*d[P[4].iFlt] .+ P[2].Vpl*t .- delfref 315 | 316 | tEnd = t 317 | tauafter = (tau +P[3].tauo)./1e6 318 | 319 | # Save start and end time and stress 320 | write(event_time, join(hcat(tStart,tEnd, -hypo), " "), "\n") 321 | write(event_stress, join(hcat(taubefore, tauafter), " "), "\n") 322 | write(dfafter, join(delfafter, " "), "\n") 323 | 324 | slipstart = 0 325 | 326 | end 327 | 328 | 329 | 330 | #----- 331 | # Output the variables certain timesteps: 2yr interseismic, 1 sec dynamic 332 | #----- 333 | if t > tvsx 334 | ntvsx = ntvsx + 1 335 | idd += 1 336 | # write(stress, join((tau + P[3].tauo)./1e6, " "), "\n") 337 | write(dfyr, join(2*d[P[4].iFlt] .+ P[2].Vpl*t, " "), "\n") 338 | 339 | tvsx = tvsx + tvsxinc 340 | end 341 | 342 | if Vfmax > P[2].Vevne 343 | if idelevne == 0 344 | nevne = nevne + 1 345 | idd += 1 346 | idelevne = 1 347 | tevneb = t 348 | tevne = tevneinc 349 | 350 | # write(stress, join((tau + P[3].tauo)./1e6, " "), "\n") 351 | write(dfsec, join(2*d[P[4].iFlt] .+ P[2].Vpl*t, " "), "\n") 352 | end 353 | 354 | if idelevne == 1 && (t - tevneb) > tevne 355 | nevne = nevne + 1 356 | idd += 1 357 | 358 | write(dfsec, join(2*d[P[4].iFlt] .+ P[2].Vpl*t, " "), "\n") 359 | tevne = tevne + tevneinc 360 | end 361 | 362 | else 363 | idelevne = 0 364 | end 365 | 366 | current_sliprate = 2*v[P[4].iFlt] .+ P[2].Vpl 367 | 368 | # Output timestep info on screen 369 | if mod(it,500) == 0 370 | @printf("Time (yr) = %1.5g\n", t/P[1].yr2sec) 371 | # println("Vfmax = ", maximum(current_sliprate)) 372 | end 373 | 374 | 375 | # Write stress, sliprate, slip to file every 10 timesteps 376 | if mod(it,10) == 0 377 | write(sliprate, join(2*v[P[4].iFlt] .+ P[2].Vpl, " "), "\n") 378 | write(stress, join((tau + P[3].tauo)./1e6, " "), "\n") 379 | end 380 | 381 | # Determine quasi-static or dynamic regime based on max-slip velocity 382 | # if isolver == 1 && Vfmax < 5e-3 || isolver == 2 && Vfmax < 2e-3 383 | if isolver == 1 && Vfmax < 5e-3 || isolver == 2 && Vfmax < 2e-3 384 | isolver = 1 385 | else 386 | isolver = 2 387 | end 388 | 389 | # Write max sliprate and time 390 | write(Vf_time, join(hcat(t,Vfmax,Vf[end]), " "), "\n") 391 | 392 | # Compute next timestep dt 393 | dt = dtevol!(dt , dtmin, P[3].XiLf, P[1].FltNglob, NFBC, current_sliprate, isolver) 394 | 395 | 396 | end # end of time loop 397 | 398 | # close files 399 | end 400 | end 401 | end 402 | end 403 | end 404 | end 405 | end 406 | end 407 | end 408 | 409 | 410 | end 411 | -------------------------------------------------------------------------------- /src/otherFunctions.jl: -------------------------------------------------------------------------------- 1 | exp1(x::Float64) = ccall(:exp, Float64, (Float64,), x) 2 | log1(x::Float64) = ccall(:log, Float64, (Float64,), x) 3 | 4 | # IDstate functions 5 | function IDS!(xLf, Vo, psi, dt, Vf, cnd, IDstate = 2) 6 | #= compute slip-rates on fault based on different 7 | formulations =# 8 | 9 | if IDstate == 1 10 | psi1 = psi + dt*((Vo./xLf).*exp1(-psi) - abs(Vf)./xLf) 11 | 12 | elseif IDstate == 2 13 | VdtL = abs(Vf)*dt/xLf 14 | if VdtL < cnd 15 | psi1 = log1( exp1(psi-VdtL) + Vo*dt/xLf - 16 | 0.5*Vo*abs(Vf)*dt*dt/(xLf^2)) 17 | else 18 | psi1 = log1(exp1(psi-VdtL) + (Vo/abs(Vf))*(1-exp1(-VdtL))) 19 | end 20 | 21 | elseif IDstate == 3 22 | psi1 = exp1(-abs(Vf)*dt/xLf) * log1(abs(Vf)/Vo) + 23 | exp1(-abs(Vf)*dt/xLf)*psi + log1(Vo/abs(Vf)) 24 | 25 | if ~any(imag(psi1)) == 0 26 | return 27 | end 28 | end 29 | 30 | return psi1 31 | 32 | end 33 | 34 | # On fault slip rates 35 | function IDS2!(xLf, Vo, psi, psi1, dt, Vf, Vf1, IDstate = 2) 36 | 37 | if IDstate == 1 38 | psi2 = psi + 0.5*dt*( (Vo/xLf)*exp1(-psi) - abs(Vf)/xLf 39 | + (Vo/xLf)*exp1(-psi1) - abs(Vf1)/xLf ) 40 | 41 | elseif IDstate == 2 42 | VdtL = 0.5*abs(Vf1 + Vf)*dt/xLf 43 | 44 | if VdtL < 1e-6 45 | psi2 = log1( exp1(psi-VdtL) + Vo*dt/xLf - 46 | 0.5*Vo*0.5*abs(Vf1 + Vf)*dt*dt/(xLf^2)) 47 | else 48 | psi2 = log1(exp1(psi-VdtL) + 49 | (Vo/(0.5*abs(Vf + Vf1)))*(1-exp1(-VdtL))) 50 | end 51 | 52 | elseif IDstate == 3 53 | psi2 = exp1(-0.5*abs(Vf + Vf1)*dt/xLf) * log1(0.5*abs(Vf + Vf1)/Vo) + 54 | exp1(-0.5*abs(Vf + Vf1)*dt/xLf)*psi 55 | + log1(Vo/(-0.5*abs(Vf + Vf1)) ) 56 | end 57 | 58 | return psi2 59 | end 60 | 61 | # Slip rates on fault for quasi-static regime 62 | function slrFunc!(P::params_farray, NFBC, FltNglob, psi, psi1, Vf, Vf1, IDstate, tau1, dt) 63 | 64 | tauAB::Vector{Float64} = zeros(FltNglob) 65 | 66 | # temp::Float64 = 0. 67 | 68 | for j = NFBC:FltNglob 69 | 70 | # temp = 0. 71 | psi1[j] = IDS!(P.xLf[j], P.Vo[j], psi[j], dt, Vf[j], 1e-6, IDstate) 72 | 73 | tauAB[j] = tau1[j] + P.tauo[j] 74 | fa = tauAB[j]/(P.Seff[j]*P.cca[j]) 75 | help = -(P.fo[j] + P.ccb[j]*psi1[j])/P.cca[j] 76 | help1 = exp(help + fa) 77 | help2 = exp(help - fa) 78 | Vf1[j] = P.Vo[j]*(help1 - help2) 79 | end 80 | 81 | return psi1, Vf1 82 | 83 | end 84 | -------------------------------------------------------------------------------- /src/untitled.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thehalfspace/Spear/0b7dc5671761d1a06fe2f700e0ef39557eb67cda/src/untitled.txt -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | ### Test for different simulation runs, and their results. 2 | -------------------------------------------------------------------------------- /tests/basic_test_01.jl: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Basic testing to visualize results 3 | # ##################################### 4 | 5 | include("$(@__DIR__)/../analyze_results.jl") 6 | 7 | VfmaxPlot(Vfmax, t, yr2sec); 8 | cumSlipPlot(delfsec[1:4:end,:], delfyr[1:4:end, :], FltX); 9 | -------------------------------------------------------------------------------- /xfer/xfer_dizhi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scp prith@dizhi.earth.lsa.umich.edu:/opt/home/prith/Desktop/JuliaSEM/output/$1 /Users/prith/JuliaSEM/output/dizhi_sims/ 4 | -------------------------------------------------------------------------------- /xfer/xfer_down: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scp flux-xfer.arc-ts.umich.edu:$1 . 4 | -------------------------------------------------------------------------------- /xfer/xfer_up: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scp $1 flux-xfer.arc-ts.umich.edu: 4 | -------------------------------------------------------------------------------- /xfer/xfer_wozhi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scp -r prith@wozhi.earth.lsa.umich.edu:/opt/home/prith/damageEvol/data/$1 /Users/prith/damage_evol/data/. 4 | --------------------------------------------------------------------------------