Пример #1
0
import mechanica as m

m.init(dt=0.1, dim=[15, 5, 5], cutoff = 3,
       bc={'x':('periodic','reset')})

class A(m.Particle):
    species = ['S1', 'S2', 'S3']
    style = {"colormap" : {"species" : "S1",
                           "map" : "rainbow",
                           "range" : "auto"}}

m.flux(A, A, "S1", 2)

a1 = A(m.universe.center - [0, 1, 0])
a2 = A(m.universe.center + [-5, 1, 0], velocity=[0.5, 0, 0])

a1.species.S1 = 3
a2.species.S1 = 0

m.show()
Пример #2
0
class B(m.Particle):
    radius = 0.1
    species = ['S1', 'S2', 'S3']
    style = {"colormap": {"species": "S1", "map": "rainbow", "range": "auto"}}

    def spew(self, event):

        print("spew...")

        # reset the value of the species
        # secrete consumes material...
        self.species.S1 = 500
        self.species.S1.secrete(250, distance=1)


m.flux(A, A, "S1", 5, 0.005)

uc = m.lattice.sc(0.25, A)

parts = m.lattice.create_lattice(uc, [25, 25, 25])

# grap the particle at the top cornder
o = parts[24, 0, 24][0]

print("secreting pos: ", o.position)

# change type to B, since there is no flux rule between A and B
o.become(B)

m.on_time(B.spew, period=0.3)
m.show()
Пример #3
0
import mechanica as m
import numpy as n

m.init()


class A(m.Particle):
    species = ['S1', 'S2', 'S3']
    style = {"colormap": {"species": "S1", "map": "rainbow", "range": "auto"}}


m.flux(A, A, "S1", 5)

a1 = A(m.Universe.center)
a2 = A(m.Universe.center + [0, 0.5, 0])

a1.species.S1 = 0
a2.species.S1 = 1

m.show()
Пример #4
0
    radius = 0.1
    species = ['S1', 'S2', 'S3']
    style = {"colormap" : {"species" : "S1", "map" : "rainbow","range" : "auto"}}

class Producer (m.Particle):
    radius = 0.1
    species = ['S1', 'S2', 'S3']
    style = {"colormap" : {"species" : "S1", "map" : "rainbow","range" : "auto"}}

class Consumer (m.Particle):
    radius = 0.1
    species = ['S1', 'S2', 'S3']
    style = {"colormap" : {"species" : "S1", "map" : "rainbow","range" : "auto"}}

# define fluxes between objects types
m.flux(A, A, "S1", 5, 0)
m.produce_flux(Producer, A, "S1", 5, 0)
m.consume_flux(A, Consumer, "S1", 10, 500)

# make a lattice of objects
uc = m.lattice.sc(0.25, A)
parts = m.lattice.create_lattice(uc, [25, 25, 1])

# grap the left part
left = parts[0,12,0][0]

# grab the right part
right = parts[24,12,0][0]

# change types
left.become(Producer)
Пример #5
0

class Source(m.Particle):
    radius = 0.1
    species = ['$S1=5', 'S2', 'S3']  # make S1 a boundary species here.
    style = {"colormap": {"species": "S1", "map": "rainbow", "range": "auto"}}


class Sink(m.Particle):
    radius = 0.1
    species = ['$S1', 'S2', 'S3']  # make S1 a boundary species here.
    style = {"colormap": {"species": "S1", "map": "rainbow", "range": "auto"}}


# define fluxes between objects types
m.flux(A, A, "S1", 5, 0.001)
m.secrete_flux(Producer, A, "S1", 5, 0)
m.uptake_flux(A, Consumer, "S1", 10, 500)
m.secrete_flux(Source, A, "S1", 5, 0)
m.flux(Sink, A, "S1", 200, 0)

# make a lattice of objects
uc = m.lattice.sc(0.25, A)
parts = m.lattice.create_lattice(uc, [25, 25, 1])

# grap the left part, make it a producer
parts[0, 12, 0][0].become(Producer)

# grab the right part, make it a consumer
parts[24, 12, 0][0].become(Consumer)