From 92d30d0526c3283a9ab24ba0d6cc51c060e2250d Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 11 Sep 2023 09:20:11 -0400 Subject: [PATCH] introduced print_tree_jsonfile, wrapper around Function::print_tree_json that also saves the simulation cell in JSON --- src/madness/mra/funcplot.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/madness/mra/funcplot.h b/src/madness/mra/funcplot.h index c6b919c2661..f73a41f1428 100644 --- a/src/madness/mra/funcplot.h +++ b/src/madness/mra/funcplot.h @@ -990,6 +990,30 @@ void plot_plane(World& world, const std::vector >& vfuncti fclose(file); } + template + typename std::enable_if::type + print_tree_jsonfile(World& world, const Function& f, std::string filename) { + + if (world.size() > 1) + return; + + Tensor cell = copy(FunctionDefaults<3>::get_cell()); + std::ofstream os(filename.c_str()); + + os << "{"; + os << "\"cell\":["; + for (int xyz = 0; xyz != 3; ++xyz) { + os << "[" << cell(xyz, 0) << "," << cell(xyz, 1) << "]"; + if (xyz != 2) + os << ","; + } + os << "],"; + + os << "\"tree\":{"; + f.print_tree_json(os); + os << "}}"; + } + /// convenience to get plot_plane and plot_cubefile template void plot(const std::vector >& vf, const std::string& name, const std::vector& header){