Skip to content

Commit e8bd609

Browse files
fix README example
1 parent 4c4f059 commit e8bd609

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

README.md

+52-12
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,16 @@ is `construct(T::AbstractMultiScaleArray, nodes, values)`, though if `values` is
6262
taken to be empty.
6363

6464
```julia
65-
population = construct(Population, deepcopy([cell1, cell2])) # Make a Population from cells
6665
cell3 = Cell([3.0; 2.0; 5.0])
6766
cell4 = Cell([4.0; 6.0])
68-
population2 = construct(Population, deepcopy([cell3, cell4]))
69-
tissue1 = construct(Tissue, deepcopy([population, population2])) # Make a Tissue from Populations
70-
tissue2 = construct(Tissue, deepcopy([population2, population]))
67+
population2 = construct(Population, deepcopy([cell1, cell3, cell4]))
68+
population3 = construct(Population, deepcopy([cell1, cell3, cell4]))
69+
tissue1 = construct(Tissue, deepcopy([population, population2, population3])) # Make a Tissue from Populations
70+
tissue2 = construct(Tissue, deepcopy([population2, population, population3]))
7171
embryo = construct(Embryo, deepcopy([tissue1, tissue2])) # Make an embryo from Tissues
7272
```
7373

74-
Note that tuples can be used as well. This allows for type-stable indexing with
75-
heterogeneous nodes. For example:
76-
77-
```julia
78-
tissue1 = construct(Tissue, deepcopy((population, cell3)))
79-
```
80-
81-
(of course at the cost of mutability).
74+
## Indexing and Iteration
8275

8376
The head node then acts as the king. It is designed to have functionality which
8477
mimics a vector in order for usage in DifferentialEquations or Optim. So for example
@@ -142,6 +135,53 @@ remove_node!(embryo, 2, 1) # Removes population 1 from tissue 2 of the embryo
142135
Combined with event handling, this allows for dynamic structures to be derived from
143136
low level behaviors.
144137

138+
## Heterogeneous Nodes via Tuples
139+
140+
Note that tuples can be used as well. This allows for type-stable broadcasting with
141+
heterogeneous nodes. This could be useful for mixing types
142+
inside of the nodes. For example:
143+
144+
```julia
145+
struct PlantSettings{T} x::T end
146+
struct OrganParams{T} y::T end
147+
148+
struct Organ{B<:Number,P} <: AbstractMultiScaleArrayLeaf{B}
149+
values::Vector{B}
150+
name::Symbol
151+
params::P
152+
end
153+
154+
struct Plant{B,S,N<:Tuple{Vararg{<:Organ{<:Number}}}} <: AbstractMultiScaleArray{B}
155+
nodes::N
156+
values::Vector{B}
157+
end_idxs::Vector{Int}
158+
settings::S
159+
end
160+
161+
struct Community{B,N<:Tuple{Vararg{<:Plant{<:Number}}}} <: AbstractMultiScaleArray{B}
162+
nodes::N
163+
values::Vector{B}
164+
end_idxs::Vector{Int}
165+
end
166+
167+
mutable struct Scenario{B,N<:Tuple{Vararg{<:Community{<:Number}}}} <: AbstractMultiScaleArrayHead{B}
168+
nodes::N
169+
values::Vector{B}
170+
end_idxs::Vector{Int}
171+
end
172+
173+
organ1 = Organ([1.1,2.1,3.1], :Shoot, OrganParams(:grows_up))
174+
organ2 = Organ([4.1,5.1,6.1], :Root, OrganParams("grows down"))
175+
organ3 = Organ([1.2,2.2,3.2], :Shoot, OrganParams(true))
176+
organ4 = Organ([4.2,5.2,6.2], :Root, OrganParams(1//3))
177+
plant1 = construct(Plant, (deepcopy(organ1), deepcopy(organ2)), Float64[], PlantSettings(1))
178+
plant2 = construct(Plant, (deepcopy(organ3), deepcopy(organ4)), Float64[], PlantSettings(1.0))
179+
community = construct(Community, (deepcopy(plant1), deepcopy(plant2), ))
180+
scenario = construct(Scenario, (deepcopy(community),))
181+
```
182+
183+
(of course at the cost of mutability).
184+
145185
## Idea
146186

147187
The idea behind MultiScaleArrays is simple. The `*DiffEq` solvers (OrdinaryDiffEq.jl,

0 commit comments

Comments
 (0)