1 Introduction

Despite of the great, well established and successful theory, the general theory of relativity, in the past century, numerous valuable modifications are being suggested by researchers. In these modification, the Ricci scalar is replace by some arbitrary function, like \(f({\mathcal {R}})\) in which \({\mathcal {R}}\) is Ricci scalar, \(f({\mathcal {G}})\), where \({\mathcal {G}}\) in Gauss–Bonnet invariant and many others as discussed in Refs. [1,2,3,4,5,6,7,8,9].

The expansion of the universe is the remarkable phenomenon which is being addressed by these modified theories [10]. The well-established fact is, the accelerated expansion of universe cannot be explaining by GR alone in its regular arrangement without adding extra term in the gravitational Lagrangian or exotic matter [11, 12]. The simplest modification was given by Buchdal in 1970 [13] with the help of replacement of \({\mathcal {R}}\) by \(f({\mathcal {R}})\) arbitrary function of \({\mathcal {R}}\) in the Hilbert–Einstein gravitational action. In literature, lot of information regarding modified theories of gravity is available [14,15,16,17,18,19,20]. One of the well-known modified theory is, Gauss Bonnet gravity, which has been studied many times in the recent past years [22, 23]. In this modified gravity, the Hilbert–Einstein action consist of a function \(f({\mathcal {R}},{\mathcal {G}})\) instead of \({\mathcal {R}}\). This is one of the fact that the additional Gauss–Bonnet term resolve the shortcomings of \(f({\mathcal {R}})\) gravity theory in the background of large expansion of universe [21,22,23,24,25]. The simplest form of \(f({\mathcal {R}},{\mathcal {G}})\) modified gravity is the \(f({\mathcal {G}})\) gravity which is widely addressed and can reproduce any kind of cosmological solutions.

Like, it could help out in the possible study of an acceleration regimes, and their transition to decelerated regimes, inflationary epoch and passes all tests evoked by solar system experiments and crossing phantom divide line [26, 27]. The \(f({\mathcal {G}})\) gravity is less constrained than \(f({\mathcal {R}})\) gravity as discussed in [28]. In addition, the \(f ({\mathcal {G}})\) gravity offer an efficient platform to analyze several cosmic issues as an alternate to dark energy [29]. similarly, the \(f ({\mathcal {G}})\) gravity is very supportive to study the behavior of finite time future singularities along with late time eras of an accelerating universe [30, 31]. Furthermore, in the background of some viable models in \(f({\mathcal {G}})\) gravity, the cosmic accelerating nature followed by matter era is also studied [28, 29]. Several viable \(f ({\mathcal {G}})\) gravity models were suggested for the purpose to pass some certain solar system constraints [28, 29] which are studied in [32] and further bounds on \(f ({\mathcal {G}})\) gravity models may develop from the behavior of energy conditions [33,34,35].

Observations of compact objects like pulsars, neutron stars and black holes have attracted the researchers towards the useful physical modeling stuff based on highly precise observational data instead of just finding the mathematical expeditions [36].

Recently, some of the physical properties of different strange compact stars were studied in the framework of different modified gravity theories and it was concluded that all these strange stars under consideration are stable, matter content is realistic and obeys all the energy conditions [37,38,39]. In favor of modeling static objects, supposition of spherical symmetry geometry is very useful and natural while there are more options in the choice of matter content. In past, many researchers focused their attention on perfect fluid matter content. While fluids with viscosity and pressure anisotropic fluids have also been studied and concluded that the anisotropy disturb the stability of the configuration relative to local isotropic case. Furthermore, the effects of local anisotropy have been elaborated with the help of equation of state [40]. Therefore it looks suitable to deal the anisotropic pressure with modified gravity models. Some of the physical properties of compact stars have been studied in the presence of pressure anisotropy and charge [41,42,43,44].

The aim of this research work is to investigate the role of \(f({\mathcal {G}})\) gravity models in modeling of realistic charged compact stellar structures. We investigate the different structural properties, like evolution of charged matter density and anisotropic pressure, the Tolman–Oppenheimer–Volkoff equation, the stability, the equation of state parameters as well as the different energy conditions, for different observational data of compact stars. This paper is design as, in a very next section, we discuss the modified \(f({\mathcal {G}})\) gravity with charged anisotropic matter distribution of the static spherically symmetric geometry. In Sect. 3, we demonstrate some of viable \(f({\mathcal {G}})\) gravity models. Section 4 is dedicated to check the physical analysis and viability of different well known compact stars through plots. And finally, we summarize the main results in last section.

2 \(f({\mathcal {G}})\) gravity

