31#include <itertools/itertools.hpp>
48 using nda::C_stride_layout;
51 template <Mesh M,
typename Target = matrix_valued,
typename Layout = C_layout>
class gf;
52 template <Mesh M,
typename Target = matrix_valued,
typename Layout = C_str
ide_layout>
class gf_view;
53 template <Mesh M,
typename Target = matrix_valued,
typename Layout = C_str
ide_layout>
class gf_const_view;
72 template <
template <
typename...>
class TMPLT,
typename T>
struct is_instantiation_of : std::false_type {};
75 template <
template <
typename...>
class TMPLT,
typename... U>
struct is_instantiation_of<TMPLT, TMPLT<U...>> : std::true_type {};
83 template <
template <
typename...>
class gf,
typename T>
101 template <
typename G,
typename M =
void>
inline constexpr bool is_gf_v =
false;
104 template <
typename G,
typename M>
105 requires(!std::is_same_v<G, std::remove_cvref_t<G>>)
109 template <
typename G>
132 template <typename G, typename M = typename std::remove_cvref_t<G>::mesh_t>
134 { g.data() } -> nda::MemoryArray;
135 requires std::same_as<std::decay_t<
decltype(g.mesh())>, M>;
140 template <MemoryGf G>
void mpi_broadcast(G &&g, mpi::communicator c = {},
int root = 0);
141 template <MemoryGf G1, MemoryGf G2>
142 void mpi_reduce_into(G1
const &g_in, G2 &&g_out, mpi::communicator c = {},
int root = 0,
bool all =
false, MPI_Op op = MPI_SUM);
150 template <
typename G>
using get_target_t =
typename std::decay_t<G>::target_t;
160 template <
int N = 0, MemoryGf G>
auto const &
get_mesh(G
const &g) {
162 return std::get<N>(g.mesh());
168 template <MemoryGf G>
using target_value_t =
decltype(std::declval<G>()[std::declval<typename G::mesh_point_t>()]);
196 static_assert(not std::is_same_v<M, triqs::lattice::brillouin_zone>,
197 "Since TRIQS 2.3, brillouin_zone is replaced by mesh::brzone as a mesh name. Cf Doc, changelog");
308 target_and_shape_t
target()
const {
return target_and_shape_t{stdutil::front_mpop<arity>(_data.shape())}; }
342 void swap_impl(
gf &b)
noexcept {
344 swap(this->_mesh, b._mesh);
345 swap(this->_data, b._data);
352 return stdutil::join(m.size_of_components(), shape);
354 return stdutil::front_append(shape, m.size());
399 template <
typename G>
400 explicit gf(G
const &g)
401 requires(GreenFunction<G>::value and std::is_same_v<mesh_t, typename G::mesh_t>)
422 this->swap_impl(rhs);
437 template <
typename RHS>
439 requires(GreenFunction<RHS>::value and not std::is_same_v<std::decay_t<RHS>,
gf>)
442 _data.resize(rhs.data_shape());
443 for (
auto w : _mesh) (*this)[w] = rhs[w];
463 auto d2 = std::forward<Fdata>(fd)(_data);
466 return gv_t{
mesh(), d2};
480 auto d2 = std::forward<Fdata>(fd)(_data);
483 return gv_t{
mesh(), d2};
488 template <MemoryGf G>
friend void mpi_broadcast(G &&, mpi::communicator,
int root);
489 template <MemoryGf G1, MemoryGf G2>
friend void mpi_reduce_into(G1
const &, G2 &&, mpi::communicator,
int,
bool, MPI_Op);
510 template <
typename Tag,
typename L,
typename R>
struct gf_expr;
513 template <
typename Tag,
typename L,
typename R>
517 template <
typename Tag,
typename L,
typename R>
Member code shared by triqs::gfs::gf, triqs::gfs::gf_view and triqs::gfs::gf_const_view.
A read-only, non-owning view of a Green's function.
A mutable, non-owning view of a Green's function.
The owning Green's function container.
gf< M, typename T::complex_t, Layout > complex_t
typename mesh_t::mesh_point_t mesh_point_t
static constexpr int data_rank
gf(gf_const_view< M, Target > const &g)
Construct from a const view, making a deep copy of the data.
gf_view< M, T, typename Layout::with_lowest_guarantee_t > view_type
static constexpr int target_rank
gf(gf_view< M, Target > const &g)
Construct from a view, making a deep copy of the data.
nda::basic_array< scalar_t, data_rank, Layout, 'A', nda::heap<> > data_t
gf_view< M, T, typename Layout::with_lowest_guarantee_t > mutable_view_type
data_t & data() &
Get the data array.
data_t data() &&
Get the data array (rvalue overload).
target_and_shape_t target() const
Get a handle to the target and its shape.
static constexpr bool is_const
typename mesh_t::index_t mesh_index_t
gf & operator=(gf const &rhs)=default
Copy assignment.
std::array< long, T::rank > target_shape_t
auto const & data_shape() const
Get the shape of the data array.
gf< M, T, Layout > regular_type
typename T::scalar_t scalar_t
gf_const_view< M, T, typename Layout::with_lowest_guarantee_t > const_view_type
gf(gf const &x)=default
Copy constructor.
gf(mesh_t m, data_t dat)
Construct from a mesh and a data array.
auto apply_on_data(Fdata &&fd) const
Build a const view of a Green's function whose data is the result of applying a function to the data ...
gf(G const &g)
Construct from any object modeling the GreenFunction concept with the same mesh type.
auto target_indices() const
Get a generator over the multi-indices of the target space.
auto apply_on_data(Fdata &&fd)
Build a view of a Green's function whose data is the result of applying a function to the data array.
mesh_t const & mesh() const
Get the mesh of the Green's function.
gf< M, typename T::real_t, Layout > real_t
gf(gf &&)=default
Move constructor.
gf & operator=(RHS &&rhs)
Assign from any object modeling the GreenFunction concept.
static constexpr bool is_view
static constexpr int arity
gf & operator=(gf &&rhs) noexcept
Move assignment.
std::array< long, Target::rank > target_shape() const
Get the shape of the target.
data_t const & data() const &
Get the data array (const overload).
gf(mesh_t m, target_shape_t shape={})
Construct from a mesh and a target shape.
Concept checking that a type behaves like an in-memory Green's function.
Provides common type aliases, forward declarations and internal helpers for the Green's function cont...
static constexpr int n_variables
Constexpr variable that holds the number of meshes in a triqs::mesh::Mesh type ( for non-product mes...
TRIQS exception hierarchy and related macros.
void mpi_broadcast(BG &&bg, mpi::communicator c={}, int root=0)
Implementation of an MPI broadcast for triqs::gfs::block_gf and triqs::gfs::block_gf_view types.
void mpi_reduce_into(BG1 const &bg_in, BG2 &&bg_out, mpi::communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for triqs::gfs::block_gf and triqs::gfs::block_gf_view types that red...
typename _target_from_type_rank< typename std::decay_t< typename std::decay_t< A >::value_type >, std::decay_t< A >::rank - nvar >::type target_from_array
Deduce the target type of a Green's function from its data array type and arity.
typename std::decay_t< G >::target_t get_target_t
The target type of a block Green's function type G.
decltype(std::declval< G >()[std::declval< typename G::mesh_point_t >()]) target_value_t
The type of value obtained when accessing a Green's function of type G with a mesh point.
constexpr bool is_gf_v
Trait to check whether a type models the Green's function concept.
auto const & get_mesh(BG const &bg)
Get the mesh of a block Green's function, or its N-th component for a product mesh.
constexpr bool is_instantiation_of_v
Variable template for triqs::gfs::is_instantiation_of, decaying the tested type first.
static constexpr bool is_product
Constexpr bool that is true if the given triqs::mesh::Mesh type is a product of meshes,...
#define TRIQS_DEFINE_CONCEPT_AND_ASSOCIATED_TRAIT(MyBeautifulConcept)
Define a tag-based pseudo-concept.
#define TRIQS_CONCEPT_TAG_NAME(MyBeautifulConcept)
Helper macro that produces the name of the tag for TRIQS_DEFINE_CONCEPT_AND_ASSOCIATED_TRAIT.
Common macros used in TRIQS.
Lightweight handle bundling the target type and its shape.
Target target_t
The target type.
target_shape_t _shape
The shape of the target.
target_shape_t const & shape() const
Get the shape of the target.
Lazy expression node representing a binary operation between two Green's function operands.
typename gfs_expr_tools::_or_< typename L_t::target_t, typename R_t::target_t >::type target_t
Target type of the expression, deduced from the two operands.
Trait to detect whether a type is an instantiation of a given class template.
Provides the target types that fix the value stored at each mesh point of a Green's function.