Line data Source code
1 : //
2 : // This implements a basic two-phase field model with Cahn-Hilliard kinetics.
3 : //
4 : // The free energy is
5 : //
6 : // .. math::
7 : //
8 : // F[\eta] = \int_\Omega \Big[\frac{1}{4}(\eta^2 - 1)^2 +
9 : // \frac{1}{2}\gamma |\nabla\eta|^2\Big] d\mathbf{x}
10 : //
11 : // The corresponding governing equation under conservative kinetics is
12 : //
13 : // .. math::
14 : //
15 : // \frac{\partial\eta}{\partial t} = L\nabla^2\Big(\eta^3 - \eta - \gamma\nabla^2\eta\Big)
16 : //
17 : // which is integrated using a forward Euler scheme.
18 : //
19 : // This is tested in :ref:`CahnHilliard`
20 :
21 : #ifndef INTEGRATOR_CAHNHILLIARD_H
22 : #define INTEGRATOR_CAHNHILLIARD_H
23 :
24 : #include <iostream>
25 : #include <fstream>
26 : #include <iomanip>
27 :
28 : #include "AMReX.H"
29 : #include "AMReX_ParmParse.H"
30 : #include "AMReX_ParallelDescriptor.H"
31 : #include <AMReX_MLMG.H>
32 :
33 : #include "IC/Random.H"
34 : #include "Integrator/Integrator.H"
35 : #include "BC/Nothing.H"
36 :
37 : namespace Integrator
38 : {
39 :
40 : class CahnHilliard : public Integrator
41 : {
42 : public:
43 :
44 : /// Basic constructor (don't use)
45 : CahnHilliard();
46 :
47 : /// Destroy pointers defined in Parse
48 : ~CahnHilliard();
49 :
50 : /// Use this constructor
51 1 : CahnHilliard(IO::ParmParse& pp) : CahnHilliard()
52 1 : { Parse(*this, pp); }
53 :
54 : /// Scan input values and initialize fields
55 : static void Parse(CahnHilliard& value, IO::ParmParse& pp);
56 :
57 : protected:
58 :
59 : /// Set values in fields
60 : void Initialize (int lev) override;
61 : /// Integrate eta over one timestep on lev
62 : void Advance (int lev, Set::Scalar time, Set::Scalar dt) override;
63 : /// Mark any cells that need to be refined
64 : void TagCellsForRefinement (int lev, amrex::TagBoxArray& tags, amrex::Real time, int ngrow) override;
65 :
66 : private:
67 :
68 : Set::Field<Set::Scalar> etanew_mf; /// The new value for eta this timestep
69 : Set::Field<Set::Scalar> etaold_mf; /// Last timestep's value for eta
70 : Set::Field<Set::Scalar> intermediate; /// Intermediate field used for CH kinetics
71 :
72 : BC::BC<Set::Scalar> *bc; /// eta's bc object
73 : IC::IC<Set::Scalar> *ic; /// eta's ic object
74 :
75 : Set::Scalar gamma = NAN;
76 : Set::Scalar L = NAN;
77 : Set::Scalar refinement_threshold = NAN;
78 :
79 : };
80 : }
81 : #endif
|