powered by NetLogo

view/download model file: 2dflow03.nlogo

NOTE FROM RALPH

This model for 2D flows is adapted from Vector Field.nlogo by Uri Wilensky
by changing the definition of the field only.

In this model, 2dflow02, his equations (expressed in the notation of
Dynamics, the Geometry of Behavior) are:
x' = y
y' = -x

We now replace these by the cusp scheme. This is a two-parameter family
of gradient vectorfields in the line:
x' = x^3 + a * x + b
with control parameters a and b.
Hre we follow Poston and Setewart. p. 174.
We will embed this into a family of
gradient vectorfields in the plane, by adjoining the equation:
y' = -y
The two parameters may be controlled by the sliders on the interface.

Try drawing the attractor and basin portrait with a = -1000, and several
values of b between -15,000 and +15,000. In each case, how many attractors
and basins to you find?

Uri's original info follows without change.
=============================================================================
WHAT IS IT?

This is a mathematical model that demonstrates abstract vector fields and integral curves.

Generally speaking, a field is a "region in which a body experiences a force as the result of the presence of some other body or bodies. A field is thus a method of representing the way in which bodies are able to influence each other. For example, a body that has mass is surrounded by a region in which another body that has mass experiences a force tending to draw the two bodies together.... The strength of any field can be described as the ratio of the force experienced by a small appropriate specimen to the relevant property of that specimen, e.g. force/mass for the gravitational field" (Oxford Minidictionary of Physics).

By 'abstract vector fields' we mean that this model is not committed to any specific type of force, such as gravity or magnetism. Rather, it simulates a general field, in which some focal property of influence affects a "small appropriate specimen", or particle, placed in the field.

Normally, if you look at a field with bare eyes, you will not necessarily see the forces. For instance, if you drop an apple it falls down, even though you cannot see the gravitational force. The apple is an object in the gravitational field. You saw how it behaved so you could guess that there is some force that made it go down. Humans do not perceive (visually) forces of gravitation or electro-magnetic forces. However, in a model, we can use little arrows (vectors) to show where, how forceful, and in which direction there are forces in this field.


HOW IT WORKS

In this model, the field is plotted using vector graphics: green streaks are individual vectors with yellow turtles serving as arrowheads. The length of each vector is roughly proportional to the magnitude of the vector field at each point. In this model, it is just the distance from the origin: The further away from the origin, the larger the vector. Also, all vectors are aimed clockwise along tangents to circles centered on the origin.

The vectors show you in what direction and how forcefully an appropriate specimen -- here, a 'particle' -- will be "knocked about" once it is placed the field. Once the particle is "knocked" to a new location, it will be knocked yet again by the force there (represented by the vector). Actually, it being "knocked about" continuously, but in this simulation, the "knock" occurs at discrete points in the field. Since the particle does not use up the forces, it will keep being knocked about. The path the particle takes is called its 'trajectory.' You will be able to track this trajectory because the particle will leave a red trail behind it as it moves along its trajectory. Trajectories in vector fields are called 'integral curves.'

Even though behavior of particles can be interesting and possibly unanticipated, owing to forces not being distributed uniformly in the field, or some other factor, we have chosen, for clarity, a vector field with a logical and consistent relation between location in space and size/orientation of the force. The vector field chosen for this particular model is

    - y d/dx  +  x d/dy

Ideally, in the particular force field modeled here, the particle trajectories should be concentric circles (that is, the particle should go round and round along the same circular trajectory).


HOW TO USE IT

SETUP: Clears the screen and computes the vector field.
PLACE-PARTICLES: Puts the program into the mode in which you can position red test-particles by clicking anywhere in the graphics window.
GO: Runs the simulation continuously to show the integral curves.


THINGS TO NOTICE

Notice that the vectors grow in length as you move away from the origin. What effect do short vectors have on a particle? Long vectors?

The way this model is programmed, each particle moves some finite amount before calculating its new heading. Therefore, the particles do not turn as much as they would if their headings were continuously recalculated. This causes their trajectories to spiral slowly outward. (You have to let the model run for a while before this becomes apparent.) We tried to minimize this by having the particles move forward only a very small amount at each time step (the variable STEP-SIZE). We couldn't make this amount too small since the model would then run too slowly. If you want the particles to spiral less, or you want the model to run faster, change this value.


THINGS TO TRY

Place particles in different parts of the screen. Does the particle's position have any effect on the trajectory?


EXTENDING THE MODEL

Try a different vector field by changing it in the SETUP-VECTOR, FORCE-X, and FORCE-Y procedures. For instance, if you choose

    x d/dx - y d/dy

the integral curves will be hyperbolas.


CREDITS AND REFERENCES

To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Vector Fields model. http://ccl.northwestern.edu/netlogo/models/VectorFields. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/VectorFields for terms of use.


