1 Introduction

General relativity (GR) has proved to be extremely fruitful in describing the physical universe and the structures contained therein. Over and above contributing to our understanding of astrophysical bodies and the evolution of the universe, GR is quintessential in understanding the nature of gravity and its behaviour in the presence of extremely dense sources as well as in higher dimensions [1, 2]. With the discovery and observations of ultra-compact objects such as pulsars, neutron stars and black holes, the search for exact solutions of the Einstein field equations has moved away from mere mathematical excursions into the realm of modelling physical objects based on observational data [3]. It has just been over a century since the first solution of the Einstein field equations describing a self-gravitating, bounded object was first obtained by Schwarzschild [4]. The Schwarzschild interior solution describes a uniform density sphere and is a first approximation in describing the gravitational field of a static, spherically symmetric object. This solution is highly idealised and propagation speeds within the object exceed the speed of light thus rendering the model noncausal. Since the pioneering effort of Schwarzschild in obtaining exact solutions of the Einstein field equations describing the gravitational field of a bounded mass, there has been a massive drive to obtain realistic solutions describing self-gravitating objects. An in-depth study of the available exact solutions in the literature indicate that many of them fall short of describing physically realizable stellar structures [5]. Many of these solutions are only valid in some region of the object, other solutions display unphysical behaviour in the density and pressure profiles while many stellar models are unstable against radial perturbations. The wide body of exact solutions which currently exist were obtained through various assumptions on the spacetime geometry, matter content or both [6]. Spherical symmetry is the natural assumption to make when modelling static stars. There is, however, more freedom in choosing the matter content of the stellar fluid. In the past researchers have worked with perfect fluids, charged interiors, pressure anisotropy, bulk viscosity and scalar fields. More recently, motivated by developments in cosmology, modelling of stellar structures has included dark energy, dark matter and phantom energy [7, 8].

Departure from spherical symmetry has been utilised in modelling stars. The Vaidya–Tikekar (VT) superdense stellar model incorporates a spheroidal geometry for the interior of the star [9]. The VT model has been shown to approximate the behaviour of neutron stars to a very good approximation [10]. Tikekar et al. have successfully modelled stars with paraboidal symmetry. The spheroidal parameter which appears in the gravitational potential measures the deviation from spherical symmetry. Work on rotating stars utilise an axis-symmetric metric to describe the stellar interior [11, 12]. Recently there has been a surge in obtaining exact solutions of the Einstein field equations via embedding [13,14,15,16,17,18,19,20,21]. In 1947 Karmarkar obtained a restriction which is a necessary condition for embedding a spherically symmetric spacetime in four dimensions into a flat five-dimensional spacetime. In general, an n-dimensional Riemannian spacetime is said to be of class p if it can be embedded into a flat space of dimension \(n + p\) [22]. The Karmarkar condition relates to class 1 spacetimes. Pandey and Sharma later showed that the Karmarakar condition is only a necessary condition for a spacetime to be of class 1 [23]. A further requirement has to be imposed for sufficiency of the Karmarkar condition. The derivation of the Karmarkar condition is purely geometric in nature; it gives a relationship between the two gravitational potentials. This is useful because in order to obtain a complete description of the gravitational behaviour of the model one needs to specify one of the metric functions and the other is obtained via the Karmarakar condition. It is also interesting to note that the Karmarkar condition together with the assumption of pressure isotropy picks out the interior Schwarzschild solution as the only bounded matter configuration with vanishing pressure anisotropy. It follows that if the interior metric of a bounded sphere is of class 1, then the matter content is necessarily anisotropic or charged, with the Schwarzschild interior solution being the only exception.

In this paper we present a model of a spherically symmetric, charged object obtained by embedding a spherically symmetric static metric in Schwarzschild coordinates into a five-dimensional flat space. The pressure within the fluid distribution is anisotropic. The resulting condition arising from the embedding reduces the problem of finding an exact solution to the Einstein–Maxwell equations to specifying one of the gravitational potentials and the behaviour of the electric field intensity.

2 The Einstein–Maxwell field equations for charged anisotropic matter distribution

The line element describing the interior of a static, spherically symmetric matter distribution is given in Schwarzschild coordinates [24, 25] \(x^i=(r, \theta , \phi , t)\) as follows:

$$\begin{aligned} \mathrm{d}s^2 = - \mathrm{e}^{\lambda (r)} \mathrm{d}r^2 - r^2(\mathrm{d}\theta ^2 + \sin ^2\theta \mathrm{d}\phi ^2) + \mathrm{e}^{\nu (r)} \mathrm{d}t^2, \end{aligned}$$
(1)

where we seek the radial dependence of the potentials \(\lambda \) and \(\nu \).

In this work we study charged compact objects within the framework of classical general relativity. The Einstein–Maxwell field equations relating the spacetime geometry to the matter content are

$$\begin{aligned} {R^i}_j - \frac{1}{2} R {g^i}_j = \kappa ({T^i}_j + {E^i}_j), \end{aligned}$$
(2)

where \(\kappa = 8\pi \) is the Einstein coupling constant. We use geometrized units in which \(G=1=c\) with G and c are the Newtonian gravitational constant and speed of photons in vacuum, respectively.

We assume that the radial and tangential stresses within the interior matter distribution are unequal thus implying that the matter within the star is locally anisotropic. The energy-momentum tensor of the fluid the distribution and electromagnetic field are defined, respectively, as [26]

