Infinite time horizon spatially distributed optimal ... - Uni Oldenburg

2 downloads 0 Views 761KB Size Report
Apr 3, 2017 - 2.1.3 Main oc-lib function . ...... of the parameters (g, η, d, δ, β, ξ, ru,rw,d1,2) we refer to [BX10, Uec16], and here only remark that ρ = 0.03,p = 1.1 ...
Infinite time horizon spatially distributed optimal control problems with pde2path – a user guide Hannes Uecker1 1

Institut f¨ ur Mathematik, Universit¨ at Oldenburg, D26111 Oldenburg, [email protected]

April 3, 2017 Abstract The continuation and bifurcation package pde2path can also be used for infinite time horizon optimal control (OC) problems for parabolic systems of PDE over 1D, 2D or 3D spatial domains. The basic idea is a two step approach to the canonical systems, derived from Pontryagin’s maximum principle. First we use pde2path to find branches of canonical steady states (CSS), and then use these results to compute the objective values of time-dependent canonical paths connecting to a CSS with the so called saddle point property. This is a (high dimensional) boundary value problem (BVP) in time, which we solve by combining a modification of the BVP solver TOM with a continuation algorithm in the initial states. We explain the approach via some example problems and associated pde2path demo directories. First we consider the optimal management of a distributed shallow lake, and of a vegetation system, both with (spatially, and temporally) distributed controls. These examples show interesting bifurcations of so called patterned CSS, and in particular the latter also a variety of patterned optimal steady states. As a third example we discuss the optimal control of a fishing problem with boundary catch.

Contents 1 Introduction 1.1 Pontryagin’s Maximum Principle and the canonical system . . . . . . . . . . . . . . . 1.2 The general setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Examples and implementation details 2.1 The SLOC model . . . . . . . . . . . . . . . . 2.1.1 The setup for canonical steady states . 2.1.2 Canonical paths . . . . . . . . . . . . 2.1.3 Main oc-lib function . . . . . . . . . 2.1.4 Skiba points . . . . . . . . . . . . . . . 2.2 The vegOC model . . . . . . . . . . . . . . . 2.3 Boundary control . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

1 2 3 5 6 6 8 10 12 14 17

. . . . . . .

3 Summary and outlook

1

19

Introduction

We consider optimal control (OC) problems for partial differential equations (PDEs) of the form ∂t v = −G1 (v, k) := D∆v + g1 (v, k), in Ω ⊂ Rd (a bounded domain),

(1a)

with initial condition v|t=0 = v0 , and suitable boundary conditions. Here v : Ω×[0, ∞) → RN denotes a (vector of) state variables, k : Ωk × [0, ∞) → R is a control with Ωk = Ω for the case of a so called distributed control, or Ωk ⊂ ∂Ω for the case of a boundary control, D ∈ RN ×N is a diffusion matrix,

1

and ∆ = ∂x21 + . . . + ∂x2d is the Laplacian. For definiteness we first consider the case of a distributed control. The goal is to find V (v0 ) := max J(v0 (·), k(·, ·))

(1b)

k(·,·)

for the discounted time integral Z



J(v0 (·), k(·, ·)) :=

e−ρt Jca (v(t), k(t)) dt,

(2)

0

R 1 where Jca (v(·, t), k(·, t)) = |Ω| Ω Jc (v(x, t), k(x, t)) dx is the spatially averaged current value objective function, with the local current value Jc : RN +1 → R a given function, and ρ > 0 is the discount rate. The max (formally sup) in (1b) runs over all admissible controls k; this will be specified in more detail in the examples below. In applications, Jc and G1 of course often also depend on a number of parameters, which however for simplicity we do not display here.1 The discounted time integral in (1b) is typical for economic problems, where “profits now” weight more than mid or far future profits. More specifically, ρ corresponds to a long-term investment rate. In this tutorial we explain by means of three examples how to numerically study problems of type (1) with pde2path2 . The examples are from [Uec16, GU17, UU17] and we mostly refer to these works for modeling background and (bioeconomic) interpretation of the results, and for general references and comments on OC for PDE problems, here keeping these aspects to a minimum. In the first example, k : Ω×[0, ∞) → R is the phosphate load in a model describing the phosphorus contamination of a shallow lake by a scalar PDE (1a) with homogeneous Neumann BC ∂ν v = 0, ν the outer normal. Similarly, in the second example, k : Ω × [0, ∞) → R is the harvesting effort in a vegetation-water system, such that (1a) is a two component reaction diffusion, again with homogeneous Neumann BC. By contrast, in the third example k : ∂Ωk × [0, ∞) → R2 with Ωk ⊂ ∂Ω is a boundary control, namely the fishing effort on (part of) the shore of a lake. To keep this tutorial simple, for all three examples we restrict to the 1D case of Ω ⊂ R an interval. Generalizations to domains in R2 are straightforward, and also straightforward to implement in pde2path, and for the shallow lake and vegetation systems have also been studied in [Uec16, GU17], respectively. In the remainder of this introduction, we first briefly review the derivation of the so-called canonical system as a necessary first order optimality condition from (1) via Pontryagin’s maximum principle. Then we explain the basic algorithms to treat the canonical system, i.e., first the canonical steady states (CSS) and then the canonical paths. In §2 we present the example problems and the implementation details for pde2path. We assume that the reader has a basic knowledge of Matlab, has installed pde2path (see also [dWDR+ 17]), and also has some previous experience with the software. If this is not the case, then we recommend to at least briefly look at one of the simpler problems discussed in, e.g., [RU17]. In particular, also in the present tutorial all implementations are based on the OOPDE [Pr¨ u16] setting of pde2path. In §3 we close with a brief summary and outlook. Acknowledgment. I thank Dieter Grass, ORCOS Wien, for introducing me to the field of optimal control over infinite time horizons, and for clarifying (and posing) many questions regarding the aim of software based on Pontryagin’s Maximum Principle for spatially distributed OC problems, and Thorsten Upmann, Universit¨ at Bielefeld, for cooperation on the boundary fishery problem from §2.3.

1.1

Pontryagin’s Maximum Principle and the canonical system

For definiteness, we first consider the case of spatially distributed controls k : Ω × [0, ∞) → R, and assume homogeneous Neumann BC for v, i.e., ∂ν v = 0 on ∂Ω, ν the outer normal. Introducing the costates λ : Ω × (0, ∞) → RN and the (local current value) Hamiltonian H = H(v, λ, k) = Jc (v, k) + λT (D∆v + g1 (v, k)), 1

(3)

G1 in (1a) can in fact be of a much more general form, but for simplicity here we stick to (1a). see [UWR14] for background, and [Uec17c] for download of the package, demo files, and various documentation and tutorials, including a quick start guide also giving installation instructions 2

2

R ˜ = ∞ e−ρt H(t) dt with the spatial integral by Pontryagin’s Maximum Principle (see Remark 1.1) for H 0 Z H(v(x, t), λ(x, t), k(x, t)) dx, (4) H(t) = Ω

an optimal solution (v, λ) (or equivalently (v, k) : Ω × [0, ∞) → RN +1 )) has to solve the canonical system (CS) ∂t v = ∂λ H = D∆v + g1 (v, k),

v|t=0 = v0 ,

(5a)

∂t λ = ρλ − ∂v H = ρλ + g2 (v, k) − D∆λ,

(5b)

˜ which generally we assume to be obtained from solving where k = argmaxk˜ H(v, λ, k), ∂k H(v, λ, k) = 0.

(5c)

Under suitable concavity conditions on Jc this holds due to the absence of control constraints. The costates λ also fulfill zero flux BC, and in the derivation of (5) we imposed the so called inter–temporal transversality condition Z hv(t, x), λ(t, x)i dx = 0. (5d) lim e−ρt t→∞



As already said, see Remark 1.1 and [Uec16, GU17] for (some) theoretical background and further references. In principle we want so solve (5) for t ∈ [0, ∞), but in (5a) we have initial data for only half the variables, and in (5b) we have anti–diffusion, such that (5) is ill–posed as an initial value problem. For convenience we set   v(t, ·) : Ω → R2N , (6) u(t, ·) := λ(t, ·) and write (5) as  ∂t u = −G(u, η) := D∆u + f (u),

D=

 D 0 , 0 −D

 f (u) =

 g1 (u) , g2 (u)

(7)

