Exemplo n.º 1
0
    def setUp(self):
        self.model = smodel.Model()
        A = smodel.Spec('A', self.model)
        volsys = smodel.Volsys('vsys', self.model)
        D_a = smodel.Diff('D_a', volsys, A)
        self.DCST = 0.2e-9
        D_a.setDcst(self.DCST)

        self.mesh = meshio.importAbaqus2("directional_dcst_test/mesh_tet.inp",
                                         "directional_dcst_test/mesh_tri.inp",
                                         1e-6,
                                         "directional_dcst_test/mesh_conf")[0]

        boundary_tris = self.mesh.getROIData("boundary")
        v1_tets = self.mesh.getROIData("v1_tets")
        v2_tets = self.mesh.getROIData("v2_tets")

        comp1 = sgeom.TmComp("comp1", self.mesh, v1_tets)
        comp2 = sgeom.TmComp("comp2", self.mesh, v2_tets)

        comp1.addVolsys("vsys")
        comp2.addVolsys("vsys")

        db = sgeom.DiffBoundary("boundary", self.mesh, boundary_tris)

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

        self.solver = solv.Tetexact(self.model, self.mesh, self.rng)
Exemplo n.º 2
0
def gen_geom():
    mesh = meshio.loadMesh('meshes/cyl_len10_diam1')[0]
    ntets = mesh.countTets()

    tets_compA = []
    tets_compB = []
    tris_compA = set()
    tris_compB = set()
    z_max = mesh.getBoundMax()[2]
    z_min = mesh.getBoundMin()[2]
    z_mid = z_min + (z_max - z_min) / 2.0

    for t in range(ntets):
        # Fetch the z coordinate of the barycenter
        barycz = mesh.getTetBarycenter(t)[2]
        # Fetch the triangle indices of the tetrahedron, a tuple of length 4:
        tris = mesh.getTetTriNeighb(t)
        if barycz < z_mid:
            tets_compA.append(t)
            tris_compA.add(tris[0])
            tris_compA.add(tris[1])
            tris_compA.add(tris[2])
            tris_compA.add(tris[3])
        else:
            tets_compB.append(t)
            tris_compB.add(tris[0])
            tris_compB.add(tris[1])
            tris_compB.add(tris[2])
            tris_compB.add(tris[3])

    # Create the mesh compartments
    compA = sgeom.TmComp('compA', mesh, tets_compA)
    compB = sgeom.TmComp('compB', mesh, tets_compB)
    compA.addVolsys('vsysA')
    compB.addVolsys('vsysB')

    # Make the diff boundary tris with the intersection and convert to list
    tris_DB = tris_compA.intersection(tris_compB)
    tris_DB = list(tris_DB)

    # Create the diffusion boundary between compA and compB
    diffb = sgeom.DiffBoundary('diffb', mesh, tris_DB)

    return mesh, tets_compA, tets_compB
Exemplo n.º 3
0
    else: 
        bcomptets.append(t)
        compbtris.add(tris[0])
        compbtris.add(tris[1])
        compbtris.add(tris[2])
        compbtris.add(tris[3])

dbset = compatris.intersection(compbtris)
dbtris = list(dbset)

compa = sgeom.TmComp('compa', mesh, acomptets)
compb = sgeom.TmComp('compb', mesh, bcomptets)
compa.addVolsys('vsys')
compb.addVolsys('vsys')

diffb = sgeom.DiffBoundary('diffb', mesh, dbtris)


# Now fill the array holding the tet indices to sample at random
assert(SAMPLE <= ntets)

numfilled = 0
while (numfilled < SAMPLE):
    tetidxs[numfilled] = numfilled
    numfilled +=1

# Now find the distance of the center of the tets to the Z lower face
for i in range(SAMPLE):
	baryc = mesh.getTetBarycenter(int(tetidxs[i]))
	r = baryc[0]
	tetrads[i] = r*1.0e6
