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

NREL / SolTrace / 14628243107

23 Apr 2025 09:13PM UTC coverage: 44.154% (+0.5%) from 43.617%
14628243107

Pull #65

github

web-flow
Merge e65736e0a into 96166e291
Pull Request #65: Refactor the Trace function (and related functions)

363 of 670 new or added lines in 6 files covered. (54.18%)

135 existing lines in 4 files now uncovered.

1941 of 4396 relevant lines covered (44.15%)

10000057.29 hits per line

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

0.0
/coretrace/torusclosedform.cpp
1

2
/*******************************************************************************************************
3
*  Copyright 2018 Alliance for Sustainable Energy, LLC
4
*
5
*  NOTICE: This software was developed at least in part by Alliance for Sustainable Energy, LLC
6
*  ("Alliance") under Contract No. DE-AC36-08GO28308 with the U.S. Department of Energy and the U.S.
7
*  The Government retains for itself and others acting on its behalf a nonexclusive, paid-up,
8
*  irrevocable worldwide license in the software to reproduce, prepare derivative works, distribute
9
*  copies to the public, perform publicly and display publicly, and to permit others to do so.
10
*
11
*  Redistribution and use in source and binary forms, with or without modification, are permitted
12
*  provided that the following conditions are met:
13
*
14
*  1. Redistributions of source code must retain the above copyright notice, the above government
15
*  rights notice, this list of conditions and the following disclaimer.
16
*
17
*  2. Redistributions in binary form must reproduce the above copyright notice, the above government
18
*  rights notice, this list of conditions and the following disclaimer in the documentation and/or
19
*  other materials provided with the distribution.
20
*
21
*  3. The entire corresponding source code of any redistribution, with or without modification, by a
22
*  research entity, including but not limited to any contracting manager/operator of a United States
23
*  National Laboratory, any institution of higher learning, and any non-profit organization, must be
24
*  made publicly available under this license for as long as the redistribution is made available by
25
*  the research entity.
26
*
27
*  4. Redistribution of this software, without modification, must refer to the software by the same
28
*  designation. Redistribution of a modified version of this software (i) may not refer to the modified
29
*  version by the same designation, or by any confusingly similar designation, and (ii) must refer to
30
*  the underlying software originally provided by Alliance as "SolTrace". Except to comply with the 
31
*  foregoing, the term "SolTrace", or any confusingly similar designation may not be used to refer to 
32
*  any modified version of this software or any modified version of the underlying software originally 
33
*  provided by Alliance without the prior written consent of Alliance.
34
*
35
*  5. The name of the copyright holder, contributors, the United States Government, the United States
36
*  Department of Energy, or any of their employees may not be used to endorse or promote products
37
*  derived from this software without specific prior written permission.
38
*
39
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
40
*  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41
*  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER,
42
*  CONTRIBUTORS, UNITED STATES GOVERNMENT OR UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR
43
*  EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44
*  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
46
*  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
47
*  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
*******************************************************************************************************/
49

50

51
#include <math.h>
52

53
#include "types.h"
54
#include "procs.h"
55

56

57
void TorusClosedForm(
×
58
                        TElement *Element,
59
                        double PosLoc[3],
60
                        double CosLoc[3],
61
                        double PosXYZ[3],
62
                        double DFXYZ[3],
63
                        double *PathLength,
64
                        int *ErrorFlag)
