diff --git a/src/c_ggrid.cpp b/src/c_ggrid.cpp index 46b3a42..ceb8669 100644 --- a/src/c_ggrid.cpp +++ b/src/c_ggrid.cpp @@ -40,19 +40,23 @@ void c_ggrid::interpolate( nec_float x, nec_float y, nec_complex *f1, { static const int nda[3] = {11,17,9}, ndpa[3] = {110, 85, 72}; - bool recalculate = true; + /* A point below the cached region origin carries no valid index, so it + forces the coefficients to be rebuilt. */ + bool jump = false; - if( (x >= m_ip_xs) && (y >= m_ip_ys) ) { + if( (x < m_ip_xs) || (y < m_ip_ys) ) { + jump = true; + } else { m_ip_ix = static_cast((x - m_ip_xs) / m_ip_dx) + 1; m_ip_iy = static_cast((y - m_ip_ys) / m_ip_dy) + 1; - } else { - /* if point lies in same 4 by 4 point region */ - /* as previous point, old values are reused. */ - if ( ((m_ip_ix >= m_ip_ixeg) && (m_ip_iy >= m_ip_iyeg)) && - ((std::abs(m_ip_ix - m_ip_ixs) < 2) && (std::abs(m_ip_iy - m_ip_iys) < 2)) ) - recalculate = false; } + /* if point lies in same 4 by 4 point region */ + /* as previous point, old values are reused. */ + bool recalculate = jump || + (m_ip_ix < m_ip_ixeg) || (m_ip_iy < m_ip_iyeg) || + (std::abs(m_ip_ix - m_ip_ixs) >= 2) || (std::abs(m_ip_iy - m_ip_iys) >= 2); + if (true == recalculate) { /* determine correct grid and grid region */ int igr; diff --git a/src/nec_context.cpp b/src/nec_context.cpp index e6fb98e..08e4d9e 100644 --- a/src/nec_context.cpp +++ b/src/nec_context.cpp @@ -2975,7 +2975,7 @@ void nec_context::efld( nec_float xi, nec_float yi, nec_float zi, nec_float ai, rhox= sabj* zij- salpr* yij; rhoy= salpr* xij- cabj* zij; rhoz= cabj* yij- sabj* xij; - rh = norm(rhox, rhoy, rhoz); // rhox* rhox+ rhoy* rhoy+ rhoz* rhoz; + rh = norm2(rhox, rhoy, rhoz); if ( rh <= 1.e-10) { xo= xi- ai* ysn; @@ -5638,7 +5638,7 @@ void nec_context::rom2( nec_float a, nec_float b, complex_array& sum, nec_float WRITE(3,18) STOP */ - int nts = 4, nx = 1; + int nts = 4, nx = 1, nma = 65536; const int n = 9; nec_float rx = 1e-4; nec_float dz = 0.0; @@ -5666,7 +5666,7 @@ void nec_context::rom2( nec_float a, nec_float b, complex_array& sum, nec_float complex_array t01(9), t10(9), t20(9), t11(9); /*! tolerance for hitting upper limit */ - const nec_float ep = _s/(1.0e4 * m_geometry->n_plus_m()); + const nec_float ep = _s/(1.0e4 * nma); /*! upper limit */ const nec_float zend = ze - ep; @@ -5846,7 +5846,7 @@ C GO TO 5 */ nt=0; - if ( ns >= m_geometry->n_plus_m() ) + if ( ns >= nma ) { nec_error_mode em(m_output); m_output.string("ROM2 -- STEP SIZE LIMITED AT Z = "); @@ -5894,7 +5894,7 @@ void nec_context::rom2( nec_float a, nec_float b, complex_array& sum, nec_float bool recalculate_fields = true; - int nts = 4, nx = 1, n = 9; + int nts = 4, nx = 1, n = 9, nma = 65536; /*! subinterval size */ nec_float dz=0.0; @@ -5918,7 +5918,7 @@ void nec_context::rom2( nec_float a, nec_float b, complex_array& sum, nec_float } /*! tolerance for hitting upper limit */ - const nec_float ep = _s/(1.0e4 * m_geometry->n_plus_m()); + const nec_float ep = _s/(1.0e4 * nma); /*! upper limit */ const nec_float zend = ze - ep; @@ -6015,7 +6015,7 @@ void nec_context::rom2( nec_float a, nec_float b, complex_array& sum, nec_float if ( tr > rx) { nt=0; - if ( ns <= m_geometry->n_plus_m() ) + if ( ns <= nma ) { // halve step size ns = ns*2;