1 #ifndef CASM_MonteIO_impl_HH
2 #define CASM_MonteIO_impl_HH
11 template<
typename MonteType>
15 return static_cast<const MonteType *
>(ptr)->conditions().temperature();
21 template<
typename MonteType>
25 return static_cast<const MonteType *
>(ptr)->conditions().beta();
31 template<
typename MonteType>
35 return static_cast<const MonteType *
>(ptr)->conditions().param_chem_pot()(index);
42 template<
typename MonteType>
46 return static_cast<const MonteType *
>(ptr)->conditions().chem_pot(index);
53 template<
typename MonteType>
57 return static_cast<const MonteType *
>(ptr)->conditions().param_composition()(index);
64 template<
typename MonteType>
68 return static_cast<const MonteType *
>(ptr)->conditions().mol_composition()(index);
75 template<
typename MonteType>
78 const MonteType *mc_ptr =
static_cast<const MonteType *
>(mc);
83 std::string header = std::string(
"site_frac(") + mc.primclex().get_prim().get_struc_molecule_name()[index] +
")";
88 template<
typename MonteType>
91 const MonteType *mc_ptr =
static_cast<const MonteType *
>(mc);
93 if(mc->primclex().vacancy_allowed()) {
94 comp_n(mc->primclex().vacancy_index()) = 0.0;
96 auto atom_frac = comp_n / comp_n.sum();
97 return atom_frac[index];
99 std::string header = std::string(
"atom_frac(") + mc.primclex().get_prim().get_struc_molecule_name()[index] +
")";
106 template<
typename MonteType>
110 CovEvaluator cov_evaluator(
"potential_energy",
"potential_energy");
111 auto N = mc->supercell().volume();
113 auto T =
static_cast<const MonteType *
>(ptr)->conditions().temperature();
114 return cov_evaluator(mc) * N / (
KB * T * T);
118 return mc->is_equilibrated().first;
121 std::string header = std::string(
"heat_capacity");
132 template<
typename MonteType>
135 std::string name_i =
"comp(" + comp_var_i +
")";
136 std::string name_j =
"comp(" + comp_var_j +
")";
140 auto N = mc->supercell().volume();
142 auto T =
static_cast<const MonteType *
>(ptr)->conditions().temperature();
143 return cov_evaluator(mc) * N / (
KB * T);
147 return mc->is_equilibrated().first;
150 std::string header = std::string(
"susc_x(" + comp_var_i +
"," + comp_var_j +
")");
161 template<
typename MonteType>
164 std::string name_i =
"comp_n(" + species_i +
")";
165 std::string name_j =
"comp_n(" + species_j +
")";
169 auto N = mc->supercell().volume();
171 auto T =
static_cast<const MonteType *
>(ptr)->conditions().temperature();
172 return cov_evaluator(mc) * N / (
KB * T);
176 return mc->is_equilibrated().first;
179 std::string header = std::string(
"susc_n(" + species_i +
"," + species_j +
")");
189 template<
typename MonteType>
190 GenericDatumFormatter<double, ConstMonteCarloPtr>
193 std::string name_i =
"comp(" + comp_var_i +
")";
197 auto N = mc->supercell().volume();
199 auto T =
static_cast<const MonteType *
>(ptr)->conditions().temperature();
200 return cov_evaluator(mc) * N / (
KB * T);
204 return mc->is_equilibrated().first;
207 std::string header = std::string(
"susc_x(S," + comp_var_i +
")");
213 template<
typename MonteType>
214 GenericDatumFormatter<double, ConstMonteCarloPtr>
217 std::string name_i =
"comp_n(" + species_i +
")";
221 auto N = mc->supercell().volume();
223 auto T =
static_cast<const MonteType *
>(ptr)->conditions().temperature();
224 return cov_evaluator(mc) * N / (
KB * T);
228 return mc->is_equilibrated().first;
231 std::string header = std::string(
"susc_n(S," + species_i +
")");
237 template<
typename MonteType>
247 _log <<
"write: " <<
dir.results_csv() <<
"\n";
251 if(!fs::exists(file)) {
253 formatter.print_header(&mc, sout);
256 sout.open(file, std::ios::app);
259 formatter.print(&mc, sout);
266 _log <<
"write: " <<
dir.results_json() <<
"\n";
270 if(fs::exists(file)) {
277 formatter.to_json_arrays(&mc, results);
282 std::cerr <<
"ERROR writing results" << std::endl;
289 template<
typename MonteType>
293 fs::create_directories(
dir.conditions_dir(cond_index));
295 to_json(mc.conditions(), json);
296 _log <<
"write: " <<
dir.conditions_json(cond_index) <<
"\n";
297 json.write(
dir.conditions_json(cond_index));
300 std::cerr <<
"ERROR writing conditions.json" << std::endl;
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloThermoChemSuscXFormatter(std::string comp_var_i)
Print parametric thermo-chemical susceptibility, 'susc_x(S,a)'.
void write_results(const MonteSettings &settings, const MonteType &mc, Log &_log)
Will create new file or append to existing file results of the latest run.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloAtomFracFormatter(const MonteType &mc, int index)
Print atom_frac(X) for any class MonteType with valid 'Eigen::VectorXd MonteType::comp_n'.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloParamChemPotFormatter(const MonteType &mc, int index)
Print param_chem_pot(x)
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloBetaFormatter()
Print Beta.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloCompFormatter(const MonteType &mc, int index)
Print comp(x)
void write_conditions_json(const MonteSettings &settings, const MonteType &mc, Index cond_index, Log &_log)
Write conditions to conditions.cond_index directory.
void write(const std::string &file_name, unsigned int indent=2, unsigned int prec=12) const
Write json to file.
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloCompNFormatter(const MonteType &mc, int index)
Print comp_n(N)
bool read(std::istream &stream)
Reads json from the stream.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloHeatCapacityFormatter()
Print heat capacity, 'heat_capacity'.
const fs::path output_directory() const
Directory where output should go.
std::vector< std::string > get_struc_molecule_name() const
Returns an Array of each possible Molecule in this Structure.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloSuscXFormatter(std::string comp_var_i, std::string comp_var_j)
Print parametric susceptibility, 'susc_x(a,b)'.
Eigen::VectorXd comp_n(const ConfigDoF &configdof, const Supercell &scel)
Returns comp_n, the number of each molecule per primitive cell, ordered as Structure::get_struc_molec...
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloChemPotFormatter(const MonteType &mc, int index)
Print chem_pot(N)
static std::string comp_var(size_type i)
Composition variable names: "a", "b", ...
EigenIndex Index
For long integer indexing:
const PrimClex & primclex() const
const Access the PrimClex that *this is based on
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloSiteFracFormatter(const MonteType &mc, int index)
Print site_frac(x) for any class MonteType with valid 'Eigen::VectorXd MonteType::comp_n'.
Interface base class for all types of Monte Carlo simulations (not meant to be used polymorphically) ...
Eigen::VectorXd site_frac(const Configuration &config)
Returns the composition as site fraction, in the order of Structure::get_struc_molecule.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloSuscNFormatter(std::string species_i, std::string species_j)
Print susceptibility, 'susc_n(A,B)'.
Functor to help evaluate covariance.
bool write_csv() const
Write csv versions of files? (csv is the default format if no 'output_format' given) ...
bool write_json() const
Write json versions of files?
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloTFormatter()
Print Temperature.
GenericDatumFormatter< double, ConstMonteCarloPtr > MonteCarloThermoChemSuscNFormatter(std::string species_i)
Print thermo-chemical susceptibility, 'susc_n(S,A)'.
Settings for Monte Carlo calculations.
static jsonParser object()
Returns an empty json object.
const Structure & get_prim() const
const Access to primitive Structure
DataFormatter< ConstMonteCarloPtr > make_results_formatter(const GrandCanonical &mc)
Make a LTE results formatter.