-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathradiation.cpp
249 lines (212 loc) · 7.4 KB
/
radiation.cpp
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
// -*-c++-*-
//
//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
//
// MASA - Manufactured Analytical Solutions Abstraction Library
//
// Copyright (C) 2010,2011,2012,2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301 USA
//
//-----------------------------------------------------------------------el-
// $Author: nick $
// $Id: heat.cpp 18162 2011-03-01 05:23:07Z nick $
//
// radiation.cpp: These are the MASA class member functions and constructors
// For Radiation
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//
#include <masa_internal.h>
using namespace MASA;
/* ------------------------------------------------
*
* radiation_integrated_intensity
*
*
* -----------------------------------------------
*/
template <typename Scalar>
MASA::radiation_integrated_intensity<Scalar>::radiation_integrated_intensity()
{
this->mmsname = "radiation_integrated_intensity";
this->dimension=1;
// registering variables
this->register_var("no_gauss",&no_gauss);
// registering a vector
this->register_vec("vec_mean",vec_mean);
this->register_vec("vec_amp",vec_amp);
this->register_vec("vec_stdev",vec_stdev);
// initialize all defaults
this->init_var();
}//done with constructor
template <typename Scalar>
int MASA::radiation_integrated_intensity<Scalar>::init_var()
{
int err = 0;
std::vector<Scalar> vec1,vec2,vec3;
/*
! Random number generated :: Matlab
a =(/ 7.4462631920000945d+01, 6.6885970491068861d+01, &
9.5002692320883099d+01, 6.8462339056010748d+01, &
5.5560137764689372d+01, 8.9012603416056891d+01, &
6.9486941848062671d+01, 6.2084564295691635d+01, &
7.0195607279405735d+01, 5.4822726258419429d+01, &
5.6598664630316755d+01, 9.7102529538774263d+01, &
9.7806727011490111d+01, 7.8760429753923276d+01, &
5.2988977147357794d+01, 6.1738995668620319d+01, &
6.7657928561103546d+01, 9.1059702009897961d+01, &
5.0770171882577756d+01, 5.2151190082890395d+01, &
5.8449501473135214d+01, 8.2455773747822604d+01, &
8.6586119282933510d+01, 8.2387298156815334d+01, &
7.2546185321547242d+01 /);
b(1) = 0.2d0
do i = 2, ngaussians
b(i) = b(i-1)+(0.8d0-0.2d0)/(dble(ngaussians-1));
enddo
do i = 1, ngaussians
c(i) = 0.05;
enddo
*/
// using marcos defaults
err += this->set_var("no_gauss",25);
// set size of vectors and set default values
vec_mean.resize(no_gauss);
vec_mean[0]=0.2;
for(int it = 1;it<int(vec_mean.size());it++)
{
//vec_mean[it]=it;
vec_mean[it]=vec_mean[it-1]+(0.8-0.2)/(24.0);;
}
vec_amp.resize(no_gauss);
vec_amp[0] = 7.4462631920000945;
vec_amp[1] = 6.6885970491068861;
vec_amp[2] = 9.5002692320883099;
vec_amp[3] = 6.8462339056010748;
vec_amp[4] = 5.5560137764689372;
vec_amp[5] = 8.9012603416056891;
vec_amp[6] = 6.9486941848062671;
vec_amp[7] = 6.2084564295691635;
vec_amp[8] = 7.0195607279405735;
vec_amp[9] = 5.4822726258419429;
vec_amp[10]= 5.6598664630316755;
vec_amp[11]= 9.7102529538774263;
vec_amp[12]= 9.7806727011490111;
vec_amp[13]= 7.8760429753923276;
vec_amp[14]= 5.2988977147357794;
vec_amp[15]= 6.1738995668620319;
vec_amp[16]= 6.7657928561103546;
vec_amp[17]= 9.1059702009897961;
vec_amp[18]= 5.0770171882577756;
vec_amp[19]= 5.2151190082890395;
vec_amp[20]= 5.8449501473135214;
vec_amp[21]= 8.2455773747822604;
vec_amp[22]= 8.6586119282933510;
vec_amp[23]= 8.2387298156815334;
vec_amp[24]= 7.2546185321547242;
vec_stdev.resize(no_gauss);
vec_amp.resize(no_gauss);
for(int it = 0;it<int(vec_amp.size());it++)
{
vec_stdev[it]=0.05;
}
return err;
}
template <typename Scalar>
int MASA::radiation_integrated_intensity<Scalar>::check_vec()
{
if(vec_mean.size() != vec_amp.size() || vec_mean.size() != vec_stdev.size())
{
std::cout << "MASA WARNING:: in mms radiation_integrated_intensity--\n";
std::cout << "Vectors vec_amp,vec_mean,vec_stdev are not identically sized!\n";
return 1;
}
return 0;
}
template <typename Scalar>
Scalar MASA::radiation_integrated_intensity<Scalar>::eval_q_u(Scalar x)
{
using std::exp;
using std::pow;
// this is the manufactured solution: i.e. the gaussians contributions
Scalar Q_I = 0;
// error handling for vectors
if(check_vec() == 1)
{
return -1;
}
// sum up intensity at particular location by
// looping over gaussians of intensity
for(int it = 0;it<int(vec_amp.size());it++)
{
// this is evaluating the gaussians contributions at
// a particular spatial location
Q_I += vec_amp[it]*exp( -pow(x-vec_mean[it],2)/(2*pow(vec_stdev[it],2)));
}
return Q_I;
}
template <typename Scalar>
Scalar MASA::radiation_integrated_intensity<Scalar>::eval_exact_u(Scalar x)
{
// this is the source term: i.e. integrated intensity
Scalar exact_I = 0;
Scalar xs,s;
// error handling for vectors
if(check_vec() == 1)
return -1;
// error handling for x
if(x <= 0)
{
std::cout << "MASA WARNING:: in mms radiation_integrated_intensity--\n";
std::cout << "Integration bound must be greater than zero!\n";
return -1;
}
// sum up gaussians for integrated intensity
// achtung: some sort of iterator failure here, hacking together a loop for now
// for(std::vector<Scalar>::iterator it = vec_amp.begin(); it != vec_amp.end(); it++)
for(int it = 0;it<int(vec_amp.size());it++)
{
xs = (x-vec_mean[it])/vec_stdev[it];
s = -vec_mean[it]/vec_stdev[it];
// integrate [0,inf]
if(x>1000.0)
{
exact_I += vec_amp[it]*(1-phi(s));
}
else // integrate [0,x]
{
exact_I += vec_amp[it]*(phi(xs)-phi(s));
}
// c = std::pow(2.0,0.5);
// p = std::pow(pi,0.5);
// 0.50*erf((c*vec_mean[it])/(2.0*vec_stdev[it]))*vec_amp[it]*std::sqrt(pi)*std::sqrt(2.0)*vec_stdev[it]
// - 0.5*erf((vec_stdev[it]*(-1.0+vec_mean[it]))/(2.0*vec_stdev[it])) * vec_amp[it]*p*c*vec_stdev[it];
}
return exact_I;
}
template <typename Scalar>
Scalar MASA::radiation_integrated_intensity<Scalar>::phi(Scalar x)
{
Scalar out;
// using c99 provided erf(double x) from cmath
out = 0.5 * (1 + erf(x));
return out;
}
// ----------------------------------------
// Template Instantiation(s)
// ----------------------------------------
MASA_INSTANTIATE_ALL(MASA::radiation_integrated_intensity);