$$\begin{aligned} {T^i}_j= & {} [(\rho + p_t)v^iv_j - p_t{\delta ^i}_j + (p_r - p_t) \theta ^i \theta _j],\end{aligned}$$
(3)
$$\begin{aligned} {E^i}_j= & {} \frac{1}{4}\left( -F^{im}F_{jm} + \frac{1}{4}{\delta ^i}_jF^{mn}F_{mn}\right) , \end{aligned}$$
(4)

where \(v^i\) is the four-velocity, \(v^i=\mathrm{e}^{\nu (r)/2}{\delta ^i}_4\), \(\theta ^i\) is a unit space-like vector in the radial direction, \(\theta ^i = \mathrm{e}^{\lambda (r)/2}{\delta ^i}_1\), \(\rho \) is the energy density, \(p_r\) is the radial pressure and \(p_t\) is the tangential pressure. The components for \({T^i}_j\) and \({E^i}_j\) are defined, respectively, as

$$\begin{aligned} {T^1}_1= & {} -p_r,\quad {T^2}_2={T^3}_3=-p_t,\quad {T^4}_4=\rho ,\end{aligned}$$
(5)
$$\begin{aligned} {E^1}_1= & {} -{E^2}_2=-{E^3}_3={E^4}_4=\frac{1}{8\pi }\mathrm{e}^{\nu +\lambda }F^{14}F^{41}. \end{aligned}$$
(6)

Since we are employing spherical symmetry, the four-current component is only a function of radial distance, r. The only non-vanishing components of the electromagnetic field tensor are \(F^{41}\) and \(F^{14}\), related by \(F^{41} = - F^{14}\), which describe the radial component of the electric field. If q(r) represents the total charge contained within the sphere of radius r, then it can be defined by the relativistic Gauss law as

$$\begin{aligned} q(r) = 4\pi \int _0^r \sigma r^2 \mathrm{e}^{\lambda /2} \mathrm{d}r = r^2 \sqrt{-F_{14}F^{14}}. \end{aligned}$$
(7)

From Eq. (7), we obtain

$$\begin{aligned} F^{41}=- \mathrm{e}^{-(\nu +\lambda )/2} \frac{q(r)}{r^2}. \end{aligned}$$
(8)

For the spherically symmetric metric (1), the Einstein–Maxwell field equations may be expressed as the following system of ordinary differential equations [26]:

$$\begin{aligned} \frac{{\nu }^{\prime }}{r} \mathrm{e}^{-\lambda } - \frac{(1 - \mathrm{e}^{-\lambda })}{r^2} = 8\pi p_r - \frac{q^2}{r^4}= -8\pi ({T^1}_1+{E^1}_1,) \nonumber \\ \end{aligned}$$
(9)
$$\begin{aligned} \left[ \frac{{\nu }^{\prime \prime }}{2} - \frac{{\lambda }^{\prime }{\nu }^{\prime }}{4} + \frac{{{\nu }^{\prime }}^2}{4} + \frac{{\nu }^{\prime } - {\lambda }^{\prime }}{2r}\right] \mathrm{e}^{-\lambda }= & {} 8\pi p_t + \frac{q^2}{r^4} \nonumber \\= & {} -8\pi ({T^2_2}+{E^2}_2) \nonumber \\= & {} -8\pi ({T^3}_3+{E^3}_3) ,\nonumber \\ \end{aligned}$$
(10)
$$\begin{aligned} \frac{{\lambda }^{\prime }}{r} \mathrm{e}^{-\lambda } + \frac{(1 - \mathrm{e}^{-\lambda })}{r^2}=8\pi \rho + \frac{q^2}{r^4} =8\pi ({T^4}_4+{E^4}_4) , \end{aligned}$$
(11)

where the prime denotes differentiation with respect to r. If we define the anisotropy parameter as \(\varDelta = p_t - p_r\), then from Eqs. (9) and (10) we obtain [27]

$$\begin{aligned} \varDelta= & {} \left[ \frac{{\nu }^{\prime \prime }}{2} - \frac{{\lambda }^{\prime }{\nu }^{\prime }}{4} + \frac{{{\nu }^{\prime }}^2}{4} - \left( \frac{{\nu ^\prime } + {{\lambda }^{\prime }}}{2r}\right) \right] \mathrm{e}^{-\lambda } \nonumber \\&+ \left( \frac{1 - \mathrm{e}^{-\lambda }}{r^2}\right) - 2\frac{q^2}{r^4} . \end{aligned}$$
(12)

We note that when \(\varDelta = 0\) the pressure is isotropic at each interior point of the matter distribution. The term \(2(p_t - p_r)/r\) appears in the conservation equations \({T^i}_{j;i} = 0\) and represents a force due to the anisotropic nature of the fluid. When \(p_t > p_r\) the force associated with anisotropy is directed outwards and when \(p_t < p_r\) (\(\varDelta < 0\)), the force is directed inwards. For \(\varDelta > 0\) it has been shown that it is possible to construct more compact objects compared to their neutral counterparts (\(\varDelta = 0\)) [28]. Various approaches have been adopted in finding solutions of the above system of equations. The system (9)–(11) consists of the six unknowns \(\rho \), \(p_r\), \(p_t\), \(\nu \), \(\lambda \) and \(E^2 = q^2/r^4\), the electric field intensity. In attempting to find exact solutions of the system describing anisotropic charged compact objects one could specify an equation of state of the form \(p = p(\rho )\), choose the gravitational potentials \(\nu \) and \(\lambda \) based on physical grounds or prescribe the behaviour of the anisotropy parameter, \(\varDelta \).

By using Eqs. (9)–(11), the expression of the pressure gradient in terms of the anisotropy, the metric functions and charge read

