source: ThirdParty/mpqc_open/src/lib/chemistry/qc/intv3/array.cc@ bbc982

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since bbc982 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 10.5 KB
Line 
1//
2// array.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <stdlib.h>
33#include <util/misc/exenv.h>
34#include <chemistry/qc/intv3/array.h>
35
36using namespace std;
37using namespace sc;
38
39static void
40no_storage(const char *msg)
41{
42 ExEnv::errn() << msg << ": ran out of memory" << endl;
43 abort();
44}
45
46////////////////////////////////////////////////////////////////////////////
47
48IntV3Arraydouble2::IntV3Arraydouble2()
49{
50 n1_ = n2_ = 0;
51 data_ = 0;
52}
53
54IntV3Arraydouble2::~IntV3Arraydouble2()
55{
56 for (int i=0; i<n1_; i++) {
57 delete[] data_[i];
58 }
59 delete[] data_;
60}
61
62void
63IntV3Arraydouble2::set_dim(int n1, int n2)
64{
65 n1_ = n1;
66 n2_ = n2;
67 data_ = new double*[n1_];
68 if (data_ == 0) no_storage("IntV3Arraydouble2");
69 for (int i=0; i<n1_; i++) {
70 data_[i] = new double[n2_];
71 if (data_[i] == 0) no_storage("IntV3Arraydouble2");
72 }
73}
74
75void
76IntV3Arraydouble2::print(ostream &o)
77{
78 for (int i=0; i<n1_; i++) {
79 o << "i = " << i << endl;
80 for (int j=0; j<n2_; j++) {
81 o << data_[i][j];
82 }
83 o << endl;
84 }
85}
86
87int
88IntV3Arraydouble2::nbyte() const
89{
90 return n1_ * (sizeof(double*) + n2_ * sizeof(double));
91}
92
93////////////////////////////////////////////////////////////////////////////
94
95IntV3Arraydouble3::IntV3Arraydouble3()
96{
97 n1_ = n2_ = n3_ = 0;
98 data_ = 0;
99}
100
101IntV3Arraydouble3::~IntV3Arraydouble3()
102{
103 for (int i=0; i<n1_; i++) {
104 for (int j=0; j<n2_; j++) {
105 delete[] data_[i][j];
106 }
107 delete[] data_[i];
108 }
109 delete[] data_;
110}
111
112void
113IntV3Arraydouble3::set_dim(int n1, int n2, int n3)
114{
115 n1_ = n1;
116 n2_ = n2;
117 n3_ = n3;
118 data_ = new double**[n1_];
119 if (data_ == 0) no_storage("IntV3Arraydouble3");
120 for (int i=0; i<n1_; i++) {
121 data_[i] = new double*[n2_];
122 if (data_[i] == 0) no_storage("IntV3Arraydouble3");
123 for (int j=0; j<n2_; j++) {
124 data_[i][j] = new double[n3_];
125 if (data_[i][j] == 0) no_storage("IntV3Arraydouble3");
126 }
127 }
128}
129
130void
131IntV3Arraydouble3::print(ostream &o)
132{
133 for (int i=0; i<n1_; i++) {
134 for (int j=0; j<n2_; j++) {
135 o << "i, j = " << i << j << endl;
136 for (int k=0; k<n3_; k++) {
137 o << data_[i][j][k];
138 }
139 }
140 o << endl;
141 }
142}
143
144int
145IntV3Arraydouble3::nbyte() const
146{
147 return n1_*(sizeof(double**) + n2_*(sizeof(double*) + n3_*sizeof(double)));
148}
149
150////////////////////////////////////////////////////////////////////////////
151
152IntV3Arraydoublep2::IntV3Arraydoublep2()
153{
154 n1_ = n2_ = 0;
155 data_ = 0;
156}
157
158IntV3Arraydoublep2::~IntV3Arraydoublep2()
159{
160 for (int i=0; i<n1_; i++) {
161 delete[] data_[i];
162 }
163 delete[] data_;
164}
165
166void
167IntV3Arraydoublep2::set_dim(int n1, int n2)
168{
169 n1_ = n1;
170 n2_ = n2;
171 data_ = new double**[n1_];
172 if (data_ == 0) no_storage("IntV3Arraydoublep2");
173 for (int i=0; i<n1_; i++) {
174 data_[i] = new double*[n2_];
175 if (data_[i] == 0) no_storage("IntV3Arraydoublep2");
176 }
177}
178
179void
180IntV3Arraydoublep2::print(ostream &o)
181{
182 for (int i=0; i<n1_; i++) {
183 o << "i = " << i << endl;
184 for (int j=0; j<n2_; j++) {
185 o << data_[i][j];
186 }
187 o << endl;
188 }
189}
190
191int
192IntV3Arraydoublep2::nbyte() const
193{
194 return n1_*(sizeof(double**)
195 + n2_*(sizeof(double*)));
196}
197
198////////////////////////////////////////////////////////////////////////////
199
200IntV3Arraydoublep3::IntV3Arraydoublep3()
201{
202 n1_ = n2_ = n3_ = 0;
203 data_ = 0;
204}
205
206IntV3Arraydoublep3::~IntV3Arraydoublep3()
207{
208 for (int i=0; i<n1_; i++) {
209 for (int j=0; j<n2_; j++) {
210 delete[] data_[i][j];
211 }
212 delete[] data_[i];
213 }
214 delete[] data_;
215}
216
217void
218IntV3Arraydoublep3::set_dim(int n1, int n2, int n3)
219{
220 n1_ = n1;
221 n2_ = n2;
222 n3_ = n3;
223 data_ = new double***[n1_];
224 if (data_ == 0) no_storage("IntV3Arraydoublep3");
225 for (int i=0; i<n1_; i++) {
226 data_[i] = new double**[n2_];
227 if (data_[i] == 0) no_storage("IntV3Arraydoublep3");
228 for (int j=0; j<n2_; j++) {
229 data_[i][j] = new double*[n3_];
230 if (data_[i][j] == 0) no_storage("IntV3Arraydoublep3");
231 }
232 }
233}
234
235void
236IntV3Arraydoublep3::delete_data()
237{
238 for (int i=0; i<n1_; i++) {
239 double ***datai = data_[i];
240 for (int j=0; j<n2_; j++) {
241 double **dataj = datai[j];
242 for (int k=0; k<n3_; k++) {
243 delete[] dataj[k];
244 }
245 }
246 }
247}
248
249void
250IntV3Arraydoublep3::print(ostream &o)
251{
252 for (int i=0; i<n1_; i++) {
253 for (int j=0; j<n2_; j++) {
254 o << "i, j = " << i << j << endl;
255 for (int k=0; k<n3_; k++) {
256 o << data_[i][j][k];
257 }
258 o << endl;
259 }
260 }
261}
262
263int
264IntV3Arraydoublep3::nbyte() const
265{
266 return n1_*(sizeof(double***)
267 + n2_*(sizeof(double**)
268 + n3_*sizeof(double*)));
269}
270
271////////////////////////////////////////////////////////////////////////////
272
273IntV3Arraydoublep4::IntV3Arraydoublep4()
274{
275 n1_ = n2_ = n3_ = n4_ = 0;
276 data_ = 0;
277}
278
279IntV3Arraydoublep4::~IntV3Arraydoublep4()
280{
281 for (int i=0; i<n1_; i++) {
282 for (int j=0; j<n2_; j++) {
283 for (int k=0; k<n3_; k++) {
284 delete[] data_[i][j][k];
285 }
286 delete[] data_[i][j];
287 }
288 delete[] data_[i];
289 }
290 delete[] data_;
291 data_=0;
292}
293
294void
295IntV3Arraydoublep4::set_dim(int n1, int n2, int n3, int n4)
296{
297 if (data_) {
298 for (int i=0; i<n1_; i++) {
299 for (int j=0; j<n2_; j++) {
300 for (int k=0; k<n3_; k++) {
301 delete[] data_[i][j][k];
302 }
303 delete[] data_[i][j];
304 }
305 delete[] data_[i];
306 }
307 delete[] data_;
308 }
309 n1_ = n1;
310 n2_ = n2;
311 n3_ = n3;
312 n4_ = n4;
313 data_ = new double****[n1_];
314 if (data_ == 0) no_storage("IntV3Arraydoublep4");
315 for (int i=0; i<n1_; i++) {
316 data_[i] = new double***[n2_];
317 if (data_[i] == 0) no_storage("IntV3Arraydoublep4");
318 for (int j=0; j<n2_; j++) {
319 data_[i][j] = new double**[n3_];
320 if (data_[i][j] == 0) no_storage("IntV3Arraydoublep4");
321 for (int k=0; k<n3_ ;k++) {
322 data_[i][j][k] = new double*[n4_];
323 if (data_[i][j][k] == 0) no_storage("IntV3Arraydoublep4");
324 }
325 }
326 }
327}
328
329void
330IntV3Arraydoublep4::print(ostream &o)
331{
332 for (int i=0; i<n1_; i++) {
333 for (int j=0; j<n2_; j++) {
334 for (int k=0; k<n3_; k++) {
335 o << "i, j, k = " << i << j << k << endl;
336 for (int l=0; l<n4_; l++) {
337 o << data_[i][j][k][l];
338 }
339 o << endl;
340 }
341 }
342 }
343}
344
345int
346IntV3Arraydoublep4::nbyte() const
347{
348 return n1_*(sizeof(double****)
349 + n2_*(sizeof(double***)
350 + n3_*(sizeof(double**)
351 + n4_*sizeof(double*))));
352}
353
354////////////////////////////////////////////////////////////////////////////
355
356IntV3Arrayint3::IntV3Arrayint3()
357{
358 n1_ = n2_ = n3_ = 0;
359 data_ = 0;
360}
361
362IntV3Arrayint3::~IntV3Arrayint3()
363{
364 for (int i=0; i<n1_; i++) {
365 for (int j=0; j<n2_; j++) {
366 delete[] data_[i][j];
367 }
368 delete[] data_[i];
369 }
370 delete[] data_;
371}
372
373void
374IntV3Arrayint3::set_dim(int n1, int n2, int n3)
375{
376 n1_ = n1;
377 n2_ = n2;
378 n3_ = n3;
379 data_ = new int**[n1_];
380 if (data_ == 0) no_storage("IntV3Arrayint3");
381 for (int i=0; i<n1_; i++) {
382 data_[i] = new int*[n2_];
383 if (data_[i] == 0) no_storage("IntV3Arrayint3");
384 for (int j=0; j<n2_; j++) {
385 data_[i][j] = new int[n3_];
386 if (data_[i][j] == 0) no_storage("IntV3Arrayint3");
387 }
388 }
389}
390
391void
392IntV3Arrayint3::print(ostream &o)
393{
394 for (int i=0; i<n1_; i++) {
395 for (int j=0; j<n2_; j++) {
396 o << "i, j = " << i << j << endl;
397 for (int k=0; k<n3_; k++) {
398 o << data_[i][j][k];
399 }
400 o << endl;
401 }
402 }
403}
404
405int
406IntV3Arrayint3::nbyte() const
407{
408 return n1_*(sizeof(int**)
409 + n2_*(sizeof(int*)
410 + n3_*sizeof(int)));
411}
412
413////////////////////////////////////////////////////////////////////////////
414
415IntV3Arrayint4::IntV3Arrayint4()
416{
417 n1_ = n2_ = n3_ = n4_ = 0;
418 data_ = 0;
419}
420
421IntV3Arrayint4::~IntV3Arrayint4()
422{
423 for (int i=0; i<n1_; i++) {
424 for (int j=0; j<n2_; j++) {
425 for (int k=0; k<n3_; k++) {
426 delete[] data_[i][j][k];
427 }
428 delete[] data_[i][j];
429 }
430 delete[] data_[i];
431 }
432 delete[] data_;
433}
434
435void
436IntV3Arrayint4::set_dim(int n1, int n2, int n3, int n4)
437{
438 n1_ = n1;
439 n2_ = n2;
440 n3_ = n3;
441 n4_ = n4;
442 data_ = new int***[n1_];
443 if (data_ == 0) no_storage("IntV3Arrayint4");
444 for (int i=0; i<n1_; i++) {
445 data_[i] = new int**[n2_];
446 if (data_[i] == 0) no_storage("IntV3Arrayint4");
447 for (int j=0; j<n2_; j++) {
448 data_[i][j] = new int*[n3_];
449 if (data_[i][j] == 0) no_storage("IntV3Arrayint4");
450 for (int k=0; k<n3_ ;k++) {
451 data_[i][j][k] = new int[n4_];
452 if (data_[i][j][k] == 0) no_storage("IntV3Arrayint4");
453 }
454 }
455 }
456}
457
458void
459IntV3Arrayint4::print(ostream &o)
460{
461 for (int i=0; i<n1_; i++) {
462 for (int j=0; j<n2_; j++) {
463 for (int k=0; k<n3_; k++) {
464 o << "i, j, k = " << i << j << k << endl;
465 for (int l=0; l<n4_; l++) {
466 o << data_[i][j][k][l];
467 }
468 o << endl;
469 }
470 }
471 }
472}
473
474int
475IntV3Arrayint4::nbyte() const
476{
477 return n1_*(sizeof(int***)
478 + n2_*(sizeof(int**)
479 + n3_*(sizeof(int*)
480 + n4_*sizeof(int))));
481}
482
483/////////////////////////////////////////////////////////////////////////////
484
485// Local Variables:
486// mode: c++
487// c-file-style: "CLJ"
488// End:
Note: See TracBrowser for help on using the repository browser.