File chternary.c

RCS Header: /cvsroot/rheoplast/chternary.c,v 1.25 2006/03/06 19:37:36 wanida Exp

This provides a simple nonsolvent/solvent/polymer chternary module for Rheoplast. It goes as The chemicalpotential is then the variation of this free energy, given by+html+ the homogeneous free energy derivative term and a laplacian term corresponding to the gradient penalty.


Included Files


Preprocessor definitions

#define __FUNCT__ "psiprime2"

#define __FUNCT__ "psiprime3"

#define __FUNCT__ "chternary_first_setup"

#define __FUNCT__ "chternary_labels_initcond"

#define SMALL_PRIME 1571

#define MEDIUM_PRIME 524287

#define LARGE_PRIME 2147483647

#define MY_RANDOM( pseudo_random )

#define C2( point )

#define C3( point )

#define C2func( point )

#define C3func( point )

#define Mu2( point )

#define Mu3( point )

#define Psi( point )

#define u( point )

#define v( point )

#define sigma( point )

#define V( point )

#define pu( point )

#define pv( point )

#define pw( point )

#define __FUNCT__ "chternary_integrate_interior_line"

#define __FUNCT__ "chternary_temp_parameters_line"

#define __FUNCT__ "chternary_temp_parameters_boundary_line"

#define __FUNCT__ "chternary_interior_line_function"

#define __FUNCT__ "chternary_boundary_line_function"


Global Function chternary_boundary_line_function()

For now this assumes uniform kappa.

void chternary_boundary_line_function ( PetscScalar* x, PetscScalar* func, PetscScalar* temp, PetscTruth** mixed_constraints, int points, int gxm, int gym, PetscScalar xmin, PetscScalar xmax, PetscScalar ycoord, PetscScalar zcoord, PetscScalar time, AppCtx* data, int side )


Global Function chternary_first_setup()

The basic setup, assigning the number of solved and temporary field variables, the stencil width, and using options to set the parameters in the chtparm struct typedef.

void chternary_first_setup ( PetscTruth threedee, int* vars, int* tempvars, int* intvars, int* stencilwid, AppCtx* data )

PetscTruth threedee
Request support for 3-D.
int* vars
Pointer to the number of solved field variables.
int* tempvars
Pointer to the number of temporary field variables.
int* intvars
 
int* stencilwid
Pointer to the stencil width.
AppCtx* data
Pointer to the AppCtx struct typedef, into whose chtparm structure this inserts parameters from the command line.
This sets mobility and +latex+$K_{ij}$ chternary_labels_initcond().


Global Function chternary_integrate_interior_line()

This calculates the chternary integration variable Psi, which is the free energy.

void chternary_integrate_interior_line ( PetscScalar* x, PetscScalar* integ, int points, int gxm, int gym, PetscScalar xmin, PetscScalar xmax, PetscScalar ycoord, PetscScalar zcoord, PetscScalar time, AppCtx* data )

PetscScalar* x
Array with the "real" field variables.
PetscScalar* integ
Array with the integration variables.
int points
Number of points at which to calculate the integration variables.
int gxm
The x-width of the ``local'' vector's array, including shadow nodes, for the y-increment.
int gym
The y-width of the ``local'' vector's array, including shadow nodes, for the z-increment.
PetscScalar xmin
First node x-coordinate.
PetscScalar xmax
Last node plus one x-coordinate.
PetscScalar ycoord
This line y-coordinate.
PetscScalar zcoord
This line z-coordinate.
PetscScalar time
Current simulation time.
AppCtx* data
Pointer to the main simulation parameter structure, which includes the chtparm struct typedef, from which this gets needed parameters.

Global Function chternary_interior_line_function()

This calculates the time derivative of C2,C3 using the divergence of flux, which goes down the gradient of chemical potential described above, with mobility kappa.

void chternary_interior_line_function ( PetscScalar* x, PetscScalar* func, PetscScalar* temp, PetscTruth** mixed_constraints, int points, int gxm, int gym, PetscScalar xmin, PetscScalar xmax, PetscScalar ycoord, PetscScalar zcoord, PetscScalar time, AppCtx* data )

PetscScalar* x
The field variables from which to evaluate the function.
PetscScalar* func
Where to put the evaluated function.
PetscScalar* temp
Array of temporary field variables.
PetscTruth** mixed_constraints
Arrays of boolean variables indicating constraint equations in mixed timestep-constraint fields.
int points
Number of points to evaluate at.
int gxm
The x-width of the ``local'' vector's array, including shadow nodes, for the y-increment.
int gym
The y-width of the ``local'' vector's array, including shadow nodes, for the z-increment.
PetscScalar xmin
First node x-coordinate.
PetscScalar xmax
Last node plus one x-coordinate.
PetscScalar ycoord
This line y-coordinate.
PetscScalar zcoord
This line z-coordinate.
PetscScalar time
Current simulation time.
AppCtx* data
Pointer to the main simulation parameter structure, which includes the chtparm struct typedef, from which this gets needed parameters.
For now this assumes uniform kappa.


