@@ -101,22 +101,23 @@ end subroutine adaptiveTimeStep_Destruct
101101! -----------------------------------------------
102102 subroutine adaptiveTimeStep_Update (this , mesh , t , dt )
103103 implicit none
104- class(adaptiveTimeStep_t) , intent (inout ) :: this
105- class(HexMesh) , intent (in ) :: mesh
106- real (kind= RP) , intent (in ) :: t
107- real (kind= RP) , intent (inout ) :: dt
104+ class(adaptiveTimeStep_t) , intent (inout ) :: this
105+ class(HexMesh) , intent (inout ) :: mesh
106+ real (kind= RP) , intent (in ) :: t
107+ real (kind= RP) , intent (inout ) :: dt
108108! ! ---------------
109109! Local variables
110110! ! ---------------
111111 integer :: eID, ierr, i
112- real (kind= RP) :: dt_weight, sum_dt_weight, dt_lim, min_dt_lim, max_dt_lim
112+ real (kind= RP) :: dt_weight, sum_dt_weight, avg_sum_dt_weight, dt_lim, min_dt_lim, max_dt_lim
113113
114114 min_dt_lim = 0.5_RP ! Minimum limit for the time step
115115 max_dt_lim = 1.3_RP ! Maximum limit for the time step
116116
117117 this % lastAdaptationTime = t
118118 dt_weight = 0.0_RP
119119 sum_dt_weight = 0.0_RP
120+ avg_sum_dt_weight = 0.0_RP
120121! $omp parallel shared(dt_weight, mesh, this)
121122! $omp do reduction(+:dt_weight) schedule(runtime)
122123 do eID = 1 , mesh % no_of_elements
@@ -133,10 +134,18 @@ subroutine adaptiveTimeStep_Update(this, mesh, t, dt)
133134 sum_dt_weight = dt_weight
134135 end if
135136
137+ avg_sum_dt_weight = sum_dt_weight / mesh % no_of_allElements
138+
139+ ! $omp parallel do schedule(runtime)
140+ do eID = 1 , mesh % no_of_elements
141+ mesh % elements(eID) % ML_error_ratio = mesh % elements(eID) % ML_error_ratio / avg_sum_dt_weight
142+ end do
143+ ! $omp end parallel do
144+
136145 if (isnan(sum_dt_weight)) then
137146 this % dt_eps(3 ) = 1e-10_RP
138147 else
139- this % dt_eps(3 ) = 1.0_RP / max (sqrt (sum_dt_weight / mesh % no_of_allElements ), 1e-10_RP )
148+ this % dt_eps(3 ) = 1.0_RP / max (sqrt (avg_sum_dt_weight ), 1e-10_RP )
140149 end if
141150
142151 if ((this % dt_eps(1 ) == this % dt_eps(2 )) .and. (this % dt_eps(2 ) == 1.0_RP )) then
@@ -208,9 +217,9 @@ end subroutine AdaptiveTimeStep_Update
208217
209218 function adaptiveTimeStep_ComputeWeights (this , e ) result(dt_weight)
210219 implicit none
211- class(adaptiveTimeStep_t), intent (in ) :: this
212- type (Element) , intent (in ) :: e
213- real (kind= RP) :: dt_weight
220+ class(adaptiveTimeStep_t), intent (in ) :: this
221+ type (Element) , intent (inout ) :: e
222+ real (kind= RP) :: dt_weight
214223! ! ---------------
215224 integer :: i, j, k, dir, Ndir
216225 integer :: Pxyz(3 )
@@ -220,7 +229,7 @@ function adaptiveTimeStep_ComputeWeights(this, e) result(dt_weight)
220229! Initialization of P
221230 Pxyz = e % Nxyz
222231
223- Ndir = 7 ! Number of available error variables
232+ Ndir = 3
224233
225234 dt_weight = 0.0_RP
226235
@@ -247,6 +256,10 @@ function adaptiveTimeStep_ComputeWeights(this, e) result(dt_weight)
247256 Q_error(k, j, i) = e % storage % QNS(IMP,k,j,i)
248257 QLowRK_error(k, j, i) = e % storage % QLowRK(IMP,k,j,i)
249258#endif
259+ else if (this % error_variable == 8 ) then
260+ ! Density
261+ Q_error(k, j, i) = e % storage % Q(1 ,k,j,i)
262+ QLowRK_error(k, j, i) = e % storage % QLowRK(1 ,k,j,i)
250263 end if
251264 end if
252265 end do
@@ -257,6 +270,9 @@ function adaptiveTimeStep_ComputeWeights(this, e) result(dt_weight)
257270
258271 dt_weight = dt_weight / (e % storage % sensor)** 2.0_RP
259272 dt_weight = dt_weight / ((Pxyz(1 )+ 1 ) * (Pxyz(2 )+ 1 ) * (Pxyz(3 )+ 1 )) ! Average over all Gauss points
273+ ! MLRK correction
274+ dt_weight = dt_weight / (3.0_RP ** (e % MLevel - 1 ))** 2.0_RP
275+ e % ML_error_ratio = dt_weight
260276#endif
261277 end function adaptiveTimeStep_ComputeWeights
262278
0 commit comments