diff options
author | Karl Berry <karl@freefriends.org> | 2009-06-29 00:06:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-06-29 00:06:37 +0000 |
commit | d9b69c486ff463e30179a9e8bdacf6710f0ebc91 (patch) | |
tree | 1ff82edb1147b80fc710394e364298779bc5b4d1 /Build/source/utils/asymptote/base | |
parent | 8a2548cb37acbacd1a379a9771b3076788a210f0 (diff) |
asy 1.78
git-svn-id: svn://tug.org/texlive/trunk@13994 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/base')
-rw-r--r-- | Build/source/utils/asymptote/base/asy-kate.sh | 146 | ||||
-rw-r--r-- | Build/source/utils/asymptote/base/ode.asy | 125 | ||||
-rw-r--r-- | Build/source/utils/asymptote/base/three.asy | 2 | ||||
-rw-r--r-- | Build/source/utils/asymptote/base/three_arrows.asy | 8 |
4 files changed, 233 insertions, 48 deletions
diff --git a/Build/source/utils/asymptote/base/asy-kate.sh b/Build/source/utils/asymptote/base/asy-kate.sh new file mode 100644 index 00000000000..5f482b376d9 --- /dev/null +++ b/Build/source/utils/asymptote/base/asy-kate.sh @@ -0,0 +1,146 @@ +#!/bin/sh +echo '<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE language SYSTEM "language.dtd"> +<!-- based on asy-keywords.el and Highlighting file asymptote.xml by Christoph Hormann--> +<language version="1.0" kateversion="3.2.2" name="asymptote" section="Sources" extensions="*.asy" mimetype="text/x-asymptote" licence="LGPL" author="Carsten Brenner"> + +<highlighting> +' > asymptote.xml + +# 1. Change Name of lists in <\list> <list name="..."> +# 2. tail to get rid of the first lines +# 3. building the right line ending +# 4-5. kill linebreaks +# 6. change spaces into <\item><item> +# 7. Undo change (7.) in 'list name' +# 8. do some formatting + +cat asy-keywords.el | sed 's/^(.*\-\([^\-]*\)\-.*/\n<list name="\1"><item>/' | tail -14 | sed 's/ ))/<\/item><\/list>/' | tr '\n' '@' | sed 's/@//g' | sed 's/ /<\/item><item>/g' | sed 's/list<\/item><item>name/list name/g' | sed 's/></>\n</g' >> asymptote.xml + +echo ' +<contexts> + <context attribute="Normal Text" lineEndContext="#stay" name="Normal"> + <DetectSpaces /> + <RegExpr attribute="Preprocessor" context="Outscoped" String="#\s*if\s+0" beginRegion="Outscoped" firstNonSpace="true" /> + <DetectChar attribute="Preprocessor" context="Preprocessor" char="#" firstNonSpace="true" /> + <StringDetect attribute="Region Marker" context="Region Marker" String="//BEGIN" beginRegion="Region1" firstNonSpace="true" /> + <StringDetect attribute="Region Marker" context="Region Marker" String="//END" endRegion="Region1" firstNonSpace="true" /> + <keyword attribute="Keyword" context="#stay" String="keyword" /> + <keyword attribute="Extensions" context="#stay" String="extensions" /> + <keyword attribute="Function" context="#stay" String="function" /> + <keyword attribute="Data Type" context="#stay" String="type" /> + <keyword attribute="Constants" context="#stay" String="constants" /> + <keyword attribute="Variable" context="#stay" String="variable" /> + <HlCChar attribute="Char" context="#stay"/> + <DetectChar attribute="String" context="String" char="""/> + <DetectIdentifier /> + <Float attribute="Float" context="#stay"> + <AnyChar String="fF" attribute="Float" context="#stay"/> + </Float> + <HlCOct attribute="Octal" context="#stay"/> + <HlCHex attribute="Hex" context="#stay"/> + <Int attribute="Decimal" context="#stay"> + <StringDetect attribute="Decimal" context="#stay" String="ULL" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="LUL" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="LLU" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="UL" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="LU" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="LL" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="U" insensitive="TRUE"/> + <StringDetect attribute="Decimal" context="#stay" String="L" insensitive="TRUE"/> + </Int> + <IncludeRules context="##Doxygen" /> + <Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/> + <Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/> + <DetectChar attribute="Symbol" context="#stay" char="{" beginRegion="Brace1" /> + <DetectChar attribute="Symbol" context="#stay" char="}" endRegion="Brace1" /> + <AnyChar attribute="Symbol" context="#stay" String=":!%&()+,-/.*<=>?[]{|}~^;"/> + </context> + <context attribute="String" lineEndContext="#pop" name="String"> + <LineContinue attribute="String" context="#stay"/> + <HlCStringChar attribute="String Char" context="#stay"/> + <DetectChar attribute="String" context="#pop" char="""/> + </context> + <context attribute="Region Marker" lineEndContext="#pop" name="Region Marker"> + </context> + <context attribute="Comment" lineEndContext="#pop" name="Commentar 1"> + <DetectSpaces /> + <IncludeRules context="##Alerts" /> + <DetectIdentifier /> + </context> + <context attribute="Comment" lineEndContext="#stay" name="Commentar 2"> + <DetectSpaces /> + <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment"/> + <IncludeRules context="##Alerts" /> + <DetectIdentifier /> + </context> + <context attribute="Preprocessor" lineEndContext="#pop" name="Preprocessor"> + <LineContinue attribute="Preprocessor" context="#stay"/> + <RegExpr attribute="Preprocessor" context="Define" String="define.*((?=\\))"/> + <RegExpr attribute="Preprocessor" context="#stay" String="define.*"/> + <RangeDetect attribute="Prep. Lib" context="#stay" char=""" char1="""/> + <RangeDetect attribute="Prep. Lib" context="#stay" char="<" char1=">"/> + <IncludeRules context="##Doxygen" /> + <Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/> + <Detect2Chars attribute="Comment" context="Commentar/Preprocessor" char="/" char1="*"/> + </context> + <context attribute="Preprocessor" lineEndContext="#pop" name="Define"> + <LineContinue attribute="Preprocessor" context="#stay"/> + </context> + <context attribute="Comment" lineEndContext="#stay" name="Commentar/Preprocessor"> + <DetectSpaces /> + <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" /> + <DetectIdentifier /> + </context> + <context attribute="Comment" lineEndContext="#stay" name="Outscoped" > + <DetectSpaces /> + <IncludeRules context="##Alerts" /> + <DetectIdentifier /> + <DetectChar attribute="String" context="String" char="""/> + <IncludeRules context="##Doxygen" /> + <Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/> + <Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/> + <RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="Outscoped" firstNonSpace="true" /> + <RegExpr attribute="Preprocessor" context="#pop" String="#\s*(endif|else|elif)" endRegion="Outscoped" firstNonSpace="true" /> + </context> + <context attribute="Comment" lineEndContext="#stay" name="Outscoped intern"> + <DetectSpaces /> + <IncludeRules context="##Alerts" /> + <DetectIdentifier /> + <DetectChar attribute="String" context="String" char="""/> + <IncludeRules context="##Doxygen" /> + <Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/> + <Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/> + <RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="Outscoped" firstNonSpace="true"/> + <RegExpr attribute="Comment" context="#pop" String="#\s*endif" endRegion="Outscoped" firstNonSpace="true"/> + </context> + </contexts> + <itemDatas> + <itemData name="Char" defStyleNum="dsChar"/> + <itemData name="Comment" defStyleNum="dsComment"/> + <itemData name="Data Type" defStyleNum="dsDataType"/> + <itemData name="Decimal" defStyleNum="dsDecVal"/> + <itemData name="Extensions" defStyleNum="dsKeyword" color="#0095ff" selColor="#ffffff" bold="1" italic="0"/> + <itemData name="Float" defStyleNum="dsFloat"/> + <itemData name="Function" defStyleNum="dsFunction" /> + <itemData name="Hex" defStyleNum="dsBaseN"/> + <itemData name="Keyword" defStyleNum="dsKeyword"/> + <itemData name="Normal Text" defStyleNum="dsNormal"/> + <itemData name="Octal" defStyleNum="dsBaseN"/> + <itemData name="Prep. Lib" defStyleNum="dsOthers"/> + <itemData name="Preprocessor" defStyleNum="dsOthers"/> + <itemData name="Region Marker" defStyleNum="dsRegionMarker" /> + <itemData name="String Char" defStyleNum="dsChar"/> + <itemData name="String" defStyleNum="dsString"/> + <itemData name="Symbol" defStyleNum="dsNormal"/> + <itemData name="Variable" defStyleNum="dsOthers" /> + </itemDatas> + </highlighting> + <general> + <comments> + <comment name="singleLine" start="//" /> + <comment name="multiLine" start="/*" end="*/" region="Comment"/> + </comments> + <keywords casesensitive="1" /> + </general> + </language>' >> asymptote.xml diff --git a/Build/source/utils/asymptote/base/ode.asy b/Build/source/utils/asymptote/base/ode.asy index 643c56feec7..fe65f2f1c8e 100644 --- a/Build/source/utils/asymptote/base/ode.asy +++ b/Build/source/utils/asymptote/base/ode.asy @@ -1,24 +1,39 @@ real stepfactor=2.0; // Maximum dynamic step size adjustment factor. -struct RKTableau +struct coefficients { - int order; - real[] steps; + real[] factors; real[][] weights; real[] highOrderWeights; real[] lowOrderWeights; +} + +struct RKTableau +{ + int order; + real[] steps; + coefficients a; + void stepDependence(real h, real c, coefficients a) {} + real pgrow; real pshrink; + bool exponential; void operator init(int order, real[][] weights, real[] highOrderWeights, real[] lowOrderWeights=new real[], real[] steps=sequence(new real(int i) { - return sum(weights[i]);},weights.length)) { + return sum(weights[i]);},weights.length), + void stepDependence(real, real, coefficients)=null) { this.order=order; this.steps=steps; - this.weights=weights; - this.highOrderWeights=highOrderWeights; - this.lowOrderWeights=lowOrderWeights; + a.factors=array(steps.length+1,1); + a.weights=weights; + a.highOrderWeights=highOrderWeights; + a.lowOrderWeights=lowOrderWeights; + if(stepDependence != null) { + this.stepDependence=stepDependence; + exponential=true; + } pgrow=(order > 0) ? 1/order : 0; pshrink=(order > 1) ? 1/(order-1) : pgrow; } @@ -28,6 +43,13 @@ struct RKTableau RKTableau Euler=RKTableau(1,new real[][], new real[] {1}); +RKTableau E_Euler=RKTableau(1,new real[][], new real[] {1}, + new void (real h, real c, coefficients a) { + real x=-c*h; + a.factors[0]=exp(x); + a.highOrderWeights[0]=x != 0 ? expm1(x)/x : 1; + }); + // Second-Order Runge-Kutta RKTableau RK2=RKTableau(2,new real[][] {{1/2}}, new real[] {0,1}); @@ -50,12 +72,12 @@ RKTableau RK4=RKTableau(4,new real[][] {{1/2},{0,1/2},{0,0,1}}, new real[] {1/6,1/3,1/3,1/6}); // Fifth-Order Cash-Karp Runge-Kutta -RKTableau RK5CK=RKTableau(5,new real[][] {{1/5}, - {3/40,9/40}, - {3/10,-9/10,6/5}, - {-11/54,5/2,-70/27,35/27}, - {1631/55296,175/512,575/13824, - 44275/110592,253/4096}}, +RKTableau RK5=RKTableau(5,new real[][] {{1/5}, + {3/40,9/40}, + {3/10,-9/10,6/5}, + {-11/54,5/2,-70/27,35/27}, + {1631/55296,175/512,575/13824, + 44275/110592,253/4096}}, new real[] {37/378,0,250/621,125/594, 0,512/1771}, // 5th order new real[] {2825/27648,0,18575/48384,13525/55296, @@ -84,7 +106,7 @@ RKTableau RK5DP=RKTableau(5,new real[][] {{1/5}, new real[] {5179/57600,0,7571/16695,393/640, -92097/339200,187/2100,1/40}); // 4th order -real error(real error, real initial, real norm, real lowOrder, real diff) +real error(real error, real initial, real lowOrder, real norm, real diff) { if(initial != 0.0 && lowOrder != initial) { static real epsilon=realMin/realEpsilon; @@ -94,73 +116,89 @@ real error(real error, real initial, real norm, real lowOrder, real diff) return error; } -real adjust(real h, real error, real t, real tolmin, real tolmax, +real adjust(real h, real error, real t, real c, real tolmin, real tolmax, real dtmin, real dtmax, RKTableau tableau, bool verbose=true) { real dt=h; void report(real t) { - if(h != dt) - write("Time step changed from "+(string) dt+" to "+(string) h+" at t="+ - (string) t+"."); + if(h != dt) { + tableau.stepDependence(h,c,tableau.a); + if(verbose) + write("Time step changed from "+(string) dt+" to "+(string) h+" at t="+ + (string) t+"."); + } } if(error > tolmax) { h=max(h*max((tolmin/error)^tableau.pshrink,1/stepfactor),dtmin); - if(verbose) report(t); + report(t); return h; } if(error > 0 && error < tolmin) { h=min(h*min((tolmin/error)^tableau.pgrow,stepfactor),dtmax); - if(verbose) report(t+dt); + report(t+dt); } return h; } -// Integrate dy/dt=f(t,y) from a to b using initial conditions y, +// Integrate dy/dt+cy=f(t,y) from a to b using initial conditions y, // specifying either the step size h or the number of steps n. -real integrate(real y, real f(real t, real y), real a, real b=a, real h=0, - int n=0, bool dynamic=false, real tolmin=0, real tolmax=0, - real dtmin=0, real dtmax=realMax, RKTableau tableau, - bool verbose=false) +real integrate(real y, real c=0, real g(real t, real y), real a, real b=a, + real h=0, int n=0, bool dynamic=false, real tolmin=0, + real tolmax=0, real dtmin=0, real dtmax=realMax, + RKTableau tableau, bool verbose=false) { + real f(real t, real y)=(c == 0 || tableau.exponential) ? g : + new real(real t, real y) {return g(t,y)-c*y;}; + if(h == 0) { if(b == a) return y; if(n == 0) abort("Either n or h must be specified"); else h=(b-a)/n; } + + tableau.stepDependence(h,c,tableau.a); + real t=a; real f0; - bool fsal=tableau.lowOrderWeights.length > tableau.highOrderWeights.length; + if(tableau.a.lowOrderWeights.length == 0) dynamic=false; + bool fsal=dynamic && + (tableau.a.lowOrderWeights.length > tableau.a.highOrderWeights.length); if(fsal) f0=f(t,y); - if(tableau.lowOrderWeights.length == 0) dynamic=false; while(t < b) { real[] predictions={fsal ? f0 : f(t,y)}; for(int i=0; i < tableau.steps.length; ++i) predictions.push(f(t+h*tableau.steps[i], - y+h*dot(tableau.weights[i],predictions))); + tableau.a.factors[i]*y+h*dot(tableau.a.weights[i], + predictions))); - real highOrder=h*dot(tableau.highOrderWeights,predictions); + real highOrder=h*dot(tableau.a.highOrderWeights,predictions); + real Y=tableau.a.factors[tableau.steps.length]*y; if(dynamic) { real f1; if(fsal) { - f1=f(t+h,y+highOrder); + f1=f(t+h,Y+highOrder); predictions.push(f1); } - real lowOrder=h*dot(tableau.lowOrderWeights,predictions); + real lowOrder=h*dot(tableau.a.lowOrderWeights,predictions); real error; - error=error(error,y,y+highOrder,y+lowOrder,highOrder-lowOrder); + error=error(error,y,Y+lowOrder,Y+highOrder,highOrder-lowOrder); real dt=h; - h=adjust(h,error,t,tolmin,tolmax,dtmin,min(dtmax,b-t-h),tableau,verbose); + h=adjust(h,error,t,c,tolmin,tolmax,dtmin,min(dtmax,b-t-h),tableau,verbose); if(h >= dt) { t += dt; - y += highOrder; + y=Y+highOrder; f0=f1; } } else { t += h; - y += highOrder; + y=Y+highOrder; + } + real remain=b-t; + if(h > remain) { + h=remain; + tableau.stepDependence(h,c,tableau.a); } - h=min(h,b-t); if(t >= b || t+h == t) break; } return y; @@ -181,30 +219,31 @@ real[] integrate(real[] y, real[] f(real t, real[] y), real a, real b=a, real[] y=copy(y); real t=a; real[] f0; - bool fsal=tableau.lowOrderWeights.length > tableau.highOrderWeights.length; + if(tableau.a.lowOrderWeights.length == 0) dynamic=false; + bool fsal=dynamic && + (tableau.a.lowOrderWeights.length > tableau.a.highOrderWeights.length); if(fsal) f0=f(t,y); - if(tableau.lowOrderWeights.length == 0) dynamic=false; while(t < b) { real[][] predictions={fsal ? f0 : f(t,y)}; for(int i=0; i < tableau.steps.length; ++i) predictions.push(f(t+h*tableau.steps[i], - y+h*tableau.weights[i]*predictions)); + y+h*tableau.a.weights[i]*predictions)); - real[] highOrder=h*tableau.highOrderWeights*predictions; + real[] highOrder=h*tableau.a.highOrderWeights*predictions; if(dynamic) { real[] f1; if(fsal) { f1=f(t+h,y+highOrder); predictions.push(f1); } - real[] lowOrder=h*tableau.lowOrderWeights*predictions; + real[] lowOrder=h*tableau.a.lowOrderWeights*predictions; real error; for(int i=0; i < y.length; ++i) - error=error(error,y[i],y[i]+highOrder[i],y[i]+lowOrder[i], + error=error(error,y[i],y[i]+lowOrder[i],y[i]+highOrder[i], highOrder[i]-lowOrder[i]); real dt=h; - h=adjust(h,error,t,tolmin,tolmax,dtmin,min(dtmax,b-t-h),tableau,verbose); + h=adjust(h,error,t,0,tolmin,tolmax,dtmin,min(dtmax,b-t-h),tableau,verbose); if(h >= dt) { t += dt; y += highOrder; diff --git a/Build/source/utils/asymptote/base/three.asy b/Build/source/utils/asymptote/base/three.asy index d454d032b23..d42ea928b16 100644 --- a/Build/source/utils/asymptote/base/three.asy +++ b/Build/source/utils/asymptote/base/three.asy @@ -1956,7 +1956,7 @@ draw=new void(frame f, path3 g, material p=currentpen, if(settings.thick) { real width=linewidth(q); if(width > 0) { - surface s=tube(g,width); + surface s=tube(g,width,p.granularity); int L=length(g); if(L >= 0) { if(!cyclic(g)) { diff --git a/Build/source/utils/asymptote/base/three_arrows.asy b/Build/source/utils/asymptote/base/three_arrows.asy index 78ee56d9f04..418065e5e1e 100644 --- a/Build/source/utils/asymptote/base/three_arrows.asy +++ b/Build/source/utils/asymptote/base/three_arrows.asy @@ -48,7 +48,7 @@ void bend(surface s, path3 g, real L) } } -void render(path3 s, void f(path3, real)) +void render(path3 s, real granularity=tubegranularity, void f(path3, real)) { static int maxdepth=ceil(-log(realEpsilon)/log(2))+1; void Split(triple z0, triple c0, triple c1, triple z1, real t0=0, real t1=1, @@ -62,7 +62,7 @@ void render(path3 s, void f(path3, real)) --depth; for(int i=0; i <= nintervals; ++i) { R=min(R,radius(z0,c0,c1,z1,i/nintervals)); - if(S > max(tubegranularity*R,fuzz)) { + if(S > max(granularity*R,fuzz)) { triple m0=0.5*(z0+c0); triple m1=0.5*(c0+c1); triple m2=0.5*(c1+z1); @@ -82,7 +82,7 @@ void render(path3 s, void f(path3, real)) Split(point(s,0),postcontrol(s,0),precontrol(s,1),point(s,1)); } -surface tube(path3 g, real width) +surface tube(path3 g, real width, real granularity=tubegranularity) { surface tube; real r=0.5*width; @@ -97,7 +97,7 @@ surface tube(path3 g, real width) triple u=point(g,i+1)-v; tube.append(shift(v)*align(unit(u))*scale(r,r,abs(u))*unitcylinder); } else { - render(subpath(g,i,i+1),new void(path3 q, real) { + render(subpath(g,i,i+1),granularity,new void(path3 q, real) { real L=arclength(q); surface segment=scale(r,r,L)*unitcylinder; bend(segment,q,L); |