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
//! Helpers

use crate::traits::Kernel;
use crate::types::GreenKernelEvalType;
use rlst::RlstScalar;

pub(crate) fn check_dimensions_evaluate<K: Kernel, T: RlstScalar>(
    kernel: &K,
    eval_type: GreenKernelEvalType,
    sources: &[T::Real],
    targets: &[T::Real],
    charges: &[T],
    result: &[T],
) {
    assert!(
        sources.len() % kernel.space_dimension() == 0,
        "Length of sources {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    assert!(
        targets.len() % kernel.space_dimension() == 0,
        "Length of targets {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    let nsources = sources.len() / kernel.space_dimension();
    let ntargets = targets.len() / kernel.space_dimension();

    assert_eq!(
        charges.len(),
        nsources,
        "Wrong dimension for `charges`. {} != {} ",
        charges.len(),
        nsources,
    );

    assert_eq!(
        result.len(),
        kernel.range_component_count(eval_type) * ntargets,
        "Wrong dimension for `result`. {} != {} ",
        result.len(),
        ntargets * kernel.range_component_count(eval_type),
    );
}

pub(crate) fn check_dimensions_assemble<K: Kernel, T: RlstScalar>(
    kernel: &K,
    eval_type: GreenKernelEvalType,
    sources: &[T::Real],
    targets: &[T::Real],
    result: &[T],
) {
    assert!(
        sources.len() % kernel.space_dimension() == 0,
        "Length of sources {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    assert!(
        targets.len() % kernel.space_dimension() == 0,
        "Length of targets {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    let nsources = sources.len() / kernel.space_dimension();
    let ntargets = targets.len() / kernel.space_dimension();

    assert_eq!(
        result.len(),
        kernel.range_component_count(eval_type) * nsources * ntargets,
        "Wrong dimension for `result`. {} != {} ",
        result.len(),
        nsources * ntargets * kernel.range_component_count(eval_type),
    );
}

pub(crate) fn check_dimensions_assemble_diagonal<K: Kernel, T: RlstScalar>(
    kernel: &K,
    eval_type: GreenKernelEvalType,
    sources: &[T::Real],
    targets: &[T::Real],
    result: &[T],
) {
    assert!(
        sources.len() % kernel.space_dimension() == 0,
        "Length of sources {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    assert!(
        targets.len() % kernel.space_dimension() == 0,
        "Length of targets {} is not a multiple of space dimension {}.",
        sources.len(),
        kernel.space_dimension()
    );

    let nsources = sources.len() / kernel.space_dimension();
    let ntargets = targets.len() / kernel.space_dimension();

    assert_eq!(
        nsources, ntargets,
        "Lengths of sources and targets do not match. {} != {} ",
        nsources, ntargets,
    );

    assert_eq!(
        result.len(),
        kernel.range_component_count(eval_type) * nsources,
        "Wrong dimension for `result`. {} != {} ",
        result.len(),
        nsources * kernel.range_component_count(eval_type),
    );
}