Skip to content

Commit 3aba6cd

Browse files
committed
fix(HorizonsStack): Added functions to loop on horizons/units from top to bottom.
1 parent 769b554 commit 3aba6cd

3 files changed

Lines changed: 116 additions & 24 deletions

File tree

include/geode/geosciences/implicit/representation/core/horizons_stack.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ namespace geode
6060
class opengeode_geosciences_implicit_api HorizonOrderedRange
6161
{
6262
public:
63-
HorizonOrderedRange( const HorizonsStack& horizons_stack );
63+
HorizonOrderedRange(
64+
const HorizonsStack& horizons_stack, bool bottom_to_top );
6465
HorizonOrderedRange( HorizonOrderedRange&& other ) noexcept;
6566
HorizonOrderedRange( const HorizonOrderedRange& other );
6667
~HorizonOrderedRange();
@@ -90,7 +91,7 @@ namespace geode
9091
{
9192
public:
9293
StratigraphicUnitOrderedRange(
93-
const HorizonsStack& horizons_stack );
94+
const HorizonsStack& horizons_stack, bool bottom_to_top );
9495
StratigraphicUnitOrderedRange(
9596
StratigraphicUnitOrderedRange&& other ) noexcept;
9697
StratigraphicUnitOrderedRange(
@@ -152,6 +153,10 @@ namespace geode
152153

153154
[[nodiscard]] StratigraphicUnitOrderedRange bottom_to_top_units() const;
154155

156+
[[nodiscard]] HorizonOrderedRange top_to_bottom_horizons() const;
157+
158+
[[nodiscard]] StratigraphicUnitOrderedRange top_to_bottom_units() const;
159+
155160
[[nodiscard]] bool is_eroded_by(
156161
const StratigraphicUnit< dimension >& eroded,
157162
const Horizon< dimension >& erosion ) const;

src/geode/geosciences/implicit/representation/core/horizons_stack.cpp

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace geode
118118
"on HorizonsStack will be empty: top and bottom "
119119
"horizons have not been computed, or stack is empty." );
120120
}
121-
return { *this };
121+
return { *this, true };
122122
}
123123

124124
template < index_t dimension >
@@ -128,11 +128,39 @@ namespace geode
128128
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
129129
{
130130
Logger::warn(
131-
"[HorizonsStack::bottom_to_top_horizons] Iteration "
131+
"[HorizonsStack::bottom_to_top_units] Iteration "
132+
"on HorizonsStack will be empty: top and bottom "
133+
"horizons have not been computed, or stack is empty" );
134+
}
135+
return { *this, true };
136+
}
137+
138+
template < index_t dimension >
139+
auto HorizonsStack< dimension >::top_to_bottom_horizons() const
140+
-> HorizonOrderedRange
141+
{
142+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
143+
{
144+
Logger::warn(
145+
"[HorizonsStack::top_to_bottom_horizons] Iteration "
146+
"on HorizonsStack will be empty: top and bottom "
147+
"horizons have not been computed, or stack is empty." );
148+
}
149+
return { *this, false };
150+
}
151+
152+
template < index_t dimension >
153+
auto HorizonsStack< dimension >::top_to_bottom_units() const
154+
-> StratigraphicUnitOrderedRange
155+
{
156+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
157+
{
158+
Logger::warn(
159+
"[HorizonsStack::top_to_bottom_units] Iteration "
132160
"on HorizonsStack will be empty: top and bottom "
133161
"horizons have not been computed, or stack is empty" );
134162
}
135-
return { *this };
163+
return { *this, false };
136164
}
137165

138166
template < index_t dimension >
@@ -206,12 +234,15 @@ namespace geode
206234
class HorizonsStack< dimension >::HorizonOrderedRange::Impl
207235
{
208236
public:
209-
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
237+
Impl( const HorizonsStack< dimension >& stack, bool bottom_to_top )
238+
: stack_( stack ), bottom_to_top_( bottom_to_top )
210239
{
211240
auto bot_horizon = stack.bottom_horizon();
212-
if( bot_horizon && stack.top_horizon() )
241+
auto top_horizon = stack.top_horizon();
242+
if( bot_horizon && top_horizon )
213243
{
214-
iter_ = bot_horizon.value();
244+
iter_ =
245+
bottom_to_top_ ? bot_horizon.value() : top_horizon.value();
215246
}
216247
}
217248

@@ -222,10 +253,23 @@ namespace geode
222253

223254
void operator++()
224255
{
225-
if( iter_ != stack_.top_horizon().value() )
256+
if( bottom_to_top_ )
257+
{
258+
if( iter_ != stack_.top_horizon().value() )
259+
{
260+
iter_ =
261+
stack_.above( stack_.above( iter_ ).value() ).value();
262+
return;
263+
}
264+
}
265+
else
226266
{
227-
iter_ = stack_.above( stack_.above( iter_ ).value() ).value();
228-
return;
267+
if( iter_ != stack_.bottom_horizon().value() )
268+
{
269+
iter_ =
270+
stack_.under( stack_.under( iter_ ).value() ).value();
271+
return;
272+
}
229273
}
230274
iter_ = uuid{};
231275
}
@@ -237,13 +281,14 @@ namespace geode
237281

238282
private:
239283
const HorizonsStack< dimension >& stack_;
284+
bool bottom_to_top_;
240285
uuid iter_{};
241286
};
242287

