13 for (
int i = 0; i <
b; i++) {
20template <
typename T, std::
size_t NDIM>
class FunctionIO {
29 const auto &coeffs =
f.get_impl()->get_coeffs();
31 for (
auto it = coeffs.begin(); it != coeffs.end(); ++it) {
32 const auto &key = it->first;
33 const auto &node = it->second;
34 if (node.has_coeff()) {
38 f.get_impl()->world.gop.sum(count);
42 std::ostream &out,
const Key<NDIM> &key) {
43 const auto &coeffs =
f.get_impl()->get_coeffs();
44 auto it = coeffs.find(key).get();
45 if (it == coeffs.end()) {
46 for (
int i = 0; i < key.
level(); ++i)
48 out << key <<
" missing --> " << coeffs.owner(key) <<
"\n";
50 const auto &node = it->second;
51 if (node.has_coeff()) {
52 auto values =
f.get_impl()->coeffs2values(key, node.coeff());
53 for (
int i = 0; i < key.
level(); ++i)
55 out << key.
level() <<
" ";
56 for (
int i = 0; i <
NDIM; ++i)
62 for (
size_t i = 0; i < values.size(); i++)
63 out << values.ptr()[i] <<
" ";
68 if (node.has_children()) {
79 auto flags = out.flags();
80 auto precision = out.precision();
81 out << std::setprecision(17);
82 out << std::scientific;
84 if (
f.get_impl()->world.rank() == 0) {
85 out <<
NDIM << std::endl;
87 for (
int d = 0;
d <
NDIM; ++
d) {
88 for (
int i = 0; i < 2; ++i)
89 out << cell(
d, i) <<
" ";
92 out <<
f.k() << std::endl;
97 f.get_impl()->world.gop.fence();
99 out << std::setprecision(precision);
104 int num_leaf_nodes) {
105 auto &coeffs =
f.get_impl()->get_coeffs();
107 for (
int i = 0; i < num_leaf_nodes; i++) {
115 for (
int i = 0; i <
NDIM; ++i) {
122 for (
size_t i = 0; i < values.
size(); i++)
123 in >> values.
ptr()[i];
124 auto t =
f.get_impl()->values2coeffs(key, values);
137 for (
int d = 0;
d <
NDIM; ++
d) {
138 for (
int i = 0; i < 2; ++i)
146 in >> num_leaf_nodes;
165 std::vector<std::array<long, NDIM + 1>>
nl;
175 if (
f.get_impl()->world.rank() == 0) {
180 for (
int d = 0;
d <
NDIM; ++
d) {
181 cell[
d].first = cell_world(
d, 0);
182 cell[
d].second = cell_world(
d, 1);
187 f.get_impl()->world.gop.fence();
192 const auto &coeffs =
f.get_impl()->get_coeffs();
193 auto it = coeffs.find(key).get();
194 if (it == coeffs.end()) {
195 for (
int i = 0; i < key.
level(); ++i)
197 std::cout << key <<
" missing --> " << coeffs.owner(key) <<
"\n";
199 const auto &node = it->second;
200 if (node.has_coeff()) {
201 auto node_values =
f.get_impl()->coeffs2values(key, node.coeff());
202 std::array<long, NDIM + 1> key_i;
203 key_i[0] = key.
level();
204 for (
int i = 0; i <
NDIM; ++i)
211 std::copy(node_values.ptr(), node_values.ptr() +
npts_per_box,
214 values.push_back(values_i);
216 if (node.has_children()) {
224 auto &coeffs =
f.get_impl()->get_coeffs();
230 for (
int i = 0; i <
NDIM; ++i) {
235 for (
int j = 0; j <
NDIM; ++j) {
241 std::copy(this->values[i].begin(), this->values[i].end(),
values.
ptr());
242 auto t =
f.get_impl()->values2coeffs(key,
values);
254 for (
int d = 0;
d <
NDIM; ++
d) {
255 cell_t(
d, 0) =
cell[
d].first;
256 cell_t(
d, 1) =
cell[
d].second;
273template <
typename T, std::
size_t NDIM>
275 j =
json{{
"npts_per_box",
p.npts_per_box},
278 {
"num_leaf_nodes",
p.num_leaf_nodes},
281 {
"values",
p.values}};
284template <
typename T, std::
size_t NDIM>
286 j.at(
"npts_per_box").get_to(
p.npts_per_box);
287 j.at(
"k").get_to(
p.k);
288 j.at(
"cell").get_to(
p.cell);
289 j.at(
"num_leaf_nodes").get_to(
p.num_leaf_nodes);
290 j.at(
"nl").get_to(
p.nl);
291 j.at(
"values").get_to(
p.values);
292 j.at(
"ndim").get_to(
p.ndim);
constexpr int simple_pow(int a, int b)
Definition FunctionIOHDF5.h:10
constexpr int simple_pow(int a, int b)
Definition FunctionIO.h:8
Definition FunctionIO.h:20
static void write_function(const Function< T, NDIM > &f, std::ostream &out)
Definition FunctionIO.h:75
static size_t count_leaf_nodes(const Function< T, NDIM > &f)
Definition FunctionIO.h:28
static void write_function_coeffs(const Function< T, NDIM > &f, std::ostream &out, const Key< NDIM > &key)
Definition FunctionIO.h:41
long npts_per_box
Definition FunctionIO.h:25
long k
Definition FunctionIO.h:23
static void read_function_coeffs(Function< T, NDIM > &f, std::istream &in, int num_leaf_nodes)
Definition FunctionIO.h:103
static Function< T, NDIM > read_function(World &world, std::istream &in)
Definition FunctionIO.h:131
long ndims
Definition FunctionIO.h:24
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
static int get_k()
Returns the default wavelet order.
Definition funcdefaults.h:163
static void set_cell(const Tensor< double > &value)
Gets the user cell for the simulation.
Definition funcdefaults.h:354
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition funcdefaults.h:347
FunctionFactory implements the named-parameter idiom for Function.
Definition function_factory.h:86
virtual FunctionFactory & k(int k)
Definition function_factory.h:193
FunctionFactory & empty()
Definition function_factory.h:246
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:127
A multiresolution adaptive numerical function.
Definition mra.h:139
Iterates in lexical order thru all children of a key.
Definition key.h:466
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:69
Level level() const
Definition key.h:168
const Vector< Translation, NDIM > & translation() const
Definition key.h:173
A tensor is a multidimensional array.
Definition tensor.h:317
T * ptr()
Returns a pointer to the internal data.
Definition tensor.h:1825
A simple, fixed dimension vector.
Definition vector.h:64
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
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.
#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
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
int Level
Definition key.h:58
NDIM & f
Definition mra.h:2481
void to_json(nlohmann::json &j)
void from_json(const nlohmann::json &, ResponseParameters &p)
Definition response_parameters.cpp:8
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
nlohmann::json json
Definition response_parameters.cpp:6
Definition FunctionIO.h:158
std::vector< std::array< long, NDIM+1 > > nl
Definition FunctionIO.h:165
FunctionIOData(const Function< T, NDIM > &f)
Definition FunctionIO.h:170
long npts_per_box
Definition FunctionIO.h:161
std::array< std::pair< double, double >, NDIM > cell
Definition FunctionIO.h:163
Function< T, NDIM > create_function(World &world)
Definition FunctionIO.h:249
std::size_t ndim
Definition FunctionIO.h:162
long num_leaf_nodes
Definition FunctionIO.h:164
long k
Definition FunctionIO.h:160
void set_function_coeffs(Function< T, NDIM > &f, int num_leaf_nodes)
Definition FunctionIO.h:223
void initialize_func_coeffs(const Function< T, NDIM > &f, const Key< NDIM > &key)
Definition FunctionIO.h:190
std::vector< std::vector< double > > values
Definition FunctionIO.h:166
constexpr std::size_t NDIM
Definition testgconv.cc:54