Skip to content

Commit

Permalink
synch
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlutsko committed Oct 21, 2024
1 parent 2219799 commit 727d240
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
5 changes: 4 additions & 1 deletion include/DFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class DFT : public Dynamical_Matrix
double get_f_ext() const { return F_ext_;} //external field contribution to free energy including chemical potential
double get_f_hs() const { return F_hs_;} //Hard-sphere contribution to free energy
double get_f_mf() const { return F_mf_;} //mean field contribution to free energy
double get_f_eos() const { return F_eos_;}

// Implement Dynamical_Matrix interface.
// Second derivatives contracted into arbitrary vector
Expand Down Expand Up @@ -167,7 +168,8 @@ class DFT : public Dynamical_Matrix
ar & F_id_;
ar & F_ext_;
ar & F_hs_;
ar & F_mf_;
ar & F_mf_;
ar & F_eos_;
}

protected:
Expand All @@ -180,6 +182,7 @@ class DFT : public Dynamical_Matrix
double F_ext_ = 0.0; ///< External field contribution to free energy (including chemical potential)
double F_hs_ = 0.0; ///< Hard-sphere contribution to free energy
double F_mf_ = 0.0; ///< Mean-field contribution to free energy
double F_eos_ = 0.0;

mutable bool full_hessian_ = true; // used in matrix_holder to distinguish full hessian from excess hessian.
mutable double rms_force_ = 0.0; // updated everytime the forces are calculated.
Expand Down
21 changes: 20 additions & 1 deletion src/DFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ double DFT::calculateFreeEnergyAndDerivatives_internal_(bool onlyFex)
species->doFFT();
}

// EOS term
F_eos_ = 0;
for(auto &species : allSpecies_)
{
FMT_Species_EOS *eos_species = dynamic_cast<FMT_Species_EOS*>(species);
if(eos_species)
{
const Density& density = species->getDensity();
double dV = density.dV();
long Ntot = density.Ntot();

double F = 0;
for(long I=0;I<Ntot;I++)
F += eos_species->dfex(I, fmt_);
F_eos_ += F*dV;
}
}
F += F_eos_;


//< Mean field contribution to F and dF
F_mf_ = 0;
for(auto &interaction: DFT::Interactions_)
Expand All @@ -242,7 +262,6 @@ double DFT::calculateFreeEnergyAndDerivatives_internal_(bool onlyFex)

for(auto &species: allSpecies_)
F_ext_ += species->evaluate_contribution_chemical_potential();


for(auto &field : external_fields_)
F_ext_ += allSpecies_[field->get_species()]->evaluate_external_field(*field);
Expand Down
11 changes: 6 additions & 5 deletions src/FMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,15 @@ double FMT::calculateFreeEnergy(vector<Species*> &allSpecies)
throw Eta_Too_Large_Exception();

// Add in contributions from any EOS corrections
double FEOS = 0;
/* double FEOS = 0;
for(auto s: allSpecies)
{
FMT_Species_EOS *eos_species = dynamic_cast<FMT_Species_EOS*>(s);
if(eos_species)
FEOS += EOS_Correction(*eos_species);
}

*/
// For the AO species, there is additional work to do for both the free energy and the forces.
// Do FFT of density and compute the fundamental measures by convolution
double FAO = 0;
Expand All @@ -372,9 +373,9 @@ double FMT::calculateFreeEnergy(vector<Species*> &allSpecies)
FAO += fao_species->free_energy_post_process(needsTensor());
}

return F.sum()+FEOS+FAO;
return F.sum()+FAO; //FEOS+FAO;
}

/*
double FMT::EOS_Correction(FMT_Species_EOS &eos_species)
{
double F = 0;
Expand All @@ -384,7 +385,7 @@ double FMT::EOS_Correction(FMT_Species_EOS &eos_species)
F += eos_species.dfex(I, this);
return F;
}

*/
// Calculate dF[i] = dPhi/drho(i)
// = sum_j dV * dPhi(j)/drho(i)
// = sum_j dV * sum_alpha dPhi(j)/dn_{alpha}(j) dn_{alpha}(j)/drho(i)
Expand Down
2 changes: 0 additions & 2 deletions src/FMT_Species_EOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ void FMT_Species_EOS::add_second_derivative(const DFT_FFT &v, DFT_Vec &d2F, cons
// N.B. the fmt weights have all necessary normalization factors built in, including dV
bool bConjugate = false;
convolute_eos_eta_weight_with(v, Psi, bConjugate);
for(int i=0;i<1;i++)
cout << "i = " << i << " r = " << i*0.05 << " Psi[" << i << "] = " << Psi.Real().get(i) << endl;

// Get Lambda: Lambda(K) = (d2dfex(K)/deta(K) deta(K))psi(K)
DFT_FFT Lambda(Nx,Ny,Nz);
Expand Down

0 comments on commit 727d240

Please sign in to comment.