diff --git a/source/CALPHADFreeEnergyStrategyBinaryThreePhase.h b/source/CALPHADFreeEnergyStrategyBinaryThreePhase.h index 6197efde..df9eb8a7 100644 --- a/source/CALPHADFreeEnergyStrategyBinaryThreePhase.h +++ b/source/CALPHADFreeEnergyStrategyBinaryThreePhase.h @@ -35,7 +35,7 @@ class CALPHADFreeEnergyStrategyBinaryThreePhase : public ConcFreeEnergyStrategy MolarVolumeStrategy* mvstrategy, const int conc_l_id, const int conc_a_id, const int conc_b_id); - ~CALPHADFreeEnergyStrategyBinaryThreePhase(){}; + virtual ~CALPHADFreeEnergyStrategyBinaryThreePhase(){}; void setup(boost::property_tree::ptree calphad_db, std::shared_ptr newton_db); @@ -128,6 +128,10 @@ class CALPHADFreeEnergyStrategyBinaryThreePhase : public ConcFreeEnergyStrategy d_calphad_fenergy->preRunDiagnostics(temperature); } + protected: + Thermo4PFM::EnergyInterpolationType d_energy_interp_func_type; + Thermo4PFM::ConcInterpolationType d_conc_interp_func_type; + private: int d_conc_l_id; int d_conc_a_id; @@ -137,9 +141,6 @@ class CALPHADFreeEnergyStrategyBinaryThreePhase : public ConcFreeEnergyStrategy MolarVolumeStrategy* d_mv_strategy; - Thermo4PFM::EnergyInterpolationType d_energy_interp_func_type; - Thermo4PFM::ConcInterpolationType d_conc_interp_func_type; - void defaultComputeSecondDerivativeEnergyPhaseL( const double temperature, const std::vector& c, std::vector& d2fdc2, const bool use_internal_units); diff --git a/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc b/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc new file mode 100644 index 00000000..a67218d4 --- /dev/null +++ b/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2018, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and +// the Oak Ridge National Laboratory +// LLNL-CODE-747500 +// All rights reserved. +// This file is part of AMPE. +// For details, see https://github.com/LLNL/AMPE +// Please also read AMPE/LICENSE. +// +#include "CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h" + +#include +#include "Database2JSON.h" +namespace pt = boost::property_tree; + +#include "SAMRAI/tbox/InputManager.h" +#include "SAMRAI/pdat/CellData.h" +#include "SAMRAI/hier/Index.h" +#include "SAMRAI/math/HierarchyCellDataOpsReal.h" + +using namespace SAMRAI; + +#include + +//======================================================================= + +CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB:: + CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB( + boost::property_tree::ptree calphad_db, + std::shared_ptr newton_db, + const Thermo4PFM::EnergyInterpolationType energy_interp_func_type, + const Thermo4PFM::ConcInterpolationType conc_interp_func_type, + MolarVolumeStrategy* mvstrategy, const int conc_l_id, + const int conc_a_id, const int conc_b_id) + : CALPHADFreeEnergyStrategyBinaryThreePhase< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinary3Ph2Sl, + TiltingFolchPlapp2005>(calphad_db, newton_db, energy_interp_func_type, + conc_interp_func_type, mvstrategy, conc_l_id, + conc_a_id, conc_b_id) +{ + setup(calphad_db, newton_db); +} + +//======================================================================= + +void CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB::setup( + pt::ptree calphad_pt, std::shared_ptr newton_db) +{ + pt::ptree newton_pt; + if (newton_db) copyDatabase(newton_db, newton_pt); + // set looser tol in solver + newton_pt.put("tol", 1.e-6); + d_ceq_fenergy.reset(new Thermo4PFM::CALPHADFreeEnergyFunctionsBinary( + calphad_pt, newton_pt, d_energy_interp_func_type, + d_conc_interp_func_type)); +} + + +bool CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB::computeCeqT( + const double temperature, const Thermo4PFM::PhaseIndex pi0, + const Thermo4PFM::PhaseIndex pi1, double* ceq) +{ + std::cout << "CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB::" + "computeCeqT..." + << std::endl; + return d_ceq_fenergy->computeCeqT(temperature, &ceq[0], 50, true); +} diff --git a/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h b/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h new file mode 100644 index 00000000..6a7b5e5b --- /dev/null +++ b/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h @@ -0,0 +1,54 @@ +// Copyright (c) 2018, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and +// the Oak Ridge National Laboratory +// LLNL-CODE-747500 +// All rights reserved. +// This file is part of AMPE. +// For details, see https://github.com/LLNL/AMPE +// Please also read AMPE/LICENSE. +// +#ifndef included_CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB +#define included_CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB + +#include "CALPHADFreeEnergyStrategyBinaryThreePhase.h" +#include "InterpolationType.h" +#include "TiltingFolchPlapp2005.h" + +#include "CALPHADFreeEnergyFunctionsBinary3Ph2Sl.h" +#include "CALPHADFreeEnergyFunctionsBinary.h" + +#include "SAMRAI/pdat/CellData.h" +#include "SAMRAI/tbox/Database.h" +#include "SAMRAI/hier/Box.h" +class MolarVolumeStrategy; + +#include +#include +#include + +class CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB + : public CALPHADFreeEnergyStrategyBinaryThreePhase< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinary3Ph2Sl, + TiltingFolchPlapp2005> +{ + public: + CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB( + boost::property_tree::ptree calphad_db, + std::shared_ptr newton_db, + const Thermo4PFM::EnergyInterpolationType energy_interp_func_type, + const Thermo4PFM::ConcInterpolationType conc_interp_func_type, + MolarVolumeStrategy* mvstrategy, const int conc_l_id, + const int conc_a_id, const int conc_b_id); + + bool computeCeqT(const double temperature, const Thermo4PFM::PhaseIndex pi0, + const Thermo4PFM::PhaseIndex pi1, double* ceq) override; + + private: + void setup(boost::property_tree::ptree calphad_pt, + std::shared_ptr newton_db); + + std::shared_ptr d_ceq_fenergy; +}; + +#endif diff --git a/source/CALPHADequilibriumPhaseConcentrationsStrategy.cc b/source/CALPHADequilibriumPhaseConcentrationsStrategy.cc index 2cb6f4f2..655e630c 100644 --- a/source/CALPHADequilibriumPhaseConcentrationsStrategy.cc +++ b/source/CALPHADequilibriumPhaseConcentrationsStrategy.cc @@ -17,6 +17,7 @@ namespace pt = boost::property_tree; #include "CALPHADFreeEnergyFunctionsBinaryThreePhase.h" #include "CALPHADFreeEnergyFunctionsBinary3Ph2Sl.h" #include "CALPHADFreeEnergyFunctionsBinary2Ph1Sl.h" +#include "CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB.h" #include "SAMRAI/geom/CartesianPatchGeometry.h" #include "SAMRAI/math/PatchCellDataNormOpsReal.h" @@ -159,6 +160,25 @@ CALPHADequilibriumPhaseConcentrationsStrategy< Thermo4PFM::ConcInterpolationType::LINEAR)); } +template +CALPHADequilibriumPhaseConcentrationsStrategy:: + CALPHADequilibriumPhaseConcentrationsStrategy( + const int conc_l_scratch_id, const int conc_a_scratch_id, + const int conc_b_scratch_id, const int conc_l_ref_id, + const int conc_a_ref_id, const int conc_b_ref_id, + const Thermo4PFM::EnergyInterpolationType energy_interp_func_type, + const Thermo4PFM::ConcInterpolationType conc_interp_func_type, + const bool with_third_phase, pt::ptree calphad_pt, + std::shared_ptr newton_db, const unsigned ncompositions) + : PhaseConcentrationsStrategy(conc_l_scratch_id, conc_a_scratch_id, + conc_b_scratch_id, with_third_phase), + d_conc_l_ref_id(conc_l_ref_id), + d_conc_a_ref_id(conc_a_ref_id), + d_conc_b_ref_id(conc_b_ref_id), + d_conc_interp_func_type(conc_interp_func_type) +{ +} + template int CALPHADequilibriumPhaseConcentrationsStrategy:: computePhaseConcentrationsOnPatch( @@ -385,8 +405,11 @@ int CALPHADequilibriumPhaseConcentrationsStrategy:: int status = d_calphad_fenergy->computePhaseConcentrations(temp, c, hphi, x); - // std::cerr << "x=" << x[0] << "," << x[1] << "," << x[2] - // << std::endl; + std::cout << "computePhaseConcentrations for T=" << temp + << ", hphi="; + for (short i = 0; i < nphases; i++) + std::cerr << hphi[i] << ", "; + std::cerr << ", c=" << c[0] << std::endl; if (status < 0) { std::cerr << "computePhaseConcentrations failed for T=" << temp @@ -452,3 +475,8 @@ int CALPHADequilibriumPhaseConcentrationsStrategy:: #endif return nits; } + +template class CALPHADequilibriumPhaseConcentrationsStrategy< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhase>; +template class CALPHADequilibriumPhaseConcentrationsStrategy< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB>; diff --git a/source/CALPHADequilibriumPhaseConcentrationsStrategy.h b/source/CALPHADequilibriumPhaseConcentrationsStrategy.h index 55ce6ecf..873aaa03 100644 --- a/source/CALPHADequilibriumPhaseConcentrationsStrategy.h +++ b/source/CALPHADequilibriumPhaseConcentrationsStrategy.h @@ -16,6 +16,8 @@ #include "SAMRAI/tbox/InputManager.h" +#include + template class CALPHADequilibriumPhaseConcentrationsStrategy : public PhaseConcentrationsStrategy @@ -28,7 +30,7 @@ class CALPHADequilibriumPhaseConcentrationsStrategy const Thermo4PFM::EnergyInterpolationType energy_interp_func_type, const Thermo4PFM::ConcInterpolationType conc_interp_func_type, const bool with_third_phase, boost::property_tree::ptree calphad_pt, - std::shared_ptr newton_d, const unsigned ncompositions); + std::shared_ptr newton_db, const unsigned ncompositions); ~CALPHADequilibriumPhaseConcentrationsStrategy() {} @@ -42,13 +44,14 @@ class CALPHADequilibriumPhaseConcentrationsStrategy std::shared_ptr > cd_c_b, std::shared_ptr patch); + protected: + std::unique_ptr d_calphad_fenergy; + private: int d_conc_l_ref_id; int d_conc_a_ref_id; int d_conc_b_ref_id; - std::unique_ptr d_calphad_fenergy; - const Thermo4PFM::ConcInterpolationType d_conc_interp_func_type; }; diff --git a/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.cc b/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.cc new file mode 100644 index 00000000..4ca842d5 --- /dev/null +++ b/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.cc @@ -0,0 +1,40 @@ +// Copyright (c) 2018, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and +// the Oak Ridge National Laboratory +// LLNL-CODE-747500 +// All rights reserved. +// This file is part of AMPE. +// For details, see https://github.com/LLNL/AMPE +// Please also read AMPE/LICENSE. +// +#include "CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.h" +#include "Database2JSON.h" + +namespace pt = boost::property_tree; + +CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB:: + CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB( + const double cB, const int conc_l_scratch_id, + const int conc_a_scratch_id, const int conc_b_scratch_id, + const int conc_l_ref_id, const int conc_a_ref_id, + const int conc_b_ref_id, pt::ptree calphad_pt, + std::shared_ptr newton_db) + : CALPHADequilibriumPhaseConcentrationsStrategy< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB>( + conc_l_scratch_id, conc_a_scratch_id, conc_b_scratch_id, + conc_l_ref_id, conc_a_ref_id, conc_b_ref_id, + Thermo4PFM::EnergyInterpolationType::LINEAR, + Thermo4PFM::ConcInterpolationType::LINEAR, false, calphad_pt, + newton_db, 1) +{ + pt::ptree newton_pt; + if (newton_db) copyDatabase(newton_db, newton_pt); + + d_calphad_fenergy = std::unique_ptr< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB>( + new Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB( + cB, calphad_pt, newton_pt, + Thermo4PFM::EnergyInterpolationType::LINEAR, + Thermo4PFM::ConcInterpolationType::LINEAR)); +} diff --git a/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.h b/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.h new file mode 100644 index 00000000..337bc51f --- /dev/null +++ b/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.h @@ -0,0 +1,35 @@ +// Copyright (c) 2018, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and +// the Oak Ridge National Laboratory +// LLNL-CODE-747500 +// All rights reserved. +// This file is part of AMPE. +// For details, see https://github.com/LLNL/AMPE +// Please also read AMPE/LICENSE. +// +#ifndef included_CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB +#define included_CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB + +#include "CALPHADequilibriumPhaseConcentrationsStrategy.h" +#include "CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB.h" + +#include "SAMRAI/tbox/InputManager.h" + +#include + +class CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB + : public CALPHADequilibriumPhaseConcentrationsStrategy< + Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB> +{ + public: + CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB( + const double cB, const int conc_l_id, const int conc_a_id, + const int conc_b_id, const int conc_l_ref_id, const int conc_a_ref_id, + const int conc_b_ref_id, boost::property_tree::ptree calphad_pt, + std::shared_ptr newton_db); + + ~CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB() {} +}; + +#endif diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 42360219..83e866f8 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -73,6 +73,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/source/KKStools.cc ${CMAKE_SOURCE_DIR}/source/CALPHADequilibriumPhaseConcentrationsStrategyMultiOrderThreePhases.cc ${CMAKE_SOURCE_DIR}/source/QuadraticEquilibriumThreePhasesTernaryStrategyMultiOrder.cc ${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyStrategyBinaryThreePhase.cc + ${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc ${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyStrategyTernary.cc ${CMAKE_SOURCE_DIR}/source/tools.cc ${CMAKE_SOURCE_DIR}/source/FreeEnergyStrategy.cc @@ -132,6 +133,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/source/KKStools.cc ${CMAKE_SOURCE_DIR}/source/QuadraticFreeEnergyStrategy.cc ${CMAKE_SOURCE_DIR}/source/QuadraticEquilibriumPhaseConcentrationsStrategy.cc ${CMAKE_SOURCE_DIR}/source/CALPHADequilibriumPhaseConcentrationsStrategy.cc + ${CMAKE_SOURCE_DIR}/source/CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.cc ${CMAKE_SOURCE_DIR}/source/GaussianTemperatureStrategy.cc ${CMAKE_SOURCE_DIR}/source/ScalarTemperatureStrategy.cc ${CMAKE_SOURCE_DIR}/source/SteadyStateTemperatureStrategy.cc diff --git a/source/FreeEnergyStrategyFactory.h b/source/FreeEnergyStrategyFactory.h index be7ffc75..36e7721a 100644 --- a/source/FreeEnergyStrategyFactory.h +++ b/source/FreeEnergyStrategyFactory.h @@ -19,6 +19,7 @@ #include "CALPHADFreeEnergyStrategyWithPenalty.h" #include "CALPHADFreeEnergyStrategyBinaryThreePhase.h" #include "CALPHADFreeEnergyStrategyMultiOrder.h" +#include "CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h" #include "QuadraticFreeEnergyStrategyMultiOrder.h" #include "QuadraticFreeEnergyStrategyMultiOrderTernaryThreePhase.h" #include "KKSdiluteBinary.h" @@ -117,16 +118,26 @@ class FreeEnergyStrategyFactory tbox::plog << "CALPHADFreeEnergyFunctionsBinaryThreePha" "se" << std::endl; - free_energy_strategy.reset( - new CALPHADFreeEnergyStrategyBinaryThreePhase< - Thermo4PFM:: - CALPHADFreeEnergyFunctionsBinaryThreePhase, - TiltingFolchPlapp2005>( - calphad_pt, newton_db, - model_parameters.energy_interp_func_type(), - model_parameters.conc_interp_func_type(), - mvstrategy, conc_l_scratch_id, - conc_a_scratch_id, conc_b_scratch_id)); + if (model_parameters.getStochioB()) { + free_energy_strategy.reset( + new CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB( + calphad_pt, newton_db, + model_parameters.energy_interp_func_type(), + model_parameters.conc_interp_func_type(), + mvstrategy, conc_l_scratch_id, + conc_a_scratch_id, conc_b_scratch_id)); + } else { + free_energy_strategy.reset( + new CALPHADFreeEnergyStrategyBinaryThreePhase< + Thermo4PFM:: + CALPHADFreeEnergyFunctionsBinaryThreePhase, + TiltingFolchPlapp2005>( + calphad_pt, newton_db, + model_parameters.energy_interp_func_type(), + model_parameters.conc_interp_func_type(), + mvstrategy, conc_l_scratch_id, + conc_a_scratch_id, conc_b_scratch_id)); + } } // conc_b_scratch_id<0 } else { diff --git a/source/PhaseConcentrationsStrategyFactory.h b/source/PhaseConcentrationsStrategyFactory.h index 37609d11..f2056081 100644 --- a/source/PhaseConcentrationsStrategyFactory.h +++ b/source/PhaseConcentrationsStrategyFactory.h @@ -11,6 +11,7 @@ #ifndef included_PhaseConcentrationsStrategyFactory #define included_PhaseConcentrationsStrategyFactory +#include "CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB.h" #include "CALPHADequilibriumPhaseConcentrationsStrategy.h" #include "KKSdiluteEquilibriumPhaseConcentrationsStrategy.h" #include "QuadraticEquilibriumPhaseConcentrationsStrategy.h" @@ -70,6 +71,7 @@ class PhaseConcentrationsStrategyFactory if (ncompositions == 1) { tbox::plog << "Binary alloy..." << std::endl; bool subl = Thermo4PFM::checkSublattice(calphad_pt); + double cB = model_parameters.getStochioB(); if (conc_b_scratch_id >= 0) { tbox::plog << "Three phases..." << std::endl; // three phases @@ -95,7 +97,13 @@ class PhaseConcentrationsStrategyFactory } } else { // three phases model - if (subl) { + if (cB >= 0.) { + phase_conc_strategy.reset( + new CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB( + cB, conc_l_scratch_id, conc_a_scratch_id, + conc_b_scratch_id, conc_l_ref_id, conc_a_ref_id, + conc_b_ref_id, calphad_pt, newton_db)); + } else if (subl) { phase_conc_strategy.reset( new CALPHADequilibriumPhaseConcentrationsStrategy< Thermo4PFM:: diff --git a/source/QuatModelParameters.cc b/source/QuatModelParameters.cc index efa307d8..7d090633 100644 --- a/source/QuatModelParameters.cc +++ b/source/QuatModelParameters.cc @@ -89,6 +89,7 @@ QuatModelParameters::QuatModelParameters() : d_moving_frame_velocity(def_val) d_well_bias_gamma = def_val; d_liquidus_slope = def_val; d_average_concentration = def_val; + d_stochio_cB = -1.; d_avg_func_type = ""; d_diffq_avg_func_type = ""; @@ -399,6 +400,8 @@ void QuatModelParameters::readConcDB(std::shared_ptr conc_db) d_init_phase_conc_eq = conc_db->getBoolWithDefault("init_phase_conc_eq", true); + + d_stochio_cB = conc_db->getDoubleWithDefault("stochio_cB", -1.); } void QuatModelParameters::readDiluteAlloy( diff --git a/source/QuatModelParameters.h b/source/QuatModelParameters.h index 3efe3b52..f72f0fee 100644 --- a/source/QuatModelParameters.h +++ b/source/QuatModelParameters.h @@ -136,6 +136,7 @@ class QuatModelParameters { return d_initc_in_phase[d_ncompositions + index]; } + double getStochioB() { return d_stochio_cB; } double meltingT() const { return d_meltingT; } double interfaceMobility() const { return d_interface_mobility; } double rescale_factorT() const { return d_rescale_factorT; } @@ -586,6 +587,9 @@ class QuatModelParameters */ std::vector d_initc_in_phase; + // stochio composition of phase B (if set to value >= 0) + double d_stochio_cB; + // free energy parameters: // f(phi) = d_phase_well_scale * g(phi) // + p(phi)*( d_free_energy_solid - d_free_energy_liquid)