cfsem 11.1.0

Quasi-steady electromagnetics including filamentized approximations, Biot-Savart, and Grad-Shafranov.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
use super::{
    BoundedGeometry, ClusterTreeView, HierarchicalError, HierarchicalKernel, Scalar,
    SourceCollection, SourceMomentCollection, TargetCollection,
};
use std::sync::atomic::{AtomicU32, Ordering};

/// CPU-owned source summary storage.
pub struct SourceNodeSummaries<K: HierarchicalKernel> {
    pub node_summaries: Vec<K::SourceSummary>,
}

impl<K: HierarchicalKernel> SourceNodeSummaries<K> {
    #[inline]
    /// Construct the default kernel value.
    pub fn new(tree: ClusterTreeView<'_, K::Scalar>) -> Self {
        Self {
            node_summaries: vec![K::SourceSummary::default(); tree.n_nodes()],
        }
    }
}

/// Scratch storage for exact and far contribution evaluation.
pub struct EvaluationScratch<'a, Output> {
    pub contribution: &'a mut [Output],
}

/// Number of contribution scratch entries required by source-tree-only evaluation.
#[inline]
pub fn scratch_len() -> usize {
    1
}

/// Number of contribution scratch entries required by parallel source-tree evaluation.
#[inline]
pub fn scratch_len_par(target_count: usize) -> usize {
    let chunk_size = crate::chunksize(target_count);
    target_count.div_ceil(chunk_size).max(1)
}

/// Update source summaries for a fixed source tree and changed source moments.
#[inline]
pub fn update_summaries<K, S, M>(
    kernel: &K,
    tree: ClusterTreeView<'_, K::Scalar>,
    sources: S,
    moments: M,
    summaries: &mut [K::SourceSummary],
) -> HierarchicalError
where
    K: HierarchicalKernel,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
{
    let err = validate_source_tree_layout(tree);
    if err != HierarchicalError::Ok {
        return err;
    }
    if sources.len() != tree.n_items()
        || !sources.valid_lengths()
        || moments.len() != tree.n_items()
        || !moments.valid_lengths()
    {
        return HierarchicalError::LengthMismatch;
    }
    if summaries.len() < tree.n_nodes() {
        return HierarchicalError::ScratchTooSmall;
    }

    for i in 0..tree.leaf_node_ids.len() {
        let node_id = tree.leaf_node_ids[i];
        let start = tree.leaf_start[node_id as usize] as usize;
        let count = tree.leaf_count[node_id as usize] as usize;
        let end = start + count;
        let source_ids = &tree.sorted_indices[start..end];
        let err = kernel.summarize_leaf_sources(
            source_ids,
            sources,
            moments,
            &mut summaries[node_id as usize],
        );
        if err != HierarchicalError::Ok {
            return err;
        }
    }

    propagate_source_summaries(kernel, tree, summaries)
}

/// Evaluate vector-valued targets independently against the source tree.
///
/// This is the public hierarchical evaluation path. Each target is summarized
/// as a single target leaf, walked against the source tree, and written directly
/// into caller-provided component slices. The output slice count must match the
/// kernel output dimension `D`.
#[inline]
pub fn eval<K, T, S, M, C, const D: usize>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, T>,
    source_summaries: &[K::SourceSummary],
    sources: S,
    targets: C,
    moments: M,
    theta: T,
    out: [&mut [T]; D],
    scratch: &mut EvaluationScratch<'_, [T; D]>,
) -> HierarchicalError
where
    K: HierarchicalKernel<Scalar = T, Output = [T; D]>,
    T: Scalar,
    K::TargetGeometry: Copy,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
    C: TargetCollection<K>,
{
    let err = validate_source_tree_layout(source_tree);
    if err != HierarchicalError::Ok {
        return err;
    }
    eval_validated(
        kernel,
        source_tree,
        source_summaries,
        sources,
        targets,
        moments,
        theta,
        out,
        scratch,
    )
}

