Skip to content

Commit

Permalink
filtration, W: mobility constant to 1e-7
Browse files Browse the repository at this point in the history
Former-commit-id: 63d109e
  • Loading branch information
PierreLaurentinCS committed Dec 18, 2023
1 parent 6ecf9fc commit b50832e
Show file tree
Hide file tree
Showing 19 changed files with 679 additions and 125 deletions.
1 change: 1 addition & 0 deletions include/core/interface_property_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class InterfacePropertyModel
model_depends_on[previous_temperature] = false;
model_depends_on[pressure] = false;
model_depends_on[phase_order_cahn_hilliard] = false;
model_depends_on[phase_order_cahn_hilliard_filtered] = false;
}

/**
Expand Down
108 changes: 74 additions & 34 deletions include/core/mobility_cahn_hilliard_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
, model(CahnHilliardMobilityModel::quartic)
{
this->model_depends_on[field::phase_order_cahn_hilliard] = true;
this->model_depends_on[field::phase_order_cahn_hilliard_filtered] = true;
}

/**
Expand Down Expand Up @@ -214,14 +215,22 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
double
value(const std::map<field, double> &fields_value) override
{
const double &phase_order_cahn_hilliard =
fields_value.at(field::phase_order_cahn_hilliard);
if (std::abs(phase_order_cahn_hilliard) > 1)
return 0.0;
else
return mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard) *
(1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard);
// const double &phase_order_cahn_hilliard =
// fields_value.at(field::phase_order_cahn_hilliard);
const double &phase_order_cahn_hilliard_filtered =
fields_value.at(field::phase_order_cahn_hilliard_filtered);
// if (std::abs(phase_order_cahn_hilliard) > 1)
// return 0.0;
// else
// return mobility_cahn_hilliard_constant *
// (1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard) *
// (1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard);
if (std::abs(phase_order_cahn_hilliard_filtered) > 1)
return 0.0;
else
return mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard_filtered * phase_order_cahn_hilliard_filtered) *
(1 - phase_order_cahn_hilliard_filtered * phase_order_cahn_hilliard_filtered);
}

/**
Expand All @@ -233,17 +242,30 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
vector_value(const std::map<field, std::vector<double>> &field_vectors,
std::vector<double> &property_vector) override
{
const std::vector<double> &phase_order_cahn_hilliard =
field_vectors.at(field::phase_order_cahn_hilliard);
for (unsigned int i = 0; i < property_vector.size(); ++i)
// const std::vector<double> &phase_order_cahn_hilliard =
// field_vectors.at(field::phase_order_cahn_hilliard);
// for (unsigned int i = 0; i < property_vector.size(); ++i)
// {
// if (std::abs(phase_order_cahn_hilliard[i]) > 1)
// property_vector[i] = 0.0;
// else
// property_vector[i] =
// mobility_cahn_hilliard_constant *
// (1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]) *
// (1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]);
// }

const std::vector<double> &phase_order_cahn_hilliard_filtered =
field_vectors.at(field::phase_order_cahn_hilliard_filtered);
for (unsigned int i = 0; i < property_vector.size(); ++i)
{
if (std::abs(phase_order_cahn_hilliard[i]) > 1)
property_vector[i] = 0.0;
else
property_vector[i] =
mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]) *
(1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]);
if (std::abs(phase_order_cahn_hilliard_filtered[i]) > 1)
property_vector[i] = 0.0;
else
property_vector[i] =
mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard_filtered[i] * phase_order_cahn_hilliard_filtered[i]) *
(1 - phase_order_cahn_hilliard_filtered[i] * phase_order_cahn_hilliard_filtered[i]);
}
}

Expand All @@ -258,13 +280,21 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
double
jacobian(const std::map<field, double> &fields_value, field /*id*/) override
{
const double &phase_order_cahn_hilliard =
fields_value.at(field::phase_order_cahn_hilliard);
if (std::abs(phase_order_cahn_hilliard) > 1)
return 0.0;
else
return -4 * phase_order_cahn_hilliard * mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard);
// const double &phase_order_cahn_hilliard =
// fields_value.at(field::phase_order_cahn_hilliard);
// if (std::abs(phase_order_cahn_hilliard) > 1)
// return 0.0;
// else
// return -4 * phase_order_cahn_hilliard * mobility_cahn_hilliard_constant *
// (1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard);

const double &phase_order_cahn_hilliard_filtered =
fields_value.at(field::phase_order_cahn_hilliard_filtered);
if (std::abs(phase_order_cahn_hilliard_filtered) > 1)
return 0.0;
else
return -4 * phase_order_cahn_hilliard_filtered * mobility_cahn_hilliard_constant *
(1 - phase_order_cahn_hilliard_filtered * phase_order_cahn_hilliard_filtered);
}