with BC ∂ν u = 0, where η ∈ Rp stands for parameters present, which for instance include the discount rate ρ. A solution u of the canonical system (7) is called a canonical path, and a fixed point of (7) (which automatically fulfills (5d)) is called a canonical steady state (CSS). With a slight abuse of notation we also call (v, k) with k given by (5c) a canonical path. Remark 1.1 For general background on OC in a PDE setting see [GCF+ 08, Tr¨o10] and the references therein, or specifically [RZ99a, RZ99b] and [AAC11, Chapter5] for Pontryagin’s maximum principle for OC problems for semilinear diffusive models. However, these works are in a finite time horizon setting, and often the objective function is linear in the control and there are control constraints, e.g., k(x, t) ∈ K with some bounded set K. Therefore k is not obtained from the analogue of (5c), but rather takes the values from ∂K, which is often called bang–bang control. Here we do not (yet) consider (active) control or state constraints, and no terminal time, but the infinite time horizon. Our models and method are motivated by [BX08, BX10], which also discuss Pontryagin’s maximum principle in this setting. c

1.2

The general setup

To study (7) we proceed in two steps, which can be seen as a variant of the “connecting orbit method”, see, e.g., [BPS01] and [Gra15, Chapter 7]: first we compute (branches of) CSS, and second we compute canonical paths connecting to some CSS. Thus we take a somewhat broader perspective than aiming at computing just one optimal control, given an initial condition v0 , which without further information is ill-posed anyway. Instead, we aim to give a somewhat global picture by identifying the optimal CSS and their respective domains of attraction. 3

(a) CSS branches. We compute (approximate) CSS of (7), i.e., solutions u ˆ of G(u, η) = 0,

(8)

together with the BC, by discretizing (8) via the finite element method (FEM) and then treating the discretized system as a continuation/bifurcation problem. This gives branches s 7→ (ˆ u(η), η(s)) of solutions, parametrized by a (pseudo-) arclength, which is in particular useful to possibly find several solutions u ˆ(l) (η), j = l, . . . , m at fixed η. By computing the associated Jca (ˆ v (l) , k (l) ) we can identify which of these is optimal amongst the CSS. Given a CSS u ˆ, for simplicity we also write Jca (ˆ u) := Jca (ˆ v (l) , k (l) ), and moreover have, by explicit evaluation of the time integral, J(ˆ u) = Jca (ˆ u)/ρ.

(9)

(b) Canonical paths. In a second step, using the results from (a), we compute canonical paths connecting to a CSS u ˆ, and the objective values of the canonical paths. For this we choose a truncation time T and modify (5d) to the condition that u(T ) ∈ Ws (ˆ u) and near u ˆ, where Ws (ˆ u) denotes the stable manifold of u ˆ. In practice, we approximate Ws (ˆ u) by the stable eigenspace Es (ˆ u), and thus consider the BVP ∂t u = −G(u),

(10a)

v|t=0 = v0 ,

(10b)

u(T ) ∈ Es (ˆ u) (and ku(T ) − u ˆk small).

(10c)

If the mesh in the FEM discretization from (a) consists of n nodes, then u(t) ∈ R2N n , and (10a) yields a system of 2N n ODEs in the form (with a slight abuse of notation) M

d u = −G(u), dt

(11a)

while the initial and transversality conditions become v|t=0 = v0 ,

(11b)

Ψ(u(T ) − u ˆ) = 0 (and ku(T ) − u ˆk small).

(11c)

Here M ∈ R2N n×2N n is the mass matrix of the FEM mesh, and Ψ ∈ RN n×2N n defines the projection onto the unstable eigenspace Eu (ˆ u). Moreover, (11b) consists of N n initial conditions for the states, while the costates λ (and hence the control k) are free. Thus, to have 2N n BC altogether we need dimEs (ˆ u) = N n. On the other hand, we always have dimEs (ˆ u) ≤ N n, see [GU17, Appendix A]. We define the defect d(ˆ u) := dimEs (ˆ u) − N n

(12)

and call a CSS u ˆ with d(ˆ u) = 0 a CSS with the saddle–point property (SPP). At first sight it may appear that d(ˆ u) depends on the spatial discretization, i.e., on the number of n of nodes. However, d(ˆ u) remains constant for finer and finer meshes, see [GU17, Appendix A] for further comments. ˆ with the SPP, and kv0 − vˆk sufficiently small, we may expect the existence of For u ˆ = (ˆ v , λ) a solution u of (11), which moreover can be found from a Newton loop for (11) with initial guess u(t) ≡ u ˆ. On the other hand, for larger kv0 − vˆk a solution of (11) may not exist, or a good initial guess may be hard to find, and therefore we use a continuation process also for (11). In the simplest setting, assume that for some α ∈ [0, 1] we have a solution uα of (11) with (11b) replaced by v(0) = αv0 + (1 − α)ˆ v,

(13)

(e.g., α = 0 and u ≡ u ˆ). We then increase α by some stepsize δα and use uα as initial guess for (11a), (11c) and (13), ultimately aiming at α = 1. 4

