This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Incremental fmatrix #716
Merged
Merged
Incremental fmatrix #716
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b96e12e
incremental fmatrix and option changes
jenswehnerteaching fcd30ba
merged and fixed
JensWehner a5170f7
Merge branch 'libecpint' into incremental_fmatrix
JensWehner d46e445
fixed settings
JensWehner 5db14bb
merged
JensWehner c9bbc20
refactored incremental fock
JensWehner 996cc91
Merge branch 'master' into incremental_fmatrix
JensWehner 03eaf49
Merge branch 'master' into incremental_fmatrix
JensWehner 7e97e58
Update CHANGELOG.rst
votca-bot fcf4fcf
Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34)
votca-bot deb6063
added tests
JensWehner 8423389
Merge branch 'incremental_fmatrix' of https://github.com/votca/xtp in…
JensWehner 810d242
added defaults
JensWehner 72ce365
Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34)
votca-bot 8d8606b
made options clearer
JensWehner 064f0ba
Merge branch 'incremental_fmatrix' of https://github.com/votca/xtp in…
JensWehner 6a12080
updated logging output
JensWehner bfa20e8
Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34)
votca-bot 206daf7
remove cout
JensWehner 2b4adbf
Merge branch 'incremental_fmatrix' of https://github.com/votca/xtp in…
JensWehner 9c6aa7a
Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34)
votca-bot bafeab8
fixed test
JensWehner 7efdb4e
large fingers
JensWehner 2ef45e2
Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34)
votca-bot 5197861
Update CHANGELOG.rst
JensWehner 769095e
Merge branch 'master' into incremental_fmatrix
JensWehner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2009-2020 The VOTCA Development Team | ||
* (http://www.votca.org) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
#ifndef VOTCA_XTP_INCREMENTALFOCKBUILDER_H | ||
#define VOTCA_XTP_INCREMENTALFOCKBUILDER_H | ||
|
||
#include "votca/xtp/logger.h" | ||
#include <votca/tools/types.h> | ||
namespace votca { | ||
namespace xtp { | ||
|
||
// Small Wrapper class to build incremental fock matrix | ||
class IncrementalFockBuilder { | ||
public: | ||
IncrementalFockBuilder(Logger& log, double start_threshold, | ||
Index fock_matrix_reset) | ||
: log_(log), | ||
start_incremental_F_threshold_(start_threshold), | ||
fock_matrix_reset_(fock_matrix_reset) {} | ||
|
||
void Configure(const Eigen::MatrixXd& dmat) { | ||
Ddiff_ = dmat; | ||
Dlast_ = dmat; | ||
} | ||
|
||
void Start(Index iteration, double DiisError) { | ||
if (!incremental_Fbuild_started_ && | ||
DiisError < start_incremental_F_threshold_) { | ||
incremental_Fbuild_started_ = true; | ||
reset_incremental_fock_formation_ = false; | ||
last_reset_iteration_ = iteration - 1; | ||
next_reset_threshold_ = DiisError / 10.0; | ||
XTP_LOG(Log::error, log_) | ||
<< TimeStamp() << " Using incremental 4c build from here" | ||
<< std::flush; | ||
} | ||
} | ||
|
||
void resetMatrices(Eigen::MatrixXd& J, Eigen::MatrixXd& K, | ||
const Eigen::MatrixXd& dmat) { | ||
if (reset_incremental_fock_formation_ || !incremental_Fbuild_started_) { | ||
J.setZero(); | ||
K.setZero(); | ||
Ddiff_ = dmat; | ||
} | ||
} | ||
|
||
const Eigen::MatrixXd& getDmat_diff() const { return Ddiff_; } | ||
|
||
void UpdateCriteria(double DiisError, Index Iteration) { | ||
if (reset_incremental_fock_formation_ && incremental_Fbuild_started_) { | ||
reset_incremental_fock_formation_ = false; | ||
last_reset_iteration_ = Iteration; | ||
next_reset_threshold_ = DiisError / 10.0; | ||
XTP_LOG(Log::error, log_) | ||
<< TimeStamp() << " Reset incremental 4c build" << std::flush; | ||
} | ||
} | ||
|
||
void UpdateDmats(const Eigen::MatrixXd& dmat, double DiisError, | ||
Index Iteration) { | ||
if (DiisError < next_reset_threshold_ || | ||
Iteration - last_reset_iteration_ > fock_matrix_reset_) { | ||
reset_incremental_fock_formation_ = true; | ||
} | ||
Ddiff_ = dmat - Dlast_; | ||
Dlast_ = dmat; | ||
} | ||
|
||
private: | ||
Logger& log_; | ||
double start_incremental_F_threshold_; // Diis error from which to start | ||
// using incremental builds | ||
Index fock_matrix_reset_; // After how many iterations the fock matrix should | ||
// be reset regardless | ||
|
||
Eigen::MatrixXd Ddiff_; | ||
Eigen::MatrixXd Dlast_; | ||
|
||
bool reset_incremental_fock_formation_ = false; | ||
bool incremental_Fbuild_started_ = false; | ||
double next_reset_threshold_ = 0.0; | ||
Index last_reset_iteration_ = 0; | ||
}; // namespace xtp | ||
|
||
} // namespace xtp | ||
} // namespace votca | ||
|
||
#endif // VOTCA_XTP_INCREMENTALFOCKBUILDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this if have an else with an error something like "already started"? Or can we do without the if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now see how you use it in the loop, but I don't understand the logic now, it seems that as soon as you have called
Start
incremental_Fbuild_started
will betrue
and will not be turned to false again? In that case this function block only executes once, so why not call it once?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we want to start it in the middle of the iterations, when the threshold is reached and not before we start the SCF. So each SCF cycle before it starts it has to be checked if it should start.