ARTEMIS
MacroscopicProperties.H
Go to the documentation of this file.
1 /* Copyright 2020 Revathi Jambunathan
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef WARPX_MACROSCOPICPROPERTIES_H_
9 #define WARPX_MACROSCOPICPROPERTIES_H_
10 
12 
13 #include "Utils/WarpXConst.H"
14 
15 #include <AMReX_Array.H>
16 #include <AMReX_Extension.H>
17 #include <AMReX_GpuQualifiers.H>
18 #include <AMReX_MultiFab.H>
19 #include <AMReX_Parser.H>
20 #include <AMReX_REAL.H>
21 
22 #include <memory>
23 #include <string>
24 
25 
30 class
32 {
33 public:
34  MacroscopicProperties (); // constructor
36  void ReadParameters ();
38  void InitData ();
39 
41  amrex::MultiFab& getsigma_mf () {return (*m_sigma_mf);}
42  amrex::MultiFab * get_pointer_sigma () {return m_sigma_mf.get();}
44  amrex::MultiFab& getepsilon_mf () {return (*m_eps_mf);}
45  amrex::MultiFab * get_pointer_eps () {return m_eps_mf.get();}
47  amrex::MultiFab& getmu_mf () {return (*m_mu_mf);}
48  amrex::MultiFab * get_pointer_mu () {return m_mu_mf.get();}
49 
55  void InitializeMacroMultiFabUsingParser (amrex::MultiFab *macro_mf,
56  amrex::ParserExecutor<3> const& macro_parser,
57  const int lev);
58 
59  void InitializeMacroMultiFabFromNumpy (amrex::MultiFab* macro_mf,
60  const std::string& npy_filename,
61  const int lev,
62  const int npy_k_index,
63  const amrex::Real npy_value);
64 
65  void InitializePECFromSigma (amrex::MultiFab* sigma_mf,
66  amrex::MultiFab* PECx,
67  amrex::MultiFab* PECy,
68  const int npy_k_index);
69 
88 
90  std::string m_sigma_s = "constant";
92  std::string m_epsilon_s = "constant";
94  std::string m_mu_s = "constant";
96  amrex::Real m_sigma = 0.0;
98  amrex::Real m_epsilon = PhysConst::ep0;
100  amrex::Real m_mu = PhysConst::mu0;
102  int m_npy_k_index = 0;
104  std::string m_sigma_npy_filename;
106  std::string m_mu_npy_filename;
108  amrex::Real m_sigma_npy_value = 0.;
109  amrex::Real m_epsilon_npy_value = 0.;
110  amrex::Real m_mu_npy_value = 0.;
112  std::unique_ptr<amrex::Parser> m_sigma_parser;
113  std::unique_ptr<amrex::Parser> m_epsilon_parser;
114  std::unique_ptr<amrex::Parser> m_mu_parser;
115 
116 #ifdef WARPX_MAG_LLG
118  amrex::GpuArray<int, 3> Hx_IndexType;
120  amrex::GpuArray<int, 3> Hy_IndexType;
122  amrex::GpuArray<int, 3> Hz_IndexType;
124  amrex::GpuArray<int, 3> Mx_IndexType;
126  amrex::GpuArray<int, 3> My_IndexType;
128  amrex::GpuArray<int, 3> Mz_IndexType;
130  amrex::GpuArray<amrex::Real, 3> mag_LLG_anisotropy_axis;
131 
132  amrex::MultiFab& getmag_Ms_mf (int dir) {return (*m_mag_Ms_mf[dir]);}
133  amrex::MultiFab * getmag_pointer_Ms (int dir) {return m_mag_Ms_mf[dir].get();}
134  amrex::MultiFab& getmag_alpha_mf (int dir) {return (*m_mag_alpha_mf[dir]);}
135  amrex::MultiFab * getmag_pointer_alpha (int dir) {return m_mag_alpha_mf[dir].get();}
136  amrex::MultiFab& getmag_gamma_mf (int dir) {return (*m_mag_gamma_mf[dir]);}
137  amrex::MultiFab * getmag_pointer_gamma (int dir) {return m_mag_gamma_mf[dir].get();}
138  amrex::MultiFab& getmag_exchange_mf (int dir) {return (*m_mag_exchange_mf[dir]);}
139  amrex::MultiFab * getmag_pointer_exchange (int dir) {return m_mag_exchange_mf[dir].get();}
140  amrex::MultiFab& getmag_anisotropy_mf(int dir) {return (*m_mag_anisotropy_mf[dir]);}
141  amrex::MultiFab * getmag_pointer_anisotropy (int dir) {return m_mag_anisotropy_mf[dir].get();}
142 
143  amrex::Real getmag_normalized_error () {return m_mag_normalized_error;}
144  int getmag_max_iter () {return m_mag_max_iter;}
145  amrex::Real getmag_tol () {return m_mag_tol;}
146 
147  // interpolate the magnetic properties to B locations
148  // magnetic properties are cell nodal
149  // B locations are face centered
150  // iv is an IntVect with a 1 in the face direction of interest, and 0 in the others
152  static amrex::Real macro_avg_to_face (int i, int j, int k, amrex::IntVect iv, amrex::Array4<amrex::Real> const& macro_mag_prop){
153  using namespace amrex;
154  return ( 0.125_rt * ( macro_mag_prop(i ,j ,k )
155  + macro_mag_prop(i-iv[0]+1,j ,k )
156  + macro_mag_prop(i ,j-iv[1]+1,k )
157  + macro_mag_prop(i ,j ,k-iv[2]+1)
158  + macro_mag_prop(i ,j-iv[1]+1,k-iv[2]+1)
159  + macro_mag_prop(i-iv[0]+1,j ,k-iv[2]+1)
160  + macro_mag_prop(i-iv[0]+1,j-iv[1]+1,k )
161  + macro_mag_prop(i-iv[0]+1,j-iv[1]+1,k-iv[2]+1)
162  ));
163  }
164 
183  static amrex::Real face_avg_to_face (int i, int j, int k, int n,
184  amrex::IntVect iv_in, amrex::IntVect iv_out,
185  amrex::Array4<amrex::Real> const& Fieldcomp) {
186  using namespace amrex;
187  return ( 0.125_rt * ( Fieldcomp(i , j , k , n)
188  + Fieldcomp(i+iv_in[0]-iv_out[0], j , k , n)
189  + Fieldcomp(i , j+iv_in[1]-iv_out[1], k , n)
190  + Fieldcomp(i , j , k+iv_in[2]-iv_out[2], n)
191  + Fieldcomp(i+iv_in[0]-iv_out[0], j+iv_in[1]-iv_out[1], k , n)
192  + Fieldcomp(i+iv_in[0]-iv_out[0], j , k+iv_in[2]-iv_out[2], n)
193  + Fieldcomp(i , j+iv_in[1]-iv_out[1], k+iv_in[2]-iv_out[2], n)
194  + Fieldcomp(i+iv_in[0]-iv_out[0], j+iv_in[1]-iv_out[1], k+iv_in[2]-iv_out[2], n)
195  ));
196  }
197 
213  static amrex::Real getH_Maxwell (int i, int j, int k, int n,
214  amrex::IntVect iv_in, amrex::IntVect iv_out,
215  amrex::Array4<amrex::Real> const& Bcomp, amrex::Array4<amrex::Real> const& Mcomp) {
216  using namespace amrex;
217  amrex::Real H_Maxwell = face_avg_to_face(i, j, k, 0, iv_in, iv_out, Bcomp)/PhysConst::mu0
218  - Mcomp(i, j, k, n); //magnetic constitutive relation
219  return H_Maxwell;
220  }
221 
228  static amrex::Real updateM_field (int i, int j, int k, int n,
230  using namespace amrex;
231  amrex::Real a_square = pow(a(i, j, k, 0), 2.0) + pow(a(i, j, k, 1), 2.0) + pow(a(i, j, k, 2), 2.0);
232  amrex::Real a_dot_b = a(i, j, k, 0) * b(i, j, k, 0) +
233  a(i, j, k, 1) * b(i, j, k, 1) +
234  a(i, j, k, 2) * b(i, j, k, 2);
235  // Initialize to 0.
236  amrex::Real M_field = 0._rt;
237 
238  if(n==0){
239  amrex::Real a_cross_b_x = a(i, j, k, 1) * b(i, j, k, 2) -
240  a(i, j, k, 2) * b(i, j, k, 1);
241  M_field = ( b(i, j, k, 0) + a_dot_b * a(i, j, k, 0) - a_cross_b_x ) / ( 1.0 + a_square);
242  }
243  else if(n==1){
244  amrex::Real a_cross_b_y = a(i, j, k, 2) * b(i, j, k, 0) -
245  a(i, j, k, 0) * b(i, j, k, 2);
246  M_field = ( b(i, j, k, 1) + a_dot_b * a(i, j, k, 1) - a_cross_b_y ) / ( 1.0 + a_square);
247  }
248  else if(n==2){
249  amrex::Real a_cross_b_z = a(i, j, k, 0) * b(i, j, k, 1) -
250  a(i, j, k, 1) * b(i, j, k, 0);
251  M_field = ( b(i, j, k, 2) + a_dot_b * a(i, j, k, 2) - a_cross_b_z ) / ( 1.0 + a_square);
252  }
253  else{
254  amrex::Abort("Wrong component n of the M_field");
255  }
256  return M_field;
257  }
258 #endif //closes ifdef MAG_LLG
259 
260 #ifdef WARPX_MAG_LLG
262  amrex::Real m_mag_Ms;
264  amrex::Real m_mag_alpha;
266  amrex::Real m_mag_gamma;
268  amrex::Real m_mag_exchange;
270  amrex::Real m_mag_anisotropy;
271 
272  // If the magnitude of the magnetization deviates by more than this amount relative
273  // to the user-defined Ms, abort. Default 0.1.
274  amrex::Real m_mag_normalized_error;
275 
276  // maximum iteration count for the second-order time advancement scheme of M field, default 100
277  int m_mag_max_iter;
278 
279  // the relative tolerance for the second-order time advancement scheme of M field, default 0.0001
280  amrex::Real m_mag_tol;
281 
283  std::array<std::unique_ptr<amrex::MultiFab>, 3> m_mag_Ms_mf;
285  std::array<std::unique_ptr<amrex::MultiFab>, 3> m_mag_alpha_mf;
287  std::array<std::unique_ptr<amrex::MultiFab>, 3> m_mag_gamma_mf;
289  std::array<std::unique_ptr<amrex::MultiFab>, 3> m_mag_exchange_mf;
291  std::array<std::unique_ptr<amrex::MultiFab>, 3> m_mag_anisotropy_mf;
292 
293  // these store the type of initialization, e.g., "constant", "parse_X_function", etc.
294  std::string m_mag_Ms_s;
295  std::string m_mag_alpha_s;
296  std::string m_mag_gamma_s;
297  std::string m_mag_exchange_s;
298  std::string m_mag_anisotropy_s;
299 
300  // these store the parsed expression for the material properties
301  std::string m_str_mag_Ms_function;
302  std::string m_str_mag_alpha_function;
303  std::string m_str_mag_gamma_function;
304  std::string m_str_mag_exchange_function;
305  std::string m_str_mag_anisotropy_function;
306 
307  std::unique_ptr<amrex::Parser> m_mag_Ms_parser;
308  std::unique_ptr<amrex::Parser> m_mag_alpha_parser;
309  std::unique_ptr<amrex::Parser> m_mag_gamma_parser;
310  std::unique_ptr<amrex::Parser> m_mag_exchange_parser;
311  std::unique_ptr<amrex::Parser> m_mag_anisotropy_parser;
312 #endif
313 
314 private:
315 
317  std::unique_ptr<amrex::MultiFab> m_sigma_mf;
319  std::unique_ptr<amrex::MultiFab> m_eps_mf;
321  std::unique_ptr<amrex::MultiFab> m_mu_mf;
322 
323 
325  std::string m_str_sigma_function;
327  std::string m_str_mu_function;
328 
329 };
330 
340 
342  static amrex::Real alpha (amrex::Real const sigma,
343  amrex::Real const epsilon,
344  amrex::Real dt) {
345  using namespace amrex;
346  amrex::Real fac1 = 0.5_rt * sigma * dt / epsilon;
347  amrex::Real alpha = (1._rt - fac1)/(1._rt + fac1);
348  return alpha;
349  }
350 
352  static amrex::Real beta (amrex::Real const sigma,
353  amrex::Real const epsilon,
354  amrex::Real dt) {
355  using namespace amrex;
356  amrex::Real fac1 = 0.5_rt * sigma * dt / epsilon;
357  amrex::Real beta = dt / ( epsilon * (1._rt + fac1) );
358  return beta;
359  }
360 
361 };
362 
372 
374  static amrex::Real alpha (amrex::Real const sigma,
375  amrex::Real const epsilon,
376  amrex::Real dt) {
377  using namespace amrex;
378  amrex::Real fac1 = sigma * dt / epsilon;
379  amrex::Real alpha = (1._rt)/(1._rt + fac1);
380  return alpha;
381  }
382 
384  static amrex::Real beta (amrex::Real const sigma,
385  amrex::Real const epsilon,
386  amrex::Real dt) {
387  using namespace amrex;
388  amrex::Real fac1 = sigma * dt / epsilon;
389  amrex::Real beta = dt / ( epsilon * (1._rt + fac1) );
390  return beta;
391  }
392 
393 };
394 
395 #endif // WARPX_MACROSCOPIC_PROPERTIES_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
This class contains the macroscopic properties of the medium needed to evaluate macroscopic Maxwell e...
Definition: MacroscopicProperties.H:32
amrex::GpuArray< int, 3 > epsilon_IndexType
Definition: MacroscopicProperties.H:73
amrex::GpuArray< int, 3 > mu_IndexType
Definition: MacroscopicProperties.H:75
amrex::GpuArray< int, 3 > Bx_IndexType
Definition: MacroscopicProperties.H:83
amrex::GpuArray< int, 3 > sigma_IndexType
Definition: MacroscopicProperties.H:71
amrex::GpuArray< int, 3 > By_IndexType
Definition: MacroscopicProperties.H:85
std::string m_str_epsilon_function
Definition: MacroscopicProperties.H:326
std::string m_str_mu_function
Definition: MacroscopicProperties.H:327
amrex::MultiFab * get_pointer_eps()
Definition: MacroscopicProperties.H:45
amrex::MultiFab & getepsilon_mf()
Definition: MacroscopicProperties.H:44
std::unique_ptr< amrex::Parser > m_mu_parser
Definition: MacroscopicProperties.H:114
amrex::MultiFab & getsigma_mf()
Definition: MacroscopicProperties.H:41
std::unique_ptr< amrex::MultiFab > m_mu_mf
Definition: MacroscopicProperties.H:321
std::string m_str_sigma_function
Definition: MacroscopicProperties.H:325
std::unique_ptr< amrex::Parser > m_epsilon_parser
Definition: MacroscopicProperties.H:113
std::string m_epsilon_npy_filename
Definition: MacroscopicProperties.H:105
amrex::GpuArray< int, 3 > Ex_IndexType
Definition: MacroscopicProperties.H:77
amrex::GpuArray< int, 3 > Ey_IndexType
Definition: MacroscopicProperties.H:79
amrex::GpuArray< int, 3 > Bz_IndexType
Definition: MacroscopicProperties.H:87
amrex::MultiFab * get_pointer_sigma()
Definition: MacroscopicProperties.H:42
amrex::MultiFab & getmu_mf()
Definition: MacroscopicProperties.H:47
amrex::GpuArray< int, 3 > Ez_IndexType
Definition: MacroscopicProperties.H:81
std::string m_sigma_npy_filename
Definition: MacroscopicProperties.H:104
std::string m_mu_npy_filename
Definition: MacroscopicProperties.H:106
amrex::GpuArray< int, 3 > macro_cr_ratio
Definition: MacroscopicProperties.H:51
std::unique_ptr< amrex::Parser > m_sigma_parser
Definition: MacroscopicProperties.H:112
std::unique_ptr< amrex::MultiFab > m_sigma_mf
Definition: MacroscopicProperties.H:317
amrex::MultiFab * get_pointer_mu()
Definition: MacroscopicProperties.H:48
std::unique_ptr< amrex::MultiFab > m_eps_mf
Definition: MacroscopicProperties.H:319
const FAB & get(const MFIter &mfi) const noexcept
static constexpr auto ep0
vacuum permittivity: dielectric permittivity of vacuum [F/m]
Definition: constant.H:46
static constexpr auto mu0
vacuum permeability: magnetic permeability of vacuum = 4.0e-7 * pi [H/m]
Definition: constant.H:48
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
void Abort(const std::string &msg)
i
Definition: check_interp_points_and_weights.py:174
int n
Definition: run_libensemble_on_warpx.py:67
int dt
Definition: stencil.py:440
This struct contains only static functions to compute the co-efficients for the BackwardEuler scheme ...
Definition: MacroscopicProperties.H:371
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real beta(amrex::Real const sigma, amrex::Real const epsilon, amrex::Real dt)
Definition: MacroscopicProperties.H:384
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real alpha(amrex::Real const sigma, amrex::Real const epsilon, amrex::Real dt)
Definition: MacroscopicProperties.H:374
This struct contains only static functions to compute the co-efficients for the Lax-Wendroff scheme o...
Definition: MacroscopicProperties.H:339
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real beta(amrex::Real const sigma, amrex::Real const epsilon, amrex::Real dt)
Definition: MacroscopicProperties.H:352
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real alpha(amrex::Real const sigma, amrex::Real const epsilon, amrex::Real dt)
Definition: MacroscopicProperties.H:342