Alamo
PFC.cpp
Go to the documentation of this file.
1#include <AMReX_MLPoisson.H>
2
3#ifdef ALAMO_FFT
4#include <AMReX_FFT.H>
5#endif
6
7
8#include "PFC.H"
9#include "BC/Constant.H"
10#include "IO/ParmParse.H"
11#include "IC/Random.H"
12#include "Set/Set.H"
14
15namespace Integrator
16{
18{
19}
21{
22 delete ic;
23 delete bc;
24}
25
26void PFC::Parse(PFC &value, IO::ParmParse &pp)
27{
28 // frequency term
29 pp.query_required("q0",value.q0);
30 // chemical potential width
31 pp.query_required("eps", value.eps);
32
33 // initial condition for :math:`\eta`
34 pp.select_default<IC::Random>("eta.ic", value.ic, value.geom);
35 // boundary condition for :math:`\eta`
36 pp.select_default<BC::Constant>("eta.bc", value.bc, 1);
37
38 value.RegisterNewFab(value.eta_mf, value.bc, 1, 1, "eta",true);
39 value.RegisterNewFab(value.grad_chempot_mf, value.bc, 1, 1, "grad_chempot",true);
40}
41
42
43#ifdef ALAMO_FFT
44void
45PFC::Advance (int lev, Set::Scalar /*time*/, Set::Scalar dt)
46{
47 //
48 // FFT Boilerplate
49 //
50
51 Operator::Spectral::FFT fft(geom,refRatio(),lev);
52
53 //
54 // Compute the gradient of the chemical potential in realspace
55 //
56 for ( amrex::MFIter mfi(*eta_mf[lev],true); mfi.isValid(); ++mfi )
57 {
58 const amrex::Box& bx = mfi.tilebox();
59 amrex::Array4<const amrex::Real> const& eta = eta_mf[lev]->array(mfi);
60 amrex::Array4<amrex::Real> const& grad_chempot = grad_chempot_mf[lev]->array(mfi);
61 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
62 {
63 grad_chempot(i, j, k) = eta(i, j, k) * eta(i, j, k) * eta(i, j, k);
64 });
65 }
66
67 grad_chempot_mf[lev]->FillBoundary();
68
69 //
70 // FFT of eta
71 //
72 amrex::FabArray<amrex::BaseFab<Set::Complex>> eta_hat_mf = fft.MakeSpectralFab();
73 fft.Forward(*eta_mf[lev],eta_hat_mf);
74
75 //
76 // FFT of chemical potential gradient
77 //
78 amrex::FabArray<amrex::BaseFab<amrex::GpuComplex<Set::Scalar> > > chempot_hat_mf = fft.MakeSpectralFab();
79 fft.Forward(*grad_chempot_mf[lev], chempot_hat_mf);
80
81 //
82 // Perform update in spectral coordinatees
83 //
84 for (amrex::MFIter mfi(eta_hat_mf, amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
85 {
86 const amrex::Box &bx = mfi.tilebox();
87
88 amrex::Array4<amrex::GpuComplex<Set::Scalar>> const & eta_hat = eta_hat_mf.array(mfi);
89 amrex::Array4<amrex::GpuComplex<Set::Scalar>> const & N_hat = chempot_hat_mf.array(mfi);
90
91 fft.ParallelFor(bx, [=] AMREX_GPU_DEVICE(int m, int n, int p, Set::Scalar omega2) {
92
93 Set::Scalar omega4 = omega2*omega2;
94 Set::Scalar omega6 = omega2*omega2*omega2;
95
96 eta_hat(m, n, p) = eta_hat(m, n, p) - dt * omega2 * N_hat(m, n, p);
97 eta_hat(m,n,p) /= 1.0 + dt * ((q0*q0*q0*q0 - eps)*omega2 - 2.0* q0*q0 * omega4 + omega6);
98 });
99 }
100
101 //
102 // Transform solution back to realspace
103 //
104 fft.Backward(eta_hat_mf, *eta_mf[lev]);
105}
106#else
107void
109{
110 Util::Abort(INFO,"Alamo must be compiled with fft");
111}
112#endif
113
114void
116{
117 ic->Initialize(lev,eta_mf);
118 grad_chempot_mf[lev]->setVal(0.0);
119}
120
121
122void
123PFC::TagCellsForRefinement (int /*lev*/, amrex::TagBoxArray& /*a_tags*/, Set::Scalar /*time*/, int /*ngrow*/)
124{
125}
126
127
128}
#define INFO
Definition Util.H:24
void Initialize(const int &a_lev, Set::Field< T > &a_field, Set::Scalar a_time=0.0)
Definition IC.H:39
Set each point to a random value.
Definition Random.H:28
int query_required(std::string name, T &value)
Definition ParmParse.H:249
void select_default(std::string name, PTRTYPE *&ic_eta, Args &&... args)
Definition ParmParse.H:1103
void RegisterNewFab(Set::Field< Set::Scalar > &new_fab, BC::BC< Set::Scalar > *new_bc, int ncomp, int nghost, std::string name, bool writeout, bool evolving=true, std::vector< std::string > suffix={})
Add a new cell-based scalar field.
amrex::Vector< amrex::Real > dt
Timesteps for each level of refinement.
Definition Integrator.H:394
Set::Field< Set::Scalar > grad_chempot_mf
Order parameter field.
Definition PFC.H:73
void TagCellsForRefinement(int lev, amrex::TagBoxArray &tags, amrex::Real time, int ngrow) override
Mark any cells that need to be refined.
Definition PFC.cpp:123
~PFC()
Destroy pointers defined in Parse.
Definition PFC.cpp:20
static void Parse(PFC &value, IO::ParmParse &pp)
Scan input values and initialize fields.
Definition PFC.cpp:26
PFC()
Basic constructor (don't use)
Definition PFC.cpp:17
IC::IC< Set::Scalar > * ic
eta's bc object
Definition PFC.H:76
Set::Scalar eps
Definition PFC.H:79
Set::Field< Set::Scalar > eta_mf
Definition PFC.H:72
BC::BC< Set::Scalar > * bc
Field to calculate FFT of nonlinar part.
Definition PFC.H:75
Set::Scalar q0
eta's ic object
Definition PFC.H:78
void Initialize(int lev) override
Set values in fields.
Definition PFC.cpp:115
void Advance(int lev, Set::Scalar time, Set::Scalar dt) override
Integrate eta over one timestep on lev.
Definition PFC.cpp:108
Collection of numerical integrator objects.
Definition AllenCahn.H:43
amrex::Real Scalar
Definition Base.H:19
void Abort(const char *msg)
Definition Util.cpp:268