1 Introduction

In relativistic astrophysics, there has been a growing interest in studying the physical behaviour of stellar objects composed of anisotropic fluid distributions, i.e., objects where the radial component of pressure \((p_r)\) is not equal to its transverse component \((p_t)\). A Newtonian approach is sufficient to study stellar structures in a comparatively low-density regime. However, in the case of compact stellar structures in the high-density regime, a general relativistic treatment is necessary, and the impact of anisotropy cannot be neglected while modelling such systems, see for example [1,2,3,4] and references therein. Ruderman [5] and Canuto [6] observed that material distribution in the highly dense core of a compact star might exhibit unequal stresses. Bowers and Liang [7] have extensively analyzed the sources of anisotropy at the stellar interior.

Pressure anisotropy in compact star may arise due to various factors which include phase transitions, pion condensation [8,9,10], the existence of a solid core or presence of a type-3A superfluid [11], strong electromagnetic fields [12,13,14], slow rotation of fluids [15], etc. Ivanov [16] has pointed out that influences of shear and/or electromagnetic field on self-bound systems can be interpreted by incorporating a gross anisotropic parameter into the system of field equations. Self-bound systems composed of scalar fields, i.e., the ‘boson stars’ are naturally anisotropic [17]. Similarly, wormholes [18] and gravastars [19, 20] are also structurally anisotropic systems. The shearing motion of the fluid is another source of anisotropy in self-gravitating objects [21,22,23]. The origin and effects of local anisotropy on astrophysical objects have been studied in details in [24, 25]. An exhaustive review of the subject may be found in [26].

The objective of the current investigation is to provide a new algorithm to generate anisotropic analogues of a large family of well-known solutions describing self-gravitating systems in equilibrium. An algorithm to generate anisotropic solutions from a seed isotropic solution was initiated by Chaisi and Maharaj [27]. Herrera et al. [28] had extended the Lake [29] algorithm to the case of locally anisotropic fluids to study spherically symmetric relativistic stars. Herrera and Barreto [2] had set up a general formalism to model relativistic polytropic stars with anisotropic pressure. In our formalism, we have shown that it is possible to generalize a large class of well-known exact isotropic stellar solutions by extending the models to the case of an anisotropic matter distribution. Most importantly, the resultant solution fulfils the criteria of physical acceptability.

The paper has been organized as follows: In Sect. 2, the Einstein field equations for a static spherically symmetric anisotropic fluid distribution have been laid down. An equivalent form of the field equations has been obtained by making use of the Durgapal and Bannerji [30] transformation equations. In Sect. 3, for a particular choice of the \(g_{tt}\) component of the gravitational potential together with a prescribed form of the anisotropic parameter, a formalism to has been developed to generate analytic solutions in terms elementary functions. In Sect. 4, we have shown how a plethora of physically reasonable isotropic stellar solutions can be regained by suitable parametrization of our general class of solutions describing an anisotropic matter distribution. In Sects. 5 and 6, we have analyzed physical acceptability and implications of our class of solutions on the gross physical behaviour of relativistic compact stars. Some concluding remarks have been made in Sect. 7.

2 Einstein field equations

To describe the interior of a static and spherically symmetric relativistic star, we write the line element in coordinates \((x^{a}) = (t,r,\theta ,\phi )\) as

$$\begin{aligned} ds^{2} = -e^{2\nu (r)} dt^{2} + e^{2\lambda (r)} dr^{2} + r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}).\qquad \end{aligned}$$
(1)

For an anisotropic matter distribution, we choose the energy-momentum tensor in the form

$$\begin{aligned} T^i_{j}=\hbox {diag}(-\rho , p_r, p_t, p_t). \end{aligned}$$
(2)

The energy density \(\rho \), the radial pressure \(p_r\) and the tangential pressure \(p_t\) are measured relative to the comoving fluid velocity \(u^i = e^{-\nu }\delta ^i_0.\) For the line element (1), the independent set of Einstein field equations are then obtained as