Exemplo n.º 4
0
def test_kisilevich():
    "Reaction-diffusion - Degradation-diffusion (Parallel TetOpSplit)"

    NITER = 50  # The number of iterations
    DT = 0.1  # Sampling time-step
    INT = 0.3  # Sim endtime

    DCSTA = 400 * 1e-12
    DCSTB = DCSTA
    RCST = 100000.0e6

    #NA0 = 100000    # 1000000            # Initial number of A molecules
    NA0 = 1000
    NB0 = NA0  # Initial number of B molecules

    SAMPLE = 1686

    # <1% fail with a tolerance of 7.5%
    tolerance = 7.5 / 100

    # create the array of tet indices to be found at random
    tetidxs = numpy.zeros(SAMPLE, dtype='int')
    # further create the array of tet barycentre distance to centre
    tetrads = numpy.zeros(SAMPLE)

    mdl = smod.Model()

    A = smod.Spec('A', mdl)
    B = smod.Spec('B', mdl)

    volsys = smod.Volsys('vsys', mdl)

    R1 = smod.Reac('R1', volsys, lhs=[A, B], rhs=[])

    R1.setKcst(RCST)

    D_a = smod.Diff('D_a', volsys, A)
    D_a.setDcst(DCSTA)
    D_b = smod.Diff('D_b', volsys, B)
    D_b.setDcst(DCSTB)

    mesh = meshio.loadMesh('validation_rd_mpi/meshes/brick_40_4_4_1686tets')[0]

    VOLA = mesh.getMeshVolume() / 2.0
    VOLB = VOLA

    ntets = mesh.countTets()

    acomptets = []
    bcomptets = []
    max = mesh.getBoundMax()
    min = mesh.getBoundMax()
    midz = 0.0
    compatris = set()
    compbtris = set()
    for t in range(ntets):
        barycz = mesh.getTetBarycenter(t)[0]
        tris = mesh.getTetTriNeighb(t)
        if barycz < midz:
            acomptets.append(t)
            compatris.add(tris[0])
            compatris.add(tris[1])
            compatris.add(tris[2])
            compatris.add(tris[3])
        else:
            bcomptets.append(t)
            compbtris.add(tris[0])
            compbtris.add(tris[1])
            compbtris.add(tris[2])
            compbtris.add(tris[3])

    dbset = compatris.intersection(compbtris)
    dbtris = list(dbset)

    compa = sgeom.TmComp('compa', mesh, acomptets)
    compb = sgeom.TmComp('compb', mesh, bcomptets)
    compa.addVolsys('vsys')
    compb.addVolsys('vsys')

    diffb = sgeom.DiffBoundary('diffb', mesh, dbtris)

    # Now fill the array holding the tet indices to sample at random
    assert (SAMPLE <= ntets)

    numfilled = 0
    while (numfilled < SAMPLE):
        tetidxs[numfilled] = numfilled
        numfilled += 1

    # Now find the distance of the centre of the tets to the Z lower face
    for i in range(SAMPLE):
        baryc = mesh.getTetBarycenter(int(tetidxs[i]))
        r = baryc[0]
        tetrads[i] = r * 1.0e6

    Atets = acomptets
    Btets = bcomptets

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

    tet_hosts = gd.binTetsByAxis(mesh, steps.mpi.nhosts)
    sim = solvmod.TetOpSplit(mdl, mesh, rng, False, tet_hosts)

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

    resA = numpy.zeros((NITER, ntpnts, SAMPLE))
    resB = numpy.zeros((NITER, ntpnts, SAMPLE))

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

        sim.setDiffBoundaryDiffusionActive('diffb', 'A', True)
        sim.setDiffBoundaryDiffusionActive('diffb', 'B', True)

        sim.setCompCount('compa', 'A', NA0)
        sim.setCompCount('compb', 'B', NB0)

        for t in range(0, ntpnts):
            sim.run(tpnts[t])
            for k in range(SAMPLE):
                resA[i, t, k] = sim.getTetCount(int(tetidxs[k]), 'A')
                resB[i, t, k] = sim.getTetCount(int(tetidxs[k]), 'B')

    itermeansA = numpy.mean(resA, axis=0)
    itermeansB = numpy.mean(resB, axis=0)

    def getdetc(t, x):
        N = 1000  # The number to represent infinity in the exponential calculation
        L = 20e-6

        concA = 0.0
        for n in range(N):
            concA += ((1.0 / (2 * n + 1)) * math.exp(
                (-(DCSTA / (20.0e-6)) * math.pow(
                    (2 * n + 1), 2) * math.pow(math.pi, 2) * t) / (4 * L)) *
                      math.sin(((2 * n + 1) * math.pi * x) / (2 * L)))
        concA *= ((4 * NA0 / math.pi) / (VOLA * 6.022e26)) * 1.0e6

        return concA

    tpnt_compare = [1, 2]
    passed = True
    max_err = 0.0

    for tidx in tpnt_compare:
        NBINS = 10
        radmax = 0.0
        radmin = 10.0
        for r in tetrads:
            if (r > radmax): radmax = r
            if (r < radmin): radmin = r

        rsec = (radmax - radmin) / NBINS
        binmins = numpy.zeros(NBINS + 1)
        tetradsbinned = numpy.zeros(NBINS)
        r = radmin
        bin_vols = numpy.zeros(NBINS)

        for b in range(NBINS + 1):
            binmins[b] = r
            if (b != NBINS): tetradsbinned[b] = r + rsec / 2.0
            r += rsec

        bin_countsA = [None] * NBINS
        bin_countsB = [None] * NBINS
        for i in range(NBINS):
            bin_countsA[i] = []
            bin_countsB[i] = []
        filled = 0

        for i in range(itermeansA[tidx].size):
            irad = tetrads[i]

            for b in range(NBINS):
                if (irad >= binmins[b] and irad < binmins[b + 1]):
                    bin_countsA[b].append(itermeansA[tidx][i])
                    bin_vols[b] += sim.getTetVol(int(tetidxs[i]))
                    filled += 1.0
                    break
        filled = 0
        for i in range(itermeansB[tidx].size):
            irad = tetrads[i]

            for b in range(NBINS):
                if (irad >= binmins[b] and irad < binmins[b + 1]):
                    bin_countsB[b].append(itermeansB[tidx][i])
                    filled += 1.0
                    break

        bin_concsA = numpy.zeros(NBINS)
        bin_concsB = numpy.zeros(NBINS)

        for c in range(NBINS):
            for d in range(bin_countsA[c].__len__()):
                bin_concsA[c] += bin_countsA[c][d]
            for d in range(bin_countsB[c].__len__()):
                bin_concsB[c] += bin_countsB[c][d]

            bin_concsA[c] /= (bin_vols[c])
            bin_concsA[c] *= (1.0e-3 / 6.022e23) * 1.0e6
            bin_concsB[c] /= (bin_vols[c])
            bin_concsB[c] *= (1.0e-3 / 6.022e23) * 1.0e6

        for i in range(NBINS):
            rad = abs(tetradsbinned[i]) * 1.0e-6

            if (tetradsbinned[i] < -5):
                # compare A
                det_conc = getdetc(tpnts[tidx], rad)
                steps_conc = bin_concsA[i]
                assert tol_funcs.tolerable(det_conc, steps_conc, tolerance)

            if (tetradsbinned[i] > 5):
                # compare B
                det_conc = getdetc(tpnts[tidx], rad)
                steps_conc = bin_concsB[i]
                assert tol_funcs.tolerable(det_conc, steps_conc, tolerance)
