List Info

Thread: Diffuse6...




Diffuse6...
country flaguser name
Brazil
2008-03-07 07:11:35

Hi,

I am trying to create a function within my code that makes the spread for the 6 neighbouring primary environmental 3D, tried at first to do it well:

ask patches
    [ ;;let neighbor6 [ ( list pxcor pycor pzcor ) ] of neighbors6
      ;;let value 0
 
      set TNF TNF * diffuse-rate
      set IFN IFN * diffuse-rate
      repeat 10 [ set quim quim * diffuse-rate ]
 ;    
      let q1 TNF / 6
      let q2 IFN / 6
      let q3 0
      repeat 10 [ set q3 quim / 6 ] 
 
      ask neighbors6
         [ set TNF q1
         ;  set IFN q2
      ;     repeat 10 [ set quim q3 ]
       ;  ]
     
     
      ;;while [ length neighbor6 > 0 ]
      ;;  [ set value one-of neighbor6
  ;    ;;    set TNF q1
     ; ;;    set IFN q2
     ; ;;    repeat 10 [ set quim q3 ]
     
      ;;   set neighbor6 remove value neighbor6
      ;;  ]
    ]

But is generating some mistakes and getting very heavy, anyone have any idea or suggestion to improve it?


Yours Truly;
--

Luís César da Costa
B.Sci. in Computer Science
Computer sCience Coordination - CCC
==================================
National Laboratory of sCientific Computing - LNCC
Av. Getú;lio Vargas, 333, Quitandinha, Petrópolis - RJ
Tel: -55 (24) 2233-6267
Fax: -55 (24) 2233-6071
lcostalncc.br

"I log in, therefore I am. Reality is for people without Internet access..." Electrical Cheap

==================================

Esta mensagem possui conteúdo destinado apenas às pessoas ou pessoa destinatária.Se
você; recebeu esta mensagem por engano favor me avisar e depois destruí-la
(juntamente com seus respectivos anexos) . Não autorizo o uso desta mensagem fora do
seu contexto.
This e-mail message may contain privileged and/or confidential information, and is
intended to be received only by persons entitled to receive such information. If you
have received this e-mail in error, please notify the sender immediately. Please
delete it and all attachments from any servers, hard drives or any other media.
Other use of this e-mail by you is strictly prohibited.

__._,_.___
.

__,_._,___
Re: Diffuse6...
country flaguser name
United States
2008-03-07 16:02:46

Why do you have this?

repeat 10 [ set quim quim * diffuse-rate ]

That is the same as:

set quim quim * ( diffuse-rate ^ 10 )

Is that what you meant?

And this:

repeat 10 [ set q3 quim / 6 ] 

Is the same as:

set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6
set q3 quim / 6

The 9 extra assigments are waste.

I think there is a rather fundamental misunderstanding of how NetLogo works going on here.


Here is a home-grown diffuse routine.

globals [ diffusion-rate number-of-neighbors input-rate output-rate ]
patches-own [ temp variable ]

to setup
   ca
   set diffusion-rate 1
   set number-of-neighbors 8
   set input-rate diffusion-rate / ( number-of-neighbors + 1 )
   set output-rate input-rate * number-of-neighbors
  
   ask patches [ set variable  (.1 * random 1399 ) set pcolor variable ]
   ; ask patch 0 0 [ set variable 9.9 set pcolor variable ]
end

to diff
 ; ask patches [ set temp calc-variable ]
  ask patches [ set variable temp set pcolor variable]
end

to-report calc-variable
    let input (sum [ variable ] of neighbors) * input-rate
    let output variable * output-rate
    report variable - output + input
end

   
~~James


On Fri, Mar 7, 2008 at 8:11 AM, < lcostalncc.br">lcostalncc.br&gt; wrote:
Hi,

I am trying to create a function within my code that makes the spread for the 6 neighbouring primary environmental 3D, tried at first to do it well:

ask patches
&nbsp; &nbsp; [ ;;let neighbor6 [ ( list pxcor pycor pzcor ) ] of neighbors6
 &nbsp; &nbsp;  ;;let value 0
 
 &nbsp; &nbsp;  set TNF TNF * diffuse-rate
 &nbsp; &nbsp;  set IFN IFN * diffuse-rate
 &nbsp; &nbsp;  repeat 10 [ set quim quim * diffuse-rate ]
 ; &nbsp; &nbsp;
 &nbsp; &nbsp;  let q1 TNF / 6
 &nbsp; &nbsp;  let q2 IFN / 6
 &nbsp; &nbsp;  let q3 0
 &nbsp; &nbsp;  repeat 10 [ set q3 quim / 6 ] 
 
 &nbsp; &nbsp;  ask neighbors6
 &nbsp; &nbsp; &nbsp;   [ set TNF q1
 &nbsp; &nbsp; &nbsp;   ;  set IFN q2
&nbsp; &nbsp;   ; &nbsp; &nbsp; repeat 10 [ set quim q3 ]
 &nbsp; &nbsp;   ;  ]
 &nbsp; &nbsp; 
 &nbsp; &nbsp; 
 &nbsp; &nbsp;  ;;while [ length neighbor6 > 0 ]
 &nbsp; &nbsp;  ;;  [ set value one-of neighbor6
  ; &nbsp;  ;; &nbsp;  set TNF q1
 &nbsp;   ; ;; &nbsp;  set IFN q2
 &nbsp;   ; ;; &nbsp;  repeat 10 [ set quim q3 ]
 &nbsp; &nbsp; 
 &nbsp; &nbsp;  ;; &nbsp; set neighbor6 remove value neighbor6
&nbsp; &nbsp; &nbsp; ;;  ]
 &nbsp;  ]

