v0.15.0
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
free_surface.cpp File Reference
#include <MoFEM.hpp>
#include <petsc/private/petscimpl.h>
#include <FreeSurfaceOps.hpp>

Go to the source code of this file.

Classes

struct  TSPrePostProc
 Set of functions called by PETSc solver used to refine and update mesh. More...
 
struct  FreeSurface
 
struct  Monitor
 [Push operators to pipeline] More...
 

Typedefs

template<int DIM>
using ElementsAndOps = PipelineManager::ElementsAndOpsByDim< SPACE_DIM >
 
using DomainEle = ElementsAndOps< SPACE_DIM >::DomainEle
 
using DomainParentEle = ElementsAndOps< SPACE_DIM >::DomainParentEle
 
using DomainEleOp = DomainEle::UserDataOperator
 
using BoundaryEle = ElementsAndOps< SPACE_DIM >::BoundaryEle
 
using BoundaryParentEle = ElementsAndOps< SPACE_DIM >::BoundaryParentEle
 
using BoundaryEleOp = BoundaryEle::UserDataOperator
 
using SideEle = ElementsAndOps< SPACE_DIM >::FaceSideEle
 
using SideOp = SideEle::UserDataOperator
 
using PostProcEleDomain = PostProcBrokenMeshInMoab< DomainEle >
 
using PostProcEleDomainCont = PostProcBrokenMeshInMoabBaseCont< DomainEle >
 
using PostProcEleBdyCont = PostProcBrokenMeshInMoabBaseCont< BoundaryEle >
 
using EntData = EntitiesFieldData::EntData
 
using AssemblyDomainEleOp = FormsIntegrators< DomainEleOp >::Assembly< A >::OpBase
 
using AssemblyBoundaryEleOp = FormsIntegrators< BoundaryEleOp >::Assembly< A >::OpBase
 
using OpDomainMassU = FormsIntegrators< DomainEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, U_FIELD_DIM >
 
using OpDomainMassH = FormsIntegrators< DomainEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, 1 >
 
using OpDomainMassP = OpDomainMassH
 
using OpDomainMassG = OpDomainMassH
 
using OpBoundaryMassL = FormsIntegrators< BoundaryEleOp >::Assembly< A >::BiLinearForm< I >::OpMass< BASE_DIM, 1 >
 
using OpDomainAssembleVector = FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpBaseTimesVector< BASE_DIM, SPACE_DIM, 1 >
 
using OpDomainAssembleScalar = FormsIntegrators< DomainEleOp >::Assembly< A >::LinearForm< I >::OpBaseTimesScalar< BASE_DIM >
 
using OpBoundaryAssembleScalar = FormsIntegrators< BoundaryEleOp >::Assembly< A >::LinearForm< I >::OpBaseTimesScalar< BASE_DIM >
 
template<CoordinateTypes COORD_TYPE>
using OpMixScalarTimesDiv = FormsIntegrators< DomainEleOp >::Assembly< A >::BiLinearForm< I >::OpMixScalarTimesDiv< SPACE_DIM, COORD_TYPE >
 
using BoundaryNaturalBC = NaturalBC< BoundaryEleOp >::Assembly< A >::LinearForm< I >
 
using OpFluidFlux = BoundaryNaturalBC::OpFlux< NaturalMeshsetType< BLOCKSET >, 1, 1 >
 

Enumerations

enum  FR { F , R }
 

Functions

int main (int argc, char *argv[])
 Main function for free surface simulation.
 

Variables

static char help [] = "...\n\n"
 
int coord_type = EXECUTABLE_COORD_TYPE
 
constexpr int BASE_DIM = 1
 
constexpr int SPACE_DIM = 2
 
constexpr int U_FIELD_DIM = SPACE_DIM
 
constexpr AssemblyType A = AssemblyType::PETSC
 
constexpr IntegrationType I
 
FTensor::Index< 'i', SPACE_DIMi
 
FTensor::Index< 'j', SPACE_DIMj
 
FTensor::Index< 'k', SPACE_DIMk
 
FTensor::Index< 'l', SPACE_DIMl
 
constexpr auto t_kd = FTensor::Kronecker_Delta_symmetric<int>()
 
int order = 3
 approximation order
 
int nb_levels = 4
 
int refine_overlap = 4
 
constexpr bool debug = true
 
auto get_start_bit
 
auto get_current_bit
 dofs bit used to do calculations
 
auto get_skin_parent_bit = []() { return 2 * get_start_bit() + 2; }
 
auto get_skin_child_bit = []() { return 2 * get_start_bit() + 3; }
 
auto get_projection_bit = []() { return 2 * get_start_bit() + 4; }
 
auto get_skin_projection_bit = []() { return 2 * get_start_bit() + 5; }
 
double a0 = 980
 
double rho_m = 0.998
 
double mu_m = 0.010101 * 1e2
 
double rho_p = 0.0012
 