#[inline]
/// Evaluate validated source-target rows with the hierarchical tree walk.
fn eval_validated<K, T, S, M, C, const D: usize>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, T>,
    source_summaries: &[K::SourceSummary],
    sources: S,
    targets: C,
    moments: M,
    theta: T,
    out: [&mut [T]; D],
    scratch: &mut EvaluationScratch<'_, [T; D]>,
) -> HierarchicalError
where
    K: HierarchicalKernel<Scalar = T, Output = [T; D]>,
    T: Scalar,
    K::TargetGeometry: Copy,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
    C: TargetCollection<K>,
{
    if D == 0
        || sources.len() != source_tree.n_items()
        || !sources.valid_lengths()
        || moments.len() != source_tree.n_items()
        || !moments.valid_lengths()
        || !targets.valid_lengths()
    {
        return HierarchicalError::LengthMismatch;
    }
    for component in 0..D {
        if out[component].len() != targets.len() {
            return HierarchicalError::LengthMismatch;
        }
    }
    if source_summaries.len() < source_tree.n_nodes() || scratch.contribution.is_empty() {
        return HierarchicalError::ScratchTooSmall;
    }

    let mut target_summary = K::TargetSummary::default();
    let mut active = Vec::new();
    let target_ids = [0_u32];
    let mut target_out = [T::ZERO; D];

    for target_id in 0..targets.len() {
        let target = targets.target(target_id);
        let err = eval_scalar(
            kernel,
            source_tree,
            source_summaries,
            sources,
            target,
            moments,
            theta,
            &mut target_out,
            &mut scratch.contribution[0],
            &mut target_summary,
            &mut active,
            &target_ids,
        );
        if err != HierarchicalError::Ok {
            return err;
        }
        for component in 0..D {
            out[component][target_id] = target_out[component];
        }
    }

    HierarchicalError::Ok
}

/// Evaluate one scalar target against the source tree.
///
/// Serial and parallel vector evaluators both call this helper so the source
/// traversal and acceptance behavior cannot diverge between evaluation modes.
#[inline]
fn eval_scalar<K, S, M>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, K::Scalar>,
    source_summaries: &[K::SourceSummary],
    sources: S,
    target: K::TargetGeometry,
    moments: M,
    theta: K::Scalar,
    out: &mut K::Output,
    contribution: &mut K::Output,
    target_summary: &mut K::TargetSummary,
    active: &mut Vec<u32>,
    target_ids: &[u32],
) -> HierarchicalError
where
    K: HierarchicalKernel,
    K::TargetGeometry: Copy,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
{
    kernel.zero_output(out);
    let err =
        kernel.summarize_leaf_targets(target_ids, core::slice::from_ref(&target), target_summary);
    if err != HierarchicalError::Ok {
        return err;
    }

    active.clear();
    active.push(0_u32);
    while let Some(source_node) = active.pop() {
        let source_node_index = source_node as usize;
        let source_summary = &source_summaries[source_node_index];
        let source_aabb = source_tree.node_aabb[source_node_index];
        if kernel.accept_far(target.aabb(), source_aabb, source_summary, theta) {
            kernel.eval_far(target_summary, source_summary, contribution);
            kernel.accumulate(out, contribution);
            continue;
        }

        let leaf_count = source_tree.leaf_count[source_node_index];
        if leaf_count > 0 {
            let start = source_tree.leaf_start[source_node_index] as usize;
            let count = leaf_count as usize;
            let end = start + count;
            let source_ids = &source_tree.sorted_indices[start..end];
            for i in 0..source_ids.len() {
                let source_id = source_ids[i] as usize;
                let source = sources.source(source_id);
                let moment = moments.moment(source_id);
                kernel.eval_near(&target, &source, &moment, contribution);
                kernel.accumulate(out, contribution);
            }
        } else {
            active.push(source_tree.node_left_child[source_node_index]);
            active.push(source_tree.node_right_child[source_node_index]);
        }
    }

    HierarchicalError::Ok
}

