Skip to content

Commit

Permalink
wrap functions using std::filesystem with directives
Browse files Browse the repository at this point in the history
  • Loading branch information
ahurta92 committed Jul 1, 2024
1 parent ede1667 commit 43083d5
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 983 deletions.
4 changes: 4 additions & 0 deletions src/apps/molresponse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(MOLRESPONSE_SOURCES
property.cc
global_functions.cc
timer.cc
Plot_VTK.cc
basic_operators.cc
response_parameters.cpp
x_space.cc
Expand All @@ -28,6 +29,7 @@ set(MOLRESPONSE_HEADERS
x_space.h
global_functions.h
timer.h
Plot_VTK.h
basic_operators.h
response_parameters.h
)
Expand Down Expand Up @@ -79,6 +81,7 @@ set(RALL_SOURCES
property.cc
global_functions.cc
timer.cc
Plot_VTK.cc
basic_operators.cc
response_parameters.cpp
x_space.cc
Expand All @@ -92,6 +95,7 @@ set(RALL_HEADERS
global_functions.h
timer.h
basic_operators.h
Plot_VTK.h
response_parameters.h
x_space.h
)
Expand Down
185 changes: 47 additions & 138 deletions src/apps/molresponse/Plot_VTK.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
*/

#include "Plot_VTK.h"

#include <madness/mra/mra.h>

#include <cstdint>
//#include <filesystem>
#include <string>
#include <vector>

#include "../chem/molecule.h"
#if defined(__has_include)
#if __has_include(<filesystem>)
#define MADCHEM_HAS_STD_FILESYSTEM
// <filesystem> is not reliably usable on Linux with gcc < 9
#if defined(__GNUC__)
#if __GNUC__ >= 7 && __GNUC__ < 9
#undef MADCHEM_HAS_STD_FILESYSTEM
#endif
#endif
#if defined(MADCHEM_HAS_STD_FILESYSTEM)

#include <filesystem>
namespace madness {
void write_molecules_to_file(const Molecule &molecule, const std::string &geo_file) {

Expand All @@ -36,19 +43,18 @@ namespace madness {
// Write the data
size_t Natoms = molecule.natom();
for (size_t i = 0; i < Natoms; i++) {
std::fprintf(f,
"%5s %16.12f %16.12f %16.12f\n",
atomic_number_to_symbol(molecule.get_atomic_number(i)).c_str(),
coords[i][0],
coords[i][1],
std::fprintf(f, "%5s %16.12f %16.12f %16.12f\n",
atomic_number_to_symbol(molecule.get_atomic_number(i)).c_str(), coords[i][0], coords[i][1],
coords[i][2]);
}

// Clean up
fclose(f);
}

void do_response_orbital_vtk_plots(World &world, int npt_plot, double L, const Molecule &molecule, const vector_real_function_3d &ground_orbs, const response_matrix &responseMatrix) {
void do_response_orbital_vtk_plots(World &world, int npt_plot, double L, const Molecule &molecule,
const vector_real_function_3d &ground_orbs,
const response_matrix &responseMatrix) {
// Stuff needed to plot
//
Vector<double, 3> box_lo{-L / 4, -L / 4, -L / 4};
Expand Down Expand Up @@ -81,15 +87,7 @@ namespace madness {
auto orb_file = vtk_dir + "/phi0_" + std::to_string(orb_num) + ".vts";
filename = orb_file.c_str();
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(phi0_i,
"ground_orbtial",
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(phi0_i, "ground_orbtial", world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);
orb_num++;
});
Expand All @@ -104,14 +102,7 @@ namespace madness {
auto orb_file = vtk_dir + "/" + "x" + std::to_string(state_number) + std::to_string(orb_num) + ".vts";
filename = orb_file.c_str();
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(xi,
"response_x_orbitals",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(xi, "response_x_orbitals", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
orb_num++;
Expand All @@ -121,22 +112,17 @@ namespace madness {
auto orb_file = vtk_dir + "/" + "y" + std::to_string(state_number) + std::to_string(orb_num) + ".vts";
filename = orb_file.c_str();
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(yi,
"response_y_orbitals",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(yi, "response_y_orbitals", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
orb_num++;
});
state_number++;
});
}
void do_response_density_vtk_plots(World &world, int npt_plot, double L, const Molecule &molecule, const real_function_3d &ground_density, const vector_real_function_3d &response_density) {
void do_response_density_vtk_plots(World &world, int npt_plot, double L, const Molecule &molecule,
const real_function_3d &ground_density,
const vector_real_function_3d &response_density) {
// Stuff needed to plot
//
Vector<double, 3> box_lo{-L / 4, -L / 4, -L / 4};
Expand All @@ -156,15 +142,7 @@ namespace madness {
auto density_file = vtk_dir + "/" + "rho0.vts";
filename = density_file.c_str();
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(ground_density,
"ground_density",
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(ground_density, "ground_density", world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);

//***********************************ground density plot
Expand All @@ -174,27 +152,13 @@ namespace madness {
filename = density_file.c_str();
auto field_name = "r_density_" + std::to_string(state_number);
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(rho_i,
field_name.c_str(),
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(rho_i, field_name.c_str(), world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);
state_number++;
});
}
void do_vtk_plots(World &world,
int npt_plot,
double L,
int lowest_orbital,
int highest_orbital,
const Molecule &molecule,
std::vector<real_function_3d> densities,
const std::string &name) {
void do_vtk_plots(World &world, int npt_plot, double L, int lowest_orbital, int highest_orbital,
const Molecule &molecule, std::vector<real_function_3d> densities, const std::string &name) {
// Stuff needed to plot
//
Vector<double, 3> box_lo{-L, -L, -L};
Expand Down Expand Up @@ -239,15 +203,7 @@ namespace madness {
// npts
// binary
// plot refile
plotvtk_data<double, 3>(densities[i],
"density",
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(densities[i], "density", world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);
}
std::string b;
Expand All @@ -256,24 +212,11 @@ namespace madness {
b = vtk_dir + "/" + "total-electrondensity.vts";
filename = b.c_str();
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(rho,
"total-electrondensity",
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(rho, "total-electrondensity", world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);
}
void do_vtk_plots(World &world,
int npt_plot,
double L,
Molecule molecule,
real_function_3d &rho_0,
std::vector<real_function_3d> &rho_omega,
std::vector<real_function_3d> &ground_orbitals,
void do_vtk_plots(World &world, int npt_plot, double L, Molecule molecule, real_function_3d &rho_0,
std::vector<real_function_3d> &rho_omega, std::vector<real_function_3d> &ground_orbitals,
X_space &Chi) {
std::string vtk_dir = "vtk_plots";
std::filesystem::create_directories(vtk_dir);
Expand All @@ -297,11 +240,8 @@ namespace madness {
// Write the data
size_t Natoms = molecule.natom();
for (size_t i = 0; i < Natoms; i++) {
std::fprintf(f,
"%5s %16.12f %16.12f %16.12f\n",
atomic_number_to_symbol(molecule.get_atomic_number(i)).c_str(),
coords[i][0],
coords[i][1],
std::fprintf(f, "%5s %16.12f %16.12f %16.12f\n",
atomic_number_to_symbol(molecule.get_atomic_number(i)).c_str(), coords[i][0], coords[i][1],
coords[i][2]);
}
// Clean up
Expand All @@ -310,15 +250,7 @@ namespace madness {
filename = rho0_file.c_str();

plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(rho_0,
"ground_density",
world,
filename,
box_lo,
box_hi,
points,
true,
false);
plotvtk_data<double, 3>(rho_0, "ground_density", world, filename, box_lo, box_hi, points, true, false);
plotvtk_end<3>(world, filename, true);
// ground orbitals
std::string g_orb_file = "phi_";
Expand All @@ -328,54 +260,31 @@ namespace madness {
filename = fname.c_str();
// VTK plotting stuff
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(ground_orbitals[i],
"ground_orbital",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(ground_orbitals[i], "ground_orbital", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
}

std::string x_orb_file = "x_";
for (size_t i = 0; i < Chi.num_states(); ++i) {
for (size_t j = 0; j < Chi.num_orbitals(); ++j) {
fname = vtk_dir + "/" + x_orb_file + std::to_string(i) + "_" +
std::to_string(j) + ".vts";
fname = vtk_dir + "/" + x_orb_file + std::to_string(i) + "_" + std::to_string(j) + ".vts";
filename = fname.c_str();
// VTK plotting stuff
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(Chi.x[i][j],
"x_orbitals",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(Chi.x[i][j], "x_orbitals", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
}
}
std::string y_orb_file = "y_";
for (size_t i = 0; i < Chi.num_states(); ++i) {
for (size_t j = 0; j < Chi.num_orbitals(); ++j) {
fname = vtk_dir + "/" + y_orb_file + std::to_string(i) + "_" +
std::to_string(j) + ".vts";
fname = vtk_dir + "/" + y_orb_file + std::to_string(i) + "_" + std::to_string(j) + ".vts";
filename = fname.c_str();
// VTK plotting stuff
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(Chi.y[i][j],
"y_orbitals",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(Chi.y[i][j], "y_orbitals", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
}
Expand All @@ -387,14 +296,7 @@ namespace madness {
filename = fname.c_str();
// VTK plotting stuff
plotvtk_begin<3>(world, filename, box_lo, box_hi, points, true);
plotvtk_data<double, 3>(rho_omega[i],
"transition_density",
world,
filename,
box_lo,
box_hi,
points,
true,
plotvtk_data<double, 3>(rho_omega[i], "transition_density", world, filename, box_lo, box_hi, points, true,
false);
plotvtk_end<3>(world, filename, true);
}
Expand All @@ -405,4 +307,11 @@ namespace madness {
//
//
}

}// namespace madness

#endif
#endif
#endif

#include "../chem/molecule.h"
Loading

0 comments on commit 43083d5

Please sign in to comment.