/**
Expand All @@ -279,15 +309,25 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
const field /*id*/,
std::vector<double> &jacobian_vector) override
{
const std::vector<double> &phase_order_cahn_hilliard =
field_vectors.at(field::phase_order_cahn_hilliard);
for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
if (std::abs(phase_order_cahn_hilliard[i]) > 1)
jacobian_vector[i] = 0.0;
else
jacobian_vector[i] =
-mobility_cahn_hilliard_constant * 4 * phase_order_cahn_hilliard[i] *
(1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]);
// const std::vector<double> &phase_order_cahn_hilliard =
// field_vectors.at(field::phase_order_cahn_hilliard);
// for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
// if (std::abs(phase_order_cahn_hilliard[i]) > 1)
// jacobian_vector[i] = 0.0;
// else
// jacobian_vector[i] =
// -mobility_cahn_hilliard_constant * 4 * phase_order_cahn_hilliard[i] *
// (1 - phase_order_cahn_hilliard[i] * phase_order_cahn_hilliard[i]);

const std::vector<double> &phase_order_cahn_hilliard_filtered =
field_vectors.at(field::phase_order_cahn_hilliard_filtered);
for (unsigned int i = 0; i < jacobian_vector.size(); ++i)
if (std::abs(phase_order_cahn_hilliard_filtered[i]) > 1)
jacobian_vector[i] = 0.0;
else
jacobian_vector[i] =
-mobility_cahn_hilliard_constant * 4 * phase_order_cahn_hilliard_filtered[i] *
(1 - phase_order_cahn_hilliard_filtered[i] * phase_order_cahn_hilliard_filtered[i]);
}

private:
Expand Down
23 changes: 23 additions & 0 deletions include/core/parameters_multiphysics.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ namespace Parameters
quartic
};

/**
* @brief CahnHilliard_PhaseFilter - Defines the parameters for the phase filtration of CahnHilliard physics
*/
struct CahnHilliard_PhaseFilter
{
// Type of filter
Parameters::FilterType type;

// $$\beta$$ value for the tanh filter
double beta;

// Type of verbosity for the phase filter
Parameters::Verbosity verbosity;

void
declare_parameters(ParameterHandler &prm);
void
parse_parameters(ParameterHandler &prm);
};

/**
* @brief Defines the sub-parameters for free surface mass conservation.
* Has to be declared before member creation in VOF structure.
Expand Down Expand Up @@ -231,6 +251,9 @@ namespace Parameters
// Mobility constant
double cahn_hilliard_mobility_constant;

// Phase filtration parameters
Parameters::CahnHilliard_PhaseFilter cahn_hilliard_phase_filter;

void
declare_parameters(ParameterHandler &prm);
void
Expand Down
3 changes: 2 additions & 1 deletion include/core/physical_property_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ enum field : int
temperature,
previous_temperature,
pressure,
phase_order_cahn_hilliard
phase_order_cahn_hilliard,
phase_order_cahn_hilliard_filtered
};

inline void
Expand Down
17 changes: 17 additions & 0 deletions include/solvers/cahn_hilliard.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <solvers/auxiliary_physics.h>
#include <solvers/cahn_hilliard_assemblers.h>
#include <solvers/cahn_hilliard_filter.h>
#include <solvers/cahn_hilliard_scratch_data.h>
#include <solvers/multiphysics_interface.h>

Expand Down Expand Up @@ -179,6 +180,12 @@ class CahnHilliard : public AuxiliaryPhysics<dim, TrilinosWrappers::MPI::Vector>
void
percolate_time_vectors() override;

/**
* @brief Carry out modifications on the auxiliary physic solution.
*/
void
modify_solution() override;

/**
* @brief Postprocess the auxiliary physics results. Post-processing this case implies
* the calculation of all derived quantities using the solution vector of the
Expand Down Expand Up @@ -408,6 +415,12 @@ class CahnHilliard : public AuxiliaryPhysics<dim, TrilinosWrappers::MPI::Vector>
calculate_barycenter(const TrilinosWrappers::MPI::Vector &solution,
const VectorType &current_solution_fd);

/**
* @brief Applies filter on phase fraction values.
*/
void
apply_phase_filter();


MultiphysicsInterface<dim> *multiphysics;

Expand Down Expand Up @@ -443,6 +456,7 @@ class CahnHilliard : public AuxiliaryPhysics<dim, TrilinosWrappers::MPI::Vector>
AffineConstraints<double> nonzero_constraints;
AffineConstraints<double> zero_constraints;
TrilinosWrappers::SparseMatrix system_matrix;
TrilinosWrappers::MPI::Vector filtered_solution;


// Previous solutions vectors
Expand All @@ -464,6 +478,9 @@ class CahnHilliard : public AuxiliaryPhysics<dim, TrilinosWrappers::MPI::Vector>

// Phase statistics table
TableHandler statistics_table;

