Loading...
Searching...
No Matches
EigenmodeStrategy.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#pragma once
13
14#include "Davidson.h"
15#include "Dimer.h"
16#include "ImprovedDimer.h"
17#include "Lanczos.h"
18#include "LowestEigenmode.h"
19#include <stdexcept>
20#include <variant>
21
22#ifdef WITH_GPRD
23#include "AtomicGPDimer.h"
24#endif
25
26namespace eonc {
27
28#ifdef WITH_GPRD
30 std::variant<Dimer, ImprovedDimer, Lanczos, Davidson, AtomicGPDimer>;
31#else
32using EigenmodeStrategy = std::variant<Dimer, ImprovedDimer, Lanczos, Davidson>;
33#endif
34
37inline std::shared_ptr<EigenmodeStrategy>
38buildEigenmodeStrategy(std::shared_ptr<Matter> matter, const Parameters &params,
39 std::shared_ptr<Potential> pot) {
42 if (params.dimer_options.improved) {
43 return std::make_shared<EigenmodeStrategy>(
44 ImprovedDimer(matter, params, pot));
45 }
46 return std::make_shared<EigenmodeStrategy>(Dimer(matter, params, pot));
47 } else if (params.saddle_search_options.minmode_method ==
49 return std::make_shared<EigenmodeStrategy>(Lanczos(matter, params, pot));
50 } else if (params.saddle_search_options.minmode_method ==
52 return std::make_shared<EigenmodeStrategy>(Davidson(matter, params, pot));
53 }
54#ifdef WITH_GPRD
55 else if (params.saddle_search_options.minmode_method ==
57 // AtomicGPDimer embeds atmd::AtomicDimer (unique_ptr + user dtor → not
58 // movable). Construct the alternative in place; do not pass a temporary.
59 return std::make_shared<EigenmodeStrategy>(
60 std::in_place_type<AtomicGPDimer>, matter, params, pot);
61 }
62#else
63 else if (params.saddle_search_options.minmode_method ==
65 throw std::runtime_error(
66 "min_mode_method=gprdimer requires -Dwith_gprd=true (WITH_GPRD)");
67 }
68#endif
69 // Default to improved dimer
70 return std::make_shared<EigenmodeStrategy>(
71 ImprovedDimer(matter, params, pot));
72}
73
76 std::shared_ptr<Matter> matter,
77 AtomMatrix direction) {
78 std::visit([&](auto &impl) { impl.compute(matter, direction); }, s);
79}
80
83 return std::visit([](auto &impl) { return impl.getEigenvalue(); }, s);
84}
85
88 return std::visit([](auto &impl) { return impl.getEigenvector(); }, s);
89}
90
94 return std::get_if<ImprovedDimer>(&s);
95}
96
99 return std::visit([](auto &impl) { return impl.totalForceCalls; }, s);
100}
101
103 return std::visit([](auto &impl) { return impl.statsTorque; }, s);
104}
105
107 return std::visit([](auto &impl) { return impl.statsAngle; }, s);
108}
109
111 return std::visit([](auto &impl) { return impl.statsRotations; }, s);
112}
113
115 return std::visit([](auto &impl) { return impl.totalIterations; }, s);
116}
117
118} // namespace eonc
119
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Definition Eigen.h:37
Classic dimer method to find the lowest curvature mode.
Definition Dimer.h:22
static const char MINMODE_DIMER[]
static const char MINMODE_GPRDIMER[]
static const char MINMODE_DAVIDSON[]
static const char MINMODE_LANCZOS[]
struct eonc::Parameters::dimer_options_t dimer_options
struct eonc::Parameters::saddle_search_options_t saddle_search_options
RAII resource manager for the ARTn C library with global synchronization.
double eigenmodeStatsAngle(EigenmodeStrategy &s)
AtomMatrix eigenmodeGetEigenvector(EigenmodeStrategy &s)
Dispatch getEigenvector() to the active variant.
ImprovedDimer * asImprovedDimer(EigenmodeStrategy &s)
Access ImprovedDimer-specific features.
double eigenmodeStatsTorque(EigenmodeStrategy &s)
std::shared_ptr< EigenmodeStrategy > buildEigenmodeStrategy(std::shared_ptr< Matter > matter, const Parameters &params, std::shared_ptr< Potential > pot)
Build the eigenmode solver from parameters.
void eigenmodeCompute(EigenmodeStrategy &s, std::shared_ptr< Matter > matter, AtomMatrix direction)
Dispatch compute() to the active variant.
double eigenmodeGetEigenvalue(EigenmodeStrategy &s)
Dispatch getEigenvalue() to the active variant.
long eigenmodeStatsRotations(EigenmodeStrategy &s)
long eigenmodeTotalForceCalls(EigenmodeStrategy &s)
Read stats from any variant (all inherit LowestEigenmode stats fields).
std::variant< Dimer, ImprovedDimer, Lanczos, Davidson > EigenmodeStrategy
long eigenmodeTotalIterations(EigenmodeStrategy &s)