$$\begin{aligned}&\rho = \frac{1}{r^{2}} \left[ r(1-e^{-2\lambda }) \right] ', \end{aligned}$$
(3)
$$\begin{aligned}&p_r = - \frac{1}{r^{2}} \left( 1-e^{-2\lambda } \right) + \frac{2\nu '}{r}e^{-2\lambda } , \end{aligned}$$
(4)
$$\begin{aligned}&p_t= e^{-2\lambda }\left( \nu '' + \nu '^{2} + \frac{\nu '}{r}- \nu '\lambda ' - \frac{\lambda '}{r} \right) , \end{aligned}$$
(5)

where a prime (\('\)) denotes differentiation with respect to r. In the field equations (3)–(5), we have assumed \(8\pi G=1=c\). The system of equations determines the behaviour of the gravitational field of an anisotropic imperfect fluid sphere. The mass contained within a radius r of the sphere is defined as

$$\begin{aligned} m(r)= \frac{1}{2}\int _0^r\omega ^2 \rho (\omega )d\omega . \end{aligned}$$
(6)

A different but equivalent form of the field equations can be obtained if we introduce the transformation [30]

$$\begin{aligned} x = Cr^2,~~ Z(x) = e^{-2\lambda (r)} ~\text{ and }~ A^{2}y^{2}(x) = e^{2\nu (r)}, \end{aligned}$$
(7)

where A and C are arbitrary constants. Under the transformation (7), the system of Eqs. (3)–(5) take the following form

$$\begin{aligned} \frac{\rho }{C}= & {} \frac{1-Z}{x} - 2\dot{Z} , \end{aligned}$$
(8)
$$\begin{aligned} \frac{p_r}{C}= & {} 4Z\frac{\dot{y}}{y} + \frac{Z-1}{x} , \end{aligned}$$
(9)
$$\begin{aligned} p_t= & {} p_r +{\varDelta } \end{aligned}$$
(10)
$$\begin{aligned} 0= & {} \dot{Z} \left( 2x^2\dot{y}+xy\right) + Z(4x^2\ddot{y}-y)\nonumber \\&+\left( 1-\frac{{\varDelta } x}{C}\right) y, \end{aligned}$$
(11)

where \({\varDelta } = p_t-p_r\) is the measure of anisotropy and dots denote differentiation with respect to the variable x. The anisotropic stress will be directed outward (repulsive) when \(p_t > p_r\) (i.e., \( {\varDelta } > 0\)) and inwards when \(p_t < p_r\) (i.e., \({\varDelta } < 0\)).

3 Method of generating analytic solutions

The system (8)–(11) comprises four equations in the six unknowns namely, \(Z, y, \rho , p_r, p_t\) and \({\varDelta }\). Therefore, we have the freedom to choose any two variables to integrate the system. In our formalism, rather than assuming an equation of state (EOS) for the matter composition, we assume a particular form of y together with a prescribed anisotropy \({\varDelta }\) which are well-behaved and can provide solutions to Eq. (11). We choose the metric function y as

$$\begin{aligned} y = (1+ a x^n)^m \end{aligned}$$
(12)

where am and n are real numbers. Substitution of Eq. (12) in (11) yields

$$\begin{aligned}&\dot{Z}+f(x) Z -\frac{\left( \frac{{\varDelta } x}{C}-1\right) (1+ax^n)}{x[1+(2mn+1)ax^n]}=0,\\&f(x)= \frac{1}{x(1+ax^n)[1+(2mn+1)ax^n]}\nonumber \\&\qquad \qquad \times \left[ (4mn(mn-1)-1)(ax^n)^{2}\right. \nonumber \\&\qquad \qquad \left. +(4mn(n-1)-2)ax^n -1\right] \nonumber . \end{aligned}$$
(13)

Using partial fractions, we write Eq. (13) in the form

$$\begin{aligned}&\dot{Z} + g(x) Z = \frac{\left( \frac{{\varDelta } x}{C}-1\right) (1+ax^n)}{x[1+(2mn+1)ax^n]},\nonumber \\&g(x)= \left[ - \frac{1}{x} + \frac{2n(m-1)ax^{n-1}}{(1+ax^n)} \right. \nonumber \\&\qquad \qquad \left. +\frac{2n[2m(n-1)+1]ax^{n-1}}{[1+(2mn+1)ax^n]} \right] , \end{aligned}$$
(14)

whose solution can be expressed in integral form as

$$\begin{aligned} Z= & {} \frac{x}{(1+ax^n)^{2(m-1)}[1+ (2mn+1)ax^n]^{\frac{2[2m(n-1)+1]}{2mn+1}}} \nonumber \\&\times \left[ \int \left( \frac{{\varDelta }}{Cx}-\frac{1}{x^2}\right) (1+ax^n)^{(2m-1)}\right. \nonumber \\&\left. \times [1+(2mn+1)ax^n]^{1- \frac{4m}{2mn+1}} dx - B \right] , \end{aligned}$$
(15)

where B is the constant of integration. At this stage, we specify the anisotropy \({\varDelta }\). We assume the radial fall-off profile of the anisotropic parameter in the form

$$\begin{aligned} {\varDelta }=\frac{\alpha Ca x}{(1+ax^n)^{(2m+1)}[1+(2mn+1)ax^n]^{1- \frac{4m}{2mn+1}}}, \end{aligned}$$
(16)

where the constant \(\alpha \) specifies the extend of anisotropy. This particular choice ensures that anisotropy vanishes at the center of the star. Substitution of (16) into (15) yields

$$\begin{aligned}&Z = \frac{x}{(1+ax^n)^{2(m-1)}[1+ (2mn+1)ax^n]^{\frac{2[2m(n-1)+1]}{2mn+1}}} \nonumber \\&\qquad \quad \times \left[ \int \left( \frac{\alpha }{(1+ax^n)^2} - l(x)\right) dx - B \right] ,\nonumber \\&l(x)= \frac{(1+ax^n)^{(2m-1)}[1+(2mn+1)ax^n]^{1- \frac{4m}{2mn+1}}}{x^2},\nonumber \\ \end{aligned}$$
(17)

which solves the system. It should be mentioned here that in an earlier work Herrera et al. [28] had shown that all static spherically symmetric anisotropic solutions to Einstein field equations could be obtained by making use of two generating functions. In our case, it turns out that the solution (17) can be obtained as a special case by choosing the following generating functions

$$\begin{aligned}&z(r) = \frac{1}{r}+\frac{2m n a C^n r^{2n-1}}{1+a C^n r^{2n}};\\&{\varPi } (r) = \frac{-8 \pi \alpha C a x}{(1+a x^n)^{(2m+1)}[1+(2m n+1)a x^n]^{1- \frac{4m}{2m n+1}}} \end{aligned}$$

in Eq. (10) of Ref. [28].

We are now in a position to integrate Eq. (17) for specified values of m and n. Interestingly, it turns out that the solutions can also be expressed in terms of elementary functions for particular values of m and n as will be shown in the following section.

4 Anisotropic models

It is interesting to note that an anisotropic generalization of a large family of physically reasonable isotropic stellar models studied earlier can be regained by suitably fixing the values of m and n. Our motivation will be to generate new solutions only for those values of m and n which would allow us to regain the isotropic analogues of solutions which have been shown to be well-behaved and physically acceptable [31]. It is remarkable that the new class of solutions, as shown below, contains a large class of known solutions which have been developed to study relativistic isotropic fluid spheres.

4.1 Case I: \(m=\frac{1}{2}\) and \(n=1\)

By setting \(m=\frac{1}{2}\) and \(n=1\) in Eqs. (17) and (16), we obtain

$$\begin{aligned} Z= & {} \frac{(1+ax)(1-Bx)}{(1+2ax)}-\frac{\alpha x}{(1+2ax)}, \end{aligned}$$
(18)
$$\begin{aligned} {\varDelta }= & {} \frac{\alpha C ax}{(1+ax)^2}, \end{aligned}$$
(19)

so that the line element (1) takes the form

$$\begin{aligned} ds^{2}= & {} -A^2(1+aCr^2) dt^{2} \nonumber \\&+\left[ \frac{(1+aCr^2)(1-BCr^2)}{(1+2aCr^2)}-\frac{\alpha Cr^2}{(1+2aCr^2)}\right] ^{-1}dr^{2} \nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(20)

4.1.1 Anisotropic generalization of Tolman IV Model

In (20), if we set \(a=\frac{1}{D^2}, B=\frac{1}{R^2}\) and \(C=1\), the line element (20) reduces to

$$\begin{aligned} ds^{2}= & {} -A^2\left( 1+\frac{r^2}{D^2}\right) dt^{2}\nonumber \\&+\left[ \frac{\left( 1+\frac{r^2}{D^2}\right) \left( 1- \frac{r^2}{R^2}\right) }{\left( 1+2\frac{r^2}{D^2}\right) } -\frac{\alpha r^2}{\left( 1+2\frac{r^2}{D^2}\right) }\right] ^{-1}dr^{2} \nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(21)

Note that for zero anisotropy \({\varDelta }=0\) (i.e., \(\alpha =0\)), the line element (21) reduces to

$$\begin{aligned} ds^{2}= & {} -A^2\left( 1+\frac{r^2}{R^2}\right) dt^{2} + \frac{1+2\frac{r^2}{D^2}}{\left( 1+\frac{r^2}{D^2}\right) \left( 1-\frac{r^2}{R^2}\right) }dr^{2}\nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}), \end{aligned}$$
(22)

which is the well known Tolman IV solution [32]. Thus, the metric (21) turns out to be an anisotropic generalization of Tolman IV solution. This solution was shown to satisfy all the physical requirements of a realistic star [31] and previously used by Tolman [32] to study relativistic compact stars with isotropic matter distribution. It is to be noted that an anisotropic generalization of the Tolman IV solution was obtained earlier by Cosenza et al. [33]. While in the earlier approach the generalization was done by assuming a specific density profile (or equivalently making an ansatz for the metric potential \(g_{rr}\)), in our case, the metric potential \(g_{rr}\) gets determined for a specific form of the metric potential \(g_{tt}\).

4.1.2 Anisotropic generalization of de-Sitter solution

For \(a=-1, A=1, B=2\) and \(C=\frac{1}{R^2}\), the line element (20) becomes

$$\begin{aligned} ds^{2}= & {} -\left( 1- \frac{r^2}{R^2} \right) dt^{2}\nonumber \\&+ \left[ \left( 1-\frac{r^2}{R^2}\right) -\frac{\alpha \frac{r^2}{R^2}}{\left( 1-2\frac{r^2}{R^2}\right) }\right] ^{-1}dr^{2} \nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(23)

Now, if we set \(\alpha =0\) (i.e., \({\varDelta }=0\)), the metric reduces to the familiar de-Sitter solution

$$\begin{aligned} ds^{2}= & {} -\left( 1-\frac{r^2}{R^2}\right) dt^{2} + \left( 1-\frac{r^2}{R^2}\right) ^{-1}dr^{2} \nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}), \end{aligned}$$
(24)