But is generating some mistakes and getting very heavy, anyone have any idea or suggestion to improve it?

__._,_.___
.

__,_._,___
Re: Diffuse6...
country flaguser name
United States
2008-03-07 16:29:27

Luís,

I think you may be overthinking this one, making it too difficult. While it is true that NetLogo 3D Preview 5 doesn't have a diffuse6 primitive (though I hope that will change at some point), it does (as you have found) have the neighbors6 primitive, and that will do most of what you want. I'm not really clear on what your model is doing, but here's a basic example of the approach I would take.

First, let's assume that each patch has a temperature, and we want the temperature to diffuse through the 3D world, but only by each patch giving some of its heat to its nearest six neighbors (i.e. using a 3D Von Neumann neighborhood). Also, in the current version of NetLogo 3D, the topology always wraps around in the X, Y, and Z directions, so we don't have to worry about boundaries (for now); in other words, every patch has exactly six other patches in the agentset reported by neighbors6.

So, let's start by defining a couple of patch variables:

patches-own [
   ; temperature
&nbsp;   ;working-temperature
]

Now, we need a function that will diffuse the temperature values, in the same way that diffuse6 temperature rate conceivably would - if there were a diffuse6 primitive:

to diffuse-temperature [rate]
&nbsp;   ;ask patches [
   ; &nbsp; &nbsp; set working-temperature
 &nbsp; &nbsp; &nbsp; &nbsp;   ; ((1 - rate) * temperature + sum [rate * temperature / 6] of neighbors6)
 &nbsp;  ]
&nbsp;   ;ask patches [
   ; &nbsp; &nbsp; set temperature working-temperature
 &nbsp; &nbsp;]
end

Note one very important details: in each iteration, all patches must get a chance to read their neighbors' temperature values, before any patch changes its own temperature. That's why there is one ask patches block in which all patches update working-temperature, based on their own temperature and that of their neighbors; then there is a second ask patches block in which the value of working-temperature is copied to temperature. If these two operations were combined in a single ask patches block, then some patches would already have changed the value of their temperature variables before their neighbors had a chance to read the old values. This is a common programming problem in cellular automata-type models, where the state of each cell in generation n is based on its state - and that of its neighbors - in generation n-1. This is dealt with transparently and automatically by the diffuse primitives in NetLogo.

Of course, the approach above won't run as fast as diffuse6 temperature rate would, if a diffuse6 primitive existed. But it will give you the same results, and should give you much of what you need, for now.

I hope this helps.

Regards,

Nick


--- In netlogo-usersyahoogroups.com, lcosta... wrote:
>;
>
>
> Hi,
>
> I am trying to create a function within my code that makes
> the spread for the 6 neighbouring primary environmental 3D, tried at first
> to do it well:
>
> ask patches
&gt; [ ;;let
> neighbor6 [ ( list pxcor pycor pzcor ) ] of neighbors6
> ;;let value 0
>
> set TNF TNF * diffuse-rate
> set IFN IFN * diffuse-rate
> repeat 10 [ set quim quim * diffuse-rate
> ]
>
>
> let q1 TNF / 6
> let q2 IFN / 6
> let q3 0
> repeat 10 [ set q3 quim / 6 ]
>
> ask neighbors6
> [ set TNF q1
> set IFN
> q2
>
> repeat 10 [ set quim q3 ]
> ]
>
>
> ;;while [ length neighbor6 > 0 ]
> ;; [ set value one-of neighbor6
> ;; set TNF q1
> ;; set IFN q2
> ;; repeat 10 [ set quim
> q3 ]
>
> ;; set neighbor6 remove value
> neighbor6
> ;; ]
> ]
>
> But is generating some mistakes and
> getting very heavy, anyone have any idea or suggestion to improve it?
>
>
> Yours Truly;
>; --
>
> Luís César da
> Costa
> B.Sci. in Computer Science
> Computer sCience Coordination
> - CCC
> ==================================
> National Laboratory of
> sCientific Computing - LNCC
> Av. Getúlio Vargas, 333,
> Quitandinha, Petrópolis - RJ
> Tel: -55 (24) 2233-6267
> Fax:
> -55 (24) 2233-6071
> lcosta...
>
> "I log in,
> therefore I am. Reality is for people without Internet access..."
> Electrical Cheap
>
> ==================================
>
> Esta mensagem possui conteúdo destinado apenas às pessoas
&gt; ou pessoa destinatária.Se
> você recebeu esta mensagem por
> engano favor me avisar e depois destruí-la
> (juntamente com
> seus respectivos anexos) . Não autorizo o uso desta mensagem fora
> do
> seu contexto.
> This e-mail message may contain privileged
> and/or confidential information, and is
> intended to be received only
> by persons entitled to receive such information. If you
> have received
&gt; this e-mail in error, please notify the sender immediately. Please
>; delete it and all attachments from any servers, hard drives or any other
> media.
>; Other use of this e-mail by you is strictly prohibited.
>

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )