@@ -61,6 +61,19 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
61
61
"""
62
62
systems:: Vector
63
63
"""
64
+ analytic: A vector of explicit symbolic expressions for the analytic solutions of each
65
+ dependent variable. e.g. `analytic = [u(t, x) ~ a*sin(c*t) * cos(k*x)]`
66
+ """
67
+ analytic:: Any
68
+ """
69
+ analytic_func: A vector of functions for the analytic solutions of each dependent
70
+ variable. Will be generated from `analytic` if not provided. Should have the same
71
+ argument signature as the variable, and a `ps` argument as the last argument,
72
+ which takes an indexable of parameter values in the order you specified them in `ps`.
73
+ e.g. `analytic_func = [u(t, x) => (ps, t, x) -> ps[1]*sin(ps[2]*t) * cos(ps[3]*x)]`
74
+ """
75
+ analytic_func:: Any
76
+ """
64
77
name: the name of the system
65
78
"""
66
79
name:: Symbol
@@ -78,15 +91,40 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
78
91
systems = [],
79
92
connector_type = nothing ,
80
93
metadata = nothing ,
94
+ analytic = nothing ,
95
+ analytic_func = nothing ,
81
96
gui_metadata = nothing ,
82
97
checks:: Union{Bool, Int} = true ,
83
98
name)
84
99
if checks == true || (checks & CheckUnits) > 0
85
100
all_dimensionless ([dvs; ivs; ps]) || check_units (eqs)
86
101
end
102
+
87
103
eqs = eqs isa Vector ? eqs : [eqs]
88
- new (eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, name,
89
- metadata, gui_metadata)
104
+
105
+ if ! isnothing (analytic)
106
+ analytic = analytic isa Vector ? analytic : [analytic]
107
+ if length (analytic) != length (dvs)
108
+ throw (ArgumentError (" The number of analytic solutions must match the number of dependent variables" ))
109
+ end
110
+
111
+ if isnothing (analytic_func)
112
+ analytic_func = map (analytic) do eq
113
+ args = arguments (eq. lhs)
114
+ p = ps isa SciMLBase. NullParameters ? [] : map (a -> a. first, ps)
115
+ args = vcat (DestructuredArgs (p), args)
116
+ ex = Func (args, [], eq. rhs) |> toexpr
117
+ eq. lhs => @RuntimeGeneratedFunction (ex)
118
+ end
119
+ end
120
+ end
121
+
122
+ if ! isnothing (analytic_func)
123
+ analytic_func = analytic_func isa Dict ? analytic_func : analytic_func |> Dict
124
+ end
125
+
126
+ new (eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, analytic,
127
+ analytic_func, name, metadata, gui_metadata)
90
128
end
91
129
end
92
130
0 commit comments