Skip to content

Commit

Permalink
Added normalization of M magnitude at each iteration of 2nd order al…
Browse files Browse the repository at this point in the history
…gorithm (#32)

* added normalization in 2nd order evolveM and input file for debug

* added normalizationto M

* test commit #1

* test commit #2

* added field output lines

* added python script for viz

* turned off LLG-EM coupling

* turned off LLG-EM coupling

* fixed white space at line end

* changed python script name

* Delete M time sequence.ipynb

duplicate file

* clear up no coupling lines

* clear up output functions

* Delete M_time_sequence.ipynb

* Added new line at end of inputs_3d.evolveM2nd

* Added new line at the end of WarpX.cpp

* make file easier to read

Co-authored-by: Andy Nonaka <[email protected]>
  • Loading branch information
jackieyao0114 and ajnonaka authored Aug 28, 2020
1 parent 0e1b80b commit 36b188d
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
107 changes: 107 additions & 0 deletions Examples/Tests/Macroscopic_Maxwell/inputs_3d.evolveM2nd
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
################################
####### GENERAL PARAMETERS ######
#################################
max_step = 1000
amr.n_cell = 8 8 8 # number of cells spanning the domain in each coordinate direction at level 0
amr.max_grid_size = 512 # maximum size of each AMReX box, used to decompose the domain
amr.blocking_factor = 8
geometry.coord_sys = 0
geometry.is_periodic = 1 1 1

geometry.prob_lo = -1.5e-6 -1.5e-6 -1.5e-6
geometry.prob_hi = 1.5e-6 1.5e-6 1.5e-6

amr.max_level = 0

#################################
############ NUMERICS ###########
#################################
warpx.verbose = 0
warpx.use_filter = 0
warpx.cfl = 4000
warpx.do_pml = 0
warpx.mag_time_scheme_order = 2 # default 1
particles.nspecies = 0

algo.em_solver_medium = macroscopic # vacuum/macroscopic

algo.macroscopic_sigma_method = laxwendroff # laxwendroff or backwardeuler
macroscopic.sigma_init_style = "parse_sigma_function" # parse or "constant"
macroscopic.sigma_function(x,y,z) = "0.0"
#macroscopic.sigma = 0.0

macroscopic.epsilon_init_style = "parse_epsilon_function" # parse or "constant"
macroscopic.epsilon_function(x,y,z) = "8.8541878128e-12"
#macroscopic.epsilon = 8.8541878128e-12

macroscopic.mu_init_style = "parse_mu_function" # parse or "constant"
macroscopic.mu_function(x,y,z) = "1.25663706212e-06"
#macroscopic.mu = 1.25663706212e-06

#unit conversion: 1 Gauss = (1000/4pi) A/m
macroscopic.mag_Ms_init_style = "parse_mag_Ms_function" # parse or "constant"
macroscopic.mag_Ms_function(x,y,z) = "1.4e5"
#macroscopic.mag_Ms = 1.4e5 # in unit A/m, equal to 1750 Gauss

macroscopic.mag_alpha_init_style = "parse_mag_alpha_function" # parse or "constant"
macroscopic.mag_alpha_function(x,y,z) = "5e-01"
#macroscopic.mag_alpha = 5e-01 # alpha is unitless, typical values range from 1e-3 ~ 1e-5

macroscopic.mag_gamma_init_style = "parse_mag_gamma_function" # parse or "constant"
macroscopic.mag_gamma_function(x,y,z) = "-1.759e11"
#macroscopic.mag_gamma = -1.759e11 # gyromagnetic ratio is constant for electrons in all materials

macroscopic.mag_max_iter = 100 # maximum number of M iteration in each time step
macroscopic.mag_tol = 0.00001 # M magnitude relative error tolerance compared to previous iteration
macroscopic.mag_normalized_error = 0.1 # if M magnitude relatively changes more than this value, raise a red flag

#################################
############ FIELDS #############
#################################
my_constants.pi = 3.14159265359
my_constants.L = 141.4213562373095e-6
my_constants.c = 299792458.
my_constants.wavelength = 1.2e-1

warpx.E_ext_grid_init_style = parse_E_ext_grid_function

warpx.Ex_external_grid_function(x,y,z) = 0.
warpx.Ey_external_grid_function(x,y,z) = 0.
#warpx.Ey_external_grid_function(x,y,z) = "1.e5exp(-z2/L2)cos(2piz/wavelength)"
warpx.Ez_external_grid_function(x,y,z) = 0.

warpx.B_ext_grid_init_style = parse_B_ext_grid_function
warpx.Bx_external_grid_function(x,y,z)= 0.1759
#warpx.Bx_external_grid_function(x,y,z)= 0.
#warpx.Bx_external_grid_function(x,y,z)= "-1.e5exp(-z2/L2)cos(2piz/wavelength)/c"
warpx.By_external_grid_function(x,y,z)= 0.
warpx.Bz_external_grid_function(x,y,z) = 0.

#unit conversion: 1 Gauss = 1 Oersted = (1000/4pi) A/m
#calculation of H_bias: H_bias (oe) = frequency / 2.8e6

warpx.H_bias_ext_grid_init_style = parse_H_bias_ext_grid_function
warpx.Hx_bias_external_grid_function(x,y,z)= 0.
warpx.Hy_bias_external_grid_function(x,y,z)= 0.
warpx.Hz_bias_external_grid_function(x,y,z)= 3e4 # in A/m, equal to 382 Oersted
#warpx.Hz_bias_external_grid_function(x,y,z)= 0. # in A/m, equal to 382 Oersted

#warpx.H_bias_ext_grid_init_style = constant
#warpx.Hx_bias_external_grid = 0
#warpx.Hy_bias_external_grid = 0
#warpx.Hz_bias_external_grid = 0

#warpx.M_ext_grid_init_style = parse_M_ext_grid_function
#warpx.Mx_external_grid_function(x,y,z)= "-1.e5exp(-z2/L2)cos(2piz/wavelength)/c"
#warpx.My_external_grid_function(x,y,z)= 0.
#warpx.Mz_external_grid_function(x,y,z) = 0.

warpx.M_ext_grid_init_style = constant
warpx.M_external_grid = 140000. 0. 0.

#Diagnostics
diagnostics.diags_names = plt
plt.period = 100
plt.diag_type = Full
plt.fields_to_plot = Ex Ey Ez Bx By Bz Mx_xface My_xface Mz_xface Mx_yface My_yface Mz_yface Mx_zface My_zface Mz_zface
plt.plot_raw_fields = 0
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd (
std::unique_ptr<MacroscopicProperties> const& macroscopic_properties )
{

// obtain the maximum relative amount we let M deviate from Ms before aborting
amrex::Real mag_normalized_error = macroscopic_properties->getmag_normalized_error();

// build temporary vector<multifab,3> Mfield_prev, Mfield_error, a_temp, a_temp_static, b_temp_static
std::array< std::unique_ptr<amrex::MultiFab>, 3 > Mfield_prev; // M^n before the iteration
std::array< std::unique_ptr<amrex::MultiFab>, 3 > Mfield_error; // The error of the M field between the twoiterations
Expand Down Expand Up @@ -176,7 +179,6 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd (
Real Hy_bias_yface = MacroscopicProperties::face_avg_to_face(i, j, k, 0, amrex::IntVect(0,1,0), amrex::IntVect(0,1,0), Hy_bias);
Real Hz_bias_yface = MacroscopicProperties::face_avg_to_face(i, j, k, 0, amrex::IntVect(0,0,1), amrex::IntVect(0,1,0), Hz_bias);
// H_eff = H_maxwell + H_bias + H_exchange + H_anisotropy ... (only the first two terms are considered here)

Real Hx_eff = Hx_yface + Hx_bias_yface;
Real Hy_eff = Hy_yface + Hy_bias_yface;
Real Hz_eff = Hz_yface + Hz_bias_yface;
Expand Down Expand Up @@ -383,6 +385,22 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd (
// z component on x-faces of grid
M_xface(i, j, k, 2) = MacroscopicProperties::updateM_field(i, j, k, 2, a_temp_xface, b_temp_static_xface);

// temporary normalized magnitude of M_xface field at the fixed point
// re-investigate the way we do Ms interp, in case we encounter the case where Ms changes across two adjacent cells that you are doing interp
amrex::Real mag_normalized = std::sqrt( std::pow(M_xface(i, j, k, 0),2.0) + std::pow(M_xface(i, j, k, 1),2.0) +
std::pow(M_xface(i, j, k, 2),2.0) ) / MacroscopicProperties::macro_avg_to_face(i,j,k,amrex::IntVect(1,0,0),mag_Ms_arr);

// check the normalized error
if ( amrex::Math::abs(1._rt-mag_normalized) > mag_normalized_error ){
printf("i = %d, j=%d, k=%d\n", i, j, k);
printf("mag_normalized = %f, mag_normalized_error=%f\n", mag_normalized, mag_normalized_error);
amrex::Abort("Exceed the normalized error of the M_xface field");
}
// normalize the M_xface field
M_xface(i,j,k,0) /= mag_normalized;
M_xface(i,j,k,1) /= mag_normalized;
M_xface(i,j,k,2) /= mag_normalized;

// calculate M_error_xface
// x component on x-faces of grid
M_error_xface(i, j, k, 0) = std::abs((M_xface(i, j, k, 0) - M_prev_xface(i, j, k, 0))) / Mfield_prev_max[0];
Expand Down Expand Up @@ -442,6 +460,22 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd (
// z component on y-faces of grid
M_yface(i, j, k, 2) = MacroscopicProperties::updateM_field(i, j, k, 2, a_temp_yface, b_temp_static_yface);

// temporary normalized magnitude of M_yface field at the fixed point
// re-investigate the way we do Ms interp, in case we encounter the case where Ms changes across two adjacent cells that you are doing interp
amrex::Real mag_normalized = std::sqrt( std::pow(M_yface(i, j, k, 0),2.0) + std::pow(M_yface(i, j, k, 1),2.0) +
std::pow(M_yface(i, j, k, 2),2.0) ) / MacroscopicProperties::macro_avg_to_face(i,j,k,amrex::IntVect(0,1,0),mag_Ms_arr);

// check the normalized error
if ( amrex::Math::abs(1._rt-mag_normalized) > mag_normalized_error ){
printf("i = %d, j=%d, k=%d\n", i, j, k);
printf("mag_normalized = %f, mag_normalized_error=%f\n",mag_normalized, mag_normalized_error);
amrex::Abort("Exceed the normalized error of the M_yface field");
}
// normalize the M_yface field
M_yface(i,j,k,0) /= mag_normalized;
M_yface(i,j,k,1) /= mag_normalized;
M_yface(i,j,k,2) /= mag_normalized;

// calculate M_error_yface
// x component on y-faces of grid
M_error_yface(i, j, k, 0) = std::abs((M_yface(i, j, k, 0) - M_prev_yface(i, j, k, 0))) / Mfield_prev_max[0];
Expand Down Expand Up @@ -500,6 +534,22 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd (
// z component on z-faces of grid
M_zface(i, j, k, 2) = MacroscopicProperties::updateM_field(i, j, k, 2, a_temp_zface, b_temp_static_zface);

// temporary normalized magnitude of M_zface field at the fixed point
// re-investigate the way we do Ms interp, in case we encounter the case where Ms changes across two adjacent cells that you are doing interp
amrex::Real mag_normalized = std::sqrt( std::pow(M_zface(i, j, k, 0),2.0_rt) + std::pow(M_zface(i, j, k, 1),2.0_rt) +
std::pow(M_zface(i, j, k, 2),2.0_rt) ) / MacroscopicProperties::macro_avg_to_face(i,j,k,amrex::IntVect(0,0,1),mag_Ms_arr);

// check the normalized error
if ( amrex::Math::abs(1.-mag_normalized) > mag_normalized_error ){
printf("i = %d, j=%d, k=%d\n", i, j, k);
printf("mag_normalized = %f, mag_normalized_error=%f\n", mag_normalized, mag_normalized_error);
amrex::Abort("Exceed the normalized error of the M_zface field");
}
// normalize the M_zface field
M_zface(i,j,k,0) /= mag_normalized;
M_zface(i,j,k,1) /= mag_normalized;
M_zface(i,j,k,2) /= mag_normalized;

// calculate M_error_zface
// x component on z-faces of grid
M_error_zface(i, j, k, 0) = amrex::Math::abs((M_zface(i, j, k, 0) - M_prev_zface(i, j, k, 0))) / Mfield_prev_max[0];
Expand Down

0 comments on commit 36b188d

Please sign in to comment.