PROCEDURES

breed [ particles ]
breed [ vectors ]


globals
[
  max-modulus  ;; the maximum modulus of all the vectors
  clicked?     ;; true if we have clicked the mouse button but have not yet placed a particle
  step-size    ;; the amount a particle moves forward
  signum       ;; sign in orce equations (changed by chooser "direction")
]

vectors-own
[
  modulus  ;; the length of the vector
]

;; set up the field, and create vectors
to setup
  ca
  set clicked? false
  
  ;; have particles move forward .005 so that we don't spiral too much but 
  ;; also so that the model doesn't run too slowly
  set step-size .005
  set signum 1
  
  ;; create vectors at regular intervals to see the effect of the force
  ;; at a particular place.
  ask patches
  [
    if (pxcor mod 13 = 0) and (pycor mod 13 = 0)
    [
      sprout-vectors 1
      [ setup-vector ]
    ]
  ] 
  ;; draw vector field
  set max-modulus (max [modulus] of vectors)
  ask vectors
  [ show-vector ]
end

;; make the turtle become a vector and initialize the vector's variables
to setup-vector  ;; turtle procedure
  set color green
  pendown
  if (force-x != 0) or (force-y != 0)
    [ set heading atan force-x force-y ]
  set modulus distancexy 0 0
end
  
;; particles update their orientation according to the vector-field force 
;; operating on the patch where they are at
to go
  let stop? false
  ask particles
  [
    ;; calculate the heading based on the force where this turtle is
    if force-x != 0 or force-y != 0
      [ set heading (atan force-x force-y) ]
    ifelse going-to-wrap?
    [
      ;; don't move forward if we are going to wrap around the edge
      set stop? true
    ]
    [ forward step-size ]
  ]
  ;; if one of the particles was going to wrap around the Graphics Window, stop.
  if stop?
  [ stop ]
end

;; report true if we will wrap around if we move forward by step-size
to-report going-to-wrap?  ;; turtle procedure
  let next-patch patch-ahead step-size
  report (abs [pxcor] of next-patch >= max-pxcor)
         or
         (abs [pycor] of next-patch >= max-pycor)
end

;; place test particles
to place-particles
  if mouse-down?
  [ set clicked? true ]
  if (not mouse-down?) and clicked?
  [ place-particle mouse-xcor mouse-ycor ]
end

;; create a particle at (x,y)
to place-particle [x y]
  create-particles 1
  [
    setxy x y
    set size 10
    set heading 0
    set color red
    pendown  ;; put the pen down so that we can see where it has traveled
    if force-x != 0 or force-y != 0
      [ set heading (atan force-x force-y) ]
  ]
  set clicked? false
end

;; calculate the horizontal force where the turtle is located
to-report force-x  ;; turtle procedure
  ifelse direction = "direct" [ set signum 1 ] [ set signum ( - 1 ) ]
  report ( - 1 ) * signum * (  xcor ^ 3 + a * xcor + b ) ;;; ralph's modification for the cusp
end

;; calculate the vertical force where the turtle is located
to-report force-y  ;; turtle procedure
  ifelse direction = "direct" [ set signum 1 ] [ set signum ( - 1 ) ]
  report ( - ycor ) * signum  ;;; ralph's modification
end

;; draw the vector using a turtle to display strength and direction of field
to show-vector  ;; turtle procedure
  set modulus (10 * modulus / max-modulus)
  forward modulus
  set color yellow
end


; *** NetLogo Model Copyright Notice ***
;
; This model was created as part of the project: CONNECTED MATHEMATICS:
; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL
; MODELS (OBPML).  The project gratefully acknowledges the support of the
; National Science Foundation (Applications of Advanced Technologies
; Program) -- grant numbers RED #9552950 and REC #9632612.
;
; Copyright 1998 by Uri Wilensky. All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from Uri Wilensky.
; Contact Uri Wilensky for appropriate licenses for redistribution for
; profit.
;
; This model was converted to NetLogo as part of the project:
; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN
; CLASSROOMS.  The project gratefully acknowledges the support of the
; National Science Foundation (REPP program) -- grant number REC #9814682.
; Converted from StarLogoT to NetLogo, 2002.  Updated 2003.
;
; To refer to this model in academic publications, please use:
; Wilensky, U. (1998).  NetLogo Vector Fields model.
; http://ccl.northwestern.edu/netlogo/models/VectorFields.
; Center for Connected Learning and Computer-Based Modeling,
; Northwestern University, Evanston, IL.
;
; In other publications, please use:
; Copyright 1998 by Uri Wilensky.  All rights reserved.  See
; http://ccl.northwestern.edu/netlogo/models/VectorFields
; for terms of use.
;
; *** End of NetLogo Model Copyright Notice ***