def setUp(self):
        DCST = 0.08e-10
        self.model = smodel.Model()
        A = smodel.Spec('A', self.model)

        self.vsys = smodel.Volsys('vsys', self.model)
        self.ssys = smodel.Surfsys('ssys', self.model)
        self.diff = smodel.Diff("diff", self.vsys, A, DCST)
        self.sdiff = smodel.Diff("diff", self.ssys, A, DCST)

        if __name__ == "__main__":
            self.mesh = meshio.importAbaqus('meshes/test_mesh.inp', 1e-7)[0]
        else:
            self.mesh = meshio.importAbaqus(
                'parallel_std_string_bugfix_test/meshes/test_mesh.inp',
                1e-7)[0]

        self.tmcomp = sgeom.TmComp('comp', self.mesh, range(self.mesh.ntets))
        self.tmcomp.addVolsys('vsys')
        self.surf_tris = self.mesh.getSurfTris()
        self.tmpatch = sgeom.TmPatch('patch',
                                     self.mesh,
                                     self.surf_tris,
                                     icomp=self.tmcomp)
        self.tmpatch.addSurfsys('ssys')

        self.rng = srng.create('r123', 512)
        self.rng.initialize(1000)

        tet_hosts = gd.binTetsByAxis(self.mesh, steps.mpi.nhosts)
        tri_hosts = gd.partitionTris(self.mesh, tet_hosts, self.surf_tris)
        self.solver = solv.TetOpSplit(self.model, self.mesh, self.rng,
                                      solv.EF_NONE, tet_hosts, tri_hosts)

        self.solver.reset()
예제 #2
0
 def testSetGetTriCount(self):
     tet_hosts = gd.binTetsByAxis(self.mesh, steps.mpi.nhosts)
     tri_hosts = gd.partitionTris(self.mesh, tet_hosts, self.surf_tris)
     solver = solv.TetOpSplit(self.model, self.mesh, self.rng, solv.EF_NONE,
                              tet_hosts, tri_hosts)
     for tri in self.surf_tris:
         solver.setTriCount(tri, 'A', tri)
         get_count = solver.getTriCount(tri, 'A')
         self.assertEqual(get_count, tri)
예제 #3
0
    def setUp(self):
        self.model = smodel.Model()
        A = smodel.Spec("A", self.model)
        B = smodel.Spec("B", self.model)
        C = smodel.Spec("C", self.model)
        D = smodel.Spec("D", self.model)
        E = smodel.Spec("E", self.model)

        self.vsys1 = smodel.Volsys('vsys1', self.model)
        self.vsys2 = smodel.Volsys('vsys2', self.model)
        self.ssys1 = smodel.Surfsys('ssys1', self.model)

        self.reac1 = smodel.Reac('reac1', self.vsys1, lhs = [A], rhs = [A],  kcst = 1e5)
        self.reac2 = smodel.Reac('reac2', self.vsys2, lhs = [E], rhs = [E],  kcst = 1e4)

        self.sreac = smodel.SReac('sreac', self.ssys1, slhs = [B], srhs = [B],  kcst = 1e3)
    
        if __name__ == "__main__":
            self.mesh = meshio.loadMesh('meshes/cyl_len10_diam1')[0]
        else:
            self.mesh = meshio.loadMesh('getROIArea_bugfix_test/meshes/cyl_len10_diam1')[0]

        ntets = self.mesh.countTets()
        comp1Tets, comp2Tets = [], []
        comp1Tris, comp2Tris = set(), set()
        for i in range(ntets):
            if self.mesh.getTetBarycenter(i)[0] > 0:
                comp1Tets.append(i)
                comp1Tris |= set(self.mesh.getTetTriNeighb(i))
            else:
                comp2Tets.append(i)
                comp2Tris |= set(self.mesh.getTetTriNeighb(i))
        patch1Tris = list(comp1Tris & comp2Tris)

        self.comp1 = sgeom.TmComp('comp1', self.mesh, comp1Tets)
        self.comp2 = sgeom.TmComp('comp2', self.mesh, comp2Tets)
        self.comp1.addVolsys('vsys1')
        self.comp2.addVolsys('vsys2')

        self.patch1 = sgeom.TmPatch('patch1', self.mesh, patch1Tris, self.comp1, self.comp2)
        self.patch1.addSurfsys('ssys1')

        self.ROI1 = self.mesh.addROI('ROI1', sgeom.ELEM_TET, comp1Tets)
        self.ROI2 = self.mesh.addROI('ROI2', sgeom.ELEM_TET, comp2Tets)
        self.ROI3 = self.mesh.addROI('ROI3', sgeom.ELEM_TRI, patch1Tris)
    
        self.rng = srng.create('r123', 512)
        self.rng.initialize(1000)
        tet_hosts = gd.linearPartition(self.mesh, [steps.mpi.nhosts, 1, 1])
        tri_hosts = gd.partitionTris(self.mesh, tet_hosts, patch1Tris)
        self.solver = solv.TetOpSplit(self.model, self.mesh, self.rng, solv.EF_NONE, tet_hosts, tri_hosts)
