faunus
externalpotential.h
1 #pragma once
2 
3 #include "geometry.h"
4 #include "group.h"
5 #include "aux/timers.h"
6 #include "aux/equidistant_table.h"
7 #include <set>
8 
9 template <std::floating_point T> class ExprFunction;
10 
11 namespace Faunus {
12 
13 struct Change;
14 class Space;
15 
16 namespace Energy {
17 
22 {
23  public:
24  enum class MonteCarloState
25  {
26  ACCEPTED,
27  TRIAL,
28  NONE
29  };
30  MonteCarloState state = MonteCarloState::NONE;
31  std::string name;
32  std::string citation_information;
34  virtual double energy(const Change& change) = 0;
35  virtual void to_json(json& j) const;
36  virtual void sync(EnergyTerm* other_energy,
37  const Change& change);
38  virtual void init();
39  virtual void
40  updateState(const Change& change);
41  virtual void force(PointVector& forces);
42  inline virtual ~EnergyTerm() = default;
43 };
44 
45 void to_json(json& j, const EnergyTerm& base);
46 
57 {
58  private:
59  bool act_on_mass_center = false;
60  std::set<int> molecule_ids;
61  std::vector<std::string> molecule_names;
62  double groupEnergy(const Group& group) const;
63  protected:
64  const Space& space;
65  std::function<double(const Particle&)> externalPotentialFunc;
66  public:
67  ExternalPotential(const json& j, const Space& spc);
68  double energy(const Change& j) override;
69  void to_json(json& j) const override;
70 };
71 
83 std::function<double(const Particle&)> createGouyChapmanPotential(const json& j,
84  const Geometry::Chameleon&);
85 
90 {
91  private:
92  std::unique_ptr<ExprFunction<double>> expr;
93 
94  struct ParticleData
95  { // storage for particle properties
96  double charge = 0, x = 0, y = 0, z = 0;
97  };
98 
99  ParticleData particle_data;
100  json json_input_backup; // initial json input
101 
102  public:
103  CustomExternal(const json&, Space&);
104  void to_json(json&) const override;
105 };
106 
121 {
122  private:
123  std::string filename;
124  bool fixed_potential = false;
125  unsigned int nstep = 0;
126  unsigned int phi_update_interval = 0;
127  unsigned int num_rho_updates = 0;
128  unsigned int num_density_updates = 0;
129  double dielectric_constant;
130  double dz;
131  double bjerrum_length;
132  double half_box_length_z;
133  Equidistant2DTable<double> charge_profile;
136 
137  static double evalPotential(double z, double a);
138  void updateChargeDensity();
139  void updatePotential();
140  void saveChargeDensity();
141  void loadChargeDensity();
142  void to_json(json&) const override;
143  void sync(EnergyTerm*, const Change&) override;
144 
145  public:
146  ExternalAkesson(const json& j, const Space& spc);
147  double energy(const Change& change) override;
148  ~ExternalAkesson() override;
149 };
150 
156 {
157  public:
158  enum Variant
159  {
160  sphere,
161  cylinder,
162  cuboid,
163  none
164  };
165 
166  Variant type = none;
167 
168  private:
169  Point origo = {0.0, 0.0, 0.0};
170  Point dir = {1.0, 1.0, 1.0};
171  Point low;
172  Point high;
173  double radius = 0.0;
174  double spring_constant = 0.0;
175  bool scale = false;
176  std::map<std::string, Variant> m = {
177  {"sphere", sphere}, {"cylinder", cylinder}, {"cuboid", cuboid}};
178 
179  public:
180  Confine(const json& j, Space& spc);
181  void to_json(json& j) const override;
182 };
183 
195 {
196  public:
197  ParticleSelfEnergy(Space&, std::function<double(const Particle&)>);
198 };
199 
200 } // namespace Energy
201 } // namespace Faunus
nlohmann::json json
JSON object.
Definition: json_support.h:10
Eigen::Vector3d Point
3D vector used for positions, velocities, forces etc.
Definition: coordinates.h:7
virtual void init()
reset and initialize
Definition: externalpotential.cpp:28
std::vector< Point > PointVector
Vector of 3D vectors.
Definition: core.h:24
Geometry class for spheres, cylinders, cuboids, hexagonal prism, truncated octahedron, slits.
Definition: geometry.h:342
std::string citation_information
Possible reference; may be left empty.
Definition: externalpotential.h:32
std::string name
Meaningful name.
Definition: externalpotential.h:31
Base class for external potentials.
Definition: externalpotential.h:56
Used to add self energies to atoms from i.e.
Definition: externalpotential.h:194
virtual double energy(const Change &change)=0
energy due to change
std::function< double(const Particle &)> createGouyChapmanPotential(const json &j, const Geometry::Chameleon &)
Returns a functor for a Gouy-Chapman electric potential.
Definition: externalpotential.h:83
virtual void force(PointVector &forces)
update forces on all particles
Definition: externalpotential.cpp:30
virtual void sync(EnergyTerm *other_energy, const Change &change)
Sync (copy from) another energy instance.
Definition: externalpotential.cpp:23
std::function< double(const Particle &)> externalPotentialFunc
energy of single particle
Definition: externalpotential.h:65
Custom external potential on molecules.
Definition: externalpotential.h:89
Particle class for storing positions, id, and other properties.
Definition: particle.h:220
TimeRelativeOfTotal< std::chrono::microseconds > timer
Timer for measuring speed.
Definition: externalpotential.h:33
virtual void updateState(const Change &change)
Update internal state to reflect change in e.g. Space.
Definition: externalpotential.cpp:37
Since parser<T> is non-copyable we instantiate it with a shared pointer, allowing ExprFunction to be ...
Definition: externalpotential.h:9
Cell list class templates.
Definition: actions.cpp:11
End of Group class.
Definition: group.h:177
All energies inherit from this class.
Definition: externalpotential.h:21
Specify changes made to a system.
Definition: space.h:29
Mean field electric potential from outside rectangular simulation box.
Definition: externalpotential.h:120
const Space & space
reference to simulation space
Definition: externalpotential.h:64
Placeholder for atoms and molecules.
Definition: space.h:92
Confines molecules inside geometric shapes Confine particles to a sub-region of the simulation contai...
Definition: externalpotential.h:155
virtual void to_json(json &j) const
json output
Definition: externalpotential.cpp:17