Skip to content

Commit

Permalink
mobility works (mat. interac to 0 im prm!!)
Browse files Browse the repository at this point in the history
Former-commit-id: d600933
  • Loading branch information
PierreLaurentinCS committed Dec 18, 2023
1 parent e24dc4d commit 0740317
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 123 deletions.
30 changes: 15 additions & 15 deletions include/core/mobility_cahn_hilliard_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class MobilityCahnHilliardModel : public InterfacePropertyModel
virtual double
get_mobility_constant() = 0;

// /**
// * @brief Definition of a virtual destructor
// */
// virtual ~MobilityCahnHilliardModel() = default;
/**
* @brief Definition of a virtual destructor
*/
virtual ~MobilityCahnHilliardModel() = default;
};

/**
Expand All @@ -77,10 +77,10 @@ class MobilityCahnHilliardModelConstant : public MobilityCahnHilliardModel
: mobility_cahn_hilliard_constant(p_mobility_cahn_hilliard_constant)
{}

// /**
// * @brief Destructor of derived class
// */
// ~MobilityCahnHilliardModelConstant() = default;
/**
* @brief Destructor of derived class
*/
~MobilityCahnHilliardModelConstant() = default;


/**
Expand Down Expand Up @@ -182,10 +182,10 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
this->model_depends_on[field::phase_order_cahn_hilliard_filtered] = true;
}

// /**
// * @brief Destructor of derived class
// */
// ~MobilityCahnHilliardModelQuartic() = default;
/**
* @brief Destructor of derived class
*/
~MobilityCahnHilliardModelQuartic() = default;

