35 #ifndef MADNESS_DERIVATIVE_H__INCLUDED
36 #define MADNESS_DERIVATIVE_H__INCLUDED
57 template<
typename T, std::
size_t NDIM>
60 template<
typename T, std::
size_t NDIM>
72 template <
typename T, std::
size_t NDIM>
80 const std::vector<long>
vk;
88 typedef std::pair<keyT,coeffT>
argT ;
112 const argT& right)
const {
117 if (owner == world.
rank()) {
118 if (!left.second.has_data()) {
123 else if (!right.second.has_data()) {
129 else if (left.first.is_invalid() || right.first.is_invalid()) {
131 f, df, key, left, center, right);
136 f, df, key, left, center, right);
149 const argT& right)
const {
150 MADNESS_ASSERT(axis<
NDIM);
153 if ((!left.second.has_data()) || (!right.second.has_data())) {
157 const keyT& child = kit.key();
174 virtual Void do_diff2b(
const implT*
f, implT* df,
const keyT& key,
177 const argT& right)
const = 0;
179 virtual Void do_diff2i(
const implT*
f, implT* df,
const keyT& key,
182 const argT& right)
const = 0;
197 MADNESS_EXCEPTION(
"diff: trying to diff a compressed function without fencing",0);
217 MADNESS_ASSERT(bc_left == bc_right);
223 else if (l >= two2n) {
229 MADNESS_ASSERT(bc_left == bc_right);
263 template <
typename Archive>
void serialize(
const Archive& ar)
const {
264 throw "NOT IMPLEMENTED";
271 template <
typename T, std::
size_t NDIM>
280 typedef std::pair<keyT,coeffT>
argT ;
291 Tensor<double> rm, r0, rp ;
292 Tensor<double> rmt, r0t, rpt ;
293 Tensor<double> left_rm, left_r0 ;
294 Tensor<double> left_rmt, left_r0t ;
295 Tensor<double> right_r0, right_rp;
296 Tensor<double> right_r0t, right_rpt;
297 Tensor<double> bv_left, bv_right ;
299 Void do_diff2b(
const implT*
f, implT* df,
const keyT& key,
302 const argT& right)
const {
304 double lev = (double) key.
level();
309 if (l[this->
axis] == 0) {
311 coeffT tensor_right=df->
parent_to_child(right.second, right.first, this->neighbor(key,1));
312 coeffT tensor_center=df->
parent_to_child(center.second, center.first, key);
319 coeffT tensor_left=df->
parent_to_child(left.second, left.first, this->neighbor(key,-1));
320 coeffT tensor_center=df->
parent_to_child(center.second, center.first, key);
332 int bc_left = this->
bc(this->
axis,0);
333 int bc_right = this->
bc(this->
axis,1);
338 if (l[this->
axis] == 0) {
341 found_argT = g1.
get_impl()->find_me(key);
350 found_argT = g2.
get_impl()->find_me(key);
356 tensorT gcoeffs = df->
parent_to_child(found_argT.
get().second, found_argT.
get().first,key).full_tensor_copy();
360 bdry_t = gcoeffs[0]*bf;
363 tensorT slice_aid(this->
k);
365 tensorT tmp =
inner(slice_aid, gcoeffs, 0, this->
axis);
366 bdry_t =
outer(bf,tmp);
367 if (this->
axis) bdry_t =
copy(bdry_t.cycledim(this->axis,0,this->axis));
371 if (l[this->
axis]==0) {
373 bdry_t.scale( pow(2.0,lev));
379 bdry_t.scale( pow(2.0,lev));
390 Void do_diff2i(
const implT*
f, implT*df,
const keyT& key,
393 const argT& right)
const
412 coeffT tensor_left=df->parent_to_child(left.second, left.first, this->neighbor(key,-1));
413 coeffT tensor_center=df->parent_to_child(center.second, center.first, key);
414 coeffT tensor_right=df->parent_to_child(right.second, right.first, this->neighbor(key,1));
421 d.reduce_rank(df->get_thresh());
422 df->get_coeffs().replace(key,
nodeT(d,
false));
430 void initCoefficients() {
431 r0 = Tensor<double>(this->
k,this->
k);
432 rp = Tensor<double>(this->
k,this->
k);
433 rm = Tensor<double>(this->
k,this->
k);
435 left_rm = Tensor<double>(this->
k,this->
k);
436 left_r0 = Tensor<double>(this->
k,this->
k);
438 right_r0 = Tensor<double>(this->
k,this->
k);
439 right_rp = Tensor<double>(this->
k,this->
k);
442 bv_left = Tensor<double>(this->
k);
443 bv_right = Tensor<double>(this->
k);
446 int bc_left = this->
bc(this->
axis,0);
447 int bc_right = this->
bc(this->
axis,1);
449 double kphase = -1.0;
450 if (this->k%2 == 0) kphase = 1.0;
452 for (
int i=0; i<this->
k; ++i) {
454 for (
int j=0; j<this->
k; ++j) {
455 double gammaij =
sqrt(
double((2*i+1)*(2*j+1)));
457 if (((i-j)>0) && (((i-j)%2)==1))
462 r0(i,j) = 0.5*(1.0 - iphase*jphase - 2.0*Kij)*gammaij;
463 rm(i,j) = 0.5*jphase*gammaij;
464 rp(i,j) =-0.5*iphase*gammaij;
468 left_rm(i,j) = jphase*gammaij*0.5*(1.0 + iphase*kphase/this->
k);
470 double phi_tmpj_left = 0;
472 for (
int l=0; l<this->
k; ++l) {
473 double gammalj =
sqrt(
double((2*l+1)*(2*j+1)));
476 if (((l-j)>0) && (((l-j)%2)==1)) Klj = 2.0;
479 phi_tmpj_left +=
sqrt(
double(2*l+1))*Klj*gammalj;
481 phi_tmpj_left = -jphase*phi_tmpj_left;
482 left_r0(i,j) = (0.5*(1.0 + iphase*kphase/this->
k) - Kij)*gammaij + iphase*
sqrt(
double(2*i+1))*phi_tmpj_left/
pow(this->k,2.);
485 left_rm(i,j) = rm(i,j);
489 left_r0(i,j) = (0.5 - Kij)*gammaij;
493 left_r0(i,j) = (0.5 - iphase*jphase - Kij)*gammaij;
498 right_rp(i,j) = -0.5*(iphase + kphase / this->
k)*gammaij;
500 double phi_tmpj_right = 0;
501 for (
int l=0; l<this->
k; ++l) {
502 double gammalj =
sqrt(
double((2*l+1)*(2*j+1)));
504 if (((l-j)>0) && (((l-j)%2)==1)) Klj = 2.0;
506 phi_tmpj_right +=
sqrt(
double(2*l+1))*Klj*gammalj;
508 right_r0(i,j) = -(0.5*jphase*(iphase+ kphase/this->
k) + Kij)*gammaij +
sqrt(
double(2*i+1))*phi_tmpj_right/
pow(this->k,2.);
511 right_rp(i,j) = rp(i,j);
515 right_r0(i,j) = -(0.5*iphase*jphase + Kij)*gammaij;
519 right_r0(i,j) = (1.0 - 0.5*iphase*jphase - Kij)*gammaij;
530 for (
int i=0; i<this->
k; ++i) {
534 bv_left(i) = iphase*
sqrt(
double(2*i+1));
536 bv_left(i) = -iphase*
sqrt(
double(2*i+1))/
pow(this->k,2.);
541 bv_right(i) =
sqrt(
double(2*i+1));
543 bv_right(i) =
sqrt(
double(2*i+1))/
pow(this->k,2.);
583 MADNESS_ASSERT(axis<
NDIM);
596 template <
typename T, std::
size_t NDIM>
604 template <
typename T, std::
size_t NDIM>
611 template <
typename T, std::
size_t NDIM>
622 template <
typename T, std::
size_t NDIM>
623 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
627 std::vector< std::shared_ptr< Derivative<T,NDIM> > > r(
NDIM);
628 for (std::size_t d=0; d<
NDIM; ++d) {
638 template <
class Archive,
class T, std::
size_t NDIM>
647 template <
class Archive,
class T, std::
size_t NDIM>
657 #endif // MADNESS_MRA_DERIVATIVE_H_INCLUDED
void process_pending()
To be called from derived constructor to process pending messages.
Definition: worldobj.h:330
Makes a distributed container with specified attributes.
Definition: worlddc.h:55
virtual ~DerivativeBase()
Definition: derivative.h:107
Future< argT > find_neighbor(const implT *f, const Key< NDIM > &key, int step) const
Definition: derivative.h:250
GenTensor< T > full_tensor_copy() const
Definition: gentensor.h:184
double get_thresh() const
Definition: mraimpl.h:281
static TaskAttributes hipri()
Definition: worldthread.h:277
Header to declare stuff which has not yet found a home.
FunctionDefaults holds default paramaters as static class members.
Definition: funcdefaults.h:175
FunctionImpl< T, NDIM > implT
Definition: derivative.h:89
std::pair< keyT, coeffT > argT
Definition: derivative.h:280
const Vector< Translation, NDIM > & translation() const
Definition: key.h:225
const mpreal pow(const mpreal &a, const unsigned int b, mp_rnd_t rnd_mode=mpreal::default_rnd)
Definition: mpreal.h:2788
const int NDIM
Definition: tdse1.cc:44
Function< T, NDIM > functionT
Definition: derivative.h:282
DerivativeBase(World &world, std::size_t axis, int k, BoundaryConditions< NDIM > bc)
Definition: derivative.h:95
Implements derivatives operators with variety of boundary conditions on simulation domain...
Definition: derivative.h:272
virtual Void do_diff2i(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const =0
const std::shared_ptr< FunctionImpl< T, NDIM > > & get_impl() const
Returns a shared-pointer to the implementation.
Definition: mra.h:589
Function< T, NDIM > operator()(const functionT &f, bool fence=true) const
Differentiate w.r.t. given coordinate (x=0, y=1, ...) with optional fence.
Definition: derivative.h:189
GenTensor< T > outer(const GenTensor< T > &left, const GenTensor< T > &right)
Outer product ... result(i,j,...,p,q,...) = left(i,k,...)*right(p,q,...)
Definition: gentensor.h:230
Provides a tensor with taking advantage of possibly low rank.
static bool enforce_bc(int bc_left, int bc_right, Level n, Translation &l)
Definition: derivative.h:209
virtual Void do_diff2b(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const =0
Void do_diff1(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition: derivative.h:146
WorldContainer< Key< NDIM >, FunctionNode< T, NDIM > > dcT
Definition: derivative.h:91
Derivative< T, NDIM > free_space_derivative(World &world, int axis, int k=FunctionDefaults< NDIM >::get_k())
Convenience function returning derivative operator with free-space boundary conditions.
Definition: derivative.h:598
const uniqueidT & id() const
Returns the globally unique object ID.
Definition: worldobj.h:377
NDIM & f
Definition: mra.h:2179
void verify_tree() const
Verifies the tree data structure ... global sync implied.
Definition: mra.h:452
Definition: funcdefaults.h:56
Provides FunctionDefaults and utilities for coordinate transformation.
Default store of a thingy via serialize(ar,t)
Definition: archive.h:708
const coeffT parent_to_child(const coeffT &s, const keyT &parent, const keyT &child) const
Directly project parent coeffs to child coeffs.
Definition: mraimpl.h:2983
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition: funcdefaults.h:48
This header should include pretty much everything needed for the parallel runtime.
bool is_invalid() const
Checks if a key is invalid.
Definition: key.h:152
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product
Definition: nemo.h:112
Defines and implements most of Tensor.
TensorType get_tensor_type() const
Definition: mraimpl.h:275
FunctionImpl< T, NDIM > implT
Definition: derivative.h:281
FunctionNode< T, NDIM > nodeT
Definition: derivative.h:284
static void store(const Archive &ar, const DerivativeBase< T, NDIM > *const &ptr)
Definition: derivative.h:649
Void sock_it_to_me(const keyT &key, const RemoteReference< FutureImpl< std::pair< keyT, coeffT > > > &ref) const
Walk up the tree returning pair(key,node) for first node with coefficients.
Definition: mraimpl.h:2678
GenTensor< T > coeffT
Definition: derivative.h:278
T & get()
Gets the value, waiting if necessary (error if not a local future)
Definition: worldfut.h:513
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
Key< NDIM > neighbor(const keyT &key, int step) const
Definition: derivative.h:238
void reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm...
Definition: mra.h:737
Void forward_do_diff1(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition: derivative.h:109
Key< NDIM > keyT
Definition: derivative.h:87
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6,a7,a8,a9)".
Definition: worldobj.h:493
GenTensor< T > coeffT
Definition: derivative.h:86
static Key< NDIM > invalid()
Returns an invalid key.
Definition: key.h:146
const BoundaryConditions< NDIM > bc
Definition: derivative.h:79
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:1835
Tensor< TENSOR_RESULT_TYPE(T, Q)> transform_dir(const Tensor< T > &t, const Tensor< Q > &c, int axis)
Transforms one dimension of the tensor t by the matrix c, returns new contiguous tensor.
Definition: tensor.h:1929
Tensor< T > tensorT
Definition: derivative.h:277
void replace(const pairT &datum)
Inserts/replaces key+value pair (non-blocking communication if key not local)
Definition: worlddc.h:727
This class is used to specify boundary conditions for all operatorsExterior boundary conditions (i...
Definition: funcdefaults.h:72
Level level() const
Definition: key.h:220
void reduce_rank(const double &eps)
Definition: gentensor.h:193
Default load of a thingy via serialize(ar,t)
Definition: archive.h:718
const int k
Definition: derivative.h:78
Function< T, NDIM > functionT
Definition: derivative.h:90
Implements most parts of a globally addressable object (via unique ID)
Definition: worldam.h:74
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
Definition: funcdefaults.h:56
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
Tensor< T > tensorT
Definition: derivative.h:85
A multiresolution adaptive numerical function.
Definition: derivative.h:61
int Level
Definition: key.h:58
static void load(const Archive &ar, const DerivativeBase< T, NDIM > *&ptr)
Definition: derivative.h:640
Derivative(World &world, std::size_t axis, const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), const functionT g1=functionT(), const functionT g2=functionT(), int k=FunctionDefaults< NDIM >::get_k())
Constructs a derivative operator.
Definition: derivative.h:573
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
const std::size_t axis
Definition: derivative.h:77
void serialize(const Archive &ar) const
Definition: derivative.h:263
T opT
Definition: derivative.h:563
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition: derivative.h:58
Tri-diagonal operator traversing tree primarily for derivative operator.
Definition: derivative.h:73
ProcessID rank() const
Returns the process rank in this world (same as MPI_Comm_rank()))
Definition: worldfwd.h:526
Defines simple templates for printing to std::cout "a la Python".
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication)
Definition: worlddc.h:786
virtual ~Derivative()
Definition: derivative.h:591
void set_impl(const std::shared_ptr< FunctionImpl< T, NDIM > > &impl)
Replace current FunctionImpl with provided new one.
Definition: mra.h:596
FunctionNode< T, NDIM > nodeT
Definition: derivative.h:92
World & world
Definition: derivative.h:76
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition: worldfut.h:552
Derivative< T, NDIM > periodic_derivative(World &world, int axis, int k=FunctionDefaults< NDIM >::get_k())
Conveinence function returning derivative operator with periodic boundary conditions.
Definition: derivative.h:606
Key< NDIM > keyT
Definition: derivative.h:279
WorldContainer< Key< NDIM >, FunctionNode< T, NDIM > > dcT
Definition: derivative.h:283
Implements WorldContainer.
Definition: funcdefaults.h:56
A future is a possibly yet unevaluated value.
Definition: ref.h:210
A type you can return when you want to return void ... use "return None".
Definition: typestuff.h:154
Definition: funcdefaults.h:56
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition: tensor.h:1945
Definition: funcdefaults.h:56
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
Multidimension Key for MRA tree and associated iterators.
Definition: gentensor.h:123
std::vector< std::shared_ptr< Derivative< T, NDIM > > > gradient_operator(World &world, const BoundaryConditions< NDIM > &bc=FunctionDefaults< NDIM >::get_bc(), int k=FunctionDefaults< NDIM >::get_k())
Convenience function returning vector of derivative operators implementing grad ( ) ...
Definition: derivative.h:624
int64_t Translation
Definition: key.h:57
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const dcT & get_coeffs() const
Definition: mraimpl.h:296
Function< T, NDIM > apply(const Derivative< T, NDIM > &D, const Function< T, NDIM > &f, bool fence=true)
Applies derivative operator to function (for syntactic equivalence to integral operator apply) ...
Definition: derivative.h:613
Definition: funcdefaults.h:56
const std::vector< long > vk
(k,...) used to initialize Tensors
Definition: derivative.h:80
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
TensorArgs get_tensor_args() const
Definition: mraimpl.h:278
bool is_compressed() const
Returns true if compressed, false otherwise. No communication.
Definition: mra.h:461
std::pair< keyT, coeffT > argT
Definition: derivative.h:88
Iterates in lexical order thru all children of a key.
Definition: key.h:61