votca 2026-dev
Loading...
Searching...
No Matches
ewaldregistry.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_EWALDREGISTRY_H
22#define VOTCA_XTP_EWALDREGISTRY_H
23
24// Standard includes
25#include <map>
26#include <vector>
27
28// Local VOTCA includes
29#include "checkpoint.h"
30#include "classicalsegment.h"
31
59
60namespace votca {
61namespace xtp {
62
64
66 public:
67 EwaldRegistry() = default;
68
69 // Registers `segment` under (id, state). Overwrites any existing entry
70 // for the same (id, state) pair. `id` is expected to match the stable
71 // segment id used elsewhere in the topology (Segment::getId()); it is
72 // not required to match segment.getId() and is kept as an explicit
73 // argument so the same PolarSegment content could in principle be
74 // registered under a different id if that is ever useful, though in
75 // normal use the two will agree.
76 void Register(Index id, EwaldChargeState state, PolarSegment segment);
77
78 // True if an entry exists for (id, state).
79 bool Has(Index id, EwaldChargeState state) const;
80
81 // Returns the stored segment for (id, state). Throws std::out_of_range
82 // if no such entry exists; callers are expected to check Has() first
83 // when the presence of a given state is not already guaranteed by
84 // construction.
85 const PolarSegment& Get(Index id, EwaldChargeState state) const;
87
88 // Removes the entry for (id, state), if present. No-op otherwise.
89 void Erase(Index id, EwaldChargeState state);
90
91 // Every segment id that has at least one registered state.
92 std::vector<Index> AllIds() const;
93
94 // Every state currently registered for `id`. Empty if `id` is unknown.
95 std::vector<EwaldChargeState> StatesFor(Index id) const;
96
97 Index size() const { return static_cast<Index>(store_.size()); }
98
99 void WriteToCpt(CheckpointWriter& w) const;
101
102 private:
103 using Key = std::pair<Index, EwaldChargeState>;
104
105 struct KeyLess {
106 bool operator()(const Key& a, const Key& b) const {
107 if (a.first != b.first) {
108 return a.first < b.first;
109 }
110 return static_cast<int>(a.second) < static_cast<int>(b.second);
111 }
112 };
113
114 std::map<Key, PolarSegment, KeyLess> store_;
115};
116
117} // namespace xtp
118} // namespace votca
119
120#endif // VOTCA_XTP_EWALDREGISTRY_H
std::map< Key, PolarSegment, KeyLess > store_
bool Has(Index id, EwaldChargeState state) const
std::pair< Index, EwaldChargeState > Key
std::vector< EwaldChargeState > StatesFor(Index id) const
std::vector< Index > AllIds() const
void WriteToCpt(CheckpointWriter &w) const
const PolarSegment & Get(Index id, EwaldChargeState state) const
void Erase(Index id, EwaldChargeState state)
void Register(Index id, EwaldChargeState state, PolarSegment segment)
void ReadFromCpt(CheckpointReader &r)
ClassicalSegment< PolarSite > PolarSegment
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
bool operator()(const Key &a, const Key &b) const