SUNphi  1.0
Conj.hpp
Go to the documentation of this file.
1 #ifndef _CONJ_HPP
2 #define _CONJ_HPP
3 
4 /// \file Conj.hpp
5 ///
6 /// \brief Header file for the definition of the conjugate of a number
7 
8 #include <physics/Compl.hpp>
9 #include <ios/Logger.hpp>
10 #include <tens/TensKind.hpp>
11 #include <smet/NnarySmET.hpp>
12 #include <smet/Transpose.hpp>
13 
14 namespace SUNphi
15 {
16  // Base type to qualify as Conjer
17  DEFINE_BASE_TYPE(Conjer);
18 
19  /// Class to take the conjugate of a \c SmET
20  template <typename..._Refs> // Type of the expression to conjugate
21  class Conjer :
22  public BaseConjer, // Inherit from \c BaseConjer to detect in expression
23  public NnarySmET<Conjer<_Refs...>>, // Inherit from \c NnarySmET
24  public ConstrainAreSmETs<_Refs...> // Constrain all \c _Refs to be \c SmET
25  {
26 
27  public:
28 
30 
31  /// Position of the Compl component
32  constexpr static int posOfCompl=
33  posOfType<Compl,typename TkOf<Ref<0>>::types>;
34 
36 
37  // Attributes
40 
41  /// TensorKind of the bound expression
43 
45 
47 
48  PROVIDE_EXTRA_MERGE_DELIMS(IntSeq<posOfCompl,posOfCompl+1>);
49 
51 
53 
55 
56  /// Evaluator for \c Conjer
57  template <typename...Args> // Type of the arguments
58  auto eval(Args&&...args) //!< Components to get
59  const
60  {
61  STATIC_ASSERT_ARE_N_TYPES(TkOf<Ref<0>>::nTypes,args);
62 
63  /// Detect if we have to put "-" in the result
64  const bool isIm=
65  get<posOfCompl>(Tuple<Args...>(forw<Args>(args)...));
66 
67  /// Temporary result
68  auto val=
69  get<0>(refs).eval(forw<Args>(args)...);
70 
71  if(isIm)
72  return -val;
73  else
74  return +val;
75  }
76  };
77 
78  // Check that a test Conjer is a NnarySmET
79  STATIC_ASSERT_IS_NNARY_SMET(Conjer<Tens<TensKind<Compl>,double>>);
80 
81  /// Build Conjer from conj, if TensKind is complex
82  template <typename T, // Type of the SmET to get
84  auto conj(T&& smet, //!< SmET to act upon
86  {
88 
89  /// Tens Kind of the conjugated type
90  using TK=
91  typename RemRef<T>::Tk;
92 
93  /// Types of the tensor kind
94  using TK_TYPES=
95  typename TK::types;
96 
97  // If Compl is a type of the TensKind, return the Conjer
98  if constexpr(tupleHasType<Compl,TK_TYPES>)
99  return Conjer<T>(forw<T>(smet));
100  // Otherwise returns the object itself
101  else
102  return smet;
103  }
104  // Simplifies conj(conj)
106 
107  // Defines commutativity of Conj with other nnary expressions
108  NNARY_SMET_GOES_INSIDE(conj,Transposer,transpose);
109 }
110 
111 #endif
#define PROVIDE_NNARY_GET_MERGED_COMPS_VIEW_ACCORDING_TO_REPRESENTATIVE_FUNCTION
Uses the representativeFunction to provide a merged view.
Definition: NnarySmET.hpp:365
#define SAME_TK_AS_REF(ID)
Get the same TensKind of a given ref.
Definition: NnarySmET.hpp:201
#define PROVIDE_POS_OF_RES_TCS_IN_REFS
Provide the position of result Tk TensComp in each input.
Definition: NnarySmET.hpp:206
#define STATIC_ASSERT_ARE_N_TYPES(N, UNEXP_PARPACK)
Static assert if not passing exactly N types.
Definition: TypeTraits.hpp:422
#define PROVIDE_MERGEABLE_COMPS_ACCORDING_TO_REFS_AND_EXTRA
Provide MergeableComps delimiter according to references and extra.
Definition: NnarySmET.hpp:324
#define PROVIDE_SIMPLE_NNARY_COMP_SIZE
Definition: NnarySmET.hpp:151
#define CANCEL_DUPLICATED_NNARY_SMET_CALL(CALLER,NNARY_SMET)
Definition: NnarySmET.hpp:451
#define SFINAE_WORSEN_DEFAULT_VERSION_TEMPLATE_PARS
Definition: SFINAE.hpp:58
#define SAME_FUND_AS_REF(ID)
Get the same Fund type of a given ref.
Definition: NnarySmET.hpp:192
#define FORWARD_IS_ALIASING_TO_REFS
Definition: NnarySmET.hpp:420
#define PROVIDE_NNARY_SMET_SIMPLE_CREATOR(NNARY_SMET)
Defines a simple creator taking n references.
Definition: NnarySmET.hpp:383
#define STATIC_ASSERT_IS_NNARY_SMET(...)
Defines the check for a Nnary SmET.
Definition: NnarySmET.hpp:394
#define PROVIDE_EXTRA_MERGE_DELIMS(...)
Add an ExtraDelims IntSeq called ExtraDelims.
Definition: NnarySmET.hpp:313
#define SFINAE_WORSEN_DEFAULT_VERSION_ARGS_CHECK
Check that no extra arg is passed.
Definition: SFINAE.hpp:66
#define NOT_STORING
Set the SmET to not-storing.
Definition: BaseSmET.hpp:86
#define SFINAE_WORSEN_DEFAULT_VERSION_ARGS
Provide empty list of args, used to unprioritize default version.
Definition: SFINAE.hpp:62
#define NNARY_SMET_GOES_INSIDE(EXT_FUN,NNARY_SMET, INT_FUN)
Definition: NnarySmET.hpp:494
#define PROVIDE_NNARY_SMET_REFS_AND_CHECK_ARE_N(N)
Definition: NnarySmET.hpp:126
#define DEFINE_BASE_TYPE(TYPE,...)
Definition: TypeTraits.hpp:526