32#ifndef MADNESS_DERIVATIVE_H__INCLUDED
33#define MADNESS_DERIVATIVE_H__INCLUDED
56 template<
typename T, std::
size_t NDIM>
59 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 ;
117 const argT& right)
const {
119 const dcT& coeffs =
f->get_coeffs();
123 if (!left.second.has_data()) {
128 else if (!right.second.has_data()) {
134 else if (left.first.is_invalid() || right.first.is_invalid()) {
136 f, df, key, left, center, right);
141 f, df, key, left, center, right);
153 const argT& right)
const {
157 if ((!left.second.has_data()) || (!right.second.has_data())) {
180 const argT& right)
const = 0;
185 const argT& right)
const = 0;
195 MADNESS_CHECK_THROW(
f.is_reconstructed(),
"diff: trying to diff a compressed function without fencing");
200 df.
get_impl()->diff(
this,
f.get_impl().get(), fence);
219 else if (l >=
two2n) {
252 const dcT& coeffs =
f->get_coeffs();
253 std::map<ProcessID, std::vector<argT> > out;
254 for (
const auto& [key,
node] : coeffs) {
255 for (
int step : {-1, 1}) {
257 if (
consumer.is_invalid())
continue;
271 if (
neigh.is_invalid()) {
279 if (
f->get_coeffs().is_local(
neigh))
297 const keyT& key = it->first;
299 if (
node.has_coeff()) {
317 rangeT(
f->get_coeffs().begin(),
f->get_coeffs().end()),
submit_op(
this,
f, df));
321 throw "NOT IMPLEMENTED";
328 template <
typename T, std::
size_t NDIM>
337 typedef std::pair<keyT,coeffT>
argT ;
371 const argT& right)
const {
378 if (l[this->
axis] == 0) {
411 if (l[this->
axis] == 0) {
430 std::cerr <<
"FATAL ERROR: PaRSEC does not support recursive task execution but Derivative::do_diff2b requires this. Use a different backend" << std::endl;
449 if (l[this->
axis]==0) {
462 bdry_t +=
d.full_tensor_copy();;
469 const argT& right)
const
529 if (this->
k%2 == 0) kphase = 1.0;
531 for (
int i=0; i<this->
k; ++i) {
533 for (
int j=0; j<this->
k; ++j) {
536 if (((i-j)>0) && (((i-j)%2)==1))
551 for (
int l=0; l<this->
k; ++l) {
555 if (((l-j)>0) && (((l-j)%2)==1))
Klj = 2.0;
580 for (
int l=0; l<this->
k; ++l) {
583 if (((l-j)>0) && (((l-j)%2)==1))
Klj = 2.0;
609 for (
int i=0; i<this->
k; ++i) {
677 if(
k > 18)
throw "Bspline derivatives are only available up to k=18";
684 if(
k > 18)
throw "Bspline derivatives are only available up to k=18";
691 if(
k > 18)
throw "Bspline derivatives are only available up to k=18";
698 if(
k > 15)
throw "BLE derivatives are only available up to k=15";
705 if(
k > 15)
throw "BLE derivatives are only available up to k=15";
719 for (
int m;
f >>
m; ) {
721 for (
int i=0; i<
m; i++)
722 for (
int j=0; j<
m; j++)
724 for (
int i=0; i<
m; i++)
725 for (
int j=0; j<
m; j++)
727 for (
int i=0; i<
m; i++)
728 for (
int j=0; j<
m; j++)
735 for (
int i=0; i<3*
m*
m; i++)
754 else if(order == 2) {
757 else if(order == 3) {
765 template <
typename T, std::
size_t NDIM>
773 template <
typename T, std::
size_t NDIM>
780 template <
typename T, std::
size_t NDIM>
791 template <
typename T, std::
size_t NDIM>
792 std::vector< std::shared_ptr< Derivative<T,NDIM> > >
796 std::vector< std::shared_ptr< Derivative<T,NDIM> > > r(
NDIM);
797 for (std::size_t
d=0;
d<
NDIM; ++
d) {
807 template <
class Archive,
class T, std::
size_t NDIM>
816 template <
class Archive,
class T, std::
size_t NDIM>
This header should include pretty much everything needed for the parallel runtime.
This class is used to specify boundary conditions for all operators.
Definition bc.h:72
Tri-diagonal operator traversing tree primarily for derivative operator.
Definition derivative.h:73
void submit_diff_tasks(const implT *f, implT *df) const
Parallel form of FunctionImpl::diff's submission loop; the caller owns the fence.
Definition derivative.h:314
void do_diff1(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition derivative.h:150
GenTensor< T > coeffT
holding the node's coeffs (possibly low rank)
Definition derivative.h:86
static bool enforce_bc(int bc_left, int bc_right, Level n, Translation &l)
Definition derivative.h:205
DerivativeBase(World &world, std::size_t axis, int k, BoundaryConditions< NDIM > bc)
Definition derivative.h:100
Key< NDIM > keyT
Definition derivative.h:87
const BoundaryConditions< NDIM > bc
Definition derivative.h:79
Tensor< T > tensorT
regular tensors, like rm, etc
Definition derivative.h:85
const std::vector< long > vk
(k,...) used to initialize Tensors
Definition derivative.h:80
Key< NDIM > neighbor(const keyT &key, int step) const
Definition derivative.h:234
WorldContainer< Key< NDIM >, FunctionNode< T, NDIM > > dcT
Definition derivative.h:91
virtual ~DerivativeBase()
Definition derivative.h:112
FunctionImpl< T, NDIM > implT
Definition derivative.h:89
FunctionNode< T, NDIM > nodeT
Definition derivative.h:92
Function< T, NDIM > functionT
Definition derivative.h:90
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:114
const int k
Number of wavelets of the function.
Definition derivative.h:78
WorldObject< DerivativeBase< T, NDIM > > woT
Definition derivative.h:74
void serialize(const Archive &ar) const
Definition derivative.h:320
Future< argT > find_neighbor(const implT *f, const Key< NDIM > &key, int step) const
Definition derivative.h:269
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:192
void stage_halo(const implT *f, bool fence=true) const
Push f's remote same-level neighbor coefficients to the ranks that will need them.
Definition derivative.h:251
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::size_t axis
Axis along which the operation is performed.
Definition derivative.h:77
World & world
Definition derivative.h:76
virtual void do_diff2b(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const =0
bool parallel_submit_
Spawn diff's per-node tasks from the task pool instead of the main thread.
Definition derivative.h:98
std::pair< keyT, coeffT > argT
Definition derivative.h:88
Implements derivatives operators with variety of boundary conditions on simulation domain.
Definition derivative.h:329
Tensor< double > right_r0t
Definition derivative.h:356
void set_ble2()
Definition derivative.h:703
Tensor< double > rmt
Definition derivative.h:352
Tensor< double > bv_left
Definition derivative.h:357
void set_bspline1()
Definition derivative.h:675
Tensor< double > r0
Definition derivative.h:351
Tensor< double > rp_bsp
Definition derivative.h:363
bool is_second
Definition derivative.h:347
Tensor< double > right_rp
Blocks of the derivative for the right boundary.
Definition derivative.h:355
void set_is_second()
Definition derivative.h:672
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:651
Function< T, NDIM > functionT
Definition derivative.h:339
Tensor< double > r0t
Definition derivative.h:352
std::pair< keyT, coeffT > argT
Definition derivative.h:337
FunctionImpl< T, NDIM > implT
Definition derivative.h:338
Tensor< double > right_rpt
Blocks of the derivative for the right boundary.
Definition derivative.h:356
Tensor< double > left_rmt
Definition derivative.h:354
Tensor< double > rp_bsp_t
Definition derivative.h:366
virtual ~Derivative()
Definition derivative.h:669
GenTensor< T > coeffT
holding the node's coeffs (possibly low rank)
Definition derivative.h:335
const functionT g2
Function describing the boundary condition on the left side.
Definition derivative.h:345
void read_from_file(const std::string &filename, unsigned int order=1)
Definition derivative.h:710
Tensor< double > rp
Blocks of the derivative operator.
Definition derivative.h:351
void do_diff2i(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition derivative.h:466
bool is_third
Definition derivative.h:348
void set_bspline3()
Definition derivative.h:689
Tensor< double > rm_bsp
Definition derivative.h:362
void set_bspline2()
Definition derivative.h:682
Tensor< double > rm
Definition derivative.h:351
void initCoefficients()
Definition derivative.h:507
Tensor< double > left_r0
Blocks of the derivative for the left boundary.
Definition derivative.h:353
Tensor< double > rpt
Blocks of the derivative operator, transposed.
Definition derivative.h:352
void do_diff2b(const implT *f, implT *df, const keyT &key, const argT &left, const argT ¢er, const argT &right) const
Definition derivative.h:368
void set_is_third()
Definition derivative.h:673
T opT
Definition derivative.h:641
Tensor< double > rm_bsp_t
Definition derivative.h:365
Tensor< double > left_r0t
Blocks of the derivative for the left boundary.
Definition derivative.h:354
Tensor< T > tensorT
Definition derivative.h:334
void set_is_first()
Definition derivative.h:671
FunctionNode< T, NDIM > nodeT
Definition derivative.h:341
Tensor< double > bv_right
Blocks of the derivative operator for the boundary contribution.
Definition derivative.h:357
Key< NDIM > keyT
Definition derivative.h:336
const functionT g1
Function describing the boundary condition on the right side.
Definition derivative.h:344
void set_ble1()
Definition derivative.h:696
Tensor< double > left_rm
Definition derivative.h:353
WorldContainer< Key< NDIM >, FunctionNode< T, NDIM > > dcT
Definition derivative.h:340
Tensor< double > r0_bsp
Definition derivative.h:361
Tensor< double > right_r0
Definition derivative.h:355
DerivativeBase< T, NDIM > baseT
Definition derivative.h:331
Tensor< double > r0_bsp_t
Definition derivative.h:364
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
static int get_k()
Returns the default wavelet order.
Definition funcdefaults.h:164
static const Tensor< double > & get_rcell_width()
Returns the reciprocal of the width of each user cell dimension.
Definition funcdefaults.h:386
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:968
World & world
Definition funcimpl.h:987
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:2859
double get_thresh() const
Definition mraimpl.h:328
void receive_halo(const std::vector< std::pair< keyT, coeffT > > &buf) const
Insert pushed neighbor nodes into the halo; runs as a task, concurrently with other pushes.
Definition funcimpl.h:1050
TensorType get_tensor_type() const
Definition mraimpl.h:319
void do_diff1(const DerivativeBase< T, NDIM > *D, const implT *f, const keyT &key, const std::pair< keyT, coeffT > &left, const std::pair< keyT, coeffT > ¢er, const std::pair< keyT, coeffT > &right)
Definition mraimpl.h:943
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:3281
const dcT & get_coeffs() const
Definition mraimpl.h:343
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:136
A multiresolution adaptive numerical function.
Definition mra.h:144
const std::shared_ptr< FunctionImpl< T, NDIM > > & get_impl() const
Returns a shared-pointer to the implementation.
Definition mra.h:724
const Function< T, NDIM > & reconstruct(bool fence=true) const
Reconstructs the function, transforming into scaling function basis. Possible non-blocking comm.
Definition mra.h:916
void set_impl(const std::shared_ptr< FunctionImpl< T, NDIM > > &impl)
Replace current FunctionImpl with provided new one.
Definition mra.h:731
A future is a possibly yet unevaluated value.
Definition future.h:370
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition future.h:672
Definition lowranktensor.h:59
Tensor< T > full_tensor_copy() const
Definition gentensor.h:206
Iterates in lexical order thru all children of a key.
Definition key.h:548
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Level level() const
Definition key.h:169
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
static Key< NDIM > invalid()
Returns an invalid key.
Definition key.h:110
Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with c...
Definition range.h:64
iteratorT iterator
Alias for the iterator type.
Definition range.h:71
static TaskAttributes hipri()
Definition thread.h:456
A tensor is a multidimensional array.
Definition tensor.h:318
A simple, fixed dimension vector.
Definition vector.h:64
Makes a distributed container with specified attributes.
Definition worlddc.h:1127
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication)
Definition worlddc.h:1321
void replace(const pairT &datum)
Inserts/replaces key+value pair (non-blocking communication if key not local)
Definition worlddc.h:1261
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:176
Implements most parts of a globally addressable object (via unique ID).
Definition world_object.h:366
const uniqueidT & id() const
Returns the globally unique object ID.
Definition world_object.h:713
void process_pending()
To be called from derived constructor to process pending messages.
Definition world_object.h:658
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)().
Definition world_object.h:1007
void add(TaskInterface *t)
Add a new local task, taking ownership of the pointer.
Definition world_task_queue.h:466
A parallel world class.
Definition world.h:132
WorldTaskQueue & taskq
Task queue.
Definition world.h:206
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:320
WorldGopInterface & gop
Global operations.
Definition world.h:207
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
Provides FunctionDefaults and utilities for coordinate transformation.
Tensor< T > transpose(const Tensor< T > &t)
Returns a new deep copy of the transpose of the input tensor.
Definition tensor.h:2035
Multidimension Key for MRA tree and associated iterators.
static double pow(const double *a, const double *b)
Definition lda.h:74
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#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
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Header to declare stuff which has not yet found a home.
static const bool VERIFY_TREE
Definition mra.h:57
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
@ BC_DIRICHLET
Definition bc.h:54
@ BC_NEUMANN
Definition bc.h:56
@ BC_ZERO
Definition bc.h:51
@ BC_PERIODIC
Definition bc.h:52
@ BC_ZERONEUMANN
Definition bc.h:55
@ BC_FREE
Definition bc.h:53
static const char * filename
Definition legendre.cc:96
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:60
int64_t Translation
Definition key.h:58
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:793
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:775
int Level
Definition key.h:59
std::enable_if< std::is_base_of< ProjectorBase, projT >::value, OuterProjector< projT, projQ > >::type outer(const projT &p0, const projQ &p1)
Definition projector.h:457
std::string get_mra_data_dir()
Definition startup.cc:209
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:767
NDIM & f
Definition mra.h:2619
GenTensor< TENSOR_RESULT_TYPE(R, Q)> transform_dir(const GenTensor< R > &t, const Tensor< Q > &c, const int axis)
Definition lowranktensor.h:1106
CCPairFunction< T, NDIM > apply(const SeparatedConvolution< T, NDIM/2 > &op, const CCPairFunction< T, NDIM > &arg)
apply the operator to the argument
Definition ccpairfunction.h:896
Function< T, CCPairFunction< T, NDIM >::LDIM > inner(const CCPairFunction< T, NDIM > &c, const Function< T, CCPairFunction< T, NDIM >::LDIM > &f, const std::tuple< int, int, int > v1, const std::tuple< int, int, int > v2)
Definition ccpairfunction.h:993
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
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:2187
static const double d
Definition nonlinschro.cc:121
Defines simple templates for printing to std::cout "a la Python".
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
static const long k
Definition rk.cc:44
Definition test_ar.cc:204
Body of FunctionImpl::diff's submission loop, as a functor for taskq.for_each.
Definition derivative.h:289
submit_op(const DerivativeBase< T, NDIM > *D=nullptr, const implT *f=nullptr, implT *df=nullptr)
Definition derivative.h:294
Range< typename dcT::const_iterator > rangeT
Definition derivative.h:290
void serialize(const Archive &ar)
Definition derivative.h:310
const DerivativeBase< T, NDIM > * D
Definition derivative.h:291
const implT * f
Definition derivative.h:292
bool operator()(typename rangeT::iterator &it) const
Definition derivative.h:296
implT * df
Definition derivative.h:293
static void load(const Archive &ar, const DerivativeBase< T, NDIM > *&ptr)
Definition derivative.h:809
Default load of an object via serialize(ar, t).
Definition archive.h:667
static void store(const Archive &ar, const DerivativeBase< T, NDIM > *const &ptr)
Definition derivative.h:818
Default store of an object via serialize(ar, t).
Definition archive.h:612
Defines and implements most of Tensor.
constexpr std::size_t NDIM
Definition testgconv.cc:54
std::size_t axis
Definition testpdiff.cc:59
Implements WorldContainer.
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43