1D PDE: SIS diffusion model

1D PDE: SIS diffusion model#

Source

\[\begin{split} \begin{align} \frac{\partial S}{\partial t} &= d_S S_{xx} - \beta(x)\frac{SI}{S+I} + \gamma(x)I \\ \frac{\partial I}{\partial t} &= d_I I_{xx} + \beta(x)\frac{SI}{S+I} - \gamma(x)I \end{align} \end{split}\]

where \(x \in (0, 1)\)

Solve the steady-state problem \(\frac{\partial S}{\partial t} = \frac{\partial I}{\partial t} = 0\)

The boundary condition: \(\frac{\partial S}{\partial x} = \frac{\partial I}{\partial x} = 0\) for x = 0, 1

The conservative relationship: \(\int^{1}_{0} (S(x) + I(x) ) dx = 1\)

Notations:

  • \(x\) : location

  • \(t\) : time

  • \(S(x, t)\) : the density of susceptible populations

  • \(I(x, t)\) : the density of infected populations

  • \(d_S\) / \(d_I\) : the diffusion coefficients for susceptible and infected individuals

  • \(\beta(x)\) : transmission rates

  • \(\gamma(x)\) : recovery rates

using OrdinaryDiffEq
using ModelingToolkit
using MethodOfLines
using DomainSets
using Plots
Precompiling OrdinaryDiffEq...
    477.3 ms  ✓ IteratorInterfaceExtensions
    509.8 ms  ✓ ConcreteStructs
    665.5 ms  ✓ SimpleUnPack
    923.2 ms  ✓ ADTypes
   1010.0 ms  ✓ FunctionWrappers
    650.2 ms  ✓ InverseFunctions
    573.5 ms  ✓ SciMLPublic
    555.4 ms  ✓ ExprTools
    964.2 ms  ✓ DocStringExtensions
    447.0 ms  ✓ UnPack
    499.7 ms  ✓ CommonSolve
    859.8 ms  ✓ Statistics
    825.6 ms  ✓ NaNMath
    530.4 ms  ✓ ManualMemory
    738.1 ms  ✓ Requires
    828.7 ms  ✓ OrderedCollections
   1675.0 ms  ✓ IrrationalConstants
    796.2 ms  ✓ EnumX
    418.4 ms  ✓ Reexport
   3119.7 ms  ✓ ExproniconLite
    473.6 ms  ✓ IfElse
    559.5 ms  ✓ ConstructionBase
    598.6 ms  ✓ CommonWorldInvalidations
    597.7 ms  ✓ StaticArraysCore
    528.5 ms  ✓ MuladdMacro
    616.6 ms  ✓ FastClosures
    526.3 ms  ✓ CompositionsBase
    585.8 ms  ✓ SIMDTypes
   1313.4 ms  ✓ FillArrays
    448.5 ms  ✓ FastPower
    888.3 ms  ✓ EnzymeCore
   1857.0 ms  ✓ GenericSchur
    982.9 ms  ✓ CpuId
    707.8 ms  ✓ Compat
    895.3 ms  ✓ OpenSpecFun_jll
   1071.8 ms  ✓ oneTBB_jll
   4184.2 ms  ✓ MacroTools
   2067.3 ms  ✓ IntelOpenMP_jll
   2780.5 ms  ✓ RecipesBase
    798.8 ms  ✓ FunctionWrappersWrappers
   2064.2 ms  ✓ DifferentiationInterface
   1047.5 ms  ✓ InverseFunctions → InverseFunctionsDatesExt
    710.5 ms  ✓ RuntimeGeneratedFunctions
   1025.7 ms  ✓ Statistics → SparseArraysExt
   1439.4 ms  ✓ ThreadingUtilities
    751.6 ms  ✓ Adapt
    700.2 ms  ✓ Parameters
   1036.0 ms  ✓ LogExpFunctions
    707.1 ms  ✓ ConstructionBase → ConstructionBaseLinearAlgebraExt
    678.8 ms  ✓ ADTypes → ADTypesConstructionBaseExt
   4946.3 ms  ✓ TimerOutputs
    641.4 ms  ✓ DiffResults
   1363.3 ms  ✓ Static
   3789.4 ms  ✓ Jieko
    628.4 ms  ✓ CompositionsBase → CompositionsBaseInverseFunctionsExt
    766.0 ms  ✓ FillArrays → FillArraysStatisticsExt
  11912.3 ms  ✓ Krylov
    605.4 ms  ✓ ADTypes → ADTypesEnzymeCoreExt
   1081.2 ms  ✓ FillArrays → FillArraysSparseArraysExt
    711.0 ms  ✓ Compat → CompatLinearAlgebraExt
    800.8 ms  ✓ CommonSubexpressions
    857.6 ms  ✓ TruncatedStacktraces
    729.3 ms  ✓ GPUArraysCore
   1054.8 ms  ✓ DifferentiationInterface → DifferentiationInterfaceSparseArraysExt
   1075.1 ms  ✓ Adapt → AdaptSparseArraysExt
    896.8 ms  ✓ ArrayInterface
   2352.2 ms  ✓ MKL_jll
    738.9 ms  ✓ EnzymeCore → AdaptExt
    891.1 ms  ✓ LogExpFunctions → LogExpFunctionsInverseFunctionsExt
   1109.9 ms  ✓ BitTwiddlingConvenienceFunctions
   2662.3 ms  ✓ Setfield
   1958.0 ms  ✓ CPUSummary
  15756.6 ms  ✓ SparseMatrixColorings
   5242.8 ms  ✓ SpecialFunctions
   2491.5 ms  ✓ ChainRulesCore
   3143.2 ms  ✓ DataStructures
   4507.1 ms  ✓ Accessors
    688.0 ms  ✓ DifferentiationInterface → DifferentiationInterfaceGPUArraysCoreExt
  13818.6 ms  ✓ StaticArrays
    586.5 ms  ✓ SciMLStructures
   1087.1 ms  ✓ MaybeInplace
    953.9 ms  ✓ ArrayInterface → ArrayInterfaceSparseArraysExt
    545.7 ms  ✓ ArrayInterface → ArrayInterfaceGPUArraysCoreExt
   1838.1 ms  ✓ StaticArrayInterface
    833.0 ms  ✓ ArrayInterface → ArrayInterfaceStaticArraysCoreExt
    727.1 ms  ✓ PolyesterWeave
   1473.1 ms  ✓ PreallocationTools
    765.5 ms  ✓ ChainRulesCore → ChainRulesCoreSparseArraysExt
   1335.7 ms  ✓ DifferentiationInterface → DifferentiationInterfaceSparseMatrixColoringsExt
   1204.6 ms  ✓ DiffRules
    560.8 ms  ✓ DifferentiationInterface → DifferentiationInterfaceChainRulesCoreExt
    711.5 ms  ✓ ADTypes → ADTypesChainRulesCoreExt
    752.1 ms  ✓ ArrayInterface → ArrayInterfaceChainRulesCoreExt
    986.9 ms  ✓ Accessors → LinearAlgebraExt
   1015.6 ms  ✓ StaticArrays → StaticArraysStatisticsExt
   2112.4 ms  ✓ LogExpFunctions → LogExpFunctionsChainRulesCoreExt
    867.5 ms  ✓ StaticArrays → StaticArraysChainRulesCoreExt
   1060.6 ms  ✓ ConstructionBase → ConstructionBaseStaticArraysExt
    899.7 ms  ✓ DifferentiationInterface → DifferentiationInterfaceStaticArraysExt
   2974.2 ms  ✓ SpecialFunctions → SpecialFunctionsChainRulesCoreExt
   1112.9 ms  ✓ Adapt → AdaptStaticArraysExt
   1277.1 ms  ✓ Accessors → StaticArraysExt
   1059.8 ms  ✓ MaybeInplace → MaybeInplaceSparseArraysExt
   3119.1 ms  ✓ FastGaussQuadrature
   1192.9 ms  ✓ StaticArrayInterface → StaticArrayInterfaceStaticArraysExt
    912.6 ms  ✓ CloseOpenIntervals
   1154.3 ms  ✓ LayoutPointers
   1364.0 ms  ✓ FiniteDiff
  18338.2 ms  ✓ Moshi
   2755.0 ms  ✓ SciMLOperators
   1985.1 ms  ✓ SymbolicIndexingInterface
   1605.1 ms  ✓ StrideArraysCore
    974.7 ms  ✓ FiniteDiff → FiniteDiffSparseArraysExt
   5975.0 ms  ✓ ForwardDiff
   1203.8 ms  ✓ FiniteDiff → FiniteDiffStaticArraysExt
    959.4 ms  ✓ DifferentiationInterface → DifferentiationInterfaceFiniteDiffExt
    701.1 ms  ✓ SciMLOperators → SciMLOperatorsStaticArraysCoreExt
   1053.2 ms  ✓ SciMLOperators → SciMLOperatorsSparseArraysExt
   1376.9 ms  ✓ Polyester
   1227.6 ms  ✓ ForwardDiff → ForwardDiffStaticArraysExt
   1145.9 ms  ✓ FastPower → FastPowerForwardDiffExt
   3187.6 ms  ✓ RecursiveArrayTools
   1137.3 ms  ✓ DifferentiationInterface → DifferentiationInterfaceForwardDiffExt
   1100.7 ms  ✓ PreallocationTools → PreallocationToolsForwardDiffExt
    911.7 ms  ✓ RecursiveArrayTools → RecursiveArrayToolsForwardDiffExt
   1270.1 ms  ✓ FastBroadcast
   1102.8 ms  ✓ RecursiveArrayTools → RecursiveArrayToolsSparseArraysExt
   1028.6 ms  ✓ RecursiveArrayTools → RecursiveArrayToolsFastBroadcastExt
   1394.4 ms  ✓ NLSolversBase
   2293.1 ms  ✓ LineSearches
  20233.6 ms  ✓ ArrayLayouts
   1504.6 ms  ✓ ArrayLayouts → ArrayLayoutsSparseArraysExt
   3324.5 ms  ✓ LazyArrays
   8859.7 ms  ✓ SciMLBase
   1600.6 ms  ✓ SciMLBase → SciMLBaseChainRulesCoreExt
   1748.2 ms  ✓ LazyArrays → LazyArraysStaticArraysExt
   1816.4 ms  ✓ SciMLBase → SciMLBaseForwardDiffExt
   4254.9 ms  ✓ SciMLJacobianOperators
   2842.6 ms  ✓ DiffEqBase
   1575.8 ms  ✓ DiffEqBase → DiffEqBaseChainRulesCoreExt
   1927.7 ms  ✓ DiffEqBase → DiffEqBaseForwardDiffExt
   1939.7 ms  ✓ DiffEqBase → DiffEqBaseSparseArraysExt
   6539.3 ms  ✓ LineSearch
   1602.4 ms  ✓ LineSearch → LineSearchLineSearchesExt
   9622.8 ms  ✓ NonlinearSolveBase
   5330.4 ms  ✓ OrdinaryDiffEqCore
   1899.3 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseSparseMatrixColoringsExt
   1968.2 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseForwardDiffExt
   1528.3 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseChainRulesCoreExt
   1331.2 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseLineSearchExt
   2127.4 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseSparseArraysExt
   1775.5 ms  ✓ OrdinaryDiffEqCore → OrdinaryDiffEqCoreEnzymeCoreExt
   2846.3 ms  ✓ OrdinaryDiffEqFunctionMap
   7642.1 ms  ✓ BracketingNonlinearSolve
   3424.3 ms  ✓ OrdinaryDiffEqPRK
   4063.4 ms  ✓ OrdinaryDiffEqExplicitRK
  15993.5 ms  ✓ NonlinearSolveSpectralMethods
  13450.5 ms  ✓ OrdinaryDiffEqTsit5
   5105.7 ms  ✓ OrdinaryDiffEqStabilizedRK
   5421.2 ms  ✓ OrdinaryDiffEqSSPRK
   4240.8 ms  ✓ OrdinaryDiffEqRKN
   3373.4 ms  ✓ OrdinaryDiffEqQPRK
   3716.6 ms  ✓ OrdinaryDiffEqSymplecticRK
   4574.9 ms  ✓ OrdinaryDiffEqHighOrderRK
   8471.4 ms  ✓ OrdinaryDiffEqLowOrderRK
   5833.8 ms  ✓ OrdinaryDiffEqFeagin
  48730.9 ms  ✓ LinearSolve
   2438.7 ms  ✓ BracketingNonlinearSolve → BracketingNonlinearSolveForwardDiffExt
   2522.2 ms  ✓ NonlinearSolveSpectralMethods → NonlinearSolveSpectralMethodsForwardDiffExt
   3668.6 ms  ✓ OrdinaryDiffEqNordsieck
   7622.8 ms  ✓ OrdinaryDiffEqLowStorageRK
   5186.6 ms  ✓ OrdinaryDiffEqAdamsBashforthMoulton
   4673.4 ms  ✓ LinearSolve → LinearSolveEnzymeExt
  84871.2 ms  ✓ ExponentialUtilities
   1813.2 ms  ✓ BracketingNonlinearSolve → BracketingNonlinearSolveChainRulesCoreExt
   6260.0 ms  ✓ LinearSolve → LinearSolveForwardDiffExt
   4359.2 ms  ✓ NonlinearSolveBase → NonlinearSolveBaseLinearSolveExt
  10124.8 ms  ✓ LinearSolve → LinearSolveSparseArraysExt
   2754.0 ms  ✓ ExponentialUtilities → ExponentialUtilitiesStaticArraysExt
   4027.3 ms  ✓ OrdinaryDiffEqLinear
   7975.8 ms  ✓ OrdinaryDiffEqDifferentiation
   5061.8 ms  ✓ OrdinaryDiffEqDifferentiation → OrdinaryDiffEqDifferentiationSparseArraysExt
  21518.6 ms  ✓ SimpleNonlinearSolve
  30010.9 ms  ✓ NonlinearSolveQuasiNewton
  11862.0 ms  ✓ OrdinaryDiffEqExtrapolation
   2742.4 ms  ✓ SimpleNonlinearSolve → SimpleNonlinearSolveChainRulesCoreExt
   5681.7 ms  ✓ NonlinearSolveQuasiNewton → NonlinearSolveQuasiNewtonForwardDiffExt
   9054.5 ms  ✓ OrdinaryDiffEqExponentialRK
  56211.4 ms  ✓ NonlinearSolveFirstOrder
  82446.0 ms  ✓ OrdinaryDiffEqVerner
  49606.8 ms  ✓ OrdinaryDiffEqRosenbrock
  13409.3 ms  ✓ NonlinearSolve
   4555.8 ms  ✓ OrdinaryDiffEqNonlinearSolve
   7505.8 ms  ✓ OrdinaryDiffEqStabilizedIRK
   7525.6 ms  ✓ OrdinaryDiffEqIMEXMultistep
   8450.2 ms  ✓ OrdinaryDiffEqPDIRK
   9212.3 ms  ✓ OrdinaryDiffEqSDIRK
  14590.7 ms  ✓ OrdinaryDiffEqBDF
  25565.5 ms  ✓ OrdinaryDiffEqFIRK
  30627.8 ms  ✓ OrdinaryDiffEqDefault
   4714.3 ms  ✓ OrdinaryDiffEq
  201 dependencies successfully precompiled in 261 seconds. 35 already precompiled.
  2 dependencies had output during precompilation:
