@@ -39,6 +39,22 @@ namespace functionObjects
3939}
4040}
4141
42+ //- Add an element to the back of a list and shift all elements left.
43+ // Removes first element. This allows to only keep the information needed.
44+ template < class Type >
45+ void add_to_list_like_static_queue (List < Type > & list , const Type & value )
46+ {
47+ for (label i = 0 ; i < list .size () - 1 ; i ++ )
48+ {
49+ //- Movel all elements
50+ list [i ] = list [i + 1 ];
51+ }
52+
53+ //- emplace last element
54+ list [list .size ()- 1 ] = value ;
55+
56+ }
57+
4258
4359// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
4460
@@ -54,11 +70,11 @@ Foam::functionObjects::disengagement::disengagement
5470 phases_ (mesh_ .lookupObject < phaseSystem > ("phaseProperties" ).phases ()),
5571 phaseName_ (dict .lookup < word > ("phase" )),
5672 inletPatch_ (dict .lookup < word > ("inlet" )),
57- holdup_ (),
5873 tolerance_ (dict .lookup < scalar > ("tolerance" )),
5974 nsamples_ (dict .lookup < label > ("nsamples" )),
60- disengaged_ (false),
61- writtenAt_ (0 )
75+ disengage_ (dict .lookup ("disengage" )),
76+ holdup_ (2 * nsamples_ ,{0. ,-1. }),
77+ disengaged_ (false)
6278{
6379 //- Check that U has fixedValue
6480 volVectorField & U = const_cast < volVectorField & > (mesh_ .lookupObject < volVectorField > ("U." + phaseName_ ));
@@ -93,6 +109,7 @@ void Foam::functionObjects::disengagement::writeFileHeader(const label i)
93109 writeHeader (file (), "holdup" );
94110 writeCommented (file (), "time" );
95111 writeTabbed (file (), "holdup" );
112+ writeTabbed (file (), "disengaged" );
96113
97114 file () << endl ;
98115 }
@@ -107,31 +124,34 @@ bool Foam::functionObjects::disengagement::execute()
107124 scalar holdup = gSum (fvc ::volumeIntegrate (alpha ))/volume ;
108125 Pair < scalar > holddata (mesh_ .time ().value (), holdup );
109126
110- holdup_ .append (holddata );
127+ //- See function at the beginning of file
128+ add_to_list_like_static_queue (holdup_ ,holddata );
129+
130+ //- Skip rest if no disengagement is required
131+ if (!disengage_ ) return true;
111132
112133 //- Stop if already disengaged
113- if (disengaged_ ) return true;
134+ if (disengaged_ ) return true;
114135
115- //- Check if the average over the last samples
116- if (holdup_ . size () > 2 * nsamples_ + 1 )
136+ //- Do the check only if the list is complete
137+ if (holdup_ [ 0 ]. second () > 0. )
117138 {
118139 scalar holdup_mean_long (0. );
119140 scalar holdup_mean_short (0. );
120- scalar t0_long (holdup_ [holdup_ . size () - 2 * nsamples_ ].first ());
141+ scalar t0_long (holdup_ [0 ].first ());
121142 scalar deltat_long (0. );
122143 scalar deltat_short (0. );
123144
124- t0_long = holdup_ [holdup_ .size () - 2 * nsamples_ - 1 ].first ();
125-
126-
127- for (int i = holdup_ .size () - 2 * nsamples_ ; i < holdup_ .size (); i ++ )
145+ //- The first (oldest) sample is skipped to have a well-defined dt
146+ for (int i = 1 ; i < 2 * nsamples_ ; i ++ )
128147 {
129148 scalar dt = holdup_ [i ].first () - t0_long ;
130149 t0_long = holdup_ [i ].first ();
131150 holdup_mean_long += dt * holdup_ [i ].second ();
132151 deltat_long += dt ;
133152
134- if (i >= holdup_ .size () - nsamples_ )
153+ //- Compute average on the most recent samples
154+ if (i >= nsamples_ )
135155 {
136156 holdup_mean_short += dt * holdup_ [i ].second ();
137157 deltat_short += dt ;
@@ -174,21 +194,20 @@ bool Foam::functionObjects::disengagement::write()
174194 Info << logFiles ::names ();
175195 logFiles ::write ();
176196
197+ label dis = 0 ;
198+ if (disengaged_ ) dis = 1 ;
199+
177200 if (Pstream ::master ())
178201 {
179- for ( label i = writtenAt_ ; i < holdup_ . size (); i ++ )
180- {
181- file () << holdup_ [i ]. first ();
202+ file () << holdup_ [ 2 * nsamples_ - 1 ]. first ();
203+ file () << tab ;
204+ file () << holdup_ [2 * nsamples_ - 1 ]. second ();
182205 file () << tab ;
183- file () << holdup_ [ i ]. second () ;
206+ file () << dis ;
184207 file () << endl ;
185- }
186-
187-
208+
188209 }
189210
190- writtenAt_ = holdup_ .size () - 1 ;
191-
192211 return true;
193212}
194213
0 commit comments