To actually discretize in time and then solve (11a), (11c) and (13) we use the BVP solver TOM [MS02, MT04, MST09]3 , in a version mtom which accounts for the mass matrix M on the lhs of (11a)4 . This predictor (uα ) – corrector (mtom for α + δα ) continuation method corresponds to a “natural” parametrization by α, and is thus implemented in pde2path as iscnat (Initial State Continuation NATural). We also give the option to use a secant predictor  uj (t) = uj−1 (t) + δα τ (t), τ (t) = u(j−1) (t) − u(j−2) (t) /ku(j−1) (·) − u(j−2) (·)k2 , (14) where uj−2 and uj−1 are the two previous steps. However, the corrector still works at fixed α, in contrast to the arclength predictor–corrector iscarc described next. It may happen that no solution of (11a), (11c) and (13) is found for α > α0 for some α0 < 1, i.e., that the continuation to the intended initial states fails. In that case, often the BVP shows a fold in α, and we use a modified continuation process, letting α be a free parameter and using a pseudo–arclength parametrization by σ in the BC at t = 0. We add the dummy ODE α˙ = 0, and BCs at continuation step j, D E s, (u(0) − u(j−1) (0) + sα (α − α(j−1) ) = σ, (15) with (u(j−1) (·), αj−1 ) the solution from the previous step, and (s, sα ) ∈ R2N n ×R appropriately chosen with k(s, sα )k∗ = 1, where k · k∗ is a suitable norm in R2N n+1 , which may contain different weights of v and vα . For s = 0 and sα = 1 we find iscnat with stepsize δα = σ again. To get around folds we may use the secant  s := ξ u(j−1) (0) − u(j−2) (0) /ku(j−1) (0) − u(j−2) (0)k2 and sα = 1 − ξ with small ξ, and also a secant predictor (uj , αj )pred = (uj−1 , αj−1 ) + στ

(16)

 τ = ξ u(j−1) (·) − u(j−2) (·) /ku(j−1) (·) − u(j−2) (·)k2 and τα = 1 − ξ.

(17)

for t 7→ uj (t) with

This essentially follows [GCF+ 08, §7.2], and is implemented in a routine iscarc (Initial State Continuation ARClength). Finally, given u ˆ, to calculate Ψ, at startup we solve the generalized adjoint eigenvalue problem ∂u G(ˆ u)T Φ = ΛM Φ

(18)

for the eigenvalues Λ and (adjoint) eigenvectors Φ, which also gives the defect d(ˆ u) by counting the negative eigenvalues in Λ. If d(ˆ u) = 0, then from Φ ∈ C2N n×2N n we generate a real base of Eu (ˆ u) which we sort into the matrix Ψ ∈ RN n×2N n .

2

Examples and implementation details

We now explain how to use pde2path to calculate CSS and canonical paths for three example problems of type (1), namely the sloc (shallow lake optimal control) problem from [GU17], the vegoc (vegetation optimal control) problem from [Uec16], and the boundary fishing problem lvoc (LotkaVolterra optimal control) from [UU17]. For all examples we first briefly sketch the models, and then summarize the contents of the respective demo folder and explain the most important files in some detail. Together with the first model we also explain the main OC related routines of pde2path. For all models we give some plots, but for details and interpretation of the results we refer to the respective papers. 3 4

see also www.dm.uniba.it/~mazzia/mazzia/?page_id=433 and which is also used for finding time-periodic orbits in pde2path, see [Uec17b, Uec17a]

5

2.1

The SLOC model

Following [BX08], in [GU17] we consider a model for phosphorus v = v(x, t) in a shallow lake, and phosphate load k = k(x, t) as a control. In 0D, i.e., in the ODE setting, this has been analyzed in detail for instance in [KW10]. Here we explain how we set up the spatial problem in pde2path. The model reads Z ∞ ! e−ρt Jca (v(t), k(t)), dt (19a) V (v0 (·)) = max J(v0 (·), k(·, ·)), J(v0 (·), k(·, ·)) := k(·,·)

0

where Jc (v, k) = ln k − γv 2 , Jca (v(t), k(t)) = PDE ∂t v(x, t) = k(x, t) − bv(x, t) + ∂ν v(x, t)∂Ω = 0,

1 |Ω|

R

Ω Jc (v(x, t), k(x, t))dx

as in (1b), and v fulfills the

v(x, t)2 + D∆v(x, t), 1 + v(x, t)2

(19b)

x ∈ Ω ⊂ Rd .

v(x, t)t=0 = v0 (x),

(19c)

The parameter b > 0 is the phosphorus degradation rate, and γ > 0 are ecological costs of the phosphorus contamination v. Thus, the objective function consists of the concave increasing function ln k, and the concave decreasing function −γv 2 . In the demo directory sloc we consider the parameters D = 0.5, ρ = 0.03, γ = 0.5, b ∈ (0.5, 0.8) (primary bif. param.). With the co-state λ, the canonical system for (19) becomes, with k(x, t) = −

1 , λ(x, t)

v(x, t)2 + D∆v(x, t), ∂t v(x, t) = k(x, t) − bv(x, t) + 1 + v(x, t)2   2v(x, t) ∂t λ(x, t) = 2γv(x, t) + λ(x, t) ρ + b − − D∆λ(x, t), (1 + v(x, t)2 )2 ∂ν v = ∂ν λ = 0 on ∂Ω, v(x, t)t=0 = v0 (x), 2.1.1

x ∈ Ω.

(20)

(21a) (21b) (21c) (21d)

The setup for canonical steady states

To compute CSS we use a standard pde2path setup for (the steady version) of (21). Thus, for new users we refer to [RU17] for an introduction into the basic pde2path data structures and setup of elliptic systems. As an overview, Table 1 lists the scripts and functions in ocdemos/sloc; these will be explained in more detail below. As usual, our basic structure is a Matlab struct p as in problem, which has a number of fields (and subfields). However, most of these can be set to standard values by calling p=stanparam(p). In standard problems the user only has to provide: 1. The geometry of the domain Ω, and in the OOPDE setting used here a function oosetfemops used to generate the needed FEM matrices. 2. Function handles sG implementing G, and, for speedup, sGjac, implementing the Jacobian. 3. An initial guess for a solution u of G(u) = 0, i.e., an initial guess for a CSS. Typically, the steps 1-3 are put into an init routine, here p=slinit(p,lx,ly,nx,sw,ndim), where lx,ly,nx and ndim are parameters to describe the domain size and discretization5 , and sw is used to set up different initial guesses, see Listing 1. For CSS computations the only additions/modifications to the standard pde2path setting are as follows: (the additional function handle) p.fuha.jc should be set to the local current value objective function, here p.fuha.jc=@sljcf (see Listing 5

ly (irrelevant) and ndim(=1) play no role in this tutorial, but we kept them in slinit because the same init routine is also used in 2D

6

Table 1: Scripts and functions in ocdemos/sloc (for the 1D case; some additional functions for the 2D case are also in the folder). The bottom part list some helper functions. bdcmds1D (2D) cpdemo1D, cpdemo2D skibademo( short) p=slinit(p,lx,ly,nx,sw,ndim)

p=oosetfemops(p) r=slsG(p,u) Gu=slsGjac(p,u) jc=sljcf(p,u) k=slcon(p,u) cssvalf(dir,pt) plot1D(f), slsolplot psol3Dm(p,sol0,sol,wnr,cmp,tit)

script(s) to compute CSS; here only 1D case discussed script(s) to compute CPs, here only 1D discussed script(s) to compute Skiba paths init routine; first sets the pde2path parameters to standard values, then some parameters to problem specific values; then initializes the domain, sets an initial guess u (chosen via sw), and finds a first steady state by a Newton loop set FEM matrices (stiffness K and mass M) G(u) for (21) the Jacobian ∂u G(u) computes the current value Jc extract control from states/costates print CSS value and characteristics helper functions for plotting plot sol0 and sol into one fig, e.g., for Skiba, modification of the pde2path function psol3D

5), and p.fuha.outfu to ocbra, i.e., p.fuha.outfu=@ocbra. This automatically puts Jca (u) at position 4 of the calculated output–branch. Finally, it is useful (for instance for plotting) to set p.fuha.con=@slcon, where k=slcon(p,u) (see Listing 4) extracts the control k from the states v, costates λ and parameters η, all contained in the vector u. function p = slinit (p , lx , ly , nx , sw , ndim ) % init - routine p = stanparam ( p ) ; % set generic parameters to standard , if needed reset below .. p . fuha . sG = @slsG ; p . fuha . sGjac = @slsGjac ; p . fuha . outfu = @ocbra ; % rhs and branch p . fuha . jcf = @sljcf ; p . fuha . con = @slcon ; % current - val , and fun to get k from u

5 h =2* lx / nx ; % mesh - size ; now generate domain and mesh depending on dimension if ndim ==1; pde = stanpdeo1D ( lx , h ) ; p . vol =2* lx ; % 1 D else pde = stanpdeo2D ( lx , ly , h ) ; p . vol =4* lx * ly ; % 2 D end

10 p . pdeo = pde ; p . np = pde . grid . nPoints ; % save the pde object ( and some more ) in p p . sol . xi =1/ p . np ; p . nc . neq =2; p . nu = p . np * p . nc . neq ; % weight , # eqns , and DoF p . sw . sfem = -1; p = setfemops ( p ) ; % use OOPDE , generate FEM matrices p . sw . spcalc =0; p . file . smod =100; % don ’ t compute EVals , save each 100 th point 15 par =[0.03; 0.55; 0.5; 0.5]; p . nc . ilam =2; p . sol . ds =0.1; % startup param % r = par (1) ; bp = par (2) ; cp = par (3) ; D = par (4) ; % to recall the meaning of par p . usrlam =[0.55 0.6 0.65 0.7 0.75]; % target - values for lam p . nc . dsmin =1 e -6; p . nc . dsmax =0.5; p . nc . lammax =0.8; p . nc . lammin =0.549;

20 switch sw

% choose initial guess according to switch case 1; u =0.3* ones ( p . np ,1) ; v = -13* ones ( p . np ,1) ; u0 =[ u v ]; p . u = u0 (:) ; % FSC case 2; u =2* ones ( p . np ,1) ; v = -4* ones ( p . np ,1) ; u0 =[ u v ]; p . u = u0 (:) ; % FSM end

25 p . u =[ p . u ; par ]; % append pars , find 1 st sol from initial guess then plot [ p .u , res ]= nloop (p , p . u ) ; fprintf ( ’ first res =% g \ n ’ , res ) ; plotsol (p ,1 ,1 ,1) ;

Listing 1: sloc/slinit.m, which collects some typical initialization commands. p=stanparam(p) in line 2 sets the pde2path controls, switches and numerical constants to standard values; these can always be overwritten afterwards, and some typically are. For instance, in line 3, besides setting the function handles to the rhs (necessarily problem dependent), here we overwrite the standard branch-output p.fuha.outfu=@stanbra with the OC standard output ocbra. The remainder of slinit follows the general rules of initialization in the OOPDE setting, explained in [RU17]. We only comment that while we here no further discuss the 2D case, the same init-file is used for the 1D and 2D cases, controlled via the input argument ndim, and that via the switch sw the user can choose an initial guess u near one of the two spatially homogeneous branches: sw=1 leads to the so called ’flat state clean’ (FSC) which turns into ’flat state intermediate’ (FSI), and sw=2 leads to ’flat state muddy’ (FSM); see [GU17] for this nomenclature. 7

function p = oosetfemops ( p ) % set FEM matrices ( stiffness K and mass M ) [K ,M ,~]= p . pdeo . fem . assema ( p . pdeo . grid ,1 ,1 ,1) ; p . mat . K = kron ([[1 ,0];[0 , -1]] , K ) ; p . mat . M = kron ([[1 ,0];[0 ,1]] , M ) ;

Listing 2: sloc/oosetfemops.m, setting up the stiffness matrix K (Neumann Laplacian) and the mass matrix M needed in the OOPDE implementation of the rhs in Listing 3. function r = slsG (p , u ) % rhs for SL v_t = D * lap v -1/ l - b * v + v ^2/(1+ v ^2) % l_t = - D lap l +2 cp * v + l *( rho + bp -2* v /(1+ v ^2) ^2; par = u ( p . nu +1: end ) ; r = par (1) ; bp = par (2) ; cp = par (3) ; D = par (4) ; % extract pars v = u (1: p . np ) ; l = u ( p . np +1:2* p . np ) ; % extract sol components 5 f1 = -1./ l - bp * v + v .^2./(1+ v .^2) ; % nonlin . , first component f2 =2* cp * v + l .*( r + bp -2* v ./(1+ v .^2) .^2) ; % 2 nd component f =[ f1 ; f2 ]; r = D * p . mat . K * u (1: p . nu ) -p . mat . M * f ; % residual

Listing 3: sloc/slsG.m. The rhs of (21a,b) in the standard OOPDE setting: first we extract the parameters (line 3) and the fields v, λ (line 4) (with l for λ) from the full solution vector u which contains the pde variables (v, λ) and the parameters. Then we compute the nonlinearity f (here containing everything but diffusion), and then we compute the residual as usual (line 8). The Jacobian in sloc/slsGjac.m works accordingly. function k = slcon (p , u ) % extract control from states / costates k = -1./ u ( p . np +1: p . nu ) ;

Listing 4: sloc/slcon.m Computing the control k from the costates. function jc = sljcf (p , u ) % current value J cp = u ( p . nu +3) ; v = u (1: p . np ) ; k = -1./ u ( p . np +1: p . nu ) ; jc = log ( k ) - cp * v .^2;

Listing 5: sloc/sljcf.m Computing the current value J from the states/costates. At the end of slinit, we call a Newton–loop to converge to a (numerical) CSS, which is called ’flat’, i.e., spatially homogeneous. By calling p=cont(p) we can continue such a state in some parameter. If p.sw.bifcheck>0, then pde2path detects, localizes and saves to disk bifurcation points on the branch. Afterwards, the bifurcating branches can be computed by calling swibra and cont again. These (and other) pde2path commands (continuation, branch switching, and plotting) are typically put into a script file, here bdcmds1D.m, see Listing 6, which we recommend to organize into cells. There are some modifications to the standard pde2path plotting commands, see, e.g., plot1D.m, to plot v and k simultaneously. These work as usual by overloading the respective pde2path functions by putting the adapted file in the current directory. See Fig. 1 for example results of running bdcmds1D. % % stat . BD for sloc model : (1 D , hence ly below just dummy ) close all ; clear all ; keep pphome ; p =[]; % % FSC / FSI branch ; init , then cont to find bif . points lx =2* pi /0.44; ly =1; nx =20; sw =1; ndim =1; p = slinit (p , lx , ly , nx , sw , ndim ) ; 5 p = setfn (p , ’ f1 ’) ; p . nc . nsteps =10; screenlayout ( p ) ; p = cont (p ,100) ; % % FSM branch sw =2; p = slinit (p , lx , ly , nx , sw , ndim ) ; p = setfn (p , ’ f2 ’) ; p . nc . dsmax =0.2; p . sol . ds =0.1; p = cont (p ,25) ; % % bif from f1 ( set bpt * and p * and repeat as necessary ) 10 p = swibra ( ’ f1 ’ , ’ bpt1 ’ , ’ p1 ’ , -0.05) ; p . nc . dsmax =0.3; p = cont (p ,150) ;

Listing 6: sloc/bdcmds.m (first 10 lines). This follows standard pde2path principles. The remainder of sloc/bdcmds.m deals with plotting, see the source code.

2.1.2

Canonical paths

For OC problems, the computation of CSS is just the first step (which may already yield rather complex results). The next goal is to calculate canonical paths from some starting state v(0) to a CSS u ˆ1 with the SPP. For this we use one of the continuation algorithm iscnat or iscarc which in turn call mtom, based on TOM. For this we found it convenient (though somewhat dangerous) to pass 8

(a) BD of CSS

(b) BD, current values Jca

p1/pt15

1.6 p1

p3

ca

||v||2,a

0.5

13 19

1 0.8

−2

68

1.2

38

FSI

0.4

0

−2.2

0.65 b

38

0.75

0.6

0

10

0

−10

0.7

0

v k

0.5

−10

0

10

1

0.5

0.65

0 p3/pt19

v k

1

−2.6 0.7

−10

p2/pt15

FSC 0.6

v k

1 0.5

16 −2.4

16 15 13

0.6

v k

1

FSM

p1/pt68 1.5

−1.8

12

p2

J

1.4

(c) example CSS

10

0

−10

0

10

b

Figure 1: Example bifurcation diagrams and solution plots from running bdcmds.m. For b < bfold ≈ 0.73 there are three branches of FCSS, here called FSC (Flat State Clean, low v), FSI (Flat State Intermediate), and FSM (Flat State Muddy, high v). On FSC∪FSI there are a number of bifurcations to patterned CSS branches. See [GU17] for further discussion. a number of parameters to the functions called by mtom via global variables. Thus, at the start of the canonical path scripts (here cpdemo1D.m) we define a number of global variables, see Table 2. Table 2: Global variables for the computation of canonical paths, i.e., mainly for interfacing the driver scripts with the functions called by TOM. name s0,s1 Psi u0, u1 par um1, um2 sig

purpose pde2path structs containing the boundary values at t = 0 (s0) and at t = T (s1) the matrix Ψ to encode the BC at t = T , see (11c) vectors containing the current values of u at the boundaries the parameter values from s1 (target CSS) solutions at continuation steps j−1 and j−2 (to calculate secant predictors and used in extended system in iscarc) current (arclength) stepsize in iscarc

The setup to compute canonical paths is best understood by inspecting and running cell–by–cell the demo file cpdemo1D.m from Listing 7, where we also comment on the parameter settings in some detail. % script for SLOC canonical paths ( short version , see cpdemo1D_full for more ) global s0 s1 u0 u1 Psi par xi um1 um2 sig ; % set global vars % % Cell 1: preparations ; put filenames into fn , set some bvp parameters sd0 = ’ f1 ’; sp0 = ’ pt13 ’; sd1 = ’ p3 ’; sp1 = ’ pt19 ’; flip =1; % p3 - > FSC 5 fn = setfnflip ( sd0 , sp0 , sd1 , sp1 , flip ) ; % filename - struct opt =[]; opt = ocstanopt ( opt ) ; % set options and params for CP computations % set oc - params for which there is no default : opt . rhoi =1; % index of discount rate rho , rho is at p . u ( p . nu + p . nq + rhoi ) opt . t1 =100; % truncation time 10 % reset some oc - params to customized values opt . start =1; % 1 for first call opt . tv =[]; sol =[]; % t - mesh , solution , empty at startup opt . nti =10; % initial # of points in t - mesh opt . retsw =0; % only return final step in iscnat 15 opt . msw =1; % use secant predictors ( after first step ) in iscnat usec =[]; % first secant ( naturally ) empty alvin =[0.25 0.5 0.7 1]; % desired alpha - values ; these can also be split , e . g . , % first call iscnat with alvin =[0.25 0.5] , then again with alvin =[0.7 1] 20 [ alv , vv , sol , udat , tlv , tv , uv ]= iscnat ( alvin , sol , usec , opt , fn ) ; % continuation call ,

9

25

30

35

40

45

50

% see iscnat source and tutorial for more explanation va =[15 ,30]; % viewing angles used in solution plots slsolplot ( sol , va ) ; % some plots % % Cell 2: a fold in alpha , here iscarc needed ; Prep . and initial iscarc call sd0 = ’ f1 ’; sp0 = ’ pt13 ’; sd1 = ’ p1 ’; sp1 = ’ pt68 ’; flip =1; fn = setfnflip ( sd0 , sp0 , sd1 , sp1 , flip ) ; esol =[]; % no extended sol at startup ( iscarc on startup calls isnat anyway ) opt . start =1; % 1 for first call opt . alvin =[0.2 0.3]; % alpha values for startup of iscarc opt . nsteps =3; % # of steps for iscarc sig =0.1; opt . sigmax =1; % stepsize and max stepsize opt . Stats_step = ’ on ’; % give mtom diagnostics opt . retsw =1; % return full alpha and soln history [ alv , vv , usec1 , esol1 , tlv , tv , uv ]= iscarc ( esol , usec , opt , fn ) ; % continuation call opt . start =0; % set to 0 for subsequent calls % % Cell 3: subsequent iccarc - calls ( repeat this cell to continue further ) opt . nsteps =35; usec = usec1 ; esol = esol1 ; % new input ( for repeated calls ) [ alv1 , vv1 , usec1 , esol1 , tlv1 , tv1 , uv1 ]= iscarc ( esol , usec , opt , fn ) ; % append output to previous steps for repeated calls alv =[ alv alv1 ]; vv =[ vv vv1 ]; tlv =[ tlv tlv1 ]; tv =[ tv ; tv1 ]; uv =[ uv ; uv1 ]; alv0 = alv ; vv0 = vv ; tv0 = tv ; uv0 = uv ; tlv0 = tlv ; % save results for skibademo . m % % Cell 4: a simple plot of J over alpha figure (6) ; clf ; plot ( alv (1 ,:) , vv (1 ,:) , ’ -* ’) ; set ( gca , ’ FontSize ’ ,14) ; xlabel ( ’\ alpha ’ , ’ FontSize ’ ,14) ; ylabel ( ’ J_ { a } ’ , ’ FontSize ’ ,14) ; % % Cell 5: plot selected ( here : the last ) path from continuation j = length ( tlv ) ; tl = tlv ( j ) ; va =[25 ,15]; n = s1 . nu ; sol . x = tv (j ,1: tlv ( j ) ) ; sol . y = squeeze ( uv (j ,1: n ,1: tlv ( j ) ) ) ; al = alv ( j ) , u0 = al * s0 . u (1: n ) +(1 - al ) * s1 . u (1: n ) ; u1 = s1 . u (1: s1 . nu ) ; slsolplot ( sol , va ) ; % % Cell 6: fix al from iscarc to some given value and compute CPs j =22; alv ( j ) , n = s1 . nu ; sol . x = tv (j ,1: tlv ( j ) ) ; sol . y = squeeze ( uv (j ,1: n ,1: tlv ( j ) ) ) ; al =0.6; u0 = al * s0 . u (1: n ) +(1 - al ) * s1 . u (1: n ) ; u1 = s1 . u (1: s1 . nu ) ; opt . M = s1 . mat . M ; sol = mtom ( @mrhs , @cbcf , sol , opt ) ; v =[100 ,30]; slsolplot ( sol , va ) ;

Listing 7: sloc/cpdemo1D.m. In the 0th cell we set some global variables. Cell 1 starts in lines 4,5 with setting the file names for the starting and target CSS. In line 6ff we first set the parameters for canonical path computations (via iscnat and iscarc) to standard values, and then reset some as suitable for the present problem. See the comments in the m-source, and Table 3. In line 23 we then call one of the two main continuation methods for canonical paths, namely iscnat, described below, and in lines 25,26 we plot the obtained results. In Cell 2 we use iscarc (described below) instead of iscnat, because for the initial and target states used here the continuation in the initial states leads to a fold. Cell 3 calls iscarc again, and can be repeated to continue further. In line 20 we store the obtained data in some helper fields alv0, ..., for postprocessing in skibademo, see §2.1.4. In Cell 4 we plot the branch obtained so far, and in Cells 5 and 6 we illustrate how to extract data for plotting and postprocessing from the full α history returned by iscnat in Cell 3. Some results of running cpdemo1D are shown in Fig. 2. (a) shows the “easy” case of a (canonical) path from p3/pt19 to FSC (Listing 7 up to line 21), while (b) illustrates the case of a fold in α when trying to get a path from p1/pt71 to the FSC. (c)-(d) shows a path obtained from picking a path from the output of iscarc and a posteriori correcting to α = 0.6 (Cell 7). 2.1.3

Main oc-lib function

We now give an overview of the involved functions from pde2path/libs/oc, with the Cells referring to Listing 7. fn=setfnflip(sd0,sp0,sd1,sp1,flip); (Cell 1) generates the file name struct fn from sd0, sp0 (sd0/sp0.mat contains IC u0 ) and sd1,sp1 (contains u ˆ); if flip=1, then interchange *0 and *1. opt=ocstanopt(opt); (Cell 1) Convenience function (similar to p=stanparam(p)) to set parameters for the computation of canonical paths. These are parameters for TOM (see tom/tomset.m), and parameters for iscnat and/or iscarc, see Table 3 for an overview. Typically some of these are afterwards reset to problem depending values, and finally we need to set the vector alvin of desired α values for the continuation in the initial states. 10

(a) canonical path from p3/pt19 to FSC

(b) A fold in α

(c) The “upper” canonical path at α = 0.6

(d) diagnostics

Figure 2: Example outputs from running slcpdemo.m Table 3: Switches/controls in opt besides the TOM options (for which we refer to the mtom source code). Note that iscarc only has a very elementary stepsize control via opt.sigmin,opt.sigmax. name start retsw rhoi nti nsteps lu

purpose 1 for startup, 0 else 1 to return full continuation data index of discount rate ρ in par, i.e., ρ is at p.u(p.nu+p.nq+rhoi) # of points in startup t–mesh number of steps for iscarc 0/1 to not use/use LU decomposition for linear systems in mtom, default 0

name M t1 tv sigmin,sigmax vsw

purpose mass matrix in p (extra) verbosity for mtom truncation time T current t–mesh min&max stepsize for iscarc verbosity switch, 0 (default) or 1, controls screen output in mtom

[alv,vv,sol,udat,tlv,tv,uv]=iscnat(alvin,sol,usec,opt,fn); (Cell 1) Input: alvin as the vector of desired α values, for instance alvin=[0.25 0.5 1]. sol,usec can be empty (typically on first call), but on subsequent calls should contain the last solution and the last secant (if opt.msw=1). fn is a structure containing the file names for the start CSS and end CSS 6 , and opt is an options structure containing TOM options and some more, see Table 3 and Remark 2.1. Output: alv as the α vector of successful solves; vv as the canonical path values Ja of the successful solves; sol as the (last) canonical path; ydat contains the 2 last steps and the last secant (useful for repeated calls, and for using iscnat as startup for iscarc). Finally, if opt.retsw=1, then tlv,tv,uv contain data of all successful solves, namely: for the j-th step, j=1:length(alv), tlv(j), contains the mesh size (in t), tv(j,1:tlv(j)) the mesh, and uv(j,1:n,1:tlv(j) the solution. Thus, via sol.x=xv(j,1:tlv(j)); sol.y=squeeze(uv(j, 1:n, 1:tlv(j))); the solution of the j-th step is recovered. This is useful for a posteriori inspecting some solution from the continuation (see line 22, and skibademo.m). Note that uv 6 Taking v from a CSS is basically for convenience. The initial states v0 can be arbitrary, and there are no initial conditions for the co–states (and in particular those of the “starting CSS” are not used). However, the construction is also motivated by the fact that one of the most interesting questions is if given v from some CSS u ˆ0 there exists a canonical path connecting to a different CSS u ˆ1 , and whether this yields a higher value. Then, it is also interesting if one can also go the other way round, and for this we provide the flip parameter in setfnflip, see below.

11

can be large, and might give memory problems. If opt.retsw=0, then tlv,tv,uv are empty. [alv,vv,usec,esol,tlv,tv,uv]=iscarc(esol,usec,opt,fn) (Cell 2) Input: as for iscnat (without alvin), but with esol containing the extended solution (uα , α), and similar for the secant usec; as in iscnat, if opt.start=1, then esol,usec can be empty. Output: alv,val∈ R1×m as the vectors of achieved α and Ja (α); usec,esol as the last secant and solution; tlv,tv,uv as in iscnat, but all in the sense of extended solutions, i.e. (uα , α). Remark 2.1 Concerning the original TOM options we remark that typically we run iscnat and iscarc with weak error requirements and what appears to be the fastest monitor and order options, i.e., opt.Monitor=3; opt.order=2. Once continuation is successful (or also if it fails at some α), we can always postprocess by calling mtom again with a higher order, stronger error requirements, and different monitor options. See the original TOM documentation. c The functions iscnat and iscarc are the two main user interface functions for the canonical path numerics. There are a number of additional functions for internal use, and some convenience functions, which we briefly review as follows: [Psi,mu,d,t]=getPsi(s1); compute Ψ, the eigenvalues mu, the defect d, and a suggestion for T . Note that this becomes expensive with large 2nN (i.e., the number of spatial DoF). [sol,info]=mtom(ODE,BC,solinit,opt,varargin); Our modification of TOM, which allows for M in (11a). Extra arguments M and lu,vsw in opt. If opt.lu=0, then \ is used for solving linear systems instead of an LU–decomposition, which becomes too slow when 2nN × m becomes too large. See the TOM documentation for all other arguments including opt, and note that the modifications in mtom can be identified by searching “HU” in mtom.m. Of course mtom (as any other function) can also be called directly, which for instance is useful to postprocess the output of some continuation by changing parameters by hand. f=mrhs(t,u,k); J=fjac(t,u); and f=mrhse(t,u,k); J=fjace(t,u); the rhs and its Jacobian to be called within mtom. These are just wrappers which calculate f and J by calling the resp. functions in the pde2path–struct s1, which were already set up and used to calculate the CSS. s1 is passed as a global variable. Similar remarks apply to mrhse and fjace for the extended setting in iscarc. bc=cbcf(ya,yb);[ja,jb]=cbcjac(ya,yb) and bc=cbcfe(ya,yb);[ja,jb]=cbcjace(ya,yb); The boundary conditions (in time) for (11) and the associated Jacobians. Implemented by passing u0 , u ˆ1 , Ψ and similar as global variables. The *e (as in extended) versions are for iscarc. jcaval=jcai(s1,sol,rho) and djca=isjca(s1,sol,rho); Calculate the objective value Z T J(u) = e−ρt Jca (v(t, ·), k(t, ·)) dt (22) 0

of the solution u in sol (with Jc taken from s1.fuha.jcf), and similarly the discounted value of a CSS contained in sol.y(:,end). slsolplot(sol,view); convenience plotting function for sloc canonical paths, including diagnostic plots. This is for instance useful to check the convergence behavior of the canonical path as t → T , cf. (d),(f) in Fig. 2. Thus, after having set up p as in §2.1.1 for the CSS, including G and p.fuha.jcf, the user does not need to set up any additional functions to calculate canonical paths and their values. 2.1.4

Skiba points

In ODE OC applications, if there are several locally stable OSS, then often an important issue is to identify their domains of attractions. These are separated by so called threshold or Skiba–points (if N = 1) or Skiba–manifolds (if N > 1), see [Ski78] and [GCF+ 08, Chapter 5]. Roughly speaking, these are initial states from which there are several optimal paths with the same value but leading to different CSS. Here we give an example for the SLOC model how to compute a patterned Skiba point between FSC and FSM. 12

In Cell 3 of cpdemo1D.m we attempt to find a path from vPS given by p1/pt68 to (v, q)FSC given by FSC/pt13; this fails due to the fold in α. However, for given α we can also try to find a path from the initial state vα (0) := αvPS + (1 − α)PFSC to the FSM, and compare to the path to the FSC. For this, in Cell 3 of cpdemo1D.m, we stored the α and Jca values into alv0, vv0, and also the path data into tlv0,tv0 uv0. In skibademo.m (Listing 8, which is a rather elaborate application of the OC facilities of pde2path, and can be skipped on first reading) we find paths from these uv0 initial states from cpdemo1D.m to the other flat steady state with the SPP, namely FSM, and compare the values with the values of the paths to FSC, stored in vv0. See Fig. 3 for illustration.

5

10

15

20

25

% Skiba example , continues cpdemo1D . m % find paths from the uv0 initial states from cpdemo . m to FSM js =10; je =30; jl = je - js +1; % alpha - range ; now set the target and Psi to FSM : s1 = loadp ( ’ f2 ’ , ’ pt12 ’) ; u1 = s1 . u (1: s1 . nu ) ; [ Psi , muv ,d , t1 ]= getPsi ( s1 ) ; a0l = length ( alv0 ) ; tva = zeros ( jl , opt . Nmax +1) ; % some prep . and fields to hold paths n = s1 . nu ; uva = zeros ( jl , n +1 , opt . Nmax +1) ; alva =[]; vva =[]; tavl =[]; sol =[]; alvin =[0.1 0.25 0.5 0.75 1]; % we run from uv0 (j ,:) to FSM with iscnat tv = linspace (0 , opt . t1 , opt . nti ) ; se =2; opt . tv = tv .^ se ./ opt . t1 ^( se -1) ; doplot =1; opt . start =0; opt . msw =0; opt . Stats_step = ’ off ’; v =[50 ,8]; % switch off stats for j = js : je ; % continue till Skiba paths found , or till the end ... fprintf ( ’j =% i , al =% g \ n ’ , j , alv0 ( j ) ) ; s0 . u (1: n ) = uv0 (j ,1: n ,1) ’; [ alv , vv , sol , udat ]= iscnat ( alvin ,[] ,[] , opt , fn ) ; if alv ( end ) ==1; Jd = vv0 ( j ) - vv ( end ) ; fprintf ( ’J1 - J2 =% g \ n ’ , Jd ) ; % cont . success alva =[ alva alv0 ( j ) ]; vva =[ vva vv ( end ) ]; tl = length ( sol . x ) ; % save values talv =[ tavl tl ]; tva (j ,1: tl ) = sol . x ; uva (j ,1: n ,1: tl ) = sol . y ; if abs ( Jd ) 1 u = varargin {1}; else u = p . u ; end par = p . u ( p . nu +1: end ) ; cp = par (11) ; pp = par (12) ; al = par (13) ; v = u (1: p . np ) ; l1 = u (2* p . np +1:3* p . np ) ; 5 gas =(( pp - l1 ) *(1 - al ) ./ cp ) .^(1/ al ) ; e = gas .* v ; h = v .^ al .* e .^(1 - al ) ; J = pp * v .^ al .* e .^(1 - al ) - cp * e ;

Listing 12: vegoc/efu.m. Auxiliary function computing the harvesting effort (control) E, the harvest h and the current value J, hence also called in vegoc/vegjcf.m Figure 4 shows a basic bifurcation diagram of CSS in 1D with Ω = (−L, L), L = 5, from the script file bdcmds.m, which follows the same principles as the one for the SLOC demo. Again we start with a spatially flat (i.e., homogeneous) canonical steady FSS (black), on which we find a number of Turing-like bifurcations. The blue branch in (a) represents the primary bifurcation of PCSS (patterned canonical steady states), which for certain R have the SPP, and, moreover, turn out to be POSS (patterned optimal steady states). See [Uec16] for more plots, including a comparison with case of so called “private optimization”, and 2D results for Ω = (−L, L) × √ the uncontrolled √ (− 3L/2, 3L/2) yielding various POSS, including hexagonal patterns. The script files cpcmds.m for canonical paths, and skibacmds.m for a Skiba point between the flat optimal steady state FSS/pt13 and the POSS p1/pt34, again follow the same principles as in the the SLOC demo. See Figure 5 for an example output. We use customized colormaps for vegetation (green) and water (blue), which are provided as vegcm.asc, watcm.asc and whitecm.asc, respectively.

16

p1/pt11 to FSS/pt17. J0=733.37, J=735.41, J1=748.29 200

||v(t)−v0||∞

150

||v(t)−v1||∞

14

4Jc,a

12 10

200

−5 50 t

100

0

−5 5 0

100

9.5 50

50 0 0

10

100

100

8

50

300

w

v

10.5

E

100

11 400

t

0

5 0

t

50 −5

0

5 0

t

Figure 5: Example output of vegoc/cpcmds.m, namely the canonical path from the lower PCSS(p1/pt11) to the FCSS (FSS/pt17) at R = 26. The left panel indicates the convergence behavior, the current value profit, and obtained objective value. The middle and right panels show the strategy E and the corresponding behavior of (v, w). See [Uec16] for comments and more details.

2.3

Boundary control

Our third example, taken from [UU17], considers the optimization of the discounted fishing profit 2 X R ∞ −ρt J = 0 e Jc (v(0, t), k(t)) dt, Jc (v, k) = pj hj (vj , kj ) − cj kj . Here v = (v1 , v2 ) are the populations j=1

of two fish species (v1 =prey, v2 =predator) in a (1D) lake or ocean Ω = (0, lx ), k = (k1 , k2 ) are the fishing (harvesting) efforts (controls) of v1 and v2 , respectively, at the shore, and p1,2 and c1,2 are the prices for the fishes and the costs for fishing, respectively, and we again choose a Cobb–Douglas α 1−α form for the harvests hj (vj , kj ) = vj j kj j , with parameters αj ∈ (0, 1). We assume that fishing is only possible at the boundary x = 0, and that the fish populations evolve according to a standard Lotka-Volterra model, namely ∂t v1 = d1 ∆v1 + (1 − βv1 − v2 )v1 , , or ∂t v = −G1 (v) = D∆v + f (v), ∂t v2 = d2 ∆v2 + (v1 − 1)v2 ,

(25)

    d1 0 (1 − βv1 − v2 )v1 in Ω, with D = and growth function f (v) = , with parameter β > 0. 0 d2 (v1 − 1)v2 The controls k1,2 (fishing efforts for species v1,2 , respectively) occur in the BC for (25), i.e., we assume the Robin BC dj ∂n vj = −gj := −γj hj ,

j = 1, 2, at x = 0,

(26)

and zero flux BC ∂n vj = 0 at x = lx . Thus, in contrast to the sloc and vegoc examples we no longer have a spatially distributed control, but a (two component) boundary control. Introducing the co-states λ1,2 : Ω → R, Pontryagin’s maximum principle yields the evolution and the BCs of the co-states (combining with (25), to have it all together)  ∂t v = D∆v + f (v), in Ω = (0, lx ), (27a) ∂t λ = ρλ − D∆λ − (∂v f (v))T λ  D∂n v + g = 0, on the left boundary x = 0, (27b) D∂n λ + ∂v g(v)λ − ∂v Jc = 0,  D∂n v = 0, on the right boundary x = lx , (27c) D∂n λ = 0, and  kj =

(1 − αj )2 (pj − γj λj ) cj

1/αj vj , evaluated at the left boundary x = 0,

17

j = 1, 2.

(27d)

See [UU17] for details on the derivation of (27). Thus, we again have a 4 component reaction diffusion system (27a-c) for the states v and the costates λ, but now the controls live on the boundary at x = 0, leading to nonlinear flux boundary conditions. Also, from the modeling point of view, the pertinent questions for (27) are slightly different than for (24), since for (27) we are not so much interested in bifurcations and pattern formation (which do not occur for the parameters chosen below), but rather in the dependence of the (unique) CSS on the parameters, and mostly in the canonical paths leading to these CSS. In any case, we now focus on how to put the nonlinear BC into pde2path. Table 5 lists the scripts and functions in ocdemos/lvoc, and some further comments are given in the listing captions below. Table 5: Scripts and functions in ocdemos/lvoc; the first four follow rather closely the same pde2path principles as the respective functions in sloc, vegoc. lvsG is a rather non–generic implementation of the rhs of (27), and in particular strongly uses the 1D nature of the problem. The others are naturally also problem specific, and in particular the last three overload some pde2path standard functions. script/function bdcmds cpcmds p=lvinit(p,lx,nx,sw) p=oosetfemops(p) r=lvsG(p,u) out=lvbra(p,u) [h,hv,hk]=hfu(p,u) [jc,jc1,jc2]=lvjcf(p,u) ja=jca(p,u) zdia=lvdiagn(sol,wnr,fn,sw) classdef stanpdeo1D < pde [alv,...]=iscnat(alvin,...) plotsol(f),psol3D

purpose,remarks script to compute CSS script to compute CPs init routine, where again sw is used to choose different initial guesses u; also contains, in contrast to sloc and vegoc, the setting of parameters set FEM matrices (stiffness K and mass M) the rhs for (27a), also explicitly implementing the BC (27b), while (27c) are naturally fulfilled with K the Neumann Laplacian. branch-output, here substantially modified from stanocbra, i.e., writing specific data like profits/harvest/controls per fish-species on the branch returns harvest h ∈ R2 , and derivatives (needed for lvsG) ∂v h ∈ R2×2 , ∂k h ∈ R2×2 ; straightforward implementation. returns Jc , as required in the standard pde2path setup for OC problems, but also the individual profits J1,2 per fish-species. Jc average, overloaded here since Jc is on boundary, hence the default averaging by 1/|Ω| makes no sense diagnostics functions for canonical paths overloads the pde2path function (classdef) stanpdeo1D in order to have Ω = (0, lx ) instead of Ω = (−lx , lx ) (standard). overloads the pde2path function of the same name because here we also want to set initial states ’by hand’, see l13-15. some more overloads of pde2path standard functions for customized plotting

function p = oosetfemops ( p ) % for lvoc , all standard , Neumann Laplacian , % no BC matrices here since BC directly put into sG ( feasible in 1 D ) [ p . mat .K ,M ,~]= p . pdeo . fem . assema ( p . pdeo . grid ,1 ,1 ,1) ; p . mat . M = kron ( eye (4) ,M ) ;

Listing 13: lvoc/oosetfemops.m. We save the system (multi-component) mass matrix M in p.mat.M (as usual), but we only save the scalar Neumann Laplacian in p.mat.K, from which we assemble the system stiffness matrix in lvsG.m. function out = lvbra (p , u ) % branch - output for lvoc par = u ( p . nu +1: end ) ; p1 = par (11) ; p2 = par (12) ; ga1 = par (6) ; ga2 = par (7) ; v1 = u (1) ; v2 = u ( p . np +1) ; l1 = u (2* p . np +1) ; l2 = u (3* p . np +1) ; au1 = p1 - ga1 * l1 ; au2 = p2 - ga2 * l2 ; [h , hp ]= hfu (p , p . u ) ; 5 [ jc , jc1 , jc2 ]= lvjcf (p , p . u ) ; k = lvcon (p , p . u ) ; out =[ jc ; jc1 ; jc2 ; v1 ; v2 ; l1 ; l2 ; k (1) ; k (2) ; h (1) ; h (2) ; au1 ; au2 ; max ( u (1: p . np ) ) ; min ( u (1: p . np ) ) ];

Listing 14: lvoc/lvbra.m as an example where we put a lot of problem-specific data on the branch (for later plotting or other post-processing). function [ jc , jc1 , jc2 ]= lvjcf (p , u ) % current value ( s ) J

18

par = u ( p . nu +1: end ) ; al1 = par (9) ; al2 = par (10) ; p1 = par (11) ; p2 = par (12) ; c1 = par (13) ; c2 = par (14) ; v1 = u (1) ; v2 = u ( p . np +1) ; k = lvcon (p , u ) ; 5 jc1 = p1 * v1 ^ al1 * k (1) ^(1 - al1 ) - c1 * k (1) ; jc2 = p2 * v2 ^ al2 * k (2) ^(1 - al2 ) - c2 * k (2) ; jc = jc1 + jc2 ;

Listing 15: lvoc/lvjcf.m as an example where additional to the objective function J (standard) we also compute the individual profits for each species (used in lvbra). function r = lvsG (p , u ) % rhs for lvoc . n = p . np ; par = u ( p . nu +1: end ) ; beta = par (1) ; d1 = par (4) ; d2 = par (5) ; ga1 = par (6) ; ga2 = par (7) ; rho = par (8) ; p1 = par (11) ; p2 = par (12) ; % extract pars v1 = u (1: n ) ; v2 = u ( n +1:2* n ) ; l1 = u (2* n +1:3* n ) ; l2 = u (3* n +1:4* n ) ; % extract fields

5 f1 = v1 .*(1 - beta * v1 - v2 ) ; f2 =( v1 -1) .* v2 ; % bulk nonlin . a11 =1 -2* beta * v1 - v2 ; a12 = - v1 ; a21 = v2 ; a22 = v1 -1; f3 = rho * l1 - a11 .* l1 - a21 .* l2 ; f4 = rho * l2 - a12 .* l1 - a22 .* l2 ; 10 f =[ f1 ; f2 ; f3 ; f4 ]; F = p . mat . M * f ; l11 = l1 (1) ; l21 = l2 (1) ; [h , hv , hk ]= hfu (p , u ) ; % bd vals of lambda , and harvest g1 = - ga1 * h (1) ; g2 = - ga2 * h (2) ; % BC for states g3 = -( p1 - ga1 * l11 ) * hv (1) ; g4 = -( p2 - ga2 * l21 ) * hv (4) ; % BC for co - states

15 F (1) = F (1) + g1 ; F ( n +1) = F ( n +1) + g2 ; % add BC directly into F , states F (2* n +1) = F (2* n +1) + g3 ; F (3* n +1) = F (3* n +1) + g4 ; % BC for co - states zM =0* speye ( n ) ; K = p . mat . K ; % finally assemble the system K K =[[ d1 * K zM zM zM ]; [ zM d2 * K zM zM ]; [ zM zM - d1 * K zM ]; [ zM zM zM - d2 * K ]]; 20 r = K *[ v1 ; v2 ; l1 ; l2 ] - F ; % and compute the residual as usual

Listing 16: lvoc/lvsG.m. As usual we first extract the relevant parameters and fields from u, and compute the ’bulk’ nonlinearity f (i.e., the nonlinearity in Ω). Then, to compute the BC we first extract values of the co-states on the boundary, and the associated harvests and their derivatives. These are needed to compute the BCs gj , j = 1, . . . , 4 (lines 13,14), which can then directly be added to the rhs on the boundary (lines 16,17). Here we strongly use the 1D setup, i.e., that the left boundary value of component j is at u((j-1)*np+1), where np is the number of spatial discretization points. In line 19 we then assemble the system K. Compared to the setup in vegoc/vegsG this has the advantage that the diffusion constants d1,2 can be used like any other parameter at this point. The actual computation of r in line 20 then works as usual. Figure 6 gives some example plots from running bdcmds.m. This script is rather lengthy, with the main point here to illustrate how to plot various data of interest by first putting it on the branch (here via lvbra.m) and then choosing the pertinent component for plotting. The script cpcmds.m for computing canonical paths follows the same outline as those for the sloc and vegoc examples. Figure 7 shows a canonical path to the CSS at c = (0.1, 0.1), starting from the homogeneous fixed point V ∗ = (1, 1 − β) of (25), which is the reason for the only change in the local overload of iscnat.m in the working directory ocdemos/lvoc. As already said, we refer to [UU17] for discussion of the results.

3

Summary and outlook

We explained how to study OC problems of class (1) in pde2path in a simple and convenient way. The class (1) is quite general, and with the pde2path machinery we have a powerful tool to first study the bifurcations of CSS. The computation of canonical paths is comparatively more involved. Essentially, our step (b) implements for the class (1) (parts of) the connecting orbits methods explained for ODE problems in [GCF+ 08, Chapter 7], see also [Gra15]. See [DCF+ 97, BPS01] and the references therein for earlier work on connecting orbits in ODE problems, including connecting orbits to periodic solutions, which for ODE OC problems may also be important as long-run optimal solutions, again cf. [GCF+ 08]. See also [Uec17b, §4.4] for a simple PDE case with (nontrivial, i.e., spatially patterned) Hopf bifurcations in a canonical system, and associated time periodic solutions, and [Uec17a, §2.4] for 19

(a) cont. in c1 , J, v and k at x = 0

(b) CSS at c = (0.1, 0.1)

Figure 6: (a) continuation diagrams in c1 (costs for prey fishing); Jj = pj hj − cj kj , J = J1 + J2 . (b) An example CSS plots. (a) CP from V ∗ to the CSS at (c1 , c2 ) = (0.1, 0.1)

Figure 7: CPs starting from the spatially homogeneous steady state V ∗ of (25). Note the logarithmic scales in the time-series of the values at the left boundary.

the implementation. However, the computation of connecting orbits to such periodic orbits remains to be implemented in pde2path, and thus we cannot yet discuss their optimality. Of course, there is a rather large number of issues we do not address (yet), for instance inequality constraints that frequently occur in OC problems. In our examples we can simply check the natural constraints (such as v, k ≥ 0 in the sloc example) a posteriori and find them to be always fulfilled, i.e., inactive. If such constraints become active the problem becomes much more complicated.

References [AAC11]

S. Anit¸a, V. Arn˘ autu, and V. Capasso. An introduction to optimal control problems in life sciences and economics. Birkh¨ auser/Springer, New York, 2011.

[BPS01]

W.J. Beyn, Th. Pampel, and W. Semmler. Dynamic optimization and Skiba sets in economic examples. Optimal Control Applications and Methods, 22(5–6):251–280, 2001.

[BX08]

W.A. Brock and A. Xepapadeas. Diffusion-induced instability and pattern formation in infinite horizon recursive optimal control. Journal of Economic Dynamics and Control, 32(9):2745–2787, 2008.

[BX10]

W. Brock and A. Xepapadeas. Pattern formation, spatial externalities and regulation in coupled economic–ecological systems. Journal of Environmental Economics and Management, 59(2):149– 164, 2010.

[DCF+ 97]

E. Doedel, A. R. Champneys, Th. F. Fairgrieve, Y. A. Kuznetsov, Bj. Sandstede, and X. Wang. AUTO: Continuation and bifurcation software for ordinary differential equations (with HomCont). http://cmvl.cs.concordia.ca/auto/, 1997.

[dWDR+ 17] H. de Witt, T. Dohnal, J. Rademacher, H. Uecker, and D. Wetzel. pde2path - Quickstart guide and reference card, 2017. Available at [Uec17c].

20

[GCF+ 08]

D. Grass, J.P. Caulkins, G. Feichtinger, G. Tragler, and D.A. Behrens. Optimal Control of Nonlinear Processes: With Applications in Drugs, Corruption, and Terror. Springer Verlag, 2008.

[Gra15]

D. Grass. From 0D to 1D spatial models using OCMat. Technical report, ORCOS, 2015.

[GU17]

D. Grass and H. Uecker. Optimal management and spatial patterns in a distributed shallow lake model. Electr. J. Differential Equations, 2017(1):1–21, 2017.

[KW10]

T. Kiseleva and F.O.O. Wagener. Bifurcations of optimal vector fields in the shallow lake system. Journal of Economic Dynamics and Control, 34(5):825–843, 2010.

[MS02]

F. Mazzia and I. Sgura. Numerical approximation of nonlinear BVPs by means of BVMs. Applied Numerical Mathematics, 42(1–3):337–352, 2002. Numerical Solution of Differential and Differential-Algebraic Equations, 4-9 September 2000, Halle, Germany.

[MST09]

F. Mazzia, A. Sestini, and D. Trigiante. The continuous extension of the B-spline linear multistep methods for BVPs on non-uniform meshes. Applied Numerical Mathematics, 59(3–4):723–738, 2009.

[MT04]

F. Mazzia and D. Trigiante. A hybrid mesh selection strategy based on conditioning for boundary value ODE problems. Numerical Algorithms, 36(2):169–187, 2004.

[Pr¨ u16]

U. Pr¨ ufert. OOPDE: FEM for Matlab, www.mathe.tu-freiberg.de/nmo/mitarbeiter/ uwe-pruefert/software, 2016.

[RU17]

J.D.M. Rademacher and H. Uecker. The OOPDE setting of pde2path – a tutorial via some Allen-Cahn models, 2017.

[RZ99a]

J. P. Raymond and H. Zidani. Hamiltonian Pontryagin’s principles for control problems governed by semilinear parabolic equations. Appl. Math. Optim., 39(2):143–177, 1999.

[RZ99b]

J. P. Raymond and H. Zidani. Pontryagin’s principle for time-optimal problems. J. Optim. Theory Appl., 101(2):375–402, 1999.

[Ski78]

A. K. Skiba. Optimal growth with a convex-concave production function. 46(3):527–539, 1978.

[Tr¨ o10]

Fredi Tr¨ oltzsch. Optimal control of partial differential equations, volume 112 of Graduate Studies in Mathematics. American Mathematical Society, Providence, RI, 2010.

[Uec16]

H. Uecker. Optimal harvesting and spatial patterns in a semi arid vegetation system. Natural Resource Modelling, 29(2):229–258, 2016.

[Uec17a]

H. Uecker. Hopf bifurcation and time periodic orbits with pde2path – a tutorial, 2017. Available at [Uec17c].

[Uec17b]

H. Uecker. Hopf bifurcation and time periodic orbits with pde2path – algorithms and applications, Preprint, 2017.

[Uec17c]

H. Uecker. www.staff.uni-oldenburg.de/hannes.uecker/pde2path, 2017.

[UU17]

H. Uecker and T. Upmann. Optimal fishery with coastal catch. Preprint, 2017.

[UWR14]

H. Uecker, D. Wetzel, and J. Rademacher. pde2path – a Matlab package for continuation and bifurcation in 2D elliptic systems. NMTMA, 7:58–106, 2014.

21

Econometrica,