1 | //
|
---|
2 | // twobodygrid.cc
|
---|
3 | //
|
---|
4 | // Copyright (C) 2004 Edward Valeev
|
---|
5 | //
|
---|
6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
|
---|
7 | // Maintainer: EV
|
---|
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 __GNUG__
|
---|
29 | #pragma implementation
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <cmath>
|
---|
33 | #include <stdexcept>
|
---|
34 | #include <util/misc/formio.h>
|
---|
35 | #include <chemistry/qc/mbptr12/twobodygrid.h>
|
---|
36 |
|
---|
37 | using namespace std;
|
---|
38 | using namespace sc;
|
---|
39 |
|
---|
40 | /*---------------
|
---|
41 | TwoBodyGrid
|
---|
42 | ---------------*/
|
---|
43 | static ClassDesc TwoBodyGrid_cd(
|
---|
44 | typeid(TwoBodyGrid),"TwoBodyGrid",1,"virtual public SavableState",
|
---|
45 | 0, create<TwoBodyGrid>, create<TwoBodyGrid>);
|
---|
46 |
|
---|
47 | TwoBodyGrid::TwoBodyGrid(StateIn& si) : SavableState(si), O_(0.0)
|
---|
48 | {
|
---|
49 | si.get(name_);
|
---|
50 | int npts; si.get(npts); r1_.resize(npts); r2_.resize(npts);
|
---|
51 | for(int pt=0; pt<npts; pt++) {
|
---|
52 | si.get(r1_[pt].x());
|
---|
53 | si.get(r1_[pt].y());
|
---|
54 | si.get(r1_[pt].z());
|
---|
55 | }
|
---|
56 | for(int pt=0; pt<npts; pt++) {
|
---|
57 | si.get(r2_[pt].x());
|
---|
58 | si.get(r2_[pt].y());
|
---|
59 | si.get(r2_[pt].z());
|
---|
60 | }
|
---|
61 | si.get(O_.x());
|
---|
62 | si.get(O_.y());
|
---|
63 | si.get(O_.z());
|
---|
64 | }
|
---|
65 |
|
---|
66 | TwoBodyGrid::TwoBodyGrid(const Ref<KeyVal>& keyval)
|
---|
67 | {
|
---|
68 | name_ = keyval->stringvalue("name",KeyValValuestring("two-body grid"));
|
---|
69 |
|
---|
70 | // Default is to assume Cartesian coordinates
|
---|
71 | bool polar = keyval->booleanvalue("polar",KeyValValueboolean((int)false));
|
---|
72 |
|
---|
73 | bool O_is_given = keyval->exists("origin");
|
---|
74 | if (O_is_given) {
|
---|
75 | const int dim = keyval->count("origin");
|
---|
76 | if (dim != 3)
|
---|
77 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword origin must be an array of 3 elements");
|
---|
78 | for(int xyz=0; xyz<3; xyz++)
|
---|
79 | O_.elem(xyz) = keyval->doublevalue("origin",xyz);
|
---|
80 | }
|
---|
81 | else
|
---|
82 | O_ = 0.0;
|
---|
83 |
|
---|
84 | bool r1_is_given = keyval->exists("r1");
|
---|
85 | bool r2_is_given = keyval->exists("r2");
|
---|
86 | if (r1_is_given == false)
|
---|
87 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r1 must be given");
|
---|
88 | if (r2_is_given == false)
|
---|
89 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r2 must be given");
|
---|
90 |
|
---|
91 | const int nelem1 = keyval->count("r1");
|
---|
92 | const int nelem2 = keyval->count("r2");
|
---|
93 | if (nelem1 == 0)
|
---|
94 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r1 must be an array of 3-dimensional vectors");
|
---|
95 | if (nelem2 == 0)
|
---|
96 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r2 must be an array of 3-dimensional vectors");
|
---|
97 | if (nelem1 != nelem2 && nelem1 != 1 && nelem2 != 1)
|
---|
98 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword arrays r1 and r2 must have the same number of elements, \
|
---|
99 | otherwise one of the arrays must contain one element only");
|
---|
100 |
|
---|
101 | const int nelem = (nelem1 > nelem2) ? nelem1 : nelem2;
|
---|
102 |
|
---|
103 | r1_.resize(nelem);
|
---|
104 | r2_.resize(nelem);
|
---|
105 |
|
---|
106 | if (nelem1 == 1) {
|
---|
107 | SCVector3 R1;
|
---|
108 | const int dim = keyval->count("r1",0);
|
---|
109 | if (dim != 3)
|
---|
110 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r1:0 must be an array of 3 elements");
|
---|
111 | for(int xyz=0; xyz<3; xyz++)
|
---|
112 | R1.elem(xyz) = keyval->doublevalue("r1",0,xyz);
|
---|
113 |
|
---|
114 | if (polar)
|
---|
115 | for(int i=0; i<nelem; i++) {
|
---|
116 | r1_[i].spherical_to_cartesian(R1);
|
---|
117 | r1_[i] += O_;
|
---|
118 | }
|
---|
119 | else
|
---|
120 | for(int i=0; i<nelem; i++)
|
---|
121 | r1_[i] = R1 + O_;
|
---|
122 | }
|
---|
123 | else {
|
---|
124 | for(int i=0; i<nelem; i++) {
|
---|
125 | SCVector3 R1;
|
---|
126 | const int dim = keyval->count("r1",i);
|
---|
127 | if (dim != 3) {
|
---|
128 | std::string errmsg("TwoBodyGrid::TwoBodyGrid() -- keyword r1:");
|
---|
129 | errmsg += i + "must be an array of 3 elements";
|
---|
130 | throw std::runtime_error(errmsg.c_str());
|
---|
131 | }
|
---|
132 | for(int xyz=0; xyz<3; xyz++)
|
---|
133 | R1.elem(xyz) = keyval->doublevalue("r1",i,xyz);
|
---|
134 | if (polar) {
|
---|
135 | r1_[i].spherical_to_cartesian(R1);
|
---|
136 | r1_[i] += O_;
|
---|
137 | }
|
---|
138 | else
|
---|
139 | r1_[i] = R1 + O_;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (nelem2 == 1) {
|
---|
144 | SCVector3 R2;
|
---|
145 | const int dim = keyval->count("r2",0);
|
---|
146 | if (dim != 3)
|
---|
147 | throw std::runtime_error("TwoBodyGrid::TwoBodyGrid() -- keyword r2:0 must be an array of 3 elements");
|
---|
148 | for(int xyz=0; xyz<3; xyz++)
|
---|
149 | R2.elem(xyz) = keyval->doublevalue("r2",0,xyz);
|
---|
150 |
|
---|
151 | if (polar)
|
---|
152 | for(int i=0; i<nelem; i++) {
|
---|
153 | r2_[i].spherical_to_cartesian(R2);
|
---|
154 | r2_[i] += O_;
|
---|
155 | }
|
---|
156 | else
|
---|
157 | for(int i=0; i<nelem; i++)
|
---|
158 | r2_[i] = R2 + O_;
|
---|
159 | }
|
---|
160 | else {
|
---|
161 | for(int i=0; i<nelem; i++) {
|
---|
162 | SCVector3 R2;
|
---|
163 | const int dim = keyval->count("r2",i);
|
---|
164 | if (dim != 3) {
|
---|
165 | std::string errmsg("TwoBodyGrid::TwoBodyGrid() -- keyword r2:");
|
---|
166 | errmsg += i + "must be an array of 3 elements";
|
---|
167 | throw std::runtime_error(errmsg.c_str());
|
---|
168 | }
|
---|
169 | for(int xyz=0; xyz<3; xyz++)
|
---|
170 | R2.elem(xyz) = keyval->doublevalue("r2",i,xyz);
|
---|
171 | if (polar) {
|
---|
172 | r2_[i].spherical_to_cartesian(R2);
|
---|
173 | r2_[i] += O_;
|
---|
174 | }
|
---|
175 | else
|
---|
176 | r2_[i] = R2 + O_;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | TwoBodyGrid::~TwoBodyGrid()
|
---|
182 | {
|
---|
183 | }
|
---|
184 |
|
---|
185 | void
|
---|
186 | TwoBodyGrid::save_data_state(StateOut& so)
|
---|
187 | {
|
---|
188 | so.put(name_);
|
---|
189 | const int npts = r1_.size();
|
---|
190 | so.put(npts);
|
---|
191 | for(int pt=0; pt<npts; pt++) {
|
---|
192 | so.put(r1_[pt].x());
|
---|
193 | so.put(r1_[pt].y());
|
---|
194 | so.put(r1_[pt].z());
|
---|
195 | }
|
---|
196 | for(int pt=0; pt<npts; pt++) {
|
---|
197 | so.put(r2_[pt].x());
|
---|
198 | so.put(r2_[pt].y());
|
---|
199 | so.put(r2_[pt].z());
|
---|
200 | }
|
---|
201 | so.put(O_.x());
|
---|
202 | so.put(O_.y());
|
---|
203 | so.put(O_.z());
|
---|
204 | }
|
---|
205 |
|
---|
206 | const std::string&
|
---|
207 | TwoBodyGrid::name() const { return name_; }
|
---|
208 |
|
---|
209 | int
|
---|
210 | TwoBodyGrid::nelem() const { return r1_.size(); }
|
---|
211 |
|
---|
212 | const SCVector3&
|
---|
213 | TwoBodyGrid::origin() const { return O_; }
|
---|
214 |
|
---|
215 |
|
---|
216 | SCVector3
|
---|
217 | TwoBodyGrid::xyz1(int i, const SCVector3& O) const
|
---|
218 | {
|
---|
219 | return r1_[i] - O;
|
---|
220 | }
|
---|
221 |
|
---|
222 | SCVector3
|
---|
223 | TwoBodyGrid::xyz2(int i, const SCVector3& O) const
|
---|
224 | {
|
---|
225 | return r2_[i] - O;
|
---|
226 | }
|
---|
227 |
|
---|
228 | SCVector3
|
---|
229 | TwoBodyGrid::rtp1(int i, const SCVector3& O) const
|
---|
230 | {
|
---|
231 | SCVector3 RO = r1_[i] - O;
|
---|
232 | double r = RO.norm();
|
---|
233 | double theta = acos(RO.z()/r);
|
---|
234 | double phi = acos(RO.x()/(r*sin(theta)));
|
---|
235 | return SCVector3(r,theta,phi);
|
---|
236 | }
|
---|
237 |
|
---|
238 | SCVector3
|
---|
239 | TwoBodyGrid::rtp2(int i, const SCVector3& O) const
|
---|
240 | {
|
---|
241 | SCVector3 RO = r2_[i] - O;
|
---|
242 | double r = RO.norm();
|
---|
243 | double theta = acos(RO.z()/r);
|
---|
244 | double phi = acos(RO.x()/(r*sin(theta)));
|
---|
245 | return SCVector3(r,theta,phi);
|
---|
246 | }
|
---|
247 |
|
---|
248 | void
|
---|
249 | TwoBodyGrid::print(std::ostream& os) const
|
---|
250 | {
|
---|
251 | }
|
---|
252 |
|
---|
253 | /////////////////////////////////////////////////////////////////////////////
|
---|
254 |
|
---|
255 | // Local Variables:
|
---|
256 | // mode: c++
|
---|
257 | // c-file-style: "CLJ-CONDENSED"
|
---|
258 | // End:
|
---|