This section is to provide the extended version of Gauss–Bonnet gravity with its equations of motion. For \(f({\mathcal {G}})\) gravity, the usual Einstein–Hilbert action is modified as follows

$$\begin{aligned} S= & {} \int {d^4}x\sqrt{ - g} \left[ {\frac{{\mathcal {R}}}{2} + f({\mathcal {G}})} \right] \nonumber \\&+\, {S_m}\left( {{g^{\mu \nu }},\psi } \right) +{S_e}\left( {{g^{\mu \nu }},\psi } \right) , \end{aligned}$$
(1)

where \({\kappa ^2} = 8\pi G \equiv 1\), \({\mathcal {R}},~f,~{S_m}({{g^{\mu \nu }},\psi }),~{S_e}({{g^{\mu \nu }},\psi })\) are the Ricci scalar, arbitrary function of Gauss–Bonnet invariant, the matter action and the charged action ,respectively. The Gauss–Bonnet invariant quantity is

$$\begin{aligned} {\mathcal {G}} = {\mathcal {R}}^2 - 4{R_{\mu \nu }}{R^{\mu \nu }} + {R_{\mu \nu \alpha \beta }}{R^{\mu \nu \alpha \beta }}, \end{aligned}$$
(2)

where \(R_{\mu \nu }\), \({R_{\mu \nu \alpha \beta }}\) are the Ricci and the Riemannian tensors. Upon varying the above action with respect to \(g_{\mu \nu }\), we get the modified field equations for \(f({\mathcal {G}})\) gravity as

$$\begin{aligned} {R_{\mu \nu }} - \frac{1}{2}{\mathcal {R}}{g_{\mu \nu }} = T_{\mu \nu }^{\text {eff}}, \end{aligned}$$
(3)

where \(T_{\mu \nu }^{\text {eff}}\) is named as effective stress-energy tensor with its expression as follows

$$\begin{aligned} T_{\mu \nu }^{\mathrm{{eff}}}&= {\kappa ^2}({T_{\mu \nu }} + {E_{\mu \nu }}) - 8\left[ {{R_{\mu \rho \nu \sigma }}} \right. + {R_{\rho \nu }}{g_{\sigma \mu }} - {R_{\rho \sigma }}{g_{\mu \nu }} \nonumber \\&\quad -\, {R_{\mu \nu }}{g_{\rho \sigma }} + {R_{\mu \sigma }}{g_{\nu \rho }}\nonumber \\&\quad +\, \frac{1}{2}{\mathcal {R}}({g_{\mu \nu }}{g_{\rho \sigma }} - {g_{\mu \sigma }}\left. {{g_{\nu \rho }})} \right] {\nabla ^\rho }{\nabla ^\sigma }{f_G}\nonumber \\&\quad +\, \left( {{\mathcal {G}}{f_G} - f} \right) {g_{\mu \nu }}, \end{aligned}$$
(4)

where subscript G defines the derivation of the corresponding term with the GB term, while \({T_{\mu \nu }}\) is the usual stress energy momentum tensor and

$$\begin{aligned} {E_{\mu \nu }} = \frac{{{g_{\mu \mu }}}}{2}\left[ { - {F^{\mu \alpha }}{F_{\alpha \nu }} + \frac{1}{4}\delta _\nu ^\mu {F^{\alpha \beta }}{F_{\alpha \beta }}} \right] \end{aligned}$$
(5)

2.1 Anisotropic matter distribution in \(f({\mathcal {G}})\) gravity

Here, we wish to examine the effects of anisotropic stresses over the stability of compact charged stars. For this purpose, we take the distribution of matter content source to be anisotropic having the following mathematical formulation

$$\begin{aligned} {T_{\alpha \gamma }} = (\rho + {P_r}){V_\alpha }{V_\gamma } - {P_t}{g_{\alpha \gamma }} + \Pi {U_\alpha }{U_\gamma }, \end{aligned}$$
(6)

where \(\rho \) is fluid energy density, \(P_t\) is tangential pressure component, \(P_r\) is radial pressure component and \(\Pi \) is equal to \(P_r-P_t\). Furthermore, \({V_\gamma }\) and \(U_\gamma \) are four velocity and four vector of the fluid, respectively. These quantities obey \({V^\gamma }{V_\gamma }=1\) and \({U^\alpha }{U_\alpha }=-\,1\) relation under the comoving coordinate system,.

Now, we suppose the interior relativistic structure to be static and spherical symmetric everywhere. In this direction, we take the general line element static spherical symmetric geometry as following

$$\begin{aligned} d{s^2} = {e^{a(r)}}d{t^2} - {e^{b(r)}}d{r^2} - {r^2}\left( {d{\theta ^2} + {{\sin }^2}\theta d{\phi ^2}} \right) , \end{aligned}$$
(7)