┌ Polyester
│  WARNING: using Static.static_first in module Polyester conflicts with an existing identifier.
│  WARNING: using Static.static_step in module Polyester conflicts with an existing identifier.
└  
┌ LinearSolve
│  Downloading artifact: MKL
└  
Precompiling ModelingToolkit...
    539.9 ms  ✓ LaTeXStrings
    546.6 ms  ✓ Glob
    548.2 ms  ✓ Tricks
    741.5 ms  ✓ StatsAPI
    721.1 ms  ✓ IntervalSets
    533.6 ms  ✓ FindFirstFunctions
    864.5 ms  ✓ AbstractTrees
   1560.6 ms  ✓ OffsetArrays
   1187.8 ms  ✓ URIs
    492.3 ms  ✓ IntegerMathUtils
    625.3 ms  ✓ TestItems
    630.7 ms  ✓ PtrArrays
    653.1 ms  ✓ DataAPI
    684.8 ms  ✓ CompositeTypes
   1780.4 ms  ✓ Format
   1355.8 ms  ✓ Combinatorics
   1348.3 ms  ✓ RandomNumbers
    726.3 ms  ✓ Inflate
    593.9 ms  ✓ TermInterface
    573.5 ms  ✓ Bijections
    729.9 ms  ✓ PositiveFactorizations
    507.2 ms  ✓ TaskLocalValues
    901.3 ms  ✓ SuiteSparse
    744.7 ms  ✓ PoissonRandom
   1026.9 ms  ✓ Unityper
   1085.0 ms  ✓ SimpleTraits
   1003.4 ms  ✓ InverseFunctions → InverseFunctionsTestExt
    919.6 ms  ✓ Accessors → TestExt
    975.9 ms  ✓ Functors
   2379.1 ms  ✓ DispatchDoctor
   1161.1 ms  ✓ JpegTurbo_jll
   1136.6 ms  ✓ Rmath_jll
  10437.6 ms  ✓ MutableArithmetics
    892.7 ms  ✓ SortingAlgorithms
   1710.2 ms  ✓ QuadGK
   2126.1 ms  ✓ ArnoldiMethod
   1446.4 ms  ✓ ResettableStacks
   2006.5 ms  ✓ HypergeometricFunctions
   4809.0 ms  ✓ BlockArrays
   2292.3 ms  ✓ SCCNonlinearSolve
   4589.1 ms  ✓ ImplicitDiscreteSolve
  23959.6 ms  ✓ CommonMark
   1522.4 ms  ✓ IntervalSets → IntervalSetsRecipesBaseExt
   1103.9 ms  ✓ IntervalSets → IntervalSetsRandomExt
   1026.6 ms  ✓ IntervalSets → IntervalSetsStatisticsExt
   1040.4 ms  ✓ ConstructionBase → ConstructionBaseIntervalSetsExt
   1453.0 ms  ✓ Accessors → IntervalSetsExt
   1173.0 ms  ✓ OffsetArrays → OffsetArraysAdaptExt
    885.5 ms  ✓ StaticArrayInterface → StaticArrayInterfaceOffsetArraysExt
  39213.3 ms  ✓ MLStyle
    869.4 ms  ✓ AliasTables
   1686.2 ms  ✓ Primes
   1370.4 ms  ✓ Missings
   1667.1 ms  ✓ PDMats
   2263.3 ms  ✓ Random123
    979.4 ms  ✓ DispatchDoctor → DispatchDoctorEnzymeCoreExt
   1356.8 ms  ✓ DispatchDoctor → DispatchDoctorChainRulesCoreExt
  42546.1 ms  ✓ JuliaSyntax
   1723.7 ms  ✓ Rmath
   2269.1 ms  ✓ Ghostscript_jll
   6685.4 ms  ✓ DiffEqCallbacks
  45606.0 ms  ✓ Unitful
   1750.5 ms  ✓ BlockArrays → BlockArraysAdaptExt
   4769.3 ms  ✓ MultivariatePolynomials
   1432.2 ms  ✓ SciMLBase → SciMLBaseMLStyleExt
   3743.9 ms  ✓ DomainSets
   1109.8 ms  ✓ FillArrays → FillArraysPDMatsExt
   6991.6 ms  ✓ Graphs
  11601.4 ms  ✓ DynamicQuantities
   4232.0 ms  ✓ StatsBase
   3181.1 ms  ✓ StatsFuns
    973.0 ms  ✓ Unitful → InverseFunctionsUnitfulExt
   1051.0 ms  ✓ Unitful → PrintfExt
   1147.5 ms  ✓ Unitful → ForwardDiffExt
   1152.2 ms  ✓ Unitful → ConstructionBaseUnitfulExt
   1122.5 ms  ✓ Accessors → UnitfulExt
   1741.9 ms  ✓ DiffEqBase → DiffEqBaseUnitfulExt
   1487.6 ms  ✓ DomainSets → DomainSetsRandomExt
   5934.2 ms  ✓ Latexify
   2667.1 ms  ✓ DynamicPolynomials
   1488.3 ms  ✓ DynamicQuantities → DynamicQuantitiesLinearAlgebraExt
   2240.9 ms  ✓ DynamicQuantities → DynamicQuantitiesUnitfulExt
    845.1 ms  ✓ StatsFuns → StatsFunsInverseFunctionsExt
   4768.3 ms  ✓ JumpProcesses
   2390.5 ms  ✓ StatsFuns → StatsFunsChainRulesCoreExt
   4438.1 ms  ✓ Optim
   1329.8 ms  ✓ Latexify → SparseArraysExt
   1423.9 ms  ✓ Unitful → LatexifyExt
   6305.2 ms  ✓ Distributions
   1668.6 ms  ✓ Distributions → DistributionsChainRulesCoreExt
   1787.7 ms  ✓ Distributions → DistributionsTestExt
   2100.8 ms  ✓ SciMLBase → SciMLBaseDistributionsExt
   3537.8 ms  ✓ DiffEqNoiseProcess
  28591.4 ms  ✓ SymbolicUtils
   1512.9 ms  ✓ SymbolicLimits
  42317.5 ms  ✓ JuliaFormatter
  20827.1 ms  ✓ Symbolics
   2424.9 ms  ✓ DifferentiationInterface → DifferentiationInterfaceSymbolicsExt
   2849.1 ms  ✓ Symbolics → SymbolicsForwardDiffExt
   2347.5 ms  ✓ Symbolics → SymbolicsPreallocationToolsExt
 123428.0 ms  ✓ ModelingToolkit
  101 dependencies successfully precompiled in 243 seconds. 169 already precompiled.