65
{
66
        double Xo=0.0,Yo=0.0,Zo=0.0,Epsilon=0.0,Eta=0.0,Rho=0.0,Rs=0.0,Ra=0.0,X=0.0,Y=0.0,Z=0.0,Fx=0.0,Fy=0.0,Fz=0.0;
×
67
        double amatrix[5][5];
68
        double rvector[5];
69
        double imagroot1=0.0,imagroot2=0.0;
×
70
        int nn = 0;
×
71

72
        Rs = Element->CrossSectionRadius;
×
73
        Ra = Element->AnnularRadius;
×
74
        Xo = PosLoc[0];
×
75
        Yo = PosLoc[1];
×
76
        Zo = PosLoc[2];
×
77
        Epsilon = CosLoc[0];
×
78
        Eta = CosLoc[1];
×
79
        Rho = CosLoc[2];
×
80
        nn = 4;
×
81
        *ErrorFlag = 0;
×
82

83
        for (int i=0;i<5;i++)
×
84
        {
85
                rvector[i] = 0.0;
×
86
                for (int j=0;j<5;j++)
×
87
                        amatrix[i][j] = 0.0;
×
88
        }
89

90
        amatrix[nn][4] = pow(Epsilon,4)+2.0*Epsilon*Epsilon*(Eta*Eta+Rho*Rho)+
×
91
                                                pow(Eta,4)+2.0*Eta*Eta*Rho*Rho+pow(Rho,4);
×
92

93
        amatrix[nn][3] = 4.0*(Epsilon*Epsilon+Eta*Eta+Rho*Rho)*(Epsilon*Xo+Eta*Yo+
×
94
                                                Rho*Zo-Rho*Rs);
×
95
        
96
        amatrix[nn][2] = Xo*Xo*(6.0*Epsilon*Epsilon+2.0*Eta*Eta+2.0*Rho*Rho)+
×
97
                                                8.0*Epsilon*Xo*(Eta*Yo+Rho*Zo-Rho*Rs)+
×
98
                                                2.0*Yo*Yo*(Epsilon*Epsilon+3.0*Eta*Eta+Rho*Rho)+
×
99
                                                8.0*Eta*Rho*Yo*(Zo-Rs)+
×
100
                                                (Epsilon*Epsilon+Eta*Eta+3.0*Rho*Rho)*(2.0*Zo*Zo-4.0*Rs*Zo)-
×
101
                                                2.0*Ra*Ra*(Epsilon*Epsilon+Eta*Eta-Rho*Rho)+4.0*Rho*Rho*Rs*Rs;
×
102

103
        amatrix[nn][1] = 4.0*(Xo*Xo*(Epsilon*Xo+Eta*Yo+Rho*Zo-Rho*Rs)+Yo*Yo*(Epsilon*Xo+
×
104
                                                Eta*Yo+Rho*Zo-Rho*Rs)+Zo*Zo*(Epsilon*Xo+Eta*Yo+Rho*Zo-3.0*Rho*Rs)-
×
105
                                                2.0*Epsilon*Rs*Xo*Zo-Epsilon*Ra*Ra*Xo-2.0*Eta*Rs*Yo*Zo-
×
106
                                                Eta*Ra*Ra*Yo+Rho*Ra*Ra*(Zo-Rs)+2.0*Rho*Rs*Rs*Zo);
×
107

108
        amatrix[nn][0] = pow(Xo,4)+2.0*Xo*Xo*(Yo*Yo+Zo*Zo-2.0*Rs*Zo-Ra*Ra)+
×
109
                                                pow(Yo,4)+2.0*Yo*Yo*(Zo*Zo-2.0*Rs*Zo-Ra*Ra)+
×
110
                                                pow(Zo,4)-4.0*Rs*Zo*Zo*Zo+2.0*Ra*Ra*Zo*Zo+4.0*Rs*Rs*Zo*Zo
×
111
                                                -4.0*Ra*Ra*Rs*Zo+pow(Ra,4);
×
112

113
    Root_432(nn,amatrix,rvector,&imagroot1,&imagroot2);
×
114

115
 // {pass results}
116
    if (imagroot1==0.0 && imagroot2==0.0)
×
117
    {
118
      //four real roots rvector[1-4] which are the pathlengths
119
                piksrt(4,rvector); //sort them
×
120
                if (rvector[4] <= 0.0)  //ray heading away from surface
×
121
                {
122
                        *PathLength = rvector[4];
×
123
                        *ErrorFlag = 1;
×
124
                        return;
×
125
                }
126
                //*PathLength = rvector[4];
127
                //if (rvector[3] <= 0.0 )
128
                //        goto Label_10;
129
                //else
130
                //        *PathLength = rvector[3];
131
                //        
132
                //if (rvector[2] <= 0.0 )
133
                //        goto Label_10;
134
                //else
135
                //        *PathLength = rvector[2];
136
                //        
137
                //if (rvector[1] <= 0.0 )
138
                //        goto Label_10;
139
                //else
140
                //        *PathLength = rvector[1];
141
                        
NEW
142
                if (rvector[3] > 0)
×
143
                {
NEW
144
                        *PathLength = rvector[3];
×
NEW
145
                        if (rvector[2] > 0) 
×
146
                        {
NEW
147
                                *PathLength = rvector[2];
×
NEW
148
                                if (rvector[1] > 0)
×
149
                                {
NEW
150
                                        *PathLength = rvector[1];
×
151
                                }
152
                        }
153
                }
154

155
                //goto Label_10;
156
        }
157

158

NEW
159
        else if (imagroot1==0.0 && imagroot2!=0.0)
×
160
        {
161
                //two real roots rvector[1-2] which are the pathlengths
162
                if (rvector[1] <= rvector[2])
×
163
                        *PathLength = rvector[1];
×
164
                else
165
                        *PathLength = rvector[2];
×
166
                //goto Label_10;
167
        }
168

NEW
169
    else if (imagroot1!=0.0 && imagroot2==0.0)
×
170
    {
171
      //two real roots rvector[3-4] which are the pathlengths
172
      if (rvector[3] <= rvector[4])
×
173
                *PathLength = rvector[3];
×
174
      else
175
                *PathLength = rvector[4];
×
176
                
177
      //goto Label_10;
178
    }
179
        
180
        else
181
        {
NEW
182
                *PathLength = 0.0;
×
183
        }
184
     
185
    
186
//Label_10:
187
        if (*PathLength==0.0)   //ray missed torus completely
×
188
        {
189
                *ErrorFlag = 1;
×
190
                return;
×
191
        }
192
        
193
        X = Xo+*PathLength*Epsilon;
×
194
        Y = Yo+*PathLength*Eta;
×
195
        Z = Zo+*PathLength*Rho;
×
196
        Fx = -2.0*X*(Ra-sqrt(X*X+Y*Y))/sqrt(X*X+Y*Y);
×
197
        Fy = -2.0*Y*(Ra-sqrt(X*X+Y*Y))/sqrt(X*X+Y*Y);
×
198
        Fz = 2.0*(Z-Rs);
×
199
        PosXYZ[0] = X;
×
200
        PosXYZ[1] = Y;
×
201
        PosXYZ[2] = Z;
×
202
        DFXYZ[0] = -Fx;
×
203
        DFXYZ[1] = -Fy;
×
204
        DFXYZ[2] = -Fz;
×
205
}
206
//End of Procedure--------------------------------------------------------------
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