Skip to content

Commit

Permalink
update to v 0.8.4
Browse files Browse the repository at this point in the history
check for the surface localization of the charges
minor refactoring
  • Loading branch information
MFTabriz committed Jul 14, 2019
1 parent c6611f8 commit 8b8d172
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 39 deletions.
28 changes: 11 additions & 17 deletions manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,10 @@
<col class="field-body" />
<tbody valign="top">
<tr class="last-updated field">
<th class="docinfo-name">Last updated:</th><td class="field-body">07 July 2019</td>
<th class="docinfo-name">Last updated:</th><td class="field-body">15 July 2019</td>
</tr>
<tr><th class="docinfo-name">Version:</th>
<td>0.8.3</td></tr>
<td>0.8.4</td></tr>
</tbody>
</table>
<div class="contents topic" id="contents">
Expand Down Expand Up @@ -1569,7 +1569,7 @@ <h1><a class="toc-backref" href="#id30">6&nbsp;&nbsp;&nbsp;Input parameters</a><
</tr>
<tr><td><tt class="docutils literal">extrapolate_steps_number</tt></td>
<td>Number of the extrapolation steps in calculation of
E<sub>isolated</sub> <a class="footnote-reference" href="#id6" id="id2">[1]</a></td>
E<sub>isolated</sub></td>
<td><p class="first">10: for 2D models</p>
<p class="last">4: for the rest</p></td>
</tr>
Expand Down Expand Up @@ -1624,10 +1624,10 @@ <h1><a class="toc-backref" href="#id30">6&nbsp;&nbsp;&nbsp;Input parameters</a><
<tr><td><tt class="docutils literal">optimize_algorithm</tt></td>
<td><p class="first">Optimization algorithm in the NLOPT library
<p><a class="reference external" href="https://en.wikipedia.org/wiki/BOBYQA"><b>BOBYQA</b></a> :
Bound Optimization BY Quadratic Approximation <a class="footnote-reference" href="#id7" id="id3">[2]</a></p>
Bound Optimization BY Quadratic Approximation <a class="footnote-reference" href="#id7" id="id3">[1]</a></p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/COBYLA"><b>COBYLA</b></a>:
Constrained Optimization BY Linear Approximation <a class="footnote-reference" href="#id8" id="id4">[3]</a></p>
<p><b>SBPLX</b>: S.G. Johnson's implementation of the Subplex (subspace-searching simplex) algorithm <a class="footnote-reference" href="#idm2" id="idm1">[4]</a></p>
Constrained Optimization BY Linear Approximation <a class="footnote-reference" href="#id8" id="id4">[2]</a></p>
<p><b>SBPLX</b>: S.G. Johnson's implementation of the Subplex (subspace-searching simplex) algorithm <a class="footnote-reference" href="#idm2" id="idm1">[3]</a></p>
<p class="last"><tt class="docutils literal">optimize_algorithm = SBPLX</tt></p>
</td>
<td><p>BOBYQA</p>
Expand Down Expand Up @@ -1722,7 +1722,7 @@ <h1><a class="toc-backref" href="#id30">6&nbsp;&nbsp;&nbsp;Input parameters</a><
<td>0.5 0.5 0.5</td>
</tr>
<tr><td><tt class="docutils literal">verbosity</tt></td>
<td><p class="first">Verbosity of the program <a class="footnote-reference" href="#id9" id="id5">[5]</a></p>
<td><p class="first">Verbosity of the program <a class="footnote-reference" href="#id9" id="id5">[4]</a></p>
<p><strong>0</strong>: No extra info. Only write the output file.
Logging is disabled.</p>
<p><strong>1</strong>: Display calculated energy correction terms.
Expand All @@ -1739,34 +1739,28 @@ <h1><a class="toc-backref" href="#id30">6&nbsp;&nbsp;&nbsp;Input parameters</a><
</tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[1]</a></td><td>Extrapolating the model to very large order will accumulate errors due to energy calculations for large systems over a coarse grid size.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id7" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[2]</a></td><td>M.J.D. Powell, <a class="reference external" href="http://www.damtp.cam.ac.uk/user/na/NA_papers/NA2009_06.pdf">The BOBYQA algorithm for bound constrained optimization without derivatives</a>, Department of Applied Mathematics and Theoretical Physics, Cambridge England, technical report NA2009/06 (2009).</td></tr>
<tr><td class="label"><a class="fn-backref" href="#id3">[1]</a></td><td>M.J.D. Powell, <a class="reference external" href="http://www.damtp.cam.ac.uk/user/na/NA_papers/NA2009_06.pdf">The BOBYQA algorithm for bound constrained optimization without derivatives</a>, Department of Applied Mathematics and Theoretical Physics, Cambridge England, technical report NA2009/06 (2009).</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id8" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id4">[3]</a></td><td>M.J.D. Powell, <a class="reference external" href="https://doi.org/10.1017/S0962492900002841">Direct search algorithms for optimization calculations</a>, Acta Numerica, Vol. 7(1998) pp. 287-336</td></tr>
<tr><td class="label"><a class="fn-backref" href="#id4">[2]</a></td><td>M.J.D. Powell, <a class="reference external" href="https://doi.org/10.1017/S0962492900002841">Direct search algorithms for optimization calculations</a>, Acta Numerica, Vol. 7(1998) pp. 287-336</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="idm2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#idm1">[4]</a></td><td>T.H. Rowan, <a class="reference external" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.5708">Functional Stability Analysis of Numerical Algorithms</a>, Ph.D. thesis, Department of Computer Sciences, University of Texas at Austin, 1990.</td></tr>
<tr><td class="label"><a class="fn-backref" href="#idm1">[3]</a></td><td>T.H. Rowan, <a class="reference external" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.5708">Functional Stability Analysis of Numerical Algorithms</a>, Ph.D. thesis, Department of Computer Sciences, University of Texas at Austin, 1990.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id9" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[5]</a></td><td>Each verbosity level includes all the outputs from the lower verbosity options. Check <a class="reference internal" href="#the-files-table">the files table</a> for complete list of the output files.</td></tr>
<tr><td class="label"><a class="fn-backref" href="#id5">[4]</a></td><td>Each verbosity level includes all the outputs from the lower verbosity options. Check <a class="reference internal" href="#the-files-table">the files table</a> for complete list of the output files.</td></tr>
</tbody>
</table>
</div>
Expand Down
7 changes: 3 additions & 4 deletions manual.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**Note**: github `does not support <https://github.com/github/markup/issues/274#issuecomment-77102262>`_ math equations the in reStructuredText format. Please check the `manual.html <http://htmlpreview.github.io/?https://github.com/MFTabriz/slabcc/blob/master/manual.html>`_ for the proper rendering!

