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 parabolic free energies #72

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/InterpolationType.cc
${CMAKE_SOURCE_DIR}/src/QuadraticFreeEnergyFunctionsBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/src/QuadraticConcSolverBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/src/QuadraticFreeEnergyFunctionsTernaryThreePhase.cc
${CMAKE_SOURCE_DIR}/src/ParabolicFreeEnergyFunctionsBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/src/ParabolicConcSolverBinaryThreePhase.cc
${CMAKE_SOURCE_DIR}/src/xlogx.cc)

if(${SHARED_LIB})
Expand Down
6 changes: 4 additions & 2 deletions src/LinearSolver.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "ParabolicConcSolverBinaryThreePhase.h"
#include "QuadraticConcSolverBinaryThreePhase.h"

#include "Determinant.h"
Expand Down Expand Up @@ -109,8 +110,9 @@ int LinearSolver<Dimension, SolverType,
return 0;
}

template class LinearSolver<3, QuadraticConcSolverBinaryThreePhase,
JacobianDataType>;
template class LinearSolver<3, QuadraticConcSolverBinaryThreePhase, double>;
template class LinearSolver<3, ParabolicConcSolverBinaryThreePhase, double>;

#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp end declare target
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/LinearSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Thermo4PFM
{
template <unsigned int Dimension, class SolverType, typename JacobianDataType>
template <unsigned int Dimension, class SolverType, typename MatrixDataType>
class LinearSolver
{
public:
Expand All @@ -22,8 +22,8 @@ class LinearSolver
#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp declare target
#endif
void UpdateSolution(double* const x, const double* const fvec,
JacobianDataType** const fjac);
void UpdateSolution(
double* const x, const double* const fvec, MatrixDataType** const fjac);

int ComputeSolutionInternal(double* const conc);

Expand All @@ -35,7 +35,7 @@ class LinearSolver
template <typename ScalarType>
void CopyMatrix(ScalarType** const dst, ScalarType** const src);

void internalJacobian(const double* const x, JacobianDataType** const fjac)
void internalJacobian(const double* const x, MatrixDataType** const fjac)
{
static_cast<SolverType*>(this)->Jacobian(x, fjac);
}
Expand Down
95 changes: 95 additions & 0 deletions src/ParabolicConcSolverBinaryThreePhase.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "ParabolicConcSolverBinaryThreePhase.h"
#include "Determinant.h"

#include <iostream>

#define EQSCALING 1.e-4

namespace Thermo4PFM
{
//=======================================================================

#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp declare target
#endif

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

// solve for c=(c_L, c_A, c_B)
void ParabolicConcSolverBinaryThreePhase::RHS(
const double* const c, double* const fvec)
{
fvec[0] = -c0_ + hphi0_ * c[0] + hphi1_ * c[1] + hphi2_ * c[2];

const double t = temperature_;
const double muL = (aL_[1] * t + aL_[0]) * c[0] + (bL_[1] * t + bL_[0]);
const double muA = (aA_[1] * t + aA_[0]) * c[1] + (bA_[1] * t + bA_[0]);
const double muB = (aB_[1] * t + aB_[0]) * c[2] + (bB_[1] * t + bB_[0]);
fvec[1] = EQSCALING * (muA - muL);
fvec[2] = EQSCALING * (muB - muL);
}

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

void ParabolicConcSolverBinaryThreePhase::Jacobian(
const double* const c, double** const fjac)
{
(void)c;

const double t = temperature_;
fjac[0][0] = hphi0_;
fjac[0][1] = hphi1_;
fjac[0][2] = hphi2_;

fjac[1][0] = EQSCALING * (-1. * (aL_[1] * t + aL_[0]));
fjac[1][1] = EQSCALING * ((aA_[1] * t + aA_[0]));
fjac[1][2] = 0.;

fjac[2][0] = EQSCALING * (-1. * (aL_[1] * t + aL_[0]));
fjac[2][1] = 0.;
fjac[2][2] = EQSCALING * (aB_[1] * t + aB_[0]);
#if 0
std::cout << "Matrix:" << std::endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
std::cout << fjac[i][j] << " ";
std::cout << std::endl;
}
double d = evalDeterminant<3, double>(fjac);
std::cout << "Determinant: " << d << std::endl;
#endif
}

// set values of internal variables
void ParabolicConcSolverBinaryThreePhase::setup(const double c0,
const double hphi0, const double hphi1, const double hphi2,
const double temperature, const double coeffL[][2],
const double coeffA[][2], const double coeffB[][2])
{
c0_ = c0;
hphi0_ = hphi0;
hphi1_ = hphi1;
hphi2_ = hphi2;
temperature_ = temperature;

aL_[0] = coeffL[0][0];
aL_[1] = coeffL[0][1];
bL_[0] = coeffL[1][0];
bL_[1] = coeffL[1][1];

aA_[0] = coeffA[0][0];
aA_[1] = coeffA[0][1];
bA_[0] = coeffA[1][0];
bA_[1] = coeffA[1][1];

aB_[0] = coeffB[0][0];
aB_[1] = coeffB[0][1];
bB_[0] = coeffB[1][0];
bB_[1] = coeffB[1][1];
}

#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp end declare target
#endif
}
79 changes: 79 additions & 0 deletions src/ParabolicConcSolverBinaryThreePhase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef Thermo4PFM_included_ParabolicConcSolverBinaryThreePhase
#define Thermo4PFM_included_ParabolicConcSolverBinaryThreePhase

#include "LinearSolver.h"
#include "datatypes.h"

namespace Thermo4PFM
{
class ParabolicConcSolverBinaryThreePhase
: public LinearSolver<3, ParabolicConcSolverBinaryThreePhase, double>
{
public:
#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp declare target
#endif
/// compute "internal" concentrations cL, cS1, cS2 by solving KKS
/// equations
/// conc: solution (concentration in each phase)
int ComputeConcentration(double* const conc)
{
return LinearSolver::ComputeSolution(conc);
}

/// setup model paramater values to be used by solver,
/// including composition "c0" and phase fraction "hphi"
/// to solve for
void setup(const double c0, const double hphi0, const double hphi1,
const double hphi2, const double temperature, const double coeffL[][2],
const double coeffA[][2], const double coeffB[][2]);

/// evaluate RHS of the system of eqautions to solve for
/// specific to this solver
void RHS(const double* const x, double* const fvec);

/// evaluate Jacobian of system of equations
/// specific to this solver
void Jacobian(const double* const x, double** const fjac);
#ifdef HAVE_OPENMP_OFFLOAD
#pragma omp end declare target
#endif

private:
///
/// Nominal composition to solve for
///
double c0_;

///
/// phase fractions to solve for
///
double hphi0_;
double hphi1_;
double hphi2_;

double temperature_;

/*
* Phase L coefficients
* g(c,T) = (aL1_*T+aL0_)*c*c + (bL1_*T+bL0_)*c + cL1_*T+cL0_
*/
double aL_[2];
double bL_[2];

/*
* Phase A coefficients
* g(c,T) = (aL1_*T+aL0_)*c*c + (bL1_*T+bL0_)*c + cL1_*T+cL0_
*/
double aA_[2];
double bA_[2];

/*
* Phase B coefficients
* g(c,T) = (aL1_*T+aL0_)*c*c + (bL1_*T+bL0_)*c + cL1_*T+cL0_
*/
double aB_[2];
double bB_[2];
};
}
#endif
Loading
Loading