Beispiel #1
0
    def test_tribend(self):
        self.system.actors.clear()
        # two triangles with bending interaction
        # move nodes, should relax back

        system = self.system
        system.virtual_sites = VirtualSitesInertialessTracers()

        system.part.clear()

        # Add four particles
        system.part.add(id=0, pos=[5, 5, 5], virtual=1)
        system.part.add(id=1, pos=[5, 5, 6], virtual=1)
        system.part.add(id=2, pos=[5, 6, 6], virtual=1)
        system.part.add(id=3, pos=[5, 6, 5], virtual=1)

        # Add first triel, weak modulus
        from espressomd.interactions import IBM_Triel
        tri1 = IBM_Triel(
            ind1=0, ind2=1, ind3=2, elasticLaw="Skalak", k1=0.1, k2=0, maxDist=2.4)
        system.bonded_inter.add(tri1)
        system.part[0].add_bond((tri1, 1, 2))

        # Add second triel
        tri2 = IBM_Triel(
            ind1=0, ind2=2, ind3=3, elasticLaw="Skalak", k1=10, k2=0, maxDist=2.4)
        system.bonded_inter.add(tri2)
        system.part[0].add_bond((tri2, 2, 3))

        # Add bending
        from espressomd.interactions import IBM_Tribend
        tribend = IBM_Tribend(
            ind1=0, ind2=1, ind3=2, ind4=3, kb=1, refShape="Initial")
        system.bonded_inter.add(tribend)
        system.part[0].add_bond((tribend, 1, 2, 3))

        # twist
        system.part[1].pos = [5.2, 5, 6]

        self.reset_lb()

        # Perform integration
        last_angle = self.compute_angle()
        for i in range(6):
            system.integrator.run(430)
            angle = self.compute_angle()
            self.assertLess(angle, last_angle)
            last_angle = angle
        self.assertLess(angle, 0.03)
Beispiel #2
0
def AddSoft(system, comX, comY, comZ, k1, k2):

    # currently only works for ONE SINGLE soft object

    # open file and add nodes
    with open("tables/softPositions", "r") as fp:
        numPoints = int(fp.readline())
        print("Found {} nodes".format(numPoints))

        # actual add
        for i in range(0, numPoints):
            line = str.split(fp.readline())
            X = float(line[0]) + comX
            Y = float(line[1]) + comY
            Z = float(line[2]) + comZ
#            print X, Y, Z
            system.part.add(id=i, pos=[X, Y, Z], virtual=1)

    # triangles
    from espressomd.interactions import IBM_Triel
    with open("tables/softTriangles", "r") as fp:
        numTri = int(fp.readline())
        print("Found {} triangles".format(numTri))
        # actual add
        for i in range(0, numTri):
            line = str.split(fp.readline())
            id1 = int(line[0])
            id2 = int(line[1])
            id3 = int(line[2])
            tri = IBM_Triel(ind1=id1, ind2=id2, ind3=id3,
                            elasticLaw="Skalak", k1=k1, k2=k2, maxDist=5)
            system.bonded_inter.add(tri)
            system.part[id1].add_bond((tri, id2, id3))
