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

CHNS Free Energy Postprocessing #1095

Merged
merged 9 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to the Lethe project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [Master] - 2024-04-17

### Added

- MINOR Added computation of the energies involved in the Cahn-Hilliard equations and updated related documentation. [#1095](https://github.com/lethe-cfd/lethe/pull/1095)
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved

## [Master] - 2024-04-16

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Running on 1 MPI rank(s)...
Number of active cells: 64
Number of degrees of freedom: 243
Volume of triangulation: 4
Number of Cahn-Hilliard degrees of freedom: 162
-----------------
Phase statistics
-----------------
Min: -0.994529
Max: 1
Average: 0.607051
Integral: 2.4282
Volume phase 0: 3.2141
Volume phase 1: 0.785898
-------------
Phase energy
-------------
Bulk energy: 0.667619
Interface energy: 1.74433
Total energy: 2.41195

*******************************************************************************
Transient iteration: 1 Time: 0.5 Time step: 0.5 CFL: 0
*******************************************************************************
-----------------
Phase statistics
-----------------
Min: -1.01453
Max: 1.00534
Average: 0.60706
Integral: 2.42824
Volume phase 0: 3.21412
Volume phase 1: 0.78588
-------------
Phase energy
-------------
Bulk energy: 0.687751
Interface energy: 1.66703
Total energy: 2.35478

*******************************************************************************
Transient iteration: 2 Time: 1 Time step: 0.5 CFL: 0.967317
*******************************************************************************
-----------------
Phase statistics
-----------------
Min: -0.891115
Max: 1.0132
Average: 0.61502
Integral: 2.46008
Volume phase 0: 3.23004
Volume phase 1: 0.76996
-------------
Phase energy
-------------
Bulk energy: 1.08564
Interface energy: 1.19563
Total energy: 2.28127
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
set dimension = 2

PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved
subsection simulation control
set method = bdf1
set time end = 1
set time step = 0.5
set output name = out
set output frequency = 0
end

subsection initial conditions
set type = L2projection
subsection cahn hilliard
set Function constants = nbr_refs=5
set Function expression = -tanh(sqrt(2*0.25)*(0.5 - sqrt(x*x+y*y))/(2^(-nbr_refs+1))); 0
end
end

subsection boundary conditions
set number = 4
set time dependent = false
subsection bc 0
set id = 0
set type = slip
end
subsection bc 1
set id = 1
set type = slip
end
subsection bc 2
set id = 2
set type = slip
end
subsection bc 3
set id = 3
set type = slip
end
end

subsection boundary conditions cahn hilliard
set number = 1
subsection bc 0
set id = 0
set type = dirichlet
subsection phi
set Function constants = nbr_refs=5
set Function expression = -tanh(sqrt(2*0.25)*(0.5 - sqrt(x*x+y*y))/(2^(-nbr_refs+1)))
end
end
end

subsection multiphysics
set fluid dynamics = true
set cahn hilliard = true
end

subsection cahn hilliard
set potential smoothing coefficient = 0.0

subsection epsilon
set method = automatic
end
end

subsection physical properties
set number of fluids = 2
subsection fluid 0
set density = 1000
set kinematic viscosity = 0.01
end
subsection fluid 1
set density = 100
set kinematic viscosity = 0.01
end
set number of material interactions = 1
subsection material interaction 0
set type = fluid-fluid
subsection fluid-fluid interaction
set first fluid id = 0
set second fluid id = 1
set surface tension model = constant
set surface tension coefficient = 24.5
# Mobility Cahn-Hilliard
set cahn hilliard mobility model = constant
set cahn hilliard mobility constant = 1e-6
end
end
end

subsection mesh
set type = dealii
set grid type = hyper_cube
set grid arguments = -1 : 1 : true
set initial refinement = 3
end

subsection post-processing
set verbosity = verbose
set calculate phase statistics = true
set phase statistics name = phase_statistics
set calculate phase energy = true
end

subsection FEM
set phase cahn hilliard order = 1
set potential cahn hilliard order = 1
set velocity order = 1
set pressure order = 1
end

subsection non-linear solver
subsection fluid dynamics
set verbosity = quiet
end
subsection cahn hilliard
set verbosity = quiet
end
end

subsection linear solver
subsection fluid dynamics
set verbosity = quiet
end
subsection cahn hilliard
set verbosity = quiet
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Min: -0.994529
Max: 1
Average: 0.544551
Integral: 2.1782
Volume phase 0: 3.0891
Volume phase 1: 0.910898

*******************************************************************************
Transient iteration: 1 Time: 0.5 Time step: 0.5 CFL: 0
Transient iteration: 1 Time: 0.5 Time step: 0.5 CFL: 0
*******************************************************************************
-----------------
Phase statistics
Expand All @@ -21,6 +23,8 @@ Min: -0.786164
Max: 0.781734
Average: 0.423636
Integral: 1.69454
Volume phase 0: 2.84727
Volume phase 1: 1.15273

*******************************************************************************
Transient iteration: 2 Time: 1 Time step: 0.5 CFL: 0.533525
Expand All @@ -32,3 +36,5 @@ Min: -0.780241
Max: 0.794182
Average: 0.427977
Integral: 1.71191
Volume phase 0: 2.85595
Volume phase 1: 1.14405
24 changes: 23 additions & 1 deletion doc/source/parameters/cfd/post_processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ This subsection controls the post-processing other than the forces and torque on
# Other Cahn-Hilliard postprocessing
set calculate phase statistics = false
set phase statistics name = phase_statistics
set calculate phase energy = true
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved
set phase energy name = phase_energy

end

Expand Down Expand Up @@ -219,8 +221,28 @@ This subsection controls the post-processing other than the forces and torque on

* ``mass conservation name``: name of the output file containing the mass of both fluids for VOF simulations. The default file name is ``mass_conservation_information``.

* ``calculate phase statistics``: outputs phase statistics from the solution of the Cahn-Hilliard equations, including minimum, maximum, average, and standard deviation of the phase order parameter. This works only with the :doc:`cahn_hilliard` solver.
* ``calculate phase statistics``: outputs phase statistics from the solution of the Cahn-Hilliard equations, including minimum, maximum, average, integral of the phase order parameter. Also includes the volume of each phase. This works only with the :doc:`cahn_hilliard` solver.
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved

* ``phase statistics name``: name of the output file containing phase order parameter statistics from Cahn-Hilliard simulations. The default file name is ``phase_statistics``.

* ``calculate phase energy``: outputs phase energies from the solution of the Cahn-Hilliard equations : bulk energy, interface energy and total energy. This works only with the :doc:`cahn_hilliard` solver. The energies are computed as follow:
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved

.. math::

E_{bulk} = \int_{\Omega} (1-\phi^2)^2 \mathrm{d}\Omega

.. math::

E_{interface} = \int_{\Omega} 0.5\epsilon^2|\nabla \phi |^2 \mathrm{d}\Omega

.. math::

E_{total} = E_{bulk} + E_{interface}

where :math:`\epsilon` is the numerical interface thickness. Note that these energies are not homogeneous to physical energies, but they give nonetheless a good insight on the system's evolution.
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved


* ``phase energy name``: name of the output file containing phase energies from Cahn-Hilliard simulations. The default file name is ``phase_energy``.
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved



6 changes: 6 additions & 0 deletions include/core/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,12 @@ namespace Parameters
/// Prefix for the VOF mass conservation output
std::string mass_conservation_output_name;

/// Enable energies calculation on the domain in Cahn-Hilliard simulations
bool calculate_phase_energy;

/// Prefix for the energy output in Cahn-Hilliard simulations
std::string phase_energy_output_name;

static void
declare_parameters(ParameterHandler &prm);
void
Expand Down
18 changes: 17 additions & 1 deletion include/solvers/cahn_hilliard.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,24 @@ class CahnHilliard : public AuxiliaryPhysics<dim, GlobalVectorType>
calculate_phase_statistics();

/**
* @brief Writes the phase integral to an output file
* @brief Writes the phase statistics to an output file
*/
void
write_phase_statistics();

/**
*
* @return A pointer to an array of double containing the energies. First element is bulk energy, second is interface energy and third is total energy
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved
*/
void
calculate_phase_energy();

/*
* @brief Write the energy to an output file
*/
void
write_phase_energy();

/**
* @brief Calculates the barycenter of fluid 1 and its velocity
*
Expand Down Expand Up @@ -483,6 +496,9 @@ class CahnHilliard : public AuxiliaryPhysics<dim, GlobalVectorType>
// Phase statistics table
TableHandler statistics_table;

// Phase energy table
TableHandler phase_energy_table;

// Phase fraction filter
std::shared_ptr<CahnHilliardFilterBase> filter;
};
Expand Down
14 changes: 14 additions & 0 deletions source/core/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,18 @@ namespace Parameters
"mass_conservation_information",
Patterns::FileName(),
"Name of mass conservation output file in VOF simulations");

prm.declare_entry(
"calculate phase energy",
"false",
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved
Patterns::Bool(),
"Enable calculation of phase energies : total energy, bulk energy and interface energy");
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved

prm.declare_entry(
"phase energy name",
"phase_energy",
Patterns::FileName(),
"Name of energy output file in Cahn-Hilliard simulations.");
PierreLaurentinCS marked this conversation as resolved.
Show resolved Hide resolved
}
prm.leave_subsection();
}
Expand Down Expand Up @@ -1875,6 +1887,8 @@ namespace Parameters
barycenter_output_name = prm.get("barycenter name");
calculate_mass_conservation = prm.get_bool("calculate mass conservation");
mass_conservation_output_name = prm.get("mass conservation name");
calculate_phase_energy = prm.get_bool("calculate phase energy");
phase_energy_output_name = prm.get("phase energy name");

// Viscous dissipative fluid
const std::string op_fluid = prm.get("postprocessed fluid");
Expand Down
Loading
Loading