/**
* @brief Method to get the model used for the mobility
Expand Down Expand Up @@ -225,7 +225,7 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
// return mobility_cahn_hilliard_constant *
// (1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard) *
// (1 - phase_order_cahn_hilliard * phase_order_cahn_hilliard);
std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered<<std::endl;
//std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered<<std::endl;
if (std::abs(phase_order_cahn_hilliard_filtered) > 1)
return 0.0;
else
Expand Down Expand Up @@ -260,7 +260,7 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel
field_vectors.at(field::phase_order_cahn_hilliard_filtered);
for (unsigned int i = 0; i < property_vector.size(); ++i)
{
std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered[i]<<std::endl;
//std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered[i]<<std::endl;
if (std::abs(phase_order_cahn_hilliard_filtered[i]) > 1)
property_vector[i] = 0.0;
else
Expand Down Expand Up @@ -292,7 +292,7 @@ class MobilityCahnHilliardModelQuartic : public MobilityCahnHilliardModel

const double &phase_order_cahn_hilliard_filtered =
fields_value.at(field::phase_order_cahn_hilliard_filtered);
std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered<<std::endl;
//std::cout<<"phase order value in filter = "<<phase_order_cahn_hilliard_filtered<<std::endl;
if (std::abs(phase_order_cahn_hilliard_filtered) > 1)
return 0.0;
else
Expand Down
8 changes: 4 additions & 4 deletions source/core/mobility_cahn_hilliard_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ MobilityCahnHilliardModel::model_cast(
if (material_interaction_parameters.mobility_cahn_hilliard_model ==
Parameters::MaterialInteractions::MobilityCahnHilliardModel::quartic)
{
std::cout<<"Mobility sent to mobility quartic model = "<<material_interaction_parameters.mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant<<std::endl;
// std::cout<<"Mobility sent to mobility quartic model = "<<material_interaction_parameters.mobility_cahn_hilliard_parameters
// .mobility_cahn_hilliard_constant<<std::endl;
return std::make_shared<MobilityCahnHilliardModelQuartic>(
material_interaction_parameters.mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant);
}
else
{
std::cout<<"Mobility sent to mobility constant model = "<<material_interaction_parameters.mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant<<std::endl;
// std::cout<<"Mobility sent to mobility constant model = "<<material_interaction_parameters.mobility_cahn_hilliard_parameters
// .mobility_cahn_hilliard_constant<<std::endl;
return std::make_shared<MobilityCahnHilliardModelConstant>(
material_interaction_parameters.mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant);
Expand Down
120 changes: 60 additions & 60 deletions source/core/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ namespace Parameters
void
MobilityCahnHilliardParameters::parse_parameters(ParameterHandler &prm)
{
std::cout<<"parsing mobility constant"<<std::endl;
// std::cout<<"parsing mobility constant"<<std::endl;
mobility_cahn_hilliard_constant = prm.get_double("cahn hilliard mobility constant");
std::cout<< "mobility constant for mobility model (chns) = " << mobility_cahn_hilliard_constant<<std::endl;
//std::cout<< "mobility constant for mobility model (chns) = " << mobility_cahn_hilliard_constant<<std::endl;
}


Expand Down Expand Up @@ -1087,6 +1087,16 @@ namespace Parameters
"Model used for the calculation of the surface tension coefficient\n"
"The choices are <constant|linear|phase change>.");
surface_tension_parameters.declare_parameters(prm);

// Cahn-Hilliard mobility
prm.declare_entry(
"cahn hilliard mobility model",
"constant",
Patterns::Selection("constant|quartic"),
"Model used for the calculation of the mobility in the Cahn-Hilliard equations"
"\n"
"The choices are <constant|quartic>.");
mobility_cahn_hilliard_parameters.declare_parameters(prm);
}
prm.leave_subsection();
}
Expand All @@ -1112,66 +1122,56 @@ namespace Parameters
if (material_interaction_type == MaterialInteractionsType::fluid_fluid)
{
prm.enter_subsection("fluid-fluid interaction");
std::pair<unsigned int, unsigned int> fluid_fluid_interaction;
fluid_fluid_interaction.first = prm.get_integer("first fluid id");
fluid_fluid_interaction.second = prm.get_integer("second fluid id");
AssertThrow(fluid_fluid_interaction.first <=
fluid_fluid_interaction.second,
OrderOfFluidIDsError(fluid_fluid_interaction.first,
fluid_fluid_interaction.second));
fluid_fluid_interaction_with_material_interaction_id.first =
fluid_fluid_interaction;
fluid_fluid_interaction_with_material_interaction_id.second = id;

// Surface tension
op = prm.get("surface tension model");
std::cout<<op<<std::endl;
if (op == "constant")
{
surface_tension_model = SurfaceTensionModel::constant;
surface_tension_parameters.parse_parameters(prm);
//std::cout<<"entering fluid-fluid interaction subsection"<<std::endl;
std::pair<unsigned int, unsigned int> fluid_fluid_interaction;
fluid_fluid_interaction.first = prm.get_integer("first fluid id");
fluid_fluid_interaction.second = prm.get_integer("second fluid id");
AssertThrow(fluid_fluid_interaction.first <=
fluid_fluid_interaction.second,
OrderOfFluidIDsError(fluid_fluid_interaction.first,
fluid_fluid_interaction.second));
fluid_fluid_interaction_with_material_interaction_id.first =
fluid_fluid_interaction;
fluid_fluid_interaction_with_material_interaction_id.second = id;

// Surface tension
op = prm.get("surface tension model");
if (op == "constant") {
surface_tension_model = SurfaceTensionModel::constant;
surface_tension_parameters.parse_parameters(prm);
} else if (op == "linear") {
surface_tension_model = SurfaceTensionModel::linear;
surface_tension_parameters.parse_parameters(prm);
} else if (op == "phase change") {
surface_tension_model = SurfaceTensionModel::phase_change;
surface_tension_parameters.parse_parameters(prm);
} else
throw (std::runtime_error(
"Invalid surface tension model. The choices are <constant|linear|phase change>."));


// Cahn-Hilliard mobility
op = prm.get("cahn hilliard mobility model");
if (op == "constant") {
mobility_cahn_hilliard_model =
MobilityCahnHilliardModel::constant;
mobility_cahn_hilliard_parameters.parse_parameters(prm);
// std::cout << "mobility is constant and equal to "
// << mobility_cahn_hilliard_parameters
// .mobility_cahn_hilliard_constant
// << std::endl;
} else if (op == "quartic") {
mobility_cahn_hilliard_model = MobilityCahnHilliardModel::quartic;
mobility_cahn_hilliard_parameters.parse_parameters(prm);
// std::cout << "mobility is quartic and its constant equal to "
// << mobility_cahn_hilliard_parameters
// .mobility_cahn_hilliard_constant
// << std::endl;
} else
throw (std::runtime_error(
"Invalid mobility model. The choices are <constant|quartic>."));
}
else if (op == "linear")
{
surface_tension_model = SurfaceTensionModel::linear;
surface_tension_parameters.parse_parameters(prm);
}
else if (op == "phase change")
{
surface_tension_model = SurfaceTensionModel::phase_change;
surface_tension_parameters.parse_parameters(prm);
}
else
throw(std::runtime_error(
"Invalid surface tension model. The choices are <constant|linear|phase change>."));


// Cahn-Hilliard mobility
op = prm.get("cahn hilliard mobility model");
std::cout<<op<<std::endl;
if (op == "constant")
{
mobility_cahn_hilliard_model =
MobilityCahnHilliardModel::constant;
mobility_cahn_hilliard_parameters.parse_parameters(prm);
std::cout << "mobility is constant and equal to "
<< mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant
<< std::endl;
}
else if (op == "quartic")
{
mobility_cahn_hilliard_model = MobilityCahnHilliardModel::quartic;
mobility_cahn_hilliard_parameters.parse_parameters(prm);
std::cout << "mobility is quartic and its constant equal to "
<< mobility_cahn_hilliard_parameters
.mobility_cahn_hilliard_constant
<< std::endl;
}
else
throw(std::runtime_error(
"Invalid mobility model. The choices are <constant|quartic>."));

prm.leave_subsection();
}
else // Solid-fluid interactions
Expand Down
8 changes: 4 additions & 4 deletions source/core/parameters_multiphysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,21 +647,21 @@ Parameters::CahnHilliard::parse_parameters(ParameterHandler &prm)
if (op_mobility == "constant")
{
cahn_hilliard_mobility_model = CahnHilliardMobilityModel::constant;
std::cout<<"mobility is constant (ch)"<<std::endl;
//std::cout<<"mobility is constant (ch)"<<std::endl;
}
else if (op_mobility == "quartic")
{
cahn_hilliard_mobility_model = CahnHilliardMobilityModel::quartic;
std::cout<<"mobility is quartic (ch)"<<std::endl;
//std::cout<<"mobility is quartic (ch)"<<std::endl;
}
else
throw(std::runtime_error("Invalid mobility model. "
"Options are 'constant' or 'quartic'."));

cahn_hilliard_mobility_constant = prm.get_double("mobility constant");

std::cout << "mobility = " << cahn_hilliard_mobility_constant
<< std::endl;
// std::cout << "mobility = " << cahn_hilliard_mobility_constant
// << std::endl;
}

prm.leave_subsection();
Expand Down
2 changes: 1 addition & 1 deletion source/solvers/cahn_hilliard_assemblers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CahnHilliardAssemblerCore<dim>::assemble_matrix(
this->cahn_hilliard_parameters.cahn_hilliard_mobility_constant;
const auto mobility_model =
this->cahn_hilliard_parameters.cahn_hilliard_mobility_model;
std::cout<< "mobility via ch assembler = "<< mobility_constant<<std::endl;
// std::cout<< "mobility via ch assembler = "<< mobility_constant<<std::endl;
const double epsilon = scratch_data.epsilon;
const double cell_size = scratch_data.cell_size;
const double xi =
Expand Down
80 changes: 41 additions & 39 deletions source/solvers/navier_stokes_scratch_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ NavierStokesScratchData<dim>::calculate_physical_properties()
}
else if (gather_cahn_hilliard && !gather_vof)
{
/* std::cout<< "Computing properties for Cahn-Hilliard"
<<std::endl;*/
//std::cout<< "Computing properties for Cahn-Hilliard"
//<<std::endl;
// Blend the physical properties using the CahnHilliard field
for (unsigned int q = 0; q < this->n_q_points; ++q)
{
Expand All @@ -556,49 +556,49 @@ NavierStokesScratchData<dim>::calculate_physical_properties()
/* std::cout << "density_diff = " << density_diff <<
std::endl;*/

double phase_order_cahn_hilliard_value=
this->phase_order_cahn_hilliard_values[q];
//double phase_order_cahn_hilliard_value =
// this->filtered_phase_order_cahn_hilliard_values[q];
// double phase_order_cahn_hilliard_value=
// this->phase_order_cahn_hilliard_values[q];
double phase_order_cahn_hilliard_value =
this->filtered_phase_order_cahn_hilliard_values[q];



/* std::cout<<"phase value = "
<<phase_order_cahn_hilliard_value_old<<std::endl;
std::cout<<"phase value filtered = "
<<phase_order_cahn_hilliard_value<<std::endl;
std::cout<<"density 0 = "
<<density_0[q]<<std::endl;
std::cout<<"density 1 = "
<<density_1[q]<<std::endl;
std::cout<<"expected density at point q ="<<
// std::cout<<"phase value = "
// <<phase_order_cahn_hilliard_value_old<<std::endl;
// std::cout<<"phase value filtered = "
// <<phase_order_cahn_hilliard_value<<std::endl;
// std::cout<<"density 0 = "
// <<density_0[q]<<std::endl;
// std::cout<<"density 1 = "
// <<density_1[q]<<std::endl;
// std::cout<<"expected density at point q ="<<
//
// 0.5*density_0[q]*(phase_order_cahn_hilliard_value+1)
// -0.5*density_1[q]*(phase_order_cahn_hilliard_value-1)<<std::endl;

0.5*density_0[q]*(phase_order_cahn_hilliard_value+1)
-0.5*density_1[q]*(phase_order_cahn_hilliard_value-1)<<std::endl;
*/
density[q] = calculate_point_property_cahn_hilliard(
phase_order_cahn_hilliard_value,
this->density_0[q],
this->density_1[q]);


/* std::cout<<"computed density at point q ="<< density[q]<<std::endl;
// std::cout<<"computed density at point q ="<< density[q]<<std::endl;
//
//
// std::cout<<"mu 0 = "
// <<dynamic_viscosity_0[q]<<std::endl;
// std::cout<<"mu 1 = "
// <<dynamic_viscosity_1[q]<<std::endl;
// std::cout<<"expected mu at point q = "<<
// 0.5*dynamic_viscosity_0[q]*(phase_order_cahn_hilliard_value+1)
// -0.5*dynamic_viscosity_1[q]*(phase_order_cahn_hilliard_value-1)<<std::endl;

std::cout<<"mu 0 = "
<<dynamic_viscosity_0[q]<<std::endl;
std::cout<<"mu 1 = "
<<dynamic_viscosity_1[q]<<std::endl;
std::cout<<"expected mu at point q = "<<
0.5*dynamic_viscosity_0[q]*(phase_order_cahn_hilliard_value+1)
-0.5*dynamic_viscosity_1[q]*(phase_order_cahn_hilliard_value-1)<<std::endl;
*/
dynamic_viscosity[q] = calculate_point_property_cahn_hilliard(
phase_order_cahn_hilliard_value,
this->dynamic_viscosity_0[q],
this->dynamic_viscosity_1[q]);

//::cout<<"computed mu at point q = "<<dynamic_viscosity[q]<<std::endl;
// std::cout<<"computed mu at point q = "<<dynamic_viscosity[q]<<std::endl;

// Gather surface tension
const auto material_interaction_id =
Expand All @@ -609,18 +609,20 @@ NavierStokesScratchData<dim>::calculate_physical_properties()
const auto mobility_cahn_hilliard_model =
properties_manager.get_mobility_cahn_hilliard(
material_interaction_id);
/* std::cout << "get mobility is ok "<<
std::endl;*/
// std::cout << "get mobility is ok "<<
// std::endl;
mobility_cahn_hilliard_model->vector_value(
fields, mobility_cahn_hilliard);
/* std::cout << "vector_value is ok "<<
std::endl;
std::cout << "material interaction for mobility is ok "<< std::endl;
std::cout << "mobility_via_ns_scratch_data = "
<< mobility_cahn_hilliard[q] <<
std::endl;*/
//std::cout<<"phase order cahn hilliard field"<<fields[field::phase_order_cahn_hilliard][q]<<std::endl;
//std::cout<<" filtered phase order cahn hilliard field"<<fields[field::phase_order_cahn_hilliard_filtered][q]<<std::endl;
// std::cout << "vector_value is ok "<<
// std::endl;
//
// std::cout << "material interaction for mobility is ok "<< std::endl;
//
// std::cout << "mobility_via_ns_scratch_data = "
// << mobility_cahn_hilliard[q] <<
// std::endl;
}
break;
}
Expand Down

0 comments on commit 0740317

Please sign in to comment.