########################### MESH & BRANCH MAPPING ###########################

import CaBurst_geom
mesh, rois, roi_areas, roi_vols = CaBurst_geom.getGeom(MESH_FILE, MORPH_FILE)

########################### Recording ###########################
if steps.mpi.rank == 0:
    try:
        os.mkdir(RESULT_DIR)
    except:
        pass

########################### PARTITIONING ###########################
partition_file = 'meshes/partition/branch.metis.epart.' + str(steps.mpi.nhosts)
mpi_tet_partitions = metis_support.readPartition(partition_file)
mpi_tri_partitions = gd.partitionTris(mesh, mpi_tet_partitions,
                                      mesh.getSurfTris())

########################### CREATE SOLVER ###########################

r = srng.create_mt19937(512)
r.initialize(int(time.time()) * steps.mpi.rank)

sim = mpisolver.TetOpSplit(mdl,
                           mesh,
                           r,
                           tet_hosts=mpi_tet_partitions,
                           tri_hosts=mpi_tri_partitions)

########################### LOAD PRESET CALCIUM INFLUX DATA ###########################

# convert P type calcium current data to calcium influx profile
예제 #5
0
#  Chen W and De Schutter E (2017) Parallel STEPS: Large Scale Stochastic Spatial Reaction-Diffusion Simulation with High Performance Computers. Front. Neuroinform. 11:13. doi: 10.3389/fninf.2017.00013
#
##########################################################################

from extra.activity_viewer import *
import cPickle
import steps.utilities.geom_decompose as gd
import steps.utilities.meshio as meshio
import steps.visual
import pyqtgraph as pg
import random
import math
import sys

ACTIVITY_FILE = sys.argv[1]

MESH_FILE = "meshes/branch.inp"
mesh = meshio.importAbaqus(MESH_FILE, 1e-6)[0]
morph_file = open("meshes/branch.morph", 'r')
morph = cPickle.load(morph_file)
tet_parts = gd.mapMorphTetmesh(morph, mesh)
tri_parts = gd.partitionTris(mesh, tet_parts, mesh.getSurfTris())

tet_part_table = gd.getTetPartitionTable(tet_parts)
tri_part_table = gd.getTriPartitionTable(tri_parts)

