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

Parabolic 3phases new #288

Draft
wants to merge 10 commits 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
21 changes: 21 additions & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ add_executable(plotCALPHADbinary
target_link_libraries(plotCALPHADbinary ${PROJECT_LINK_LIBS_SAMRAI}
${THERMOLIB})

add_executable(plotEnergyVsCompositionParabolicThreePhase
${CMAKE_SOURCE_DIR}/drivers/plotEnergyVsCompositionParabolicThreePhase.cc )
target_link_libraries(plotEnergyVsCompositionParabolicThreePhase ${PROJECT_LINK_LIBS_SAMRAI}
${THERMOLIB})

add_executable(computeEquilibriumCompositions
computeEquilibriumCompositions.cc
${CMAKE_SOURCE_DIR}/source/Database2JSON.cc
Expand Down Expand Up @@ -41,6 +46,22 @@ target_link_libraries(computeCALPHADbinaryEquilibrium
${PROJECT_LINK_LIBS_SAMRAI}
${THERMOLIB})

add_executable(computeParabolic3PhasesEquilibrium
computeParabolic3PhasesEquilibrium.cc
${CMAKE_SOURCE_DIR}/source/Database2JSON.cc
${CMAKE_SOURCE_DIR}/source/fortran/functions.f)
target_link_libraries(computeParabolic3PhasesEquilibrium
${PROJECT_LINK_LIBS_SAMRAI}
${THERMOLIB})

add_executable(computeParabolic3PhasesKKS
computeParabolic3PhasesKKS.cc
${CMAKE_SOURCE_DIR}/source/Database2JSON.cc
${CMAKE_SOURCE_DIR}/source/fortran/functions.f)
target_link_libraries(computeParabolic3PhasesKKS
${PROJECT_LINK_LIBS_SAMRAI}
${THERMOLIB})

add_executable(convertDatabase2JSON
${CMAKE_SOURCE_DIR}/source/Database2JSON.cc
convertDatabase2JSON.cc )
Expand Down
110 changes: 110 additions & 0 deletions drivers/computeParabolic3PhasesEquilibrium.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "ParabolicEqConcSolverBinary.h"

#include "SAMRAI/tbox/SAMRAIManager.h"
#include "SAMRAI/tbox/InputManager.h"
#include "SAMRAI/tbox/Database.h"
#include "SAMRAI/SAMRAI_config.h"
#include "SAMRAI/tbox/SAMRAI_MPI.h"

#include <boost/optional/optional.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

namespace pt = boost::property_tree;
using namespace SAMRAI;

int main(int argc, char* argv[])
{
tbox::SAMRAI_MPI::init(&argc, &argv);
tbox::SAMRAIManager::initialize();
tbox::SAMRAIManager::startup();

int ret = 0;
{
std::string databasename(argv[1]);
double temperature = atof(argv[2]);
std::cout << "Temperature = " << temperature << std::endl;
double c0 = 0.5;
double c1 = 1.5;
if (argc > 3) {
c0 = atof(argv[3]);
c1 = atof(argv[4]);
}

std::shared_ptr<tbox::MemoryDatabase> input_db(
new tbox::MemoryDatabase("db"));
std::cout << "Filename = " << databasename << std::endl;
tbox::InputManager::getManager()->parseInputFile(databasename, input_db);

double coeffL[3][2];
std::shared_ptr<tbox::Database> liquid_db =
input_db->getDatabase("Liquid");
coeffL[0][0] = liquid_db->getDouble("a0");
coeffL[0][1] = liquid_db->getDouble("a1");
coeffL[1][0] = liquid_db->getDouble("b0");
coeffL[1][1] = liquid_db->getDouble("b1");
coeffL[2][0] = liquid_db->getDouble("c0");
coeffL[2][1] = liquid_db->getDouble("c1");

double coeffA[3][2];
std::shared_ptr<tbox::Database> phasea_db =
input_db->getDatabase("PhaseA");
coeffA[0][0] = phasea_db->getDouble("a0");
coeffA[0][1] = phasea_db->getDouble("a1");
coeffA[1][0] = phasea_db->getDouble("b0");
coeffA[1][1] = phasea_db->getDouble("b1");
coeffA[2][0] = phasea_db->getDouble("c0");
coeffA[2][1] = phasea_db->getDouble("c1");

double coeffB[3][2];
std::shared_ptr<tbox::Database> phaseb_db =
input_db->getDatabase("PhaseB");
coeffB[0][0] = phaseb_db->getDouble("a0");
coeffB[0][1] = phaseb_db->getDouble("a1");
coeffB[1][0] = phaseb_db->getDouble("b0");
coeffB[1][1] = phaseb_db->getDouble("b1");
coeffB[2][0] = phaseb_db->getDouble("c0");
coeffB[2][1] = phaseb_db->getDouble("c1");

double Tref = input_db->getDouble("Tref");

input_db->printClassData(std::cout);

Thermo4PFM::ParabolicEqConcSolverBinary solver;
solver.setup(temperature - Tref, coeffL, coeffA);

const double toln = 1.e-12;
const int max_iters = 100;
const double alpha = 1.;

double sol[2] = {c0, c1};
std::cout << "Phases L,A..." << std::endl;
int ret = solver.ComputeConcentration(sol, toln, max_iters, alpha);
std::cout << ret << " iterations" << std::endl;
std::cout << "Solution: " << sol[0] << " " << sol[1] << std::endl;

sol[0] = c0;
sol[1] = c1;

std::cout << "Phases L,B..." << std::endl;
solver.setup(temperature - Tref, coeffL, coeffB);
ret = solver.ComputeConcentration(sol, toln, max_iters, alpha);
std::cout << ret << " iterations" << std::endl;
std::cout << "Solution: " << sol[0] << " " << sol[1] << std::endl;

sol[0] = c0;
sol[1] = c1;

std::cout << "Phases A,B..." << std::endl;
solver.setup(temperature - Tref, coeffA, coeffB);
ret = solver.ComputeConcentration(sol, toln, max_iters, alpha);
std::cout << ret << " iterations" << std::endl;
std::cout << "Solution: " << sol[0] << " " << sol[1] << std::endl;
}

tbox::SAMRAIManager::shutdown();
tbox::SAMRAIManager::finalize();
tbox::SAMRAI_MPI::finalize();

return ret;
}
92 changes: 92 additions & 0 deletions drivers/computeParabolic3PhasesKKS.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "ParabolicFreeEnergyFunctionsBinaryThreePhase.h"

#include "SAMRAI/tbox/SAMRAIManager.h"
#include "SAMRAI/tbox/InputManager.h"
#include "SAMRAI/tbox/Database.h"
#include "SAMRAI/SAMRAI_config.h"
#include "SAMRAI/tbox/SAMRAI_MPI.h"

#include <boost/optional/optional.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

namespace pt = boost::property_tree;
using namespace SAMRAI;

int main(int argc, char* argv[])
{
tbox::SAMRAI_MPI::init(&argc, &argv);
tbox::SAMRAIManager::initialize();
tbox::SAMRAIManager::startup();

int ret = 0;
{
std::string databasename(argv[1]);
double temperature = atof(argv[2]);
double phiL = atof(argv[3]);
double phiA = atof(argv[4]);
double phiB = atof(argv[5]);
double c = atof(argv[6]);

std::cout << "Temperature = " << temperature << std::endl;

std::shared_ptr<tbox::MemoryDatabase> input_db(
new tbox::MemoryDatabase("db"));
std::cout << "Filename = " << databasename << std::endl;
tbox::InputManager::getManager()->parseInputFile(databasename, input_db);

double coeffL[3][2];
std::shared_ptr<tbox::Database> liquid_db =
input_db->getDatabase("Liquid");
coeffL[0][0] = liquid_db->getDouble("a0");
coeffL[0][1] = liquid_db->getDouble("a1");
coeffL[1][0] = liquid_db->getDouble("b0");
coeffL[1][1] = liquid_db->getDouble("b1");
coeffL[2][0] = liquid_db->getDouble("c0");
coeffL[2][1] = liquid_db->getDouble("c1");

double coeffA[3][2];
std::shared_ptr<tbox::Database> phasea_db =
input_db->getDatabase("PhaseA");
coeffA[0][0] = phasea_db->getDouble("a0");
coeffA[0][1] = phasea_db->getDouble("a1");
coeffA[1][0] = phasea_db->getDouble("b0");
coeffA[1][1] = phasea_db->getDouble("b1");
coeffA[2][0] = phasea_db->getDouble("c0");
coeffA[2][1] = phasea_db->getDouble("c1");

double coeffB[3][2];
std::shared_ptr<tbox::Database> phaseb_db =
input_db->getDatabase("PhaseB");
coeffB[0][0] = phaseb_db->getDouble("a0");
coeffB[0][1] = phaseb_db->getDouble("a1");
coeffB[1][0] = phaseb_db->getDouble("b0");
coeffB[1][1] = phaseb_db->getDouble("b1");
coeffB[2][0] = phaseb_db->getDouble("c0");
coeffB[2][1] = phaseb_db->getDouble("c1");

double Tref = input_db->getDouble("Tref");

input_db->printClassData(std::cout);

Thermo4PFM::ParabolicFreeEnergyFunctionsBinaryThreePhase
parabolic_fenergy(Tref, coeffL, coeffA, coeffB,
Thermo4PFM::EnergyInterpolationType::PBG,
Thermo4PFM::ConcInterpolationType::LINEAR);

double phi[3] = {phiL, phiA, phiB};
double conc[3] = {c, c, c};
parabolic_fenergy.computePhaseConcentrations(temperature, &c, phi, conc);

std::cout << "phi = (" << phiL << "," << phiA << "," << phiB << ")"
<< ", c=" << c << std::endl;
std::cout << "KKS solution: cl = " << conc[0] << ", ca=" << conc[1]
<< " and cb = " << conc[2] << std::endl;
}

tbox::SAMRAIManager::shutdown();
tbox::SAMRAIManager::finalize();
tbox::SAMRAI_MPI::finalize();

return ret;
}
99 changes: 99 additions & 0 deletions drivers/plotEnergyVsCompositionParabolicThreePhase.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "ParabolicFreeEnergyFunctionsBinaryThreePhase.h"

#include "SAMRAI/tbox/SAMRAIManager.h"
#include "SAMRAI/tbox/InputManager.h"
#include "SAMRAI/tbox/Database.h"
#include "SAMRAI/SAMRAI_config.h"
#include "SAMRAI/tbox/SAMRAI_MPI.h"

#include <boost/optional/optional.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

namespace pt = boost::property_tree;
using namespace SAMRAI;

int main(int argc, char* argv[])
{
tbox::SAMRAI_MPI::init(&argc, &argv);
tbox::SAMRAIManager::initialize();
tbox::SAMRAIManager::startup();

int ret = 0;
{
std::string databasename(argv[1]);
double temperature = atof(argv[2]);
std::cout << "Temperature = " << temperature << std::endl;
double cmin = 0.;
double cmax = 1.;
if (argc > 3) {
cmin = atof(argv[3]);
cmax = atof(argv[4]);
}

Thermo4PFM::EnergyInterpolationType energy_interp_func_type =
Thermo4PFM::EnergyInterpolationType::PBG;
Thermo4PFM::ConcInterpolationType conc_interp_func_type =
Thermo4PFM::ConcInterpolationType::LINEAR;

std::shared_ptr<tbox::MemoryDatabase> input_db(
new tbox::MemoryDatabase("db"));
std::cout << "Filename = " << databasename << std::endl;
tbox::InputManager::getManager()->parseInputFile(databasename, input_db);

double coeffL[3][2];
std::shared_ptr<tbox::Database> liquid_db =
input_db->getDatabase("Liquid");
coeffL[0][0] = liquid_db->getDouble("a0");
coeffL[0][1] = liquid_db->getDouble("a1");
coeffL[1][0] = liquid_db->getDouble("b0");
coeffL[1][1] = liquid_db->getDouble("b1");
coeffL[2][0] = liquid_db->getDouble("c0");
coeffL[2][1] = liquid_db->getDouble("c1");

double coeffA[3][2];
std::shared_ptr<tbox::Database> phasea_db =
input_db->getDatabase("PhaseA");
coeffA[0][0] = phasea_db->getDouble("a0");
coeffA[0][1] = phasea_db->getDouble("a1");
coeffA[1][0] = phasea_db->getDouble("b0");
coeffA[1][1] = phasea_db->getDouble("b1");
coeffA[2][0] = phasea_db->getDouble("c0");
coeffA[2][1] = phasea_db->getDouble("c1");

double coeffB[3][2];
std::shared_ptr<tbox::Database> phaseb_db =
input_db->getDatabase("PhaseB");
coeffB[0][0] = phaseb_db->getDouble("a0");
coeffB[0][1] = phaseb_db->getDouble("a1");
coeffB[1][0] = phaseb_db->getDouble("b0");
coeffB[1][1] = phaseb_db->getDouble("b1");
coeffB[2][0] = phaseb_db->getDouble("c0");
coeffB[2][1] = phaseb_db->getDouble("c1");

double Tref = input_db->getDouble("Tref");

input_db->printClassData(std::cout);

const int npts = 100;
std::cout << " Compute energies..." << std::endl;

Thermo4PFM::ParabolicFreeEnergyFunctionsBinaryThreePhase qfe(
Tref, coeffL, coeffA, coeffB, energy_interp_func_type,
conc_interp_func_type);

std::stringstream ss;
ss << std::fixed;
ss << std::setprecision(2);
ss << temperature;
std::ofstream os("ParabolicFvsC" + ss.str() + ".csv", std::ios::out);

qfe.printEnergyVsComposition(temperature, os, cmin, cmax, npts);
}

tbox::SAMRAIManager::shutdown();
tbox::SAMRAIManager::finalize();
tbox::SAMRAI_MPI::finalize();

return ret;
}
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/source/KKStools.cc
${CMAKE_SOURCE_DIR}/source/QuadraticFreeEnergyMultiOrderBinary.cc
${CMAKE_SOURCE_DIR}/source/QuadraticFreeEnergyMultiOrderBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/source/QuadraticFreeEnergyMultiOrderTernaryThreePhase.cc
${CMAKE_SOURCE_DIR}/source/ParabolicFreeEnergyMultiOrderBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/source/EquilibriumPhaseConcentrationsBinaryMultiOrder.cc
${CMAKE_SOURCE_DIR}/source/EquilibriumPhaseConcentrationsBinaryMultiOrderThreePhases.cc
${CMAKE_SOURCE_DIR}/source/CALPHADequilibriumPhaseConcentrationsStrategyMultiOrder.cc
Expand All @@ -82,6 +83,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/source/KKStools.cc
${CMAKE_SOURCE_DIR}/source/QuadraticEquilibriumThreePhasesTernaryMultiOrder.cc
${CMAKE_SOURCE_DIR}/source/QuadraticEquilibriumPhaseConcentrationsBinary.cc
${CMAKE_SOURCE_DIR}/source/ParabolicEquilibriumPhaseConcentrationsBinary.cc
${CMAKE_SOURCE_DIR}/source/ParabolicEquilibriumThreePhasesBinaryMultiOrder.cc
${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyStrategyBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyStrategyBinaryThreePhaseStochioB.cc
${CMAKE_SOURCE_DIR}/source/CALPHADFreeEnergyBinaryMultiOrderThreePhasesStochioB.cc
Expand Down
1 change: 0 additions & 1 deletion source/EBSCompositionRHSStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ EBSCompositionRHSStrategy::EBSCompositionRHSStrategy(
{
assert(diffusion_l_id >= 0);
assert(temperature_scratch_id >= 0);
assert(d_free_energy_strategy);

tbox::plog << "EBSCompositionRHSStrategy" << std::endl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,25 @@ int EquilibriumPhaseConcentrationsBinaryMultiOrderThreePhases::
double t = ptr_temp[idx_temp];

// solve KKS equations
assert(!std::isnan(ptr_c_l[idx_c_i]));
double x[3] = {ptr_c_l[idx_c_i], ptr_c_a[idx_c_i],
ptr_c_b[idx_c_i]};
int ret = computePhaseConcentrations(t, &c, hphi, x);
if (ret < 0) {
std::cerr << "EquilibriumPhaseConcentrationsBinaryMultiOrderThre"
"ePhases"
<< std::endl;
std::cerr << "computePhaseConcentrations failed for T=" << t
<< ", "
<< "hphi = " << hphi[0] << "," << hphi[1] << ","
<< hphi[2] << std::endl;
std::cerr << "computePhaseConcentrations failed for T = " << t
<< ", c = " << c << ", hphi (L,A,B) = " << hphi[0]
<< "," << hphi[1] << "," << hphi[2] << std::endl;
std::cerr << "x = " << x[0] << ", " << x[1] << ", " << x[2]
<< std::endl;
std::cerr << "ptr_c_l = " << ptr_c_l[idx_c_i] << std::endl;
std::cerr << "ptr_c_a = " << ptr_c_a[idx_c_i] << std::endl;
std::cerr << "ptr_c_b = " << ptr_c_b[idx_c_i] << std::endl;
MPI_Abort(mpi.getCommunicator(), -1);
}
assert(!std::isnan(x[0]));
ptr_c_l[idx_c_i] = x[0];
ptr_c_a[idx_c_i] = x[1];
ptr_c_b[idx_c_i] = x[2];
Expand Down
Loading