Cohomology ring of mapping torus A mapping torus, $M \rtimes_\varphi
S^1$, is a fiber bundle over $S^1$ with fiber $M$,  where $\varphi$ is an element of mapping class group of $M$, describing the twist around $S^1$.
For $M=S^1\times S^1 = T^2$, where the two $S^1$ are parametrized by $x$ and $y$, the map $\varphi$ is given by
$$
\begin{pmatrix}
x\\
y\\
\end{pmatrix}
\to
\begin{pmatrix}
a & b\\
c & d\\
\end{pmatrix}
\begin{pmatrix}
x\\
y\\
\end{pmatrix}
,\ \ \ \ a,b,c,d \in \mathbb{Z}, \ 
ad-bc =\pm 1.
$$
What is the cohomology ring of the mapping torus $M \rtimes_\varphi
S^1$ in terms of $ \begin{pmatrix}
a & b\\
c & d\\
\end{pmatrix}$?
added: I mean to ask the ring $H^∗(M;\mathbb{Z})$ and $H^∗(M;\mathbb{Z}_n)$.
 A: I just want to point out that one can go quite far using  algebraic topology (in this special case), although computing the cohomology ring completely may require some other ingredient.
Lets call the mapping torus $Y$. Lets assume that $ad-bc=1$ so that the $3$-manifold is orientable, and that $\phi$ is not the identity otherwise so it is not $S^1 \times T^2$.
By universal coefficients $$H^{1}(Y,\mathbb{Z}) = \mathbb{Z}^{b_1}, \:\: H^{2}(Y,\mathbb{Z}) = \mathbb{Z}^{b_1} \oplus Tor (H_{1}(Y,\mathbb{Z})) .$$
So additively computing the cohomology ammounts to computing $H_{1}(M,\mathbb{Z})$. In Hatchers algebraic topology, Example 2.48 the following long exact sequence is given for the homology of a mapping torus, $I$ always denotes the identity.
$$0 \rightarrow H_{3}(Y) \rightarrow H_{2}(T^2) \xrightarrow{\phi_{*} - I_*} H_{2}(T^2) \rightarrow H_{2}(Y) \rightarrow H_{1}(T^2) \xrightarrow{\phi_{*} - I_*} H_{1}(T^2) \rightarrow H_{1}(Y) \rightarrow H_{0}(T^2) \rightarrow 0$$
Or substituting all of the known terms:
$$0 \rightarrow H_{3}(Y) \rightarrow \mathbb{Z} \xrightarrow{\phi_{*} - I_*} \mathbb{Z}  \rightarrow H_{2}(Y) \rightarrow \mathbb{Z}^2  \xrightarrow{\phi_{*} - I_*} \mathbb{Z}^2  \rightarrow H_{1}(Y) \rightarrow \mathbb{Z} \rightarrow 0$$
Edit: The computations following this were wrong. For an analysis of what can happen see R. van Dobben de Bruyn's answer.
A: Here are some more partial observations, overlapping some of the others. The result won't be completely explicit, as there are too many case distinctions for a clean answer, but hopefully at least the outline is right.
The additive structure can be obtained from the Mayer–Vietoris sequence associated to the covering of your mapping torus $Y$ by two cylinders $U$ and $V$ homeomorphic to $T \times (0,1)$, which on rearrangement will yield (the cohomological analogue of) the result quoted from Hatcher.
The map $H^1(U) \oplus H^1(V) \to H^1(U \cap V)$ is given by $f\colon (a,b) \mapsto (\varphi(b)-a,b-a)$, if we identify $H^1$ of all the solid tori in sight with $\mathbb Z^2$. The contribution of this kernel to $H^1(Y)$ is given by pairs $(a,b)$ with $a = b = \varphi(b)$; in any event, this summand is free abelian. There is another $\mathbb Z$ summand arising as the cokernel of $\delta\colon H^0(U \cap V) \to H^1(Y)$.
The map $H^2(U) \oplus H^2(V) \to H^2(U \cap V)$ is similarly given by $g\colon (m,n) \mapsto (\det(\varphi)n-m,n-m)$ if we identify $H^2$ of each solid torus with $\mathbb Z$. Thus $H^3(Y) = \mathrm{im}\, \delta$ is $\mathbb Z$ if $\det \varphi = 1$ and $\mathbb Z / 2\mathbb Z$ if $\det \varphi = -1$.
Now $H^2(Y)$ fits into a short exact sequence
$$0 \to \mathrm{coker}\, f \to H^2(Y) \to \ker g \to 0.$$
As $\ker g$ is free abelian (either $\mathbb Z$ or $0$ depending on the sign of $\det g$, this sequence will split, with all torsion coming from $\mathrm{coker}\, f$.
The product $H^2(Y) \times H^1(Y) \to H^3(Y)$ will be determined on the free summands by Poincar'e duality if $\det \varphi = 1$. The product of any element with an element $\delta a$ of $\mathrm{im}\,\delta \leq H^1(Y)$ will also be determined by $b \smile \delta a = \delta (b \cdot a)$, where the action of $H^*(Y)$ on $H^*(U \cap V)$ is by restriction followed by cup product (I may be getting the left- vs. right-sidedness wrong—otherwise one picks up a sign—but the Mayer--Vietoris connecting map is, in general, $H^*(Y)$-linear, for $Y$ the covered space.). The same reasoning also covers products with an element of the image of $g$.
I think these considerations together determine most of the product structure, although they do not say anything about $H^1 \times H^2$ on the free parts arising from $\ker f$ and $\ker g$, if $Y$ is nonorientable, nor much about $\ker f \times \ker f$. It might be worth working out a specific example or two to see how bad the remaining ambiguities are.
A: Not a full answer, but a very natural computational tool here (only for the additive structure) is the Leray spectral sequence
$$E_2^{p,q} = H^p\big(S^1,R^qf_*\underline{\mathbf Z}\big) \Rightarrow H^{p+q}(X,\mathbf Z)$$
where $f \colon X = T \rtimes_\phi S^1 \to S^1$ is the projection. Since $f$ is a fibre bundle with fibre $T$, the sheaves $R^qf_*\underline{\mathbf Z}$ are local systems of ranks $1$, $2$, and $1$ for $q=0$, $1$, and $2$ respectively. Moreover, the $E_2$ page is concentrated in the columns $p \in \{0,1\}$, so the spectral sequence degenerates on $E_2$ and we get short exact sequences
$$0 \to H^1\big(S^1,R^{n-1}f_*\underline{\mathbf Z}\big) \to H^n(X,\mathbf Z) \to H^0\big(S^1,R^nf_*\underline{\mathbf Z}\big) \to 0.$$
Moreover, $S^1$ is a $K(\mathbf Z,1)$, so cohomology of a local system $\mathcal L$ can be computed by
\begin{align*}
H^0(S^1,\mathcal L) &= \big(\mathcal L_x\big)^{\pi_1(S^1,x)} & & & &\text{(monodromy invariants)} \\
H^1(S^1,\mathcal L) &= \big(\mathcal L_x\big)_{\pi_1(S^1,x)} & & & &\text{(monodromy coinvariants)}.
\end{align*}
Note that monodromy acts trivially on $R^0f_*\underline{\mathbf Z}$, via $\phi$ on $R^1f_*\underline{\mathbf Z}$, and via $\det\phi$ on $R^2f_*\underline{\mathbf Z}$. If $\det \phi = 1$, then $R^2f_*\underline{\mathbf Z}$ is the trivial local system, so $E_2^{p,2} = \mathbf Z$ for $p \in \{0,1\}$. If $\det \phi = -1$ then $R^2f_*\underline{\mathbf Z}$ is the rank 1 local system with action by $-1$, so $E_2^{0,2} = 0$ and $E_2^{1,2} = \mathbf Z/2$.
For $E_2^{p,1}$ there can be many possibilities; for instance if $\phi = \big(\begin{smallmatrix}n+1 & n \\ 1 & 1\end{smallmatrix}\big)$, then $\phi-1 = \big(\begin{smallmatrix}n & n \\ 1 & 0\end{smallmatrix}\big)$ so $E^{1,1} = \mathbf Z/n$, and $H^2(X,\mathbf Z)$ picks up $n$-torsion (even though $X$ is oriented in this case). What is clear is that
$$\operatorname{rk}\big(E_2^{0,1}\big) = \operatorname{rk}\big(E_2^{1,1}\big) = \dim \big(H^1(T,\mathbf Q)\big)_1 \in \{0,1,2\}$$
(the dimension of the $1$-eigenspace, not the generalised $1$-eigenspace), so at least the Betti numbers can be determined in a fairly straightforward way from the properties of $\phi$.
Unfortunately, the spectral sequence does not say much about the ring structure, so genuinely different tools are needed for that.
A: This is also an incomplete answer but from a different angle than the previous ones. Let $A=\begin{pmatrix} a&b\\c&d\end{pmatrix}$.
EDIT: the answer below only deals with the orientable case $\det(A)=1$. The rational cohomology in the nonorientable case can be handled similarly.
The picture will look qualitatively different depending on whether the eigenvalues have absolute values 1 (corresponds to trace of $A$ equal to 0 or $\pm 2$) or not.
If $tr(A)\ne 0, \pm 2$ then $|\lambda_i(A)|\ne 1$ and  the resulting 3-manifold is a solvmanifold.  In this case the commutator of $\pi_1(M)$ has rank 2, hence  the abelianization of $\pi_1(M)$ has rank 1 and therefore  both  $H^1(M)$ and $H^2(M)$ have rank 1.
Over $\mathbb Q$ (or $\mathbb R$ ) the generator of $H^1(M)$ comes from the pullback of the generator of the base circle as can be seen from the fact that the original bundle has a section. Using  Poincare duality we now easily get the  cup product structure on $H^*(M,\mathbb Q)$. There are generators $a\in H^1(M)\cong \mathbb Q, b\in H^2(M)\cong \mathbb Q, c\in H^3(M)\cong \mathbb Q$ and  $a^2=0, ab=c$.
The other case when $|\lambda_i(A)|=1$ gives infranilmanifolds. Let me discuss the nil case when $tr(A)=2$ and $\lambda_1=\lambda_2=1$.  Then in appropriate coordinates on $T^2$ the mapping matrix $A$ reduces to $\begin{pmatrix} 1&k\\0&1\end{pmatrix}$.
This actually can be viewed as an $S^1$ bundle  $S^1\to M\to T^2$ over a 2-torus (made out of the base circle and the first meridian of $T^2$ which is fixed by $A$) . The number $k$ is the Euler class of this circle bundle. You can get cohomology from the Gysin sequence of this circle bundle. Rationally it's very simple.  When $k=0$ you just get $T^3$ and when $k\ne 0$ the minimal model of this is given by the  free dga $(\Lambda (x,y,z), d)$ where $\deg x=\deg y=\deg z=1$ and $dx=dy=0, dz=xy$. The cohomology of this algebra is the rational cohomology algebra of $M$:  $x$ and $y$ are generators of $H^1$, $xz, yz$ are generators of $H^2$, $t=xyz$ is a generator of $H^3$ and the cup products are:
$xy=0, x(xz)=y(yz)=0, x(yz)=-y(xz)=t$.
Here $x$ and $y$ are  generators of $H^1(T^2)$ where $T^2$ is  the base torus.
The last case is infranil which in appropriate basis corresponds to $A=\begin{pmatrix} -1&k\\0&-1\end{pmatrix}$ or $A=\begin{pmatrix} 0&1\\-1&0\end{pmatrix}$.   These are finitely covered by the nilmanifolds (with covers of order 2 or 4 respectively) and need to be handled separately.  In this case the commutator again has rank 2 so the answer is similar to the solv case.