Precompiling LazyArraysBlockArraysExt...
   1190.0 ms  ✓ LazyArrays → LazyArraysBlockArraysExt
  1 dependency successfully precompiled in 2 seconds. 19 already precompiled.
Precompiling MethodOfLines...
    372.3 ms  ✓ Ratios
    665.3 ms  ✓ WoodburyMatrices
    518.4 ms  ✓ AxisAlgorithms
   1577.7 ms  ✓ Interpolations
   1324.2 ms  ✓ Interpolations → InterpolationsForwardDiffExt
   1384.8 ms  ✓ Interpolations → InterpolationsUnitfulExt
   6282.0 ms  ✓ PDEBase
Info Given MethodOfLines was explicitly requested, output will be shown live 
┌ Warning: The system contains interface boundaries, which are not compatible with system transformation. The system will not be transformed. Please post an issue if you need this feature.
└ @ MethodOfLines ~/.julia/packages/MethodOfLines/JDu9X/src/system_parsing/pde_system_transformation.jl:43
 119948.6 ms  ✓ MethodOfLines
  8 dependencies successfully precompiled in 127 seconds. 341 already precompiled.
  1 dependency had output during precompilation:
┌ MethodOfLines
│  [Output was shown above]
└  
Precompiling Plots...
    645.7 ms  ✓ SimpleBufferStream
    726.2 ms  ✓ Contour
    753.4 ms  ✓ TranscodingStreams
    791.9 ms  ✓ Measures
    563.0 ms  ✓ BitFlags
    575.7 ms  ✓ TensorCore
   1418.4 ms  ✓ Grisu
    645.8 ms  ✓ StableRNGs
    676.3 ms  ✓ DelimitedFiles
    900.9 ms  ✓ Unzip
   1325.4 ms  ✓ ConcurrentUtilities
    698.7 ms  ✓ Scratch
    753.5 ms  ✓ LoggingExtras
   1870.8 ms  ✓ MbedTLS
    863.3 ms  ✓ ExceptionUnwrapping
   1053.2 ms  ✓ OpenSSL_jll
   1021.1 ms  ✓ Libffi_jll
   1252.3 ms  ✓ Xorg_libICE_jll
   4159.2 ms  ✓ FixedPointNumbers
   1179.5 ms  ✓ Libuuid_jll
   2628.3 ms  ✓ UnicodeFun
    906.8 ms  ✓ fzf_jll
   1023.3 ms  ✓ LLVMOpenMP_jll
    878.7 ms  ✓ Ogg_jll
    908.0 ms  ✓ mtdev_jll
    886.2 ms  ✓ x265_jll
    995.5 ms  ✓ x264_jll
   1017.9 ms  ✓ Libiconv_jll
    953.3 ms  ✓ FriBidi_jll
    837.7 ms  ✓ Graphite2_jll
    890.9 ms  ✓ EpollShim_jll
    784.5 ms  ✓ libpng_jll
    954.9 ms  ✓ Xorg_libXau_jll
    793.3 ms  ✓ LAME_jll
    978.2 ms  ✓ Xorg_libXdmcp_jll
    863.7 ms  ✓ Zstd_jll
   1122.7 ms  ✓ libaom_jll
   1002.8 ms  ✓ Expat_jll
    991.4 ms  ✓ LZO_jll
    866.5 ms  ✓ Opus_jll
    782.5 ms  ✓ Xorg_xtrans_jll
    958.7 ms  ✓ eudev_jll
    950.6 ms  ✓ Libmount_jll
    858.4 ms  ✓ Bzip2_jll
    976.1 ms  ✓ libfdk_aac_jll
   1112.5 ms  ✓ LERC_jll
    843.1 ms  ✓ libevdev_jll
    823.2 ms  ✓ CodecZlib
    936.2 ms  ✓ XZ_jll
    643.1 ms  ✓ Showoff
    691.5 ms  ✓ RelocatableFolders
    997.6 ms  ✓ Xorg_libSM_jll
    909.8 ms  ✓ Pixman_jll
   1502.7 ms  ✓ JLFzf
   1079.1 ms  ✓ libvorbis_jll
   2774.6 ms  ✓ ColorTypes
   1339.2 ms  ✓ GettextRuntime_jll
   1026.0 ms  ✓ Dbus_jll
   3117.3 ms  ✓ OpenSSL
   2311.8 ms  ✓ Xorg_libxcb_jll
   1196.2 ms  ✓ Wayland_jll
   1180.7 ms  ✓ FreeType2_jll
   1007.4 ms  ✓ libinput_jll
   1006.6 ms  ✓ Libtiff_jll
    956.2 ms  ✓ ColorTypes → StyledStringsExt
   1265.8 ms  ✓ Glib_jll
   1025.3 ms  ✓ Xorg_xcb_util_jll
   1051.3 ms  ✓ Xorg_libX11_jll
   1538.5 ms  ✓ Fontconfig_jll
   3783.2 ms  ✓ ColorVectorSpace
   1360.1 ms  ✓ Xorg_xcb_util_keysyms_jll
   1195.1 ms  ✓ Xorg_xcb_util_renderutil_jll
   1053.4 ms  ✓ Xorg_xcb_util_image_jll
   1108.2 ms  ✓ Xorg_xcb_util_wm_jll
   1088.5 ms  ✓ Xorg_libXrender_jll
    948.2 ms  ✓ Xorg_libXext_jll
   1099.0 ms  ✓ Xorg_libXfixes_jll
    892.9 ms  ✓ Xorg_libxkbfile_jll
   1075.4 ms  ✓ Xorg_xcb_util_cursor_jll
   1129.3 ms  ✓ Xorg_libXinerama_jll
   1267.1 ms  ✓ Xorg_libXrandr_jll
   1705.3 ms  ✓ Libglvnd_jll
   1611.7 ms  ✓ Cairo_jll
   1084.9 ms  ✓ Xorg_libXcursor_jll
   8992.0 ms  ✓ Colors
   1015.0 ms  ✓ Xorg_libXi_jll
    928.4 ms  ✓ Xorg_xkbcomp_jll
   1052.5 ms  ✓ HarfBuzz_jll
    922.2 ms  ✓ Xorg_xkeyboard_config_jll
   1018.8 ms  ✓ libass_jll
   1221.9 ms  ✓ Pango_jll
   1017.6 ms  ✓ xkbcommon_jll
   1475.2 ms  ✓ FFMPEG_jll
   1215.6 ms  ✓ libdecor_jll
   1263.1 ms  ✓ Vulkan_Loader_jll
   1121.1 ms  ✓ FFMPEG
   1038.7 ms  ✓ GLFW_jll
   1674.6 ms  ✓ Qt6Base_jll
   6080.5 ms  ✓ ColorSchemes
    927.2 ms  ✓ Qt6ShaderTools_jll
   1215.4 ms  ✓ GR_jll
   1831.4 ms  ✓ Qt6Declarative_jll
    647.7 ms  ✓ Qt6Wayland_jll
  27558.4 ms  ✓ HTTP
  14040.8 ms  ✓ PlotUtils
   4457.3 ms  ✓ GR
   3616.1 ms  ✓ PlotThemes
   4426.7 ms  ✓ RecipesPipeline
  62688.7 ms  ✓ Plots
  109 dependencies successfully precompiled in 111 seconds. 68 already precompiled.
