• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CSMMLab / KiT-RT / #95

28 May 2025 02:06AM UTC coverage: 46.655% (-11.1%) from 57.728%
#95

push

travis-ci

web-flow
Release 2025 (#44)

* New neural models (#30)

* extend kitrt script

* added new neural models

* extend to m3 models

* added M3_2D models

* added M2 and M4 models

* configure ml optimizer for high order models

* added configuration for high order models

* add option for rotation postprcessing in neural networks. remove unneccessary python scripts

* started rotational symmetric postprocessing

* added rotational invariance postprocessing for m2 and m1 models

* fix post merge bugs

* created hohlraum mesh

* add hohlraum tes case

* add hohlraum test case

* add hohlraum cfg filees

* fixed hohlraum testcase

* add hohlraum cfg files

* changed hohlraum cfg

* changed hohlraum testcase to isotropic inflow source boundary condition

* added ghost cell bonudary for hohlraum testcase

* update readme and linesource mesh creator

* added proper scaling for linesource reference solution

* regularized newton debugging

* Data generator with reduced objective functional (#33)

* added reduced optimizer for sampling

* remove old debugging comments

* mesh acceleration (#38)

* added new ansatz (#36)

* added new ansatz

* debug new ansatz

* branch should be abandoned here

* debug new ansatz

* fix scaling error new ansatz

* fix config errors

* temporarily fixed dynamic ansatz rotation bug

* fix inheritance error for new ansatz

* mesh acceleration

* add structured hohlraum

* Mesh acc (#41)

* mesh acceleration

* added floor value for starmap moment methods

* enable accelleration

* delete minimum value starmap

* Update README.md

* Spherical harmonics nn (#40)

* added new ansatz

* debug new ansatz

* branch should be abandoned here

* debug new ansatz

* fix scaling error new ansatz

* fix config errors

* temporarily fixed dynamic ansatz rotation bug

* fix inheritance error for new ansatz

* mesh acceleration

* add structured hohlraum

* added sph... (continued)

767 of 3019 new or added lines in 51 files covered. (25.41%)

131 existing lines in 8 files now uncovered.

4422 of 9478 relevant lines covered (46.66%)

57163.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/velocitybasis/sphericalmonomialsrotated.cpp
1
/*!
2
 * @file sphericalmonomials.cpp
3
 * @brief Class for efficient computation of a spherical monomial basis with rotated velocity reference frame
4
 * @author S. Schotthöfer
5
 */
6

7
#include "velocitybasis/sphericalmonomialsrotated.hpp"
8
#include "toolboxes/errormessages.hpp"
9

NEW
10
SphericalMonomialsRotated::SphericalMonomialsRotated( unsigned L_degree ) {
×
NEW
11
    _LMaxDegree = L_degree;
×
12

NEW
13
    _spatialDim = 3;    // Spatial dimension 2 is hardcoded
×
14

NEW
15
    _YBasis = Vector( GetBasisSize() );
×
16
}
17

NEW
18
SphericalMonomialsRotated::SphericalMonomialsRotated( unsigned L_degree, unsigned short spatialDim ) {
×
NEW
19
    _LMaxDegree = L_degree;
×
NEW
20
    _spatialDim = (unsigned)spatialDim;
×
21

NEW
22
    if( _spatialDim != 2 ) ErrorMessages::Error( "Spatial dimension other than 2 not supported for rotated basis." , CURRENT_FUNCTION );
×
NEW
23
    if( _LMaxDegree > 2 ) ErrorMessages::Error( "Basis degree higher than 2 not supported for rotated basis." , CURRENT_FUNCTION );
×
24

NEW
25
    _YBasis = Vector( GetBasisSize() );
×
26
}
27

NEW
28
Vector SphericalMonomialsRotated::ComputeSphericalBasis( double my, double phi, double r ) {
×
29
    // default for (maximal) radius r = 1
NEW
30
    switch( _spatialDim ) {
×
NEW
31
        case 1: return ComputeSphericalBasis1D( my, r ); break;
×
NEW
32
        case 2: return ComputeSphericalBasis2D( my, phi, r ); break;
×
NEW
33
        default: return ComputeSphericalBasis3D( my, phi, r ); break;
×
34
    }
35
}
36

NEW
37
Vector SphericalMonomialsRotated::ComputeSphericalBasis1D( double my, double r ) {
×
38
    // default for (maximal) radius r = 1
NEW
39
    unsigned idx_vector = 0;
×
40
    unsigned a;
41
    double omega_Z;
42
    // go over all degrees of polynomials
NEW
43
    for( unsigned idx_degree = 0; idx_degree <= _LMaxDegree; idx_degree++ ) {
×
44
        // elem = Omega_x^a : a = idx_degree
NEW
45
        omega_Z             = Omega_z( my, r );
×
NEW
46
        a                   = idx_degree;    // a uniquely defined
×
NEW
47
        _YBasis[idx_vector] = Power( omega_Z, a );
×
NEW
48
        idx_vector++;
×
49
    }
NEW
50
    return _YBasis;
×
51
}
52

NEW
53
Vector SphericalMonomialsRotated::ComputeSphericalBasis2D( double my, double phi, double r ) {
×
54
    // default for (maximal) radius r = 1
NEW
55
    unsigned idx_vector = 0;
×
56
    double omegaX, omegaY;
57
    unsigned a, b;
58

NEW
59
    omegaX = Omega_x( my, phi, r );
×
NEW
60
    omegaY = Omega_y( my, phi, r );
×
61

NEW
62
    Vector omegaXY{ omegaX, omegaY };
×
NEW
63
    Matrix rotationMatrix = CreateRotator( omegaXY );
×
NEW
64
    Matrix rotationMatrixTrans  = blaze::trans( rotationMatrix );
×
65

NEW
66
    omegaXY = RotateM1( omegaXY, rotationMatrix );    // Rotate velocity frame to x-axis
×
67

NEW
68
    omegaX = omegaXY[0];
×
NEW
69
    omegaY = omegaXY[1];
×
70

71
    // go over all degrees of polynomials
NEW
72
    for( unsigned idx_degree = 0; idx_degree <= _LMaxDegree; idx_degree++ ) {
×
73
        // elem = Omega_x^a+ Omega_y^b  : a+b = idx_degree
74

NEW
75
        for( a = 0; a <= idx_degree; a++ ) {
×
NEW
76
            b                   = idx_degree - a;    // b uniquely defined
×
NEW
77
            _YBasis[idx_vector] = Power( omegaX, a ) * Power( omegaY, b );
×
NEW
78
            idx_vector++;
×
79
        }
80
    }
81

NEW
82
    Vector m1{ _YBasis[1], _YBasis[2] };
×
NEW
83
    Matrix m2{ { _YBasis[3], 0.5 * _YBasis[4] }, { 0.5 * _YBasis[4], _YBasis[5] } };
×
84

85
    // Rotate basis back
NEW
86
    m1 = RotateM1( m1, rotationMatrixTrans );
×
NEW
87
    m2 = RotateM2( m2, rotationMatrixTrans, rotationMatrix );
×
88

NEW
89
    _YBasis[1] = m1[0];
×
NEW
90
    _YBasis[2] = m1[1];
×
NEW
91
    _YBasis[3] = m2( 0, 0 );
×
NEW
92
    _YBasis[4] = 2 * m2( 1, 0 );
×
NEW
93
    _YBasis[5] = m2( 1, 1 );
×
94

95
    //for( unsigned idx_degree = 0; idx_degree <= _LMaxDegree; idx_degree++ ) {
96
    //    // elem = Omega_x^a+ Omega_y^b  : a+b = idx_degree
97
    //    omegaX = Omega_x( my, phi, r );
98
    //    omegaY = Omega_y( my, phi, r );
99
    //    for( a = 0; a <= idx_degree; a++ ) {
100
    //        b                   = idx_degree - a;    // b uniquely defined
101
    //        _YBasis[idx_vector] = Power( omegaX, a ) * Power( omegaY, b );
102
    //        idx_vector++;
103
    //    }
104
    //}
105

NEW
106
    return _YBasis;
×
107
}
108

NEW
109
Vector SphericalMonomialsRotated::ComputeSphericalBasis3D( double my, double phi, double r ) {
×
110
    // default for radius r = 1
NEW
111
    unsigned idx_vector = 0;
×
112
    unsigned a, b, c;
113

NEW
114
    double omega_X = Omega_x( my, phi, r );
×
NEW
115
    double omega_Y = Omega_y( my, phi, r );
×
NEW
116
    double omega_Z = Omega_z( my, r );
×
117
    // go over all degrees of polynomials
NEW
118
    for( unsigned idx_degree = 0; idx_degree <= _LMaxDegree; idx_degree++ ) {
×
119
        // elem = Omega_x^a+ Omega_y^b +Omega_z^c : a+b+c = idx_degree
NEW
120
        for( a = 0; a <= idx_degree; a++ ) {
×
NEW
121
            for( b = 0; b <= idx_degree - a; b++ ) {
×
NEW
122
                c                   = idx_degree - a - b;    // c uniquely defined
×
NEW
123
                _YBasis[idx_vector] = Power( omega_X, a ) * Power( omega_Y, b ) * Power( omega_Z, c );
×
NEW
124
                idx_vector++;
×
125
            }
126
        }
127
    }
NEW
128
    return _YBasis;
×
129
}
130

NEW
131
Vector SphericalMonomialsRotated::ComputeSphericalBasisKarthesian( double x, double y, double z ) {
×
132
    // transform (x,y,z) into (my,phi)
NEW
133
    double my  = z;                                // my = z
×
NEW
134
    double phi = atan2( y, x );                    // phi in [-pi,pi]
×
NEW
135
    double r   = sqrt( x * x + y * y + z * z );    // radius r
×
136

137
    // adapt intervall s.t. phi in [0,2pi]
NEW
138
    if( phi < 0 ) {
×
NEW
139
        phi = 2 * M_PI + phi;
×
140
    }
141

NEW
142
    return ComputeSphericalBasis( my, phi, r );
×
143
}
144

NEW
145
unsigned SphericalMonomialsRotated::GetBasisSize() {
×
NEW
146
    unsigned basisLen = 0;
×
NEW
147
    for( unsigned idx_degree = 0; idx_degree <= _LMaxDegree; idx_degree++ ) {
×
NEW
148
        basisLen += GetCurrDegreeSize( idx_degree );
×
149
    }
NEW
150
    return basisLen;
×
151
}
152

NEW
153
unsigned SphericalMonomialsRotated::GetCurrDegreeSize( unsigned currDegreeL ) {
×
NEW
154
    return Factorial( currDegreeL + _spatialDim - 1 ) / ( Factorial( currDegreeL ) * Factorial( _spatialDim - 1 ) );
×
155
}
156

NEW
157
unsigned SphericalMonomialsRotated::GetGlobalIndexBasis( int l_degree, int k_order ) {
×
NEW
158
    if( l_degree < 0 ) ErrorMessages::Error( "Negative polynomial degrees not supported.", CURRENT_FUNCTION );
×
NEW
159
    if( k_order < 0 ) ErrorMessages::Error( "Order k of spherical monomial basis must not be negative.", CURRENT_FUNCTION );
×
NEW
160
    if( k_order >= (int)GetCurrDegreeSize( l_degree ) )
×
NEW
161
        ErrorMessages::Error( "Order k of spherical monomial basis out of bounds.", CURRENT_FUNCTION );
×
162

NEW
163
    unsigned basisLen = 0;
×
NEW
164
    for( unsigned idx_degree = 0; idx_degree < (unsigned)l_degree; idx_degree++ ) {
×
NEW
165
        basisLen += GetCurrDegreeSize( idx_degree );
×
166
    }
NEW
167
    return basisLen + (unsigned)k_order;
×
168
}
169

NEW
170
unsigned SphericalMonomialsRotated::Factorial( unsigned n ) { return ( n == 1 || n == 0 ) ? 1 : Factorial( n - 1 ) * n; }
×
171

NEW
172
double SphericalMonomialsRotated::Omega_x( double my, double phi, double r ) { return r * sqrt( 1 - my * my ) * cos( phi ); }
×
NEW
173
double SphericalMonomialsRotated::Omega_y( double my, double phi, double r ) { return r * sqrt( 1 - my * my ) * sin( phi ); }
×
NEW
174
double SphericalMonomialsRotated::Omega_z( double my, double r ) { return r * my; }
×
175

NEW
176
double SphericalMonomialsRotated::Power( double basis, unsigned exponent ) {
×
NEW
177
    if( exponent == 0 ) return 1.0;               // basis^0
×
NEW
178
    double result = basis;                        // basis^1
×
NEW
179
    for( unsigned i = 1; i < exponent; i++ ) {    // exp> 1
×
NEW
180
        result = result * basis;
×
181
    }
NEW
182
    return result;
×
183
}
184

NEW
185
Vector SphericalMonomialsRotated::RotateM1( Vector& vec, Matrix& R ) { return R * vec; }
×
186

NEW
187
Matrix SphericalMonomialsRotated::RotateM2( Matrix& vec, Matrix& R, Matrix& Rt ) { return R * vec * Rt; }
×
188

NEW
189
Matrix SphericalMonomialsRotated::CreateRotator( const Vector& uFirstMoment ) {
×
NEW
190
    double a = uFirstMoment[0];
×
NEW
191
    double b = uFirstMoment[1];
×
192
    double c, s, r;
193

NEW
194
    r = norm( uFirstMoment );    // sqrt( a * a + b * b );
×
NEW
195
    c = a / r;
×
NEW
196
    s = -b / r;
×
197

NEW
198
    return Matrix{ { c, -s }, { s, c } };    // Rotation Matrix
×
199
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc