diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index b389242e5fd..780906d535c 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -1051,6 +1051,15 @@ Numerics and algorithms The conductivity, permittivity, and permeability of the computational medium, respectively. If ``algo.em_solver_medium`` is set to macroscopic, then these properties must be provided. +* ``macroscopic.mag_normalized_error`` (`double`; default: `0.1`) + The maximum relative amount we let M deviate from Ms before aborting for the LLG equation. This requires `USE_LLG=TRUE` in the GNUMakefile. + +* ``macroscopic.mag_max_iter`` (`int`; default: `100`) + The maximum number of iterations allowed of the 2nd-order trapezoidal scheme for the LLG equation. This requires `USE_LLG=TRUE` in the GNUMakefile. + +* ``macroscopic.mag_tol`` (`double`; default: `0.0001`) + The relative tolerance stopping criteria for 2nd-order iterative algorithm of the 2nd-order trapezoidal scheme for the LLG equation. This requires `USE_LLG=TRUE` in the GNUMakefile. + * ``warpx.mag_time_scheme_order`` (`1` or `2`; default: `1`) The value of the time advancement scheme of M field. `mag_time_scheme_order==1` is the 1st-order Eulerian scheme and `mag_time_scheme_order==2` is the 2nd-order trapezoidal scheme for the LLG equation. This requires `USE_LLG=TRUE` in the GNUMakefile. diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM.cpp index cda0f287dfb..60005315b95 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM.cpp @@ -43,8 +43,9 @@ void FiniteDifferenceSolver::MacroscopicEvolveM ( amrex::Real const dt, std::unique_ptr const& macroscopic_properties ) { - // Temporary value hard-coded for normalized error used for LLG. - amrex::Real mag_normalized_error = 0.1_rt; // normalization error of M field for checking + + // obtain the maximum relative amount we let M deviate from Ms before aborting + amrex::Real mag_normalized_error = macroscopic_properties->getmag_normalized_error(); for (MFIter mfi(*Mfield[0], TilingIfNotGPU()); mfi.isValid(); ++mfi) /* remember to FIX */ { diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp index 8f9a5042b43..662329c7f7f 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp @@ -282,10 +282,11 @@ void FiniteDifferenceSolver::MacroscopicEvolveM_2nd ( } // initialize M_max_iter, M_iter, M_tol, M_iter_error - // change these to user-defined input in the next PR - int M_max_iter = 100; + // maximum number of iterations allowed + int M_max_iter = macroscopic_properties->getmag_max_iter(); int M_iter = 0; - amrex::Real M_tol = 0.0001; + // relative tolerance stopping criteria for 2nd-order iterative algorithm + amrex::Real M_tol = macroscopic_properties->getmag_tol(); amrex::Real M_iter_maxerror = -1.0; int stop_iter = 0; diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H index b2cb3021489..61d91467699 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H @@ -47,6 +47,10 @@ public: amrex::MultiFab& getmag_alpha_mf () {return (*m_mag_alpha_mf);} amrex::MultiFab& getmag_gamma_mf () {return (*m_mag_gamma_mf);} + amrex::Real getmag_normalized_error () {return m_mag_normalized_error;} + int getmag_max_iter () {return m_mag_max_iter;} + amrex::Real getmag_tol () {return m_mag_tol;} + // interpolate the magnetic properties to B locations // magnetic properties are cell nodal // B locations are face centered @@ -174,6 +178,17 @@ private: amrex::Real m_mag_alpha; /** gyromagnetic ratio, should be a negative value, only applies for magnetic materials */ amrex::Real m_mag_gamma; + + // If the magnitude of the magnetization deviates by more than this amount relative + // to the user-defined Ms, abort. Default 0.1. + amrex::Real m_mag_normalized_error; + + // maximum iteration count for the second-order time advancement scheme of M field, default 100 + int m_mag_max_iter; + + // the relative tolerance for the second-order time advancement scheme of M field, default 0.0001 + amrex::Real m_mag_tol; + #endif /** Multifab for m_sigma */ diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp index b9d092b1681..57d5ee1cbe1 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp @@ -73,6 +73,16 @@ MacroscopicProperties::ReadParameters () m_mag_gamma_parser.reset(new ParserWrapper<3>( makeParser(m_str_mag_gamma_function,{"x","y","z"}))); } + + m_mag_normalized_error = 0.1; + pp.query("mag_normalized_error",m_mag_normalized_error); + + m_mag_max_iter = 100; + pp.query("mag_max_iter",m_mag_max_iter); + + m_mag_tol = 0.0001; + pp.query("mag_tol",m_mag_tol); + #endif }