Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online ROM prediction for Hartree Poisson equation #286

Draft
wants to merge 3 commits into
base: ROMFPMD
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,8 @@ void Control::setROMOptions(const boost::program_options::variables_map& vm)

rom_pri_option.num_potbasis = vm["ROM.basis.number_of_potential_basis"].as<int>();
rom_pri_option.pot_rom_file = vm["ROM.potential_rom_file"].as<std::string>();

rom_pri_option.test_restart_file = vm["ROM.online.test_restart_file"].as<std::string>();
} // onpe0

// synchronize all processors
Expand All @@ -2079,6 +2081,7 @@ void Control::syncROMOptions()
mmpi.bcast(rom_pri_option.restart_file_fmt, comm_global_);
mmpi.bcast(rom_pri_option.basis_file, comm_global_);
mmpi.bcast(rom_pri_option.pot_rom_file, comm_global_);
mmpi.bcast(rom_pri_option.test_restart_file, comm_global_);

auto bcast_check = [](int mpirc) {
if (mpirc != MPI_SUCCESS)
Expand Down
15 changes: 8 additions & 7 deletions src/Potentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,9 @@ void Potentials::initBackground(Ions& ions)
if (fabs(background_charge_) < 1.e-10) background_charge_ = 0.;
}

#ifdef MGMOL_HAS_LIBROM
void Potentials::evalIonDensityOnSamplePts(
Ions& ions, const std::vector<int> &local_idx, std::vector<RHODTYPE> &sampled_rhoc)
Ions& ions, const std::vector<int> &local_idx, CAROM::Vector &sampled_rhoc)
{
Mesh* mymesh = Mesh::instance();
MGmol_MPI& mmpi = *(MGmol_MPI::instance());
Expand All @@ -918,9 +919,8 @@ void Potentials::evalIonDensityOnSamplePts(
}

// initialize output vector
sampled_rhoc.resize(local_idx.size());
for (int d = 0; d < sampled_rhoc.size(); d++)
sampled_rhoc[d] = 0.0;
sampled_rhoc.setSize(local_idx.size());
sampled_rhoc = 0.0;

// Loop over ions
for (auto& ion : ions.overlappingVL_ions())
Expand All @@ -936,9 +936,9 @@ void Potentials::evalIonDensityOnSamplePts(
}

void Potentials::initializeRadialDataOnSampledPts(
const Vector3D& position, const Species& sp, const std::vector<int> &local_idx, std::vector<RHODTYPE> &sampled_rhoc)
const Vector3D& position, const Species& sp, const std::vector<int> &local_idx, CAROM::Vector &sampled_rhoc)
{
assert(local_idx.size() == sampled_rhoc.size());
assert(local_idx.size() == sampled_rhoc.dim());

Control& ct = *(Control::instance());

Expand Down Expand Up @@ -984,11 +984,12 @@ void Potentials::initializeRadialDataOnSampledPts(
/* accumulate ion species density */
const double r = position.minimage(point, lattice, ct.bcPoisson);
if (r < lrad)
sampled_rhoc[k] += sp.getRhoComp(r);
sampled_rhoc(k) += sp.getRhoComp(r);
}

return;
}
#endif

template void Potentials::setVxc<double>(
const double* const vxc, const int iterativeIndex);
Expand Down
14 changes: 12 additions & 2 deletions src/Potentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <string>
#include <vector>

#ifdef MGMOL_HAS_LIBROM
#include "librom.h"
#endif

class Ions;
class Species;
template <class T>
Expand Down Expand Up @@ -95,8 +99,10 @@ class Potentials
void initializeSupersampledRadialDataOnMesh(
const Vector3D& position, const Species& sp);

#ifdef MGMOL_HAS_LIBROM
void initializeRadialDataOnSampledPts(
const Vector3D& position, const Species& sp, const std::vector<int> &local_idx, std::vector<RHODTYPE> &sampled_rhoc);
const Vector3D& position, const Species& sp, const std::vector<int> &local_idx, CAROM::Vector &sampled_rhoc);
#endif

public:
Potentials(const bool vh_frozen = false);
Expand Down Expand Up @@ -164,6 +170,8 @@ class Potentials

const double getBackgroundCharge() const { return background_charge_; }

const double getIonicCharge() const { return ionic_charge_; }

/*!
* initialize total potential as local pseudopotential
*/
Expand Down Expand Up @@ -201,7 +209,9 @@ class Potentials
void initBackground(Ions& ions);
void addBackgroundToRhoComp();

void evalIonDensityOnSamplePts(Ions& ions, const std::vector<int> &local_idx, std::vector<RHODTYPE> &sampled_rhoc);
#ifdef MGMOL_HAS_LIBROM
void evalIonDensityOnSamplePts(Ions& ions, const std::vector<int> &local_idx, CAROM::Vector &sampled_rhoc);
#endif

#ifdef HAVE_TRICUBIC
void readExternalPot(const string filename, const char type);
Expand Down
4 changes: 3 additions & 1 deletion src/read_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ void setupROMConfigOption(po::options_description &rom_cfg)
("ROM.basis.number_of_potential_basis", po::value<int>()->default_value(-1),
"Number of potential POD basis to build Hartree potential ROM operator.")
("ROM.potential_rom_file", po::value<std::string>()->default_value(""),
"File name to save/load potential ROM operators.");
"File name to save/load potential ROM operators.")
("ROM.online.test_restart_file", po::value<std::string>()->default_value(""),
"File name to test online ROM.");
}
#endif
4 changes: 4 additions & 0 deletions src/rom_Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class ROMVariable
{
ORBITALS,
POTENTIAL,
DENSITY,
NONE
};

Expand All @@ -54,6 +55,9 @@ struct ROMPrivateOptions
/* options for ROM building */
int num_potbasis = -1;
std::string pot_rom_file = "";

/* options for online Poisson ROM */
std::string test_restart_file = "";
};

#endif // ROM_CONTROL_H
Loading
Loading