From 43c161197835b89a829b1620413a98d9f5c25492 Mon Sep 17 00:00:00 2001 From: Jean-Luc Fattebert Date: Thu, 5 Dec 2024 22:21:41 -0500 Subject: [PATCH] Write energies in csv files for 3 phases (#74) --- drivers/plotEnergyVsCompositionThreePhase.cc | 2 +- src/CALPHADFreeEnergyFunctionsBinary3Ph2Sl.cc | 36 +++++-------------- ...PHADFreeEnergyFunctionsBinaryThreePhase.cc | 36 +++++-------------- utils/FvsCbinaryThreePhases.plt | 8 +++-- 4 files changed, 24 insertions(+), 58 deletions(-) diff --git a/drivers/plotEnergyVsCompositionThreePhase.cc b/drivers/plotEnergyVsCompositionThreePhase.cc index f6978d9..99b28e9 100644 --- a/drivers/plotEnergyVsCompositionThreePhase.cc +++ b/drivers/plotEnergyVsCompositionThreePhase.cc @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) boost::optional newton_db; const int npts = 100; - std::ofstream os("FvsC.dat", std::ios::out); + std::ofstream os("FvsC.csv", std::ios::out); std::cout << " Compute energies..." << std::endl; if (Thermo4PFM::checkSublattice(calphad_db)) diff --git a/src/CALPHADFreeEnergyFunctionsBinary3Ph2Sl.cc b/src/CALPHADFreeEnergyFunctionsBinary3Ph2Sl.cc index b689fef..6782558 100644 --- a/src/CALPHADFreeEnergyFunctionsBinary3Ph2Sl.cc +++ b/src/CALPHADFreeEnergyFunctionsBinary3Ph2Sl.cc @@ -468,39 +468,21 @@ void CALPHADFreeEnergyFunctionsBinary3Ph2Sl::printEnergyVsComposition( const double temperature, std::ostream& os, const double cmin, const double cmax, const int npts) { - const double dc = (cmax - cmin) / (double)(npts - 1); + const double dc = (cmax - cmin) / (double)(npts - 1); + const double phil[3] = { 1., 0., 0. }; + const double phia[3] = { 0., 1., 0. }; + const double phib[3] = { 0., 0., 1. }; - os << "#phi0=1" << std::endl; + os << "c, fL, fA, fB" << std::endl; for (int i = 0; i < npts; i++) { const double conc = i * dc + cmin; - const double phi[3] = { 1., 0., 0. }; + double el = fchem(phil, &conc, temperature); + double ea = fchem(phia, &conc, temperature); + double eb = fchem(phib, &conc, temperature); - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; - } - os << std::endl << std::endl; - - os << "#phi1=1" << std::endl; - for (int i = 0; i < npts; i++) - { - const double conc = i * dc + cmin; - - const double phi[3] = { 0., 1., 0. }; - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; - } - os << std::endl << std::endl; - - os << "#phi2=1" << std::endl; - for (int i = 0; i < npts; i++) - { - const double conc = i * dc + cmin; - - const double phi[3] = { 0., 0., 1. }; - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; + os << conc << ", " << el << ", " << ea << ", " << eb << std::endl; } } diff --git a/src/CALPHADFreeEnergyFunctionsBinaryThreePhase.cc b/src/CALPHADFreeEnergyFunctionsBinaryThreePhase.cc index f636eeb..8265cd0 100644 --- a/src/CALPHADFreeEnergyFunctionsBinaryThreePhase.cc +++ b/src/CALPHADFreeEnergyFunctionsBinaryThreePhase.cc @@ -353,39 +353,21 @@ void CALPHADFreeEnergyFunctionsBinaryThreePhase::printEnergyVsComposition( const double temperature, std::ostream& os, const double cmin, const double cmax, const int npts) { - const double dc = (cmax - cmin) / (double)(npts - 1); + const double dc = (cmax - cmin) / (double)(npts - 1); + const double phil[3] = { 1., 0., 0. }; + const double phia[3] = { 0., 1., 0. }; + const double phib[3] = { 0., 0., 1. }; - os << "#phi0=1" << std::endl; + os << "c, fL, fA, fB" << std::endl; for (int i = 0; i < npts; i++) { const double conc = i * dc + cmin; - const double phi[3] = { 1., 0., 0. }; + double el = fchem(phil, &conc, temperature); + double ea = fchem(phia, &conc, temperature); + double eb = fchem(phib, &conc, temperature); - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; - } - os << std::endl << std::endl; - - os << "#phi1=1" << std::endl; - for (int i = 0; i < npts; i++) - { - const double conc = i * dc + cmin; - - const double phi[3] = { 0., 1., 0. }; - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; - } - os << std::endl << std::endl; - - os << "#phi2=1" << std::endl; - for (int i = 0; i < npts; i++) - { - const double conc = i * dc + cmin; - - const double phi[3] = { 0., 0., 1. }; - double e = fchem(phi, &conc, temperature); - os << conc << "\t" << e << std::endl; + os << conc << ", " << el << ", " << ea << ", " << eb << std::endl; } } diff --git a/utils/FvsCbinaryThreePhases.plt b/utils/FvsCbinaryThreePhases.plt index 674ea2a..a968fdf 100644 --- a/utils/FvsCbinaryThreePhases.plt +++ b/utils/FvsCbinaryThreePhases.plt @@ -5,8 +5,10 @@ set size 0.7,0.7 set output "FvsC.png" set xlabel "Composition" set ylabel "Energy (J/mol)" +set datafile separator "," +set key autotitle columnhead -plot 'FvsC.dat' i 0 u 1:2 t 'phase 1' w lines lw 2, \ - 'FvsC.dat' i 1 u 1:2 t 'phase 2' w lines lw 2, \ - 'FvsC.dat' i 2 u 1:2 t 'phase 3' w lines lw 2 +plot 'FvsC.csv' u 1:2 t 'phase L' w lines lw 2, \ + 'FvsC.csv' u 1:3 t 'phase A' w lines lw 2, \ + 'FvsC.csv' u 1:4 t 'phase B' w lines lw 2