mpi_data = SI2NEURON(readData(ACTIVITY_FILE))
app = pg.mkQApp()
conc_display = TriActivitySeriesDisplay(mesh, tri_parts, mpi_data, title = "MPI Sim", time_unit = "ms", data_unit = "mM", min_v = 0.0236, max_v = 3.51)
app.exec_()
def test_unbdiff2D_linesource_ring():
    "Surface Diffusion - Unbounded, line source (Parallel TetOpSplit)"

    m = gen_model()
    g, patch_tris, partition_tris, patch_tris_n, inject_tris, tridists, triareas = gen_geom(
    )

    tet_hosts = gd.binTetsByAxis(g, steps.mpi.nhosts)
    tri_hosts = gd.partitionTris(g, tet_hosts, partition_tris)

    sim = solvmod.TetOpSplit(m, g, rng, False, tet_hosts, tri_hosts)

    tpnts = np.arange(0.0, INT, DT)
    ntpnts = tpnts.shape[0]

    #Create the big old data structure: iterations x time points x concentrations
    res_count = np.zeros((NITER, ntpnts, patch_tris_n))
    res_conc = np.zeros((NITER, ntpnts, patch_tris_n))

    for j in range(NITER):
        sim.reset()
        for t in inject_tris:
            sim.setTriCount(t, 'X', float(NINJECT) / len(inject_tris))
        for i in range(ntpnts):
            sim.run(tpnts[i])
            for k in range(patch_tris_n):
                res_count[j, i, k] = sim.getTriCount(patch_tris[k], 'X')
                res_conc[j, i,
                         k] = 1e-12 * (sim.getTriCount(patch_tris[k], 'X') /
                                       sim.getTriArea(patch_tris[k]))

    itermeans_count = np.mean(res_count, axis=0)
    itermeans_conc = np.mean(res_conc, axis=0)

    ########################################################################

    tpnt_compare = [100, 150]

    passed = True
    max_err = 0.0

    for t in tpnt_compare:
        bin_n = 50

        r_min = 0
        r_max = 0

        for i in tridists:
            if (i > r_max): r_max = i
            if (i < r_min): r_min = i

        r_seg = (r_max - r_min) / bin_n
        bin_mins = np.zeros(bin_n + 1)
        r_tris_binned = np.zeros(bin_n)
        bin_areas = np.zeros(bin_n)

        r = r_min
        for b in range(bin_n + 1):
            bin_mins[b] = r
            if (b != bin_n): r_tris_binned[b] = r + r_seg / 2.0
            r += r_seg
        bin_counts = [None] * bin_n
        for i in range(bin_n):
            bin_counts[i] = []
        for i in range((itermeans_count[t].size)):
            i_r = tridists[i]
            for b in range(bin_n):
                if (i_r >= bin_mins[b] and i_r < bin_mins[b + 1]):
                    bin_counts[b].append(itermeans_count[t][i])
                    bin_areas[b] += sim.getTriArea(int(patch_tris[i]))
                    break

        bin_concs = np.zeros(bin_n)
        for c in range(bin_n):
            for d in range(bin_counts[c].__len__()):
                bin_concs[c] += bin_counts[c][d]
            bin_concs[c] /= (bin_areas[c] * 1.0e12)

        for i in range(bin_n):
            if (r_tris_binned[i] > -10.0 and r_tris_binned[i] < -2.0) \
            or (r_tris_binned[i] > 2.0 and r_tris_binned[i] < 10.0):
                dist = r_tris_binned[i] * 1e-6
                det_conc = 1e-6 * (NINJECT / (4 * np.sqrt(
                    (np.pi * DCST * tpnts[t])))) * (np.exp(
                        (-1.0 * (dist * dist)) / (4 * DCST * tpnts[t])))
                steps_conc = bin_concs[i]
                assert tol_funcs.tolerable(det_conc, steps_conc, tolerance)
예제 #7
0
mesh = meshio.importAbaqus(MESH_FILE, 1e-6)[0]

metis.tetmesh2metis(mesh, 'meshes/partition/fullcell.metis')

from subprocess import call
print "Generate partition for desktop computer (from 2 cores to 10 cores)"
for i in range(2, 11, 2):
    call([
        'mpmetis', '-ncommon=3', '-minconn', '-niter=1000',
        'meshes/partition/fullcell.metis',
        '%i' % (i)
    ])
    metis_parts = metis.readPartition(
        'meshes/partition/fullcell.metis.epart.%i' % (i))
    surf_tris = mesh.getSurfTris()
    tri_parts = gd.partitionTris(mesh, metis_parts, surf_tris)
    gd.printPartitionStat(metis_parts, tri_parts)

print "Generate partition for supercomputer (from 100 cores to 2000 cores)"
for i in range(2100, 5001, 100):
    call([
        'mpmetis', '-ncommon=3', '-minconn', '-niter=1000',
        'meshes/partition/fullcell.metis',
        '%i' % (i)
    ])
    metis_parts = metis.readPartition(
        'meshes/partition/fullcell.metis.epart.%i' % (i))
    surf_tris = mesh.getSurfTris()
    tri_parts = gd.partitionTris(mesh, metis_parts, surf_tris)
    gd.printPartitionStat(metis_parts, tri_parts)
