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

Make ekin immutable and disable ekin checkpointing #4327

Merged
merged 3 commits into from
Aug 12, 2021
Merged
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
50 changes: 24 additions & 26 deletions src/core/grid_based_algorithms/electrokinetics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,40 +147,38 @@ int ek_print_vtk_lbforce_density(char *filename);
int ek_lb_print_vtk_density(char *filename);
int ek_lb_print_vtk_velocity(char *filename);
int ek_init();
int ek_set_agrid(float agrid);
int ek_set_lb_density(float lb_density);
int ek_set_viscosity(float viscosity);
int ek_set_lb_ext_force_density(float lb_ext_force_dens_x,
float lb_ext_force_dens_y,
float lb_ext_force_dens_z);
int ek_set_friction(float friction);
int ek_set_T(float T);
int ek_set_prefactor(float prefactor);
int ek_set_electrostatics_coupling(bool electrostatics_coupling);
void ek_set_agrid(float agrid);
void ek_set_lb_density(float lb_density);
void ek_set_viscosity(float viscosity);
void ek_set_lb_ext_force_density(float lb_ext_force_dens_x,
float lb_ext_force_dens_y,
float lb_ext_force_dens_z);
void ek_set_friction(float friction);
void ek_set_T(float T);
void ek_set_prefactor(float prefactor);
void ek_set_electrostatics_coupling(bool electrostatics_coupling);
void ek_calculate_electrostatic_coupling();
int ek_set_bulk_viscosity(float bulk_viscosity);
int ek_set_gamma_odd(float gamma_odd);
int ek_set_gamma_even(float gamma_even);
int ek_set_density(int species, float density);
int ek_set_D(int species, float D);
int ek_set_valency(int species, float valency);
int ek_set_ext_force_density(int species, float ext_force_density_x,
float ext_force_density_y,
float ext_force_density_z);
int ek_set_stencil(int stencil);
int ek_set_advection(bool advection);
int ek_set_fluidcoupling(bool ideal_contribution);
int ek_set_fluctuations(bool fluctuations);
int ek_set_fluctuation_amplitude(float fluctuation_amplitude);
void ek_set_bulk_viscosity(float bulk_viscosity);
void ek_set_gamma_odd(float gamma_odd);
void ek_set_gamma_even(float gamma_even);
void ek_set_density(int species, float density);
void ek_set_D(int species, float D);
void ek_set_valency(int species, float valency);
void ek_set_ext_force_density(int species, float ext_force_density_x,
float ext_force_density_y,
float ext_force_density_z);
void ek_set_stencil(int stencil);
void ek_set_advection(bool advection);
void ek_set_fluidcoupling(bool ideal_contribution);
void ek_set_fluctuations(bool fluctuations);
void ek_set_fluctuation_amplitude(float fluctuation_amplitude);
void ek_set_rng_state(uint64_t counter);
int ek_node_get_density(int species, int x, int y, int z, double *density);
int ek_node_get_flux(int species, int x, int y, int z, double *flux);
int ek_node_get_potential(int x, int y, int z, double *potential);
int ek_node_set_density(int species, int x, int y, int z, double density);
float ek_calculate_net_charge();
int ek_neutralize_system(int species);
int ek_save_checkpoint(char *filename, char *lb_filename);
int ek_load_checkpoint(char *filename);

