\documentclass[tikz,border=5pt]{standalone}
\usepackage{amssymb}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.markings,arrows.meta,calc,fit,quotes,cd}
\tikzset{
oriented WD/.style={
every to/.style={out=0,in=180,draw},
label/.style={
font=\everymath\expandafter{\the\everymath\scriptstyle},
inner sep=0pt,
node distance=2pt and -2pt},
semithick,
node distance=1 and 1,
decoration={markings, mark=at position .5 with {\arrow{stealth};}},
ar/.style={postaction={decorate}},
execute at begin picture={\tikzset{
x=\bbx, y=\bby,
every fit/.style={inner xsep=\bbx, inner ysep=\bby}}}
},
bbx/.store in=\bbx,
bbx = 1.5cm,
bby/.store in=\bby,
bby = 1.75ex,
bb port sep/.store in=\bbportsep,
bb port sep=2,
bb port length/.store in=\bbportlen,
bb port length=4pt,
bb min width/.store in=\bbminwidth,
bb min width=1cm,
bb rounded corners/.store in=\bbcorners,
bb rounded corners=2pt,
bb small/.style={bb port sep=1, bb port length=2.5pt, bbx=.4cm, bb min width=.4cm, bby=.7ex},
bb/.code 2 args={
\pgfmathsetlengthmacro{\bbheight}{\bbportsep * (max(#1,#2)+1) * \bby}
\pgfkeysalso{draw,minimum height=\bbheight,minimum width=\bbminwidth,outer sep=0pt,
rounded corners=\bbcorners,thick,
prefix after command={\pgfextra{\let\fixname\tikzlastnode}},
append after command={\pgfextra{\draw
\ifnum #1=0{} \else foreach \i in {1,...,#1} {
($(\fixname.north west)!{\i/(#1+1)}!(\fixname.south west)$) +(-\bbportlen,0) coordinate (\fixname_in\i) -- +(\bbportlen,0) coordinate (\fixname_in\i')}\fi
\ifnum #2=0{} \else foreach \i in {1,...,#2} {
($(\fixname.north east)!{\i/(#2+1)}!(\fixname.south east)$) +(-\bbportlen,0) coordinate (\fixname_out\i') -- +(\bbportlen,0) coordinate (\fixname_out\i)}\fi;
}}}
},
bb name/.style={append after command={\pgfextra{\node[anchor=north] at (\fixname.north) {#1};}}}
}
\begin{document}
\begin{tikzpicture}[oriented WD, baseline=(Z.center), bbx = .5cm, bby =.8ex, bb min width=.5cm, bb port length=2pt, bb port sep=1]
\node[bb={1}{3}] (X11) {$\scriptstyle X_{11}$};
\node[bb={2}{1}, right=1.5 of X11] (X12) {$\scriptstyle X_{12}$};
\node[bb={3}{2}, below right=of X12] (X13) {$\scriptstyle X_{13}$};
\node[bb={2}{2}, fit={(X11) (X12) (X13) ($(X12.north)+(0,2)$) ($(X13.east)+(.5,0)$)}, dashed] (Y1) {};
\node[bb={2}{1}, below left=6 and 0 of X13] (X21) {$\scriptstyle X_{21}$};
\node[bb={0}{2},below left=of X21] (X22) {$\scriptstyle X_{22}$};
\node[bb={1}{2}, fit=(X21) (X22), dashed] (Y2) {};
\node[bb={2}{3}, fit={($(Y1.north)+(0,1)$) ($(Y2.south)-(0,1)$) ($(Y1.west)-(.25,0)$) ($(Y1.east)+(.25,0)$)}] (Z) {};
\draw[label]
node at ($(Y1.north west)+(.5,-2)$) {$Y_1$}
node at ($(Y2.north west)+(.5,-2)$) {$Y_2$}
node at ($(Z.north west)+(.5,-2)$) {$Z$};
\begin{scope}[gray]
\draw[ar] (Z_in1') to (Y1_in1);
\draw[ar] (Z_in2') to (Y2_in1);
\draw (Y2_in1') to[in looseness=2] (X21_in1);
\draw[ar] (X22_out1) to (X21_in2);
\draw (X22_out2) to (Y2_out2');
\draw[ar] (Y2_out2) to (Z_out3');
\draw (Y1_in1') to (X11_in1);
\draw (X13_out2) to (Y1_out2');
\draw (Y1_in2') to[in looseness=2] (X13_in3);
\draw (X11_out3) to[in looseness=2] (X13_in2);
\draw (X12_out1) to (X13_in1);
\draw (X11_out2) to (X12_in2);
\draw (Y1_out1) to (Z_out1');
\draw[ar] (Y1_out2) to (Z_out2');
\draw (X21_out1) to (Y2_out1');
\draw[ar] let \p1=(Y2.north east), \p2=(Y1.south west), \n1={\y1+2*\bby}, \n2=\bbportlen in
(Y2_out1) to[in=0] (\x1+\n2,\n1) -- (\x2-\n2,\n1) to[out=180] (Y1_in2);
\draw[ar] let \p1=(X13.north east), \p2=(X12.north west), \n1={\y2+\bby}, \n2=\bbportlen in
(X13_out1) to[in=0] (\x1+\n2,\n1) -- (\x2-\n2,\n1) to[out=180] (X12_in1);
\draw let \p1=(X12.north west), \p2=(X13.north east), \n1={\y1+2*\bby}, \n2=\bbportlen in
(X11_out1) to (\x1-2*\n2,\n1) -- (\x2+2*\n2,\n1) to[out=0] (Y1_out1');
\end{scope}
\end{tikzpicture}
\end{document}