From 653889bc580bc63c7c60bc1ecb0d5210ea93d643 Mon Sep 17 00:00:00 2001 From: Jordan Zeng <30739800+ruohai0925@users.noreply.github.com> Date: Tue, 4 Aug 2020 11:32:03 -0500 Subject: [PATCH] Add some user-defined parameters (#27) * Added the USE_LLG in the Make.WarpX * Added the macro USE_LLG and modified the related files * Modified the git style for pulling request * Modified the git style for pulling request * indentation * indentation fixes * Modified the git style for pulling request * Added the USE_LLG in the building.rst and changed one indentation in WarpX.cpp * HtoE and normalization of M field * ws * eolw * indentation * 2nd order of M field * tabs * eolw * Update the codes and the document * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: jackiezy <58234082+jackieyao0114@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: jackiezy <58234082+jackieyao0114@users.noreply.github.com> * Update Source/FieldSolver/WarpXPushFieldsEM.cpp Co-authored-by: Andy Nonaka * Update Source/Evolve/WarpXEvolve.cpp Co-authored-by: Andy Nonaka * Update Source/WarpX.H Co-authored-by: Andy Nonaka * Update Source/WarpX.H Co-authored-by: Andy Nonaka * Update Source/WarpX.cpp Co-authored-by: Andy Nonaka * Update Source/WarpX.cpp Co-authored-by: Andy Nonaka * Update Source/WarpX.cpp Co-authored-by: Andy Nonaka * Update Source/WarpX.cpp Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: jackiezy <58234082+jackieyao0114@users.noreply.github.com> * Update Source/Evolve/WarpXEvolve.cpp Co-authored-by: Andy Nonaka * some indentations * updateM_field * some comments * resolve some comments * tab * eolw * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> * documents * use-defined inputs * tabs * eols * indentation * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM_2nd.cpp Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveM.cpp Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H Co-authored-by: Andy Nonaka * Update Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H Co-authored-by: Andy Nonaka * parameters.rst * get to query Co-authored-by: Andy Nonaka Co-authored-by: jackiezy <58234082+jackieyao0114@users.noreply.github.com> Co-authored-by: Revathi Jambunathan <41089244+RevathiJambunathan@users.noreply.github.com> --- Docs/source/running_cpp/parameters.rst | 9 +++++++++ .../FiniteDifferenceSolver/MacroscopicEvolveM.cpp | 5 +++-- .../MacroscopicEvolveM_2nd.cpp | 7 ++++--- .../MacroscopicProperties/MacroscopicProperties.H | 15 +++++++++++++++ .../MacroscopicProperties.cpp | 10 ++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) 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 }