// Phase fraction filter
std::shared_ptr<CahnHilliardFilterBase> filter;
};


Expand Down
111 changes: 111 additions & 0 deletions include/solvers/cahn_hilliard_filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* ---------------------------------------------------------------------
*
* Copyright (C) 2019 - by the Lethe authors
*
* This file is part of the Lethe library
*
* The Lethe library is free software; you can use it, redistribute
* it, and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* The full text of the license can be found in the file LICENSE at
* the top level of the Lethe distribution.
*
* ---------------------------------------------------------------------
*/

#ifndef lethe_cahn_hilliard_filter_h
#define lethe_cahn_hilliard_filter_h


#include <core/parameters_multiphysics.h>

/**
* @brief CahnHilliardFilterBase class allows phase fraction filtering
*/
class CahnHilliardFilterBase
{
public:
CahnHilliardFilterBase()
{}

/**
* @brief Instantiates and returns a pointer to a CahnHilliardFilterBase
* object by casting it to the proper child class
*
* @param phase_filter_parameters CahnHilliard model parameters
*/
static std::shared_ptr<CahnHilliardFilterBase>
model_cast(const Parameters::CahnHilliard &cahn_hilliard_parameters);

/**
* @brief filter_phase calculates the value of the filtered phase fraction
* @param unfiltered_phase Value of the phase fraction before applying the filter
* @return Value of the phase fraction after applying the filter
*/
virtual double
filter_phase(const double &unfiltered_phase) = 0;
};

/**
* @brief CahnHilliardNoFilter class is used as a default when no
* filter is applied to the phase fraction
*/
class CahnHilliardNoFilter : public CahnHilliardFilterBase
{
public:
CahnHilliardNoFilter()
{}

/**
* @brief filter_phase calculates the value of the filtered phase fraction
* @param unfiltered_phase Value of the phase fraction before applying the filter
* @return unfiltered_phase
*/
virtual double
filter_phase(const double &unfiltered_phase) override
{
return unfiltered_phase;
}
};

/**
* @brief CahnHilliardTanhFilter class is used to calculate
* a filtered phase for Cahn-Hilliard simulations. The filtered phase is defined
* as
* $$\phi_f = \tanh(\beta(\phi-0.5)) $$.
*/
class CahnHilliardTanhFilter : public CahnHilliardFilterBase
{
public:
CahnHilliardTanhFilter(const double beta,
const double well_height,
const double epsilon)
: beta(beta)
, well_height(well_height)
, epsilon(epsilon)
{}

/**
* @brief filter_phase calculates the value of the filtered phase fraction
* @param unfiltered_phase Value of the phase fraction before applying the filter
* @return Value of the phase fraction after applying the tanh filter
*/
virtual double
filter_phase(const double &unfiltered_phase) override
{
// return tanh((std::sqrt(2*well_height)/(epsilon)) * unfiltered_phase);
// return tanh(beta * sgn(unfiltered_phase)*std::sqrt(std::abs(unfiltered_phase)));
//std::cout<<"Filtered value computed = " << tanh(beta*unfiltered_phase)<< std::endl;
return tanh(beta * unfiltered_phase);
//return tanh(beta * sgn(unfiltered_phase)*unfiltered_phase*unfiltered_phase);
}

private:
// User-defined parameter that influences the definition of the interface
const double beta;
const double well_height;
const double epsilon;
};

#endif
11 changes: 8 additions & 3 deletions include/solvers/multiphysics_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class MultiphysicsInterface
}

/**
* @brief Request the present filtered solution of a given physics (used in VOF physics for STF calculation)
* @brief Request the present filtered solution of a given physics (used in VOF or CahnHilliard physics for STF calculation)
*
* @param physics_id The physics of the solution being requested
*/
Expand All @@ -455,6 +455,11 @@ class MultiphysicsInterface
active_physics.end(),
physics_id) != active_physics.end()),
ExcInternalError());
/* for (const double filtered_phase : *physics_filtered_solutions[physics_id])
{
this->pcout << "filtered phase sent by multiphysics interface" << std::endl;
this->pcout << filtered_phase << std::endl;
}*/
return physics_filtered_solutions[physics_id];
}

Expand Down Expand Up @@ -642,12 +647,12 @@ class MultiphysicsInterface
}

/**
* @brief Sets the reference to the filtered solution of the physics in the multiphysics interface (used in VOF physics for STF calculation)
* @brief Sets the reference to the filtered solution of the physics in the multiphysics interface (used in VOF or CahnHilliard physics for STF calculation)
*
* @param physics_id The physics of the DOF handler being requested
*
* @param filtered_solution_vector The reference to the filtered solution vector of the physics; this was
* specifically implemented for VOF
* implemented for VOF and CahnHilliard physics
*/
void
set_filtered_solution(const PhysicsID physics_id,
Expand Down
Loading

0 comments on commit b50832e

Please sign in to comment.