Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
multiply.cpp
Go to the documentation of this file.
1/*
2Copyright (c) 2001 Igor B. Smirnov
3
4The file can be used, copied, modified, and distributed
5according to the terms of GNU Lesser General Public License version 2.1
6as published by the Free Software Foundation,
7and provided that the above copyright notice, this permission notice,
8and notices about any modifications of the original text
9appear in all copies and in supporting documentation.
10The file is provided "as is" without express or implied warranty.
11*/
14
16 long q = f.get_qel();
17 DoubleAc s(0.0);
18 long n;
19 for (n = 0; n < q; n++) {
20 DoubleAc t = f[n];
21 s = s + square(t);
22 }
23 return sqrt(s);
24}
25
27 long q = f.get_qel();
28 DoubleAc s(0.0);
29 long n;
30 for (n = 0; n < q; n++) {
31 DoubleAc t = f[n];
32 s = s + square(t);
33 }
34 return s;
35}
36
38 const DynLinArr<double>& vc) {
39 mfunname("DynLinArr<DoubleAc> operator*(const DynArr<DoubleAc>& mt, const "
40 "DynLinArr<double>& vc)");
41
42 const DynLinArr<long>& qel_mt(mt.get_qel());
43 check_econd11(qel_mt.get_qel(), != 2, mcerr);
44 long q = vc.get_qel();
45 check_econd12(q, !=, qel_mt[1], mcerr);
46 DoubleAc s(0); // assumes that this clears the element
47 DynLinArr<DoubleAc> res(qel_mt[0], s);
48 long n1, n2;
49 for (n1 = 0; n1 < qel_mt[0]; n1++) {
50 for (n2 = 0; n2 < q; n2++) {
51 res.acu(n1) += mt.acu(n1, n2) * vc.acu(n2);
52 }
53 }
54 return res;
55}
56
58 const DynLinArr<DoubleAc>& vc) {
59 mfunname("DynLinArr<DoubleAc> operator*(const DynArr<double>& mt, const "
60 "DynLinArr<DoubleAc>& vc)");
61
62 const DynLinArr<long>& qel_mt(mt.get_qel());
63 check_econd11(qel_mt.get_qel(), != 2, mcerr);
64 long q = vc.get_qel();
65 check_econd12(q, !=, qel_mt[1], mcerr);
66 DoubleAc s(0); // assumes that this clears the element
67 DynLinArr<DoubleAc> res(qel_mt[0], s);
68 long n1, n2;
69 for (n1 = 0; n1 < qel_mt[0]; n1++) {
70 for (n2 = 0; n2 < q; n2++) {
71 res.acu(n1) += mt.acu(n1, n2) * vc.acu(n2);
72 }
73 }
74 return res;
75}
76
78 const DynLinArr<double>& vc2) {
79 mfunname("DoubleAc operator*(const DynLinArr<DoubleAc>& vc1, const "
80 "DynLinArr<double>& vc2)");
81
82 long q1 = vc1.get_qel();
83 long q2 = vc2.get_qel();
84 check_econd12(q1, !=, q2, mcerr);
85 DoubleAc s(0); // assumes that this clears the element
86 long n;
87 for (n = 0; n < q1; n++) {
88 s += vc1.acu(n) * vc2.acu(n);
89 }
90 return s;
91}
92
94 const DynLinArr<DoubleAc>& vc2) {
95 mfunname("DoubleAc operator*(const DynLinArr<double>& vc1, const "
96 "DynLinArr<DoubleAc>& vc2)");
97 //mcout<<"operator*(const DynLinArr<double>& vc1, ...):\n";
98 long q1 = vc1.get_qel();
99 long q2 = vc2.get_qel();
100 check_econd12(q1, !=, q2, mcerr);
101 DoubleAc s(0); // assumes that this clears the element
102 long n;
103 //mcout<<"s="<<s<<'\n';
104 for (n = 0; n < q1; n++) {
105 s += vc1.acu(n) * vc2.acu(n);
106 //mcout<<"vc1[n]="<<vc1[n]<<'\n';
107 //mcout<<"vc2[n]="<<vc2[n]<<'\n';
108 //mcout<<"vc1[n] * vc2[n]="<<vc1[n] * vc2[n]<<'\n';
109 //mcout<<"s="<<s<<'\n';
110 }
111 return s;
112}
113
115 const DynLinArr<double>& vc2) {
116 mfunname("DoubleAc operator+(const DynLinArr<DoubleAc>& vc1, const "
117 "DynLinArr<double>& vc2)");
118 long q1 = vc1.get_qel();
119 long q2 = vc2.get_qel();
120 check_econd12(q1, !=, q2, mcerr);
122 long n;
123 for (n = 0; n < q1; n++) {
124 s.acu(n) = vc1.acu(n) + vc2.acu(n);
125 }
126 return s;
127}
129 const DynLinArr<double>& vc2) {
130 mfunname("DoubleAc operator-(const DynLinArr<DoubleAc>& vc1, const "
131 "DynLinArr<double>& vc2)");
132 long q1 = vc1.get_qel();
133 long q2 = vc2.get_qel();
134 check_econd12(q1, !=, q2, mcerr);
136 long n;
137 for (n = 0; n < q1; n++) {
138 s.acu(n) = vc1.acu(n) - vc2.acu(n);
139 }
140 return s;
141}
142
144 const DynLinArr<DoubleAc>& vc2) {
145 mfunname("DoubleAc operator+(const DynLinArr<double>& vc1, const "
146 "DynLinArr<DoubleAc>& vc2)");
147 long q1 = vc1.get_qel();
148 long q2 = vc2.get_qel();
149 check_econd12(q1, !=, q2, mcerr);
151 long n;
152 for (n = 0; n < q1; n++) {
153 s.acu(n) = vc1.acu(n) + vc2.acu(n);
154 }
155 return s;
156}
158 const DynLinArr<DoubleAc>& vc2) {
159 mfunname("DoubleAc operator-(const DynLinArr<double>& vc1, const "
160 "DynLinArr<DoubleAc>& vc2)");
161 long q1 = vc1.get_qel();
162 long q2 = vc2.get_qel();
163 check_econd12(q1, !=, q2, mcerr);
165 long n;
166 for (n = 0; n < q1; n++) {
167 s.acu(n) = vc1.acu(n) - vc2.acu(n);
168 }
169 return s;
170}
171
173 const DynArr<double>& mt2) {
174 mfunname("DynArr<DoubleAc> operator+(const DynArr<DoubleAc>& mt1, const "
175 "DynArr<double>& mt2)");
176 long qdim1 = mt1.get_qdim();
177 long qdim2 = mt2.get_qdim();
178 check_econd12(qdim1, !=, qdim2, mcerr);
179 const DynLinArr<long>& qe1 = mt1.get_qel();
180 const DynLinArr<long>& qe2 = mt2.get_qel();
181 check_econd12(qe1, !=, qe2, mcerr);
182 DynArr<DoubleAc> ms(mt1);
183 IterDynArr<DoubleAc> iter(&ms);
184 DoubleAc* at;
185 while ((at = iter.more()) != NULL) {
186 (*at) = (*at) + mt2.acu(iter.get_ncur());
187 }
188 return ms;
189}
191 const DynArr<double>& mt2) {
192 mfunname("DynArr<DoubleAc> operator-(const DynArr<DoubleAc>& mt1, const "
193 "DynArr<double>& mt2)");
194 long qdim1 = mt1.get_qdim();
195 long qdim2 = mt2.get_qdim();
196 check_econd12(qdim1, !=, qdim2, mcerr);
197 const DynLinArr<long>& qe1 = mt1.get_qel();
198 const DynLinArr<long>& qe2 = mt2.get_qel();
199 check_econd12(qe1, !=, qe2, mcerr);
200 DynArr<DoubleAc> ms(mt1);
201 IterDynArr<DoubleAc> iter(&ms);
202 DoubleAc* at;
203 while ((at = iter.more()) != NULL) {
204 (*at) = (*at) - mt2.acu(iter.get_ncur());
205 }
206 return ms;
207}
208
210 const DynArr<DoubleAc>& mt2) {
211 mfunname("DynArr<DoubleAc> operator+(const DynArr<double>& mt1, const "
212 "DynArr<DoubleAc>& mt2)");
213 long qdim1 = mt1.get_qdim();
214 long qdim2 = mt2.get_qdim();
215 check_econd12(qdim1, !=, qdim2, mcerr);
216 const DynLinArr<long>& qe1 = mt1.get_qel();
217 const DynLinArr<long>& qe2 = mt2.get_qel();
218 check_econd12(qe1, !=, qe2, mcerr);
219 DynArr<DoubleAc> ms(mt2);
220 IterDynArr<DoubleAc> iter(&ms);
221 DoubleAc* at;
222 while ((at = iter.more()) != NULL) {
223 (*at) = (*at) + mt1.acu(iter.get_ncur());
224 }
225 return ms;
226}
227
229 const DynArr<DoubleAc>& mt2) {
230 mfunname("DynArr<DoubleAc> operator-(const DynArr<double>& mt1, const "
231 "DynArr<DoubleAc>& mt2)");
232 long qdim1 = mt1.get_qdim();
233 long qdim2 = mt2.get_qdim();
234 check_econd12(qdim1, !=, qdim2, mcerr);
235 const DynLinArr<long>& qe1 = mt1.get_qel();
236 const DynLinArr<long>& qe2 = mt2.get_qel();
237 check_econd12(qe1, !=, qe2, mcerr);
238 DynArr<DoubleAc> ms(mt2);
239 IterDynArr<DoubleAc> iter(&ms);
240 DoubleAc* at;
241 while ((at = iter.more()) != NULL) {
242 (*at) = -(*at) + mt1.acu(iter.get_ncur());
243 }
244 return ms;
245}
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:313
DoubleAc square(const DoubleAc &f)
Definition: DoubleAc.cpp:324
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
#define mfunname(string)
Definition: FunNameStack.h:67
long get_qdim(void) const
Definition: AbsArr.h:2547
T & acu(long i1)
Definition: AbsArr.h:2098
const DynLinArr< long > & get_qel(void) const
Definition: AbsArr.h:2548
long get_qel(void) const
Definition: AbsArr.h:420
T & acu(long n)
Definition: AbsArr.h:372
const DynLinArr< long > & get_ncur(void) const
Definition: AbsArr.h:2802
T * more(void)
Definition: AbsArr.h:2774
DynLinArr< DoubleAc > operator+(const DynLinArr< DoubleAc > &vc1, const DynLinArr< double > &vc2)
Definition: multiply.cpp:114
DynLinArr< DoubleAc > operator-(const DynLinArr< DoubleAc > &vc1, const DynLinArr< double > &vc2)
Definition: multiply.cpp:128
DoubleAc norm_DynLinArr(const DynLinArr< DoubleAc > &f)
Definition: multiply.cpp:15
DoubleAc normsq_DynLinArr(const DynLinArr< DoubleAc > &f)
Definition: multiply.cpp:26
DynLinArr< DoubleAc > operator*(const DynArr< DoubleAc > &mt, const DynLinArr< double > &vc)
Definition: multiply.cpp:37
#define mcerr
Definition: prstream.h:135