def pre_construct(self):
    for a in range(self.nx()):
        tmp = [[], []]
        for i in range(self.L):
            (oid, amp) = self.SzSz(i, ((i + 1) % self.L), a)
            if (not (oid in tmp[0])):
                tmp[0].append(oid)
                tmp[1].append((amp * self.J))
            else:
                idx = tmp[0].index(oid)
                tmp[1][idx] += (amp * self.J)
            (oid, amp) = self.Sx(i, a)
            if (not (oid in tmp[0])):
                tmp[0].append(oid)
                tmp[1].append((amp * (- self.Hx)))
            else:
                idx = tmp[0].index(oid)
                tmp[1][idx] += (amp * (- self.Hx))
        for i in range(len(tmp[0])):
            self.set_elem(tmp[0][i], a, tmp[1][i])
def pre_construct(self):
    for a in range(self.nx()):
        tmp = [[], []]
        for i in range(self.L):
            (oid, amp) = self.SzSz(i, ((i + 1) % self.L), a)
            if (not (oid in tmp[0])):
                tmp[0].append(oid)
                tmp[1].append((amp * self.J))
            else:
                idx = tmp[0].index(oid)
                tmp[1][idx] += (amp * self.J)
            (oid, amp) = self.Sx(i, a)
            if (not (oid in tmp[0])):
                tmp[0].append(oid)
                tmp[1].append((amp * (- self.Hx)))
            else:
                idx = tmp[0].index(oid)
                tmp[1][idx] += (amp * (- self.Hx))
        for i in range(len(tmp[0])):
            self.set_elem(tmp[0][i], a, tmp[1][i])