243288
template < index_t dimension >
244289
HorizonsStack< dimension >::HorizonOrderedRange::HorizonOrderedRange(
245-
const HorizonsStack& horizons_stack )
246-
: impl_( horizons_stack )
290+
const HorizonsStack& horizons_stack, bool bottom_to_top )
291+
: impl_( horizons_stack, bottom_to_top )
247292
{
248293
}
249294

@@ -286,12 +331,16 @@ namespace geode
286331
class HorizonsStack< dimension >::StratigraphicUnitOrderedRange::Impl
287332
{
288333
public:
289-
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
334+
Impl( const HorizonsStack< dimension >& stack, bool bottom_to_top )
335+
: stack_( stack ), bottom_to_top_( bottom_to_top )
290336
{
291337
auto bot_horizon = stack.bottom_horizon();
292-
if( bot_horizon && stack.top_horizon() )
338+
auto top_horizon = stack.top_horizon();
339+
if( bot_horizon && top_horizon )
293340
{
294-
iter_ = stack.under( bot_horizon.value() ).value();
341+
iter_ = bottom_to_top_
342+
? stack.under( bot_horizon.value() ).value()
343+
: stack.above( top_horizon.value() ).value();
295344
}
296345
}
297346

@@ -302,10 +351,25 @@ namespace geode
302351

303352
void operator++()
304353
{
305-
if( iter_ != stack_.above( stack_.top_horizon().value() ).value() )
354+
if( bottom_to_top_ )
306355
{
307-
iter_ = stack_.above( stack_.above( iter_ ).value() ).value();
308-
return;
356+
if( iter_
357+
!= stack_.above( stack_.top_horizon().value() ).value() )
358+
{
359+
iter_ =
360+
stack_.above( stack_.above( iter_ ).value() ).value();
361+
return;
362+
}
363+
}
364+
else
365+
{
366+
if( iter_
367+
!= stack_.under( stack_.bottom_horizon().value() ).value() )
368+
{
369+
iter_ =
370+
stack_.under( stack_.under( iter_ ).value() ).value();
371+
return;
372+
}
309373
}
310374
iter_ = uuid{};
311375
}
@@ -317,13 +381,15 @@ namespace geode
317381

318382
private:
319383
const HorizonsStack< dimension >& stack_;
384+
bool bottom_to_top_;
320385
uuid iter_{};
321386
};
322387

323388
template < index_t dimension >
324389
HorizonsStack< dimension >::StratigraphicUnitOrderedRange::
325-
StratigraphicUnitOrderedRange( const HorizonsStack& horizons_stack )
326-
: impl_( horizons_stack )
390+
StratigraphicUnitOrderedRange(
391+
const HorizonsStack& horizons_stack, bool bottom_to_top )
392+
: impl_( horizons_stack, bottom_to_top )
327393
{
328394
}
329395

tests/implicit/test-horizons-stack.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,17 @@ void test_create_horizons_stack()
151151
" as horizon number ", counter, ", not ", horizon.name() );
152152
counter++;
153153
}
154-
OPENGEODE_EXCEPTION(
155-
counter == 4, "[Test] Range did not pass through all horizons" );
156-
counter = 0;
154+
OPENGEODE_EXCEPTION( counter == 4,
155+
"[Test] Bottom to top Range did not pass through all horizons" );
156+
for( const auto& horizon : horizons_stack.top_to_bottom_horizons() )
157+
{
158+
counter--;
159+
OPENGEODE_EXCEPTION( horizon.name() == horizons_list[counter],
160+
"[Test] Should have found horizon ", horizons_list[counter],
161+
" as horizon number ", counter, ", not ", horizon.name() );
162+
}
163+
OPENGEODE_EXCEPTION( counter == 0,
164+
"[Test] Top to bottom Range did not pass through all horizons" );
157165
for( const auto& s_unit : horizons_stack.bottom_to_top_units() )
158166
{
159167
if( counter != 0 && counter < 4 )
@@ -167,6 +175,19 @@ void test_create_horizons_stack()
167175
}
168176
OPENGEODE_EXCEPTION( counter == 5,
169177
"[Test] Range did not pass through all stratigraphic units" );
178+
for( const auto& s_unit : horizons_stack.top_to_bottom_units() )
179+
{
180+
counter--;
181+
if( counter != 0 && counter < 4 )
182+
{
183+
OPENGEODE_EXCEPTION( s_unit.name() == units_list[counter - 1],
184+
"[Test] Should have found stratigraphic unit ",
185+
units_list[counter - 1], " as unit number ", counter, ", not ",
186+
s_unit.name() );
187+
}
188+
}
189+
OPENGEODE_EXCEPTION( counter == 0, "[Test] Top to bottom Range did not "
190+
"pass through all stratigraphic units" );
170191
}
171192

172193
int main()

0 commit comments

Comments
 (0)