:Last updated: 07 July 2019
:version: 0.8.3
:Last updated: 15 July 2019
:version: 0.8.4

.. sectnum::

Expand Down Expand Up @@ -339,7 +339,7 @@ The input file is processed as follows:
| |``extrapolate_grid_x = 1.8`` | |
+------------------------------+-------------------------------------------------------+---------------+
| |Number of the extrapolation steps in calculation of |10: for 2D |
| ``extrapolate_steps_number`` |E\ :sub:`isolated` \ [#]_ |models |
| ``extrapolate_steps_number`` |E\ :sub:`isolated` \ |models |
| | | |
| | |4: for the rest|
+------------------------------+-------------------------------------------------------+---------------+
Expand Down Expand Up @@ -486,7 +486,6 @@ The input file is processed as follows:
| |calculation step (trace mode) | |
+------------------------------+-------------------------------------------------------+---------------+

.. [#] Extrapolating the model to very large order will accumulate errors due to energy calculations for large systems over a coarse grid size.
.. [#] M.J.D. Powell, `The BOBYQA algorithm for bound constrained optimization without derivatives <http://www.damtp.cam.ac.uk/user/na/NA_papers/NA2009_06.pdf>`_, Department of Applied Mathematics and Theoretical Physics, Cambridge England, technical report NA2009/06 (2009).
.. [#] M.J.D. Powell, `Direct search algorithms for optimization calculations <https://doi.org/10.1017/S0962492900002841>`_, Acta Numerica, Vol. 7(1998) pp. 287-336
.. [#] T.H. Rowan, `Functional Stability Analysis of Numerical Algorithms <https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.5708>`_, Ph.D. thesis, Department of Computer Sciences, University of Texas at Austin, 1990.
Expand Down
8 changes: 4 additions & 4 deletions readme.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. |Version| image:: https://img.shields.io/badge/version-0.8.3-blue.svg
:alt: Version 0.8.3
.. |Update| image:: https://img.shields.io/badge/Last%20update-07.07.2019-informational.svg
:alt: Last update 07 July 2019
.. |Version| image:: https://img.shields.io/badge/version-0.8.4-blue.svg
:alt: Version 0.8.4
.. |Update| image:: https://img.shields.io/badge/Last%20update-15.07.2019-informational.svg
:alt: Last update 15 July 2019
.. |Travis| image:: https://travis-ci.org/MFTabriz/slabcc.svg?branch=master
:alt: Build Status
:target: https://travis-ci.org/MFTabriz/slabcc
Expand Down
44 changes: 31 additions & 13 deletions src/slabcc_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void slabcc_model::change_size(const mat33& new_cell_vectors) {

const rowvec3 scaling = cell_vectors_lengths / cell_vectors_lengths0;
if (abs(max(scaling) - min(scaling)) > 0.00001) {
log->debug("Model cell scaling is anisotropic!");
log->warn("Model cell scaling is anisotropic!");
}
}

Expand Down Expand Up @@ -424,16 +424,15 @@ void slabcc_model::adjust_extrapolation_grid(const int &extrapol_steps_num, cons
auto log = spdlog::get("loggers");
log->trace("Checking the extrapolation grid size");
const mat33 cell_vectors0 = cell_vectors;
const double old_total_charge = total_charge;

const double total_charge0 = total_charge;
//Force discretization error checks
for (auto step = extrapol_steps_num - 1; step > 0; --step) {
const double extrapol_factor = extrapol_steps_size * step + 1;
change_size(cell_vectors0 * extrapol_factor);
gaussian_charges_gen();
}
change_size(cell_vectors0);
total_charge = old_total_charge;
total_charge = total_charge0;
}

tuple <rowvec, rowvec> slabcc_model::extrapolate(int extrapol_steps_num, double extrapol_steps_size) {
Expand All @@ -445,8 +444,8 @@ tuple <rowvec, rowvec> slabcc_model::extrapolate(int extrapol_steps_num, double
const auto charge_position0 = charge_position;
const double slab_thickness = abs(interfaces(0) - interfaces(1));
rowvec Es = arma::zeros<rowvec>(extrapol_steps_num - 1), sizes = Es;
for (auto n = 0; n < extrapol_steps_num - 1; ++n) {
const double extrapol_factor = extrapol_steps_size * (1.0 + n) + 1;
for (auto step = 1; step < extrapol_steps_num; ++step) {
const double extrapol_factor = extrapol_steps_size * step + 1;
change_size(cell_vectors0 * extrapol_factor);
if (this->type == model_type::slab) {
//increase the slab thickness
Expand Down Expand Up @@ -478,8 +477,8 @@ tuple <rowvec, rowvec> slabcc_model::extrapolate(int extrapol_steps_num, double
extrapolation_info += "\t" + to_string(charge_position(i, normal_direction) * cell_vectors_lengths(normal_direction));
}
log->debug(extrapolation_info);
Es(n) = EperModel;
sizes(n) = 1.0 / extrapol_factor;
Es(step-1) = EperModel;
sizes(step-1) = 1.0 / extrapol_factor;
}

return make_tuple(Es, sizes);
Expand Down Expand Up @@ -710,25 +709,44 @@ void slabcc_model::verify_CHG(const cube& defect_charge) {

if (this->type != model_type::bulk) {

//find the index of the interfaces

//find the grid index of the interfaces
rowvec2 interfaces_index = cell_grid(normal_direction) * interfaces;
urowvec2 interfaces_grid_i = { (uword)interfaces_index(0), (uword)interfaces_index(1)};
interfaces_grid_i = sort(interfaces_grid_i);
vector<span> spans = { span(), span(), span(interfaces_grid_i(0),interfaces_grid_i(1)) };
swap(spans[normal_direction], spans[2]);

const double model_total = accu(real(CHG)) * voxel_vol;
const double model_in = accu(real(CHG(spans[0], spans[1], spans[2]))) * voxel_vol;
const double model_out = model_total - model_in;

const double defect_total = accu(defect_charge) * voxel_vol;
const double defect_in = accu(defect_charge(spans[0], spans[1], spans[2])) * voxel_vol;
//The original defect may have a different grid size than the final model!
const urowvec3 defect_grid = SizeVec(defect_charge);
rowvec2 defect_interfaces_index = defect_grid(normal_direction) * interfaces;
urowvec2 defect_interfaces_grid_i = { (uword)defect_interfaces_index(0), (uword)defect_interfaces_index(1) };
defect_interfaces_grid_i = sort(defect_interfaces_grid_i);
vector<span> defect_spans = { span(), span(), span(defect_interfaces_grid_i(0),defect_interfaces_grid_i(1)) };
swap(defect_spans[normal_direction], defect_spans[2]);

const double defect_voxel_vol = prod(cell_vectors_lengths / defect_grid);
const double defect_total = accu(defect_charge) * defect_voxel_vol;
const double defect_in = accu(defect_charge(defect_spans[0], defect_spans[1], defect_spans[2])) * defect_voxel_vol;
const double defect_out = defect_total - defect_in;

//these two do NOT need to closely agree with each other!
//these two do NOT need to closely agree with each other if the charge is near the surface
log->debug("Total charge of the model slab (inside, outside): {}, {}", model_in, model_out);
log->debug("Total charge of the defect slab (inside, outside): {}, {}", defect_in, defect_out);

const bool large_charge_difference = abs(model_in - defect_in) > 0.1;
const mat relative_charge_interface_distance = abs(repmat(charge_position.col(normal_direction), 1, 2) - repmat(interfaces, charge_position.n_rows, 1));
const mat charge_interface_distance = relative_charge_interface_distance * cell_vectors_lengths(normal_direction) / ang_to_bohr;
const bool charge_near_surface = charge_interface_distance.min() < 1;

if (large_charge_difference && !charge_near_surface) {
log->debug("Minimum distance of the model charge centers to the surface (Ang): {}", charge_interface_distance.min());
log->debug("Difference of the charge inside of the slab in the defect and the model: {}", abs(model_in - defect_in));
log->warn("The amount of the charge inside and outside of the slab seems to be different in the input files and the slabcc model. The extra charge may be partially localized on the slab surfaces. ");
}

}
}
2 changes: 1 addition & 1 deletion src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

constexpr auto SLABCC_VERSION_MAJOR = 0;
constexpr auto SLABCC_VERSION_MINOR = 8;
constexpr auto SLABCC_VERSION_PATCH = 3;
constexpr auto SLABCC_VERSION_PATCH = 4;

//comment the next line while developing the code! Uncommenting will disable the range checks in Armadillo. Makefile may override this!
//#define ARMA_NO_DEBUG
Expand Down

0 comments on commit 8b8d172

Please sign in to comment.