Where a and b are arbitrary constant. Now by solving the field equations (3), we get

$$\begin{aligned} \rho + E^2&= \frac{1}{{2{r^2}}}{\mathrm{{e}}^{ - 2b}}\left[ { - 2{\mathrm{{e}}^b}} \right. + 2{\mathrm{{e}}^{2b}} - {\mathrm{{e}}^{2b}}f{r^2} + {\mathrm{{e}}^{2b}}{r^2}{f_G}{\mathcal {G}}\nonumber \\&\quad +\, 2b'({\mathrm{{e}}^b}r - 2({\mathrm{{e}}^b} - 3){f_G}^\prime ) - 8{f_G}^{\prime \prime } + 8\left. {{\mathrm{{e}}^b}{f_G}^{\prime \prime }} \right] , \end{aligned}$$
(8)
$$\begin{aligned} {p_r} - E^2&= \frac{{{\mathrm{{e}}^{ - 2b}}}}{{2{r^2}}}\left[ {{\mathrm{{e}}^b}(2} + {\mathrm{{e}}^b}({r^2}f - 2)) - {\mathrm{{e}}^{2b}}{r^2}{f_G}{\mathcal {G}}\right. \nonumber \\&\quad \left. +\, 2a'({\mathrm{{e}}^b}r - 2({\mathrm{{e}}^b} - 3) {{f_G}^\prime )} \right] , \end{aligned}$$
(9)
$$\begin{aligned} {p_t}+ E^2&= \frac{1}{{4r}}{\mathrm{{e}}^{ - 2b}}\left[ { - 2{\mathrm{{e}}^{2b}}} r{f_G}{\mathcal {G}} + {{a'}^2}({\mathrm{{e}}^b}r + 4{f_G}^\prime )\right. \nonumber \\&\quad +\, 2({\mathrm{{e}}^{2b}}rf - {\mathrm{{e}}^b}b'+\, ({\mathrm{{e}}^b}r + 4{f_G}^\prime ){a^{\prime \prime }})\nonumber \\&\quad \left. + a'( - b'({\mathrm{{e}}^b}r + 12{f_G}^\prime ) + 2({\mathrm{{e}}^b} + 4 {{f_G}^{\prime \prime }))} \right] . \end{aligned}$$
(10)

Here, \(E^2=\frac{Q^2}{8\pi r^4}\). We suppose \(a =r^2 B+C\) and \(b=r^2A\) as suggested by Krori and Barua [45], here A, B and C are the arbitrary constant. Using these definitions, we reach at

$$\begin{aligned} \rho&= 2A{\mathrm{{e}}^{ - A{r^2}}} - \frac{f}{2} + \frac{1}{{{r^2}}} - \frac{{{\mathrm{{e}}^{ - A{r^2}}}}}{{{r^2}}} + \frac{1}{2}{f_G}{\mathcal {G}} - \frac{{{Q^2}}}{{8\pi {r^4}}}\nonumber \\&\quad +\,\frac{{12A{\mathrm{{e}}^{ - 2A{r^2}}}{f_G}^\prime }}{r}\nonumber \\&\quad -\, \frac{{4A{\mathrm{{e}}^{ - A{r^2}}}{f_G}^\prime }}{r} - \frac{{4{\mathrm{{e}}^{ - 2A{r^2}}}{f_G}^{\prime \prime }}}{{{r^2}}} + \frac{{4{\mathrm{{e}}^{ - A{r^2}}}{f_G}^{\prime \prime }}}{{{r^2}}}, \end{aligned}$$
(11)
$$\begin{aligned} {p_r}&= 2B{\mathrm{{e}}^{ - A{r^2}}} + \frac{f}{2} - \frac{1}{{{r^2}}} + \frac{{{\mathrm{{e}}^{ - A{r^2}}}}}{{{r^2}}} - \frac{1}{2}{f_G}{\mathcal {G}} + \frac{{{Q^2}}}{{8\pi {r^4}}}\nonumber \\&\quad +\, \frac{{12B{\mathrm{{e}}^{ - 2A{r^2}}}{f_G}^\prime }}{r} - \frac{{4B{\mathrm{{e}}^{ - A{r^2}}}{f_G}^\prime }}{r}, \end{aligned}$$
(12)
$$\begin{aligned} p_t&= 2B{\mathrm{{e}}^{ - A{r^2}}} - A{\mathrm{{e}}^{ - A{r^2}}} + \frac{f}{2} - AB{\mathrm{{e}}^{ - A{r^2}}}{r^2} \nonumber \\&\quad +\, {B^2}{\mathrm{{e}}^{ - A{r^2}}}{r^2} - \frac{1}{2}{f_G}{\mathcal {G}}- \frac{{{Q^2}}}{{8\pi {r^4}}}\nonumber \\&\quad +\, \frac{{4B{\mathrm{{e}}^{ - 2A{r^2}}}{f_G}^\prime }}{r} - 12AB{\mathrm{{e}}^{ - 2A{r^2}}}r{f_G}^\prime \nonumber \\&\quad +\, 4{B^2}{\mathrm{{e}}^{ - 2A{r^2}}}r{f_G}^\prime + 4B{\mathrm{{e}}^{ - 2A{r^2}}}{f_G}^{\prime \prime } \end{aligned}$$
(13)

We will use these equations with different models. Here, we see charge contribute in \(\rho \), \(p_r\) and \(p_t\). Now consider the quark matter EoS

$$\begin{aligned} {p_r} = \frac{1}{3}\left[ {\rho - 4{B_g}} \right] \end{aligned}$$
(14)

where \(B_g\) is bag constant. Using this equation, we find the expression for charge, read as

$$\begin{aligned} Q= & {} 2{\mathrm{{e}}^{ - A{r^2}}}\sqrt{\pi }r\left[ {{\mathrm{{e}}^{2A{r^2}}}} \right. (2 - 2Bg{r^2} + {r^2}( - f + \mathcal {G}f'))\nonumber \\&+\, 2{f^{\prime \prime }}(3(A - 3B)r\mathcal {G}' - {\mathcal {G}^{\prime \prime }})\nonumber \\&-\, 2{{\mathcal {G}'}^2}{f^{\left( 3 \right) }} + {\mathrm{{e}}^{A{r^2}}}( - 2 + (A - 3B){r^2} \nonumber \\&+\, 2{f^{\prime \prime }}( - \left( {A - 3B} \right) r\mathcal {G}' + {\mathcal {G}^{\prime \prime }}) + 2{{\mathcal {G}'}^2}{\left. {{f^{\left( 3 \right) }})} \right] ^{\frac{1}{2}}}\nonumber \\ \end{aligned}$$
(15)

The expression for Q contain a square-root which means both sign for charge are acceptable but we will consider the positive sign of charge for further investigation.

3 Matching condition and different models

In this section, we consider a hypersurface \(\Sigma \) that is a boundary of both exterior and interior regions. Furthermore, we suppose Reissner–Nordstrm metric for the description of exterior geometry, written as

$$\begin{aligned} d{s^2}= & {} \left[ {1 - \frac{{2m}}{r} + \frac{{{Q^2}}}{{{r^2}}}} \right] d{t^2} - {\left[ {1 - \frac{{2m}}{r} + \frac{{{Q^2}}}{{{r^2}}}} \right] ^{ - 1}}d{r^2}\nonumber \\&-\, {r^2}\left( {d{\theta ^2} + \sin {\theta ^2}d{\varphi ^2}} \right) , \end{aligned}$$
(16)

where m, r and Q is the mass, radius and charge, respectively. The interior of given metric in Eq. (7) for the charged fluid distribution join smoothly with the above exterior of Reissner–Nordstrm metric. By matching the these two geometries at \(r=R\) and \(m(R)=M\), we get

$$\begin{aligned} A= & {} -\,\frac{{ 1}}{{{R^2}}}\ln \left[ {1+\frac{{{Q^2}}}{{{R^2}}} - \frac{{2M}}{R}} \right] , \end{aligned}$$
(17)
$$\begin{aligned} B= & {} \left( {\frac{M}{R^3} + \frac{{{Q^2}}}{{{R^4}}}} \right) {\left[ {1 + \frac{{{Q^2}}}{{{R^2}}}- \frac{{2M}}{R}} \right] ^{ - 1}}, \end{aligned}$$
(18)
$$\begin{aligned} C= & {} \ln \left[ {1 + \frac{{{Q^2}}}{{{R^2}}}- \frac{{2M}}{R}} \right] \nonumber \\&-\, \left( {\frac{M}{R} - \frac{{{Q^2}}}{{{R^2}}}} \right) {\left[ {1 + \frac{{{Q^2}}}{{{R^2}}}- \frac{{2M}}{R}} \right] ^{ - 1}}. \end{aligned}$$
(19)
Table 1 The approximate values of the masses, radii and compactness for charged compact stars, Vela X-1, SAXJ 1808.4-3658, and 4U 1820-30 and their numerical values of the constants A, and B

We find the numerical values of these constat for three different strange compact physical stars as shown in Table 1. Furthermore, we will take some of the viable models for the study of different compact star properties like the stability analysis energy conditions etc As

$$\begin{aligned}f(\mathcal {G})=f_i(\mathcal {G})\end{aligned}$$

where we will take three different models \(i=1, 2, 3\)

3.1 Model 1

First, we assume the power-law model with the additional logarithmic correction term [46]

$$\begin{aligned} f_1 = \alpha _1 {\mathcal {G}^{n_1}}+ \beta _1\mathcal {G}\log (\mathcal {G}), \end{aligned}$$
(20)

where \(\alpha _1,~n_1\) and \(\beta _1\) are arbitrary constants. This model could provide observationally well-consistent cosmic results because of its extra degrees of freedom allowed in the dynamics.

3.2 Model 2

Next, we take another model having the form [47]

$$\begin{aligned} f_2=\alpha _2 {\mathcal {G}}^{n_2} \left( \beta _2 {\mathcal {G}}^m+1\right) , \end{aligned}$$
(21)

where \(\alpha _2,~\beta _2\) and m are any constant number, while \(n_2>0\). This model is very helpful for the treatment of finite time future singularities.

3.3 Model 3

Further, we assume another viable model of the form

$$\begin{aligned} f_3=\frac{{{a_1} {{\mathcal {G}}^{n_3}} + {b_1}}}{{{a_2} {{\mathcal {G}}^{n_3}} + {b_2}}}, \end{aligned}$$
(22)

here \(a_1,a_2,b_1,b_2\) and \(n_3\) are arbitrary constants with \(n_3>0\).

From the condition \(p_r(R)=0\), We find the value of \(B_g\) as shown in Table 2.

Table 2 The approximate values of the constant \(B_g\) for the three different stars under three different models

Using these model with Eqs. (1113), we get \(\rho \), \(p_r\) and \(p_t\) from which we check the different aspect of compact stars as shown in Table 1. We will discuss these aspect one by one in the following section.

4 Aspects of \(f({\mathcal {G}})\) gravity models

In this section, we discuss some of physical aspects of the above charged stars from the interior solution. We present the anisotropic behavior and stability of these charged stars under consideration of three different \(f(\mathcal {G)}\) viable models. We discuss these aspects one by one in following

4.1 Variation of energy density and anisotropic stresses

We study the influence of quark matter EoS with the anisotropic stresses at the center with modified \(f({\mathcal {G}})\) gravity models. The corresponding variations in the vicinity of energy density along with anisotropic stresses are shown in Figs. 12 and 3, respectively.

The evolution of the density for the strange star candidate Vela X-1, SAX J 1808.43658, and 4U 1820-30 are shown in Fig. 1. Here, for \(r\rightarrow 0\), the density goes to its maximum value. In fact, this indicates the high compactness of the core of these stars and validating our models in \(f({\mathcal {G}})\) gravity under investigation for the outer region of the core.

In case of model 1: The density at core of Vela X-1 is \(1.33881\times 10^{15}\) g cm\(^{-3}\), the density at core of SAX J 1808.43658 is \(2.72436\times 10^{15}\) g cm\(^{-3}\), while 4U 1820-30 having density at core is \(1.223106\times 10^{15}\) g cm\(^{-3}\).

Furthermore, the surface density of Vela X-1 under model 1 is \(7.215861\times 10^{14}\) g cm\(^{-3}\), SAX J 1808.43658 having \(1.362573\times 10^{15}\) g cm\(^{-3}\), while 4U 1820-30 having \(6.593945\times 10^{14}\) g cm\(^{-3}\).

The Central and surface density of these stars for different models are shown in Table 3.

Similarly, the variation of the radial and traverser pressure,are shown in Figs. 2, 3.

The behavior of radial pressure is, for \(r\rightarrow 0\), the radial pressure \(1.849116\times 10^{35}\) g cm\(^{-1}\) s\(^{-2}\) for Vela X-1 under model 1. SAX J 1808.43658 having \(4.0796995\times 10^{35}\) g  cm\(^{-1}\) s\(^{-2}\) at core and in case of 4U 1820-30, the radial pressure at core is \(1.688794\times 10^{35}\) g cm\(^{-1}\) s\(^{-2}\).

The transverse pressure in consideration of model 1, For Vela X-1, the transverse pressure is \(1.84911386\times 10^{35}\) g cm\(^{-1}\) s\(^{-2}\), for SAX J 1808.43658 is \(4.0795867\times 10^{35}\) g cm\(^{-1}\) s\(^{-2}\) while for 4U 1820-30 is \(1.6887926204\times 10^{35}\) g cm\(^{-1}\) s\(^{-2}\).

Fig. 1
figure 1

Variation of density profile for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Fig. 2
figure 2

Evolution of radial pressure for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Fig. 3
figure 3

Evolution of transverse pressure for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Table 3 The approximate values of Central density \(\rho _c\) and surface density \(\rho _R\) for three different models

The variation of radial derivative of density, \(\frac{d\rho }{{dr}}\), radial derivative of radial pressure, \(\frac{dp_r}{{dr}}\), and radial derivative of transverse pressure, \(\frac{dp_t}{{dr}}\) are shown in Figs. 45 and 6 respectively.

We see that these variations are negative and for \(r=0\), we get

$$\begin{aligned}&{\left. {\frac{{d\rho }}{{dr}}} \right| _{r = 0}} = 0\\&{\left. {\frac{{d{p_r}}}{{dr}}} \right| _{r = 0}} = 0 \end{aligned}$$

which is expected. e.g. central density of stars \(\rho (r=0)=\rho _c\).

Fig. 4
figure 4

Evolution of \(d\rho /dr\) for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Fig. 5
figure 5

Evolution of \(dp_r/dr\) for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Fig. 6
figure 6

Evolution of \(dp_t/dr\) for charged stars, Vela X-1, SAX J 1808.4-3658, and 4U 1820-30, under different viable \(f({\mathcal {G}})\) models

Fig. 7
figure 7

Different energy conditions for Model 1

4.2 Energy conditions

To deal with a physically viable and acceptable matter field, there are some mathematical constraints which should be obeyed by stress-energy tensor, these constraints are known as energy conditions. These energy conditions are coordinate invariant and can be written as following.

  • NEC: \( \rho + {p_i} \ge 0\) .

  • WEC: \( \rho \ge 0\), \( \rho + {p_i} \ge 0\) .

  • SEC: \( \rho + {p_i} \ge 0\), \( \rho + {p_i} + {p_t} \ge 0\) .

  • DEC: \( \rho \ge |{p_i}|\) .

Here \(i=r,t\) and \(\rho \), \(p_r\) and \(p_t\) include electric charge contributions as well.

All these above energy conditions for three different charged compact relativistic structures are well satisfied under consideration of different viable \(f({\mathcal {G}})\) gravity models. The evolution of these energy conditions are shown graphically in Figs. 78 and 9.

Fig. 8
figure 8

Different energy conditions for Model 2

Fig. 9
figure 9

Different energy conditions for Model 3

4.3 Equilibrium condition

To investigate the equilibrium of inner structure of these charged compact stars, we use the generalized Tolman–Oppenheimer–Volko (TOV) equation. For charged spherical anisotropic stellar interior geometry, this equation is written

$$\begin{aligned} \frac{{d{p_r}}}{{dr}} + \frac{{\nu '(\rho + {p_r})}}{2} + \frac{{2({p_r} - {p_t})}}{r} + \frac{{\sigma Q}}{{{r^2}}}{e^{\lambda /2}} = 0, \end{aligned}$$
(23)

where \(\sigma \) is charge density. Furthermore, the above Eq. (23) may be written as a sum of different forces e.g. gravitational, hydrostatic, anisotropic and electric forces

$$\begin{aligned} F_g + F_h + F_a+F_e= 0, \end{aligned}$$
(24)

which yields

$$\begin{aligned} F_g= & {} - r B(\rho +p_r),\quad F_h=\frac{{-d{p_r}}}{{dr}}, \nonumber \\ F_a= & {} 2\frac{{({p_r} - {p_t})}}{r},\quad F_e= \frac{{\sigma Q}}{{{r^2}}}{e^{\lambda /2}} \end{aligned}$$
Fig. 10
figure 10

The variation of hydrostatic force (\(F_h\)), gravitational force (\(F_g\)), anisotropic force \((F_a)\) and electric force \(F_e\) under consideration of different viable \(f({\mathcal {G}})\) models

By using these definitions with the values of different parameters from Table 1, we check the variations of these forces and their hydrostatic equilibrium, as shown in Fig. 10.

The left plot shows the evolution of these forces in background of first model, the middle one is for second model and the right plot describe the variation of these forces because of third model. It is clear from Fig. 10, that the electric force has a very negligible effect in this balancing mechanism.

4.4 Stability analysis

In this section, we investigate the stability of the interior of stars under modified \(f({\mathcal {G}})\) theory. For the mathematical modeling of compact stellar structures, it is to be noted that only those stellar models are significant which are stable against the variations. Hence, the role of stability is very crucial and burning issue in the modeling of compact objects. The stability of stellar structure has been studied by many researches. Here we adopt the techniques which is based on the concept of overturning (or cracking) [48]. According to this, the radial speed of sound \(v_{sr}^{2}\) as well as transverse speed of sound \(v_{st}^{2}\) must be in the range of a closed interval [0, 1] to preserve the causality condition and for stability the necessary condition \(0\le v_{sr}^{2}-v_{sr}^{2}\le 1\) should be obeyed.

Fig. 11
figure 11

Variations of \(v_{st}^2\) for different viable \(f({\mathcal {G}})\) gravity models

Fig. 12
figure 12

Variations of \(v_{st}^2 - v_{sr}^2\) for different viable \(f({\mathcal {G}})\) gravity models

Fig. 13
figure 13

Variations of radial EoS parameter for different viable \(f({\mathcal {G}})\) gravity models

The radial and transverse speeds is defined as

$$\begin{aligned} \frac{{d{p_r}}}{{d\rho }} = v_{sr}^2 \end{aligned}$$

and

$$\begin{aligned} \frac{{d{p_t}}}{{d\rho }} = v_{st}^2 \end{aligned}$$

In our case, \(v_{sr}^2\sim 1/3\) and \(v_{sr}^2\) is plotted in Fig. 11, which obey the condition \(0 \le v_{sr}^2 \le 1\) and \(0 \le v_{st}^2 \le 1\) which is the indication of causality preservation within these charged compact stars.

Similarly, for stability, we plot \(v_{st}^2-v_{sr}^2\) as shown in Fig. 12. It is to be noted that all of our charged stellar structures under consideration of different viable \(f ({\mathcal {G}})\) models obey the constraint:

$$\begin{aligned} 0< |v_{st}^2-v_{sr}^2|<1 \end{aligned}$$

We concluded that the stability is attained in \(f({\mathcal {G}})\) gravity models for three considered strange candidate stars, Vela X-1, SAX J 1808.43658, and 4U 1820-30.

4.5 EoS parameter

Now for anisotropic stresses, there are two equation of state parameters, written as

$$\begin{aligned} w_r= \frac{p_r}{\rho } \end{aligned}$$

and

$$\begin{aligned} w_t =\frac{p_t}{\rho } \end{aligned}$$

For a radiation dominant era, equation of state parameters must lie between 0 and 1. More precisely, \(0<w_r<1\) and \(0<w_t<1\). Here, we check the evolution of EoS parameters for three different charged stars and their behavior are shown graphically in Figs. 13 and 14.

We can see that both \(w_r\) and \(w_t\) lies in given range.

Fig. 14
figure 14

Variations of the transverse EoS parameter for different viable \(f({\mathcal {G}})\) gravity models

4.6 Mass radius relationship, compactness and redshift analysis

The mass of charged compact stars can be written as

$$\begin{aligned} m(r) = \int \limits _0^r {4\pi {{r'}^2}\rho dr'} \end{aligned}$$
(25)

Here we know that mass m is function of r and \(m(r=0)=0\) while \(m(r=R)=M\). The variation in masses of charged compact stars are shown in Fig. 15.

Fig. 15
figure 15

Variations of the mass function for different charged compact stars

Fig. 16
figure 16

Variations of the compactness for different charged compact stars

Fig. 17
figure 17

Variations of the Redshift for different charged compact stars

We see that the mass is regular at core because it is directly proportional to radial distance e.g. \(m(r)\rightarrow 0\) for \(r\rightarrow 0\). The maximum mass is attained at \(r=R\), as shown in fig. 15. The mass radius relation is also compatible with the study of neutron stars under f(G) gravity [49].

Furthermore, the compactness, \(\mu \) can be define as

$$\begin{aligned} \mu (r) = \frac{1}{r}\int \limits _0^r {4\pi {{r'}^2}\rho dr'} \end{aligned}$$
(26)

The compactness for three different strange stars are shown in Fig. 16. similarly, the Redshift, \(Z_s\) can be define for compact object

$$\begin{aligned} Z_s = {\left( {1 - 2\mu } \right) ^{ - \frac{1}{2}}} - 1 \end{aligned}$$

The bound over \(Z_s\le 2\). In our case, wee check the variation in redshift from the core to surface of stars. These evolution are shown with the help of plots, as given in Fig. 17.

4.7 The measurement of anisotropy

In modeling of relativistic stellar interior structures, it is important to discuss the anisotropicity or anisotropy which is defined as

$$\begin{aligned} \Delta = \frac{2}{r}({p_t} - {p_r}) \end{aligned}$$
(27)

We check the anisotropy for three different charged strange stars under consideration of three viable models in \(f({\mathcal {G}})\) gravity. After plugging the constant values with these models, we plot the anisotropy and get that \(\Delta > 0\) e.g. \(p_t > p_r\). This implies that the anisotropy is directed outward for all three stars. These plots are shown in Fig. 18. It is important to note that \(\Delta \rightarrow 0\) at \(r \rightarrow 0\) and becomes monotonically increasing outwards with the increase of r near the surface of the star.

Fig. 18
figure 18

Variations of anisotropic measure \(\Delta \) with respect to the radial

4.8 Electric field and charge

We observed that the electric charge on the boundary for star 1 is \(6.459234\times 10^{20}C\), for star 2 \(6.7510838\times 10^{20}C\) and for star 3 \(6.7460087\times 10^{20}C\) and zero at the core of these stars under consideration of model 1. The charge profile is monotonically increasing away from the center, as shown in Fig. 19.

Fig. 19
figure 19

Variations of electric charge Q with respect to the radial

Furthermore, the electric charge density is monotonically decreasing outward and is maximum at the center of these stars as shown in Fig. 20.

Fig. 20
figure 20

Variations of surface charge density \(\sigma \) with respect to the radial

Similarly, the behavior of electric field intensity \(E^2\) is also discuss and their variation for different stars are shown in Fig. 21.

Fig. 21
figure 21

Variations of electric field square \(E^2\) with respect to the radial

From these plots, we conclude that the core of these stars contain \(Q(r=0)=0\), \(\sigma (r=0)=\sigma _0\) and \(E^2(r=0)=0\) while at surface of these stars \(Q(r=R)=Q_m\) \(\sigma (r=R)=0\) and \(E^2(r=R)=E^2_m\) where \(\sigma _0\), \(Q_m\) and \(E^2_m\) is the maximum charge density, charge and electric field intensity.

The stellar structure formation in the background of modified gravity are comparatively higher contraction in the collapsing rate of spherical systems at its initial stages unlike GR. The extra curvature (non-gravitational fluid) on the existence of compact structure could lead arena of having relatively more compact stars than in GR.

Similarly, the influences of these additional dark source terms on mass radius relationships for compact stars predict more massive relativistic systems with comparatively smaller radii than in GR. Perhaps, the calculated apparent masses of neutron star models in modified gravity are more massive star with smaller radii than in GR. Such type of investigations could provide theoretical well-consistent way to handle and study classes of massive and super massive structures at large scales.

5 Summary

It has been attracting challenge to find the correct model for charged realistic geometry of interior compact objects not only in general relativity but also in extended theories of gravity like \(f({\mathcal {G}})\) gravity. For this purpose, we have considered the three-different observed compact stars, labeled as Vela X-1, SAX J 1808.4-3658, and 4U 1820-30. Our desire is to study the real composition of these compact objects in their central regions under consideration of three different viable models.

We have investigated several aspects of compact stars in the regime of \(f({\mathcal {G}})\) gravity with the anisotropic matter content under Einstein Maxwell spacetime. We have utilized the solutions for the metric function suggested by Krori–Barua for a spherical compact object whose arbitrary constants are calculated across the boundary of interior and exterior geometry. The values of these arbitrary constants are determined with the help of charge, mass, and radius of any compact object. We have used three different strange candidate stars with their experimental observational data to study the effects of additional degree of freedom coming from modified gravity theories. For this purpose, we used three different viable models in \(f({\mathcal {G}})\) gravity. By using these models along with calculated values for three different stars, we have plotted the relevant quantities like variation of anisotropic stress and energy density against radial distance. It is found that the energy density is very high at core of these stars and gradually decreases with the increasing radius, thereby indicating the high compactness structures of these stellar interiors.

We concluded our discussion as:

  • The variation in energy density and both radial as well as transverse stress are positive throughout these charged stars configurations.

  • The radial derivative of density and anisotropic pressures (\(d\rho /dr\), \(dP_r/dr\), \(dP_t/dr\)) remains negative and for \(r=0\), these values vanish which confirm the density and anisotropic stress maximum value at core.

  • All the energy conditions are well satisfied which show the realistic matter content.

  • Both the radial and transverse sound speed remains within the bounds, which mean the causality condition is obeyed.

  • All these stars are stable.

  • Both radial and transverse EoS parameters lie in the range of 0 and 1.

  • The isotropy remains positive throughout these charged stars.

  • The distribution of charges increase from central to surface of stars.

  • Electric field intensity is maximum at the surface of these stars.

We see that \(f({\mathcal {G}})\) gravity is much attractive in the study of compact stars. In this sense, to our knowledge, the existence and study of different charged stars and particle physics inside their highly dense cores compelled the researchers for more genuine solutions of field equations. Similarly, the study of compact charged stellar configuration and better observational data on the mass radius relation have the potential to exclude a larger region of the parameter space of alternative theories. There is of course the possibility that theoretical and observational work may give us a direction on how to modify general relativity to make it compatible with the standard model of particle physics, which would be even more exciting.