Skip to content

Commit 5fb3d9a

Browse files
committed
feature: 'sw_steady' protocol for color model to exit explicitly on sw convergence
1 parent b5cac49 commit 5fb3d9a

File tree

3 files changed

+94
-8
lines changed

3 files changed

+94
-8
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
======================================
2+
Color model -- Sw Steady
3+
======================================
4+
5+
The water saturation steady state protocol is identical to the centrifuge protocol, with
6+
the exception that the simulation explicity converges on the saturation state of fluid
7+
A.
8+
9+
That is, the simulation exits when
10+
11+
.. math::
12+
:nowrap:
13+
14+
$$
15+
\frac{\left | S_{w, i+1} - S_{w, i} \right |}{S_{w, i}} \le \epsilon
16+
$$
17+
18+
averaged over the ``analysis_interval`` where :math:`S_{w,i}` is the saturation of fluid
19+
A at step :math:`i` and :math:`\epsilon` is an allowed convergence threshold, or when
20+
the ``timestepMax`` is reached, whichever occurs first.
21+
22+
By default, :math:`\epsilon` is set to zero (i.e., the simulation continues through the
23+
``timestepMax``), but can be set via ``tolerance`` within the ``Analysis`` section of
24+
the input file database as shown below.
25+
26+
27+
.. code-block:: c
28+
29+
Color {
30+
protocol = "sw_steady"
31+
timestepMax = 1000000 // maximum timtestep
32+
alpha = 0.005 // controls interfacial tension
33+
rhoA = 1.0 // controls the density of fluid A
34+
rhoB = 1.0 // controls the density of fluid B
35+
tauA = 0.7 // controls the viscosity of fluid A
36+
tauB = 0.7 // controls the viscosity of fluid B
37+
F = 0, 0, -1.0e-5 // body force
38+
din = 1.0 // inlet density (controls pressure)
39+
dout = 1.0 // outlet density (controls pressure)
40+
WettingConvention = "SCAL" // convention for sign of wetting affinity
41+
ComponentLabels = 0, -1, -2 // image labels for solid voxels
42+
ComponentAffinity = 1.0, 1.0, 0.6 // controls the wetting affinity for each label
43+
Restart = false
44+
}
45+
Domain {
46+
Filename = "Bentheimer_LB_sim_intermediate_oil_wet_Sw_0p37.raw"
47+
ReadType = "8bit" // data type
48+
N = 900, 900, 1600 // size of original image
49+
nproc = 2, 2, 2 // process grid
50+
n = 200, 200, 200 // sub-domain size
51+
offset = 300, 300, 300 // offset to read sub-domain
52+
voxel_length = 1.66 // voxel length (in microns)
53+
ReadValues = -2, -1, 0, 1, 2 // labels within the original image
54+
WriteValues = -2, -1, 0, 1, 2 // associated labels to be used by LBPM
55+
BC = 3 // boundary condition type (0 for periodic)
56+
}
57+
Analysis {
58+
analysis_interval = 1000 // logging interval for timelog.csv
59+
subphase_analysis_interval = 5000 // loggging interval for subphase.csv
60+
visualization_interval = 100000 // interval to write visualization files
61+
N_threads = 4 // number of analysis threads (GPU version only)
62+
restart_interval = 1000000 // interval to write restart file
63+
restart_file = "Restart" // base name of restart file
64+
tolerance = 1e-9 // Sw convergence tolerance
65+
}
66+
Visualization {
67+
write_silo = true // write SILO databases with assigned variables
68+
save_8bit_raw = true // write labeled 8-bit binary files with phase assignments
69+
save_phase_field = true // save phase field within SILO database
70+
save_pressure = false // save pressure field within SILO database
71+
save_velocity = false // save velocity field within SILO database
72+
}

models/ColorModel.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void ScaLBL_ColorModel::ReadParams(string filename) {
172172
"periodic boundary condition \n");
173173
}
174174
domain_db->putScalar<int>("BC", BoundaryCondition);
175-
} else if (protocol == "centrifuge") {
175+
} else if (protocol == "centrifuge" || protocol == "sw_steady") {
176176
if (BoundaryCondition != 3) {
177177
BoundaryCondition = 3;
178178
if (rank == 0)
@@ -1116,7 +1116,11 @@ void ScaLBL_ColorModel::Run() {
11161116
Map);
11171117
//analysis.createThreads( analysis_method, 4 );
11181118
auto t1 = std::chrono::system_clock::now();
1119-
while (timestep < timestepMax) {
1119+
1120+
double delta_sw = 1.0;
1121+
double sw_prev = -1.0;
1122+
1123+
while (timestep < timestepMax && delta_sw > tolerance) {
11201124
PROFILE_START("Update");
11211125

11221126
// *************ODD TIMESTEP*************
@@ -1213,13 +1217,23 @@ void ScaLBL_ColorModel::Run() {
12131217
//************************************************************************
12141218
PROFILE_STOP("Update");
12151219

1216-
if (rank == 0 && timestep % analysis_interval == 0 &&
1217-
BoundaryCondition == 4) {
1218-
printf("%i %f \n", timestep, din);
1219-
}
12201220
// Run the analysis
12211221
analysis.basic(timestep, current_db, *Averages, Phi, Pressure, Velocity,
12221222
fq, Den);
1223+
1224+
if (timestep % analysis_interval == 0){
1225+
analysis.finish();
1226+
1227+
double volA = Averages->gnb.V / Dm->Volume;
1228+
double volB = Averages->gwb.V / Dm->Volume;
1229+
double sw = volB / (volA + volB);
1230+
1231+
delta_sw = fabs(sw - sw_prev) / analysis_interval / sw;
1232+
if (rank == 0)
1233+
printf("t: %d sw: %0.5e dSw/dt: %.5e\n", timestep, sw, delta_sw);
1234+
1235+
sw_prev = sw;
1236+
}
12231237
}
12241238
analysis.finish();
12251239
PROFILE_STOP("Loop");

tests/lbpm_color_simulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ int main( int argc, char **argv )
6666
// structure and allocate variables
6767
ColorModel.Initialize(); // initializing the model will set initial conditions for variables
6868

69-
if (SimulationMode == "legacy"){
69+
auto PROTOCOL = ColorModel.color_db->getWithDefault<std::string>( "protocol", "default" );
70+
if (PROTOCOL == "sw_steady") {
7071
ColorModel.Run();
7172
}
7273
else {
@@ -75,7 +76,6 @@ int main( int argc, char **argv )
7576
bool ContinueSimulation = true;
7677

7778
/* Variables for simulation protocols */
78-
auto PROTOCOL = ColorModel.color_db->getWithDefault<std::string>( "protocol", "default" );
7979
/* image sequence protocol */
8080
int IMAGE_INDEX = 0;
8181
int IMAGE_COUNT = 0;

0 commit comments

Comments
 (0)