grow_tree.py is the main module of the code and the one you invoke from the command line to start a simulation.
To start a simulation with parameters read from a file simulation.ini simply invoke this module as:
python grow_tree.py simulation.ini
The output will be written in a file name simulation.h5 with a HDF5 format.
Performs a step of duration dt but divides it into sub steps to make sure that the length of a channel is never longer than MAX_STEP.
Calculates the external field at points r. This is calculated from EXTERNAL_FIELD and ELECTRODE_POTENTIAL. As the code stands now only these two possibilities are physically meaningful:
- Specify EXTERNAL_FIELD with a planar electrode or with no electrode, but use ELECTRODE_POTENTIAL=0.
- ELECTRODE_POTENTIAL != 0, but ELECTRODE_GEOMETRY = 'sphere' and EXTERNAL_FIELD = 0.
However, we allow the user to shoot himself on his foot, so he can select any arbitrary combination of these parameters. Beware.
Calculates the external potential at points r. See above, in external_field for the risks here.
Init a ‘tree’ with the root node plus n additional nodes in a vertical string.
This is the main function of the code it is the starting point of a simulation.
Random values in a given shape.
Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1).
random
This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to np.random.random_sample .
>>> np.random.rand(3,2)
array([[ 0.14022471, 0.96360618], #random
[ 0.37601032, 0.25528411], #random
[ 0.49313049, 0.94909878]]) #random
Return a sample (or samples) from the “standard normal” distribution.
If positive, int_like or int-convertible arguments are provided, randn generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the \(d_i\) are floats, they are first converted to integers by truncation). A single float randomly sampled from the distribution is returned if no argument is provided.
This is a convenience function. If you want an interface that takes a tuple as the first argument, use numpy.random.standard_normal instead.
random.standard_normal : Similar, but takes a tuple as its argument.
For random samples from \(N(\mu, \sigma^2)\), use:
sigma * np.random.randn(...) + mu
>>> np.random.randn()
2.1923875335537315 #random
Two-by-four array of samples from N(3, 6.25):
>>> 2.5 * np.random.randn(2, 4) + 3
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random
Relax the conductor tree.Tree tr for a time dt.
Arguments:
- tr: the tree.Tree instance containing the tree structure.
- r: an array containing the node locations.
- q0: an array containing the charges of the nodes.
- dt: the time step.
Seed the generator.
This method is called when RandomState is initialized. It can be called again to re-seed the generator. For details, see RandomState.
RandomState
Calculates the fields created by the charges at the streamer tips on themselves.
Performs an elementary step, including relaxation and advancing the channels.
Arguments:
- tr: the tree.Tree instance containing the tree structure.
- r: an array containing the node locations.
- q0: an array containing the charges of the nodes.
- dt: the time step.
This is the parameter description file. Basically it provides a namespace where we store a function per input parameter. Each function receives a string and is responsible for converting to the appropriate type, checking for allowed values. The docstring of the function is a description of the parameter.
This parameter is completely ignored. It is used only to produce series of identical runs.
Longest step for a channel in dt. The timestep will be reduced to satisfy this constraint
This module contains the data representation for the structure of trees. Note that we separate the structure of the branched tree from its realization, that would contain things such as charges, positions, etc. that evolve even when the structure is fixed.
This is class of the segments composing a Tree.
Instances of the Tree class contain the topological information of a tree discharge: i.e. they encapsulate the relations between different segments in a tree but not about locations, conductivities etc..
Adds a segment to this tree. Returns the index of the segment inside the tree.
Returns an array with the distance of each node from the branching immediately above it. The distance is calculated along the branch.
Returns an array with an integer for each node that is unique for the branch where it sits.
Extends the tree adding one children to each segment indexed by indices, in that order. This is used to extend a propagating tree.
Returns an array with the segment lengths of the tree, given an array with the endpoints.
Returns an array with the segment midpoints of the tree, given an array with the endpoints.
Builds a matrix M that will provide the evolution of charges in every segment of the tree as dq/dt = M . phi, where phi is the potential at the center of each segment and ‘.’ is the dot product. This function builds the matrix from scratch. Usually it is much better to keep updating the matrix as the tree grows.
Builds an array with the indices to each segment’s parent. The root segment gets an index root_index.
Builds a branched tree of n segments where every segment has a probability p of having two descendants. This produces nice pictures and can be useful for testing.
Gives endpoints to a tree structure. Useful for plotting sample trees [DEBUG].
random() -> x in the interval [0, 1).
This module implement the structure of oct-trees for the implementation of the Fast Multipolar Method (FMM).
. note:
Most of this code is not used, since we disabled the use of the FMM for
the simulations reported in the paper. However, the simulated tree is
embedded in a bounding box defined by a :class:`Box` instance.
Class of 3d boxes. Each box can be linked to a set of charges.
Builds the lists of near-neighbours and the interaction list of this box. Assumes that the near-neighbours are already calculated up in the tree.
Collects the multipolar expansions of this box’s children, translate them to the center and sums them.
Calculates the inward (local) expansions of all boxes in the interaction list and adds them.
Checks whether other is a near neighbour of this box. Note that they must belong to the same oct-tree or the algorithm fails.
Sets the charges of this box. If max_charges is not None, refines the box into smaller children until each leaf box contains no more than max_charges. If evaluation is true, assumes that the charge points will also be the evaluation points.
Once we have the local expansion for the box and the list of near-neighbours, we can finally evaluate the potential. Note that generally this function is called only for leaf nodes.
This is an auxiliary module for reading input .ini files. It is based on Python’s stdlib ConfigParser
This module also provides functionality for setting run sets where one or more of the parameters run over a list of values.
Expands special characters to produce e.g. lists of many parameters.
Takes a dictionary that may contain a few lists as values and returns an iterator over dictionaries where each of these elements is iterated.
Expands an input file by expanding some of its arguments.
Converts s into int or float if possible. If not, leave it as a string. This will give us problems if the user wants to e.g. use filenames or run names that can be parser as a number. So have to implement a better approach whereby parameter names are associated with types.