Skip to content

Commit

Permalink
Merge pull request #298 from ludwig-cf/fix-issue-210
Browse files Browse the repository at this point in the history
Separate symmetric and fluctuations and test
  • Loading branch information
kevinstratford authored Apr 30, 2024
2 parents 4367aae + a520617 commit 1810bf3
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 11 deletions.
85 changes: 74 additions & 11 deletions src/ludwig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,7 @@ int free_energy_init_rt(ludwig_t * ludwig) {
lees_edw_info(le);
pth_create(pe, cs, FE_FORCE_METHOD_NO_FORCE, &ludwig->pth);
}
else if (strcmp(description, "symmetric") == 0 ||
strcmp(description, "symmetric_noise") == 0) {
else if (strcmp(description, "symmetric") == 0) {

phi_ch_info_t ch_options = {0};
fe_symm_t * fe = NULL;
Expand All @@ -1175,12 +1174,79 @@ int free_energy_init_rt(ludwig_t * ludwig) {
nhalo = 2; /* Require stress divergence. */
ngrad = 2; /* \nabla^2 required */

/* Noise requires additional stencil point for Cahn Hilliard */
cs_nhalo_set(cs, nhalo);
coords_init_rt(pe, rt, cs);
lees_edw_create(pe, cs, info, &le);
lees_edw_info(le);

if (strcmp(description, "symmetric_noise") == 0) {
nhalo = 3;
{
field_options_t opts = field_options_ndata_nhalo(nf, nhalo);
io_info_args_rt(rt, RT_FATAL, "phi", IO_INFO_READ_WRITE, &opts.iodata);
field_create(pe, cs, le, "phi", &opts, &ludwig->phi);
field_grad_create(pe, ludwig->phi, ngrad, &ludwig->phi_grad);
}

pe_info(pe, "\n");
pe_info(pe, "Free energy details\n");
pe_info(pe, "-------------------\n\n");
fe_symm_create(pe, cs, ludwig->phi, ludwig->phi_grad, &fe);
fe_symmetric_init_rt(pe, rt, fe);

pe_info(pe, "\n");
pe_info(pe, "Using Cahn-Hilliard finite difference solver.\n");

rt_key_required(rt, "mobility", RT_FATAL);
rt_double_parameter(rt, "mobility", &value);
physics_mobility_set(ludwig->phys, value);
pe_info(pe, "Mobility M = %12.5e\n", value);

pe_info(pe, "Order parameter noise = %3s\n", "off");

rt_int_parameter(rt, "cahn_hilliard_options_conserve",
&ch_options.conserve);
phi_ch_create(pe, cs, le, &ch_options, &ludwig->pch);

/* Force */

{
fe_force_method_enum_t method = fe_force_method_default();

fe_force_method_rt_messages(rt, RT_INFO);
fe_force_method_rt(rt, RT_FATAL, &method);

/* The following are supported */
switch (method) {
case FE_FORCE_METHOD_NO_FORCE:
case FE_FORCE_METHOD_STRESS_DIVERGENCE:
case FE_FORCE_METHOD_PHI_GRADMU:
case FE_FORCE_METHOD_PHI_GRADMU_CORRECTION:
break;
case FE_FORCE_METHOD_RELAXATION_SYMM:
fe->super.use_stress_relaxation = 1;
break;
default:
pe_fatal(pe, "symmetric free energy force_method not available\n");
}

pth_create(pe, cs, method, &ludwig->pth);
pe_info(pe, "Force calculation: %s\n",
fe_force_method_to_string(method));
}

ludwig->fe_symm = fe;
ludwig->fe = (fe_t *) fe;
}
else if (strcmp(description, "symmetric_noise") == 0) {

phi_ch_info_t ch_options = {0};
fe_symm_t * fe = NULL;

/* Symmetric via finite difference plus isothermal fluctuations */

nf = 1; /* 1 scalar order parameter */
nhalo = 3; /* Additional point cf no noise */
ngrad = 2; /* \nabla^2 required */

cs_nhalo_set(cs, nhalo);
coords_init_rt(pe, rt, cs);
lees_edw_create(pe, cs, info, &le);
Expand Down Expand Up @@ -1217,12 +1283,9 @@ int free_energy_init_rt(ludwig_t * ludwig) {
pe_info(pe, "Order parameter noise = %3s\n",
(noise_on == 0) ? "off" : " on");

if (noise_on) {
noise_create(pe, cs, &ludwig->noise_phi);
noise_init(ludwig->noise_phi, 0);
noise_present_set(ludwig->noise_phi, NOISE_PHI, noise_on);
if (nhalo != 3) pe_fatal(pe, "Fluctuations: use symmetric_noise\n");
}
noise_create(pe, cs, &ludwig->noise_phi);
noise_init(ludwig->noise_phi, 0);
noise_present_set(ludwig->noise_phi, NOISE_PHI, noise_on);

/* Force */

Expand Down
86 changes: 86 additions & 0 deletions tests/regression/d3q19-short/serial-spin-fd3.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
##############################################################################
#
# Symmetric with noise (smoke test)
#
##############################################################################

##############################################################################
#
# Run duration
#
###############################################################################

N_cycles 10

##############################################################################
#
# System
#
##############################################################################

size 16_16_16
grid 2_2_2

##############################################################################
#
# Fluid parameters
#
##############################################################################

viscosity 0.00625

##############################################################################
#
# Free energy parameters
#
###############################################################################

free_energy symmetric_noise

symmetric_a -0.00625
symmetric_b 0.00625
symmetric_kappa 0.004

phi0 0.0
phi_initialisation spinodal
mobility 1.25

fd_gradient_calculation 3d_7pt_fluid
fd_advection_scheme_order 2
fd_phi_fluctuations yes

###############################################################################
#
# Colloid parameters
#
###############################################################################

colloid_init no_colloids

###############################################################################
#
# Periodic conditions / boundaries
#
###############################################################################

boundary_walls 0_0_0
periodicity 1_1_1

###############################################################################
#
# Output frequency and type
#
###############################################################################

freq_statistics 10
config_at_end no

###############################################################################
#
# Miscellaneous
#
# random_seed +ve integer is the random number generator seed
#
###############################################################################

random_seed 8361235
148 changes: 148 additions & 0 deletions tests/regression/d3q19-short/serial-spin-fd3.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
Welcome to: Ludwig v0.21.0 (Serial version running on 1 process)
Git commit: 4367aaec6f44b221cfd6496a16191aea625f54b9

Start time: Tue Apr 30 11:25:56 2024

Compiler:
name: Gnu 13.2.0
version-string: 13.2.0
options: -O -g -Wall

Note assertions via standard C assert() are on.

Target thread model: OpenMP.
OpenMP threads: 1; maximum number of threads: 11.

Read 20 user parameters from input

System details
--------------
System size: 16 16 16
Decomposition: 1 1 1
Local domain: 16 16 16
Periodic: 1 1 1
Halo nhalo: 3
Reorder: true
Initialised: 1

Free energy details
-------------------

Symmetric phi^4 free energy selected.

Parameters:
Bulk parameter A = -6.25000e-03
Bulk parameter B = 6.25000e-03
Surface penalty kappa = 4.00000e-03
Surface tension = 4.71405e-03
Interfacial width = 1.13137e+00

Using Cahn-Hilliard finite difference solver.
Mobility M = 1.25000e+00
Order parameter noise = off
Force calculation: stress_divergence

System properties
----------------
Mean fluid density: 1.00000e+00
Shear viscosity 6.25000e-03
Bulk viscosity 6.25000e-03
Temperature 0.00000e+00
External body force density 0.00000e+00 0.00000e+00 0.00000e+00
External E-field amplitude 0.00000e+00 0.00000e+00 0.00000e+00
External E-field frequency 0.00000e+00
External magnetic field 0.00000e+00 0.00000e+00 0.00000e+00

Lattice Boltzmann distributions
-------------------------------
Model: d3q19
SIMD vector len: 1
Number of sets: 1
Halo type: lb_halo_target (full halo)
Input format: binary
Output format: binary
I/O grid: 1 1 1

Lattice Boltzmann collision
---------------------------
Relaxation time scheme: M10
Hydrodynamic modes: on
Ghost modes: on
Isothermal fluctuations: off
Shear relaxation time: 5.18750e-01
Bulk relaxation time: 5.18750e-01
Ghost relaxation time: 1.00000e+00
[User ] Random number seed: 8361235

Hydrodynamics
-------------
Hydrodynamics: on

Order parameter I/O
-------------------
Order parameter I/O format:
I/O decomposition: 1 1 1

Advection scheme order: 2
Initialising phi for spinodal
Gradient calculation: 3d_7pt_fluid
Initial conditions.

Scalars - total mean variance min max
[rho] 4096.00 1.00000000000 2.2204460e-16 1.00000000000 1.00000000000
[phi] -2.2941536e+00 -5.6009608e-04 8.3652803e-04 -4.9986867e-02 4.9997941e-02

Free energy density - timestep total fluid
[fed] 0 -1.2851398593e-07 -1.2851398593e-07

Momentum - x y z
[total ] 0.0000000e+00 0.0000000e+00 0.0000000e+00
[fluid ] 0.0000000e+00 0.0000000e+00 0.0000000e+00

Starting time step loop.

Scalars - total mean variance min max
[rho] 4096.00 1.00000000000 6.7551964e-11 0.99997188903 1.00002775664
[phi] -2.2941536e+00 -5.6009608e-04 1.7010997e-04 -4.2252688e-02 3.9099621e-02

Free energy density - timestep total fluid
[fed] 10 -3.1541409019e-08 -3.1541409019e-08

Momentum - x y z
[total ] 5.3634180e-14 -2.8865799e-15 -1.4536983e-15
[fluid ] 5.3634180e-14 -2.8865799e-15 -1.4536983e-15

Velocity - x y z
[minimum ] -1.5349217e-05 -1.7270731e-05 -1.8791915e-05
[maximum ] 1.7342312e-05 1.6978872e-05 1.5340738e-05

Completed cycle 10

Timer resolution: 1e-06 second

Timer statistics
Section: tmin tmax total
Total: 0.057 0.057 0.057 0.057128 (1 call)
Time step loop: 0.005 0.006 0.054 0.005408 (10 calls)
Propagation: 0.001 0.001 0.006 0.000613 (10 calls)
Propagtn (krnl) : 0.001 0.001 0.006 0.000613 (10 calls)
Collision: 0.002 0.002 0.016 0.001630 (10 calls)
Collision (krnl) : 0.002 0.002 0.016 0.001629 (10 calls)
Lattice halos: 0.000 0.000 0.002 0.000248 (10 calls)
phi gradients: 0.000 0.000 0.004 0.000400 (10 calls)
phi grad (krnl) : 0.000 0.000 0.003 0.000266 (11 calls)
phi halos: 0.000 0.000 0.001 0.000132 (10 calls)
-> irecv: 0.000 0.000 0.000 0.000000 (21 calls)
-> pack: 0.000 0.000 0.002 0.000077 (21 calls)
-> isend: 0.000 0.000 0.000 0.000000 (21 calls)
-> waitall: 0.000 0.000 0.000 0.000000 (21 calls)
-> unpack: 0.000 0.000 0.002 0.000075 (21 calls)
BBL: 0.000 0.000 0.000 0.000000 (10 calls)
Force calculation: 0.001 0.001 0.014 0.001405 (10 calls)
Phi force (krnl) : 0.001 0.001 0.011 0.001113 (10 calls)
phi update: 0.001 0.001 0.009 0.000878 (10 calls)
Advectn (krnl) : 0.000 0.000 0.004 0.000432 (10 calls)
Advectn BCS (krnl) : 0.000 0.000 0.000 0.000044 (10 calls)
Diagnostics / output: 0.000 0.001 0.001 0.000121 (10 calls)
End time: Tue Apr 30 11:25:56 2024
Ludwig finished normally.

0 comments on commit 1810bf3

Please sign in to comment.