periodic boundary for manually created multi-block

Hi, everyone
For some reason, I need to manually create multi block structure and apply periodic boundary condition in some directions of the system. I used ExplicitThreadAttribution to associate blocks to MPI processes. When I turn off periodic boundary conditions, the system is fine. But when I use periodic boundary condition, I get segmentation fault as soon as collideAndStream. Anyone can help me with it? Thanks in advance.

Here is the function I set up the system.

void init_system (OnLatticeAdvectionDiffusionBoundaryCondition3D<T,ADESCRIPTOR>& boundaryCondition)
//set sparse structure of the system, phase is a scalar field initialized with periodic boundary condtion in 0, and 1 directions.
SparseBlockStructure3D sparseBlock(phase->getBoundingBox());

delete phase;

plint numBlocks = calculationBoxes.size();

//add blocks
for(plint iBlock = 0; iBlock < numBlocks; ++iBlock)
    sparseBlock.addBlock(calculationBoxes[iBlock], sparseBlock.nextIncrementalId());

// In case of MPI parallelism, the blocks are explicitly assigned to processors,
// with equal load.
ExplicitThreadAttribution* threadAttribution = new ExplicitThreadAttribution;
std::vector<std::pair<plint,plint> > ranges;
plint numRanges = std::min(numBlocks, (plint)global::mpi().getSize());
util::linearRepartition(0, numBlocks-1, numRanges, ranges);
for (pluint iProc=0; iProc<ranges.size(); ++iProc) {
    for (plint blockId=ranges[iProc].first; blockId<=ranges[iProc].second; ++blockId) {
        threadAttribution -> addBlock(blockId, iProc);

//setup sparse lattice field, initialize bounceback contions and then change the dynamics in each calculation domains
lattice_lipid = new MultiBlockLattice3D<T, ADESCRIPTOR> (MultiBlockManagement3D (
                                                                                sparseBlock, threadAttribution, envelopeWidth ),
                                                         new BounceBack<T,ADESCRIPTOR>);
pcout << getMultiBlockInfo(*lattice_lipid) << std::endl;
parameters << getMultiBlockInfo(*lattice_lipid) << std::endl;

//periodic boundary, this part leads to segmentation fault.
lattice_lipid->periodicity().toggle(0, true);
lattice_lipid->periodicity().toggle(1, true);

//define dynamics
for(plint iBlock = 0; iBlock < calculationBoxes.size(); ++iBlock)
    defineDynamics(*lattice_lipid, calculationBoxes[iBlock], new ADYNAMICS<T,ADESCRIPTOR>(omega_lipid));

//setup boundary conditions
boundaryCondition.addTemperatureBoundary2N (inlet, *lattice_lipid);
boundaryCondition.addTemperatureBoundary2P (outlet, *lattice_lipid);
setBoundaryDensity (*lattice_lipid, inletFlowBoundary, patchCon);
setBoundaryDensity (*lattice_lipid, outlet, epidermicsCon);

initializeAtEquilibrium(*lattice_lipid, lattice_lipid->getBoundingBox(), (T)0.000001, velocity);

lattice_lipid->initialize ();