Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stochiometric composition for phase B #255

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions source/CALPHADFreeEnergyStrategyBinaryThreePhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<tbox::Database> newton_db);
Expand Down Expand Up @@ -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;
Expand All @@ -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<double>& c,
std::vector<double>& d2fdc2, const bool use_internal_units);
Expand Down
68 changes: 68 additions & 0 deletions source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc
Original file line number Diff line number Diff line change
@@ -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 <boost/property_tree/json_parser.hpp>
#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 <cassert>

//=======================================================================

CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB::
CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB(
boost::property_tree::ptree calphad_db,
std::shared_ptr<tbox::Database> 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<tbox::Database> 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);
}
54 changes: 54 additions & 0 deletions source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>
#include <boost/property_tree/ptree.hpp>

class CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB
: public CALPHADFreeEnergyStrategyBinaryThreePhase<
Thermo4PFM::CALPHADFreeEnergyFunctionsBinary3Ph2Sl,
TiltingFolchPlapp2005>
{
public:
CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB(
boost::property_tree::ptree calphad_db,
std::shared_ptr<tbox::Database> 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<tbox::Database> newton_db);

std::shared_ptr<Thermo4PFM::CALPHADFreeEnergyFunctionsBinary> d_ceq_fenergy;
};

#endif
32 changes: 30 additions & 2 deletions source/CALPHADequilibriumPhaseConcentrationsStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -159,6 +160,25 @@ CALPHADequilibriumPhaseConcentrationsStrategy<
Thermo4PFM::ConcInterpolationType::LINEAR));
}

template <class FreeEnergyType>
CALPHADequilibriumPhaseConcentrationsStrategy<FreeEnergyType>::
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<tbox::Database> 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 <class FreeEnergyType>
int CALPHADequilibriumPhaseConcentrationsStrategy<FreeEnergyType>::
computePhaseConcentrationsOnPatch(
Expand Down Expand Up @@ -385,8 +405,11 @@ int CALPHADequilibriumPhaseConcentrationsStrategy<FreeEnergyType>::
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
Expand Down Expand Up @@ -452,3 +475,8 @@ int CALPHADequilibriumPhaseConcentrationsStrategy<FreeEnergyType>::
#endif
return nits;
}

template class CALPHADequilibriumPhaseConcentrationsStrategy<
Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhase>;
template class CALPHADequilibriumPhaseConcentrationsStrategy<
Thermo4PFM::CALPHADFreeEnergyFunctionsBinaryThreePhaseStochioB>;
9 changes: 6 additions & 3 deletions source/CALPHADequilibriumPhaseConcentrationsStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "SAMRAI/tbox/InputManager.h"

#include <boost/property_tree/ptree.hpp>

template <class FreeEnergyType>
class CALPHADequilibriumPhaseConcentrationsStrategy
: public PhaseConcentrationsStrategy
Expand All @@ -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<tbox::Database> newton_d, const unsigned ncompositions);
std::shared_ptr<tbox::Database> newton_db, const unsigned ncompositions);

~CALPHADequilibriumPhaseConcentrationsStrategy() {}

Expand All @@ -42,13 +44,14 @@ class CALPHADequilibriumPhaseConcentrationsStrategy
std::shared_ptr<pdat::CellData<double> > cd_c_b,
std::shared_ptr<hier::Patch> patch);

protected:
std::unique_ptr<FreeEnergyType> 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<FreeEnergyType> d_calphad_fenergy;

const Thermo4PFM::ConcInterpolationType d_conc_interp_func_type;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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<tbox::Database> 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));
}
Original file line number Diff line number Diff line change
@@ -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 <boost/property_tree/ptree.hpp>

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<tbox::Database> newton_db);

~CALPHADequilibriumPhaseConcentrationsStrategyThreePhaseStochioB() {}
};

#endif
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 21 additions & 10 deletions source/FreeEnergyStrategyFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
Loading