which models an isotropic universe dominated by dark energy which is, in general, interpreted in terms of a cosmological constant.

4.1.3 Anisotropic generalization of Einstein universe

For \(a=0, B=1\) and \(C=\frac{1}{R^2}\), using Eq. (20), we obtain

$$\begin{aligned} ds^{2}= & {} -A^2 dt^{2} + \left( 1-\frac{r^2}{R^2}- \alpha \frac{r^2}{R^2}\right) ^{-1}dr^{2}\nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(25)

For vanishing anisotropy \((\alpha =0)\), the metric reduces to the isotropic Einstein universe model described by the metric

$$\begin{aligned} ds^{2} = -A^2 dt^{2} + \left( 1-\frac{r^2}{R^2}\right) ^{-1}dr^{2} + r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(26)

In this case, the metric corresponds to a matter dominated Friedmann model with zero curvature in which the universe will continue to expand forever with the right amount of energy provided during the time of the Big-bang.

4.2 Case II: \(m=n=1\)

4.2.1 Anisotropic generalization of Korkina and Orlyanskii solution III

By setting \(m=n=1\) and using Eqs. (17) and (16), we obtain

$$\begin{aligned} Z= & {} 1-Bx(1+3ax)^{-2/3} \nonumber \\&-\alpha x (1+ax)^{-1}(1+3ax)^{-2/3}, \end{aligned}$$
(27)
$$\begin{aligned} {\varDelta }= & {} \frac{\alpha Cax(1+3ax)^{1/3}}{(1+ax)^3}, \end{aligned}$$
(28)

