784 Chapter 17.Two Point Boundary Value Problems where o()is chosen by us.Written in terms of the mesh variable g,this equation is dx 西=石 (17.5.7) Notice that ()should be chosen to be positive definite,so that the density of mesh points is everywhere positive.Otherwise (17.5.7)can have a zero in its denominator. To use automated mesh spacing,you add the three ODEs (17.5.5)and (17.5.7)to your set of equations,i.e.,to the array y[j][k].Now r becomes a dependent variable!Q and also become new dependent variables.Normally,evaluating o requires little extra work since it will be composed from pieces of the g's that exist anyway.The automated procedure allows one to investigate quickly how the numerical results might be affected by various strategies for mesh spacing.(A special case occurs if the desired mesh spacing function Q can be found 81 analytically,i.e.,dQ/dr is directly integrable.Then,you need to add only two equations, those in 17.5.5,and two new variables . As an example of a typical strategy for implementing this scheme,consider a system with one dependent variable y(r).We could set ICAL dQ=+dm到 (17.5.8) △ 6 or )=9=1+/ RECIPES dx 4+ y6 (17.5.9) where A and 6 are constants that we choose.The first term would give a uniform spacing in if it alone were present.The second term forces more grid points to be used where y is changing rapidly.The constants act to make every logarithmic change in y of an amount o about as "attractive"to a grid point as a change in of amount A.You adjust the constants according to taste.Other strategies are possible,such as a logarithmic spacing in replacing de in the first term with dIn x. IENTIFIC CITED REFERENCES AND FURTHER READING: Eggleton,P.P.1971,Monthly Notices of the Royal Astronomical Society.vol.151,pp.351-364. 6 Kippenhan,R.,Weigert,A.,and Hofmeister,E.1968,in Methods in Computational Physics, vol.7 (New York:Academic Press),pp.129ff. 17.6 Handling Internal Boundary Conditions Numerical 色 or Singular Points 431086 Singularities can occur in the interiors of two point boundary value problems.Typically, (outside there is a point s at which a derivative must be evaluated by an expression of the form North Software. N(xs,y) S(xs)=Dxs习) (17.6.1) where the denominator D(s,y)=0.In physical problems with finite answers,singular points usually come with their own cure:Where D-0,there the physical solution y must be such as to make N-0 simultaneously,in such a way that the ratio takes on a meaningful value.This constraint on the solution y is often called a regularity condition.The condition that D(,y)satisfy some special constraint at is entirely analogous to an extra boundary condition,an algebraic relation among the dependent variables that must hold at a point. We discussed a related situation earlier,in $17.2,when we described the"fitting point method"to handle the task of integrating equations with singular behavior at the boundaries. In those problems you are unable to integrate from one side of the domain to the other
784 Chapter 17. Two Point Boundary Value Problems Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). where φ(x) is chosen by us. Written in terms of the mesh variable q, this equation is dx dq = ψ φ(x) (17.5.7) Notice that φ(x) should be chosen to be positive definite, so that the density of mesh points is everywhere positive. Otherwise (17.5.7) can have a zero in its denominator. To use automated mesh spacing, you add the three ODEs (17.5.5) and (17.5.7) to your set of equations, i.e., to the array y[j][k]. Now x becomes a dependent variable! Q and ψ also become new dependent variables. Normally, evaluating φ requires little extra work since it will be composed from pieces of the g’s that exist anyway. The automated procedure allows one to investigate quickly how the numerical results might be affected by various strategies for mesh spacing. (A special case occurs if the desired mesh spacing function Q can be found analytically, i.e., dQ/dx is directly integrable. Then, you need to add only two equations, those in 17.5.5, and two new variables x, ψ.) As an example of a typical strategy for implementing this scheme, consider a system with one dependent variable y(x). We could set dQ = dx ∆ + |d ln y| δ (17.5.8) or φ(x) = dQ dx = 1 ∆ + dy/dx yδ (17.5.9) where ∆ and δ are constants that we choose. The first term would give a uniform spacing in x if it alone were present. The second term forces more grid points to be used where y is changing rapidly. The constants act to make every logarithmic change in y of an amount δ about as “attractive” to a grid point as a change in x of amount ∆. You adjust the constants according to taste. Other strategies are possible, such as a logarithmic spacing in x, replacing dx in the first term with d ln x. CITED REFERENCES AND FURTHER READING: Eggleton, P. P. 1971, Monthly Notices of the Royal Astronomical Society, vol. 151, pp. 351–364. Kippenhan, R., Weigert, A., and Hofmeister, E. 1968, in Methods in Computational Physics, vol. 7 (New York: Academic Press), pp. 129ff. 17.6 Handling Internal Boundary Conditions or Singular Points Singularities can occur in the interiors of two point boundary value problems. Typically, there is a point xs at which a derivative must be evaluated by an expression of the form S(xs) = N(xs, y) D(xs, y) (17.6.1) where the denominator D(xs, y)=0. In physical problems with finite answers, singular points usually come with their own cure: Where D → 0, there the physical solution y must be such as to make N → 0 simultaneously, in such a way that the ratio takes on a meaningful value. This constraint on the solution y is often called a regularity condition. The condition that D(xs, y) satisfy some special constraint at xs is entirely analogous to an extra boundary condition, an algebraic relation among the dependent variables that must hold at a point. We discussed a related situation earlier, in §17.2, when we described the “fitting point method” to handle the task of integrating equations with singular behavior at the boundaries. In those problems you are unable to integrate from one side of the domain to the other
17.6 Handling Internal Boundary Conditions or Singular Points 785 (a)I XXX I XXX V XXXXXXXXXX XXXXXXXXXX -special block ⊙ B XXXXXXXXXX 4 B XXXXXXXXXX ) XXXXXXXXXX B XXXXX B XXXXXXXXXX E ⊙ XXXXXXXXXX XXXXXXXXXX V B XXXXXXXXXX E ⊙ 83 XXXXXXXXXX E granted for (b)1 XXX ⊙ 11-800-872 (including this one) I XXX B 1 XXX special block V 9 to any /Cambridge XXX NUMERICAL RECIPES IN 1 XXX ⊙ 1 XXX B I XXX 分 (I XX E 0 -7423 (North America server computer, users to make one paper e University Press. THE 1 XX V B 是 ART XX E ⊙ 1 XX D 小 Programs XX V B strictly proh I XX 日 Figure 17.6.1.FDE matrix structure with an internal boundary condition.The internal condition to dir introduces a special block.(a)Original form,compare with Figure 17.3.1;(b)final form,compare with Figure 17.3.2 However,the ODEs do have well-behaved derivatives and solutions in the neighborhood of 1881892 OF SCIENTIFIC COMPUTING(ISBN 0-521- the singularity,so it is readily possible to integrate away from the point.Both the relaxation method and the method of"shooting"to a fitting point handle such problems easily.Also in those problems the presence of singular behavior served to isolate some special boundary values that had to be satisfied to solve the equations. The difference here is that we are concerned with singularities arising at intermediate Numerical Recipes -4310-5 points,where the location of the singular point depends on the solution,so is not known a priori.Consequently,we face a circular task:The singularity prevents us from finding a numerical solution,but we need a numerical solution to find its location.Such singularities (outside are also associated with selecting a special value for some variable which allows the solution Software. to satisfy the regularity condition at the singular point.Thus,internal singularities take on North aspects of being internal boundary conditions. One way of handling internal singularities is to treat the problem as a free boundary problem,as discussed at the end of $17.0.Suppose,as a simple example,we consider visit website the equation machine =N(x,) (17.6.2) dx D(t,y) where N and D are required to pass through zero at some unknown point as.We add the equation dz 之三Ts一E1 .=0 (17.6.3) dx
17.6 Handling Internal Boundary Conditions or Singular Points 785 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). 1 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X V V V V V V B B B B B B 1 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X V V V V V V V V V V V V V V V V V V V V X X X X X X X X X 1 X 1 1 X 1 X X X X X X 1 X X X X X 1 X X X X 1 X 1 X X 1 X X 1 X X 1 1 (b) 1 B B B B B B B special block special block (a) B B B B B B B B B B B B B Figure 17.6.1. FDE matrix structure with an internal boundary condition. The internal condition introduces a special block. (a) Original form, compare with Figure 17.3.1; (b) final form, compare with Figure 17.3.2. However, the ODEs do have well-behaved derivatives and solutions in the neighborhood of the singularity, so it is readily possible to integrate away from the point. Both the relaxation method and the method of “shooting” to a fitting point handle such problems easily. Also, in those problems the presence of singular behavior served to isolate some special boundary values that had to be satisfied to solve the equations. The difference here is that we are concerned with singularities arising at intermediate points, where the location of the singular point depends on the solution, so is not known a priori. Consequently, we face a circular task: The singularity prevents us from finding a numerical solution, but we need a numerical solution to find its location. Such singularities are also associated with selecting a special value for some variable which allows the solution to satisfy the regularity condition at the singular point. Thus, internal singularities take on aspects of being internal boundary conditions. One way of handling internal singularities is to treat the problem as a free boundary problem, as discussed at the end of §17.0. Suppose, as a simple example, we consider the equation dy dx = N(x, y) D(x, y) (17.6.2) where N and D are required to pass through zero at some unknown point xs. We add the equation z ≡ xs − x1 dz dx =0 (17.6.3)
786 Chapter 17.Two Point Boundary Value Problems where is the unknown location of the singularity,and change the independent variable to t by setting x-工1=tz 0≤t≤1 (17.6.4) The boundary conditions at t =1 become N(x,y)=0, D(x,y)=0 (17.6.5) Use of an adaptive mesh as discussed in the previous section is another way to overcome the difficulties of an internal singularity.For the problem (17.6.2),we add the mesh spacing equations dQ =的 (17.6.6) 8 dg dψ =0 (17.6.7) dq with a simple mesh spacing function that maps c uniformly into g,where g runs from 1 to ICAL M,the number of mesh points: Q(x)=x-x1, do 1 (17.6.8) dx Having added three first-order differential equations,we must also add their corresponding boundary conditions.If there were no singularity,these could simply be ≥花 at9=1:x=x1,Q=0 (17.6.9) at g=M:x=x2 (17.6.10) and a total of N values ya specified at g =1.In this case the problem is essentially an initial value problem with all boundary conditions specified at and the mesh spacing function is superfluous. However,in the actual case at hand we impose the conditions at g=1:z=Z1;Q=0 (17.6.11) 6 at q=M:N(x,y)=0,D(x,y)=0 (17.6.12) and N-1 values yi at g=1.The "missing"yi is to be adjusted,in other words,so as to make the solution go through the singular point in a regular(zero-over-zero)rather than irregular (finite-over-zero)manner.Notice also that these boundary conditions do not directly impose a value for x2,which becomes an adjustable parameter that the code varies in an attempt to match the regularity condition. 10621 In this example the singularity occurred at a boundary,and the complication arose Numerica because the location of the boundary was unknown.In other problems we might wish to Recipes 43106 continue the integration beyond the internal singularity.For the example given above,we could simply integrate the ODEs to the singular point,then as a separate problem recommence the integration from the singular point on as far we care to go.However,in other cases the (outside singularity occurs internally,but does not completely determine the problem:There are still some more boundary conditions to be satisfied further along in the mesh.Such cases present North Software. no difficulty in principle,but do require some adaptation of the relaxation code given in $17.3. In effect all you need to do is to add a "special"block of equations at the mesh point where the internal boundary conditions occur,and do the proper bookkeeping. Figure 17.6.1 illustrates a concrete example where the overall problem contains 5 equations with 2 boundary conditions at the first point,one "internal"boundary condition,and two final boundary conditions.The figure shows the structure of the overall matrix equations along the diagonal in the vicinity of the special block.In the middle of the domain,blocks typically involve 5 equations (rows)in 10 unknowns (columns).For each block prior to the special block,the initial boundary conditions provided enough information to zero the first two columns of the blocks.The five FDEs eliminate five more columns,and the final three columns need to be stored for the backsubstitution step(as described in $17.3).To handle the extra condition we break the normal cycle and add a special block with only one equation:
786 Chapter 17. Two Point Boundary Value Problems Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). where xs is the unknown location of the singularity, and change the independent variable to t by setting x − x1 = tz, 0 ≤ t ≤ 1 (17.6.4) The boundary conditions at t = 1 become N(x, y)=0, D(x, y)=0 (17.6.5) Use of an adaptive mesh as discussed in the previous section is another way to overcome the difficulties of an internal singularity. For the problem (17.6.2), we add the mesh spacing equations dQ dq = ψ (17.6.6) dψ dq =0 (17.6.7) with a simple mesh spacing function that maps x uniformly into q, where q runs from 1 to M, the number of mesh points: Q(x) = x − x1, dQ dx =1 (17.6.8) Having added three first-order differential equations, we must also add their corresponding boundary conditions. If there were no singularity, these could simply be at q =1: x = x1, Q =0 (17.6.9) at q = M : x = x2 (17.6.10) and a total of N values yi specified at q = 1. In this case the problem is essentially an initial value problem with all boundary conditions specified at x1 and the mesh spacing function is superfluous. However, in the actual case at hand we impose the conditions at q =1: x = x1, Q =0 (17.6.11) at q = M : N(x, y)=0, D(x, y)=0 (17.6.12) and N − 1 values yi at q = 1. The “missing” yi is to be adjusted, in other words, so as to make the solution go through the singular point in a regular (zero-over-zero) rather than irregular (finite-over-zero) manner. Notice also that these boundary conditions do not directly impose a value for x2, which becomes an adjustable parameter that the code varies in an attempt to match the regularity condition. In this example the singularity occurred at a boundary, and the complication arose because the location of the boundary was unknown. In other problems we might wish to continue the integration beyond the internal singularity. For the example given above, we could simply integrate the ODEs to the singular point, then as a separate problem recommence the integration from the singular point on as far we care to go. However, in other cases the singularity occurs internally, but does not completely determine the problem: There are still some more boundary conditions to be satisfied further along in the mesh. Such cases present no difficulty in principle, but do require some adaptation of the relaxation code given in §17.3. In effect all you need to do is to add a “special” block of equations at the mesh point where the internal boundary conditions occur, and do the proper bookkeeping. Figure 17.6.1 illustrates a concrete example where the overall problem contains 5 equations with 2 boundary conditions at the first point, one “internal” boundary condition, and two final boundary conditions. The figure shows the structure of the overall matrix equations along the diagonal in the vicinity of the special block. In the middle of the domain, blocks typically involve 5 equations (rows) in 10 unknowns (columns). For each block prior to the special block, the initial boundary conditions provided enough information to zero the first two columns of the blocks. The five FDEs eliminate five more columns, and the final three columns need to be stored for the backsubstitution step (as described in §17.3). To handle the extra condition we break the normal cycle and add a special block with only one equation:
17.6 Handling Internal Boundary Conditions or Singular Points 787 the internal boundary condition.This effectively reduces the required storage of unreduced coefficients by one column for the rest of the grid,and allows us to reduce to zero the first three columns of subsequent blocks.The functions red,pinvs,bksub can readily handle these cases with minor recoding,but each problem makes for a special case,and you will have to make the modifications as required. CITED REFERENCES AND FURTHER READING: London,R.A.,and Flannery,B.P.1982,Astrophysical Journal,vol.258,pp.260-269 Permission is Sample page http://w.nr.com or call 1-800-872-7423(North America only),orsend email to directcustserv@cambridge.org(outside North America). granted for internet users to make one paper copy for their Copyright (C)1988-1992 by Cambridge University Press.Programs Copyright(C)1988-1992 by Numerical Recipes from NUMERICAL RECIPES IN C:THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) Software
17.6 Handling Internal Boundary Conditions or Singular Points 787 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). the internal boundary condition. This effectively reduces the required storage of unreduced coefficients by one column for the rest of the grid, and allows us to reduce to zero the first three columns of subsequent blocks. The functions red, pinvs, bksub can readily handle these cases with minor recoding, but each problem makes for a special case, and you will have to make the modifications as required. CITED REFERENCES AND FURTHER READING: London, R.A., and Flannery, B.P. 1982, Astrophysical Journal, vol. 258, pp. 260–269