Beispiel #3
0
    def test_triel(self):
        self.system.actors.clear()
        system = self.system
        system.virtual_sites = VirtualSitesInertialessTracers()
        system.virtual_sites = VirtualSitesInertialessTracers()

        system.part.clear()
        # Add particles: 0-2 are non-bonded, 3-5 are weakly bonded, 6-8 are
        # strongly bonded
        system.part.add(id=0, pos=[5, 5, 5], virtual=True)
        system.part.add(id=1, pos=[5, 5, 6], virtual=True)
        system.part.add(id=2, pos=[5, 6, 6], virtual=True)

        system.part.add(id=3, pos=[2, 5, 5], virtual=True)
        system.part.add(id=4, pos=[2, 5, 6], virtual=True)
        system.part.add(id=5, pos=[2, 6, 6], virtual=True)

        system.part.add(id=6, pos=[4, 7, 7], virtual=True)
        system.part.add(id=7, pos=[4, 7, 8], virtual=True)
        system.part.add(id=8, pos=[4, 8, 8], virtual=True)

        # Add triel, weak modulus for 3-5
        from espressomd.interactions import IBM_Triel
        triWeak = IBM_Triel(ind1=3,
                            ind2=4,
                            ind3=5,
                            elasticLaw="Skalak",
                            k1=5,
                            k2=0,
                            maxDist=2.4)
        system.bonded_inter.add(triWeak)
        system.part[3].add_bond((triWeak, 4, 5))

        # Add triel, strong modulus for 6-8
        triStrong = IBM_Triel(ind1=6,
                              ind2=7,
                              ind3=8,
                              elasticLaw="Skalak",
                              k1=15,
                              k2=0,
                              maxDist=2.4)
        system.bonded_inter.add(triStrong)
        system.part[6].add_bond((triStrong, 7, 8))

        self.reset_lb(ext_force_density=[0.1, 0, 0])
        # Perform integration
        system.integrator.run(4500)

        # For the cpu variant, check particle velocities
        if isinstance(self.lbf, lb.LBFluid):  # as opposed to LBFluidGPU
            for p in system.part:
                np.testing.assert_allclose(
                    np.copy(p.v),
                    np.copy(self.lbf.get_interpolated_velocity(p.pos)),
                    atol=2E-2)
        # get new shapes
        dist1non = np.linalg.norm(
            np.array(system.part[1].pos - system.part[0].pos))
        dist2non = np.linalg.norm(
            np.array(system.part[2].pos - system.part[0].pos))

        dist1weak = np.linalg.norm(
            np.array(system.part[3].pos - system.part[4].pos))
        dist2weak = np.linalg.norm(
            np.array(system.part[3].pos - system.part[5].pos))

        dist1strong = np.linalg.norm(
            np.array(system.part[6].pos - system.part[7].pos))
        dist2strong = np.linalg.norm(
            np.array(system.part[6].pos - system.part[8].pos))

        print("** Distances: non-bonded, weak, strong, expected")
        print(
            str(dist1non) + "    " + str(dist1weak) + "     " +
            str(dist1strong) + "    1")
        print(
            str(dist2non) + "    " + str(dist2weak) + "     " +
            str(dist2strong) + "    1.414")

        # test:
        # non-bonded should move apart by the flow (control group)
        # weakly-bonded should stretch somewhat
        # strongly-bonded should basically not stretch
        self.assertGreater(dist1non, 1.5)
        self.assertAlmostEqual(dist1weak, 1, delta=0.2)
        self.assertAlmostEqual(dist1strong, 1, delta=0.04)

        self.assertGreater(dist2non, 2)
        self.assertAlmostEqual(dist2weak, np.sqrt(2), delta=0.3)
        self.assertAlmostEqual(dist2strong, np.sqrt(2), delta=0.1)
    def test_tribend(self):

        # two triangles with bending interaction
        # move nodes, should relax back

        system = self.system
        system.virtual_sites = VirtualSitesInertialessTracers()
        self.lbf.set_params(ext_force_density=(0.0, 0., 0.))
        self.stop_fluid()

        system.part.clear()

        ## Add four particles
        system.part.add(id=0, pos=[5, 5, 5], virtual=1)
        system.part.add(id=1, pos=[5, 5, 6], virtual=1)
        system.part.add(id=2, pos=[5, 6, 6], virtual=1)
        system.part.add(id=3, pos=[5, 6, 5], virtual=1)

        ## Add first triel, weak modulus
        from espressomd.interactions import IBM_Triel
        tri1 = IBM_Triel(ind1=0,
                         ind2=1,
                         ind3=2,
                         elasticLaw="Skalak",
                         k1=0.1,
                         k2=0,
                         maxDist=2.4)
        system.bonded_inter.add(tri1)
        system.part[0].add_bond((tri1, 1, 2))

        ## Add second triel
        tri2 = IBM_Triel(ind1=0,
                         ind2=2,
                         ind3=3,
                         elasticLaw="Skalak",
                         k1=10,
                         k2=0,
                         maxDist=2.4)
        system.bonded_inter.add(tri2)
        system.part[0].add_bond((tri2, 2, 3))

        ## Add bending
        from espressomd.interactions import IBM_Tribend
        tribend = IBM_Tribend(ind1=0,
                              ind2=1,
                              ind3=2,
                              ind4=3,
                              kb=1,
                              refShape="Initial")
        system.bonded_inter.add(tribend)
        system.part[0].add_bond((tribend, 1, 2, 3))

        ## output before
        print("Angle before twisting: " + str(self.compute_angle()))

        ## twist
        system.part[1].pos = [5.2, 5, 6]

        ## output after
        print("Angle after twisting: " + str(self.compute_angle()))

        ## Perform integrat[ion
        last_angle = self.compute_angle()
        for i in range(8):
            system.integrator.run(500)
            angle = self.compute_angle()
            print("Angle after relaxation: ", angle)
            self.assertLess(angle, last_angle)
            last_angle = angle

        self.assertLess(angle, 0.03)