#!/usr/bin/python

from numpy import *

## AVA model
MOD_NAME="AVA"

## predefined cell types
GR=0
AIR=1
DUM=3
IN=4
OUT=5

###############################################################
def create_simple_space(H,L,D):
  """creates a simple cellular space with a circular source"""

  ## create cellular space
  cs=zeros((D,H,L),int8)

  ## air volume
  cs[:,:,:]=AIR

  ## GR source (disk)
  R=5
  R2=R*R
  Ld2=L/2
  Dd2=D/2
  for k in range(D):
    for i in range(L):
      di = i - Ld2
      dk = k - Dd2
      if di*di + dk*dk <= R2:
        cs[k,0,i]=IN

  ## floor
  cs[:,H-1,:]=DUM
  
  return cs

###############################################################
def create_filled_space(H,L,D):
  """creates a cellular space filled with sand with a circular output"""

  ## create cellular space
  cs=zeros((D,H,L),int8)

  ## sand
  cs[:,:,:]=GR

  ## GR output (disk)
  R=5
  R2=R*R
  Ld2=L/2
  Dd2=D/2
  for k in range(D):
    for i in range(L):
      di = i - Ld2
      dk = k - Dd2
      if di*di + dk*dk <= R2:
        cs[k,H-1,i]=OUT
      else:
        cs[k,H-1,i]=DUM
       
  return cs


###############################################################
def cellspace(H,L,D):
  """generates cellular space"""
  cs=create_simple_space(H,L,D)
  #cs=create_filled_space(H,L,D)
  return cs

