conlaw3.red 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. comment consider many solutions of crack
  2. ;
  3. % CONLAW version 3, to calculate conservation laws of systems of PDEs
  4. % by calculating characteristic functions and conserved currents
  5. % by Thomas Wolf, September 1997
  6. %----------------------------------------------------------------------
  7. symbolic fluid '(print_ logoprint_ potint_ facint_ adjust_fnc)$
  8. %-------------
  9. algebraic procedure conlaw3(problem,runmode)$
  10. begin
  11. scalar contrace,eqlist,ulist,xlist,dequ,cllist,pllist,
  12. sb,densord,flist,eqord,maxord,dulist,revdulist,vl,expl,
  13. deplist,e1,e2,e3,n,h1,h2,h3,h4,h5,h6,h7,h8,condi,soln,
  14. adjust_old,potold,adjustold,udens,gensepold,inequ0,
  15. inequ,logoold,treqlist,fl,facold,u,lhslist,cpu,gc,
  16. cpustart,gcstart,found,cf0,rtnlist,solns,nontriv,
  17. extraline,cf,cfcopy,nx,nde,mindensord,mindensord0,
  18. maxdensord;
  19. lisp <<adjustold:=adjust_fnc; adjust_fnc:=t;
  20. logoold:=logoprint_; logoprint_:=t;
  21. potold:=potint_; potint_:=t;
  22. facold:=facint_; facint_:=1000>>;
  23. cpustart:=lisp time()$ gcstart:=lisp gctime()$
  24. % contrace:=t;
  25. %--- extracting input data
  26. eqlist:= maklist first problem;
  27. ulist := maklist second problem;
  28. xlist:= maklist third problem;
  29. nx:=length xlist;
  30. nde:=length eqlist;
  31. if contrace then write"eqlist=",eqlist,
  32. " ulist=",ulist," xlist=",xlist;
  33. mindensord:=part(runmode,1)$
  34. maxdensord:=part(runmode,2)$
  35. expl :=part(runmode,3)$
  36. flist :=part(runmode,4)$
  37. inequ0 :=part(runmode,5)$
  38. problem:=runmode:=0;
  39. %--- initial printout
  40. lisp(if logoprint_ then <<terpri()$
  41. write "--------------------------------------------------",
  42. "------------------------"$ terpri()$terpri()$
  43. write "This is CONLAW3 - a program for calculating conservation",
  44. " laws of DEs"; terpri()
  45. >> else terpri());
  46. if nde = 1
  47. then write "The DE under investigation is :"
  48. else write "The DEs under investigation are :";
  49. for each e1 in eqlist do write e1;
  50. write "for the function(s): ",ulist;
  51. write"======================================================"$
  52. %--- lhslist is the list of derivatives to substitute
  53. %--- is needed in order not to let the Q depend on them and their deriv.
  54. eqlist:=reverse eqlist;
  55. lhslist:={};
  56. for each h1 in eqlist do lhslist:=cons(lhs h1,lhslist);
  57. %--- bringing eqlist and ulist in line
  58. h1:={}; h2:={};
  59. if nde neq length ulist then n:=t else
  60. for each e1 in eqlist do <<
  61. e2:=part(lhs e1,1);
  62. if freeof(ulist,e2) then n:=t
  63. else h1:=cons(e2,h1);
  64. h2:=cons(lhs e1 - rhs e1, h2)
  65. >>;
  66. if n then
  67. rederr("The lists of equations and functions are not consistent!")
  68. else <<ulist:=h1; eqlist:=h2>>;
  69. if contrace then write"ulist=",ulist," eqlist=",eqlist;
  70. %--- initializations to be done only once
  71. rtnlist:={};
  72. %------ the list of parameters of the equation to be determined
  73. paralist:={};
  74. for each e1 in flist do
  75. if not freeof(eqlist,e1) then paralist:=cons(e1,paralist);
  76. %------ determination of the order of the input equations
  77. eqord:=0;
  78. for each e1 in eqlist do
  79. for each e2 in ulist do <<
  80. h1:=totdeg(e1,e2);
  81. if h1>eqord then eqord:=h1
  82. >>;
  83. h3:=eqord;
  84. mindensord0:=mindensord$
  85. for n:=1:nde do <<
  86. h1:=mkid(q_,n);
  87. if not lisp(null get(mkid('q_,n),'avalue)) then <<
  88. for each e2 in ulist do <<
  89. h2:=totdeg(h1,e2);
  90. if h2>eqord then eqord:=h2;
  91. if h2>mindensord then mindensord:=h2
  92. >>;
  93. cf0:=t;
  94. >>
  95. >>;
  96. for n:=1:nx do <<
  97. % if the index of p_ should be a number then use n instead of h4
  98. h4:=lisp(reval algebraic(part(xlist,n)));
  99. h1:=mkid(p_,h4);
  100. if not lisp(null get(mkid('p_,h4),'avalue)) then <<
  101. for each e2 in ulist do <<
  102. h2:=totdeg(h1,e2);
  103. if h2>eqord then eqord:=h2;
  104. if (h2>=h3) and (mindensord<=h2) then mindensord:=h2+1
  105. >>;
  106. cf0:=t;
  107. >>
  108. >>;
  109. if maxdensord<mindensord then maxdensord:=mindensord;
  110. if contrace then write"eqord=",eqord," cf0=",cf0;
  111. %------ all transformations into jet-space
  112. sb:=subdif1(xlist,ulist,eqord)$
  113. if contrace then write"sb=",sb;
  114. treqlist:=eqlist;
  115. for each e1 in sb do treqlist:=sub(e1,treqlist);
  116. for each e1 in sb do lhslist:=sub(e1, lhslist);
  117. if contrace then write"treqlist=",treqlist,
  118. " lhslist=",lhslist;
  119. if cf0 then
  120. for n:=1:nde do <<
  121. h1:=mkid(q_,n);
  122. if not lisp(null get(mkid('q_,n),'avalue)) then <<
  123. for each e1 in sb do h1:=sub(e1,h1);
  124. lisp(mkid('q_,n)):=h1;
  125. >>
  126. >>;
  127. if cf0 then
  128. for n:=1:nx do <<
  129. % if the index of p_ should be a number then use n instead of h4
  130. h4:=lisp(reval algebraic(part(xlist,n)));
  131. h1:=mkid(p_,h4);
  132. if not lisp(null get(mkid('p_,h4),'avalue)) then <<
  133. for each e1 in sb do h1:=sub(e1,h1);
  134. lisp(mkid('p_,h4)):=h1;
  135. >>
  136. >>;
  137. for each e1 in sb do inequ0:=sub(e1,inequ0);
  138. %--- investigate conservation laws of increasing order
  139. for densord:=mindensord:maxdensord do <<
  140. nodepnd ulist;
  141. cpu:=lisp time()$ gc:=lisp gctime()$
  142. if cf0 then
  143. lisp<<write"A special ansatz of order ",densord,
  144. " for the characteristic"$terpri()$
  145. write"function(s) is investigated.";terpri()
  146. >> else
  147. lisp<<
  148. write"Currently conservation laws with characteristic";
  149. terpri();
  150. write"function(s) of order ",densord," are determined";
  151. terpri();
  152. write"======================================================"$
  153. >>;
  154. %--- repeated initializations
  155. %--- maxord is maximal derivative in condition
  156. maxord:=if eqord>densord then eqord
  157. else densord;
  158. if contrace then write"maxord=",maxord;
  159. if {}=fargs first ulist then
  160. for each e1 in ulist do depnd(e1,{xlist});
  161. sb:=subdif1(xlist,ulist,maxord)$
  162. nodepnd ulist;
  163. if contrace then write"sb=",sb;
  164. dulist:=ulist . reverse for each e1 in sb collect
  165. for each e2 in e1 collect rhs e2;
  166. sb:=0;
  167. revdulist:=reverse dulist; % dulist with decreasing order
  168. udens:=part(dulist,densord+1); % derivatives of order densord
  169. vl:=for each e1 in dulist join e1;
  170. if contrace then write"vl=",vl," udens=",udens;
  171. if not flist then fl:={}
  172. else fl:=flist;
  173. %--- initializing characteristic functions cf, the list of functions fl
  174. %--- the conserved current pl and the condition condi
  175. condi:=0;
  176. deplist:=ulist . for h3:=1:densord collect
  177. listdifdif2(lhslist,part(dulist,h3+1));
  178. if expl then deplist:=xlist . deplist;
  179. deplist:=reverse deplist;
  180. cf:={};
  181. for n:=1:nde do <<
  182. h1:=mkid(q_,n);
  183. if lisp(null get(mkid('q_,n),'avalue)) then <<
  184. nodepnd({h1});
  185. depnd(h1, deplist);
  186. fl:=cons(h1,fl);
  187. >>;
  188. cf:=cons(h1,cf);
  189. condi:=condi+h1*part(treqlist,n);
  190. >>;
  191. cf:=reverse cf$
  192. deplist:=for h3:=0:(maxord-1) collect part(dulist,h3+1);
  193. if expl then deplist:=xlist . deplist;
  194. deplist:=reverse deplist;
  195. pl:={};
  196. for n:=1:nx do <<
  197. % if the index of p_ should be a number then use n instead of h4
  198. h4:=lisp(reval algebraic(part(xlist,n)));
  199. h1:=mkid(p_,h4);
  200. if lisp(null get(mkid('p_,h4),'avalue)) then <<
  201. nodepnd({h1});
  202. depnd(h1, deplist);
  203. fl:=h1 . fl;
  204. >>;
  205. pl:=cons(h1,pl);
  206. condi:=condi-totdif(h1,h4,n,dulist)
  207. >>;
  208. sb:=0;
  209. if contrace then write"fl=",fl," cf=",cf," pl=",pl;
  210. if contrace then lisp (write" depl*=",depl!*);
  211. if contrace then write"condi=",condi;
  212. vl:=append(vl,xlist); % now the full list
  213. inequ:=inequ0;
  214. %--- inequ is to stop crack if order of cf is too low
  215. if (densord neq 0) and
  216. ((cf0=nil) or (mindensord0 neq 0)) then <<
  217. % for the investigation to stop if
  218. % cf is independent of highest order derivatives
  219. dequ:=0;
  220. for each e1 in cf do <<
  221. h1:=udens;
  222. while h1 neq {} do <<
  223. dequ:=dequ+df(e1,first h1)*(lisp gensym());
  224. h1:=rest h1
  225. >>;
  226. >>;
  227. inequ:=cons(dequ,inequ)
  228. >>;
  229. if contrace then write"inequ=",inequ;
  230. %--- freeing some space
  231. sb:=dulist:=revdulist:=deplist:=e1:=e2:=e3:=
  232. n:=h1:=h2:=h3:=soln:=u:=dequ:=0;
  233. %--- the real calculation
  234. if lisp(!*time) then
  235. write "time to formulate condition: ", lisp time() - cpu,
  236. " ms GC time : ", lisp gctime() - gc," ms"$
  237. solns:=crack({condi},inequ,fl,vl);
  238. %--- postprocessing
  239. lisp terpri()$
  240. pllist:={};
  241. cllist:={};
  242. found:=nil;
  243. while solns neq {} do << % for each solution (if param. are determ.)
  244. soln:=first solns;
  245. solns:=rest solns;
  246. condi:=first soln;
  247. % filtering out conservation laws found in the previous run
  248. cfcopy:=sub(second soln,cf);
  249. % any non-trivial conservation law?
  250. h1:=0;
  251. for each h2 in cfcopy do if h2 neq 0 then h1:=1;
  252. if h1 neq 0 then <<
  253. pl:=sub(second soln,pl);
  254. if contrace then write"cfcopy=",cfcopy," pl=",pl;
  255. h1:=third soln;
  256. if contrace then write"third soln=",h1;
  257. fl:={};
  258. h2:={};
  259. for each e1 in h1 do <<
  260. if not freeof(condi,e1) then fl:=cons(e1,fl);
  261. % fl to output remaining conditions later
  262. if freeof(paralist,e1) then h2:=cons(e1,h2)
  263. >>;
  264. h1:=parti_fn(h2,condi)$
  265. if contrace then write"h1(partitioned)=",h1;
  266. extraline:=nil;
  267. while h1 neq {} do << % for each potential conservation law
  268. % h1 is the list of lists of constants/functions
  269. % depending on each other
  270. h2:=first h1;h1:=rest h1;
  271. if contrace then write"h2=",h2;
  272. if contrace then write"cfcopy=",cfcopy;
  273. nontriv:=nil;
  274. %--- is the constant/function in the characteristic functions?
  275. h3:=for each e2 in cfcopy collect <<
  276. e3:=for each e1 in h2 sum fdepterms(e2,e1);
  277. if e3 neq 0 then nontriv:=t;
  278. e3
  279. >>;
  280. if nontriv then <<
  281. for each e1 in h2 do
  282. if fargs e1 neq {} then lisp <<
  283. write"The function "$
  284. fctprint list reval e1$
  285. write" is not constant!";
  286. extraline:=t;
  287. terpri()
  288. >>;
  289. %--- the currant
  290. h4:=reverse for each e2 in pl collect
  291. for each e1 in h2 sum fdepterms(e2,e1);
  292. if contrace then write"h3-1=",h3," h4-1=",h4;
  293. sb:=absorbconst(h3,h2)$
  294. if (sb neq nil) and (sb neq 0) then <<
  295. h3:=sub(sb,h3);
  296. h4:=sub(sb,h4)
  297. >>;
  298. if contrace then write"h3-2=",h3," h4-2=",h4;
  299. if (length(h2)=1) and (fargs first h2 = {}) then <<
  300. e1:=first h2;
  301. h4:=sub(e1=1,h4);
  302. h3:=sub(e1=1,h3)
  303. >>;
  304. h5:=udens;
  305. if (densord > 0) and
  306. ((cf0=nil) or (mindensord0 neq 0)) then
  307. while (h5 neq {}) and freeof(h3,first h5) do h5:=rest h5;
  308. if h5 neq {} then << % h3 is of order densord
  309. cllist:=cons(h3,cllist);
  310. pllist:=cons(h4,pllist)
  311. >>
  312. >>
  313. >>;
  314. if condi neq {} then <<
  315. write"There are remaining conditions: ",
  316. condi;
  317. lisp <<
  318. write"for the functions: ";
  319. fctprint cdr reval algebraic fl;terpri();
  320. write"Corresponding CLs might not be shown below as they";
  321. terpri()$write"could be of too low order.";terpri()>>;
  322. extraline:=t;
  323. >>;
  324. if extraline then lisp <<
  325. write"======================================================"$
  326. terpri()
  327. >>;
  328. for each e1 in ulist do depnd(e1,{xlist});
  329. if contrace then write"cllist2=",cllist," pllist2=",pllist$
  330. on evallhseqp;
  331. sb:=subdif1(xlist,ulist,maxord)$
  332. sb:=for each e1 in sb join
  333. for each e2 in e1 collect(rhs e2 = lhs e2);
  334. if contrace then write"sb=",sb$
  335. off evallhseqp;
  336. cllist:=sub(sb,cllist);
  337. if contrace then write"cllist3=",cllist$
  338. pllist:=sub(sb,pllist);
  339. if contrace then write"pllist3=",pllist$
  340. if nx=2 then
  341. pllist:=simppl(pllist,ulist,first xlist,second xlist)$
  342. if contrace then <<
  343. write"cllist3=",cllist;
  344. write"pllist3=",pllist;
  345. write"eqlist=",eqlist;
  346. write"xlist=",xlist
  347. >>;
  348. while pllist neq {} do <<
  349. found:=t;
  350. write"Conservation law:";
  351. h2:=first pllist;
  352. h3:=first cllist;
  353. rtnlist:=cons({h3,h2},rtnlist);
  354. %--- conditions on parameters
  355. if paralist neq {} then
  356. for each e2 in second soln do
  357. if not freeof(paralist,lhs e2) then
  358. <<write e2,",";lisp(terpri())>>$
  359. %--- the conservation laws
  360. h4:=eqlist;
  361. if paralist then h4:=sub(second soln,h4);
  362. n:=length h4$
  363. while h3 neq {} do <<
  364. if length h3 < n then write "+"$
  365. write"( ",first h3," ) * ( ",first h4," )"$
  366. h3:=rest h3; h4:=rest h4
  367. >>$
  368. write" = "$
  369. h4:=xlist$
  370. n:=length h4$
  371. while h2 neq {} do <<
  372. if length h2 < n then write "+"$
  373. write"df( ",first h2,", ",first h4," )"$
  374. h2:=rest h2;
  375. h4:=rest h4
  376. >>;
  377. write"======================================================"$
  378. pllist:=rest pllist;
  379. cllist:=rest cllist;
  380. >>$
  381. >>;
  382. >>;
  383. if found=nil then <<
  384. write"There is no conservation law of this order.";
  385. write"======================================================"$
  386. >>
  387. >>; % for densord:=mindensord:maxdensord
  388. if fargs(first ulist)={} then
  389. for each e1 in ulist do depnd(e1,{xlist});
  390. if lisp(!*time) then
  391. write "time to run conlaw3: ", lisp time() - cpustart,
  392. " ms GC time : ", lisp gctime() - gcstart," ms"$
  393. lisp <<adjust_fnc:=adjustold;
  394. logoprint_:=logoold;
  395. potint_:=potold;
  396. facint_:=facold>>;
  397. return rtnlist
  398. end$ % of conlaw3
  399. end$