예제 #8
0
def run_sim():
    # Set up and run the simulations once, before the tests
    # analyze the results.

    ##################### First order irreversible #########################

    global KCST_foi, N_foi, tolerance_foi

    KCST_foi = 5  # The reaction constant
    N_foi = 50  # Can set count or conc

    NITER_foi = 100000  # The number of iterations

    # Tolerance for the comparison:
    # In test runs, with good code, < 1%  will fail with a 1.5% tolerance
    tolerance_foi = 2.0 / 100

    ####################### First order reversible #########################

    global KCST_f_for, KCST_b_for, COUNT_for, tolerance_for

    KCST_f_for = 10.0  # The reaction constant
    KCST_b_for = 2.0

    COUNT_for = 100000  # Can set count or conc

    NITER_for = 10  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance_for = 1.0 / 100

    ####################### Second order irreversible A2 ###################

    global KCST_soA2, CONCA_soA2, tolerance_soA2

    KCST_soA2 = 10.0e6  # The reaction constant

    CONCA_soA2 = 10.0e-6

    NITER_soA2 = 1000  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 2%
    tolerance_soA2 = 3.0 / 100

    ####################### Second order irreversible AA ###################

    global KCST_soAA, CONCA_soAA, CONCB_soAA, tolerance_soAA

    KCST_soAA = 5.0e6  # The reaction constant

    CONCA_soAA = 20.0e-6
    CONCB_soAA = CONCA_soAA

    NITER_soAA = 1000  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance_soAA = 2.0 / 100

    ####################### Second order irreversible AB ###################

    global KCST_soAB, CONCA_soAB, CONCB_soAB, tolerance_soAB

    KCST_soAB = 5.0e6  # The reaction constant

    CONCA_soAB = 1.0e-6
    n_soAB = 2
    CONCB_soAB = CONCA_soAB / n_soAB

    NITER_soAB = 1000  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance_soAB = 1.0 / 100

    ####################### Third order irreversible A3 ###################

    global KCST_toA3, CONCA_toA3, tolerance_toA3

    KCST_toA3 = 1.0e12  # The reaction constant

    CONCA_toA3 = 10.0e-6

    NITER_toA3 = 1000  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance_toA3 = 3.0 / 100

    ####################### Third order irreversible A2B ###################

    global KCST_toA2B, CONCA_toA2B, CONCB_toA2B, tolerance_toA2B

    KCST_toA2B = 0.1e12  # The reaction constant

    CONCA_toA2B = 30.0e-6
    CONCB_toA2B = 20.0e-6

    NITER_toA2B = 1000  # The number of iterations

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance_toA2B = 1.0 / 100

    ####################### Second order irreversible 2D ###################

    global COUNTA_so2d, COUNTB_so2d, CCST_so2d, tolerance_so2d

    COUNTA_so2d = 100.0
    n_so2d = 2.0
    COUNTB_so2d = COUNTA_so2d / n_so2d

    KCST_so2d = 10.0e10  # The reaction constant

    AREA_so2d = 10.0e-12

    NITER_so2d = 1000  # The number of iterations

    # In tests fewer than 0.1% fail with tolerance of 2%
    tolerance_so2d = 2.0 / 100

    ############################ Common parameters ########################

    global VOL

    DT = 0.1  # Sampling time-step
    INT = 1.1  # Sim endtime

    NITER_max = 100000

    ########################################################################

    mdl = smod.Model()
    volsys = smod.Volsys('vsys', mdl)
    surfsys = smod.Surfsys('ssys', mdl)

    # First order irreversible
    A_foi = smod.Spec('A_foi', mdl)
    A_foi_diff = smod.Diff('A_foi_diff', volsys, A_foi, 0.01e-12)
    R1_foi = smod.Reac('R1_foi', volsys, lhs=[A_foi], rhs=[], kcst=KCST_foi)

    # First order reversible
    A_for = smod.Spec('A_for', mdl)
    B_for = smod.Spec('B_for', mdl)
    A_for_diff = smod.Diff('A_for_diff', volsys, A_for, 0.01e-12)
    B_for_diff = smod.Diff('B_for_diff', volsys, B_for, 0.01e-12)
    R1_for = smod.Reac('R1_for',
                       volsys,
                       lhs=[A_for],
                       rhs=[B_for],
                       kcst=KCST_f_for)
    R2_for = smod.Reac('R2_for',
                       volsys,
                       lhs=[B_for],
                       rhs=[A_for],
                       kcst=KCST_b_for)

    # Second order irreversible A2
    A_soA2 = smod.Spec('A_soA2', mdl)
    C_soA2 = smod.Spec('C_soA2', mdl)
    A_soA2_diff = smod.Diff('A_soA2_diff', volsys, A_soA2, 1e-12)
    R1_soA2 = smod.Reac('R1_soA2',
                        volsys,
                        lhs=[A_soA2, A_soA2],
                        rhs=[C_soA2],
                        kcst=KCST_soA2)

    # Second order irreversible AA
    A_soAA = smod.Spec('A_soAA', mdl)
    B_soAA = smod.Spec('B_soAA', mdl)
    C_soAA = smod.Spec('C_soAA', mdl)
    A_soAA_diff = smod.Diff('A_soAA_diff', volsys, A_soAA, 0.2e-12)
    B_soAA_diff = smod.Diff('B_soAA_diff', volsys, B_soAA, 0.2e-12)
    R1_soAA = smod.Reac('R1_soAA',
                        volsys,
                        lhs=[A_soAA, B_soAA],
                        rhs=[C_soAA],
                        kcst=KCST_soAA)

    # Second order irreversible AB
    A_soAB = smod.Spec('A_soAB', mdl)
    B_soAB = smod.Spec('B_soAB', mdl)
    C_soAB = smod.Spec('C_soAB', mdl)
    A_soAB_diff = smod.Diff('A_soAB_diff', volsys, A_soAB, 0.1e-12)
    B_soAB_diff = smod.Diff('B_soAB_diff', volsys, B_soAB, 0.1e-12)
    R1_soAB = smod.Reac('R1_soAB',
                        volsys,
                        lhs=[A_soAB, B_soAB],
                        rhs=[C_soAB],
                        kcst=KCST_soAB)

    # Third order irreversible A3
    A_toA3 = smod.Spec('A_toA3', mdl)
    C_toA3 = smod.Spec('C_toA3', mdl)
    A_soA3_diff = smod.Diff('A_soA3_diff', volsys, A_toA3, 0.2e-12)
    R1_toA3 = smod.Reac('R1_toA3',
                        volsys,
                        lhs=[A_toA3, A_toA3, A_toA3],
                        rhs=[C_toA3],
                        kcst=KCST_toA3)

    # Third order irreversible A2B
    A_toA2B = smod.Spec('A_toA2B', mdl)
    B_toA2B = smod.Spec('B_toA2B', mdl)
    C_toA2B = smod.Spec('C_toA2B', mdl)
    A_soA2B_diff = smod.Diff('A_soA2B_diff', volsys, A_toA2B, 0.1e-12)
    B_soA2B_diff = smod.Diff('B_soA2B_diff', volsys, B_toA2B, 0.1e-12)
    R1_toA3 = smod.Reac('R1_toA2B',
                        volsys,
                        lhs=[A_toA2B, A_toA2B, B_toA2B],
                        rhs=[C_toA2B],
                        kcst=KCST_toA2B)

    # Second order irreversible 2D
    A_so2d = smod.Spec('A_so2d', mdl)
    B_so2d = smod.Spec('B_so2d', mdl)
    C_so2d = smod.Spec('C_so2d', mdl)
    A_so2d_diff = smod.Diff('A_so2d_diff', surfsys, A_so2d, 1.0e-12)
    B_so2d_diff = smod.Diff('B_so2d_diff', surfsys, B_so2d, 1.0e-12)
    SR1_so2d = smod.SReac('SR1_so2d',
                          surfsys,
                          slhs=[A_so2d, B_so2d],
                          srhs=[C_so2d],
                          kcst=KCST_so2d)

    mesh = smeshio.importAbaqus(
        'validation_rd_mpi/meshes/sphere_rad1_37tets.inp', 1e-6)[0]
    VOL = mesh.getMeshVolume()

    comp1 = sgeom.TmComp('comp1', mesh, range(mesh.ntets))
    comp1.addVolsys('vsys')
    patch_tris = mesh.getSurfTris()
    patch1 = sgeom.TmPatch('patch1', mesh, patch_tris, comp1)
    patch1.addSurfsys('ssys')

    CCST_so2d = KCST_so2d / (6.02214179e23 * patch1.getArea())

    rng = srng.create('r123', 512)
    rng.initialize(100)

    tet_hosts = gd.binTetsByAxis(mesh, steps.mpi.nhosts)
    tri_hosts = gd.partitionTris(mesh, tet_hosts, patch_tris)

    sim = ssolv.TetOpSplit(mdl, mesh, rng, ssolv.EF_NONE, tet_hosts, tri_hosts)
    sim.reset()

    global tpnts, ntpnts
    tpnts = numpy.arange(0.0, INT, DT)
    ntpnts = tpnts.shape[0]

    res_m_foi = numpy.zeros([NITER_foi, ntpnts, 1])
    res_std1_foi = numpy.zeros([ntpnts, 1])
    res_std2_foi = numpy.zeros([ntpnts, 1])

    res_m_for = numpy.zeros([NITER_for, ntpnts, 2])

    res_m_soA2 = numpy.zeros([NITER_soA2, ntpnts, 2])

    res_m_soAA = numpy.zeros([NITER_soAA, ntpnts, 3])

    res_m_soAB = numpy.zeros([NITER_soAB, ntpnts, 3])

    res_m_toA3 = numpy.zeros([NITER_toA3, ntpnts, 2])

    res_m_toA2B = numpy.zeros([NITER_toA2B, ntpnts, 3])

    res_m_so2d = numpy.zeros([NITER_so2d, ntpnts, 3])

    for i in range(0, NITER_max):
        sim.reset()

        if i < NITER_foi:
            sim.setCompCount('comp1', 'A_foi', N_foi)

        if i < NITER_for:
            sim.setCompCount('comp1', 'A_for', COUNT_for)
            sim.setCompCount('comp1', 'B_for', 0.0)

        if i < NITER_soA2:
            sim.setCompConc('comp1', 'A_soA2', CONCA_soA2)

        if i < NITER_soAA:
            sim.setCompConc('comp1', 'A_soAA', CONCA_soAA)
            sim.setCompConc('comp1', 'B_soAA', CONCB_soAA)

        if i < NITER_soAB:
            sim.setCompConc('comp1', 'A_soAB', CONCA_soAB)
            sim.setCompConc('comp1', 'B_soAB', CONCB_soAB)

        if i < NITER_toA3:
            sim.setCompConc('comp1', 'A_toA3', CONCA_toA3)

        if i < NITER_toA2B:
            sim.setCompConc('comp1', 'A_toA2B', CONCA_toA2B)
            sim.setCompConc('comp1', 'B_toA2B', CONCB_toA2B)

        if i < NITER_so2d:
            sim.setPatchCount('patch1', 'A_so2d', COUNTA_so2d)
            sim.setPatchCount('patch1', 'B_so2d', COUNTB_so2d)

        for t in range(0, ntpnts):
            sim.run(tpnts[t])

            if i < NITER_foi:
                res_m_foi[i, t, 0] = sim.getCompCount('comp1', 'A_foi')

            if i < NITER_for:
                res_m_for[i, t, 0] = sim.getCompConc('comp1', 'A_for') * 1e6
                res_m_for[i, t, 1] = sim.getCompConc('comp1', 'B_for') * 1e6

            if i < NITER_soA2:
                res_m_soA2[i, t, 0] = sim.getCompConc('comp1', 'A_soA2')

            if i < NITER_soAA:
                res_m_soAA[i, t, 0] = sim.getCompConc('comp1', 'A_soAA')
                res_m_soAA[i, t, 1] = sim.getCompConc('comp1', 'B_soAA')

            if i < NITER_soAB:
                res_m_soAB[i, t, 0] = sim.getCompConc('comp1', 'A_soAB')
                res_m_soAB[i, t, 1] = sim.getCompConc('comp1', 'B_soAB')

            if i < NITER_toA3:
                res_m_toA3[i, t, 0] = sim.getCompConc('comp1', 'A_toA3')

            if i < NITER_toA2B:
                res_m_toA2B[i, t, 0] = sim.getCompConc('comp1', 'A_toA2B')
                res_m_toA2B[i, t, 1] = sim.getCompConc('comp1', 'B_toA2B')
                res_m_toA2B[i, t, 2] = sim.getCompConc('comp1', 'C_toA2B')

            if i < NITER_so2d:
                res_m_so2d[i, t, 0] = sim.getPatchCount('patch1', 'A_so2d')
                res_m_so2d[i, t, 1] = sim.getPatchCount('patch1', 'B_so2d')

    global mean_res_foi, std_res_foi
    mean_res_foi = numpy.mean(res_m_foi, 0)
    std_res_foi = numpy.std(res_m_foi, 0)

    global mean_res_for
    mean_res_for = numpy.mean(res_m_for, 0)

    global mean_res_soA2
    mean_res_soA2 = numpy.mean(res_m_soA2, 0)

    global mean_res_soAA
    mean_res_soAA = numpy.mean(res_m_soAA, 0)

    global mean_res_soAB
    mean_res_soAB = numpy.mean(res_m_soAB, 0)

    global mean_res_toA3
    mean_res_toA3 = numpy.mean(res_m_toA3, 0)

    global mean_res_toA2B
    mean_res_toA2B = numpy.mean(res_m_toA2B, 0)

    global mean_res_so2d
    mean_res_so2d = numpy.mean(res_m_so2d, 0)

    global ran_sim
    ran_sim = True
    def setUp(self):
        mdl = smodel.Model()

        S1 = smodel.Spec('S1', mdl)

        vsys = smodel.Volsys('vsys', mdl)
        ssys = smodel.Surfsys('ssys', mdl)

        smodel.Reac('R01', vsys, lhs=[S1], rhs=[S1], kcst=1)
        smodel.SReac('SR01', ssys, slhs=[S1], srhs=[S1], kcst=1)

        vrange = [-200.0e-3, 50e-3, 1e-3]
        vrate = lambda v: 2.0
        Chan1 = smodel.Chan('Chan1', mdl)
        chanop = smodel.ChanState('chanop', mdl, Chan1)
        chancl = smodel.ChanState('chancl', mdl, Chan1)
        smodel.VDepSReac('VDSR01',
                         ssys,
                         slhs=[chancl],
                         srhs=[chanop],
                         k=vrate,
                         vrange=vrange)
        smodel.VDepSReac('VDSR02',
                         ssys,
                         srhs=[chancl],
                         slhs=[chanop],
                         k=vrate,
                         vrange=vrange)

        Chan1_Ohm_I = smodel.OhmicCurr('Chan1_Ohm_I',
                                       ssys,
                                       chanstate=chanop,
                                       g=20e-12,
                                       erev=-77e-3)

        if __name__ == "__main__":
            self.mesh = meshio.importAbaqus('meshes/test.inp', 1e-7)[0]
        else:
            self.mesh = meshio.importAbaqus(
                'missing_solver_methods_test/meshes/test.inp', 1e-7)[0]

        comp1 = sgeom.TmComp('comp1', self.mesh, range(self.mesh.countTets()))
        comp1.addVolsys('vsys')

        patch1 = sgeom.TmPatch('patch1', self.mesh, self.mesh.getSurfTris(),
                               comp1)
        patch1.addSurfsys('ssys')

        self.c1ROIInds = range(10)
        self.p1ROIInds = range(5)
        self.mesh.addROI('comp1ROI', sgeom.ELEM_TET, self.c1ROIInds)
        self.mesh.addROI('patch1ROI', sgeom.ELEM_TRI, self.p1ROIInds)

        membrane = sgeom.Memb('membrane', self.mesh, [patch1], opt_method=1)

        rng = srng.create('mt19937', 512)
        rng.initialize(1234)

        tet_hosts = gd.linearPartition(self.mesh, [1, 1, steps.mpi.nhosts])
        tri_hosts = gd.partitionTris(self.mesh, tet_hosts,
                                     self.mesh.getSurfTris())

        self.sim = ssolver.TetOpSplit(mdl, self.mesh, rng, ssolver.EF_DEFAULT,
                                      tet_hosts, tri_hosts)
        self.sim.setEfieldDT(1e-4)

        self.sim.reset()
예제 #10
0
    mdl = smodel.Model()
    X = smodel.Spec('X', mdl)
    ssys = smodel.Surfsys('ssys', mdl)
    diff_X = smodel.Diff('diffX', ssys, X,  DCST)
    
    return mdl

########################################################################

mesh = smeshio.loadMesh('meshes/coin_10r_1h_13861')[0]

ntets = mesh.countTets()
comp = stetmesh.TmComp('cyto', mesh, range(ntets))
tet_hosts = gd.linearPartition(mesh, [steps.mpi.nhosts, 1, 1])
alltris = mesh.getSurfTris()
tri_hosts = gd.partitionTris(mesh, tet_hosts, alltris)

# Sort patch triangles as those of positive z: A +ve x, B -ve x
patchA_tris = []
patchB_tris = []
patchA_bars = set()
patchB_bars = set()

for t in alltris:
    vert0, vert1, vert2 = mesh.getTri(t)
    if (mesh.getVertex(vert0)[2] > 0.0 \
        and mesh.getVertex(vert1)[2] > 0.0 \
        and mesh.getVertex(vert2)[2] > 0.0):
        if mesh.getTriBarycenter(t)[0] > 0.0:
            patchA_tris.append(t)
            bar = mesh.getTriBars(t)