Skip to content

Commit 1712178

Browse files
committed
Refactor Green's functions, boundary integral operators and solvers
Disentangle design of Green's functions from that of the boundary integral operators and adapt solvers accordingly. The boundary integral operator is no longer implemented as a Visitor. This has two advantages: 1. It is no longer a template parameter to the Green's functions 2. It doesn't need to know about internal details of the Green's functions. The boundary integral operator appears now as an explicit argument to the solvers' `buildSystemMatrix` function.
1 parent 9fcd242 commit 1712178

File tree

82 files changed

+7696
-7320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+7696
-7320
lines changed

CHANGELOG.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
non compliant. The hook generates a patch and shows the command needed to
1313
apply it.
1414
_NOT recommended_ The hook can be skipped by passing the `--no-verify` option to `git commit`
15-
- A pre-commit hook in `.githooks/pre-commit-license-maintainer` checking the license headers.
16-
**BREAKING CHANGE** Perl5 is needed to work on the code.
17-
The hook is based on this [project](https://github.com/NitorCreations/license-maintainer)
18-
and is configured based on the `.gitattributes` file.
19-
The list of authors is automatically extracted from the `license.author`
20-
field in `.git/config`. This can either be modified by hand or by invoking
21-
`git config license.author="list-of-authors"`.
22-
The hook will check the license headers, amend them where possible and abort
23-
where not possible, showing the commands needed to update the license.
24-
_NOT recommended_ The hook can be skipped by passing the `--no-verify` option to `git commit`
2515
- An `UNUSED` preprocessor macro to mark arguments as unused.
2616
- An `UNUSED_FUNCTION` preprocessor macro to mark functions as unused.
2717

2818
### Changed
2919

20+
- The Green's function, solver and boundary integral operator classes have been
21+
radically redesigned. This avoids coupling between integrators and Green's
22+
function that existed in the previous design.
23+
See the [Green's function code
24+
reference](http://pcmsolver.readthedocs.io/en/latest/code-reference/greens-functions.html)
25+
for a more detailed explanation.
26+
3027
### Deprecated
3128

3229
### Removed

doc/code-reference/greens-functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ generic Factory class.
1313

1414
IGreensFunction
1515
---------------
16+
1617
.. doxygenclass:: IGreensFunction
1718
:project: PCMSolver
1819
:members:

doc/programmers/documentation.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ as extensive as for reStructuredText, see `these comments
2525
<https://blog.readthedocs.com/adding-markdown-support/>`_ Follow the guidelines
2626
in :cite:`Wilson2014` regarding what to document.
2727

28+
Documeting methods in derived classes
29+
-------------------------------------
30+
31+
Virtual methods should only be documented in the base classes.
32+
This avoids unnecessary verbosity and conforms to the principle: "Document
33+
_what_, not _how_" :cite:`Wilson2014`
34+
If you feel the _how_ needs to be explicitly documented, add some notes in the
35+
appropriate ``.rst`` file.
36+
2837
How does this work?
2938
-------------------
3039

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* PCMSolver, an API for the Polarizable Continuum Model
3+
* Copyright (C) 2016 Roberto Di Remigio, Luca Frediani and collaborators.
4+
*
5+
* This file is part of PCMSolver.
6+
*
7+
* PCMSolver is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* PCMSolver is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* For information on the complete list of contributors to the
21+
* PCMSolver API, see: <http://pcmsolver.readthedocs.io/>
22+
*/
23+
24+
#ifndef BIOPERATORDATA_HPP
25+
#define BIOPERATORDATA_HPP
26+
27+
#include "Config.hpp"
28+
29+
/*! @struct biOperatorData
30+
* @brief Contains all data defined from user input to set up the integrators
31+
*/
32+
33+
struct biOperatorData {
34+
/*! Scaling for the diagonal of the approximate collocation matrices */
35+
double scaling;
36+
/*! Whether the structure was initialized with user input or not */
37+
bool empty;
38+
39+
biOperatorData() { empty = true; }
40+
biOperatorData(double s) : scaling(s) { empty = false; }
41+
};
42+
43+
#endif // BIOPERATORDATA_HPP
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* PCMSolver, an API for the Polarizable Continuum Model
3+
* Copyright (C) 2016 Roberto Di Remigio, Luca Frediani and collaborators.
4+
*
5+
* This file is part of PCMSolver.
6+
*
7+
* PCMSolver is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* PCMSolver is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* For information on the complete list of contributors to the
21+
* PCMSolver API, see: <http://pcmsolver.readthedocs.io/>
22+
*/
23+
24+
#include "BoundaryIntegralOperator.hpp"
25+
26+
#include "Config.hpp"
27+
28+
#include <Eigen/Core>
29+
30+
#include "cavity/Cavity.hpp"
31+
#include "green/IGreensFunction.hpp"
32+
#include "utils/MathUtils.hpp"
33+
34+
Eigen::MatrixXd BoundaryIntegralOperator::computeS(
35+
const Cavity & cav, const IGreensFunction & gf) const {
36+
Eigen::MatrixXd biop = computeS_impl(cav.elements(), gf);
37+
// Perform symmetry blocking
38+
// The total size of the cavity
39+
PCMSolverIndex cavitySize = cav.size();
40+
// The number of irreps in the group
41+
int nrBlocks = cav.pointGroup().nrIrrep();
42+
// The size of the irreducible portion of the cavity
43+
int dimBlock = cav.irreducible_size();
44+
if (cav.pointGroup().nrGenerators() != 0) {
45+
TIMER_ON("Symmetry blocking");
46+
symmetryBlocking(biop, cavitySize, dimBlock, nrBlocks);
47+
TIMER_OFF("Symmetry blocking");
48+
}
49+
return biop;
50+
}
51+
52+
Eigen::MatrixXd BoundaryIntegralOperator::computeD(
53+
const Cavity & cav, const IGreensFunction & gf) const {
54+
Eigen::MatrixXd biop = computeD_impl(cav.elements(), gf);
55+
// Perform symmetry blocking
56+
// The total size of the cavity
57+
PCMSolverIndex cavitySize = cav.size();
58+
// The number of irreps in the group
59+
int nrBlocks = cav.pointGroup().nrIrrep();
60+
// The size of the irreducible portion of the cavity
61+
int dimBlock = cav.irreducible_size();
62+
if (cav.pointGroup().nrGenerators() != 0) {
63+
TIMER_ON("Symmetry blocking");
64+
symmetryBlocking(biop, cavitySize, dimBlock, nrBlocks);
65+
TIMER_OFF("Symmetry blocking");
66+
}
67+
return biop;
68+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* PCMSolver, an API for the Polarizable Continuum Model
3+
* Copyright (C) 2016 Roberto Di Remigio, Luca Frediani and collaborators.
4+
*
5+
* This file is part of PCMSolver.
6+
*
7+
* PCMSolver is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* PCMSolver is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* For information on the complete list of contributors to the
21+
* PCMSolver API, see: <http://pcmsolver.readthedocs.io/>
22+
*/
23+
24+
#ifndef BOUNDARYINTEGRALOPERATORS_HPP
25+
#define BOUNDARYINTEGRALOPERATORS_HPP
26+
27+
#include <vector>
28+
29+
#include "Config.hpp"
30+
31+
#include <Eigen/Core>
32+
33+
class Cavity;
34+
class Element;
35+
class IGreensFunction;
36+
37+
class BoundaryIntegralOperator {
38+
public:
39+
virtual ~BoundaryIntegralOperator() {}
40+
Eigen::MatrixXd computeS(const Cavity & cav, const IGreensFunction & gf) const;
41+
Eigen::MatrixXd computeD(const Cavity & cav, const IGreensFunction & gf) const;
42+
43+
private:
44+
virtual Eigen::MatrixXd computeS_impl(const std::vector<Element> & elems,
45+
const IGreensFunction & gf) const = 0;
46+
virtual Eigen::MatrixXd computeD_impl(const std::vector<Element> & elems,
47+
const IGreensFunction & gf) const = 0;
48+
};
49+
50+
#endif // BOUNDARYINTEGRALOPERATORS_HPP

src/bi_operators/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# List of headers
2-
list(APPEND headers_list CollocationIntegrator.hpp IntegratorForward.hpp IntegratorHelperFunctions.hpp IntegratorTypes.hpp NumericalIntegrator.hpp PurisimaIntegrator.hpp)
2+
list(APPEND headers_list BIOperatorData.hpp BoundaryIntegralOperator.hpp Collocation.hpp Purisima.hpp Numerical.hpp)
33

44
# List of sources
5-
list(APPEND sources_list )
5+
list(APPEND sources_list BoundaryIntegralOperator.cpp Collocation.cpp Purisima.cpp Numerical.cpp)
66

77
add_library(bi_operators OBJECT ${headers_list} ${sources_list})
88
set_target_properties(bi_operators PROPERTIES POSITION_INDEPENDENT_CODE 1 )

src/bi_operators/Collocation.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* PCMSolver, an API for the Polarizable Continuum Model
3+
* Copyright (C) 2016 Roberto Di Remigio, Luca Frediani and collaborators.
4+
*
5+
* This file is part of PCMSolver.
6+
*
7+
* PCMSolver is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* PCMSolver is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* For information on the complete list of contributors to the
21+
* PCMSolver API, see: <http://pcmsolver.readthedocs.io/>
22+
*/
23+
24+
#include "Collocation.hpp"
25+
26+
#include "Config.hpp"
27+
28+
#include <Eigen/Core>
29+
30+
#include "cavity/Element.hpp"
31+
#include "green/IGreensFunction.hpp"
32+
#include "BIOperatorData.hpp"
33+
#include "utils/Factory.hpp"
34+
35+
namespace integrator {
36+
Collocation::Collocation() : factor_(1.07) {}
37+
38+
Collocation::Collocation(double fac) : factor_(fac) {}
39+
40+
Eigen::MatrixXd Collocation::computeS_impl(const std::vector<Element> & elems,
41+
const IGreensFunction & gf) const {
42+
PCMSolverIndex cavitySize = elems.size();
43+
Eigen::MatrixXd S = Eigen::MatrixXd::Zero(cavitySize, cavitySize);
44+
for (PCMSolverIndex i = 0; i < cavitySize; ++i) {
45+
Element source = elems[i];
46+
S(i, i) = gf.singleLayer(source, factor_);
47+
for (PCMSolverIndex j = 0; j < cavitySize; ++j) {
48+
Element probe = elems[j];
49+
if (i != j)
50+
S(i, j) = gf.kernelS(source.center(), probe.center());
51+
}
52+
}
53+
return S;
54+
}
55+
56+
Eigen::MatrixXd Collocation::computeD_impl(const std::vector<Element> & elems,
57+
const IGreensFunction & gf) const {
58+
PCMSolverIndex cavitySize = elems.size();
59+
Eigen::MatrixXd D = Eigen::MatrixXd::Zero(cavitySize, cavitySize);
60+
for (PCMSolverIndex i = 0; i < cavitySize; ++i) {
61+
Element source = elems[i];
62+
D(i, i) = gf.doubleLayer(source, factor_);
63+
for (PCMSolverIndex j = 0; j < cavitySize; ++j) {
64+
Element probe = elems[j];
65+
if (i != j)
66+
D(i, j) =
67+
gf.kernelD(probe.normal().normalized(), source.center(), probe.center());
68+
}
69+
}
70+
return D;
71+
}
72+
} // namespace integrator
73+
74+
namespace {
75+
BoundaryIntegralOperator * createCollocation(const biOperatorData & data) {
76+
return new integrator::Collocation(data.scaling);
77+
}
78+
const std::string COLLOCATION("COLLOCATION");
79+
const bool registeredCollocation =
80+
Factory<BoundaryIntegralOperator, biOperatorData>::TheFactory().registerObject(
81+
COLLOCATION, createCollocation);
82+
}

src/bi_operators/Collocation.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* PCMSolver, an API for the Polarizable Continuum Model
3+
* Copyright (C) 2016 Roberto Di Remigio, Luca Frediani and collaborators.
4+
*
5+
* This file is part of PCMSolver.
6+
*
7+
* PCMSolver is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* PCMSolver is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* For information on the complete list of contributors to the
21+
* PCMSolver API, see: <http://pcmsolver.readthedocs.io/>
22+
*/
23+
24+
#ifndef COLLOCATION_HPP
25+
#define COLLOCATION_HPP
26+
27+
#include <vector>
28+
29+
#include "Config.hpp"
30+
31+
#include <Eigen/Core>
32+
33+
class Element;
34+
class IGreensFunction;
35+
36+
#include "BoundaryIntegralOperator.hpp"
37+
38+
namespace integrator {
39+
/*! \file Collocation.hpp
40+
* \class Collocation
41+
* \brief Implementation of the single and double layer operators matrix
42+
*representation using one-point collocation
43+
* \author Roberto Di Remigio
44+
* \date 2015, 2016
45+
*
46+
* Calculates the diagonal elements of S as:
47+
* \f[
48+
* S_{ii} = factor * \sqrt{\frac{4\pi}{a_i}}
49+
* \f]
50+
* while the diagonal elements of D are:
51+
* \f[
52+
* D_{ii} = -factor * \sqrt{\frac{\pi}{a_i}} \frac{1}{R_I}
53+
* \f]
54+
*/
55+
class Collocation __final : public BoundaryIntegralOperator {
56+
public:
57+
Collocation();
58+
Collocation(double fac);
59+
virtual ~Collocation() {}
60+
61+
private:
62+
/*! Scaling factor for the diagonal elements of the matrix representation of
63+
* the S and D operators
64+
*/
65+
double factor_;
66+
virtual Eigen::MatrixXd computeS_impl(const std::vector<Element> & elems,
67+
const IGreensFunction & gf) const __override;
68+
virtual Eigen::MatrixXd computeD_impl(const std::vector<Element> & elems,
69+
const IGreensFunction & gf) const __override;
70+
};
71+
} // namespace integrator
72+
73+
#endif // COLLOCATION_HPP

0 commit comments

Comments
 (0)