Precompiling RatiosFixedPointNumbersExt...
    387.4 ms  ✓ Ratios → RatiosFixedPointNumbersExt
  1 dependency successfully precompiled in 1 seconds. 5 already precompiled.
Precompiling SparseMatrixColoringsColorsExt...
    768.0 ms  ✓ SparseMatrixColorings → SparseMatrixColoringsColorsExt
  1 dependency successfully precompiled in 1 seconds. 18 already precompiled.
Precompiling SpecialFunctionsExt...
    559.7 ms  ✓ ColorVectorSpace → SpecialFunctionsExt
  1 dependency successfully precompiled in 1 seconds. 20 already precompiled.
Precompiling UnitfulExt...
    749.1 ms  ✓ HostCPUFeatures
   2684.0 ms  ✓ Plots → UnitfulExt
   6480.8 ms  ✓ VectorizationBase
    868.2 ms  ✓ SLEEFPirates
   2219.9 ms  ✓ MonteCarloMeasurements
   1357.2 ms  ✓ MonteCarloMeasurements → RecipesBaseExt
   1407.3 ms  ✓ MonteCarloMeasurements → UnitfulExt
  7 dependencies successfully precompiled in 12 seconds. 235 already precompiled.
  1 dependency had output during precompilation:
┌ VectorizationBase
│  WARNING: using Static.static_first in module VectorizationBase conflicts with an existing identifier.
│  WARNING: using Static.static_last in module VectorizationBase conflicts with an existing identifier.
└  