/// Evaluate vector-valued targets against the source tree in parallel over target chunks.
///
/// This is intentionally the simplest parallelization of the single-tree
/// solver: each worker owns disjoint target and component output slices and
/// runs the serial source-tree evaluator on that slice. It shares the source
/// tree and source summaries between workers, and avoids any cross-thread
/// output accumulation.
#[inline]
pub fn eval_par<K, T, S, M, C, const D: usize>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, T>,
    source_summaries: &[K::SourceSummary],
    sources: S,
    targets: C,
    moments: M,
    theta: T,
    out: [&mut [T]; D],
    scratch: &mut EvaluationScratch<'_, [T; D]>,
) -> HierarchicalError
where
    K: HierarchicalKernel<Scalar = T, Output = [T; D]> + Sync,
    T: Scalar,
    K::TargetGeometry: Copy,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
    C: TargetCollection<K>,
{
    let err = validate_source_tree_layout(source_tree);
    if err != HierarchicalError::Ok {
        return err;
    }
    if D == 0
        || sources.len() != source_tree.n_items()
        || !sources.valid_lengths()
        || moments.len() != source_tree.n_items()
        || !moments.valid_lengths()
        || !targets.valid_lengths()
    {
        return HierarchicalError::LengthMismatch;
    }
    for component in 0..D {
        if out[component].len() != targets.len() {
            return HierarchicalError::LengthMismatch;
        }
    }
    if source_summaries.len() < source_tree.n_nodes() {
        return HierarchicalError::ScratchTooSmall;
    }
    if targets.is_empty() {
        return HierarchicalError::Ok;
    }

    let chunk_size = crate::chunksize(targets.len());
    let chunk_count = targets.len().div_ceil(chunk_size);
    if scratch.contribution.len() < chunk_count {
        return HierarchicalError::ScratchTooSmall;
    }

    let error_code = AtomicU32::new(HierarchicalError::Ok as u32);
    eval_par_chunks(
        kernel,
        source_tree,
        source_summaries,
        sources,
        targets,
        moments,
        theta,
        out,
        &mut scratch.contribution[..chunk_count],
        chunk_size,
        &error_code,
    );

    HierarchicalError::from_u32(error_code.load(Ordering::Relaxed))
}

#[inline]
/// Evaluate validated output chunks in parallel and preserve the first error code.
fn eval_par_chunks<K, T, S, M, C, const D: usize>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, T>,
    source_summaries: &[K::SourceSummary],
    sources: S,
    targets: C,
    moments: M,
    theta: T,
    out: [&mut [T]; D],
    scratch_contributions: &mut [[T; D]],
    chunk_size: usize,
    error_code: &AtomicU32,
) where
    K: HierarchicalKernel<Scalar = T, Output = [T; D]> + Sync,
    T: Scalar,
    K::TargetGeometry: Copy,
    S: SourceCollection<K>,
    M: SourceMomentCollection<K>,
    C: TargetCollection<K>,
{
    if error_code.load(Ordering::Relaxed) != HierarchicalError::Ok as u32 {
        return;
    }

    let target_count = targets.len();
    if target_count <= chunk_size {
        let mut chunk_scratch = EvaluationScratch {
            contribution: &mut scratch_contributions[..1],
        };
        let err = eval_validated(
            kernel,
            source_tree,
            source_summaries,
            sources,
            targets,
            moments,
            theta,
            out,
            &mut chunk_scratch,
        );
        if err != HierarchicalError::Ok {
            let _ = error_code.compare_exchange(
                HierarchicalError::Ok as u32,
                err as u32,
                Ordering::Relaxed,
                Ordering::Relaxed,
            );
        }
        return;
    }

    let chunk_count = target_count.div_ceil(chunk_size);
    let left_chunk_count = chunk_count / 2;
    let left_target_count = left_chunk_count * chunk_size;
    let (left_out, right_out) = split_output_components(out, left_target_count);
    let (left_scratch, right_scratch) = scratch_contributions.split_at_mut(left_chunk_count);
    let left_targets = targets.slice(0, left_target_count);
    let right_targets = targets.slice(left_target_count, target_count);

    rayon::join(
        || {
            eval_par_chunks(
                kernel,
                source_tree,
                source_summaries,
                sources,
                left_targets,
                moments,
                theta,
                left_out,
                left_scratch,
                chunk_size,
                error_code,
            );
        },
        || {
            eval_par_chunks(
                kernel,
                source_tree,
                source_summaries,
                sources,
                right_targets,
                moments,
                theta,
                right_out,
                right_scratch,
                chunk_size,
                error_code,
            );
        },
    );
}

#[inline]
/// Split component-major mutable output slices into disjoint chunks.
fn split_output_components<T, const D: usize>(
    mut out: [&mut [T]; D],
    mid: usize,
) -> ([&mut [T]; D], [&mut [T]; D]) {
    let mut left: [&mut [T]; D] = std::array::from_fn(|_| &mut [] as &mut [T]);
    let mut right: [&mut [T]; D] = std::array::from_fn(|_| &mut [] as &mut [T]);
    for component in 0..D {
        let full = std::mem::take(&mut out[component]);
        let (left_component, right_component) = full.split_at_mut(mid);
        left[component] = left_component;
        right[component] = right_component;
    }
    (left, right)
}