Global Function chternary_labels_initcond()

This sets up the field variable labels, maximum stable explicit deltat, and initial condition for the Cahn-Hilliard variables.

void chternary_labels_initcond ( PetscScalar* globalarray, int nx, int ny, int nz, int xm, int ym, int zm, int xs, int ys, int zs, int vars, AppCtx* data, PetscScalar* max_explicit_deltat )

PetscScalar* globalarray
The global field array.
int nx
Overall x-width of the global array.
int ny
Overall y-width of the global array.
int nz
Overall z-width of the global array.
int xm
The x-width of the local part of the array.
int ym
The y-width of the local part of the array.
int zm
The z-width of the local part of the array.
int xs
The (integer) x-coordinate of the start of the local part of the array.
int ys
The (integer) y-coordinate of the start of the local part of the array.
int zs
The (integer) z-coordinate of the start of the local part of the array.
int vars
Total number of field variables to be solved.
AppCtx* data
Pointer to the AppCtx struct typedef, whose chtparm structure this uses for various purposes.
PetscScalar* max_explicit_deltat
Pointer to the largest allowable explicit timestep size for this equation, which this function can set/modify.
For random fluctuations in this module, it's necessary to generate different random sequences on each process, even though rand() will return the same sequences. So we create a random counter which takes on values between zero and SMALL_PRIME-1; this is initialized to rank times LARGE_PRIME (which should make it sort of random), and incremented by MEDIUM_PRIME then re-moduloed to SMALL_PRIME for each random number generated. This counter, in turn, is divided by SMALL_PRIME and the result added to rand()/RAND_MAX then modulo 1, in order to give a "different random number" (at least at the resolution of SMALL_PRIME) in each process. This is not a great algorithm, but should do for the purpose needed here.
Eventually it might be good to make this resource available to the whole code.
If we're not loading in data as the initial condition, the C2, C3 field is initiated here. There are several types of initial conditions here which are chosen by command-line parameters:
If the option -ch_random_fluct is selected without -ch_random_center, then random fluctuations with uniform distribution of width twice the fluctuation value are added to any other initial condition present.


Global Function chternary_temp_parameters_boundary_line()

void chternary_temp_parameters_boundary_line ( PetscScalar* x, PetscScalar* temp, int points, int gxm, int gym, PetscScalar xmin, PetscScalar xmax, PetscScalar ycoord, PetscScalar zcoord, PetscScalar time, AppCtx* data, int side )

Global Function chternary_temp_parameters_line()

This calculates the chternary temporary parameter mu_s,mu_p, which is the chemical potential given as the following:

void chternary_temp_parameters_line ( PetscScalar* x, PetscScalar* temp, int points, int gxm, int gym, PetscScalar xmin, PetscScalar xmax, PetscScalar ycoord, PetscScalar zcoord, PetscScalar time, AppCtx* data )

PetscScalar* x
Array with the "real" field variables.
PetscScalar* temp
Array with the temporary field variables.
int points
Number of points at which to calculate the temporary variables.
int gxm
The x-width of the ``local'' vector's array, including shadow nodes, for the y-increment.
int gym
The y-width of the ``local'' vector's array, including shadow nodes, for the z-increment.
PetscScalar xmin
First node x-coordinate.
PetscScalar xmax
Last node plus one x-coordinate.
PetscScalar ycoord
This line y-coordinate.
PetscScalar zcoord
This line z-coordinate.
PetscScalar time
Current simulation time.
AppCtx* data
Pointer to the main simulation parameter structure, which includes the chtparm struct typedef, from which this gets needed parameters.

Local Function psi()

This abstracts out the function for Psi(C_2,C_3), PetscScalar psi It returns the homogeneous free energy.

static inline PetscScalar psi ( PetscScalar C2, PetscScalar C3, chtparm* thechternary )

PetscScalar C2
 
PetscScalar C3
 
chtparm* thechternary
chternary parameter structure.
PetscScalar C The C_2, C_3 parameter it's a function of.


Local Function psiprime2()

This abstracts out the function for Psi_2'(C_2,C_3), the derivative of homogeneous free energy, so it can be easily modified.

static inline PetscScalar psiprime2 ( PetscScalar C2, PetscScalar C3, chtparm* thechternary )

PetscScalar C2
 
PetscScalar C3
 
chtparm* thechternary
chternary parameter structure.
PetscScalar psiprime It returns the derivative of homogeneous free energy.
PetscScalar C The C_2, C_3 parameter it's a function of.


Local Function psiprime3()

This abstracts out the function for Psi_3'(C_2,C_3), the derivative of homogeneous free energy, so it can be easily modified.

static inline PetscScalar psiprime3 ( PetscScalar C2, PetscScalar C3, chtparm* thechternary )

PetscScalar C2
 
PetscScalar C3
 
chtparm* thechternary
chternary parameter structure.
PetscScalar psiprime It returns the derivative of homogeneous free energy.
PetscScalar C The C_2, C_3 parameter it's a function of.