[Tex/LaTex] How to draw a grid on a shape made of curved lines

diagramstikz-pgf

I am a new user of the Tikz package and I would like to draw the image below using this package for my Thesis.enter image description here

I think I can create the first grid (left) because the lines are straight, however how could I draw the second grid of the deformed bar? Is there any way to 'deform' the first one or creating a grid from the deformed lines?
Also, regarding the 'zoomed' details: is there any 'automatic' way to draw it using Tikz (I mean like a real zoom of the figure)? Or should I create them separately?
Thanks in advance for any help!

Best Answer

It's a bit fiddly getting the non-linear transformation stuff working in pgf but it can more-or-less do what is required along with the spy library:

\documentclass[tikz,margin=5]{standalone}
\usepgfmodule{nonlineartransformations}
\usepgflibrary{curvilinear}
\usetikzlibrary{spy,calc}
\tikzset{pics/grid/.style={code={%
  \tikzset{x=10pt, y=10pt, step=10pt}
  \draw [thin] (-2, 0) grid ++(4, 20);
  \draw [thick] (-2, 0) rectangle ++(4, 20) (-4, 0) -- (4, 0);
  \draw [thick, fill=gray!50] (0,14) rectangle ++(1,1)
   ++(-.5,-.5) coordinate (-square);
  \draw [<->, thin, gray] (0,14) -- ++(1,1); 
  \coordinate (-corner) at (-2, 20);
}}}
\begin{document}
\begin{tikzpicture}[>=stealth,
  spy using outlines={circle, magnification=3, size=2.5cm, connect spies}]
\pic (a) {grid};
\draw [->, thick, shorten >=5] (a-corner) ++(-1,0)  -- (a-corner);
\spy [red] on (a-square) in node at ($(a-square)+(2.5,0)$);
\scoped{
  \pgfsetcurvilinearbeziercurve
    {\pgfpointxy{5}{0}}{\pgfpointxy{5}{10}}
    {\pgfpointxy{25}{15}}{\pgfpointxy{25}{20}}
  \pgftransformnonlinear{\pgfgetlastxy\x\y%
    \pgfpointcurvilinearbezierorthogonal{\y}{-\x}}%
  \pic (b) {grid};
}
\draw [->, thick, shorten >=5] (b-corner) ++(-1,0) -- (b-corner);
\spy [red] on (b-square) in node at ($(b-square)+(2.5,0)$);
\end{tikzpicture}
\end{document}

enter image description here