Skip to content

Commit

Permalink
some fluidity work
Browse files Browse the repository at this point in the history
  • Loading branch information
wortiz committed Jan 16, 2025
1 parent c3c0bc1 commit ab15c02
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ set(GOMA_INCLUDES
include/mm_std_models_shell.h
include/mm_unknown_map.h
include/mm_viscosity.h
include/models/fluidity.h
include/polymer_time_const.h
include/rd_dpi.h
include/rd_exo.h
Expand Down Expand Up @@ -735,6 +736,7 @@ set(GOMA_SOURCES
src/mm_std_models_shell.c
src/mm_unknown_map.c
src/mm_viscosity.c
src/models/fluidity.cpp
src/polymer_time_const.c
src/rd_dpi.c
src/rd_exo.c
Expand Down
3 changes: 3 additions & 0 deletions include/mm_mp_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ extern int Num_Var_Init_Mat[MAX_NUMBER_MATLS]; /* number of variables to overwri
#define TURBULENT_SA 52 /* Spallart Allmaras */
#define TURBULENT_SA_DYNAMIC 53 /* Spallart Allmaras */
#define TURBULENT_K_OMEGA 54
#define FLUIDITY_THIXOTROPIC_VISCOSITY 55

/*
* Heat source modeling
Expand Down Expand Up @@ -585,6 +586,8 @@ extern int Num_Var_Init_Mat[MAX_NUMBER_MATLS]; /* number of variables to overwri
#define ETCHING_KOH 935
#define ETCHING_KOH_EXT 936

#define FLUIDITY_THIXOTROPIC 937

/* Special material-related height function models */
#define CONSTANT_SPEED 1011
#define ROLL_ON 1012
Expand Down
19 changes: 19 additions & 0 deletions include/models/fluidity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef GOMA_MODELS_FLUIDITY_H
#define GOMA_MODELS_FLUIDITY_H

#ifdef __cplusplus
extern "C" {
#endif
#include "std.h"
#include "mm_as_structs.h"
#include "mm_viscosity.h"

dbl fluidity_viscosity(int fluidity_species, /* integer associated with conc eqn for bond */
VISCOSITY_DEPENDENCE_STRUCT *d_mu);

int fluidity_source(int species_no, struct Species_Conservation_Terms *st, dbl *params);

#ifdef __cplusplus
} // extern "C"
#endif
#endif // GOMA_MODELS_FLUIDITY_H
3 changes: 3 additions & 0 deletions src/mm_fill_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "std.h"
#include "user_bc.h"
#include "user_mp.h"
#include "models/fluidity.h"
#ifdef USE_CHEMKIN
#include "ck_chemkin_const.h"
#endif
Expand Down Expand Up @@ -9974,6 +9975,8 @@ int get_continuous_species_terms(struct Species_Conservation_Terms *st,
}
}
}
} else if (mp->SpeciesSourceModel[w] == FLUIDITY_THIXOTROPIC) {
fluidity_source(w, st, mp->u_species_source[w]);
} else if (mp->SpeciesSourceModel[w] == BUTLER_VOLMER) /* added by KSC: 05/15/06 */
{
dbl dh[3], p[10];
Expand Down
16 changes: 8 additions & 8 deletions src/mm_fill_stabilization.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ void tau_momentum_shakib(momentum_tau_terms *tau_terms, int dim, dbl dt, int psp
}
}

if (pd->TimeIntegration != STEADY) {
tau_terms->tau = inv_rho / (sqrt(4 / (dt * dt) + v_d_gv + diff_g_g));
} else {
tau_terms->tau = inv_rho / (sqrt(v_d_gv + diff_g_g) + 1e-14);
}
// if (pd->TimeIntegration != STEADY) {
// tau_terms->tau = inv_rho / (sqrt(4 / (dt * dt) + v_d_gv + diff_g_g));
// } else {
tau_terms->tau = inv_rho / (sqrt(v_d_gv + diff_g_g) + 1e-14);
// }