/// Compute the source-tree level represented at each target by the terminal traversal nodes.
///
/// This is a diagnostic companion to [`eval`]. It mirrors
/// the same source-tree walk but does not evaluate field values. Far-accepted
/// nodes contribute their traversal depth, while direct leaf fallbacks
/// contribute the leaf depth. Each contribution is weighted by the number of
/// original source items represented by each terminal node, giving per-target
/// accepted levels.
#[inline]
pub fn accepted_levels<K, C>(
    kernel: &K,
    source_tree: ClusterTreeView<'_, K::Scalar>,
    source_summaries: &[K::SourceSummary],
    targets: C,
    theta: K::Scalar,
    out: &mut [K::Scalar],
) -> HierarchicalError
where
    K: HierarchicalKernel,
    K::TargetGeometry: Copy,
    C: TargetCollection<K>,
{
    let err = validate_source_tree_layout(source_tree);
    if err != HierarchicalError::Ok {
        return err;
    }
    if targets.len() != out.len() || !targets.valid_lengths() {
        return HierarchicalError::LengthMismatch;
    }
    if source_summaries.len() < source_tree.n_nodes() {
        return HierarchicalError::ScratchTooSmall;
    }

    let mut active = Vec::new();
    for target_id in 0..targets.len() {
        let target = targets.target(target_id);
        let mut weighted_level = K::Scalar::ZERO;
        let mut represented_sources = K::Scalar::ZERO;

        active.clear();
        active.push((0_u32, 0_u32));
        while let Some((source_node, source_level)) = active.pop() {
            let source_node_index = source_node as usize;
            let source_count = crate::math::cast::<K::Scalar>(
                source_tree.node_range_count[source_node_index] as f64,
            );
            let source_summary = &source_summaries[source_node_index];
            let source_aabb = source_tree.node_aabb[source_node_index];
            if kernel.accept_far(target.aabb(), source_aabb, source_summary, theta) {
                weighted_level = weighted_level
                    + crate::math::cast::<K::Scalar>(f64::from(source_level)) * source_count;
                represented_sources = represented_sources + source_count;
                continue;
            }

            let leaf_count = source_tree.leaf_count[source_node_index];
            if leaf_count > 0 {
                weighted_level = weighted_level
                    + crate::math::cast::<K::Scalar>(f64::from(source_level)) * source_count;
                represented_sources = represented_sources + source_count;
            } else {
                let next_level = source_level + 1;
                active.push((source_tree.node_left_child[source_node_index], next_level));
                active.push((source_tree.node_right_child[source_node_index], next_level));
            }
        }

        out[target_id] = if represented_sources > K::Scalar::ZERO {
            weighted_level / represented_sources
        } else {
            crate::math::cast::<K::Scalar>(f64::NAN)
        };
    }

    HierarchicalError::Ok
}

/// Dense exact fallback using nested range loops.
#[inline]
pub fn eval_dense<K, S, C, M>(
    kernel: &K,
    sources: S,
    targets: C,
    moments: M,
    out: &mut [K::Output],
    scratch: &mut EvaluationScratch<'_, K::Output>,
) -> HierarchicalError
where
    K: HierarchicalKernel,
    S: SourceCollection<K>,
    C: TargetCollection<K>,
    M: SourceMomentCollection<K>,
{
    if sources.len() != moments.len()
        || !sources.valid_lengths()
        || !moments.valid_lengths()
        || targets.len() != out.len()
        || !targets.valid_lengths()
    {
        return HierarchicalError::LengthMismatch;
    }
    if scratch.contribution.is_empty() {
        return HierarchicalError::ScratchTooSmall;
    }

    for i in 0..out.len() {
        kernel.zero_output(&mut out[i]);
    }

    for target_id in 0..targets.len() {
        let target = targets.target(target_id);
        let target_out = &mut out[target_id];
        for source_id in 0..sources.len() {
            let source = sources.source(source_id);
            let moment = moments.moment(source_id);
            kernel.eval_near(&target, &source, &moment, &mut scratch.contribution[0]);
            kernel.accumulate(target_out, &scratch.contribution[0]);
        }
    }

    HierarchicalError::Ok
}