Setup parameters, variables, and differential operators

@parameters t x
@parameters dS dI brn ϵ
@variables S(..) I(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2
Differential(x) ∘ Differential(x)

Helper functions

γ(x) = x + 1
ratio(x, brn, ϵ) = brn + ϵ * sinpi(2x)
ratio (generic function with 1 method)

1D PDE for disease spreading

eqs = [
    Dt(S(t, x)) ~ dS * Dxx(S(t, x)) - ratio(x, brn, ϵ) * γ(x) * S(t, x) * I(t, x) / (S(t, x) + I(t, x)) + γ(x) * I(t, x),
    Dt(I(t, x)) ~ dI * Dxx(I(t, x)) + ratio(x, brn, ϵ) * γ(x) * S(t, x) * I(t, x) / (S(t, x) + I(t, x)) - γ(x) * I(t, x)
]
\[\begin{split} \begin{align} \frac{\mathrm{d}}{\mathrm{d}t} S\left( t, x \right) &= \frac{ - \left( 1 + x \right) S\left( t, x \right) I\left( t, x \right) \left( \mathtt{brn} + sinpi\left( 2 x \right) \epsilon \right)}{S\left( t, x \right) + I\left( t, x \right)} + \mathtt{dS} \frac{\mathrm{d}}{\mathrm{d}x} \frac{\mathrm{d}}{\mathrm{d}x} S\left( t, x \right) + \left( 1 + x \right) I\left( t, x \right) \\ \frac{\mathrm{d}}{\mathrm{d}t} I\left( t, x \right) &= \frac{\left( 1 + x \right) S\left( t, x \right) I\left( t, x \right) \left( \mathtt{brn} + sinpi\left( 2 x \right) \epsilon \right)}{S\left( t, x \right) + I\left( t, x \right)} + \mathtt{dI} \frac{\mathrm{d}}{\mathrm{d}x} \frac{\mathrm{d}}{\mathrm{d}x} I\left( t, x \right) - \left( 1 + x \right) I\left( t, x \right) \end{align} \end{split}\]

Boundary conditions

bcs = [
    S(0, x) ~ 0.9 + 0.1 * sinpi(2x),
    I(0, x) ~ 0.1 + 0.1 * cospi(2x),
    Dx(S(t, 0)) ~ 0.0,
    Dx(S(t, 1)) ~ 0.0,
    Dx(I(t, 0)) ~ 0.0,
    Dx(I(t, 1)) ~ 0.0
]
\[\begin{split} \begin{align} S\left( 0, x \right) &= 0.9 + 0.1 sinpi\left( 2 x \right) \\ I\left( 0, x \right) &= 0.1 + 0.1 cospi\left( 2 x \right) \\ \frac{\mathrm{d}}{\mathrm{d}x} S\left( t, 0 \right) &= 0 \\ \frac{\mathrm{d}}{\mathrm{d}x} S\left( t, 1 \right) &= 0 \\ \frac{\mathrm{d}}{\mathrm{d}x} I\left( t, 0 \right) &= 0 \\ \frac{\mathrm{d}}{\mathrm{d}x} I\left( t, 1 \right) &= 0 \end{align} \end{split}\]

Space and time domains

domains = [
    t  Interval(0.0, 10.0),
    x  Interval(0.0, 1.0)
]
2-element Vector{Symbolics.VarDomainPairing}:
 Symbolics.VarDomainPairing(t, 0.0 .. 10.0)
 Symbolics.VarDomainPairing(x, 0.0 .. 1.0)

Build the PDE system

@named pdesys = PDESystem(eqs, bcs, domains,
    [t, x], ## Independent variables
    [S(t, x), I(t, x)],  ## Dependent variables
    [dS, dI, brn, ϵ],    ## parameters
    defaults = Dict(dS => 0.5, dI => 0.1, brn => 3, ϵ => 0.1)
)
\[\begin{split} \begin{align} \frac{\mathrm{d}}{\mathrm{d}t} S\left( t, x \right) &= \frac{ - \left( 1 + x \right) S\left( t, x \right) I\left( t, x \right) \left( \mathtt{brn} + sinpi\left( 2 x \right) \epsilon \right)}{S\left( t, x \right) + I\left( t, x \right)} + \mathtt{dS} \frac{\mathrm{d}}{\mathrm{d}x} \frac{\mathrm{d}}{\mathrm{d}x} S\left( t, x \right) + \left( 1 + x \right) I\left( t, x \right) \\ \frac{\mathrm{d}}{\mathrm{d}t} I\left( t, x \right) &= \frac{\left( 1 + x \right) S\left( t, x \right) I\left( t, x \right) \left( \mathtt{brn} + sinpi\left( 2 x \right) \epsilon \right)}{S\left( t, x \right) + I\left( t, x \right)} + \mathtt{dI} \frac{\mathrm{d}}{\mathrm{d}x} \frac{\mathrm{d}}{\mathrm{d}x} I\left( t, x \right) - \left( 1 + x \right) I\left( t, x \right) \end{align} \end{split}\]

Finite difference method (FDM) converts the PDE system into an ODE problem

dx = 0.01
order = 2
discretization = MOLFiniteDifference([x => dx], t, approx_order=order)
prob = discretize(pdesys, discretization)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
Non-trivial mass matrix: false
timespan: (0.0, 10.0)
u0: 198-element Vector{Float64}:
 0.19980267284282716
 0.1992114701314478
 0.19822872507286887
 0.1968583161128631
 0.19510565162951538
 0.19297764858882513
 0.190482705246602
 0.18763066800438638
 0.18443279255020154
 0.18090169943749476
 ⋮
 0.9535826794978997
 0.9481753674101716
 0.9425779291565073
 0.9368124552684678
 0.9309016994374948
 0.9248689887164855
 0.9187381314585725
 0.9125333233564304
 0.9062790519529313

Solving time-dependent SIS epidemic model#

KenCarp4 is good at solving semilinear problems (like reaction-diffusion problems).

sol = solve(prob, KenCarp4(), saveat=0.2)
retcode: Success
Interpolation: Dict{Symbolics.Num, Interpolations.GriddedInterpolation{Float64, 2, Matrix{Float64}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}, Vector{Float64}}}}
t: 51-element Vector{Float64}:
  0.0
  0.2
  0.4
  0.6
  0.8
  1.0
  1.2
  1.4
  1.6
  1.8
  ⋮
  8.4
  8.6
  8.8
  9.0
  9.2
  9.4
  9.6
  9.8
 10.0ivs: 2-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
 t
 xdomain:([0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8  …  8.2, 8.4, 8.6, 8.8, 9.0, 9.2, 9.4, 9.6, 9.8, 10.0], 0.0:0.01:1.0)