dbl d_diff_g_g_dmu = 2.0 * diff_g_g / mu;
dbl supg_tau_cubed = tau_terms->tau * tau_terms->tau * tau_terms->tau;
Expand Down Expand Up @@ -1059,9 +1059,9 @@ int calc_pspg(dbl pspg[DIM],

// Use vv_speed and hh_siz for tau_pspg, note it has a continuous dependence on Re
tau_pspg1 = rho_avg * rho_avg * vv_speed / hh_siz + (9.0 * mu_avg * mu_avg) / (hh_siz * hh_siz);
if (pd->TimeIntegration != STEADY) {
tau_pspg1 += 4.0 / (dt * dt);
}
// if (pd->TimeIntegration != STEADY) {
// tau_pspg1 += 4.0 / (dt * dt);
// }
tau_pspg = PS_scaling / sqrt(tau_pspg1);

pspg_tau.tau = tau_pspg;
Expand Down
26 changes: 25 additions & 1 deletion src/mm_input_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ void rd_mp_specs(FILE *imp, char input[], int mn, char *echo_file)
ConstitutiveEquation = BOND;
} else if (!strcmp(model_name, "BOND_SH")) {
ConstitutiveEquation = BOND_SH;
} else if (!strcmp(model_name, "FLUIDITY")) {
ConstitutiveEquation = FLUIDITY_THIXOTROPIC_VISCOSITY;
} else if (!strcmp(model_name, "CARREAU_WLF_CONC_PL")) {
ConstitutiveEquation = CARREAU_WLF_CONC_PL;
} else if (!strcmp(model_name, "CARREAU_WLF_CONC_EXP")) {
Expand Down Expand Up @@ -1979,7 +1981,7 @@ void rd_mp_specs(FILE *imp, char input[], int mn, char *echo_file)
ECHO(es, echo_file);
}

