2#ifndef SRC_APPS_MOLRESPONSE_X_SPACE_H_
3#define SRC_APPS_MOLRESPONSE_X_SPACE_H_
74 auto &world =
x[0][0].world();
76 for (
const auto &i : new_x.active) {
92 bool fence =
false) const ->
X_space {
93 auto &world =
x[0][0].world();
95 for (
int i = 0; i < new_x.num_states(); i++) {
106 this->n_states =
B.num_states();
107 this->n_orbitals =
B.num_orbitals();
110 this->active =
B.active;
155 auto &world =
A.x[0][0].world();
156 for (
auto &i :
A.active) {
172 bool fence =
true) ->
X_space {
173 auto &world =
A.x[0][0].world();
176 result.set_active(
A.active);
178 for (
auto &i : result.active) {
180 result.x[i] =
func(
A.x[i]);
181 result.y[i] =
func(
A.y[i]);
188 template <
typename T>
193 auto &world =
A.x[0][0].world();
198 for (
const auto &i : result.
active) {
205 result.
x[i] =
func(ax, bx);
206 result.
y[i] =
func(ay, by);
215 auto &world =
A.x[0][0].world();
216 for (
const auto &i :
A.active) {
234 for (
int i = 0; i < zeros.num_states(); i++) {
236 ::madness::zero_functions<double, 3>(world,
n_orbitals,
true);
238 ::madness::zero_functions<double, 3>(world,
n_orbitals,
true);
246 auto &world = this->x[
B.active.front()][0].world();
247 this->active =
B.active;
261 auto result =
X_space(
A.x[
A.active.front()][0].world(),
A.num_states(),
263 result.set_active(
A.active);
264 result.from_vector(
A.to_vector() +
B.to_vector());
271 auto result =
X_space(
A.x[
A.active.front()][0].world(),
A.num_states(),
273 result.set_active(
A.active);
274 result.from_vector(
A.to_vector() -
B.to_vector());
277 auto sub_ab = [&](
const auto &
a,
const auto &
b) {
284 World &world =
A.x[
A.active.front()][0].world();
286 auto result =
X_space(world,
A.num_states(),
A.num_orbitals());
287 result.set_active(
A.active);
288 result.from_vector(
A.to_vector() *
b);
292 scale(world, vec_ai,
b,
true);
298 World &world =
A.x[
A.active.front()][0].world();
299 auto result =
X_space(world,
A.num_states(),
A.num_orbitals());
300 result.set_active(
A.active);
301 result.from_vector(
A.to_vector() *
b);
305 scale(world, vec_ai,
b,
true);
311 World &world =
A.x[
A.active.front()][0].world();
312 auto result =
X_space(
A.x[0][0].world(),
A.num_states(),
A.num_orbitals());
313 result.set_active(
A.active);
315 mul(world,
A.to_vector(),
B.to_vector());
316 result.from_vector(result_vec);
321 return mul(world, vec_ai, vec_bi,
false);
327 World &world =
A.x[
A.active.front()][0].world();
329 auto result =
X_space(
A.x[0][0].world(),
A.num_states(),
A.num_orbitals());
330 result.set_active(
A.active);
331 result.from_vector(
A.to_vector() *
f);
335 return mul(world,
f, vec_ai,
false);
341 World &world =
A.x[
A.active.front()][0].world();
342 auto result =
X_space(
A.x[0][0].world(),
A.num_states(),
A.num_orbitals());
343 result.set_active(
A.active);
344 result.from_vector(
f *
A.to_vector());
348 return mul(world,
f, vec_ai,
false);
357 World &world =
A.x[0][0].world();
358 auto transform_ai = [&](
auto &ai) {
return transform(world, ai,
b,
true); };
371 auto &world = this->x[
x.
active.front()][0].world();
379 auto &world = this->x[
active.front()][0].world();
385 auto &world = this->x[
active.front()][0].world();
391 auto &world = this->x[
x.
active.front()][0].world();
396 World &world =
x[0][0].world();
401 for (
const auto &xb :
x) {
402 norms[
b++] =
norm2(world, xb);
409 World &world =
x[0][0].world();
424 int n =
static_cast<int>(
active.size());
430 for (
const auto &ai :
active) {
431 for (
int j = 0; j <
m; j++) {
432 auto xindex = (2 * i *
m) + j;
433 auto yindex = (2 * i *
m) + j +
m;
434 rf[xindex] =
x[ai][j];
435 rf[yindex] =
y[ai][j];
447 for (
const auto &ai :
active) {
448 for (
int j = 0; j <
m; j++) {
449 auto xindex = (2 * i *
m) + j;
450 auto yindex = (2 * i *
m) + j +
m;
452 x[ai][j] = rf[xindex];
453 y[ai][j] = rf[yindex];
476 World &world =
A.x[0][0].world();
478 result.
x =
A.x -
B.x;
479 result.
y =
A.y -
B.y;
483 World &world =
A.x[0][0].world();
510 World &world =
A.x[0][0].world();
518 for (
auto &ayi : ay) {
521 for (
auto &byi : by) {
525 double result =
inner(ax, bx);
570 response_space &chi);
585 subset[j] = rf[index + j];
595 subset[j] = rf[index + j];
614 subset[j] = rf[index + j];
Definition test_ar.cc:118
Definition test_ar.cc:141
Definition test_derivative.cc:24
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
A multiresolution adaptive numerical function.
Definition mra.h:139
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:69
A tensor is a multidimensional array.
Definition tensor.h:317
Interface to be provided by any process map.
Definition worlddc.h:82
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
A parallel world class.
Definition world.h:132
WorldGopInterface & gop
Global operations.
Definition world.h:207
response_space_index(int num_orbitals)
Definition x_space.h:605
int num_orbitals
Definition x_space.h:602
vector_real_function_3d get_x_state(int i, const vector_real_function_3d &rf) const
Definition x_space.h:608
vector_real_function_3d get_y_state(int i, const vector_real_function_3d &rf) const
Definition x_space.h:590
x_space_indexer(int num_orbitals)
Definition x_space.h:576
vector_real_function_3d get_x_state(int i, const vector_real_function_3d &rf) const
Definition x_space.h:579
int num_orbitals
Definition x_space.h:573
Provides typedefs to hide use of templates and to increase interoperability.
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:28
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
Function< TENSOR_RESULT_TYPE(L, R), NDIM > gaxpy_oop(TENSOR_RESULT_TYPE(L, R) alpha, const Function< L, NDIM > &left, TENSOR_RESULT_TYPE(L, R) beta, const Function< R, NDIM > &right, bool fence=true)
Returns new function alpha*left + beta*right optional fence and no automatic compression.
Definition mra.h:1981
response_space scale(response_space a, double b)
Tensor< double > norm2s_T(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition vmra.h:858
auto to_X_space(const response_matrix &x) -> X_space
Definition x_space.cc:108
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition mra.h:1765
std::vector< vector_real_function_3d > response_matrix
Definition response_functions.h:20
void truncate(World &world, response_space &v, double tol, bool fence)
Definition basic_operators.cc:31
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:707
auto to_conjugate_X_space(const response_matrix &x) -> X_space
response_matrix [x,y] -> Xspace X.x=y X.y=conjugate(x)
Definition x_space.cc:133
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition vmra.h:149
const std::vector< Function< T, NDIM > > & reconstruct(const std::vector< Function< T, NDIM > > &v)
reconstruct a vector of functions
Definition vmra.h:162
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition vmra.h:871
void copyToResponseSpace(const vector_real_function_3d &rf, response_space &chi)
Definition x_space.cc:271
std::vector< real_function_3d > vector_real_function_3d
Definition functypedefs.h:94
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
auto create_response_matrix(const size_t &num_states, const size_t &num_orbitals) -> response_matrix
Create a response matrix object.
Definition x_space.cc:40
FunctionFactory< double, 3 > real_factory_3d
Definition functypedefs.h:108
NDIM & f
Definition mra.h:2481
auto to_response_vector(const vector_real_function_3d &vec) -> vector_real_function_3d
Definition x_space.cc:15
Function< double, 3 > real_function_3d
Definition functypedefs.h:80
void copyToXspace(const vector_real_function_3d &rf, X_space &chi)
Definition x_space.cc:233
auto to_response_matrix(const X_space &x) -> response_matrix
Definition x_space.cc:56
vector_real_function_3d copyToVector(const X_space &chi)
Definition x_space.cc:212
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
auto to_conjugate_response_matrix(const X_space &x) -> response_matrix
Definition x_space.cc:71
auto to_flattened_vector(const X_space &x) -> vector_real_function_3d
Flattens all response functions into a single vector of functions.
Definition x_space.cc:92
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2066
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const double thresh
Definition rk.cc:45
Definition test_ar.cc:261
auto norm2s() const -> Tensor< double >
Definition x_space.h:395
void compress() const
Definition x_space.h:376
friend auto operator+(const X_space &A, const X_space &B) -> X_space
Definition x_space.h:258
auto operator=(const X_space &B) -> X_space &
Definition x_space.h:103
X_space(const X_space &A)
Definition x_space.h:70
void reset_active()
Definition x_space.h:48
void clear()
Definition x_space.h:120
size_t num_states() const
Definition x_space.h:43
std::list< size_t > active
Definition x_space.h:40
friend auto inner(const X_space &A, const X_space &B) -> Tensor< double >
Computes the matrix elements between two response spaces.
Definition x_space.cc:185
auto to_vector() const -> vector_real_function_3d
Definition x_space.h:422
static X_space zero_functions(World &world, size_t n_states, size_t n_orbitals)
Definition x_space.h:231
friend X_space operator*(const X_space &A, const double &b)
Definition x_space.h:283
friend auto operator*(const X_space &A, const Tensor< double > &b) -> X_space
Definition x_space.h:353
X_space copy() const
Definition x_space.h:73
friend auto operator*(const Function< double, 3 > &f, const X_space &A) -> X_space
Definition x_space.h:339
auto operator+=(const X_space &B) -> X_space &
Definition x_space.h:244
auto component_norm2s() const -> Tensor< double >
Definition x_space.h:408
size_t num_orbitals() const
Definition x_space.h:44
friend auto size_orbitals(const X_space &x) -> size_t
Definition x_space.h:416
friend auto inplace_apply(X_space &A, const std::function< void(vector_real_function_3d &)> &func) -> void
Definition x_space.h:152
void reconstruct() const
Definition x_space.h:382
size_t n_states
Definition x_space.h:35
friend auto binary_inplace(X_space &A, const X_space &B, const T &func)
Definition x_space.h:213
friend X_space operator-(const X_space &A, const X_space &B)
Definition x_space.h:268
friend auto oop_apply(const X_space &A, const std::function< vector_real_function_3d(const vector_real_function_3d &)> &func, bool fence=true) -> X_space
Apply a function to the X_space.
Definition x_space.h:169
X_space(World &world, size_t n_states, size_t n_orbitals)
Definition x_space.h:114
void push_back(const vector_real_function_3d &vx, const vector_real_function_3d &vy)
Definition x_space.h:125
auto from_vector(const vector_real_function_3d &rf) -> void
Definition x_space.h:442
friend X_space operator*(const X_space &B, const X_space &A)
Definition x_space.h:310
response_space y
Definition x_space.h:39
response_space x
Definition x_space.h:39
friend auto same_size(const X_space &A, const X_space &B) -> bool
Definition x_space.h:417
void truncate()
Definition x_space.h:369
friend X_space operator*(const double &b, const X_space &A)
Definition x_space.h:297
X_space()
Definition x_space.h:46
void set_active(const std::list< size_t > &new_active)
Definition x_space.h:65
size_t n_orbitals
Definition x_space.h:36
friend auto binary_apply(const X_space &A, const X_space &B, T &func) -> X_space
Definition x_space.h:189
auto copy(const std::shared_ptr< WorldDCPmapInterface< Key< 3 > > > &p_map, bool fence=false) const -> X_space
Definition x_space.h:91
void truncate(double thresh)
Definition x_space.h:389
friend X_space operator*(const X_space &A, const Function< double, 3 > &f)
Definition x_space.h:326
void pop_back()
Definition x_space.h:142
friend auto size_states(const X_space &x) -> size_t
Definition x_space.h:415
X_vector(World &world, size_t n_orbtials)
Definition x_space.h:464
auto operator+=(const X_vector &B) -> X_vector &
Definition x_space.h:495
X_vector(X_space A, size_t b)
Definition x_space.h:468
friend X_vector operator-(const X_vector &A, const X_vector &B)
Definition x_space.h:473
X_vector copy() const
Definition x_space.h:489
friend X_vector operator*(const X_vector &A, const double &c)
Definition x_space.h:482
friend auto inner(X_vector &A, X_vector &B) -> double
Definition x_space.h:501
real_function_3d operator()()
Definition x_space.h:553
World & world
Definition x_space.h:550
response_function_allocator(World &world)
Definition x_space.h:551
response_function_allocator operator=(const response_function_allocator &other)
Definition x_space.h:557
World & world
Definition x_space.h:532
vector_real_function_3d operator()()
Definition x_space.h:537
response_matrix_allocator(World &world, size_t n_orbtials)
Definition x_space.h:534
const size_t n_orbtials
Definition x_space.h:533
response_matrix_allocator operator=(const response_matrix_allocator &other)
Definition x_space.h:544
Definition response_functions.h:27
void push_back(const vector_real_function_3d &f)
Definition response_functions.h:409
size_t num_orbitals
Definition response_functions.h:36
void pop_back()
Definition response_functions.h:424
response_space copy() const
Definition response_functions.h:142
std::list< size_t > active
Definition response_functions.h:38
void clear()
Definition response_functions.h:437
Defines and implements most of Tensor.
int G2
Definition testperiodic.cc:64