double mu_p = 0.000182 * 1e2
 
double lambda = 73
 surface tension
 
double W = 0.25
 
double h = 0.03
 
double eta = h
 
double eta2 = eta * eta
 
double md = 1e-2
 
double eps = 1e-12
 
double tol = std::numeric_limits<float>::epsilon()
 
double rho_ave = (rho_p + rho_m) / 2
 
double rho_diff = (rho_p - rho_m) / 2
 
double mu_ave = (mu_p + mu_m) / 2
 
double mu_diff = (mu_p - mu_m) / 2
 
double kappa = (3. / (4. * std::sqrt(2. * W))) * (lambda / eta)
 
auto integration_rule = [](int, int, int) { return 2 * order + 1; }
 
auto cylindrical
 Coordinate system scaling factor.
 
auto wetting_angle_sub_stepping
 Wetting angle sub-stepping for gradual application.
 
auto my_max = [](const double x) { return (x - 1 + std::abs(x + 1)) / 2; }
 Maximum function with smooth transition.
 
auto my_min = [](const double x) { return (x + 1 - std::abs(x - 1)) / 2; }
 Minimum function with smooth transition

 
auto cut_off = [](const double h) { return my_max(my_min(h)); }
 Phase field cutoff function.
 
auto d_cut_off
 Derivative of cutoff function.
 
auto phase_function
 Phase-dependent material property interpolation.
 
auto d_phase_function_h
 Derivative of phase function with respect to h.
 
auto get_f = [](const double h) { return 4 * W * h * (h * h - 1); }
 Double-well potential function.
 
auto get_f_dh = [](const double h) { return 4 * W * (3 * h * h - 1); }
 Derivative of double-well potential.
 
auto get_M0 = [](auto h) { return md; }
 Constant mobility function M₀
 
auto get_M0_dh = [](auto h) { return 0; }
 Derivative of constant mobility.
 
auto get_M2
 Degenerate mobility function M₂
 
auto get_M2_dh = [](auto h) { return -md * 2 * h; }
 Derivative of degenerate mobility M₂
 
auto get_M3
 Non-linear mobility function M₃
 
auto get_M3_dh
 Derivative of non-linear mobility M₃
 
auto get_M = [](auto h) { return get_M0(h); }
 
auto get_M_dh = [](auto h) { return get_M0_dh(h); }
 
auto get_D
 Create deviatoric stress tensor.
 
auto kernel_oscillation
 Oscillating interface initialization.
 
auto kernel_eye
 Eye-shaped interface initialization

 
auto capillary_tube
 Capillary tube initialization.
 
auto bubble_device
 Bubble device initialization.
 
auto init_h
 Initialisation function.
 
auto wetting_angle = [](double water_level) { return water_level; }
 Wetting angle function (placeholder)
 
auto bit = [](auto b) { return BitRefLevel().set(b); }
 Create bit reference level.
 
auto marker = [](auto b) { return BitRefLevel().set(BITREFLEVEL_SIZE - b); }
 Create marker bit reference level

 
auto get_fe_bit
 Get bit reference level from finite element.
 
auto get_global_size
 Get global size across all processors.
 
auto save_range
 Save range of entities to file.
 
auto get_dofs_ents_by_field_name
 Get entities of DOFs by field name - used for debugging.
 
auto get_dofs_ents_all
 Get all entities with DOFs in the problem - used for debugging.
 
static boost::weak_ptr< TSPrePostProctsPrePostProc
 

Typedef Documentation

◆ AssemblyBoundaryEleOp

Definition at line 130 of file free_surface.cpp.

◆ AssemblyDomainEleOp

Definition at line 129 of file free_surface.cpp.

◆ BoundaryEle

Definition at line 117 of file free_surface.cpp.

◆ BoundaryEleOp

Definition at line 119 of file free_surface.cpp.

◆ BoundaryNaturalBC

Definition at line 154 of file free_surface.cpp.

◆ BoundaryParentEle

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 118 of file free_surface.cpp.

◆ DomainEle

Definition at line 114 of file free_surface.cpp.

◆ DomainEleOp

Definition at line 116 of file free_surface.cpp.

◆ DomainParentEle

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 115 of file free_surface.cpp.

◆ ElementsAndOps

Definition at line 112 of file free_surface.cpp.

◆ EntData

Definition at line 127 of file free_surface.cpp.

◆ OpBoundaryAssembleScalar

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 146 of file free_surface.cpp.

◆ OpBoundaryMassL

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 139 of file free_surface.cpp.

◆ OpDomainAssembleScalar

using OpDomainAssembleScalar = FormsIntegrators<DomainEleOp>::Assembly< A>::LinearForm<I>::OpBaseTimesScalar<BASE_DIM>
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 144 of file free_surface.cpp.

◆ OpDomainAssembleVector

