In an interdisciplinary ﬁeld on mathematics and physics, we examine a physical problem, ﬂuid ﬂow in porous media, which is represented by a stochastic partial differential equation (SPDE). We ﬁrst give a priori error estimates for the solutions to an optimization problem constrained by the physical model under lower regularity assumptions than the literature. We then use the concept of Galerkin ﬁnite element methods to establish a new numerical algorithm to give approximations for our stochastic optimal physical problem. Finally, we develop original computer programs based on the algorithm and use several numerical examples of various situations to see how well our solver works by comparing its outputs to the priori error estimates.