Skip to content

Commit 368aff7

Browse files
author
Roberto Di Remigio
committed
Sphere is now a POD
1 parent 0f0f86e commit 368aff7

File tree

12 files changed

+58
-72
lines changed

12 files changed

+58
-72
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
- A runtime check to ensure that all atoms have a nonzero radius.
66
API kills program execution if this is the case.
77
- An API function to retrieve the areas/weights of the cavity finite elements.
8-
The values in the returned array are in Bohr^2.
9-
Addresses feature request from @shofener (Issue #13)
8+
The values in the returned array are in Bohr^2. Addresses feature request from @shofener (Issue #13)
109

1110
### Changed
1211
- GePolCavity learnt to print also the list of spheres used to generate
1312
the cavity.
1413
- Different internal handling of conversion factors from Bohr to Angstrom.
1514
- CMake minimum required version is 2.8.10
16-
- Atom and Solvent are now PODs. The radii and solvent lists are free functions.
15+
- Atom, Solvent and Sphere are now PODs. The radii and solvent lists are free functions.
1716
- `PCMSOLVER_ERROR ` kills program execution when an error arises but does
1817
not use C++ exceptions.
1918
- `include`-s are now specified on a per-directory basis (see programmers' manual

doc/code-reference/helper-classes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ Input
1515

1616
Sphere
1717
------
18-
.. doxygenclass:: Sphere
18+
.. doxygenstruct:: Sphere
1919
:project: PCMSolver
2020
:members:
2121
:protected-members:
2222
:private-members:
2323

2424
Atom
2525
----
26-
.. doxygenclass:: Atom
26+
.. doxygenstruct:: Atom
2727
:project: PCMSolver
2828
:members:
2929
:protected-members:
@@ -39,7 +39,7 @@ Molecule
3939

4040
Solvent
4141
-------
42-
.. doxygenclass:: Solvent
42+
.. doxygenstruct:: Solvent
4343
:project: PCMSolver
4444
:members:
4545
:protected-members:

src/bi_operators/CollocationIntegrator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct CollocationIntegrator
175175
for (size_t i = 0; i < mat_size; ++i) {
176176
// Fill diagonal
177177
double area = e[i].area();
178-
double radius = e[i].sphere().radius();
178+
double radius = e[i].sphere().radius;
179179
// Diagonal of S inside the cavity
180180
double Sii_I = factor_ * std::sqrt(4 * M_PI / area);
181181
// Diagonal of D inside the cavity

src/bi_operators/IntegratorHelperFunctions.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ inline double SI(double factor, double eps, const Element & el)
7272
*/
7373
inline double DI(double factor, const Element & el)
7474
{
75-
return (-factor * std::sqrt(M_PI / el.area()) * 1.0 / el.sphere().radius());
75+
return (-factor * std::sqrt(M_PI / el.area()) * 1.0 / el.sphere().radius);
7676
}
7777

7878
/*! Returns matrix representation of the single layer operator by collocation
@@ -177,7 +177,7 @@ double integrateS(const KernelS & F, const Element & e)
177177
double thetaLower = theta[numb[i]];
178178
double thetaUpper = theta[numb[i+1]];
179179
double thetaMax = 0.0;
180-
Eigen::Vector3d oc = (arcs.col(i) - sph.center()) / sph.radius();
180+
Eigen::Vector3d oc = (arcs.col(i) - sph.center) / sph.radius;
181181
double oc_norm = oc.norm();
182182
double oc_norm2 = std::pow(oc_norm, 2);
183183
for (int j = 0; j < upper_phi; ++j) { // Loop on Gaussian points: phi integration
@@ -225,7 +225,7 @@ double integrateS(const KernelS & F, const Element & e)
225225
+ normal(2) * (cos_th - 1.0);
226226
double value = F(point,
227227
Eigen::Vector3d::Zero()); // Evaluate integrand at Gaussian point
228-
scratch += std::pow(sph.radius(), 2) * value * sin_th * thetaA * thetaRule.weight(l);
228+
scratch += std::pow(sph.radius, 2) * value * sin_th * thetaA * thetaRule.weight(l);
229229
}
230230
}
231231
result += scratch * phiA * phiRule.weight(j);
@@ -290,7 +290,7 @@ double integrateD(const KernelD & F, const Element & e)
290290
double thetaLower = theta[numb[i]];
291291
double thetaUpper = theta[numb[i+1]];
292292
double thetaMax = 0.0;
293-
Eigen::Vector3d oc = (arcs.col(i) - sph.center()) / sph.radius();
293+
Eigen::Vector3d oc = (arcs.col(i) - sph.center) / sph.radius;
294294
double oc_norm = oc.norm();
295295
double oc_norm2 = std::pow(oc_norm, 2);
296296
for (int j = 0; j < upper_phi; ++j) { // Loop on Gaussian points: phi integration
@@ -338,7 +338,7 @@ double integrateD(const KernelD & F, const Element & e)
338338
double value = F(e.normal(),
339339
Eigen::Vector3d::Zero(),
340340
point); // Evaluate integrand at Gaussian point
341-
scratch += std::pow(sph.radius(), 2) * value * sin_theta * thetaA * thetaRule.weight(l);
341+
scratch += std::pow(sph.radius, 2) * value * sin_theta * thetaA * thetaRule.weight(l);
342342
}
343343
}
344344
result += scratch * phiA * phiRule.weight(j);

src/bi_operators/PurisimaIntegrator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct PurisimaIntegrator
186186
for (size_t i = 0; i < mat_size; ++i) {
187187
// Fill diagonal
188188
double area = e[i].area();
189-
double radius = e[i].sphere().radius();
189+
double radius = e[i].sphere().radius;
190190
// Diagonal of S inside the cavity
191191
double Sii_I = factor_ * std::sqrt(4 * M_PI / area);
192192
// Diagonal of D inside the cavity

src/cavity/Element.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ void Element::spherical_polygon(Eigen::Vector3d & t_, Eigen::Vector3d & b_,
4242
std::vector<double> & theta, std::vector<double> & phi,
4343
std::vector<double> & phinumb, std::vector<int> & numb) const
4444
{
45-
Eigen::Vector3d sph_center = sphere_.center();
46-
double radius = sphere_.radius();
45+
Eigen::Vector3d sph_center = sphere_.center;
46+
double radius = sphere_.radius;
4747
// Calculate the azimuthal and polar angles for the tessera vertices:
4848
// we use the normal, tangent and bitangent as a local reference frame
4949
for (int i = 0; i < nVertices_; ++i) {

src/utils/Molecule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Molecule::Molecule(const std::vector<Sphere> & sph)
8080
masses_.resize(nAtoms_);
8181
geometry_.resize(Eigen::NoChange, nAtoms_);
8282
for (size_t i = 0; i < nAtoms_; ++i) {
83-
masses_(i) = spheres_[i].radius();
84-
geometry_.col(i) = spheres_[i].center();
83+
masses_(i) = spheres_[i].radius;
84+
geometry_.col(i) = spheres_[i].center;
8585
double charge = charges_(i);
8686
double mass = masses_(i);
8787
atoms_.push_back( Atom("Dummy", "Du", charge, mass, mass, geometry_.col(i)) );

src/utils/Solvent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ struct Solvent
5656
double epsDynamic;
5757
/*! Radius of the spherical probe mimicking the solvent, in Angstrom */
5858
double probeRadius;
59-
friend std::ostream & operator<<(std::ostream & os, Solvent & solvent);
6059
};
6160

61+
std::ostream & operator<<(std::ostream & os, Solvent & solvent);
6262

6363
/*! \brief typedef for the map between solvent name and Solvent object. */
6464
typedef std::map<std::string, Solvent> SolventMap;

src/utils/Sphere.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013-2015 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
7+
*
88
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.readthedocs.org/>
2323
*/
@@ -32,10 +32,22 @@
3232

3333
#include <Eigen/Core>
3434

35-
std::ostream & Sphere::printObject(std::ostream & os)
35+
std::ostream & operator<<(std::ostream & os, Sphere & sph)
3636
{
37-
os << "Sphere radius " << radius_ << std::endl;
38-
os << "Sphere center\n" << center_;
37+
os << "Sphere radius " << sph.radius << std::endl;
38+
os << "Sphere center\n" << sph.center;
3939

4040
return os;
4141
}
42+
43+
void transfer_spheres(const std::vector<Sphere> & spheres,
44+
Eigen::Matrix3Xd & sphereCenter, Eigen::VectorXd & sphereRadius)
45+
{
46+
size_t nSpheres = spheres.size();
47+
sphereCenter.resize(Eigen::NoChange, nSpheres);
48+
sphereRadius.resize(nSpheres);
49+
for (size_t i = 0; i < nSpheres; ++i) {
50+
sphereCenter.col(i) = spheres[i].center;
51+
sphereRadius(i) = spheres[i].radius;
52+
}
53+
}

src/utils/Sphere.hpp

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013-2015 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
7+
*
88
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.readthedocs.org/>
2323
*/
@@ -35,42 +35,26 @@
3535
#include <Eigen/Core>
3636

3737
/*! \file Sphere.hpp
38-
* \class Sphere
39-
* \brief Class describing a sphere.
38+
* \struct Sphere
39+
* \brief POD describing a sphere.
4040
* \author Roberto Di Remigio
41-
* \date 2011
41+
* \date 2011, 2016
4242
*/
4343

44-
class Sphere
44+
struct Sphere
4545
{
46-
public:
4746
Sphere() {}
48-
Sphere(const Eigen::Vector3d & center, double radius,
49-
const std::string & colour = "Violet" )
50-
: center_(center), radius_(radius), colour_(colour) {}
47+
Sphere(const Eigen::Vector3d & c, double r) : center(c), radius(r) {}
5148
~Sphere() {}
52-
double radius() const { return radius_; }
53-
void radius(double r) { radius_ = r; }
54-
const Eigen::Vector3d & center() const { return center_; }
55-
double center(int i) const { return center_(i); }
56-
void center(Eigen::Vector3d & coord) { center_ = coord; }
57-
const std::string & colour() const { return colour_; }
58-
void colour(std::string & col) { colour_ = col; }
59-
6049
/// Scale sphere to other units
61-
void scale(double scaling) { center_ *= scaling; radius_ *= scaling; }
62-
63-
friend std::ostream& operator<<(std::ostream & os, Sphere & sph) {
64-
return sph.printObject(os);
65-
}
50+
void scale(double scaling) { center *= scaling; radius *= scaling; }
51+
Eigen::Vector3d center;
52+
double radius;
6653
EIGEN_MAKE_ALIGNED_OPERATOR_NEW /* See http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html */
67-
private:
68-
Eigen::Vector3d center_;
69-
double radius_;
70-
std::string colour_;
71-
std::ostream & printObject(std::ostream & os);
7254
};
7355

56+
std::ostream& operator<<(std::ostream & os, Sphere & sph);
57+
7458
/*! \fn inline void transfer_spheres(const std::vector<Sphere> & spheres, Eigen::Matrix3Xd & sphereCenter, Eigen::VectorXd & sphereRadius)
7559
* \brief Transfer info from std::vector<Sphere> to Eigen objects.
7660
* \param[in] spheres list of spheres as std::vector<Sphere>
@@ -79,16 +63,7 @@ class Sphere
7963
*
8064
* This is used in the Cavity.hpp constructor
8165
*/
82-
inline void transfer_spheres(const std::vector<Sphere> & spheres,
83-
Eigen::Matrix3Xd & sphereCenter, Eigen::VectorXd & sphereRadius)
84-
{
85-
size_t nSpheres = spheres.size();
86-
sphereCenter.resize(Eigen::NoChange, nSpheres);
87-
sphereRadius.resize(nSpheres);
88-
for (size_t i = 0; i < nSpheres; ++i) {
89-
sphereCenter.col(i) = spheres[i].center();
90-
sphereRadius(i) = spheres[i].radius();
91-
}
92-
}
66+
void transfer_spheres(const std::vector<Sphere> & spheres,
67+
Eigen::Matrix3Xd & sphereCenter, Eigen::VectorXd & sphereRadius);
9368

9469
#endif // SPHERE_HPP

0 commit comments

Comments
 (0)