using OpDomainAssembleVector = FormsIntegrators<DomainEleOp>::Assembly< A>::LinearForm<I>::OpBaseTimesVector<BASE_DIM, SPACE_DIM, 1>
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 142 of file free_surface.cpp.

◆ OpDomainMassG

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 138 of file free_surface.cpp.

◆ OpDomainMassH

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 135 of file free_surface.cpp.

◆ OpDomainMassP

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 137 of file free_surface.cpp.

◆ OpDomainMassU

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 133 of file free_surface.cpp.

◆ OpFluidFlux

Definition at line 155 of file free_surface.cpp.

◆ OpMixScalarTimesDiv

Definition at line 150 of file free_surface.cpp.

◆ PostProcEleBdyCont

Definition at line 125 of file free_surface.cpp.

◆ PostProcEleDomain

Definition at line 123 of file free_surface.cpp.

◆ PostProcEleDomainCont

Definition at line 124 of file free_surface.cpp.

◆ SideEle

Definition at line 120 of file free_surface.cpp.

◆ SideOp

Definition at line 121 of file free_surface.cpp.

Enumeration Type Documentation

◆ FR

enum FR
Enumerator

Definition at line 624 of file free_surface.cpp.

624{ F, R }; // F - forward, and reverse
@ R
@ F

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function for free surface simulation.

Parameters
argcNumber of command line arguments
argvArray of command line argument strings
Returns
Exit code (0 for success)

Main driver function that:

  1. Initializes MoFEM/PETSc and MOAB data structures
  2. Sets up logging channels for debugging output
  3. Registers MoFEM discrete manager with PETSc
  4. Creates mesh database (MOAB) and finite element database (MoFEM)
  5. Runs the complete free surface simulation
  6. Handles cleanup and finalization

Command line options are read from param_file.petsc and command line. Python initialization is optional (controlled by PYTHON_INIT_SURFACE).

[Register MoFEM discrete manager in PETSc]