so that the line element (1) takes the form

$$\begin{aligned} ds^{2}= & {} -A^2(1+aCr^2)^2 dt^{2} + \left[ 1-BCr^2(1+3aCr^2)^{-2/3} \right. \nonumber \\&\left. -\alpha Cr^2(1+aCr^2)^{-1}(1+3aCr^2)^{-2/3} \right] ^{-1}dr^{2}\nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(29)

Now, for an anisotropic sphere (\(\alpha =0\)), if we set \(B=0\) and C = 1, the metric (29) reduces to

$$\begin{aligned} ds^{2} = -A^2(1+ar^2)^2 dt^{2} + dr^{2} + r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}), \end{aligned}$$
(30)

which is the Korkina and Orlyanskii solution III [34]. Consequently, the metric (29) is a generalization of the solution of Korkina and Orlyanskii [34].

4.3 Case III: \(m=\frac{3}{2}\) and \(n=1\)

4.3.1 Anisotropic generalization of Heintzmann IIa solution

When \(m=\frac{3}{2}\) and \(n=1\), using Eqs. (17) and (16), we obtain

$$\begin{aligned} Z= & {} \frac{2-ax- 2Bx(1+4ax)^{-1/2}}{2(1+ax)} \nonumber \\&- \frac{\alpha x(1+4ax)^{-1/2}}{(1+ax)^2}, \end{aligned}$$
(31)
$$\begin{aligned} {\varDelta }= & {} \frac{\alpha Cax\sqrt{1+4ax}}{(1+ax)^4}. \end{aligned}$$
(32)

