YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpinAmplitudeCache.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
20 
21 #ifndef yap_SpinAmplitudeCache_h
22 #define yap_SpinAmplitudeCache_h
23 
24 #include "fwd/Spin.h"
25 
26 #include "SpinAmplitude.h"
27 #include "UnitSpinAmplitude.h"
28 #include "WeakPtrCache.h"
29 
30 #include <memory>
31 
32 namespace yap {
33 
34 class Model;
35 
40  public WeakPtrCache<SpinAmplitude>
41 {
42 public:
43 
46  SpinAmplitudeCache(Model* model = nullptr) :
47  WeakPtrCache(), Model_(model) {}
48 
50  bool equal(const std::shared_ptr<SpinAmplitude>& A, const std::shared_ptr<SpinAmplitude>& B) const override
51  { return (A.get() == B.get()) or A->equalTo(*B); }
52 
53  using WeakPtrCache::find;
54 
60  weak_ptr_type find(unsigned two_J, const SpinVector& two_j, unsigned L, unsigned two_S) const;
61 
67  std::shared_ptr<SpinAmplitude> spinAmplitude(unsigned two_J, const SpinVector& two_j, unsigned L, unsigned two_S);
68 
70  bool consistent() const;
71 
73  friend class Model;
74 
75 protected:
76 
78  void setModel(Model& model);
79 
86  std::shared_ptr<SpinAmplitude> unit(Model& m, unsigned two_J, const SpinVector& two_j, unsigned L, unsigned two_S) const
87  { return std::shared_ptr<SpinAmplitude>(new UnitSpinAmplitude(m, two_J, two_j, L, two_S)); }
88 
89 private:
90 
98  virtual std::shared_ptr<SpinAmplitude> create(Model& m, unsigned two_J, const SpinVector& two_j, unsigned L, unsigned two_S) const = 0;
99 
102 
103 };
104 
105 }
106 
107 #endif
std::shared_ptr< SpinAmplitude > unit(Model &m, unsigned two_J, const SpinVector &two_j, unsigned L, unsigned two_S) const
Definition: SpinAmplitudeCache.h:86
Implements a spin amplitude that always returns Complex_1.
Definition: UnitSpinAmplitude.h:37
bool consistent() const
Check consistency of cache. Skips expired entries.
Definition: SpinAmplitudeCache.cxx:39
Template for a cache of weak_ptr's to objects.
Definition: WeakPtrCache.h:37
std::shared_ptr< SpinAmplitude > spinAmplitude(unsigned two_J, const SpinVector &two_j, unsigned L, unsigned two_S)
Definition: SpinAmplitudeCache.cxx:21
weak_ptr_type find(unsigned two_J, const SpinVector &two_j, unsigned L, unsigned two_S) const
Definition: SpinAmplitudeCache.cxx:8
virtual std::shared_ptr< SpinAmplitude > create(Model &m, unsigned two_J, const SpinVector &two_j, unsigned L, unsigned two_S) const =0
void setModel(Model &model)
set raw pointer to owning Model
Definition: SpinAmplitudeCache.cxx:49
std::weak_ptr< SpinAmplitude > weak_ptr_type
std::weak_ptr to T
Definition: WeakPtrCache.h:53
Caches SpinAmplitudes.
Definition: SpinAmplitudeCache.h:39
Class implementing a PWA model.
Definition: Model.h:56
SpinAmplitudeCache(Model *model=nullptr)
Definition: SpinAmplitudeCache.h:46
weak_ptr_type find(shared_ptr_type t) const
Definition: WeakPtrCache.h:93
bool equal(const std::shared_ptr< SpinAmplitude > &A, const std::shared_ptr< SpinAmplitude > &B) const override
Equality.
Definition: SpinAmplitudeCache.h:50
Model * Model_
raw pointer to Model this cache belongs to
Definition: SpinAmplitudeCache.h:101