#ifdef EK_BOUNDARIES
void ek_gather_wallcharge_species_density(float *wallcharge_species_density,
Expand Down
173 changes: 52 additions & 121 deletions src/core/grid_based_algorithms/electrokinetics_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <iostream>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

Expand Down Expand Up @@ -3640,149 +3641,130 @@ void ek_print_lbpar() {
printf("}\n");
}

int ek_set_agrid(float agrid) {
inline void ek_setter_throw_if_initialized() {
if (ek_initialized)
throw std::runtime_error(
"Electrokinetics parameters cannot be set after initialisation");
};

void ek_set_agrid(float agrid) {
ek_setter_throw_if_initialized();
ek_parameters.agrid = agrid;
return 0;
}

int ek_set_lb_density(float lb_density) {

void ek_set_lb_density(float lb_density) {
ek_setter_throw_if_initialized();
ek_parameters.lb_density = lb_density;
return 0;
}

int ek_set_prefactor(float prefactor) {

void ek_set_prefactor(float prefactor) {
ek_setter_throw_if_initialized();
ek_parameters.prefactor = prefactor;
return 0;
}

int ek_set_electrostatics_coupling(bool electrostatics_coupling) {
void ek_set_electrostatics_coupling(bool electrostatics_coupling) {
ek_setter_throw_if_initialized();
ek_parameters.es_coupling = electrostatics_coupling;
return 0;
}

int ek_set_viscosity(float viscosity) {

void ek_set_viscosity(float viscosity) {
ek_setter_throw_if_initialized();
ek_parameters.viscosity = viscosity;
return 0;
}

int ek_set_lb_ext_force_density(float lb_ext_force_dens_x,
float lb_ext_force_dens_y,
float lb_ext_force_dens_z) {
void ek_set_lb_ext_force_density(float lb_ext_force_dens_x,
float lb_ext_force_dens_y,
float lb_ext_force_dens_z) {
ek_setter_throw_if_initialized();
ek_parameters.lb_ext_force_density[0] = lb_ext_force_dens_x;
ek_parameters.lb_ext_force_density[1] = lb_ext_force_dens_y;
ek_parameters.lb_ext_force_density[2] = lb_ext_force_dens_z;
return 0;
}

int ek_set_friction(float friction) {

void ek_set_friction(float friction) {
ek_setter_throw_if_initialized();
ek_parameters.friction = friction;
return 0;
}

int ek_set_bulk_viscosity(float bulk_viscosity) {

void ek_set_bulk_viscosity(float bulk_viscosity) {
ek_setter_throw_if_initialized();
ek_parameters.bulk_viscosity = bulk_viscosity;
return 0;
}

int ek_set_gamma_odd(float gamma_odd) {

void ek_set_gamma_odd(float gamma_odd) {
ek_setter_throw_if_initialized();
ek_parameters.gamma_odd = gamma_odd;
return 0;
}

int ek_set_gamma_even(float gamma_even) {
void ek_set_gamma_even(float gamma_even) {

ek_setter_throw_if_initialized();
ek_parameters.gamma_even = gamma_even;
return 0;
}

int ek_set_stencil(int stencil) {
void ek_set_stencil(int stencil) {
ek_setter_throw_if_initialized();
if (!ek_parameters.fluidcoupling_ideal_contribution)
return 1; // combination not implemented

throw std::runtime_error(
"Combination of stencil and fluid coupling not implmented.");
ek_parameters.stencil = stencil;
return 0;
}

int ek_set_advection(bool advection) {
void ek_set_advection(bool advection) {
ek_setter_throw_if_initialized();
ek_parameters.advection = advection;
return 0;
}

int ek_set_fluctuations(bool fluctuations) {
void ek_set_fluctuations(bool fluctuations) {
ek_setter_throw_if_initialized();
ek_parameters.fluctuations = fluctuations;
return 0;
}

int ek_set_fluctuation_amplitude(float fluctuation_amplitude) {
void ek_set_fluctuation_amplitude(float fluctuation_amplitude) {
ek_setter_throw_if_initialized();
ek_parameters.fluctuation_amplitude = fluctuation_amplitude;
return 0;
}

int ek_set_fluidcoupling(bool ideal_contribution) {
void ek_set_fluidcoupling(bool ideal_contribution) {
ek_setter_throw_if_initialized();
if (ek_parameters.stencil != 0)
return 1; // combination not implemented

throw std::runtime_error(
"Combination of stencil and fluid coupling not implemented.");
ek_parameters.fluidcoupling_ideal_contribution = ideal_contribution;
return 0;
}

int ek_set_density(int species, float density) {
void ek_set_T(float T) {
ek_setter_throw_if_initialized();
ek_parameters.T = T;
}

void ek_set_density(int species, float density) {
ek_init_species(species);

ek_parameters.density[ek_parameters.species_index[species]] = density;

return 0;
}

int ek_set_D(int species, float D) {

void ek_set_D(int species, float D) {
ek_init_species(species);

ek_parameters.D[ek_parameters.species_index[species]] = D;
ek_parameters.d[ek_parameters.species_index[species]] =
D / (1.0f + 2.0f * sqrt(2.0f));

return 0;
}

int ek_set_T(float T) {

ek_parameters.T = T;

return 0;
}

int ek_set_valency(int species, float valency) {

void ek_set_valency(int species, float valency) {
ek_init_species(species);

ek_parameters.valency[ek_parameters.species_index[species]] = valency;

return 0;
}

int ek_set_ext_force_density(int species, float ext_force_density_x,
float ext_force_density_y,
float ext_force_density_z) {

void ek_set_ext_force_density(int species, float ext_force_density_x,
float ext_force_density_y,
float ext_force_density_z) {
ek_init_species(species);

ek_parameters.ext_force_density[0][ek_parameters.species_index[species]] =
ext_force_density_x;
ek_parameters.ext_force_density[1][ek_parameters.species_index[species]] =
ext_force_density_y;
ek_parameters.ext_force_density[2][ek_parameters.species_index[species]] =
ext_force_density_z;

return 0;
}

struct ek_charge_of_particle {
Expand Down Expand Up @@ -3866,57 +3848,6 @@ int ek_neutralize_system(int species) {
return 0;
}

int ek_save_checkpoint(char *filename, char *lb_filename) {
std::ofstream fout(filename, std::ofstream::binary);
std::vector<float> densities(ek_parameters.number_of_nodes);
auto const nchars =
static_cast<std::streamsize>(densities.size() * sizeof(float));

for (unsigned i = 0; i < ek_parameters.number_of_species; i++) {
cuda_safe_mem(cudaMemcpy(densities.data(), ek_parameters.rho[i],
densities.size() * sizeof(float),
cudaMemcpyDeviceToHost));

if (!fout.write(reinterpret_cast<char *>(densities.data()), nchars)) {
fout.close();
return 1;
}
}

fout.close();

lb_lbfluid_save_checkpoint(lb_filename, true);
return 0;
}

int ek_load_checkpoint(char *filename) {
std::string fname(filename);
std::ifstream fin((const char *)(fname + ".ek").c_str(),
std::ifstream::binary);
std::vector<float> densities(ek_parameters.number_of_nodes);
auto const nchars =
static_cast<std::streamsize>(densities.size() * sizeof(float));

for (unsigned i = 0; i < ek_parameters.number_of_species; i++) {
if (!fin.read(reinterpret_cast<char *>(densities.data()), nchars)) {
fin.close();
return 1;
}

cuda_safe_mem(cudaMemcpy(ek_parameters.rho[i], densities.data(),
densities.size() * sizeof(float),
cudaMemcpyHostToDevice));
}

fin.close();

lb_lbfluid_load_checkpoint((char *)(fname + ".lb").c_str(), true);

ek_integrate_electrostatics();

return 0;
}

void ek_set_rng_state(uint64_t counter) {
if (ek_initialized)
philox_counter = Utils::Counter<uint64_t>(counter);
Expand Down
42 changes: 20 additions & 22 deletions src/python/espressomd/electrokinetics.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,31 @@ IF ELECTROKINETICS and CUDA:
int ek_lb_print_vtk_density(char * filename)
int ek_lb_print_vtk_velocity(char * filename)
int ek_init()
int ek_set_agrid(float agrid)
int ek_set_lb_density(float lb_density)
int ek_set_viscosity(float viscosity)
int ek_set_friction(float friction)
int ek_set_lb_ext_force_density(float lb_ext_force_dens_x, float lb_ext_force_dens_y, float lb_ext_force_dens_z)
int ek_set_T(float T)
int ek_set_prefactor(float prefactor)
int ek_set_bulk_viscosity(float bulk_viscosity)
int ek_set_gamma_odd(float gamma_odd)
int ek_set_gamma_even(float gamma_even)
int ek_set_density(int species, float density)
int ek_set_D(int species, float D)
int ek_set_valency(int species, float valency)
int ek_set_ext_force_density(int species, float ext_force_density_x, float ext_force_density_y, float ext_force_density_z)
int ek_set_stencil(int stencil)
int ek_set_advection(bool advection)
int ek_set_fluctuations(bool fluctuations)
int ek_set_fluctuation_amplitude(float fluctuation_amplitude)
int ek_set_fluidcoupling(bool ideal_contribution)
void ek_set_agrid(float agrid) except +
void ek_set_lb_density(float lb_density) except +
void ek_set_viscosity(float viscosity) except +
void ek_set_friction(float friction) except +
void ek_set_lb_ext_force_density(float lb_ext_force_dens_x, float lb_ext_force_dens_y, float lb_ext_force_dens_z) except +
void ek_set_T(float T) except +
void ek_set_prefactor(float prefactor) except +
void ek_set_bulk_viscosity(float bulk_viscosity) except +
void ek_set_gamma_odd(float gamma_odd) except +
void ek_set_gamma_even(float gamma_even) except +
void ek_set_density(int species, float density)
void ek_set_D(int species, float D)
void ek_set_valency(int species, float valency)
void ek_set_ext_force_density(int species, float ext_force_density_x, float ext_force_density_y, float ext_force_density_z)
void ek_set_stencil(int stencil) except +
void ek_set_advection(bool advection) except +
void ek_set_fluctuations(bool fluctuations) except +
void ek_set_fluctuation_amplitude(float fluctuation_amplitude) except +
void ek_set_fluidcoupling(bool ideal_contribution) except +
void ek_set_electrostatics_coupling(bool electrostatics_coupling) except +
int ek_node_get_density(int species, int x, int y, int z, double * density)
int ek_node_get_flux(int species, int x, int y, int z, double * flux)
int ek_node_get_potential(int x, int y, int z, double * potential)
int ek_node_set_density(int species, int x, int y, int z, double density)
float ek_calculate_net_charge()
int ek_neutralize_system(int species)
int ek_save_checkpoint(char * filename, char * lb_filename)
int ek_load_checkpoint(char * filename)

int ek_set_electrostatics_coupling(bool electrostatics_coupling)
int ek_print_vtk_particle_potential(char * filename)
Loading