D_a = smodel.Diff('D_a', volsys, A)
D_a.setDcst(DCST)
    
mesh = meshio.importAbaqus2("mesh_tet.inp", "mesh_tri.inp", 1e-6, "mesh_conf")[0]
    
boundary_tris = mesh.getROIData("boundary")
v1_tets = mesh.getROIData("v1_tets")
v2_tets = mesh.getROIData("v2_tets")
    
comp1 = sgeom.TmComp("comp1", mesh, v1_tets)
comp2 = sgeom.TmComp("comp2", mesh, v2_tets)
    
comp1.addVolsys("vsys")
comp2.addVolsys("vsys")
    
db = sgeom.DiffBoundary("boundary", mesh, boundary_tris)
rng = srng.create('mt19937', 512)
rng.initialize(int(time.time()%4294967295))
    
solver = solv.Tetexact(model, mesh, rng)

print "Set directonal dcst from comp1 to comp2, and from comp2 to comp1 to 0..."
solver.setCompCount("comp1", "A", 100)
solver.setCompCount("comp2", "A", 20)
solver.setDiffBoundaryDcst("boundary", "A", 0)
print "V1 Count: ", solver.getCompCount("comp1", "A")
print "V2 Count: ", solver.getCompCount("comp2", "A")
solver.run(1)
print "V1 Count: ", solver.getCompCount("comp1", "A")
print "V2 Count: ", solver.getCompCount("comp2", "A")