Now, if we set \(B=3a C/2\), Eq. (31) takes the form

$$\begin{aligned} Z=1-\frac{3ax }{2} \left[ \frac{1+c(1+4ax)^{-1/2}}{1+ax}\right] - \frac{\alpha x(1+4ax)^{-1/2}}{(1+ax)^2}, \end{aligned}$$
(33)

and consequently the metric (1) gets the form

$$\begin{aligned} ds^{2}= & {} -A^2(1+ar^2)^3 dt^{2} + \left( 1-\frac{3ar^2 }{2}\right. \nonumber \\&\left. \times \left[ \frac{1+c(1+4ar^2)^{-1/2}}{1+ar^2}\right] \right. \nonumber \\&\left. - \frac{\alpha r^2(1+4ar^2)^{-1/2}}{(1+ar^2)^2}\right) ^{-1}dr^{2} \nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}), \end{aligned}$$
(34)

where we have set \(C=1\). The above metric reduces to Heintzmann IIa [35] solution

$$\begin{aligned} ds^{2}= & {} -A^2(1+ar^2)^3 dt^{2} \nonumber \\&+\left( 1-\frac{3ar^2 }{2} \left[ \frac{1+c(1+4ar^2)^{-1/2}}{1+ar^2}\right] \right) ^{-1}dr^{2} \nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}), \end{aligned}$$
(35)

when \(\alpha =0\).

4.4 Case IV: \(m=2\) and \(n=1\)

4.4.1 Anisotropic generalization of Durgapal IV Model

For \(m=2\) and \(n=1\), using Eqs. (17) and (16), we obtain

$$\begin{aligned} Z= & {} \frac{7-10ax-a^2x^2}{7(1+ax)^2}-\frac{Bx}{(1+ax)^2(1+5ax)^{2/5}} \nonumber \\&-\frac{\alpha x}{(1+ax)^3(1+5ax)^{2/5}}, \end{aligned}$$
(36)
$$\begin{aligned} {\varDelta }= & {} \frac{\alpha Cax(1+5ax)^{3/5}}{(1+ax)^5}, \end{aligned}$$
(37)

and consequently, the line element (1) takes the form

$$\begin{aligned} ds^{2}= & {} -A^2(1+aCr^2)^4 dt^{2} + \left[ \frac{7-10aCr^2-a^2C^2r^4}{7(1+aCr^2)^2}\right. \nonumber \\&\left. -\frac{BCr^2}{(1+aCr^2)^2(1+5aCr^2)^{2/5}}\right. \nonumber \\&\left. -\frac{\alpha Cr^2}{(1+aCr^2)^3(1+5aCr^2)^{2/5}}\right] ^{-1}dr^{2}\nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(38)

Now, if we set \(a=1\) and \(\alpha =0\), we regain the Durgapal IV[36] metric

$$\begin{aligned} ds^{2}= & {} -A^2(1+Cr^2)^4 dt^{2} + \left[ \frac{7-10Cr^2-C^2r^4}{7(1+Cr^2)^2}\right. \nonumber \\&\left. -\frac{BCr^2}{(1+Cr^2)^2(1+5Cr^2)^{2/5}}\right] ^{-1}dr^{2} \nonumber \\&+ r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(39)

4.5 Case V: \(m=\frac{5}{2}\) and \(n=1\)

4.5.1 Anisotropic generalization of Durgapal V Model

For \(m=\frac{5}{2}\) and \(n=1\), using Eqs. (17) and (16) we obtain

$$\begin{aligned} Z= & {} \frac{1-\frac{ax(309 +54 ax+8a^2x^2)}{112}-\frac{Bx}{(1+6ax)^{1/3}}}{(1+ax)^3} \nonumber \\&- \frac{\alpha x}{(1+ax)^4(1+6ax)^{1/3}}, \end{aligned}$$
(40)
$$\begin{aligned} {\varDelta }= & {} \frac{\alpha Cax(1+6ax)^{2/3}}{(1+ax)^6}, \end{aligned}$$
(41)

and subsequently the line element (1) takes the form