if (ConstitutiveEquation == BOND_SH) {
if (ConstitutiveEquation == BOND_SH || ConstitutiveEquation == FLUIDITY_THIXOTROPIC_VISCOSITY) {

iread = look_for_optional(imp, "Suspension Species Number", input, '=');
if (fscanf(imp, "%d", &species_no) != 1) {
Expand Down Expand Up @@ -8549,6 +8551,28 @@ void rd_mp_specs(FILE *imp, char input[], int mn, char *echo_file)
mat_ptr->u_species_source[species_no][3] = a3; /* exponent for breakup eqn */
mat_ptr->u_species_source[species_no][4] = a4; /* exponent for aggregation eqn */

SPF_DBL_VEC(endofstring(es), 5, mat_ptr->u_species_source[species_no]);
}
else if (!strcmp(model_name, "FLUIDITY")) {
SpeciesSourceModel = FLUIDITY_THIXOTROPIC;
model_read = 1;
mat_ptr->SpeciesSourceModel[species_no] = SpeciesSourceModel;
if (fscanf(imp, "%lf %lf %lf %lf %lf", &a0, &a1, &a2, &a3, &a4) != 5) {
sr = sprintf(err_msg, "Matl %s needs 5 constants for %s %s model.\n",
pd_glob[mn]->MaterialName, "Species Source", "FLUIDITY");
GOMA_EH(GOMA_ERROR, err_msg);
}

mat_ptr->u_species_source[species_no] = (dbl *)array_alloc(1, 5, sizeof(dbl));

mat_ptr->len_u_species_source[species_no] = 5;

mat_ptr->u_species_source[species_no][0] = a0; /* phi_0 */
mat_ptr->u_species_source[species_no][1] = a1; /* phi_inf */
mat_ptr->u_species_source[species_no][2] = a2; /* K */
mat_ptr->u_species_source[species_no][3] = a3; /* n */
mat_ptr->u_species_source[species_no][4] = a4; /* tc */

SPF_DBL_VEC(endofstring(es), 5, mat_ptr->u_species_source[species_no]);
} else if (!strcmp(model_name, "FOAM_EPOXY")) {
SpeciesSourceModel = FOAM_EPOXY;
Expand Down
3 changes: 3 additions & 0 deletions src/mm_viscosity.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "std.h"
#include "user_mp.h"
#include "user_mp_gen.h"
#include "models/fluidity.h"

#define GOMA_MM_VISCOSITY_C

Expand Down Expand Up @@ -512,6 +513,8 @@ double viscosity(struct Generalized_Newtonian *gn_local,
d_mu->nn[j] = mp->d_viscosity[var] * bf[var]->phi[j];
}
}
} else if (gn_local->ConstitutiveEquation == FLUIDITY_THIXOTROPIC_VISCOSITY) {
mu = fluidity_viscosity(gn_local->sus_species_no, d_mu);
} else if (gn_local->ConstitutiveEquation == EPOXY) {
err = epoxy_viscosity(gn_local->cure_species_no, gn_local->mu0, gn_local->gelpoint,
gn_local->cureaexp, gn_local->curebexp, gn_local->atexp);
Expand Down
138 changes: 138 additions & 0 deletions src/models/fluidity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "Sacado.hpp"

extern "C" {
#include "mm_as.h"
#include "mm_as_const.h"
#include "mm_as_structs.h"
#include "mm_eh.h"
#include "mm_fill_util.h"
#include "mm_mp.h"
#include "rf_fem.h"
#include "rf_fem_const.h"
#include "std.h"
}

using sfad = Sacado::Fad::SFad<double, 10>;

// Function to calculate equilibrium fluidity phi_eq as a function of stress sigma
sfad calculate_phi_eq(sfad sigma, dbl phi_inf, dbl phi_0, dbl K, dbl n) {
sfad term = pow(sigma / K, 1.0 / n) * (1.0 / sigma);
sfad d_term = -(n - 1.0) * pow(sigma / K, 1.0 / n) / (n * sigma * sigma);
sfad phi_eq = term / ((phi_inf - phi_0) + term);
return phi_eq;
}

// Smoothed Heaviside function using tanh
sfad smoothed_heaviside(sfad x, double m) { return 0.5 * (1.0 + tanh(m * x)); }

extern "C" dbl
fluidity_viscosity(int fluidity_species, /* integer associated with conc eqn for bond */
VISCOSITY_DEPENDENCE_STRUCT *d_mu) {
/* Local Variables */
if (!pd->gv[MASS_FRACTION]) {
GOMA_EH(GOMA_ERROR, "Fluidity viscosity but no Species Concentration Equation\n");
}

dbl *params = mp->u_species_source[fluidity_species];
dbl phi_0 = params[0];
dbl phi_inf = params[1];

dbl phi_star = fv->c[fluidity_species];

/* Calculate the fluidity */
dbl phi = phi_0 + (phi_inf - phi_0) * phi_star;
if (d_mu != NULL) {
for (int j = 0; j < ei[pg->imtrx]->dof[MASS_FRACTION]; j++)
d_mu->C[fluidity_species][j] = bf[MASS_FRACTION]->phi[j] * -(phi_inf - phi_0) / (phi * phi);
}

return 1.0 / phi;
}

// Main function to test the implementation
extern "C" int fluidity_source(int species_no, struct Species_Conservation_Terms *st, dbl *params) {

dbl phi_0 = params[0];
dbl phi_inf = params[1];
dbl K = params[2];
dbl n = params[3];
dbl tc = params[4];

sfad phi_star(10, 0, fv->c[species_no]);
sfad grad_v[DIM][DIM];
for (int i = 0; i < VIM; i++) {
for (int j = 0; j < VIM; j++) {
grad_v[i][j] = fv->grad_v[i][j];
int idx = 1 + i * VIM + j;
grad_v[i][j].fastAccessDx(idx) = 1.0;
}
}

sfad phi = phi_0 + (phi_inf - phi_0) * phi_star;
sfad mu = 1/phi;

sfad tau[DIM][DIM];
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
tau[i][j] = mu * (grad_v[i][j] + grad_v[j][i]);
}
}

sfad sigma = 0.0;
for (int i = 0; i < DIM; i++) {
for (int j = 0; j < DIM; j++) {
sigma += tau[i][j] * tau[i][j];
}
}
sigma = max(sigma, 1e-32);
sigma = sqrt(0.5 * sigma);

// Calculate phi_eq
sfad term = pow(sigma / K, 1.0 / n) * (1.0 / sigma);
sfad d_term = -(n - 1.0) * pow(sigma / K, 1.0 / n) / (n * sigma * sigma);
sfad phi_eq = max(1e-32, term / ((phi_inf - phi_0) + term));

// Calculate t_a and s
// avalanche time
sfad ta = 59.2 * pow(1 - phi_eq, 1.1) / (pow(phi_eq, 0.4));
sfad s = 8.0 / (exp(phi_eq / 0.09) - 1.0) + 1.2;

sfad H = smoothed_heaviside(phi_star - phi_eq, 500);

// Breakdown dynamics
sfad F_breakdown =
(s / (ta * phi_eq)) * pow(max(0,phi_eq - phi_star), (s + 1) / s) * pow(phi_star, (s - 1.0) / s);

// Buildup dynamics
sfad F_buildup = -(phi_star - phi_eq) / tc;

// Calculate F
sfad F = H * F_buildup + (1.0 - H) * F_breakdown;
int eqn = MASS_FRACTION;
if (pd->e[pg->imtrx][eqn] & T_SOURCE) {
st->MassSource[species_no] = F.val();

/* Jacobian entries for source term */
int var = MASS_FRACTION;
if (pd->v[pg->imtrx][var]) {
for (int j = 0; j < ei[pg->imtrx]->dof[MASS_FRACTION]; j++) {
st->d_MassSource_dc[species_no][species_no][j] = bf[MASS_FRACTION]->phi[j] * F.dx(0);
}
}

var = VELOCITY1;
if (pd->v[pg->imtrx][var]) {
for (int a = 0; a < VIM; a++) {
for (int p = 0; p < VIM; p++) {
for (int q = 0; q < VIM; q++) {
for (int j = 0; j < ei[pg->imtrx]->dof[VELOCITY1 + a]; j++) {
st->d_MassSource_dv[species_no][a][j] +=
F.dx(1 + p * VIM + q) * bf[VELOCITY1 + a]->grad_phi_e[j][a][p][q];
}
}
}
}
}
}
return 0;
}
42 changes: 23 additions & 19 deletions src/sl_petsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ static goma_error set_petsc_pressure_matrix(PetscMatrixData *matrix_data,
}
}
double mu = viscosity(gn, gamma, NULL);
for (int mode = 0; mode < vn->modes; mode++) {
dbl mup = viscosity(ve[mode]->gn, gamma, NULL);
mu += mup;
}
double invmu = (1.0 / mu);
int eqn = PRESSURE;
for (int i = 0; i < ei[pg->imtrx]->num_local_nodes; i++) {
Expand Down Expand Up @@ -1301,18 +1305,18 @@ goma_error goma_setup_petsc_matrix(struct GomaLinearSolverData *ams,

PetscInt pcd_ns_remove_n = 0;
PetscBool pcd_ns_remove_n_set;
PetscOptionsGetInt(NULL, NULL, "-pcd_ns_remove_n", &pcd_ns_remove_n, &pcd_ns_remove_n_set);
PetscOptionsGetInt(NULL, NULL, "-user_pcd_ns_remove_n", &pcd_ns_remove_n, &pcd_ns_remove_n_set);

PetscInt pcd_ss_remove_n = 0;
PetscBool pcd_ss_remove_n_set;
PetscOptionsGetInt(NULL, NULL, "-pcd_ss_remove_n", &pcd_ss_remove_n, &pcd_ss_remove_n_set);
PetscOptionsGetInt(NULL, NULL, "-user_pcd_ss_remove_n", &pcd_ss_remove_n, &pcd_ss_remove_n_set);

PetscBool pcd_ns_remove_set;
PetscInt *pcd_ns_remove = NULL;
PetscInt pcd_ns_found = pcd_ns_remove_n;
if (pcd_ns_remove_n_set) {
PetscMalloc1(pcd_ns_remove_n, &pcd_ns_remove);
PetscOptionsGetIntArray(NULL, NULL, "-pcd_ns_remove", pcd_ns_remove, &pcd_ns_found,
PetscOptionsGetIntArray(NULL, NULL, "-user_pcd_ns_remove", pcd_ns_remove, &pcd_ns_found,
&pcd_ns_remove_set);
}

Expand All @@ -1321,7 +1325,7 @@ goma_error goma_setup_petsc_matrix(struct GomaLinearSolverData *ams,
PetscInt pcd_ss_found = pcd_ss_remove_n;
if (pcd_ss_remove_n_set) {
PetscMalloc1(pcd_ss_remove_n, &pcd_ss_remove);
PetscOptionsGetIntArray(NULL, NULL, "-pcd_ss_remove", pcd_ss_remove, &pcd_ss_found,
PetscOptionsGetIntArray(NULL, NULL, "-user_pcd_ss_remove", pcd_ss_remove, &pcd_ss_found,
&pcd_ss_remove_set);
}

Expand Down Expand Up @@ -1420,21 +1424,21 @@ goma_error goma_setup_petsc_matrix(struct GomaLinearSolverData *ams,
PCFieldSplitSetIS(pc, "u", ufields);
PCFieldSplitSetIS(pc, "p", pfields);

// if (pd_glob[0]->Num_Dim == 3) {
// PC pc;
// const PetscInt ufields[] = {0, 1, 2}, pfields[] = {3};
// KSPGetPC(matrix_data->ksp, &pc);
// PCFieldSplitSetBlockSize(pc, 4);
// PCFieldSplitSetFields(pc, "u", 3, ufields, ufields);
// PCFieldSplitSetFields(pc, "p", 1, pfields, pfields);
// } else if (pd_glob[0]->Num_Dim == 2) {
// PC pc;
// const PetscInt ufields[] = {0, 1}, pfields[] = {3};
// KSPGetPC(matrix_data->ksp, &pc);
// PCFieldSplitSetBlockSize(pc, 3);
// PCFieldSplitSetFields(pc, "u", 2, ufields, ufields);
// PCFieldSplitSetFields(pc, "p", 1, pfields, pfields);
// }
// if (pd_glob[0]->Num_Dim == 3) {
// PC pc;
// const PetscInt ufields[] = {0, 1, 2}, pfields[] = {3};
// KSPGetPC(matrix_data->ksp, &pc);
// PCFieldSplitSetBlockSize(pc, 4);
// PCFieldSplitSetFields(pc, "u", 3, ufields, ufields);
// PCFieldSplitSetFields(pc, "p", 1, pfields, pfields);
// } else if (pd_glob[0]->Num_Dim == 2) {
// PC pc;
// const PetscInt ufields[] = {0, 1}, pfields[] = {3};
// KSPGetPC(matrix_data->ksp, &pc);
// PCFieldSplitSetBlockSize(pc, 3);
// PCFieldSplitSetFields(pc, "u", 2, ufields, ufields);
// PCFieldSplitSetFields(pc, "p", 1, pfields, pfields);
// }

PetscInt local_pressure_nodes = 0, global_pressure_nodes = 0;
if ((user_schur_set && user_schur) || (user_pcd_set && user_pcd)) {
Expand Down
Loading

0 comments on commit ab15c02

Please sign in to comment.