@@ -51,18 +51,17 @@ class FDMGradient : public FEMFunctionBase<GradType>
5151
5252 auto & val = *_val_func;
5353
54+ Real one_over_dim = Real (0.5 ) / _eps;
55+
5456 g (0 ) = (val (c, p+Point (_eps), time) -
55- val (c, p+Point (-_eps), time)) /
56- 2 / _eps;
57+ val (c, p+Point (-_eps), time)) * one_over_dim;
5758#if LIBMESH_DIM > 1
5859 g (1 ) = (val (c, p+Point (0 ,_eps), time) -
59- val (c, p+Point (0 ,-_eps), time)) /
60- 2 / _eps;
60+ val (c, p+Point (0 ,-_eps), time)) * one_over_dim;
6161#endif
6262#if LIBMESH_DIM > 2
6363 g (2 ) = (val (c, p+Point (0 ,0 ,_eps), time) -
64- val (c, p+Point (0 ,0 ,-_eps), time)) /
65- 2 / _eps;
64+ val (c, p+Point (0 ,0 ,-_eps), time)) * one_over_dim;
6665#endif
6766
6867 return g;
@@ -125,18 +124,17 @@ class FDMGradient : public FEMFunctionBase<GradType>
125124
126125 auto & val = *_val_func;
127126
127+ Real one_over_dim = Real (0.5 ) / _eps;
128+
128129 g (0 ) = (val.component (c, i, p+Point (_eps), time) -
129- val.component (c, i, p+Point (-_eps), time)) /
130- 2 / _eps;
130+ val.component (c, i, p+Point (-_eps), time)) * one_over_dim;
131131#if LIBMESH_DIM > 1
132132 g (1 ) = (val.component (c, i, p+Point (0 ,_eps), time) -
133- val.component (c, i, p+Point (0 ,-_eps), time)) /
134- 2 / _eps;
133+ val.component (c, i, p+Point (0 ,-_eps), time)) * one_over_dim;
135134#endif
136135#if LIBMESH_DIM > 2
137136 g (2 ) = (val.component (c, i, p+Point (0 ,0 ,_eps), time) -
138- val.component (c, i, p+Point (0 ,0 ,-_eps), time)) /
139- 2 / _eps;
137+ val.component (c, i, p+Point (0 ,0 ,-_eps), time)) * one_over_dim;
140138#endif
141139
142140 return g;
0 commit comments