$$\begin{aligned} ds^{2}= & {} -A^2(1+aCr^2)^5 dt^{2} \nonumber \\&+\left[ \frac{1-\frac{aCr^2(309 +54a Cr^2+8a^2C^2r^4)}{112}-\frac{BCr^2}{(1+6aCr^2)^{1/3}}}{(1+aCr^2)^3} \right. \nonumber \\&\left. - \frac{\alpha Cr^2}{(1+aCr^2)^4(1+6aCr^2)^{1/3}} \right] ^{-1}dr^{2}\nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}). \end{aligned}$$
(42)

Obviously, the line element (42) reduces to Durgapal V [36] solution if we set \(a=1\) and \(\alpha =0\).

4.6 Case VI: \(m=\frac{1}{4}\) and \(n=1\)

4.6.1 Anisotropic generalization of Durgapal et al. [37] stellar model

For \(m=-\frac{1}{4}\) and \(n=1\), using Eqs. (17) and (16), we obtain

$$\begin{aligned} Z= & {} \frac{u(x)}{(2+ax)^4}, \end{aligned}$$
(43)
$$\begin{aligned} {\varDelta }= & {} \frac{8\alpha Cax }{\sqrt{1+ax}(2+ax)^3},\nonumber \\ u(x)= & {} -16x(1+ax)^{3/2}(B(1+ax)+\alpha )\nonumber \\&+\, 4(1+ax)^2(4+4ax-a^2x^2), \end{aligned}$$
(44)

so that the line element (1) takes the form

$$\begin{aligned} ds^{2}= & {} -\frac{A^2}{\sqrt{1+aCr^2}} dt^{2} \nonumber \\&+ \frac{(2+aCr^2)^4}{v(x)}dr^{2} \nonumber \\&+\, r^{2}(d\theta ^{2} + \sin ^{2}{\theta } d\phi ^{2}),\nonumber \\ v(x)= & {} -16Cr^2(B(1+aCr^2)+\alpha )(1+aCr^2)^{3/2}\nonumber \\&+\, 4(1+aCr^2)^2(4+4aCr^2-a^2C^2r^4). \end{aligned}$$
(45)

By setting \(a=-1\) and \(\alpha =0\), the above metric can be reduced to the Durgapal et al. [37] stellar model.

5 Physical acceptability

In the previous section, we have presented an algorithm to generate a large class of anisotropic solutions and showed that many well-known exact solutions may be regained by suitably fixing the model parameters in this formulation. To check physical acceptability of our class of solutions, we consider a particular solution (case I). The variables in this case are obtained as

$$\begin{aligned} e^{2\nu }= & {} A^2(1+ax), \end{aligned}$$
(46)
$$\begin{aligned} e^{2\lambda }= & {} \frac{(1+2ax)}{(1+ax)(1-Bx)-\alpha x}, \end{aligned}$$
(47)
$$\begin{aligned} \frac{\rho }{C}= & {} \frac{(a+\alpha )(3+2ax)+B[3+ax(7+6ax)]}{(1+2ax)^2}, \end{aligned}$$
(48)
$$\begin{aligned} \frac{p_r}{C}= & {} \frac{a(1+ax)-\alpha (1+3ax)- B[1+ax(4+3ax)]}{(1+ax)(1+2ax)},\nonumber \\ \end{aligned}$$
(49)
$$\begin{aligned} p_t= & {} p_r+{\varDelta }, \end{aligned}$$
(50)
$$\begin{aligned} \frac{{\varDelta }}{C}= & {} \frac{\alpha ax}{(1+ax)^2}. \end{aligned}$$
(51)

The physical quantities are expressed in simple elementary functions which facilitates a detailed study of the physical behaviour of the star. Most importantly, the solution contains an ‘anisotropic switch’ \(\alpha \) which can be conveniently used to investigate the impact of anisotropy. Another interesting feature of our solution is that the solution provides a barotropic equation of state (EOS) \(p_r = p_r(\rho )\) which is obtained explicitly in the form

$$\begin{aligned} \frac{p_r}{C}= & {} \frac{1}{8} \left[ \frac{24\alpha (3B+2\tilde{\rho })+\beta (a-7\alpha -2B- \tilde{\rho })}{a+\alpha -2B -\tilde{\rho }}\right. \nonumber \\&\left. +\frac{2B\beta }{2(a+\alpha )-B}+ 14\alpha -2a-13B \right] , \end{aligned}$$
(52)

where we have used the relation

$$\begin{aligned} \tilde{\rho }=\frac{\rho }{C}\quad \text{ and }\quad \beta =\sqrt{[2(a+\alpha )-B][2(a+\alpha )-23B+16 \tilde{\rho }]}. \end{aligned}$$

We would like to stress here that a barotropic EOS is generally difficult to extract from an exact solution of field equations. It is not so in our case.