$$\begin{aligned} \frac{\mathrm{d}p_r}{\mathrm{d}r} =- \frac{\nu '(\lambda '+\nu ')}{2r \mathrm{e}^{\lambda }}+\frac{q}{4\pi r^4} \frac{\mathrm{d}q}{\mathrm{d}r} + \frac{2\varDelta }{r}, \end{aligned}$$
(13)

where Eq. (13) represents the charged generalization of the well-known Tolman–Oppenheimer–Volkoff (TOV) equation of hydrostatic for anisotropic stellar structure [24, 25].

If the mass function for electrically charged fluid sphere is denoted by m(r) we may then write

$$\begin{aligned} \frac{2m(r)}{r}= 1 - \mathrm{e}^{-\lambda (r)} + \frac{q^2}{r^2}. \end{aligned}$$
(14)

Various studies of anisotropic charged compact objects have specified the behaviour of the mass function to obtain the gravitational potential \(\lambda (r)\). This is then fed back into the Einstein–Maxwell field equations to obtain the complete gravitational and thermodynamical behaviour of the model.

3 Class 1 condition for spherical symmetric metric

Let us consider a five-dimensional flat line element

$$\begin{aligned} \mathrm{d}s^{2}=-\!(\mathrm{d}z^1)^2\!-\!(\mathrm{d}z^2)^2\!-\! (\mathrm{d}z^3)^2-(\mathrm{d}z^4)^2\!+\!(\mathrm{d}z^5)^2, \end{aligned}$$
(15)

where we suppose the coordinates \(z^1\), \(z^2\), \(z^3\), \(z^4\) and \(z^5\) assume the following forms:

$$\begin{aligned}&z^1=r \sin \theta \cos \phi ,\quad z^2=r\sin \theta \sin \phi , \quad z^3=r\cos \theta , \\&z^4=\sqrt{K}\mathrm{e}^{\frac{\nu }{2}}\cosh {\frac{t}{\sqrt{K}}},\quad z^5=\sqrt{K} \mathrm{e}^{\frac{\nu }{2}}\sinh {\frac{t}{\sqrt{K}}}. \end{aligned}$$

In the above transformations K is a positive constant. We can then write the differential forms of the above components as

$$\begin{aligned} \mathrm{d}z^1=\mathrm{d}r\sin \theta \cos \phi \!+\! r\cos \theta \cos \phi \mathrm{d}\theta \!-\!r\sin \theta \sin \phi \mathrm{d} \phi ,\nonumber \\ \end{aligned}$$
(16)
$$\begin{aligned} \mathrm{d}z^2=\mathrm{d}r\sin \theta \sin \phi \!+\! r\cos \theta \sin \phi \mathrm{d}\theta \!+\!r\sin \theta \cos \phi \mathrm{d}\phi ,\nonumber \\ \end{aligned}$$
(17)
$$\begin{aligned} \mathrm{d}z^3=\mathrm{d}r\cos \theta - r\sin \theta \mathrm{d}\theta , \end{aligned}$$
(18)
$$\begin{aligned} \mathrm{d}z^4=\sqrt{K}\mathrm{e}^{\frac{\nu }{2}} \frac{\nu '}{2}\cosh {\frac{t}{\sqrt{K}}}\mathrm{d}r + \mathrm{e}^{\frac{\nu }{2}}\sinh {\frac{t}{\sqrt{K}}}\mathrm{d}t, \end{aligned}$$
(19)
$$\begin{aligned} \mathrm{d}z^5=\sqrt{K} \mathrm{e}^{\frac{\nu }{2}} \frac{\nu '}{2}\sinh {\frac{t}{\sqrt{K}}}\mathrm{d}r + \mathrm{e}^{\frac{\nu }{2}}\cosh {\frac{t}{\sqrt{K}}}\mathrm{d}t, \end{aligned}$$
(20)

where a prime denotes differentiation with respect to the radial coordinate r.

Substituting the above expressions \( \mathrm{d}z^1,~\mathrm{d}z^2,~ \mathrm{d}z^3,~ \mathrm{d}z^4 \) and \(\mathrm{d}z^5\) into the metric (15), we obtain

$$\begin{aligned} \mathrm{d}s^{2}= & {} -\left( 1+\frac{K\mathrm{e}^{\nu }}{4}{\nu '}^2\right) \mathrm{d}r^{2} \nonumber \\&-r^{2} (\mathrm{d}\theta ^{2}+\sin ^{2}\theta \mathrm{d}\phi ^{2} )+\mathrm{e}^{\nu (r)}\mathrm{d}t^{2} . \end{aligned}$$
(21)

A direct comparison of metric (21) and metric (1) yields

$$\begin{aligned} \mathrm{e}^{\lambda }=\left( 1+\frac{K\mathrm{e}^{\nu }}{4}{\nu '}^2\right) . \end{aligned}$$
(22)

Equation (22) stands for the embedding class condition.

The pressure anisotropy factor (\(p_t-p_r=\varDelta \)) is readily obtained from Eqs. (9) and (10) together with Eq. (22) as

$$\begin{aligned} \varDelta =\frac{\nu '\mathrm{e}^{-\lambda }}{32\pi }\left( \frac{\nu '\mathrm{e}^{\nu }}{2B^{2}r}-1\right) \left( \frac{2}{r}-\frac{\lambda '\mathrm{e}^{-\lambda }}{1-\mathrm{e}^{-\lambda }}\right) -\frac{2q^2}{r^4}. \end{aligned}$$
(23)

It is clear from (23) that when \(\varDelta = 0\), we have \(p_t = p_r\) at each interior point of the fluid distribution. At this point we should highlight the fact that the embedding class condition (22) together with the pressure isotropy (\(\varDelta = 0\)) yields only two exact solutions for uncharged fluids, (1) the interior Schwarzschild solution and (2) the Kohler–Chao solution [29]. The Kohler–Chao solution cannot be used to model a bounded configuration such as a star since there is no surface at which the radial pressure vanishes. Such a surface would define the boundary of the star. The Schwarzschild interior solution describes the interior gravitational field of a uniform density sphere and suffers various pathologies such as the prediction of superluminal propagation velocities within the fluid as well as being unstable against radial perturbations. In a recent paper Maurya and Govender [30] modelled charged compact objects with isotropic pressure via embedding. The pressure isotropy condition becomes a definition for the electric field intensity or the charge distribution. Just as in our approach here the embedding relates the two metric functions \(\nu (r)\) and \(\lambda (r)\). Recently the modelling of compact objects such as neutron stars, pulsars and strange stars has attracted huge attention amongst researchers. This is mainly due to the fact that a large number of data sets are available in the literature against which the strengths and merits of the various theoretical models can be tested. The role of the pressure anisotropy within the stellar core has been highlighted in many of these models.

4 Generalized charged anisotropic solution for compact star

We can recast Eqs. (9)–(11) in terms of the mass function as follows:

$$\begin{aligned} 8\pi p_r = \frac{[\nu ^{\prime }(r^2+q^2 - 2 r m) - 2m] }{r^3} +\frac{2q^2}{r^4}, \end{aligned}$$
(24)
$$\begin{aligned} 8\pi p_t= & {} \frac{[(q q^{\prime } -r m^{\prime })(2+r{\nu }^{\prime })-m(2r^2{\nu }^{\prime \prime } +r^2{{\nu }^{\prime }}^2 +r{\nu }^{\prime }-2)]}{2r^3} \nonumber \\&- \frac{2q^2{\nu }^{\prime } -(r^2+q^2)(2r{\nu }^{\prime \prime } +r{{\nu }^{\prime }}^2+2{\nu }^{\prime })}{4r^3} - \frac{2q^2}{r^4}, \end{aligned}$$
(25)
$$\begin{aligned} 8\pi \rho = \frac{2m^{\prime }}{r^2} - \frac{2qq^{\prime }}{r^3}. \end{aligned}$$
(26)

In this paper we would like to construct a generalized model by adopting a single generic function \(\nu (r)\). The invariance of the Ricci tensor requires that the energy density \(\rho (r)\), radial pressure \(p_r(r)\) and tangential pressure \(p_t(r)\) should be finite at the origin. The regularity of the Weyl invariants requires that mass m(r) and electric charge q(r) should attain minimum values at the centre \(r=0\) of the configuration (\(m(0)= q(0)=0\)) and attain maximum values at the surface of the star, i.e. \(m(0)=0\), \(m^{\prime }(r) > 0\) and \(q(0)=0\), \( q^{\prime }(r) > 0\).

In modelling of charged anisotropic compact stars Maurya et al. [31] have shown that the metric function \(\nu (0)=\) is finite constant, \(q(0)= 0\), \(\nu ^{\prime }(0)=0\) and \(\nu ^{\prime \prime }(0)> 0\). Since the energy density and radial pressure are positive finite and continuous it follows that \(r > 2m(r)\) [32, 33]. Form \(p_r \ge 0\) with \(r > 2m(r)\) we have \(\nu ^{\prime }(r)\ne 0\). This shows that the generic function \(\nu (r)\) is regular minimum at the centre and a monotone increasing function of r. Bearing in mind these observations we suppose the generic function \(\nu (r)\) has the following form:

$$\begin{aligned} \nu (r)= n\ln (1+Ar^2)+\ln B \end{aligned}$$
(27)

where we have two cases:

Case (i) \(n<0\) and \(A<0\),

Case (ii) \(n>0\) and \(A>0\).

Here B is positive constant. We observe that \(\nu (0)=\ln B\), \(\nu '=\frac{2n Ar}{(1+Ar^2)}\) and \(\nu ''=\frac{2nA (1-Ar^2)}{(1+Ar^2)^2}\). It follows that \(\nu (0)>0\), \(\nu '(0)=0\), \(\nu ''(0)=2nA >0\) and \(\nu (r)\ne 0\) with \(r\ne 0\) for both cases (i) and (ii). This implies that this generic source function \(\nu (r)\) is a monotone increasing function of r with regular minimum at \(r=0\) (Fig. 1). Substituting the value of \(\nu \) into Eq. (22) we obtain

$$\begin{aligned} \lambda = \ln [1+CAr^2 (1+Ar^2)^{(n-2)}], \end{aligned}$$
(28)

where \(C=n^2A BK\).

This form of the metric function is well motivated and has been utilised by numerous authors to model compact stars arising from the Karmarkar condition. The parameter n plays a pivotal role in the structure and stability of the compact object. Table 5 provides an overview of the class 1 solutions using the ansatz (27) for the metric function \(\nu (r)\). We observe that there is a strong connection as regards the range of n which admits physically viable models and the nature of the matter content of the star. Anisotropy and electric charge or the absence thereof dictate the admissibility of the range of n. It is evident from Eq. (27) that in the case of vanishing n the spacetime is rendered flat. In this study we will consider solutions for both \(n > 0\) and \(n < 0\). This approach will allow us to investigate the impact of the ’switch’, n on the various thermodynamical properties of the model. The solution is not well behaved in the range \( -3< n < 2.7\). For \(-7.5 < n \le -3 \) and \(2.7 \le n <4\), we will get a star with low mass. For \( n \le -7.5 \) and \( n\ge 4 \), we will get stellar models describing compact objects such as Her X-1.

Fig. 1
figure 1

Behaviour of gravitational potential \(\mathrm{e}^{\nu }\) (left panel) and \(\mathrm{e}^{\lambda }\) (right panel) verses fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Table 1 Numerical values of physical parameters \(AR^2\), A, C, B, \(E_0\) for the compact star Her X-1 of mass \(M=0.85 (M_\odot )\), radius \(R=8.10\) (km) [38] for negative values of n
Table 2 Numerical values of physical parameters \(AR^2\), A, C, B, \(E_0\) for the compact star Her X-1 of mass \(M=0.85 (M_\odot )\), radius \(R=8.10\) (km) [38] for positive values of n

In order to determine the mass function for an electrically charged compact star we suppose the electric charge function q(r) is of the form

$$\begin{aligned} q(r)= E_0A^2r^6(1 + Ar^2)^n \end{aligned}$$
(29)

where \(E_0\) is positive constant. We note that the electric field \((E = q/r^2)\) vanishes at the centre of the configuration. We note that in the case of isotropic pressure the condition of the pressure isotropy can be treated as a definition for the charge as a function of the radial coordinate. This approach does not guarantee that q(r) will have physically desirable properties such as the function defined in (29). Utilising Eqs. (14) and (29) we readily obtain the mass function m(r):

$$\begin{aligned} m(r) = \frac{Ar^3(1+Ar^2)^{n-2} [C+E_0 Ar^2(1+Ar^2)^2+C E_0A^2r^4(1+Ar^2)^{n}]}{2}. \nonumber \\ \end{aligned}$$
(30)

We observe from Eqs. (29) and (30) that \(q(0)=0\) and \(m(0)=0\). However, both \(q'(r)\) and \(m'(r)\) are positive for \(r>0\) in both cases (i) and (ii). This indicates that q(r) and m(r) are increasing monotonically away from centre and attain regular minima at \(r=0\).

By plugging the values of Eqs. (30) and (29) into Eqs. (24)–(26) we get [by assuming \(f=(1+Ar^2)\), \(\psi =Ar^2\)]

$$\begin{aligned} p_r=\frac{A[2n +E_0\psi f^{n+2}+Cf^n(-1+E_0\psi ^2f^n)]}{8\pi [f^2+C\psi f^n]},\quad \end{aligned}$$
(31)
$$\begin{aligned} p_t =\frac{(2+n \psi ) n A f^2-A f^n [E_0 (\psi f^4+C^2 \psi ^3 f^{2 n})+C f (1-\psi +2 E_0 \psi ^2 f^{n+1})]}{8\pi [f^2+C\psi f^n]^2},\quad \end{aligned}$$
(32)
$$\begin{aligned}&\rho =\frac{Af^n}{8\pi } \left[ -E_0\psi +\frac{C}{[f^2+C\psi f^n]}\right. \left. +\frac{2 C f [1+(n-1) \psi ]}{[f^2+C \psi f^n]^2} \right] .\quad \end{aligned}$$
(33)

The relation of Eq. (12) provides the anisotropic factor \(\varDelta \), which is given by

$$\begin{aligned} \varDelta =\frac{\psi [-n^2 f^2+2 n f (1+\psi +C f^n)+f^n (2 E_0 f^4+C^2 f^n \varDelta _1+2 C f \varDelta _2)]}{8 \pi [f^2+C \psi f^n]^2} \end{aligned}$$
(34)

where \(\varDelta _1=[-1+2 E_0 \psi ^2 f^n]\) and \(\varDelta _2=[-1+2 E_0 \psi ^2 f^{n+1}]\).

The gradients of the \(p_r\), \(p_t\) and \(\rho \) assume the following forms:

$$\begin{aligned} \frac{\mathrm{d}p_r}{\mathrm{d}r}=2rA^2 \times \left[ \frac{(f^2+C\psi f^n)[Dp_{r1}+n f^{n-1}(E_0 \psi f^2-C+C E_0\psi ^2 f^n)]+Dp_{r2} }{8\pi [f^2+C \psi f^n]^2}\right] ,\nonumber \\ \end{aligned}$$
(35)
$$\begin{aligned} \frac{\mathrm{d}p_t}{\mathrm{d}r}=-2rA^2\times \left[ \frac{Dp_{t1} Dp_{t2}+[f+C \psi f^{n-1}] [Dp_{t3}+Dp_{t4}]+f^{n+1} Dp_{t5}}{8 \pi [f^2+C \psi f^n]^3}\right] ,\nonumber \\ \end{aligned}$$
(36)
$$\begin{aligned} \frac{\mathrm{d}\rho }{\mathrm{d}r}=2rA^2 f \left[ -E_0 (f+n \psi ) f^{-1} \right. \left. \times +\frac{D\rho _1}{[f^2+C \psi f^n]^3}+\frac{D\rho _2+D\rho _3}{[f^2+C \psi f^n]^2} \right] , \end{aligned}$$
(37)

where

$$\begin{aligned} Dp_{r1}= & {} 2 n+E_0 f^{n-1} [1+3 \psi ^3 +\psi (5+2 C f^n) \\&+7 \psi ^2 +C (2+n) \psi ^2 f^n],\\ Dp_{r2}= & {} -[2+C f^n+\psi (2+C n f^{n-1})] \\&\times [2 n f+E_0 \psi f^{2+n}+C f^n (-1+E_0 \psi ^2 f^n)]\\ Dp_{t1}= & {} 2 [2+C f^n+\psi (2+C n f^{n-1})],\\ Dp_{t2}= & {} (2+n \psi ) n f^2-f^n [E_0 \psi f^4+C^2 E_0 \psi ^3 f^{2n} \\&+C f (1-\psi +2 E_0 \psi ^2 f^{n+1}],\\ Dp_{t3}= & {} -n^2f^2(1+3\psi )-n[4-C f^n-E_0\psi ^5f^n \\&-4E_0\psi ^4 f^n(1+Cf^n)+\psi (8-E_0 f^n)],\\ Dp_{t4}= & {} E_0 \psi ^3 f^n (6+8 C f^n+3 C^2 f^{2n}) -\psi ^2\\&\times [4-4 E_0 f^n+C f^n (1-4 E_0 f^n)],\\ Dp_{t5}= & {} -2 C \psi +E_0 [1+5 \psi ^4 +4 \psi (2+C f^n)\\&\times (1+2 \psi )+3 \psi ^2 (6+4 C f^n+C^2 f^{2n})],\\ D\rho _1= & {} -4 C f [1+(n-1)\psi ]\\&\times [2+C f^n+\psi (2+C n f^{-1+n})],\\ D\rho _2= & {} 2 C (n-1) f+2 C [1+(n-1)\psi ] \\&-C [2+C f^n+\psi (2+C n f^{n-1})],\\ D\rho _3= & {} nC f^{-1} [f^2+C \psi f^n]+2 C f [1+(n-1) \psi ]. \end{aligned}$$

The physical viability of our model will be pursued in the next section.

5 Physical properties of the solution

Since the pressure and density must be positive and finite at the centre, \((p_r)_{r=0}>0\), \((p_t)_{r=0}>0\) and \((\rho )_{r=0}>0\). Also the pressure and density must attain maxima at the centre and decrease continuously throughout the star, \(\left( \frac{\mathrm{d}^2p_r}{\mathrm{d}r^2}\right) _{r=0}<0\), \(\left( \frac{\mathrm{d}^2p_t}{\mathrm{d}r^2}\right) _{r=0}<0\) and \(\left( \frac{\mathrm{d}^2\rho }{\mathrm{d}r^2}\right) _{r=0}<0\). We have calculated

$$\begin{aligned} (p_r)_{r=0}=(p_t)_{r=0}=\frac{A (2n-C)}{8 \pi } > 0 , \end{aligned}$$
(38)
$$\begin{aligned} (\rho )_{r=0}=\frac{3AC}{8 \pi } >0 , \end{aligned}$$
(39)
$$\begin{aligned} \left( \frac{\mathrm{d}^2p_r}{\mathrm{d}r^2}\right) _{r=0}=\frac{2A^2 [C^2+E_0-C (3n-2)-2n]}{8 \pi } <0 ,\nonumber \\ \end{aligned}$$
(40)
Table 3 Physical parameters for Her X-1 for negative values of n
Table 4 Physical parameters for Her X-1 for positive values of n
Table 5 List of embedding class one solutions with well-behaved nature of \(\mathrm{d}p_i/\mathrm{d}\rho \) for the ansatz \(\mathrm{e}^{\nu (r)} = B(1+A r^2)^{n}\)
Fig. 2
figure 2

Behaviour of electric charge q (left panel) and m(r) versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Fig. 3
figure 3

Behaviour of radial pressure \(p_r\) (left panel) and \(p_t\) (right panel) versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

$$\begin{aligned} \left( \frac{\mathrm{d}^2p_t}{\mathrm{d}r^2}\right) _{r=0}=\frac{2A^2 [2C^2-E_0-C(5n-4)+n (n-4)]}{8 \pi } <0 ,\nonumber \\ \end{aligned}$$
(41)
$$\begin{aligned} \left( \frac{\mathrm{d}^2\rho }{\mathrm{d}r^2}\right) _{r=0}=\frac{2A^2 [-5C^2-E_0+5 C (n-2)]}{8 \pi } <0 . \end{aligned}$$
(42)

Case (i). If \(n<0\) and \(A<0\) Eqs. (38) and (39) lead to \(C>2n\) and \(C<0\). However, Eqs. (4042) give \(0\le E_0 < n^2\).

Case (ii). If \(n>0\) and \(A>0\) Eqs. (38) and (39) lead to \(C<2n\) and \(C>0\). However, Eqs. (4042) give \(0\le E_0 < n^2\).

6 Junction conditions

In order to generate a model of a physically realizable bounded object we need to ensure that the interior spacetime \(\mathcal{M}^{-}\) must match smoothly to the exterior spacetime \(\mathcal{M}^{+}\). Since the exterior spacetime is empty, \(\mathcal{M}^{+}\) is taken to be the Reissner–Nordstrom solution.

The boundary of the star is the surface for which the radial pressure vanishes, \(p_r=0\) at \(r=R\) (Misner and Sharp [44]). For our model we obtain

$$\begin{aligned} C=\frac{(1+A R^2)^{1-n} [2 n+E_0 A R^2 (1+A R^2)]}{(1-E_0 A^2 R^4 (1+A R^2)^n)}. \end{aligned}$$
(43)

The constant B can be determined by using the condition \(\mathrm{e}^{\nu (R)}=\mathrm{e}^{-\lambda (R)}\), which yields

$$\begin{aligned} B=\frac{1}{(1-AR^2)^n [1+C AR^2 (1-AR^2)^{n-2}]} . \end{aligned}$$
(44)

However, the constant A can be determined using the surface density \(\rho _s\) of the star.

6.1 Energy conditions

The charged anisotropic fluid sphere should satisfy the following three energy conditions: (1) the null energy condition (NEC), (2) the weak energy condition (WEC) and (3) the strong energy condition (SEC). For satisfying the above energy conditions, the following inequalities must hold simultaneously inside the charged fluid sphere:

$$\begin{aligned} \mathrm{NEC}: \rho +\frac{E^2}{8\pi }\ge 0, \end{aligned}$$
(45)
$$\begin{aligned} \mathrm{WEC}: \rho +p_r \ge 0 , \quad \rho +p_t + +\frac{E^2}{4\pi } \ge 0 , \end{aligned}$$
(46)
$$\begin{aligned} \mathrm{SEC}: \rho +p_r+2p_t+\frac{E^2}{4\pi } \ge 0. \end{aligned}$$
(47)
Fig. 4
figure 4

Behaviour of matter density \( \rho \) versus fractional radius r / R for Her X-1.The numerical values of the constants are given in Tables 1 and 2

Fig. 5
figure 5

Behaviour of the anisotropic factor \( \varDelta \) versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Fig. 6
figure 6

Behaviour of various energy conditions versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

6.1.1 Equilibrium condition

The Tolman–Oppenheimer–Volkoff (TOV) equation [24, 25] in the presence of charge is given from Eq. (13) as

$$\begin{aligned} \frac{\mathrm{d}p_r}{\mathrm{d}r} =- \frac{\nu ' (\lambda '+\nu ')}{2 r \mathrm{e}^{\lambda }}+\frac{q}{4\pi r^4} \frac{\mathrm{d}q}{\mathrm{d}r} + \frac{2\varDelta }{r}. \end{aligned}$$
(48)

The above equation can be expressed in terms of four different components: the gravitational force \(F_g=- \frac{\nu ' (\lambda '+\nu ')}{2 r \mathrm{e}^{\lambda }}\), the hydrostatic force \(F_h=- \mathrm{d}p_r/\mathrm{d}r\), the electric force \(F_e=\frac{q}{4 \pi r^4} \frac{\mathrm{d}q}{\mathrm{d}r}\) and the anisotropic force \(F_a=\frac{2\varDelta }{r}\) which are defined as

$$\begin{aligned} F_g=- \frac{2 n A^2 r [C (1 -Ar^2) f^n + n [f^2 + 2C Ar^2 f^n])}{[f^2 + 2C Ar^2 f^n]^2},\nonumber \\ \end{aligned}$$
(49)
$$\begin{aligned} F_h=-\frac{\mathrm{d}p_r}{\mathrm{d}r} , \end{aligned}$$
(50)
$$\begin{aligned} F_e=\frac{2 r E_0 A^2 f^{n-1}[3+(n+3) Ar^2]}{8 \pi } \end{aligned}$$
(51)
$$\begin{aligned} F_a=\frac{2\varDelta }{r} . \end{aligned}$$
(52)

Inspection of the various panels in Fig. 7 shows that the force due to anisotropy dominates the electromagnetic force for small |n|. As |n| increases the difference in the magnitudes of \(F_a\) and \(F_e\) decreases until they are equal for a particular value of |n|. A further increase in |n| shows that \(F_e\) dominates \(F_a\) with the relative difference being more marked for large positive values of n.

Fig. 7
figure 7

Behaviour of different forces versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Fig. 8
figure 8

Behaviour of radial velocity \(v_r\) (left panel) and tangential velocity \(v_t\) (right panel) verses fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Fig. 9
figure 9

Behaviour of radial velocity \(v^2_r\) (left panel) and tangential velocity \(v^2_t\) (right panel) versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

Fig. 10
figure 10

Behaviour of radial velocity \(v^2_r-v^2_t\) (left panel) and tangential velocity \(v^2_t-v^2_r\) (right panel) versus fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

6.1.2 Velocity of sound and stability analysis

The causality condition should be obeyed, i.e. the velocity of sound should be less than that of light in the model. In addition to the above the velocity of sound should be decreasing towards the surface i.e. \({\mathrm{d} \over \mathrm{d}r}~{\mathrm{d}p_r \over \mathrm{d}\rho }<0\) or \({\mathrm{d}^2 p_r\over \mathrm{d}\rho ^2}>0\) and \({\mathrm{d}\over \mathrm{d}r}{\mathrm{d}p_t \over \mathrm{d}\rho }<0\) or \({\mathrm{d}^2p_t \over \mathrm{d}\rho ^2}>0\) for \(0\le r\le r_b\). The velocity of sound is increasing with the increase of density and it should be decreasing outwards. From Fig. 8 we observe that the speed of sound decreases monotonically from the centre of the star (high density region) towards the surface of the star (low density region). The sound speed is less than unity, thus indicating that causality is preserved within the stellar core (Fig. 9). In their study of the stability of relativistic spheres, Herrera et al. adopted a perturbative scheme in which the energy density and the anisotropy are perturbed and the effects of these perturbations on the fluid elements were studied. They were able to show that different parts of the star respond differently to various degrees of anisotropy, which may lead to cracking or overturning within the core. Abreu et al. took a different approach to studying cracking in static spheres. In their approach the difference in the tangential and radial sound speeds served as an indicator of potentially unstable regions. They further showed that stable regions within the stellar fluid are characterised by the stability factor, \(|v_t^2-v_r^2|\), which has to be less than unity for a potentially stable configuration. Figure 10 clearly indicates that our model is stable for a large range of |n|.

6.1.3 Maximum allowable mass and redshift

The well-known Buchdahl [34] limit for relativistic static spheres, \(2M/R\le 8/9 \), has been generalised for static charged spheres. Work by Andréasson [35] and Böhmer and Harko [36] showed that the mass to radius ratio in the presence of charge was restricted to

$$\begin{aligned} \frac{Q^{2} (18 R^2+ Q^2) }{2R^{2} (12R^2+Q^2)}\le & {} \frac{M}{R} \nonumber \\\le & {} \left[ \frac{4R^2+3Q^2}{9R^2} +\frac{2}{9R} \sqrt{R^2+3Q^2}\right] .\nonumber \\ \end{aligned}$$
(53)

The compactness u(r) can be defined in terms of the effective mass, \(m_\mathrm{eff}\):

$$\begin{aligned} u(R)=\frac{m_\mathrm{eff}(R)}{R}=\frac{1}{2}[1-\mathrm{e}^{-\lambda (R)}] \end{aligned}$$
(54)

where

$$\begin{aligned} m_\mathrm{eff}=4\pi {\int ^R_0{\left( \rho +\frac{E^2}{8 \pi }\right) r^2 \mathrm{d}r}}=\frac{R}{2}[1-\mathrm{e}^{-\lambda (R)}] , \end{aligned}$$
(55)

and the metric potential \(\mathrm{e}^{-\lambda }\) is given in (28). In their study of anisotropic static spheres, Bowers and Liang [37] showed that the surface redshift can be arbitrarily large. In the case of isotropic stars the surface redshift has an upper bound of \(Z_s = 4.77\). The relative magnitude of the radial and tangential stresses within the core plays an important role in determining the magnitude of \(Z_s\). As pointed out by Maurya et al. [30] when \(p_t > p_r\) the associated surface redshift is greater than its isotropic counterpart. The gravitational surface redshift (\(Z_s\)) can be calculated from

$$\begin{aligned} Z_s= (1-2 u)^{\frac{-1}{2}} -1= \sqrt{1+C Ar^2 (1+Ar^2)^{(n-2)}}-1.\nonumber \\ \end{aligned}$$
(56)

We note that the surface redshift depends on the compactness u which should, in principle, be constrained by the Buchdahl limit. Tables 3 and 4 show that the surface redshift decreases with the increase in |n| (Fig. 11). For very large |n| the surface redshift is approximately constant.

Fig. 11
figure 11

Behaviour of redshift (z) verses fractional radius r / R for Her X-1. The numerical values of the constants are given in Tables 1 and 2

7 Discussion of results

We have presented an exact static model of the Einstein–Maxwell equations which describes a spherically symmetric charged body arising from the requirement that the internal geometry is of embedding class I. The energy-momentum tensor describes an anisotropic fluid with an electromagnetic field. Figure 1 displays the trend in the gravitational potentials as a function of the dimensionless ratio, r / R. The gravitational potentials are continuous and increase smoothly from the centre of the star towards the surface. An increase/decrease in n has no appreciable effect in the magnitude or nature of the gravitational potentials. In Fig. 2 we present the trend in the charge (left panel) and the mass (right panel). Both the charge and the mass vanish at the centre of the configuration and increases monotonically towards the surface of the star. An increase in |n| is accompanied by an increase in both the charge and the mass. The divergence is greater towards the surface layers of the star. Figure 3 illustrates the behaviour of the radial pressure (left panel) and the tangential pressure (right panel). It is clear that the radial and tangential pressures are monotonically decreasing functions of the radial coordinate. The radial pressure vanishes at some finite radius which defines the boundary of the star. We note that the tangential pressure is nonvanishing at the stellar surface. We also note that the radial and tangential pressures increase with an increase in |n|. This increase is noticeable closer to the inner layers of the star and is indistinguishable as the surface layers are approached. A very large increase in |n| of the order of \(10^3\) has very little effect on the relative magnitudes of both the radial and the transverse stresses throughout the interior of the star. The trend of the density is profiled in Fig. 4. We observe that the density is a monotonically decreasing function attaining a maximum value at the centre of the star. We observe an interesting trend in the density as |n| increases. An increase in |n| is accompanied by a decrease in the density at each interior point of the gravitating body. For very large values of |n| the density profile is approximately the same for each interior point. The decrease in the density is most noticeable closer to the centre of the star. The anisotropy parameter is displayed in Fig. 5. As pointed out earlier, the anisotropy parameter vanishes at the centre of the star and increases monotonically outwards towards the surface. An increase |n| is accompanied by an increase in \(\varDelta \) with the relative differences being more marked towards the surface layers of the star. All the energy conditions are satisfied at each interior point of the configuration as displayed in Fig. 6. The various forces operating within the stellar interior are plotted in Fig. 7. It has been pointed out that a change in |n| effects changes in the force due to anisotropy and the electromagnetic force. For small values of |n| we pointed out that the anisotropic force dominates the electromagnetic force. This trend switches over for large |n|. Our model obeys the causality condition throughout the stellar interior (Fig. 8). The stability of our model was studied by looking at the relative sound speeds squared (Fig. 9). The stability analysis due to Abreu et al. shows that there are no unstable regions within the stellar core, indicating that the likelihood of cracking occurring within our model is remote (Fig. 10). Figure 7 reveals a new phenomenon associated with these models. We note for the first time that the relative difference between the electromagnetic force and the force due to anisotropy can change sign and this is directly related to an increase in |n|. Figure 11 shows the trend of the redshift inside the star. The details of the embedding class one solutions with well-behaved nature of \(\mathrm {d}p_i/\mathrm {d}\rho \) for the ansatz (27) \(e^{ \nu (r)} = B (1 + Ar^2)^n\) is given by Table 5.