form-fields.scm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. ;;;; 1Form fields
  21. ;;; A form-field of rank n is an operator that takes n vector fields
  22. ;;; to a real-valued function on the manifold. A 1form field takes a
  23. ;;; single vector field.
  24. (define (form-field? fop)
  25. (and (operator? fop)
  26. (eq? (operator-subtype fop) wedge)))
  27. (define (1form-field? fop)
  28. (and (form-field? fop) (= (get-rank fop) 1)))
  29. ;;; 1form fields multiply by wedge.
  30. ;;; (See wedge.scm for definition of get-rank.)
  31. (define* (procedure->1form-field fp #:optional name)
  32. (if (default-object? name)
  33. (set! name 'unnamed-1form-field))
  34. (let ((the-field (make-operator fp name wedge)))
  35. (declare-argument-types! the-field (list vector-field?))
  36. the-field))
  37. ;;;; FBE comment out
  38. ;; ;;; Dummy... forward reference so I can define dx, dy before wedge.
  39. ;; (define (wedge f1 f2)
  40. ;; (error "Wedge not yet defined"))
  41. (define (ff:zero vf) zero-manifold-function)
  42. (define (ff:zero-like op)
  43. (assert (form-field? op) "ff:zero-like")
  44. (make-op ff:zero
  45. 'ff:zero
  46. (operator-subtype op)
  47. (operator-arity op)
  48. (operator-optionals op)))
  49. (define %calculus-form-fields-dummy-1
  50. (assign-operation 'zero-like ff:zero-like form-field?))
  51. (define (ff:zero? ff)
  52. (assert (form-field? ff) "ff:zero?")
  53. (eq? (operator-procedure ff) ff:zero))
  54. (define %calculus-form-fields-dummy-2
  55. (assign-operation 'zero? ff:zero? form-field?))
  56. ;;; A 1form is specified by a function that gives components, in a
  57. ;;; down tuple, relative to a coordinate system.
  58. (define* ((1form-field-procedure components coordinate-system) vf)
  59. (define (internal vf)
  60. (assert (vector-field? vf))
  61. (compose (* components
  62. (vector-field->components vf coordinate-system))
  63. (coordinate-system '->coords)))
  64. (s:map/r internal vf))
  65. (define* (components->1form-field components coordinate-system #:optional name)
  66. (if (default-object? name) (set! name `(1form-field ,components)))
  67. (procedure->1form-field
  68. (1form-field-procedure components coordinate-system)
  69. name))
  70. ;;; We can extract the components function for a form, given a
  71. ;;; coordinate system.
  72. (define (1form-field->components form coordinate-system)
  73. (assert (form-field? form) "Bad form field: 1form-field->components")
  74. (let ((X (coordinate-system->vector-basis coordinate-system)))
  75. (compose (form X) (coordinate-system '->point))))
  76. ;;; It is often useful to construct a 1form field
  77. (define (literal-1form-field name coordinate-system)
  78. (let ((n (coordinate-system 'dimension)))
  79. (let ((function-signature
  80. (if (fix:= n 1) (-> Real Real) (-> (UP* Real n) Real))))
  81. (let ((components
  82. (s:generate n 'down
  83. (lambda (i)
  84. (literal-function (string->symbol
  85. (string-append
  86. (symbol->string name)
  87. "_"
  88. (number->string i)))
  89. function-signature)))))
  90. (components->1form-field components coordinate-system name)))))
  91. ;;; To get the elements of a coordinate basis for the 1-form fields
  92. (define* ((coordinate-basis-1form-field-procedure coordinate-system . i) vf)
  93. (define (internal vf)
  94. (assert (vector-field? vf)
  95. "Bad vector field: coordinate-basis-1form-field")
  96. (vf (compose (apply component i) (coordinate-system '->coords))))
  97. (s:map/r internal vf))
  98. (define (coordinate-basis-1form-field coordinate-system name . i)
  99. (procedure->1form-field
  100. (apply coordinate-basis-1form-field-procedure coordinate-system i)
  101. name))
  102. #|
  103. (define (coordinate-system->1form-basis coordinate-system)
  104. (s:map (lambda (chain)
  105. (apply coordinate-basis-1form-field
  106. coordinate-system
  107. `(w ,@chain)
  108. chain))
  109. (coordinate-system 'access-chains)))
  110. |#
  111. (define (coordinate-system->1form-basis coordinate-system)
  112. (coordinate-system 'coordinate-basis-1form-fields))
  113. #|
  114. (define ((coordinate-system->1form-basis-procedure coordinate-system) vf)
  115. (vf (coordinate-system '->coords)))
  116. |#
  117. ;;; Given component functions defined on manifold points and a 1-form
  118. ;;; basis, to produce the 1-form field as a linear combination.
  119. (define (basis-components->1form-field components 1form-basis)
  120. (procedure->1form-field
  121. (lambda (v)
  122. (* components (1form-basis v)))))
  123. (define (1form-field->basis-components w vector-basis)
  124. (s:map/r w vector-basis))
  125. ;;; This is one of the two incompatible definitions of "differential".
  126. ;;; This differential is a special case of exterior derivative.
  127. ;;; The other one appears in maps.scm.
  128. (define (function->1form-field f)
  129. (define (internal v)
  130. (assert (vector-field? v))
  131. (lambda (m) ((v f) m)))
  132. (assert (function? f))
  133. (procedure->1form-field
  134. (lambda (v) (s:map/r internal v))
  135. `(d ,(diffop-name f))))
  136. (define differential-of-function function->1form-field)
  137. #|
  138. (install-coordinates R3-rect (up 'x 'y 'z))
  139. (define mr ((R3-rect '->point) (up 'x0 'y0 'z0)))
  140. (define a-1form
  141. (components->1form-field
  142. (down (literal-function 'ax (-> (UP* Real) Real))
  143. (literal-function 'ay (-> (UP* Real) Real))
  144. (literal-function 'az (-> (UP* Real) Real)))
  145. R3-rect))
  146. (define a-vector-field
  147. (components->vector-field
  148. (up (literal-function 'vx (-> (UP* Real) Real))
  149. (literal-function 'vy (-> (UP* Real) Real))
  150. (literal-function 'vz (-> (UP* Real) Real)))
  151. R3-rect))
  152. (pec ((a-1form a-vector-field) mr))
  153. #| Result:
  154. (+ (* (vx (up x0 y0 z0)) (ax (up x0 y0 z0)))
  155. (* (vy (up x0 y0 z0)) (ay (up x0 y0 z0)))
  156. (* (vz (up x0 y0 z0)) (az (up x0 y0 z0))))
  157. |#
  158. (pec ((1form-field->components a-1form R3-rect) (up 'x0 'y0 'z0)))
  159. #| Result:
  160. (down (ax (up x0 y0 z0)) (ay (up x0 y0 z0)) (az (up x0 y0 z0)))
  161. |#
  162. (install-coordinates R3-cyl (up 'r 'theta 'zeta))
  163. (pec ((1form-field->components a-1form R3-cyl) (up 'r0 'theta0 'z0)))
  164. #| Result:
  165. (down
  166. (+ (* (sin theta0) (ay (up (* r0 (cos theta0)) (* r0 (sin theta0)) z0)))
  167. (* (cos theta0) (ax (up (* r0 (cos theta0)) (* r0 (sin theta0)) z0))))
  168. (+ (* -1 r0 (sin theta0) (ax (up (* r0 (cos theta0)) (* r0 (sin theta0)) z0)))
  169. (* r0 (cos theta0) (ay (up (* r0 (cos theta0)) (* r0 (sin theta0)) z0))))
  170. (az (up (* r0 (cos theta0)) (* r0 (sin theta0)) z0)))
  171. |#
  172. |#
  173. #|
  174. (define mr ((R3-rect '->point) (up 'x0 'y0 'z0)))
  175. (define mp ((R3-cyl '->point) (up 'r0 'theta0 'z0)))
  176. ((dx d/dx) mr)
  177. ;Value 1
  178. ((dx d/dx) mp)
  179. ;Value 1
  180. (pec ((1form-field->components dr R3-rect) (up 'x0 'y0 'z0)))
  181. #| Result:
  182. (down (/ x0 (sqrt (+ (expt x0 2) (expt y0 2))))
  183. (/ y0 (sqrt (+ (expt x0 2) (expt y0 2))))
  184. 0)
  185. |#
  186. (pec ((1form-field->components dtheta R3-rect) (up 'x0 'y0 'z0)))
  187. #| Result:
  188. (down (/ (* -1 y0) (+ (expt x0 2) (expt y0 2)))
  189. (/ x0 (+ (expt x0 2) (expt y0 2)))
  190. 0)
  191. |#
  192. (pec (((+ (* 'w_0 dr) (* 'w_1 dtheta)) (+ (* 'V^0 d/dx) (* 'V^1 d/dy))) mp))
  193. #| Result:
  194. (+ (* V^0 w_0 (cos theta0))
  195. (* V^1 w_0 (sin theta0))
  196. (/ (* -1 V^0 w_1 (sin theta0)) r0)
  197. (/ (* V^1 w_1 (cos theta0)) r0))
  198. |#
  199. (pec
  200. (((components->1form-field (1form-field->components
  201. (+ (* 'w_0 dr) (* 'w_1 dtheta))
  202. R3-rect)
  203. R3-rect)
  204. (+ (* 'V^0 d/dx) (* 'V^1 d/dy)))
  205. mp))
  206. #| Result:
  207. (+ (* V^0 w_0 (cos theta0))
  208. (* V^1 w_0 (sin theta0))
  209. (/ (* -1 V^0 w_1 (sin theta0)) r0)
  210. (/ (* V^1 w_1 (cos theta0)) r0))
  211. |#
  212. (define counter-clockwise (- (* x d/dy) (* y d/dx)))
  213. (define outward (+ (* x d/dx) (* y d/dy)))
  214. (pec ((dx counter-clockwise) mr))
  215. #| Result:
  216. (* -1 y0)
  217. |#
  218. (pec ((dx outward) mr))
  219. #| Result:
  220. x0
  221. |#
  222. (pec ((dr counter-clockwise) mp))
  223. #| Result:
  224. 0
  225. |#
  226. (pec ((dr outward) mp))
  227. #| Result:
  228. r0
  229. |#
  230. (pec ((dr outward) mr))
  231. #| Result:
  232. (sqrt (+ (expt x0 2) (expt y0 2)))
  233. |#
  234. (pec (((* x dy) (+ (* 'u d/dx) (* 'v d/dy))) mr))
  235. #| Result:
  236. (* v x0)
  237. |#
  238. (pec ((dr d/dr) ((R3-rect '->point) (up 'x^0 'y^0 'z^0))))
  239. #| Result:
  240. 1
  241. |#
  242. (pec ((dr d/dtheta) ((R3-rect '->point) (up 'x^0 'y^0 'z^0))))
  243. #| Result:
  244. 0
  245. |#
  246. (pec ((dtheta d/dr) ((R3-rect '->point) (up 'x^0 'y^0 'z^0))))
  247. #| Result:
  248. 0
  249. |#
  250. (pec ((dtheta d/dtheta) ((R3-rect '->point) (up 'x^0 'y^0 'z^0))))
  251. #| Result:
  252. 1
  253. |#
  254. |#