Let us now analyze the physical acceptability of our solution:

  1. 1.

    In our model, we have \((e^{2\nu (r)})'_{r=0}=(e^{2\lambda (r)})'_{r=0}=0 \) and \(e^{2\nu (0)}=A^2,~ e^{2\lambda (0)}=1\); these imply that the metric is regular at the centre \(r=0\).

  2. 2.

    Since \(\rho (0)= 3C(a+B+\alpha )\) and \(\displaystyle p_r(0)=p_t(0)=C (a-B- \alpha )\), the energy density, radial pressure and tangential pressure will be non-negative at the centre if we choose the parameters satisfying the condition \(a>B+\alpha \).

  3. 3.

    The condition \(p_r(r=s)=0\) determines the boundary of the star

    $$\begin{aligned} s=\sqrt{\frac{a-(4B+3\alpha )+\sqrt{(a+2B)^2-6 (a-2B)\alpha +9 {\alpha }^2}}{6aBC}}. \end{aligned}$$
  4. 4.

    The interior solution (20) should be matched to the exterior Schwarzschild metric

    $$\begin{aligned} ds^2= & {} - \left( 1 - \frac{2M}{r} \right) dt^2 +\left( 1 - \frac{2M}{r} \right) ^{-1} dr^2 \nonumber \\&+ r^2 (d\theta ^2 +\sin ^2\theta d\phi ^2), \end{aligned}$$
    (53)

    across the boundary of the star \(r=s\), where M is the total mass of the sphere which can be obtained directly from Eq. (6) as

    $$\begin{aligned} \displaystyle M=m(s)=\frac{Cs^3[a+\alpha + B(1+aCs^2)]}{2(1+2aCs^2)}. \end{aligned}$$

    Matching of the line elements (20) and (53) at the boundary \(r=s\) yields

    $$\begin{aligned} \left( 1 - \frac{2M}{s} \right)= & {} \frac{(1+aCs^2)(1-BCs^2)}{(1+2aCs^2)}\nonumber \\&-\frac{\alpha Cs^2}{(1+2aCs^2)}, \end{aligned}$$
    (54)
    $$\begin{aligned} \left( 1 - \frac{2M}{s} \right)= & {} A^2(1+aCs^2). \end{aligned}$$
    (55)

    Making use of the junction conditions, the constant A is determined as

    $$\begin{aligned} \displaystyle A^2= \frac{\sqrt{(a+2B)^2-6 (a-2B)\alpha +9 {\alpha }^2}+ 2B+3 \alpha -a}{4a}. \end{aligned}$$
  5. 5.

    The gradient of density, radial pressure and tangential pressure are respectively obtained as

    $$\begin{aligned} \frac{d\rho }{dr}= & {} - \frac{2ac^2[2(a+\alpha )+B]r(5+2aCr^2)}{(1+2aCr^2)^3},\end{aligned}$$
    (56)
    $$\begin{aligned} \frac{dp_r}{dr}= & {} \frac{2 a C^2 r}{(1+a C r^2)^2 (1+2 a Cr^2)^2}\nonumber \\&\times \left[ -(2 a+B)(1+a C r^2)^2\right. \nonumber \\&\left. + 2 a C r^2(2+3 a C r^2)\alpha \right] ,\end{aligned}$$
    (57)
    $$\begin{aligned} \frac{dp_t}{dr}= & {} \frac{2 a C^2 r}{(1+a C r^2)^2 (1+2 a Cr^2)^2}\nonumber \\&\times \left[ -(2 a+B)(1+a C r^2)^3\right. \nonumber \\&\left. +(1+ a C r^2(7+2 a C r^2(5+a C r^2)))\alpha \right] .\quad \end{aligned}$$
    (58)

    The decreasing nature of these quantities is shown graphically.

  6. 6.

    Within a stellar interior, it is expected that the speed of sound should be less than the speed of light i.e., \(\displaystyle 0 \le \frac{dp_r}{d\rho }\le 1\) and \(\displaystyle 0 \le \frac{dp_t}{d\rho }\le 1\). In our model, we have

    $$\begin{aligned} \frac{dp_r}{d\rho }= & {} \frac{1}{(1+a C r^2)^2 (5+2 a C r^2) (2 a+B+2 \alpha )}\nonumber \\&\times (1+2 a C r^2)\left[ (2 a+B)(1+a C r^2)^2\right. \nonumber \\&\left. -2 a C r^2(2+3 a C r^2)\alpha \right] ,\end{aligned}$$
    (59)
    $$\begin{aligned} \frac{dp_t}{d\rho }= & {} \frac{1}{(1+a C r^2)^3 (5+2 a C r^2) (2 a+B+2 \alpha )}\nonumber \\&\times (1+2 a C r^2)\left[ (2 a+B)(1+a C r^2)^3\right. \nonumber \\&\left. -(a C r^2(7+2 a C r^2(5+a C r^2)))\alpha \right] . \end{aligned}$$
    (60)

    By choosing the model parameters appropriately, we have shown that this requirement is also satisfied in our model.

  7. 7.

    The fulfillment of energy conditions for an anisotropic fluid i.e., \(\rho -p_r-2p_t\ge 0\) and \(\rho +p_r+2p_t\ge 0\) are also shown to be satisfied in this model.

  8. 8.

    Finally, we have calculated the adiabatic index

    $$\begin{aligned} {\varGamma }=\frac{\rho +p}{p}\frac{dp}{d\rho }, \end{aligned}$$
    (61)

    for a particular configuration. Bondi’s [38, 39] analyses show that a Newtonian isotropic sphere will be in equilibrium if the adiabatic index \({\varGamma } > 4/3\) which, however, gets modified for a relativistic anisotropic fluid sphere. Subsequently, the issue relating to stability of a relativistic anisotropic spherical body was taken up by many investigators (see for example [40,41,42] and references therein). Based on these results, it can be concluded that an anisotropic fluid sphere will be stable if the following condition is fulfilled:

    $$\begin{aligned} {\varGamma } > \frac{4}{3} - \left[ \frac{4}{3}\frac{(p_r-p_t)}{|{p_r}'|r}\right] _{max}. \end{aligned}$$
    (62)

    In Figs. 8 and 9, we have plotted \({\varGamma }\) for \(\alpha =0.5\) and \(\alpha =0\), respectively. The dashed lines in the plots correspond to values of the right hand side of Eq. (62). We note that in the case of \(\alpha =0.5\), the term within bracket [ ] takes its maximum value at the centre and decreases radially outward. Consequently, the above condition is satisfied throughout the star. In the case of an isotropic configuration (\(\alpha =0\)), the right hand side of Eq. (62) remains constant (4 / 3) throughout the star and it is obvious from Fig. 9 that the stability requirement is fulfilled in this case as well.

Fig. 1
figure 1

Density profiles

Fig. 2
figure 2

Radial pressure profiles

Fig. 3
figure 3

Tangential pressure profiles

Fig. 4
figure 4

Radial component of sound speed

Fig. 5
figure 5

Transverse component of sound speed

Fig. 6
figure 6

Fulfillment of energy condition

Fig. 7
figure 7

Radial variation of anisotropy

Fig. 8
figure 8

Radial variation of adiabatic index for \(\alpha \ne 0\). The dashed line corresponds to

Fig. 9
figure 9

Radial variation of adiabatic index for \(\alpha = 0\)

6 Compatibility with observational data

We examine the physical applicability of our solution by making use of the values of masses and radii of observed pulsars as input parameters. To illustrate the case, we have considered the data available from the pulsar \(4U1820-30\) whose estimated mass and radius are \(M = 1.58 ~M_{\odot }\) and \(s = 9.1~km\), respectively [43]. For these values, we have determined two sets of constants. For the isotropic case \((\alpha =0)\), we have obtained \(A=0.7375,~C=0.0068,~B=0.2719\) and assuming the star to be composed of anisotropic matter (we have assume \(\alpha =0.5\)) the constants have been evaluated as \(A=0.7375,~C=0.0068,~B=-0.1188\). Note that the parameter a remains free in this model. Making use of these values, we have shown graphically the nature of all the physically meaningful quantities in Figs. 1, 2, 3, 4, 5, 6, 7, 8 and 9. The plots show that all the physically meaningful variables comply with the requirements of a realistic star. In particular, the figures highlight the effects of anisotropy on the gross physical behaviour of a compact star.

7 Conclusions

To summarize, we have developed an algorithm to generate exact solutions to Einstein field equations for a spherically symmetric anisotropic star. The most remarkable feature of our approach is that a large family of previously developed isotropic stellar solutions can be regained from our anisotropic family of solutions by suitably fixing the model parameters in our treatment. It will be interesting to explore the possibility of generating new class of solutions by choosing sets of values of m and n which have not been considered in this work. Probing the effects of electromagnetic field on top of anisotropy is another area which we would also like to take up in our future investigation and will be reported elsewhere.