/// Validate the flat source-tree layout before entering hot traversal loops.
///
/// This converts malformed tree views into error codes up front instead of
/// relying on slice indexing panics in the evaluator. `ClusterTree::as_view`
/// already satisfies these invariants; this guard mainly protects borrowed
/// views passed across API boundaries or future GPU-compatible wrappers.
#[inline]
fn validate_source_tree_layout<T: super::Scalar>(
    tree: ClusterTreeView<'_, T>,
) -> HierarchicalError {
    let n_nodes = tree.n_nodes();
    if n_nodes == 0 {
        return HierarchicalError::EmptyInput;
    }
    if tree.node_left_child.len() != n_nodes
        || tree.node_right_child.len() != n_nodes
        || tree.node_range_start.len() != n_nodes
        || tree.node_range_count.len() != n_nodes
        || tree.leaf_start.len() != n_nodes
        || tree.leaf_count.len() != n_nodes
    {
        return HierarchicalError::LengthMismatch;
    }

    for i in 0..tree.sorted_indices.len() {
        if tree.sorted_indices[i] as usize >= tree.sorted_indices.len() {
            return HierarchicalError::LengthMismatch;
        }
    }

    for node_id in 0..n_nodes {
        let start = tree.node_range_start[node_id] as usize;
        let count = tree.node_range_count[node_id] as usize;
        if count == 0
            || start > tree.sorted_indices.len()
            || count > tree.sorted_indices.len() - start
        {
            return HierarchicalError::LengthMismatch;
        }
        if tree.leaf_count[node_id] == 0 {
            let left = tree.node_left_child[node_id] as usize;
            let right = tree.node_right_child[node_id] as usize;
            if left >= n_nodes || right >= n_nodes {
                return HierarchicalError::LengthMismatch;
            }
        }
    }

    for i in 0..tree.leaf_node_ids.len() {
        let node_id = tree.leaf_node_ids[i] as usize;
        if node_id >= n_nodes {
            return HierarchicalError::LengthMismatch;
        }
        let start = tree.leaf_start[node_id] as usize;
        let count = tree.leaf_count[node_id] as usize;
        if count == 0
            || start > tree.sorted_indices.len()
            || count > tree.sorted_indices.len() - start
        {
            return HierarchicalError::LengthMismatch;
        }
    }

    if !tree.internal_level_offsets.is_empty() {
        let mut previous = 0_usize;
        for i in 0..tree.internal_level_offsets.len() {
            let offset = tree.internal_level_offsets[i] as usize;
            if offset < previous || offset > tree.internal_level_ids.len() {
                return HierarchicalError::LengthMismatch;
            }
            previous = offset;
        }
    }

    for i in 0..tree.internal_level_ids.len() {
        let node_id = tree.internal_level_ids[i] as usize;
        if node_id >= n_nodes {
            return HierarchicalError::LengthMismatch;
        }
        let left = tree.node_left_child[node_id] as usize;
        let right = tree.node_right_child[node_id] as usize;
        if left >= n_nodes || right >= n_nodes {
            return HierarchicalError::LengthMismatch;
        }
    }

    HierarchicalError::Ok
}

#[inline]
/// Propagate leaf source summaries upward through the internal tree levels.
fn propagate_source_summaries<K: HierarchicalKernel>(
    kernel: &K,
    tree: ClusterTreeView<'_, K::Scalar>,
    summaries: &mut [K::SourceSummary],
) -> HierarchicalError {
    if tree.internal_level_offsets.is_empty() {
        return HierarchicalError::Ok;
    }

    let n_levels = tree.internal_level_offsets.len() - 1;
    for level_rev in 0..n_levels {
        let level = n_levels - 1 - level_rev;
        let start = tree.internal_level_offsets[level] as usize;
        let end = tree.internal_level_offsets[level + 1] as usize;
        for i in start..end {
            let node_id = tree.internal_level_ids[i];
            let left = tree.node_left_child[node_id as usize];
            let right = tree.node_right_child[node_id as usize];
            let children = [summaries[left as usize], summaries[right as usize]];
            let err = kernel.combine_source_summaries(&children, &mut summaries[node_id as usize]);
            if err != HierarchicalError::Ok {
                return err;
            }
        }
    }

    HierarchicalError::Ok
}