Dear David,
Indeed, Wolfgang is correct. I gather that you’re trying to produce the sort of displacement field that you see in the attached image. This reference
C. Miehe. Computational micro-to-macro transitions for discretized micro-structures of hetero- geneous materials at finite strains based on the minimization of averaged incremental energy. Computer Methods in Applied Mechanics and Engineering, 192(5–6):559–591, January 2003. DOI: 10.1016/s0045- 7825(02)00564- 9.
gives a very tractable explanation on how to set up the problem in terms of a Lagrangian periodicity frame (and sets it up in such a way that you can use constraints to impose the periodicity).
The upshot of what’s described therein is that if you describe the microscopic displacement as the first order expansion
u = \bar{\Grad{u}}.X + \tilde{u},
where \bar{\Grad{u}} is the applied macroscopic displacement gradient (encompassing the shear that you wish to apply; also equal to the volume average of the microscopic displacement gradient) and \tilde{u} is the microscopic fluctuation field. So there is a superposition of the average field and the fluctuation field. Then the periodicity conditions for the microscopic displacement field are
[[u]] = \bar{\Grad{u}}.[[X]]
where [[ ... ]] is the jump of the field across the periodic interface and [[ X ]] is the difference in reference position between two points on the periodic interfaces.
So you can see that when you’re solving for the total displacement, there is indeed some “offset” the needs to be considered, i.e. an inhomogeneity in the constraints that you set.
You also need to impose some additional constraints on the “corner” vertices that describe the periodic frame in order to remove the rigid body modes.
However, if solving for the fluctuation field itself, i.e.
\tilde{u} = u - \bar{\Grad{u}}.X
then I believe (although I haven’t tried this myself) that the periodicity condition simplifies to
[[\tilde{u}]] = 0
and, as a post processing step, you then simply superimpose the solution with \bar{\Grad{u}}.X to get the total displacement.
I really recommend taking a look at that paper, and maybe some of the others that Miehe has written on the topic. I found them to be quite useful and enlightening. I do plan on adding a small function to do this in the future, as the same sort of description of periodic constraints applies at the very least to elasticity, magnetostatics and electrostatics.
I hope that this quick description helps compliments Wolfgang’s and David’s replies so that you can implement what you need!
Best,
Jean-Paul