u: Dict{Symbolics.Num, Matrix{Float64}} with 2 entries:
  S(t, x) => [0.904194 0.906279 … 0.893721 0.895806; 0.879603 0.879585 … 0.7899…
  I(t, x) => [0.2 0.199803 … 0.199803 0.2; 0.204066 0.20397 … 0.245398 0.245559…

Grid points

discrete_x = sol[x]
discrete_t = sol[t]
51-element Vector{Float64}:
  0.0
  0.2
  0.4
  0.6
  0.8
  1.0
  1.2
  1.4
  1.6
  1.8
  ⋮
  8.4
  8.6
  8.8
  9.0
  9.2
  9.4
  9.6
  9.8
 10.0

Results (Matrices)

S_solution = sol[S(t, x)]
I_solution = sol[I(t, x)]
51×101 Matrix{Float64}:
 0.2       0.199803  0.199211  0.198229  …  0.199211  0.199803  0.2
 0.204066  0.20397   0.203684  0.203205     0.244914  0.245398  0.245559
 0.239603  0.239568  0.239463  0.239285     0.320347  0.320719  0.320844
 0.300269  0.300279  0.300309  0.300355     0.413565  0.413853  0.413949
 0.37595   0.375987  0.376098  0.376278     0.503721  0.503946  0.504021
 0.451583  0.451629  0.451768  0.451996  …  0.573511  0.573687  0.573745
 0.516804  0.516848  0.516981  0.517198     0.620077  0.620214  0.62026
 0.566319  0.566357  0.566469  0.566653     0.646894  0.647002  0.647038
 0.601149  0.601179  0.601268  0.601415     0.660188  0.660274  0.660303
 0.624958  0.624981  0.625051  0.625165     0.665471  0.665541  0.665564
 ⋮                                       ⋱                      ⋮
 0.676304  0.676307  0.676318  0.676335     0.656519  0.656544  0.656553
 0.676303  0.676307  0.676318  0.676335     0.656519  0.656544  0.656553
 0.676303  0.676307  0.676317  0.676334     0.656519  0.656544  0.656553
 0.676302  0.676306  0.676317  0.676333  …  0.656519  0.656545  0.656553
 0.676301  0.676305  0.676316  0.676333     0.65652   0.656545  0.656554
 0.676301  0.676304  0.676315  0.676332     0.65652   0.656546  0.656554
 0.6763    0.676304  0.676315  0.676331     0.656521  0.656546  0.656554
 0.6763    0.676304  0.676314  0.676331     0.656521  0.656546  0.656554
 0.6763    0.676304  0.676315  0.676331  …  0.656521  0.656546  0.656554

Visualize the solution

surface(discrete_x, discrete_t, S_solution, xlabel="Location", ylabel="Time", title="Susceptible")
_images/a235c5d1a8681ceb448cd9d43bcf6d2779805f556b8782e6f285b12a5bf1c945.png
surface(discrete_x, discrete_t, I_solution, xlabel="Location", ylabel="Time", title="Infectious")
_images/cbbbae42e90f29fabb7fdcf1ceba88e6b24d0c15b047ff6b127fb9caa95706db.png

This notebook was generated using Literate.jl.