[Register MoFEM discrete manager in PETSc

[Create MoAB]

< mesh database

< mesh database interface

[Create MoAB]

[Create MoFEM]

< finite element database

< finite element database interface

[Create MoFEM]

[FreeSurface]

[FreeSurface]

Definition at line 2855 of file free_surface.cpp.

2855 {
2856
2857#ifdef PYTHON_INIT_SURFACE
2858 Py_Initialize();
2859#endif
2860
2861 // Initialisation of MoFEM/PETSc and MOAB data structures
2862 const char param_file[] = "param_file.petsc";
2863 MoFEM::Core::Initialize(&argc, &argv, param_file, help);
2864
2865 // Add logging channel for example
2866 auto core_log = logging::core::get();
2867 core_log->add_sink(LogManager::createSink(LogManager::getStrmWorld(), "FS"));
2868 LogManager::setLog("FS");
2869 MOFEM_LOG_TAG("FS", "free surface");
2870
2871 try {
2872
2873 //! [Register MoFEM discrete manager in PETSc]
2874 DMType dm_name = "DMMOFEM";
2875 CHKERR DMRegister_MoFEM(dm_name);
2876 //! [Register MoFEM discrete manager in PETSc
2877
2878 //! [Create MoAB]
2879 moab::Core mb_instance; ///< mesh database
2880 moab::Interface &moab = mb_instance; ///< mesh database interface
2881 //! [Create MoAB]
2882
2883 //! [Create MoFEM]
2884 MoFEM::Core core(moab); ///< finite element database
2885 MoFEM::Interface &m_field = core; ///< finite element database interface
2886 //! [Create MoFEM]
2887
2888 //! [FreeSurface]
2889 FreeSurface ex(m_field);
2890 CHKERR ex.runProblem();
2891 //! [FreeSurface]
2892 }
2894
2896
2897#ifdef PYTHON_INIT_SURFACE
2898 if (Py_FinalizeEx() < 0) {
2899 exit(120);
2900 }
2901#endif
2902}
#define CATCH_ERRORS
Catch errors.
#define CHKERR
Inline error check.
static char help[]
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Core (interface) class.
Definition Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:118
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.

Variable Documentation

◆ A

constexpr AssemblyType A = AssemblyType::PETSC
constexpr
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 107 of file free_surface.cpp.

◆ a0

double a0 = 980
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 186 of file free_surface.cpp.

◆ BASE_DIM

constexpr int BASE_DIM = 1
constexpr

Definition at line 103 of file free_surface.cpp.

◆ bit

auto bit = [](auto b) { return BitRefLevel().set(b); }

Create bit reference level.

Parameters
bBit number to set
Returns
BitRefLevel with specified bit set
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 506 of file free_surface.cpp.

506{ return BitRefLevel().set(b); };
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40

◆ bubble_device

auto bubble_device
Initial value:
= [](double x, double y, double z) {
return -tanh((-0.039 - x) / (eta * std::sqrt(2)));
}
double eta

Bubble device initialization.

Parameters
xX-coordinate
yY-coordinate (unused)
zZ-coordinate (unused)
Returns
Phase field value (-1 to 1)

Creates vertical interface for bubble formation device

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 465 of file free_surface.cpp.

465 {
466 return -tanh((-0.039 - x) / (eta * std::sqrt(2)));
467};

◆ capillary_tube

auto capillary_tube
Initial value:
= [](double x, double y, double z) {
constexpr double water_height = 0.;
return tanh((water_height - y) / (eta * std::sqrt(2)));
;
}

Capillary tube initialization.

Parameters
xX-coordinate (unused)
yY-coordinate
zZ-coordinate (unused)
Returns
Phase field value (-1 to 1)

Creates horizontal interface at specified water height

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 450 of file free_surface.cpp.

450 {
451 constexpr double water_height = 0.;
452 return tanh((water_height - y) / (eta * std::sqrt(2)));
453 ;
454};

◆ coord_type

int coord_type = EXECUTABLE_COORD_TYPE
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 101 of file free_surface.cpp.

◆ cut_off

auto cut_off = [](const double h) { return my_max(my_min(h)); }

Phase field cutoff function.

Parameters
hPhase field value
Returns
Constrained value in [-1, 1]

Constrains phase field values to physical range [-1,1] with smooth cutoff

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 264 of file free_surface.cpp.

264{ return my_max(my_min(h)); };
double h
auto my_max
Maximum function with smooth transition.
auto my_min
Minimum function with smooth transition

◆ cylindrical

auto cylindrical
Initial value:
= [](const double r) {
return 2 * M_PI * r;
else
return 1.;
}
@ CYLINDRICAL
int coord_type

Coordinate system scaling factor.

Parameters
rRadial coordinate
Returns
Scaling factor for integration

Returns 2πr for cylindrical coordinates, 1 for Cartesian. Used to scale integration measures and force contributions.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 221 of file free_surface.cpp.

221 {
222 if (coord_type == CYLINDRICAL)
223 return 2 * M_PI * r;
224 else
225 return 1.;
226};
int r
Definition sdf.py:8

◆ d_cut_off

auto d_cut_off
Initial value:
= [](const double h) {
if (h >= -1 && h < 1)
return 1.;
else
return 0.;
}

Derivative of cutoff function.

Parameters
hPhase field value
Returns
Derivative of cutoff function
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 271 of file free_surface.cpp.

271 {
272 if (h >= -1 && h < 1)
273 return 1.;
274 else
275 return 0.;
276};

◆ d_phase_function_h

auto d_phase_function_h
Initial value:
= [](const double h, const double diff) {
return diff;
}

Derivative of phase function with respect to h.

Parameters
hPhase field value (unused in linear case)
diffDifference between phase values
Returns
Derivative value
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 298 of file free_surface.cpp.

298 {
299 return diff;
300};

◆ debug

constexpr bool debug = true
constexpr

Definition at line 170 of file free_surface.cpp.

◆ eps

double eps = 1e-12
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 201 of file free_surface.cpp.

◆ eta

double eta = h

◆ eta2

double eta2 = eta * eta
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 197 of file free_surface.cpp.

◆ get_current_bit

auto get_current_bit
Initial value:
= []() {
return 2 * get_start_bit() + 1;
}
auto get_start_bit

dofs bit used to do calculations

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 175 of file free_surface.cpp.

175 {
176 return 2 * get_start_bit() + 1;
177}; ///< dofs bit used to do calculations

◆ get_D

auto get_D
Initial value:
= [](const double A) {
t_D(i, j, k, l) = A * ((t_kd(i, k) ^ t_kd(j, l)) / 4.);
return t_D;
}
FTensor::Index< 'j', SPACE_DIM > j
FTensor::Index< 'k', SPACE_DIM > k
FTensor::Index< 'i', SPACE_DIM > i
constexpr auto t_kd
FTensor::Index< 'l', SPACE_DIM > l
constexpr AssemblyType A

Create deviatoric stress tensor.

Parameters
ACoefficient for tensor scaling
Returns
Fourth-order deviatoric tensor D_ijkl

Constructs deviatoric part of fourth-order identity tensor: D_ijkl = A * (δ_ik δ_jl + δ_il δ_jk)/2 Used in viscous stress calculations for fluid flow

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 394 of file free_surface.cpp.

394 {
396 t_D(i, j, k, l) = A * ((t_kd(i, k) ^ t_kd(j, l)) / 4.);
397 return t_D;
398};

◆ get_dofs_ents_all

auto get_dofs_ents_all
Initial value:
= [](auto dm) {
auto prb_ptr = getProblemPtr(dm);
std::vector<EntityHandle> ents_vec;
MoFEM::Interface *m_field_ptr;
CHKERR DMoFEMGetInterfacePtr(dm, &m_field_ptr);
auto dofs = prb_ptr->numeredRowDofsPtr;
ents_vec.reserve(dofs->size());
for (auto d : *dofs) {
ents_vec.push_back(d->getEnt());
}
std::sort(ents_vec.begin(), ents_vec.end());
auto it = std::unique(ents_vec.begin(), ents_vec.end());
Range r;
r.insert_list(ents_vec.begin(), it);
return r;
}
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition DMMoFEM.cpp:410
auto getProblemPtr(DM dm)
get problem pointer from DM
Definition DMMoFEM.hpp:1179

Get all entities with DOFs in the problem - used for debugging.

Parameters
dmPETSc DM object containing the problem
Returns
Range of all entities containing any DOFs

Extracts all mesh entities that have degrees of freedom for any field. Useful for debugging mesh partitioning and DOF distribution.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 598 of file free_surface.cpp.

598 {
599 auto prb_ptr = getProblemPtr(dm);
600 std::vector<EntityHandle> ents_vec;
601
602 MoFEM::Interface *m_field_ptr;
603 CHKERR DMoFEMGetInterfacePtr(dm, &m_field_ptr);
604
605 auto dofs = prb_ptr->numeredRowDofsPtr;
606 ents_vec.reserve(dofs->size());
607
608 for (auto d : *dofs) {
609 ents_vec.push_back(d->getEnt());
610 }
611
612 std::sort(ents_vec.begin(), ents_vec.end());
613 auto it = std::unique(ents_vec.begin(), ents_vec.end());
614 Range r;
615 r.insert_list(ents_vec.begin(), it);
616 return r;
617};

◆ get_dofs_ents_by_field_name

auto get_dofs_ents_by_field_name
Initial value:
= [](auto dm, auto field_name) {
auto prb_ptr = getProblemPtr(dm);
std::vector<EntityHandle> ents_vec;
MoFEM::Interface *m_field_ptr;
CHKERR DMoFEMGetInterfacePtr(dm, &m_field_ptr);
auto bit_number = m_field_ptr->get_field_bit_number(field_name);
auto dofs = prb_ptr->numeredRowDofsPtr;
auto lo_it = dofs->lower_bound(FieldEntity::getLoBitNumberUId(bit_number));
auto hi_it = dofs->upper_bound(FieldEntity::getHiBitNumberUId(bit_number));
ents_vec.reserve(std::distance(lo_it, hi_it));
for (; lo_it != hi_it; ++lo_it) {
ents_vec.push_back((*lo_it)->getEnt());
}
std::sort(ents_vec.begin(), ents_vec.end());
auto it = std::unique(ents_vec.begin(), ents_vec.end());
Range r;
r.insert_list(ents_vec.begin(), it);
return r;
}
constexpr auto field_name
virtual FieldBitNumber get_field_bit_number(const std::string name) const =0
get field bit number
static UId getHiBitNumberUId(const FieldBitNumber bit_number)
static UId getLoBitNumberUId(const FieldBitNumber bit_number)

Get entities of DOFs by field name - used for debugging.

Parameters
dmPETSc DM object containing the problem
field_nameName of field to extract entities for
Returns
Range of entities containing DOFs for specified field

Extracts all mesh entities that have degrees of freedom for the specified field. Useful for debugging and visualization of field distributions across the mesh.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 566 of file free_surface.cpp.

566 {
567 auto prb_ptr = getProblemPtr(dm);
568 std::vector<EntityHandle> ents_vec;
569
570 MoFEM::Interface *m_field_ptr;
571 CHKERR DMoFEMGetInterfacePtr(dm, &m_field_ptr);
572
573 auto bit_number = m_field_ptr->get_field_bit_number(field_name);
574 auto dofs = prb_ptr->numeredRowDofsPtr;
575 auto lo_it = dofs->lower_bound(FieldEntity::getLoBitNumberUId(bit_number));
576 auto hi_it = dofs->upper_bound(FieldEntity::getHiBitNumberUId(bit_number));
577 ents_vec.reserve(std::distance(lo_it, hi_it));
578
579 for (; lo_it != hi_it; ++lo_it) {
580 ents_vec.push_back((*lo_it)->getEnt());
581 }
582
583 std::sort(ents_vec.begin(), ents_vec.end());
584 auto it = std::unique(ents_vec.begin(), ents_vec.end());
585 Range r;
586 r.insert_list(ents_vec.begin(), it);
587 return r;
588};

◆ get_f

auto get_f = [](const double h) { return 4 * W * h * (h * h - 1); }

Double-well potential function.

Parameters
hPhase field value
Returns
Free energy density f(h) = 4W*h*(h²-1)

Double-well potential with minima at h = ±1 (pure phases) and maximum at h = 0 (interface). Controls interface structure.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 312 of file free_surface.cpp.

312{ return 4 * W * h * (h * h - 1); };
double W

◆ get_f_dh

auto get_f_dh = [](const double h) { return 4 * W * (3 * h * h - 1); }

Derivative of double-well potential.

Parameters
hPhase field value
Returns
f'(h) = 4W*(3h²-1)
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 319 of file free_surface.cpp.

319{ return 4 * W * (3 * h * h - 1); };

◆ get_fe_bit

auto get_fe_bit
Initial value:
= [](FEMethod *fe_ptr) {
return fe_ptr->numeredEntFiniteElementPtr->getBitRefLevel();
}
Structure for user loop methods on finite elements.

Get bit reference level from finite element.

Parameters
fe_ptrPointer to finite element method
Returns
Current bit reference level of the element
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 520 of file free_surface.cpp.

520 {
521 return fe_ptr->numeredEntFiniteElementPtr->getBitRefLevel();
522};

◆ get_global_size

auto get_global_size
Initial value:
= [](int l_size) {
int g_size;
MPI_Allreduce(&l_size, &g_size, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
return g_size;
}

Get global size across all processors.

Parameters
l_sizeLocal size on current processor
Returns
Global sum of sizes across all processors
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 529 of file free_surface.cpp.

529 {
530 int g_size;
531 MPI_Allreduce(&l_size, &g_size, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
532 return g_size;
533};

◆ get_M

auto get_M = [](auto h) { return get_M0(h); }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 382 of file free_surface.cpp.

382{ return get_M0(h); };
auto get_M0
Constant mobility function M₀

◆ get_M0

auto get_M0 = [](auto h) { return md; }

Constant mobility function M₀

Parameters
hPhase field value (unused)
Returns
Constant mobility value
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 326 of file free_surface.cpp.

326{ return md; };
double md

◆ get_M0_dh

auto get_M0_dh = [](auto h) { return 0; }

Derivative of constant mobility.

Parameters
hPhase field value (unused)
Returns
Zero (constant mobility)
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 333 of file free_surface.cpp.

333{ return 0; };

◆ get_M2

auto get_M2
Initial value:
= [](auto h) {
return md * (1 - h * h);
}

Degenerate mobility function M₂

Parameters
hPhase field value
Returns
M₂(h) = md*(1-h²)

Mobility that vanishes at pure phases (h = ±1)

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 342 of file free_surface.cpp.

342 {
343 return md * (1 - h * h);
344};

◆ get_M2_dh

auto get_M2_dh = [](auto h) { return -md * 2 * h; }

Derivative of degenerate mobility M₂

Parameters
hPhase field value
Returns
M₂'(h) = -2*md*h
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 351 of file free_surface.cpp.

351{ return -md * 2 * h; };

◆ get_M3

auto get_M3
Initial value:
= [](auto h) {
const double h2 = h * h;
const double h3 = h2 * h;
if (h >= 0)
return md * (2 * h3 - 3 * h2 + 1);
else
return md * (-2 * h3 - 3 * h2 + 1);
}

Non-linear mobility function M₃

Parameters
hPhase field value
Returns
Piecewise cubic mobility function

Smooth mobility function with different behavior for h >= 0 and h < 0

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 360 of file free_surface.cpp.

360 {
361 const double h2 = h * h;
362 const double h3 = h2 * h;
363 if (h >= 0)
364 return md * (2 * h3 - 3 * h2 + 1);
365 else
366 return md * (-2 * h3 - 3 * h2 + 1);
367};

◆ get_M3_dh

auto get_M3_dh
Initial value:
= [](auto h) {
if (h >= 0)
return md * (6 * h * (h - 1));
else
return md * (-6 * h * (h + 1));
}

Derivative of non-linear mobility M₃

Parameters
hPhase field value
Returns
M₃'(h) with sign-dependent cubic behavior
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 374 of file free_surface.cpp.

374 {
375 if (h >= 0)
376 return md * (6 * h * (h - 1));
377 else
378 return md * (-6 * h * (h + 1));
379};

◆ get_M_dh

auto get_M_dh = [](auto h) { return get_M0_dh(h); }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 383 of file free_surface.cpp.

383{ return get_M0_dh(h); };
auto get_M0_dh
Derivative of constant mobility.

◆ get_projection_bit

auto get_projection_bit = []() { return 2 * get_start_bit() + 4; }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 180 of file free_surface.cpp.

180{ return 2 * get_start_bit() + 4; };

◆ get_skin_child_bit

auto get_skin_child_bit = []() { return 2 * get_start_bit() + 3; }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 179 of file free_surface.cpp.

179{ return 2 * get_start_bit() + 3; };

◆ get_skin_parent_bit

auto get_skin_parent_bit = []() { return 2 * get_start_bit() + 2; }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 178 of file free_surface.cpp.

178{ return 2 * get_start_bit() + 2; };

◆ get_skin_projection_bit

auto get_skin_projection_bit = []() { return 2 * get_start_bit() + 5; }
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 181 of file free_surface.cpp.

181{ return 2 * get_start_bit() + 5; };

◆ get_start_bit

auto get_start_bit
Initial value:
= []() {
return nb_levels + 1;
}
int nb_levels
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 172 of file free_surface.cpp.

172 {
173 return nb_levels + 1;
174}; //< first refinement level for computational mesh

◆ h

double h = 0.03
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 195 of file free_surface.cpp.

◆ help

char help[] = "...\n\n"
static

Definition at line 17 of file free_surface.cpp.

◆ I

constexpr IntegrationType I
constexpr
Initial value:
=
IntegrationType::GAUSS

Definition at line 108 of file free_surface.cpp.

◆ i

Definition at line 158 of file free_surface.cpp.

◆ init_h

auto init_h
Initial value:
= [](double r, double y, double theta) {
return capillary_tube(r, y, theta);
}
auto capillary_tube
Capillary tube initialization.

Initialisation function.

Note
If UMs are compiled with Python to initialise phase field "H" surface.py function is used, which has to be present in execution folder.
Examples
mofem/tutorials/vec-4/shallow_wave.cpp, and mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 476 of file free_surface.cpp.

476 {
477#ifdef PYTHON_INIT_SURFACE
478 double s = 1;
479 if (auto ptr = surfacePythonWeakPtr.lock()) {
480 CHK_THROW_MESSAGE(ptr->evalSurface(r, y, theta, eta, s),
481 "error eval python");
482 }
483 return s;
484#else
485 // return bubble_device(r, y, theta);
486 return capillary_tube(r, y, theta);
487 // return kernel_eye(r, y, theta);
488#endif
489};
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.

◆ integration_rule

auto integration_rule = [](int, int, int) { return 2 * order + 1; }

◆ j

Definition at line 159 of file free_surface.cpp.

◆ k

Definition at line 160 of file free_surface.cpp.

◆ kappa

double kappa = (3. / (4. * std::sqrt(2. * W))) * (lambda / eta)
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 209 of file free_surface.cpp.

◆ kernel_eye

auto kernel_eye
Initial value:
= [](double r, double y, double) {
constexpr double y0 = 0.5;
constexpr double R = 0.4;
y -= y0;
const double d = std::sqrt(r * r + y * y);
return tanh((R - d) / (eta * std::sqrt(2)));
}

Eye-shaped interface initialization

Parameters
rRadial coordinate
yVertical coordinate
unusedZ-coordinate (unused in 2D)
Returns
Phase field value (-1 to 1)

Creates circular droplet centered at (0, y0) with radius R

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 433 of file free_surface.cpp.

433 {
434 constexpr double y0 = 0.5;
435 constexpr double R = 0.4;
436 y -= y0;
437 const double d = std::sqrt(r * r + y * y);
438 return tanh((R - d) / (eta * std::sqrt(2)));
439};

◆ kernel_oscillation

auto kernel_oscillation
Initial value:
= [](double r, double y, double) {
constexpr int n = 3;
constexpr double R = 0.0125;
constexpr double A = R * 0.2;
const double theta = atan2(r, y);
const double w = R + A * cos(n * theta);
const double d = std::sqrt(r * r + y * y);
return tanh((w - d) / (eta * std::sqrt(2)));
}
const double n
refractive index of diffusive medium

Oscillating interface initialization.

Parameters
rRadial coordinate
yVertical coordinate
unusedZ-coordinate (unused in 2D)
Returns
Phase field value (-1 to 1)

Creates circular interface with sinusoidal perturbations:

  • Base radius R with amplitude A
  • n-fold symmetry oscillations
  • Uses tanh profile for smooth interface
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 414 of file free_surface.cpp.

414 {
415 constexpr int n = 3;
416 constexpr double R = 0.0125;
417 constexpr double A = R * 0.2;
418 const double theta = atan2(r, y);
419 const double w = R + A * cos(n * theta);
420 const double d = std::sqrt(r * r + y * y);
421 return tanh((w - d) / (eta * std::sqrt(2)));
422};

◆ l

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 161 of file free_surface.cpp.

◆ lambda

double lambda = 73

surface tension

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 191 of file free_surface.cpp.

◆ marker

auto marker = [](auto b) { return BitRefLevel().set(BITREFLEVEL_SIZE - b); }

Create marker bit reference level

Parameters
bBit number from end
Returns
BitRefLevel with bit set from end

Definition at line 513 of file free_surface.cpp.

513{ return BitRefLevel().set(BITREFLEVEL_SIZE - b); };
#define BITREFLEVEL_SIZE
max number of refinements

◆ md

double md = 1e-2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 200 of file free_surface.cpp.

◆ mu_ave

double mu_ave = (mu_p + mu_m) / 2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 206 of file free_surface.cpp.

◆ mu_diff

double mu_diff = (mu_p - mu_m) / 2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 207 of file free_surface.cpp.

◆ mu_m

double mu_m = 0.010101 * 1e2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 188 of file free_surface.cpp.

◆ mu_p

double mu_p = 0.000182 * 1e2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 190 of file free_surface.cpp.

◆ my_max

auto my_max = [](const double x) { return (x - 1 + std::abs(x + 1)) / 2; }

Maximum function with smooth transition.

Parameters
xInput value
Returns
max(x, -1) with smooth transition
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 248 of file free_surface.cpp.

248{ return (x - 1 + std::abs(x + 1)) / 2; };

◆ my_min

auto my_min = [](const double x) { return (x + 1 - std::abs(x - 1)) / 2; }

Minimum function with smooth transition

Parameters
xInput value
Returns
min(x, 1) with smooth transition
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 255 of file free_surface.cpp.

255{ return (x + 1 - std::abs(x - 1)) / 2; };

◆ nb_levels

int nb_levels = 4
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 167 of file free_surface.cpp.

◆ order

int order = 3

approximation order

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 166 of file free_surface.cpp.

◆ phase_function

auto phase_function
Initial value:
= [](const double h, const double diff, const double ave) {
return diff * h + ave;
}

Phase-dependent material property interpolation.

Parameters
hPhase field value (-1 to 1)
diffDifference between phase values (phase_plus - phase_minus)
aveAverage of phase values (phase_plus + phase_minus)/2
Returns
Interpolated material property

Linear interpolation: property = diff * h + ave Used for density and viscosity interpolation between phases

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 288 of file free_surface.cpp.

288 {
289 return diff * h + ave;
290};

◆ refine_overlap

int refine_overlap = 4
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 168 of file free_surface.cpp.

◆ rho_ave

double rho_ave = (rho_p + rho_m) / 2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 204 of file free_surface.cpp.

◆ rho_diff

double rho_diff = (rho_p - rho_m) / 2
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 205 of file free_surface.cpp.

◆ rho_m

double rho_m = 0.998
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 187 of file free_surface.cpp.

◆ rho_p

double rho_p = 0.0012
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 189 of file free_surface.cpp.

◆ save_range

auto save_range
Initial value:
= [](moab::Interface &moab, const std::string name,
const Range r) {
if (get_global_size(r.size())) {
auto out_meshset = get_temp_meshset_ptr(moab);
CHKERR moab.add_entities(*out_meshset, r);
CHKERR moab.write_file(name.c_str(), "MOAB", "PARALLEL=WRITE_PART",
out_meshset->get_ptr(), 1);
}
}
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
auto get_global_size
Get global size across all processors.
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.

Save range of entities to file.

Parameters
moabMOAB interface for mesh operations
nameOutput filename
rRange of entities to save
Returns
MoFEMErrorCode Success/failure code

Saves entities to HDF5 file if range is non-empty globally

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 544 of file free_surface.cpp.

545 {
547 if (get_global_size(r.size())) {
548 auto out_meshset = get_temp_meshset_ptr(moab);
549 CHKERR moab.add_entities(*out_meshset, r);
550 CHKERR moab.write_file(name.c_str(), "MOAB", "PARALLEL=WRITE_PART",
551 out_meshset->get_ptr(), 1);
552 }
554};

◆ SPACE_DIM

constexpr int SPACE_DIM = 2
constexpr
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 104 of file free_surface.cpp.

◆ t_kd

constexpr auto t_kd = FTensor::Kronecker_Delta_symmetric<int>()
constexpr

◆ tol

double tol = std::numeric_limits<float>::epsilon()

Definition at line 202 of file free_surface.cpp.

◆ tsPrePostProc

boost::weak_ptr<TSPrePostProc> tsPrePostProc
static

◆ U_FIELD_DIM

constexpr int U_FIELD_DIM = SPACE_DIM
constexpr
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 105 of file free_surface.cpp.

◆ W

double W = 0.25
Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 192 of file free_surface.cpp.

◆ wetting_angle

auto wetting_angle = [](double water_level) { return water_level; }

Wetting angle function (placeholder)

Parameters
water_levelCurrent water level
Returns
Wetting angle value

Currently returns input value directly. Can be modified to implement complex wetting angle dependencies on interface position or time.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 499 of file free_surface.cpp.

499{ return water_level; };

◆ wetting_angle_sub_stepping

auto wetting_angle_sub_stepping
Initial value:
= [](auto ts_step) {
constexpr int sub_stepping = 16;
return std::min(1., static_cast<double>(ts_step) / sub_stepping);
}

Wetting angle sub-stepping for gradual application.

Parameters
ts_stepCurrent time step number
Returns
Scaling factor [0,1] for gradual wetting angle application

Gradually applies wetting angle boundary condition over first 16 steps to avoid sudden changes that could destabilize the solution.

Examples
mofem/tutorials/vec-5/free_surface.cpp.

Definition at line 236 of file free_surface.cpp.

236 {
237 constexpr int sub_stepping = 16;
238 return std::min(1., static_cast<double>(ts_step) / sub_stepping);
239};