Example #1
0
void c_sqrt(const emlrtStack *sp, real_T *x)
{
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  if (*x < 0.0) {
    st.site = &f_emlrtRSI;
    eml_error(&st);
  }

  *x = muDoubleScalarSqrt(*x);
}
Example #2
0
void b_sqrt(real_T x[1000000])
{
  int32_T k;
  for (k = 0; k < 1000000; k++) {
    if (x[k] < 0.0) {
      emlrtPushRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
      eml_error();
      emlrtPopRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  for (k = 0; k < 1000000; k++) {
    x[k] = muDoubleScalarSqrt(x[k]);
  }
}
/* Function Definitions */
void JenkinsCompare(JenkinsCompareStackData *SD, const emlrtStack *sp, const
                    real_T x[78596], real_T sampleRate, emxArray_real_T *y)
{
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &emlrtRSI;
  b_st.prev = &st;
  b_st.tls = st.tls;
  if (sampleRate < 0.0) {
    b_st.site = &b_emlrtRSI;
    eml_error(&b_st);
  }

  st.site = &emlrtRSI;
  melcepst(SD, &st, x, sampleRate, muDoubleScalarFloor(3.0 * muDoubleScalarLog
            (sampleRate)), y);
}
Example #4
0
/* Function Definitions */
void do_vectors(const emlrtStack *sp, const real_T a_data[1224], const int32_T
                a_size[1], const real_T b[8], real_T c_data[8], int32_T c_size[1],
                int32_T ia_data[8], int32_T ia_size[1], int32_T ib_data[8],
                int32_T ib_size[1])
{
  int32_T ncmax;
  boolean_T y;
  int32_T ialast;
  boolean_T exitg4;
  boolean_T guard9 = FALSE;
  boolean_T p;
  boolean_T exitg3;
  boolean_T guard8 = FALSE;
  int32_T nc;
  int32_T iafirst;
  int32_T ibfirst;
  int32_T iblast;
  int32_T b_ialast;
  real_T ak;
  boolean_T exitg2;
  real_T absxk;
  int32_T exponent;
  boolean_T guard6 = FALSE;
  boolean_T guard7 = FALSE;
  int32_T b_iblast;
  real_T bk;
  boolean_T exitg1;
  int32_T b_exponent;
  boolean_T guard4 = FALSE;
  boolean_T guard5 = FALSE;
  int32_T c_exponent;
  boolean_T guard2 = FALSE;
  boolean_T guard3 = FALSE;
  boolean_T guard1 = FALSE;
  const mxArray *b_y;
  const mxArray *m20;
  int32_T b_ia_data[8];
  const mxArray *c_y;
  const mxArray *d_y;
  real_T b_c_data[8];
  emlrtStack st;
  st.prev = sp;
  st.tls = sp->tls;
  st.site = &fp_emlrtRSI;
  ncmax = muIntScalarMin_sint32(a_size[0], 8);
  c_size[0] = (int8_T)ncmax;
  ia_size[0] = ncmax;
  ib_size[0] = ncmax;
  st.site = &gp_emlrtRSI;
  y = TRUE;
  if (a_size[0] == 0) {
  } else {
    ialast = 1;
    exitg4 = FALSE;
    while ((exitg4 == FALSE) && (ialast <= a_size[0] - 1)) {
      guard9 = FALSE;
      if (a_data[ialast - 1] <= a_data[ialast]) {
        guard9 = TRUE;
      } else if (muDoubleScalarIsNaN(a_data[ialast])) {
        guard9 = TRUE;
      } else {
        p = FALSE;
      }

      if (guard9 == TRUE) {
        p = TRUE;
      }

      if (!p) {
        y = FALSE;
        exitg4 = TRUE;
      } else {
        ialast++;
      }
    }
  }

  if (!y) {
    st.site = &hp_emlrtRSI;
    eml_error(&st);
  }

  st.site = &ip_emlrtRSI;
  y = TRUE;
  ialast = 1;
  exitg3 = FALSE;
  while ((exitg3 == FALSE) && (ialast < 8)) {
    guard8 = FALSE;
    if (b[ialast - 1] <= b[ialast]) {
      guard8 = TRUE;
    } else if (muDoubleScalarIsNaN(b[ialast])) {
      guard8 = TRUE;
    } else {
      p = FALSE;
    }

    if (guard8 == TRUE) {
      p = TRUE;
    }

    if (!p) {
      y = FALSE;
      exitg3 = TRUE;
    } else {
      ialast++;
    }
  }

  if (!y) {
    st.site = &jp_emlrtRSI;
    b_eml_error(&st);
  }

  nc = 0;
  iafirst = 0;
  ialast = 0;
  ibfirst = 0;
  iblast = 0;
  while ((ialast + 1 <= a_size[0]) && (iblast + 1 <= 8)) {
    st.site = &kp_emlrtRSI;
    b_ialast = ialast + 1;
    ak = a_data[ialast];
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (b_ialast < a_size[0])) {
      absxk = muDoubleScalarAbs(a_data[ialast] / 2.0);
      if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
        if (absxk <= 2.2250738585072014E-308) {
          absxk = 4.94065645841247E-324;
        } else {
          frexp(absxk, &exponent);
          absxk = ldexp(1.0, exponent - 53);
        }
      } else {
        absxk = rtNaN;
      }

      guard6 = FALSE;
      guard7 = FALSE;
      if (muDoubleScalarAbs(a_data[ialast] - a_data[b_ialast]) < absxk) {
        guard7 = TRUE;
      } else if (muDoubleScalarIsInf(a_data[b_ialast])) {
        if (muDoubleScalarIsInf(a_data[ialast]) && ((a_data[b_ialast] > 0.0) ==
             (a_data[ialast] > 0.0))) {
          guard7 = TRUE;
        } else {
          guard6 = TRUE;
        }
      } else {
        guard6 = TRUE;
      }

      if (guard7 == TRUE) {
        p = TRUE;
      }

      if (guard6 == TRUE) {
        p = FALSE;
      }

      if (p) {
        b_ialast++;
      } else {
        exitg2 = TRUE;
      }
    }

    ialast = b_ialast - 1;
    st.site = &lp_emlrtRSI;
    b_iblast = iblast + 1;
    bk = b[iblast];
    exitg1 = FALSE;
    while ((exitg1 == FALSE) && (b_iblast < 8)) {
      absxk = muDoubleScalarAbs(b[iblast] / 2.0);
      if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
        if (absxk <= 2.2250738585072014E-308) {
          absxk = 4.94065645841247E-324;
        } else {
          frexp(absxk, &b_exponent);
          absxk = ldexp(1.0, b_exponent - 53);
        }
      } else {
        absxk = rtNaN;
      }

      guard4 = FALSE;
      guard5 = FALSE;
      if (muDoubleScalarAbs(b[iblast] - b[b_iblast]) < absxk) {
        guard5 = TRUE;
      } else if (muDoubleScalarIsInf(b[b_iblast])) {
        if (muDoubleScalarIsInf(b[iblast]) && ((b[b_iblast] > 0.0) == (b[iblast]
              > 0.0))) {
          guard5 = TRUE;
        } else {
          guard4 = TRUE;
        }
      } else {
        guard4 = TRUE;
      }

      if (guard5 == TRUE) {
        p = TRUE;
      }

      if (guard4 == TRUE) {
        p = FALSE;
      }

      if (p) {
        b_iblast++;
      } else {
        exitg1 = TRUE;
      }
    }

    iblast = b_iblast - 1;
    st.site = &mp_emlrtRSI;
    absxk = muDoubleScalarAbs(bk / 2.0);
    if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
      if (absxk <= 2.2250738585072014E-308) {
        absxk = 4.94065645841247E-324;
      } else {
        frexp(absxk, &c_exponent);
        absxk = ldexp(1.0, c_exponent - 53);
      }
    } else {
      absxk = rtNaN;
    }

    guard2 = FALSE;
    guard3 = FALSE;
    if (muDoubleScalarAbs(bk - ak) < absxk) {
      guard3 = TRUE;
    } else if (muDoubleScalarIsInf(ak)) {
      if (muDoubleScalarIsInf(bk) && ((ak > 0.0) == (bk > 0.0))) {
        guard3 = TRUE;
      } else {
        guard2 = TRUE;
      }
    } else {
      guard2 = TRUE;
    }

    if (guard3 == TRUE) {
      p = TRUE;
    }

    if (guard2 == TRUE) {
      p = FALSE;
    }

    if (p) {
      st.site = &np_emlrtRSI;
      nc++;
      c_data[nc - 1] = ak;
      ia_data[nc - 1] = iafirst + 1;
      ib_data[nc - 1] = ibfirst + 1;
      st.site = &op_emlrtRSI;
      ialast = b_ialast;
      iafirst = b_ialast;
      st.site = &pp_emlrtRSI;
      iblast = b_iblast;
      ibfirst = b_iblast;
    } else {
      st.site = &qp_emlrtRSI;
      guard1 = FALSE;
      if (ak < bk) {
        guard1 = TRUE;
      } else if (muDoubleScalarIsNaN(bk)) {
        guard1 = TRUE;
      } else {
        p = FALSE;
      }

      if (guard1 == TRUE) {
        p = TRUE;
      }

      if (p) {
        st.site = &rp_emlrtRSI;
        ialast = b_ialast;
        iafirst = b_ialast;
      } else {
        st.site = &sp_emlrtRSI;
        iblast = b_iblast;
        ibfirst = b_iblast;
      }
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      b_y = NULL;
      m20 = mxCreateString("Assertion failed.");
      emlrtAssign(&b_y, m20);
      st.site = &yt_emlrtRSI;
      b_error(&st, b_y, &y_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_ia_data[iafirst] = ia_data[iafirst];
    }

    ia_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      ia_data[iafirst] = b_ia_data[iafirst];
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      c_y = NULL;
      m20 = mxCreateString("Assertion failed.");
      emlrtAssign(&c_y, m20);
      st.site = &xt_emlrtRSI;
      b_error(&st, c_y, &ab_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_ia_data[iafirst] = ib_data[iafirst];
    }

    ib_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      ib_data[iafirst] = b_ia_data[iafirst];
    }
  }

  if (ncmax > 0) {
    if (nc <= ncmax) {
    } else {
      d_y = NULL;
      m20 = mxCreateString("Assertion failed.");
      emlrtAssign(&d_y, m20);
      st.site = &wt_emlrtRSI;
      b_error(&st, d_y, &bb_emlrtMCI);
    }

    if (1 > nc) {
      ialast = 0;
    } else {
      ialast = nc;
    }

    for (iafirst = 0; iafirst < ialast; iafirst++) {
      b_c_data[iafirst] = c_data[iafirst];
    }

    c_size[0] = ialast;
    for (iafirst = 0; iafirst < ialast; iafirst++) {
      c_data[iafirst] = b_c_data[iafirst];
    }
  }
}
Example #5
0
/* Function Definitions */
void MechanicalPointForce(const emlrtStack *sp, const emxArray_real_T
  *particlePosition, const emxArray_real_T *pointSourcePosition, real_T
  forceDirection, real_T forceMagnitude, real_T cutoff, emxArray_real_T *force)
{
  uint32_T sz[2];
  int32_T ix;
  emxArray_real_T *forceTemp;
  int32_T loop_ub;
  emxArray_real_T *forceMag;
  int32_T vlen;
  int32_T sIdx;
  emxArray_real_T *forceDir;
  emxArray_real_T *distToSource;
  emxArray_int32_T *r0;
  emxArray_boolean_T *r1;
  emxArray_int32_T *r2;
  emxArray_real_T *x;
  emxArray_real_T *b_x;
  emxArray_real_T *r3;
  emxArray_real_T *r4;
  emxArray_real_T *b_pointSourcePosition;
  emxArray_real_T *b_forceDir;
  emxArray_real_T *c_forceDir;
  int32_T k;
  int32_T vstride;
  int32_T iy;
  int32_T ixstart;
  boolean_T overflow;
  real_T s;
  boolean_T b0;
  uint32_T varargin_2[2];
  boolean_T p;
  boolean_T exitg1;
  int32_T iv0[1];
  int32_T iv1[2];
  int32_T b_force[2];
  int32_T iv2[1];
  int32_T b_iy;
  int32_T c_iy;
  int32_T b_forceTemp[2];
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);

  /*  apply mechanical (push or pull) force on particles */
  /*  mechanicalForce is a logical flag  */
  /*  particlPosition is a N by 3 vector of particle position */
  /*  pointSourcePosition is the position of force sources  */
  /*  forceDirection is either  -1 for 'in' or 1 for 'out' */
  /*  forceMagnitude is a positive number between 0 and 1 */
  /*  cutoff is the maximal direction the force operates on particle relative */
  /*  to the pointSourcePosition  */
  /*  the output is a vector of N by 3 of delta position to th */
  for (ix = 0; ix < 2; ix++) {
    sz[ix] = (uint32_T)particlePosition->size[ix];
  }

  emxInit_real_T(sp, &forceTemp, 2, &c_emlrtRTEI, true);
  ix = forceTemp->size[0] * forceTemp->size[1];
  forceTemp->size[0] = (int32_T)sz[0];
  emxEnsureCapacity(sp, (emxArray__common *)forceTemp, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  ix = forceTemp->size[0] * forceTemp->size[1];
  forceTemp->size[1] = (int32_T)sz[1];
  emxEnsureCapacity(sp, (emxArray__common *)forceTemp, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  loop_ub = (int32_T)sz[0] * (int32_T)sz[1];
  for (ix = 0; ix < loop_ub; ix++) {
    forceTemp->data[ix] = 0.0;
  }

  for (ix = 0; ix < 2; ix++) {
    sz[ix] = (uint32_T)particlePosition->size[ix];
  }

  ix = force->size[0] * force->size[1];
  force->size[0] = (int32_T)sz[0];
  emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  ix = force->size[0] * force->size[1];
  force->size[1] = (int32_T)sz[1];
  emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  loop_ub = (int32_T)sz[0] * (int32_T)sz[1];
  for (ix = 0; ix < loop_ub; ix++) {
    force->data[ix] = 0.0;
  }

  emxInit_real_T(sp, &forceMag, 2, &d_emlrtRTEI, true);
  vlen = particlePosition->size[0];
  ix = forceMag->size[0] * forceMag->size[1];
  forceMag->size[0] = vlen;
  emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  vlen = particlePosition->size[0];
  ix = forceMag->size[0] * forceMag->size[1];
  forceMag->size[1] = vlen;
  emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  loop_ub = particlePosition->size[0] * particlePosition->size[0];
  for (ix = 0; ix < loop_ub; ix++) {
    forceMag->data[ix] = 0.0;
  }

  sIdx = 0;
  emxInit_real_T(sp, &forceDir, 2, &e_emlrtRTEI, true);
  b_emxInit_real_T(sp, &distToSource, 1, &f_emlrtRTEI, true);
  emxInit_int32_T(sp, &r0, 1, &emlrtRTEI, true);
  emxInit_boolean_T(sp, &r1, 2, &emlrtRTEI, true);
  emxInit_int32_T(sp, &r2, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &x, 2, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &b_x, 1, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &r3, 1, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &r4, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &b_pointSourcePosition, 2, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &b_forceDir, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &c_forceDir, 2, &emlrtRTEI, true);
  while (sIdx <= pointSourcePosition->size[0] - 1) {
    loop_ub = pointSourcePosition->size[1];
    ix = pointSourcePosition->size[0];
    if ((sIdx + 1 >= 1) && (sIdx + 1 < ix)) {
      vlen = sIdx + 1;
    } else {
      vlen = emlrtDynamicBoundsCheckR2012b(sIdx + 1, 1, ix, (emlrtBCInfo *)
        &e_emlrtBCI, sp);
    }

    ix = b_pointSourcePosition->size[0] * b_pointSourcePosition->size[1];
    b_pointSourcePosition->size[0] = 1;
    b_pointSourcePosition->size[1] = loop_ub;
    emxEnsureCapacity(sp, (emxArray__common *)b_pointSourcePosition, ix,
                      (int32_T)sizeof(real_T), &emlrtRTEI);
    for (ix = 0; ix < loop_ub; ix++) {
      b_pointSourcePosition->data[b_pointSourcePosition->size[0] * ix] =
        pointSourcePosition->data[(vlen + pointSourcePosition->size[0] * ix) - 1];
    }

    st.site = &emlrtRSI;
    bsxfun(&st, particlePosition, b_pointSourcePosition, forceDir);

    /*  Find the distance between the particles and the source */
    st.site = &b_emlrtRSI;
    b_st.site = &h_emlrtRSI;
    c_st.site = &i_emlrtRSI;
    d_st.site = &j_emlrtRSI;
    for (ix = 0; ix < 2; ix++) {
      sz[ix] = (uint32_T)forceDir->size[ix];
    }

    ix = x->size[0] * x->size[1];
    x->size[0] = (int32_T)sz[0];
    x->size[1] = (int32_T)sz[1];
    emxEnsureCapacity(&d_st, (emxArray__common *)x, ix, (int32_T)sizeof(real_T),
                      &b_emlrtRTEI);
    if (dimagree(x, forceDir)) {
    } else {
      emlrtErrorWithMessageIdR2012b(&d_st, &b_emlrtRTEI, "MATLAB:dimagree", 0);
    }

    ix = (int32_T)sz[0] * (int32_T)sz[1];
    for (k = 0; k < ix; k++) {
      x->data[k] = forceDir->data[k] * forceDir->data[k];
    }

    st.site = &b_emlrtRSI;
    b_st.site = &k_emlrtRSI;
    c_st.site = &l_emlrtRSI;
    for (ix = 0; ix < 2; ix++) {
      sz[ix] = (uint32_T)x->size[ix];
    }

    ix = b_x->size[0];
    b_x->size[0] = (int32_T)sz[0];
    emxEnsureCapacity(&c_st, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                      &emlrtRTEI);
    if ((x->size[0] == 0) || (x->size[1] == 0)) {
      ix = b_x->size[0];
      b_x->size[0] = (int32_T)sz[0];
      emxEnsureCapacity(&c_st, (emxArray__common *)b_x, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      loop_ub = (int32_T)sz[0];
      for (ix = 0; ix < loop_ub; ix++) {
        b_x->data[ix] = 0.0;
      }
    } else {
      vlen = x->size[1];
      vstride = x->size[0];
      iy = -1;
      ixstart = -1;
      d_st.site = &m_emlrtRSI;
      overflow = (x->size[0] > 2147483646);
      if (overflow) {
        e_st.site = &g_emlrtRSI;
        check_forloop_overflow_error(&e_st);
      }

      for (loop_ub = 1; loop_ub <= vstride; loop_ub++) {
        ixstart++;
        ix = ixstart;
        s = x->data[ixstart];
        d_st.site = &n_emlrtRSI;
        if (2 > vlen) {
          b0 = false;
        } else {
          b0 = (vlen > 2147483646);
        }

        if (b0) {
          e_st.site = &g_emlrtRSI;
          check_forloop_overflow_error(&e_st);
        }

        for (k = 2; k <= vlen; k++) {
          ix += vstride;
          s += x->data[ix];
        }

        iy++;
        b_x->data[iy] = s;
      }
    }

    st.site = &b_emlrtRSI;
    ix = distToSource->size[0];
    distToSource->size[0] = b_x->size[0];
    emxEnsureCapacity(&st, (emxArray__common *)distToSource, ix, (int32_T)sizeof
                      (real_T), &emlrtRTEI);
    loop_ub = b_x->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      distToSource->data[ix] = b_x->data[ix];
    }

    for (k = 0; k < b_x->size[0]; k++) {
      if (b_x->data[k] < 0.0) {
        b_st.site = &o_emlrtRSI;
        eml_error(&b_st);
      }
    }

    for (k = 0; k < b_x->size[0]; k++) {
      distToSource->data[k] = muDoubleScalarSqrt(distToSource->data[k]);
    }

    /*  Normalize the forceDirection */
    iy = 0;
    while (iy < 3) {
      loop_ub = forceDir->size[0];
      ix = r2->size[0];
      r2->size[0] = loop_ub;
      emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        r2->data[ix] = ix;
      }

      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&c_emlrtBCI,
        sp);
      st.site = &c_emlrtRSI;
      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&d_emlrtBCI,
        &st);
      ix = forceDir->size[0];
      sz[0] = (uint32_T)ix;
      sz[1] = 1U;
      varargin_2[0] = (uint32_T)distToSource->size[0];
      varargin_2[1] = 1U;
      overflow = false;
      p = true;
      k = 0;
      exitg1 = false;
      while ((!exitg1) && (k < 2)) {
        if (!((int32_T)sz[k] == (int32_T)varargin_2[k])) {
          p = false;
          exitg1 = true;
        } else {
          k++;
        }
      }

      if (!p) {
      } else {
        overflow = true;
      }

      if (overflow) {
      } else {
        emlrtErrorWithMessageIdR2012b(&st, &l_emlrtRTEI, "MATLAB:dimagree", 0);
      }

      loop_ub = forceDir->size[0];
      ix = b_x->size[0];
      b_x->size[0] = loop_ub;
      emxEnsureCapacity(&st, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        b_x->data[ix] = forceDir->data[ix + forceDir->size[0] * iy] /
          distToSource->data[ix];
      }

      iv0[0] = r2->size[0];
      emlrtSubAssignSizeCheckR2012b(iv0, 1, *(int32_T (*)[1])b_x->size, 1,
        (emlrtECInfo *)&d_emlrtECI, sp);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceDir->data[r2->data[ix] + forceDir->size[0] * iy] = b_x->data[ix];
      }

      /*  bsxfun(@rdivide,forceDir,distToSource); */
      iy++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    /*  Multiply the */
    if (forceDirection == -1.0) {
      ix = r4->size[0];
      r4->size[0] = distToSource->size[0];
      emxEnsureCapacity(sp, (emxArray__common *)r4, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      loop_ub = distToSource->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        r4->data[ix] = 1.0 + distToSource->data[ix];
      }

      rdivide(sp, forceMagnitude, r4, b_x);
      vlen = b_x->size[0];
      ix = forceMag->size[0] * forceMag->size[1];
      forceMag->size[0] = vlen;
      emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      ix = forceMag->size[0] * forceMag->size[1];
      forceMag->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceMag->data[ix] = 1.0 - b_x->data[ix];
      }
    } else {
      if (forceDirection == 1.0) {
        ix = r3->size[0];
        r3->size[0] = distToSource->size[0];
        emxEnsureCapacity(sp, (emxArray__common *)r3, ix, (int32_T)sizeof(real_T),
                          &emlrtRTEI);
        loop_ub = distToSource->size[0];
        for (ix = 0; ix < loop_ub; ix++) {
          r3->data[ix] = 1.0 + distToSource->data[ix];
        }

        rdivide(sp, forceMagnitude, r3, b_x);
        vlen = b_x->size[0];
        ix = forceMag->size[0] * forceMag->size[1];
        forceMag->size[0] = vlen;
        emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                          (real_T), &emlrtRTEI);
        ix = forceMag->size[0] * forceMag->size[1];
        forceMag->size[1] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                          (real_T), &emlrtRTEI);
        loop_ub = b_x->size[0];
        for (ix = 0; ix < loop_ub; ix++) {
          forceMag->data[ix] = b_x->data[ix];
        }
      }
    }

    iy = 0;
    while (iy < 3) {
      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&b_emlrtBCI,
        sp);
      ix = forceDir->size[0];
      iv1[0] = ix;
      iv1[1] = 1;
      for (ix = 0; ix < 2; ix++) {
        b_force[ix] = forceMag->size[ix];
      }

      if ((iv1[0] != b_force[0]) || (1 != b_force[1])) {
        emlrtSizeEqCheckNDR2012b(iv1, b_force, (emlrtECInfo *)&c_emlrtECI, sp);
      }

      loop_ub = forceTemp->size[0];
      ix = r2->size[0];
      r2->size[0] = loop_ub;
      emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        r2->data[ix] = ix;
      }

      ix = forceTemp->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&emlrtBCI, sp);
      loop_ub = forceDir->size[0];
      vlen = forceDir->size[0];
      vstride = forceDir->size[0];
      ix = b_forceDir->size[0];
      b_forceDir->size[0] = vstride;
      emxEnsureCapacity(sp, (emxArray__common *)b_forceDir, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < vstride; ix++) {
        b_forceDir->data[ix] = forceDir->data[ix + forceDir->size[0] * iy];
      }

      ix = c_forceDir->size[0] * c_forceDir->size[1];
      c_forceDir->size[0] = loop_ub;
      c_forceDir->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)c_forceDir, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        c_forceDir->data[ix] = b_forceDir->data[ix];
      }

      ix = b_x->size[0];
      b_x->size[0] = vlen;
      emxEnsureCapacity(sp, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      for (ix = 0; ix < vlen; ix++) {
        b_x->data[ix] = c_forceDir->data[ix] * forceMag->data[ix];
      }

      iv2[0] = r2->size[0];
      emlrtSubAssignSizeCheckR2012b(iv2, 1, *(int32_T (*)[1])b_x->size, 1,
        (emlrtECInfo *)&b_emlrtECI, sp);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceTemp->data[r2->data[ix] + forceTemp->size[0] * iy] = b_x->data[ix];
      }

      /*  bsxfun(@times,forceDir,forceTemp); */
      iy++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    iy = distToSource->size[0] - 1;
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (distToSource->data[vstride] > cutoff) {
        vlen++;
      }
    }

    ix = r2->size[0];
    r2->size[0] = vlen;
    emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                      &emlrtRTEI);
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (distToSource->data[vstride] > cutoff) {
        r2->data[vlen] = vstride + 1;
        vlen++;
      }
    }

    loop_ub = forceTemp->size[1];
    vstride = forceTemp->size[0];
    vlen = r2->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      for (ixstart = 0; ixstart < vlen; ixstart++) {
        iy = r2->data[ixstart];
        if ((iy >= 1) && (iy < vstride)) {
          b_iy = iy;
        } else {
          b_iy = emlrtDynamicBoundsCheckR2012b(iy, 1, vstride, (emlrtBCInfo *)
            &f_emlrtBCI, sp);
        }

        forceTemp->data[(b_iy + forceTemp->size[0] * ix) - 1] = 0.0;
      }
    }

    ix = r1->size[0] * r1->size[1];
    r1->size[0] = forceTemp->size[0];
    r1->size[1] = forceTemp->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)r1, ix, (int32_T)sizeof(boolean_T),
                      &emlrtRTEI);
    loop_ub = forceTemp->size[0] * forceTemp->size[1];
    for (ix = 0; ix < loop_ub; ix++) {
      r1->data[ix] = muDoubleScalarIsNaN(forceTemp->data[ix]);
    }

    iy = r1->size[0] * r1->size[1] - 1;
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (r1->data[vstride]) {
        vlen++;
      }
    }

    ix = r0->size[0];
    r0->size[0] = vlen;
    emxEnsureCapacity(sp, (emxArray__common *)r0, ix, (int32_T)sizeof(int32_T),
                      &emlrtRTEI);
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (r1->data[vstride]) {
        r0->data[vlen] = vstride + 1;
        vlen++;
      }
    }

    vstride = forceTemp->size[0];
    vlen = forceTemp->size[1];
    loop_ub = r0->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      ixstart = vstride * vlen;
      iy = r0->data[ix];
      if ((iy >= 1) && (iy < ixstart)) {
        c_iy = iy;
      } else {
        c_iy = emlrtDynamicBoundsCheckR2012b(iy, 1, ixstart, (emlrtBCInfo *)
          &g_emlrtBCI, sp);
      }

      forceTemp->data[c_iy - 1] = 0.0;
    }

    for (ix = 0; ix < 2; ix++) {
      b_force[ix] = force->size[ix];
    }

    for (ix = 0; ix < 2; ix++) {
      b_forceTemp[ix] = forceTemp->size[ix];
    }

    if ((b_force[0] != b_forceTemp[0]) || (b_force[1] != b_forceTemp[1])) {
      emlrtSizeEqCheckNDR2012b(b_force, b_forceTemp, (emlrtECInfo *)&emlrtECI,
        sp);
    }

    ix = force->size[0] * force->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                      &emlrtRTEI);
    vlen = force->size[0];
    vstride = force->size[1];
    loop_ub = vlen * vstride;
    for (ix = 0; ix < loop_ub; ix++) {
      force->data[ix] += forceTemp->data[ix];
    }

    sIdx++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_real_T(&c_forceDir);
  emxFree_real_T(&b_forceDir);
  emxFree_real_T(&b_pointSourcePosition);
  emxFree_real_T(&r4);
  emxFree_real_T(&r3);
  emxFree_real_T(&b_x);
  emxFree_real_T(&x);
  emxFree_int32_T(&r2);
  emxFree_boolean_T(&r1);
  emxFree_int32_T(&r0);
  emxFree_real_T(&distToSource);
  emxFree_real_T(&forceDir);
  emxFree_real_T(&forceMag);
  emxFree_real_T(&forceTemp);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Example #6
0
/* Function Definitions */
void rsf2csf(const emxArray_real_T *Ur, const emxArray_real_T *Tr,
             emxArray_creal_T *U, emxArray_creal_T *T)
{
  int32_T y;
  int32_T loop_ub;
  int16_T varargin_1[2];
  int32_T mtmp;
  int32_T m;
  real_T c;
  real_T b;
  real_T temp;
  real_T p;
  real_T bcmax;
  real_T scale;
  real_T bb;
  real_T b_p;
  real_T cs;
  int32_T b_scale;
  real_T b_c;
  real_T mu1_re;
  emlrtPushRtStackR2012b(&bh_emlrtRSI, emlrtRootTLSGlobal);
  y = T->size[0] * T->size[1];
  T->size[0] = Tr->size[0];
  T->size[1] = Tr->size[1];
  emxEnsureCapacity((emxArray__common *)T, y, (int32_T)sizeof(creal_T),
                    &v_emlrtRTEI);
  loop_ub = Tr->size[0] * Tr->size[1];
  for (y = 0; y < loop_ub; y++) {
    T->data[y].re = Tr->data[y];
    T->data[y].im = 0.0;
  }

  y = U->size[0] * U->size[1];
  U->size[0] = Ur->size[0];
  U->size[1] = Ur->size[1];
  emxEnsureCapacity((emxArray__common *)U, y, (int32_T)sizeof(creal_T),
                    &v_emlrtRTEI);
  loop_ub = Ur->size[0] * Ur->size[1];
  for (y = 0; y < loop_ub; y++) {
    U->data[y].re = Ur->data[y];
    U->data[y].im = 0.0;
  }

  for (y = 0; y < 2; y++) {
    varargin_1[y] = (int16_T)Tr->size[y];
  }

  mtmp = varargin_1[0];
  if (varargin_1[1] < varargin_1[0]) {
    mtmp = varargin_1[1];
  }

  for (y = 0; y < 2; y++) {
    varargin_1[y] = (int16_T)Ur->size[y];
  }

  loop_ub = varargin_1[0];
  if (varargin_1[1] < varargin_1[0]) {
    loop_ub = varargin_1[1];
  }

  mtmp = (int32_T)muDoubleScalarMin(mtmp, loop_ub);
  if (mtmp == 0) {
  } else {
    for (m = mtmp - 1; m + 1 >= 2; m--) {
      if (Tr->data[m + Tr->size[0] * (m - 1)] != 0.0) {
        emlrtPushRtStackR2012b(&ch_emlrtRSI, emlrtRootTLSGlobal);
        c = Tr->data[m + Tr->size[0] * (m - 1)];
        b = Tr->data[(m + Tr->size[0] * m) - 1];
        temp = Tr->data[(m + Tr->size[0] * (m - 1)) - 1];
        if (Tr->data[m + Tr->size[0] * (m - 1)] == 0.0) {
        } else if (Tr->data[(m + Tr->size[0] * m) - 1] == 0.0) {
          temp = Tr->data[m + Tr->size[0] * m];
          b = -Tr->data[m + Tr->size[0] * (m - 1)];
          c = 0.0;
        } else if ((Tr->data[(m + Tr->size[0] * (m - 1)) - 1] - Tr->data[m +
                    Tr->size[0] * m] == 0.0) && ((Tr->data[(m + Tr->size[0] * m)
          - 1] < 0.0) != (Tr->data[m + Tr->size[0] * (m - 1)] < 0.0))) {
        } else {
          temp = Tr->data[(m + Tr->size[0] * (m - 1)) - 1] - Tr->data[m +
            Tr->size[0] * m];
          p = 0.5 * temp;
          bcmax = muDoubleScalarMax(muDoubleScalarAbs(Tr->data[(m + Tr->size[0] *
            m) - 1]), muDoubleScalarAbs(Tr->data[m + Tr->size[0] * (m - 1)]));
          if (!(Tr->data[(m + Tr->size[0] * m) - 1] < 0.0)) {
            loop_ub = 1;
          } else {
            loop_ub = -1;
          }

          if (!(Tr->data[m + Tr->size[0] * (m - 1)] < 0.0)) {
            y = 1;
          } else {
            y = -1;
          }

          scale = muDoubleScalarMax(muDoubleScalarAbs(p), bcmax);
          bcmax = p / scale * p + bcmax / scale * (muDoubleScalarMin
            (muDoubleScalarAbs(Tr->data[(m + Tr->size[0] * m) - 1]),
             muDoubleScalarAbs(Tr->data[m + Tr->size[0] * (m - 1)])) * (real_T)
            loop_ub * (real_T)y);
          if (bcmax >= 8.8817841970012523E-16) {
            emlrtPushRtStackR2012b(&gg_emlrtRSI, emlrtRootTLSGlobal);
            bb = muDoubleScalarSqrt(scale) * muDoubleScalarSqrt(bcmax);
            emlrtPopRtStackR2012b(&gg_emlrtRSI, emlrtRootTLSGlobal);
            if (!(p < 0.0)) {
              b_p = bb;
            } else {
              b_p = -bb;
            }

            temp = Tr->data[m + Tr->size[0] * m] + (p + b_p);
            b = Tr->data[(m + Tr->size[0] * m) - 1] - Tr->data[m + Tr->size[0] *
              (m - 1)];
            c = 0.0;
          } else {
            scale = Tr->data[(m + Tr->size[0] * m) - 1] + Tr->data[m + Tr->size
              [0] * (m - 1)];
            bcmax = muDoubleScalarHypot(scale, temp);
            emlrtPushRtStackR2012b(&hg_emlrtRSI, emlrtRootTLSGlobal);
            bb = 0.5 * (1.0 + muDoubleScalarAbs(scale) / bcmax);
            if (bb < 0.0) {
              emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
              eml_error();
              emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
            }

            cs = muDoubleScalarSqrt(bb);
            emlrtPopRtStackR2012b(&hg_emlrtRSI, emlrtRootTLSGlobal);
            if (!(scale < 0.0)) {
              b_scale = 1;
            } else {
              b_scale = -1;
            }

            bcmax = -(p / (bcmax * cs)) * (real_T)b_scale;
            scale = Tr->data[(m + Tr->size[0] * (m - 1)) - 1] * cs + Tr->data[(m
              + Tr->size[0] * m) - 1] * bcmax;
            bb = -Tr->data[(m + Tr->size[0] * (m - 1)) - 1] * bcmax + Tr->data
              [(m + Tr->size[0] * m) - 1] * cs;
            p = Tr->data[m + Tr->size[0] * (m - 1)] * cs + Tr->data[m + Tr->
              size[0] * m] * bcmax;
            temp = -Tr->data[m + Tr->size[0] * (m - 1)] * bcmax + Tr->data[m +
              Tr->size[0] * m] * cs;
            b = bb * cs + temp * bcmax;
            c = -scale * bcmax + p * cs;
            temp = 0.5 * ((scale * cs + p * bcmax) + (-bb * bcmax + temp * cs));
            if (c != 0.0) {
              if (b != 0.0) {
                if ((b < 0.0) == (c < 0.0)) {
                  emlrtPushRtStackR2012b(&ig_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&ig_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPushRtStackR2012b(&jg_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&jg_emlrtRSI, emlrtRootTLSGlobal);
                  bb = muDoubleScalarSqrt(muDoubleScalarAbs(b)) *
                    muDoubleScalarSqrt(muDoubleScalarAbs(c));
                  emlrtPushRtStackR2012b(&kg_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&kg_emlrtRSI, emlrtRootTLSGlobal);
                  if (!(c < 0.0)) {
                    b_c = bb;
                  } else {
                    b_c = -bb;
                  }

                  temp += b_c;
                  b -= c;
                  c = 0.0;
                }
              } else {
                b = -c;
                c = 0.0;
              }
            }
          }
        }

        if (c == 0.0) {
          bcmax = 0.0;
        } else {
          emlrtPushRtStackR2012b(&lg_emlrtRSI, emlrtRootTLSGlobal);
          bcmax = muDoubleScalarSqrt(muDoubleScalarAbs(b)) * muDoubleScalarSqrt
            (muDoubleScalarAbs(c));
          emlrtPopRtStackR2012b(&lg_emlrtRSI, emlrtRootTLSGlobal);
        }

        emlrtPopRtStackR2012b(&ch_emlrtRSI, emlrtRootTLSGlobal);
        mu1_re = temp - Tr->data[m + Tr->size[0] * m];
        scale = muDoubleScalarHypot(muDoubleScalarHypot(mu1_re, bcmax), Tr->
          data[m + Tr->size[0] * (m - 1)]);
        if (bcmax == 0.0) {
          mu1_re /= scale;
          cs = 0.0;
        } else if (mu1_re == 0.0) {
          mu1_re = 0.0;
          cs = bcmax / scale;
        } else {
          mu1_re /= scale;
          cs = bcmax / scale;
        }

        c = Tr->data[m + Tr->size[0] * (m - 1)] / scale;
        emlrtPushRtStackR2012b(&dh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&dh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = m - 1; loop_ub + 1 <= mtmp; loop_ub++) {
          b = T->data[(m + T->size[0] * loop_ub) - 1].re;
          temp = T->data[(m + T->size[0] * loop_ub) - 1].im;
          bb = T->data[(m + T->size[0] * loop_ub) - 1].re;
          p = T->data[(m + T->size[0] * loop_ub) - 1].im;
          bcmax = T->data[(m + T->size[0] * loop_ub) - 1].im;
          scale = T->data[(m + T->size[0] * loop_ub) - 1].re;
          T->data[(m + T->size[0] * loop_ub) - 1].re = (mu1_re * bb + cs * p) +
            c * T->data[m + T->size[0] * loop_ub].re;
          T->data[(m + T->size[0] * loop_ub) - 1].im = (mu1_re * bcmax - cs *
            scale) + c * T->data[m + T->size[0] * loop_ub].im;
          bcmax = mu1_re * T->data[m + T->size[0] * loop_ub].re - cs * T->data[m
            + T->size[0] * loop_ub].im;
          scale = mu1_re * T->data[m + T->size[0] * loop_ub].im + cs * T->data[m
            + T->size[0] * loop_ub].re;
          T->data[m + T->size[0] * loop_ub].re = bcmax - c * b;
          T->data[m + T->size[0] * loop_ub].im = scale - c * temp;
        }

        emlrtPushRtStackR2012b(&eh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&eh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = 0; loop_ub + 1 <= m + 1; loop_ub++) {
          b = T->data[loop_ub + T->size[0] * (m - 1)].re;
          temp = T->data[loop_ub + T->size[0] * (m - 1)].im;
          bcmax = mu1_re * T->data[loop_ub + T->size[0] * (m - 1)].re - cs *
            T->data[loop_ub + T->size[0] * (m - 1)].im;
          scale = mu1_re * T->data[loop_ub + T->size[0] * (m - 1)].im + cs *
            T->data[loop_ub + T->size[0] * (m - 1)].re;
          bb = T->data[loop_ub + T->size[0] * m].re;
          p = T->data[loop_ub + T->size[0] * m].im;
          T->data[loop_ub + T->size[0] * (m - 1)].re = bcmax + c * bb;
          T->data[loop_ub + T->size[0] * (m - 1)].im = scale + c * p;
          bb = T->data[loop_ub + T->size[0] * m].re;
          p = T->data[loop_ub + T->size[0] * m].im;
          bcmax = T->data[loop_ub + T->size[0] * m].im;
          scale = T->data[loop_ub + T->size[0] * m].re;
          T->data[loop_ub + T->size[0] * m].re = (mu1_re * bb + cs * p) - c * b;
          T->data[loop_ub + T->size[0] * m].im = (mu1_re * bcmax - cs * scale) -
            c * temp;
        }

        emlrtPushRtStackR2012b(&fh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&fh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = 0; loop_ub + 1 <= mtmp; loop_ub++) {
          b = U->data[loop_ub + U->size[0] * (m - 1)].re;
          temp = U->data[loop_ub + U->size[0] * (m - 1)].im;
          bcmax = mu1_re * U->data[loop_ub + U->size[0] * (m - 1)].re - cs *
            U->data[loop_ub + U->size[0] * (m - 1)].im;
          scale = mu1_re * U->data[loop_ub + U->size[0] * (m - 1)].im + cs *
            U->data[loop_ub + U->size[0] * (m - 1)].re;
          bb = U->data[loop_ub + U->size[0] * m].re;
          p = U->data[loop_ub + U->size[0] * m].im;
          U->data[loop_ub + U->size[0] * (m - 1)].re = bcmax + c * bb;
          U->data[loop_ub + U->size[0] * (m - 1)].im = scale + c * p;
          bb = U->data[loop_ub + U->size[0] * m].re;
          p = U->data[loop_ub + U->size[0] * m].im;
          bcmax = U->data[loop_ub + U->size[0] * m].im;
          scale = U->data[loop_ub + U->size[0] * m].re;
          U->data[loop_ub + U->size[0] * m].re = (mu1_re * bb + cs * p) - c * b;
          U->data[loop_ub + U->size[0] * m].im = (mu1_re * bcmax - cs * scale) -
            c * temp;
        }

        T->data[m + T->size[0] * (m - 1)].re = 0.0;
        T->data[m + T->size[0] * (m - 1)].im = 0.0;
      }
    }
  }

  emlrtPopRtStackR2012b(&bh_emlrtRSI, emlrtRootTLSGlobal);
}
Example #7
0
/* Function Definitions */
real_T Bcoeff(const emlrtStack *sp, real_T ksi, real_T j, real_T x, real_T t,
              const emxArray_real_T *gridT)
{
  real_T vals;
  int32_T k;
  int32_T i1;
  boolean_T b_x[3];
  boolean_T y;
  boolean_T exitg2;
  boolean_T exitg1;
  real_T c_x;
  real_T d_x;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;

  /*  evaluate the coefficient B at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  k = gridT->size[1];
  i1 = (int32_T)emlrtIntegerCheckFastR2012b(j, &b_emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k, &n_emlrtBCI,
       sp) - 1]) {
    vals = 0.0;
  } else {
    k = gridT->size[1];
    i1 = (int32_T)j;
    b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
               &o_emlrtBCI, sp) - 1]);
    k = gridT->size[1];
    i1 = (int32_T)((uint32_T)j + 1U);
    b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
               &p_emlrtBCI, sp) - 1]);
    b_x[2] = (x == ksi);
    y = true;
    k = 0;
    exitg2 = false;
    while ((!exitg2) && (k < 3)) {
      if (b_x[k] == 0) {
        y = false;
        exitg2 = true;
      } else {
        k++;
      }
    }

    if (y) {
      vals = 0.0;
    } else {
      k = gridT->size[1];
      i1 = (int32_T)j;
      b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
                 &q_emlrtBCI, sp) - 1]);
      k = gridT->size[1];
      i1 = (int32_T)((uint32_T)j + 1U);
      b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
                 &r_emlrtBCI, sp) - 1]);
      b_x[2] = (x != ksi);
      y = true;
      k = 0;
      exitg1 = false;
      while ((!exitg1) && (k < 3)) {
        if (b_x[k] == 0) {
          y = false;
          exitg1 = true;
        } else {
          k++;
        }
      }

      if (y) {
        st.site = &g_emlrtRSI;
        k = gridT->size[1];
        i1 = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
          &v_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        vals = -scalar_erf(muDoubleScalarAbs(x - ksi) / (2.0 *
          muDoubleScalarSqrt(c_x))) / 2.0;
      } else {
        k = gridT->size[1];
        i1 = (int32_T)((uint32_T)j + 1U);
        if (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
             &s_emlrtBCI, sp) - 1]) {
          st.site = &h_emlrtRSI;
          k = gridT->size[1];
          i1 = (int32_T)j;
          c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
            &t_emlrtBCI, &st) - 1];
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &i_emlrtRSI;
          k = gridT->size[1];
          i1 = (int32_T)((uint32_T)j + 1U);
          d_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i1, 1, k,
            &u_emlrtBCI, &st) - 1];
          if (d_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          vals = (b_scalar_erf(muDoubleScalarAbs(x - ksi) / (2.0 *
                    muDoubleScalarSqrt(c_x))) - b_scalar_erf(muDoubleScalarAbs(x
                    - ksi) / (2.0 * muDoubleScalarSqrt(d_x)))) / 2.0;
        } else {
          vals = 0.0;
        }
      }
    }
  }

  return vals;
}
Example #8
0
/* Function Definitions */
void clcPMP_olyHyb_tmp(const emlrtStack *sp, real_T engKinPre, real_T engKinAct,
  real_T gea, real_T slp, real_T batEng, real_T psiBatEng, real_T psiTim, real_T
  batPwrAux, real_T batEngStp, real_T wayStp, const struct0_T *par, real_T
  *cosHamMin, real_T *batFrcOut, real_T *fulFrcOut)
{
  real_T mtmp;
  real_T vehVel;
  real_T b_engKinPre[2];
  real_T crsSpdVec[2];
  int32_T i18;
  int32_T k;
  boolean_T y;
  boolean_T exitg3;
  boolean_T exitg2;
  real_T crsSpd;
  real_T whlTrq;
  real_T crsTrq;
  real_T iceTrqMax;
  real_T iceTrqMin;
  real_T b_par[100];
  real_T emoTrqMaxPos;
  real_T emoTrqMinPos;
  real_T emoTrqMax;
  real_T emoTrqMin;
  real_T batPwrMax;
  real_T batPwrMin;
  real_T batOcv;
  real_T batEngDltMin;
  real_T batEngDltMax;
  real_T batEngDltMinInx;
  real_T batEngDltMaxInx;
  real_T batEngDlt;
  real_T fulFrc;
  real_T batFrc;
  real_T b_batFrc;
  real_T batPwr;
  real_T emoTrq;
  real_T iceTrq;
  real_T fulPwr;
  int32_T ixstart;
  int32_T itmp;
  int32_T ix;
  boolean_T exitg1;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;

  /* CLCPMP Minimizing Hamiltonian: Co-States for soc and time */
  /*  Erstellungsdatum der ersten Version 19.08.2015 - Stephan Uebel */
  /*  */
  /*  Batterieleistungsgrenzen hinzugefügt am 13.12.2015 */
  /*  ^^added battery power limit */
  /*  */
  /*  Massenaufschlag durch Trägheitsmoment herausgenommen */
  /*  ^^Mass increment removed by inertia */
  /*  */
  /* % Inputdefinition */
  /*  */
  /*  engKinPre     - Double(1,1)  - kinetische Energie am Intervallanfang in J */
  /*                                 ^^ kinetic energy at start of interval (J) */
  /*  engKinAct     - Double(1,1)  - kinetische Energie am Intervallende in J */
  /*                                 ^^ kinetic energe at end of interval (J) */
  /*  gea           - Double(1,1)  - Gang */
  /*                                 ^^ gear */
  /*  slp           - Double(1,1)  - Steigung in rad */
  /*                                 ^^ slope in radians */
  /*  iceFlg        - Boolean(1,1) - Flag für Motorzustand */
  /*                                 ^^ flag for motor condition */
  /*  batEng        - Double(1,1)  - Batterieenergie in J */
  /*                                 ^^ battery energy (J) */
  /*  psibatEng     - Double(1,1)  - Costate für Batterieenergie ohne Einheit */
  /*                                 ^^ costate for battery energy w/o unity */
  /*  psiTim        - Double(1,1)  - Costate für die Zeit ohne Einheit */
  /*                                 ^^ costate for time without unity */
  /*  batPwrAux     - Double(1,1)  - elektr. Nebenverbraucherleistung in W */
  /*                                 ^^ electric auxiliary power consumed (W) */
  /*  batEngStp     - Double(1,1)  - Drehmomentschritt */
  /*                                 ^^ torque step <- no, it's a battery step */
  /*  wayStp        - Double(1,1)  - Intervallschrittweite in m */
  /*                                 ^^ interval step distance (m) */
  /*  par           - Struct(1,1)  - Modelldaten */
  /*                                 ^^ model data */
  /* % Initialisieren der Ausgabe der Funktion */
  /*    initializing function output */
  /*  Ausgabewert des Minimums der Hamiltonfunktion */
  /*    output for minimizing the hamiltonian */
  *cosHamMin = rtInf;

  /*  Batterieladungsänderung im Wegschritt beir minimaler Hamiltonfunktion */
  /*    battery change in path_idx step with the minial hamiltonian */
  *batFrcOut = rtInf;

  /*  Kraftstoffkraftänderung im Wegschritt bei minimaler Hamiltonfunktion */
  /*    fuel change in path_idx step with the minimal hamiltonian */
  *fulFrcOut = 0.0;

  /* % Initialisieren der persistent Größen */
  /*    initialize the persistance variables */
  /*  Diese werden die nur einmal für die Funktion berechnet */
  /*    only calculated once for the function */
  if (!crsSpdHybMax_not_empty) {
    /*  maximale Drehzahl Elektrommotor */
    /*    maximum electric motor rotational speed */
    /*  maximale Drehzahl der Kurbelwelle */
    /*    maximum crankshaft rotational speed */
    crsSpdHybMax = muDoubleScalarMin(par->iceSpdMgd[14850], par->emoSpdMgd[14850]);
    crsSpdHybMax_not_empty = true;

    /*  minimale Drehzahl der Kurbelwelle */
    /*    minimum crankshaft rotational speed */
    crsSpdHybMin = par->iceSpdMgd[0];
  }

  /* % Initialisieren der allgemein benötigten Kenngrößen */
  /*    initializing the commonly required parameters */
  /*  mittlere kinetische Energie im Wegschritt berechnen */
  /*    define the average kinetic energy at path_idx step - is just previous KE */
  /*  mittlere Geschwindigkeit im Wegschritt berechnen */
  /*    define the average speed at path_idx step */
  mtmp = 2.0 * engKinPre / par->vehMas;
  st.site = &g_emlrtRSI;
  if (mtmp < 0.0) {
    b_st.site = &h_emlrtRSI;
    eml_error(&b_st);
  }

  vehVel = muDoubleScalarSqrt(mtmp);

  /* % vorzeitiger Funktionsabbruch? */
  /*    premature function termination? */
  /*  Drehzahl der Kurbelwelle und Grenzen */
  /*    crankshaft speed and limits */
  /*  Aus den kinetischen Energien des Fahrzeugs wird über die Raddrehzahl */
  /*  und die übersetzung vom Getriebe die Kurbelwellendrehzahl berechnet. */
  /*  Zeilenrichtung entspricht den Gängen. (Zeilenvektor) */
  /*    from the vehicle's kinetic energy, the crankshaft speed is calculated */
  /*    by the speed and gearbox translation. Line direction corresponding to */
  /*    the aisles (row rector). EQUATION 1 */
  b_engKinPre[0] = engKinPre;
  b_engKinPre[1] = engKinAct;
  for (i18 = 0; i18 < 2; i18++) {
    crsSpdVec[i18] = 2.0 * b_engKinPre[i18] / par->vehMas;
  }

  st.site = &f_emlrtRSI;
  for (k = 0; k < 2; k++) {
    if (crsSpdVec[k] < 0.0) {
      b_st.site = &h_emlrtRSI;
      eml_error(&b_st);
    }
  }

  for (k = 0; k < 2; k++) {
    crsSpdVec[k] = muDoubleScalarSqrt(crsSpdVec[k]);
  }

  i18 = par->geaRat->size[1];
  k = (int32_T)gea;
  emlrtDynamicBoundsCheckR2012b(k, 1, i18, &mb_emlrtBCI, sp);
  mtmp = par->geaRat->data[(int32_T)gea - 1];
  for (i18 = 0; i18 < 2; i18++) {
    crsSpdVec[i18] = mtmp * crsSpdVec[i18] / par->whlDrr;
  }

  /*  Abbruch, wenn die Drehzahlen der Kurbelwelle zu hoch im hybridischen */
  /*  Modus */
  /*    stop if the crankshaft rotatoinal speed is too high in hybrid mode */
  y = false;
  k = 0;
  exitg3 = false;
  while ((!exitg3) && (k < 2)) {
    if (!!(crsSpdVec[k] > crsSpdHybMax)) {
      y = true;
      exitg3 = true;
    } else {
      k++;
    }
  }

  if (y) {
  } else {
    /*  Falls die Drehzahl des Verbrennungsmotors niedriger als die */
    /*  Leerlaufdrehzahl ist, */
    /*    stop if crankhaft rotional speed is lower than the idling speed */
    y = false;
    k = 0;
    exitg2 = false;
    while ((!exitg2) && (k < 2)) {
      if (!!(crsSpdVec[k] < crsSpdHybMin)) {
        y = true;
        exitg2 = true;
      } else {
        k++;
      }
    }

    if (y) {
    } else {
      /*  Prüfen, ob die Drehzahlgrenze des Elektromotors eingehalten wird */
      /*    check if electric motor speed limit is maintained */
      /*  mittlere Kurbelwellendrehzahlen berechnen */
      /*    calculate average crankshaft rotational speed */
      /*    - really just selecting the previous path_idx KE crankshaft speed */
      crsSpd = crsSpdVec[0];

      /* % Längsdynamik berechnen */
      /*    calculate longitundinal dynamics */
      /*  Es wird eine konstante Beschleunigung angenommen, die im Wegschritt */
      /*  wayStp das Fahrzeug von velPre auf velAct beschleunigt. */
      /*    constant acceleration assumed when transitioning from velPre to velAct */
      /*    for the selected wayStp path_idx step distance */
      /*  Berechnen der konstanten Beschleunigung */
      /*    calculate the constant acceleration */
      /*  Aus der mittleren kinetischen Energie im Intervall, der mittleren */
      /*  Steigung und dem Gang lässt sich über die Fahrwiderstandsgleichung */
      /*  die nötige Fahrwiderstandskraft berechnen, die aufgebracht werden */
      /*  muss, um diese zu realisieren. */
      /*    from the (avg) kinetic energy in the interval, the (avg) slope and */
      /*    transition can calculate the necessary traction force on the driving */
      /*    resistance equation (PART OF EQUATION 5) */
      /*  Steigungskraft aus der mittleren Steigung berechnen (Skalar) */
      /*    gradiant force from the calculated (average) gradient */
      /*  Rollreibungskraft berechnen (Skalar) */
      /*    calculated rolling friction force - not included in EQ 5??? */
      /*  Luftwiderstandskraft berechnen (2*c_a/m * E_kin) (Skalar)  */
      /*    calculated air resistance force  */
      /* % Berechnung der minimalen kosten der Hamiltonfunktion */
      /*    Calculating the minimum cost of the Hamiltonian */
      /* % Berechnen der Kraft am Rad für Antriebsstrangmodus */
      /*    calculate the force on the wheel for the drivetrain mode */
      /*  % dynamische Fahrzeugmasse bei Fahrzeugmotor an berechnen. Das */
      /*  % heißt es werden Trägheitsmoment von Verbrennungsmotor, */
      /*  % Elektromotor und Rädern mit einbezogen. */
      /*    calculate dynamic vehicle mass with the vehicle engine (with the moment */
      /*    of intertia of the ICE, electric motor, and wheels) */
      /*  vehMasDyn = (par.iceMoi_geaRat(gea) +... */
      /*      par.emoGeaMoi_geaRat(gea) + par.whlMoi)/par.whlDrr^2 ... */
      /*      + par.vehMas; */
      /*  Radkraft berechnen (Beschleunigungskraft + Steigungskraft + */
      /*  Rollwiderstandskraft + Luftwiderstandskraft) */
      /*    caluclating wheel forces (accerlation force + gradient force + rolling */
      /*    resistance + air resistance)    EQUATION 5 */
      /* % Getriebeübersetzung und -verlust */
      /*    gear ratio and loss */
      /*  Das Drehmoment des Rades ergibt sich über den Radhalbmesser aus */
      /*  der Fahrwiderstandskraft. */
      /*    the weel torque is obtained from the wheel radius of the rolling */
      /*    resistance force (torque = force * distance (in this case, radius) */
      whlTrq = ((((engKinAct - engKinPre) / (par->vehMas * wayStp) * par->vehMas
                  + par->vehMas * 9.81 * muDoubleScalarSin(slp)) +
                 par->whlRolResCof * par->vehMas * 9.81 * muDoubleScalarCos(slp))
                + 2.0 * par->drgCof / par->vehMas * engKinPre) * par->whlDrr;

      /*  Berechnung des Kurbelwellenmoments */
      /*  Hier muss unterschieden werden, ob das Radmoment positiv oder */
      /*  negativ ist, da nur ein einfacher Wirkungsgrad für das Getriebe */
      /*  genutzt wird */
      /*    it's important to determine sign of crankshaft torque (positive or */
      /*    negative), since only a simple efficiency is used for the transmission */
      /*    PART OF EQ4  <- perhaps reversed? not too sure */
      if (whlTrq < 0.0) {
        i18 = par->geaRat->size[1];
        k = (int32_T)gea;
        emlrtDynamicBoundsCheckR2012b(k, 1, i18, &nb_emlrtBCI, sp);
        crsTrq = whlTrq / par->geaRat->data[(int32_T)gea - 1] * par->geaEfy;
      } else {
        i18 = par->geaRat->size[1];
        k = (int32_T)gea;
        emlrtDynamicBoundsCheckR2012b(k, 1, i18, &ob_emlrtBCI, sp);
        crsTrq = whlTrq / par->geaRat->data[(int32_T)gea - 1] / par->geaEfy;
      }

      /* % Verbrennungsmotor */
      /*    internal combustion engine */
      /*  maximales Moment des Verbrennungsmotors berechnen */
      /*    calculate max torque of the engine (quadratic based on rotation speed) */
      iceTrqMax = (par->iceTrqMaxCof[0] * (crsSpdVec[0] * crsSpdVec[0]) +
                   par->iceTrqMaxCof[1] * crsSpdVec[0]) + par->iceTrqMaxCof[2];

      /*  minimales Moment des Verbrennungsmotors berechnen */
      /*    calculating mimimum ICE moment */
      iceTrqMin = (par->iceTrqMinCof[0] * (crsSpdVec[0] * crsSpdVec[0]) +
                   par->iceTrqMinCof[1] * crsSpdVec[0]) + par->iceTrqMinCof[2];

      /* % Elektromotor */
      /*    electric motor */
      /*  maximales Moment, dass die E-Maschine liefern kann */
      /*    max torque that the electric motor can provide - from interpolation */
      /*  emoTrqMaxPos = ... */
      /*      lininterp1(par.emoSpdMgd(1,:)',par.emoTrqMax_emoSpd,crsSpd); */
      for (i18 = 0; i18 < 100; i18++) {
        b_par[i18] = par->emoSpdMgd[150 * i18];
      }

      emoTrqMaxPos = interp1q(b_par, par->emoTrqMax_emoSpd, crsSpdVec[0]);

      /*  Die gültigen Kurbelwellenmomente müssen kleiner sein als das */
      /*  Gesamtmoment von E-Motor und Verbrennungsmotor */
      /*    The valid crankshaft moments must be less than the total moment of the */
      /*    electric motor and the ICE.Otherwise, leave the function */
      if (crsTrq > iceTrqMax + emoTrqMaxPos) {
      } else {
        /* % %% Optimaler Momentensplit - Minimierung der Hamiltonfunktion */
        /*        optimum torque split - minimizing the Hamiltonian */
        /*  Die Vorgehensweise ist ähnlich wie bei der ECMS. Es wird ein Vektor der */
        /*  möglichen Batterieenergieänderungen aufgestellt. Aus diesen lässt sich  */
        /*  eine Batterieklemmleistung berechnen. Aus der über das */
        /*  Kurbelwellenmoment, ein Elektromotormoment berechnet werden kann. */
        /*  Über das geforderte Kurbelwellenmoment, kann für jedes Moment des  */
        /*  Elektromotors ein Moment des Verbrennungsmotors gefunden werden. Für  */
        /*  jedes Momentenpaar kann die Hamiltonfunktion berechnet werden. */
        /*  Ausgegeben wird der minimale Wert der Hamiltonfunktion und die */
        /*  durch das dabei verwendete Elektromotormoment verursachte */
        /*  Batterieladungsänderung. */
        /*    The procedure is similar to ECMS. It's based on a vector of possible */
        /*    battery energy changes, from which a battery terminal power can be */
        /*    calculated. */
        /*    From the crankshaft torque, an electric motor torque can be */
        /*    calculated, and an engine torque can be found for every electric motor */
        /*    moment.  */
        /*    For every moment-pair the Hamiltonian can be calculated. It */
        /*    outputs the minimum Hamilotnian value and the battery charge change */
        /*    caused by the electric motor torque used. */
        /* % Elektromotor - Aufstellen des Batterienergievektors */
        /*    electric motor - positioning the battery energy vectors */
        if (batEngStp > 0.0) {
          /* Skalar - änderung der minimalen Batterieenergieänderung */
          /*  Skalar - änderung der maximalen Batterieenergieänderung */
          /*  FUNCTION CALL */
          /*       Skalar - Wegschrittweite */
          /*       Skalar - mittlere Geschwindigkeit im Intervall */
          /*    Skalar - Nebenverbraucherlast */
          /*       Skalar - Batterieenergie */
          /*          struct - Fahrzeugparameter */
          /*       Skalar - crankshaft rotational speed */
          /*       Skalar - crankshaft torque */
          /*    Skalar - min ICE torque allowed */
          /*    Skalar - max ICE torque allowed */
          /*  Skalar - max EM torque possible */
          st.site = &e_emlrtRSI;

          /* Skalar - änderung der minimalen Batterieenergieänderung */
          /*  Skalar - änderung der maximalen Batterieenergieänderung */
          /*       Skalar - Wegschrittweite */
          /*          Skalar - Geschwindigkeit im Intervall */
          /*    Skalar - Nebenverbraucherlast */
          /*    Skalar - Batterieenergie */
          /*          struct - Fahrzeugparameter */
          /*       Skalar - crankshaft rotational speed */
          /*       Skalar - crankshaft torque */
          /*    Skalar - min ICE torque allowed */
          /*    Skalar - max ICE torque */
          /*  Skalar - max EM torque possible */
          /* BatEngDltClc Calculates the change in battery energy */
          /*  */
          /*  Erstellungsdatum der ersten Version 17.11.2015 - Stephan Uebel */
          /*    Berechnung der Verluste des Elektromotors bei voller rein elektrischer */
          /*    Fahrt (voller Lastpunktabsenkung) und bei voller Lastpunktanhebung */
          /*        Calculations of loss of electric motor at purely full electric */
          /*        Driving (full load point lowering) and at full load point raising */
          /*  */
          /*  Version vom 17.02.2016: Keine Einbeziehung von Rotationsmassen */
          /*                          ^^ No inclusion of rotational masses */
          /*  */
          /*  Version vom 25.05.2016: Zero-Order-Hold (keine mittlere Geschwindigkeit) */
          /*                          ^^ Zero-Order-Hold (no average velocities) */
          /* % Initialisieren der Ausgabe der Funktion */
          /*    initializing the function output (delta battery_energy min and max) */
          /* % Elektromotor */
          /*  minimales Moment, dass die E-Maschine liefern kann */
          /*    minimum moment that the EM can provide (max is an input to function) */
          /*  emoTrqMinPos = ... */
          /*      lininterp1(par.emoSpdMgd(1,:)',par.emoTrqMin_emoSpd,crsSpd); */
          for (i18 = 0; i18 < 100; i18++) {
            b_par[i18] = par->emoSpdMgd[150 * i18];
          }

          emoTrqMinPos = interp1q(b_par, par->emoTrqMin_emoSpd, crsSpdVec[0]);

          /* % Verbrennungsmotor berechnen */
          /*  Durch EM zu lieferndes Kurbelwellenmoment */
          /*    crankshaft torque to be delivered by the electric motor (min and max) */
          emoTrqMax = crsTrq - iceTrqMin;
          emoTrqMin = crsTrq - iceTrqMax;

          /* % Elektromotor berechnen */
          /*    calculate the electric motor */
          if (emoTrqMaxPos < emoTrqMax) {
            /*  Moment des Elektromotors bei maximaler Entladung der Batterie */
            /*    EM torque at max battery discharge */
            emoTrqMax = emoTrqMaxPos;
          }

          if (emoTrqMaxPos < emoTrqMin) {
            /*  Moment des Elektromotors bei minimaler Entladung der Batterie */
            /*    EM torque at min battery discharge */
            emoTrqMin = emoTrqMaxPos;
          }

          emoTrqMax = muDoubleScalarMax(emoTrqMinPos, emoTrqMax);
          emoTrqMin = muDoubleScalarMax(emoTrqMinPos, emoTrqMin);

          /* % Berechnung der änderung der Batterieladung */
          /*    calculating the change in battery charge */
          /*  Interpolation der benötigten Batterieklemmleistung für das */
          /*  EM-Moment. Stellen die nicht definiert sind, werden mit inf */
          /*  ausgegeben. Positive Werte entsprechen entladen der Batterie. */
          /*    interpolating the required battery terminal power for the EM torque. */
          /*    Assign undefined values to inf. Positive values coresspond with battery */
          /*    discharge. */
          /*  batPwrMax = lininterp2(par.emoSpdMgd(1,:),par.emoTrqMgd(:,1),... */
          /*      par.emoPwr_emoSpd_emoTrq',crsSpd,emoTrqMax) + batPwrAux; */
          /*   */
          /*  batPwrMin = lininterp2(par.emoSpdMgd(1,:),par.emoTrqMgd(:,1),... */
          /*      par.emoPwr_emoSpd_emoTrq',crsSpd,emoTrqMin) + batPwrAux; */
          b_st.site = &i_emlrtRSI;
          batPwrMax = codegen_interp2(&b_st, par->emoSpdMgd, par->emoTrqMgd,
            par->emoPwr_emoSpd_emoTrq, crsSpdVec[0], emoTrqMax) + batPwrAux;
          b_st.site = &j_emlrtRSI;
          batPwrMin = codegen_interp2(&b_st, par->emoSpdMgd, par->emoTrqMgd,
            par->emoPwr_emoSpd_emoTrq, crsSpdVec[0], emoTrqMin) + batPwrAux;

          /*  überprüfen, ob Batterieleistung möglich */
          /*    make sure that current battery max power is not above bat max bounds */
          if (batPwrMax > par->batPwrMax) {
            batPwrMax = par->batPwrMax;
          }

          /*  überprüfen, ob Batterieleistung möglich */
          /*    make sure that current battery min power is not below bat min bounds */
          if (batPwrMin > par->batPwrMax) {
            batPwrMin = par->batPwrMax;
          }

          /*  Es kann vorkommen, dass mehr Leistung gespeist werden soll, als */
          /*  möglich ist. */
          /*    double check that the max and min still remain within the other bounds */
          if (batPwrMax < par->batPwrMin) {
            batPwrMax = par->batPwrMin;
          }

          if (batPwrMin < par->batPwrMin) {
            batPwrMin = par->batPwrMin;
          }

          /*  Batteriespannung aus Kennkurve berechnen */
          /*    calculating battery voltage of characteristic curve - eq?-------------- */
          batOcv = batEng * par->batOcvCof_batEng[0] + par->batOcvCof_batEng[1];

          /*  FUNCTION CALL - min delta bat.energy */
          /*            Skalar - Batterieklemmleistung */
          /*                  Skalar - mittlere Geschwindigkeit im Intervall */
          /*        Skalar - Entladewiderstand */
          /*        Skalar - Ladewiderstand */
          /*                Skalar - battery open-circuit voltage */
          batEngDltMin = batFrcClc_tmp(batPwrMax, vehVel, par->batRstDch,
            par->batRstChr, batOcv) * wayStp;

          /*  <-multiply by delta_S */
          /*  FUNCTION CALL - max delta bat.energy */
          /*            Skalar - Batterieklemmleistung */
          /*                  Skalar - mittlere Geschwindigkeit im Intervall */
          /*        Skalar - Entladewiderstand */
          /*        Skalar - Ladewiderstand */
          /*                Skalar - battery open-circuit voltage */
          batEngDltMax = batFrcClc_tmp(batPwrMin, vehVel, par->batRstDch,
            par->batRstChr, batOcv) * wayStp;

          /*  Es werden 2 Fälle unterschieden: */
          /*    there are 2 different cases */
          if ((batEngDltMin > 0.0) && (batEngDltMax > 0.0)) {
            /*         %% konventionelles Bremsen + Rekuperieren */
            /*    conventional brakes + recuperation */
            /*  */
            /*  set change in energy to discretized integer values w/ ceil and */
            /*  floor. This also helps for easy looping */
            /*  Konventionelles Bremsen wird ebenfalls untersucht. */
            /*  Hier liegt eventuell noch Beschleunigungspotential, da diese */
            /*  Zustandswechsel u.U. ausgeschlossen werden können. */
            /*  NOTE: u.U. = unter Ümständen = circumstances permitting */
            /*    convetional breaks also investigated. An accelerating potential */
            /*    is still possible, as these states can be excluded */
            /*    (circumstances permitting)  <- ??? not sure what above means */
            /*  */
            /*    so if both min and max changes in battery energy are */
            /*    increasing, then set the delta min to zero */
            batEngDltMinInx = 0.0;
            batEngDltMaxInx = muDoubleScalarFloor(batEngDltMax / batEngStp);
          } else {
            batEngDltMinInx = muDoubleScalarCeil(batEngDltMin / batEngStp);
            batEngDltMaxInx = muDoubleScalarFloor(batEngDltMax / batEngStp);
          }
        } else {
          batEngDltMinInx = 0.0;
          batEngDltMaxInx = 0.0;
        }

        /*  you got a larger min chnage and a max change, you're out of bounds. Leave */
        /*  the function */
        if (batEngDltMaxInx < batEngDltMinInx) {
        } else {
          /* % Schleife über alle Elektromotormomente */
          /*    now loop through all the electric-motor torques */
          i18 = (int32_T)(batEngDltMaxInx + (1.0 - batEngDltMinInx));
          emlrtForLoopVectorCheckR2012b(batEngDltMinInx, 1.0, batEngDltMaxInx,
            mxDOUBLE_CLASS, i18, &o_emlrtRTEI, sp);
          k = 0;
          while (k <= i18 - 1) {
            batEngDlt = (batEngDltMinInx + (real_T)k) * batEngStp;

            /*  open circuit voltage over each iteration */
            batOcv = (batEng + batEngDlt) * par->batOcvCof_batEng[0] +
              par->batOcvCof_batEng[1];

            /*           Skalar für die Batterieleistung in W */
            /*           Skalar Krafstoffkraft in N */
            /*             FUNCTION CALL */
            /*          Skalar für die Wegschrittweite in m, */
            /*           Skalar - vehicular velocity */
            /*        Nebenverbraucherlast */
            /*           Skalar - battery open circuit voltage */
            /*       Skalar - Batterieenergie�nderung, */
            /*           Skalar - crankshaft speed at given path_idx */
            /*           Skalar - crankshaft torque at given path_idx */
            /*        Skalar - min ICE torque allowed */
            /*        Skalar - max ICE torque */
            /*               struct der Fahrzeugparameter */
            st.site = &d_emlrtRSI;

            /*   Skalar für die Batterieleistung */
            /*       Skalar Kraftstoffkraft */
            /*      Skalar für die Wegschrittweite in m */
            /*          vehicular velocity */
            /*    Nebenverbraucherlast */
            /*       Skalar - battery open circuit voltage */
            /*   Skalar - Batterieenergieänderung */
            /*       Skalar - crankshaft speed at given path_idx */
            /*       Skalar - crankshaft torque at given path_idx */
            /*    Skalar - min ICE torque allowed */
            /*    Skalar - max ICE torque */
            /*           struct der Fahrzeugparameter */
            /*  */
            /* FULENGCLC Calculating fuel consumption */
            /*  Erstellungsdatum der ersten Version 04.09.2015 - Stephan Uebel */
            /*  */
            /*  Diese Funktion berechnet den Kraftstoffverbrauch für einen gegebenen */
            /*  Wegschritt der kinetischen Energie, der Batterieenergie und des */
            /*  Antriebsstrangzustands über dem Weg. */
            /*    this function calculates fuel consumption for a given route step of */
            /*    KE, the battery energy, and drivetrain state of the current path_idx */
            /*  */
            /*  Version vom 17.02.2016 : Rotationsmassen vernachlässigt */
            /*                            ^^ neglected rotatary masses */
            /*  */
            /*  Version vom 25.05.2016: Zero-Order-Hold (keine mittlere Geschwindigkeit) */
            /*  */
            /*  version from 1.06.2016 - removed crsTrq calulations - they are already */
            /*  done in parent function (clcPMP_olHyb_tmp) and do not change w/ each */
            /*  iteration, making the caluclation here unnecessary */
            /* % Initialisieren der Ausgabe der Funktion */
            /*    initializing function output */
            /*    Skalar - electric battery power (W) */
            fulFrc = rtInf;

            /*    Skalar - fuel force intialization (N) */
            /* % Batterie */
            /*  Batterieenergieänderung über dem Weg (Batteriekraft) */
            /*    Change in battery energy over the path_idx way (ie battery power) */
            batFrc = batEngDlt / wayStp;

            /*  Fallunterscheidung, ob Batterie geladen oder entladen wird */
            /*    Case analysis - check if battery is charging or discharging. Set */
            /*    resistance accordingly */
            /*  elektrische Leistung des Elektromotors */
            /*    electric power from electric motor - DERIVATION? dunno */
            /*  innere Batterieleistung / internal batt power */
            /* dissipat. Leist. / dissipated */
            if (batFrc < 0.0) {
              b_batFrc = par->batRstDch;
            } else {
              b_batFrc = par->batRstChr;
            }

            batPwr = (-batFrc * vehVel - batFrc * batFrc * (vehVel * vehVel) /
                      (batOcv * batOcv) * b_batFrc) - batPwrAux;

            /*           Nebenverbrauchlast / auxiliary power */
            /* % Elektromotor */
            /*  Ermitteln des Kurbelwellenmoments durch EM aus Batterieleistung */
            /*    determine crankshaft torque cauesd by EM's battery power */
            /*        switching out codegen_interp2 for lininterp2-just might work! */
            /*  */
            b_st.site = &k_emlrtRSI;
            emoTrq = codegen_interp2(&b_st, par->emoSpdMgd, par->emoPwrMgd,
              par->emoTrq_emoSpd_emoPwr, crsSpd, batPwr);

            /*  emoTrq = lininterp2(par.emoSpdMgd(1,:), par.emoPwrMgd(:,1),... */
            /*      par.emoTrq_emoSpd_emoPwr',crsSpd,emoPwrEle); */
            if (muDoubleScalarIsInf(emoTrq)) {
            } else {
              /*  Grenzen des Elektromotors müssen hier nicht überprüft werden, da die */
              /*  Ladungsdeltas schon so gewählt wurden, dass das maximale Motormoment */
              /*  nicht überstiegen wird. */
              /*    Electric motor limits need not be checked here, since the charge deltas */
              /*    have been chosen so that the max torque is not exceeded. */
              /* % Verbrennungsmotor */
              /*  Ermitteln des Kurbelwellenmoments durch den Verbrennungsmotor */
              /*    Determining the crankshaft moment from the ICE */
              iceTrq = crsTrq - emoTrq;

              /*  Wenn das Verbrennungsmotormoment kleiner als das minimale */
              /*  Moment ist, ist dieser in der Schubabschaltung. Das */
              /*  verbleibende Moment liefern die Bremsen */
              /*    If engine torque is less than the min torque, fuel is cut. The */
              /*    remaining torque is deliver the brakes. */
              if (iceTrq < iceTrqMin) {
                fulPwr = 0.0;
              } else if (iceTrq > iceTrqMax) {
                fulPwr = rtInf;
              } else {
                /*  replacing another coden_interp2 */
                b_st.site = &l_emlrtRSI;
                fulPwr = codegen_interp2(&b_st, par->iceSpdMgd, par->iceTrqMgd,
                  par->iceFulPwr_iceSpd_iceTrq, crsSpd, iceTrq);

                /*      fulPwr = lininterp2(par.iceSpdMgd(1,:), par.iceTrqMgd(:,1), ... */
                /*          par.iceFulPwr_iceSpd_iceTrq', crsSpd, iceTrq); */
              }

              /*  Berechnen der Kraftstoffkraft */
              /*    calculate fuel force */
              fulFrc = fulPwr / vehVel;

              /*  Berechnen der Kraftstoffvolumenänderung */
              /*  caluclate change in fuel volume - energy, no? */
              /* % Ende der Funktion */
            }

            /*       FUNCTION CALL */
            /*           Skalar - Batterieklemmleistung */
            /*           Skalar - mittlere Geschwindigkeit im Intervall */
            /*    Skalar - Entladewiderstand */
            /*    Skalar - Ladewiderstand */
            /*            Skalar - battery open circuit voltage */
            batFrc = batFrcClc_tmp(batPwr, vehVel, par->batRstDch,
              par->batRstChr, batOcv);

            /*     %% Hamiltonfunktion bestimmen */
            /*    determine the hamiltonian */
            /*  Eq (29b) */
            crsSpdVec[0] = (fulFrc + psiBatEng * batFrc) + psiTim / vehVel;
            ixstart = 1;
            mtmp = crsSpdVec[0];
            itmp = 1;
            if (muDoubleScalarIsNaN(crsSpdVec[0])) {
              ix = 2;
              exitg1 = false;
              while ((!exitg1) && (ix < 3)) {
                ixstart = 2;
                if (!muDoubleScalarIsNaN(*cosHamMin)) {
                  mtmp = *cosHamMin;
                  itmp = 2;
                  exitg1 = true;
                } else {
                  ix = 3;
                }
              }
            }

            if ((ixstart < 2) && (*cosHamMin < mtmp)) {
              mtmp = *cosHamMin;
              itmp = 2;
            }

            *cosHamMin = mtmp;

            /*  Wenn der aktuelle Punkt besser ist, als der in cosHamMin */
            /*  gespeicherte Wert, werden die Ausgabegrößen neu beschrieben. */
            /*    if the current point is better than the stored cosHamMin value, */
            /*    then the output values are rewritten (selected prev. value is = 2) */
            if (itmp == 1) {
              *batFrcOut = batFrc;
              *fulFrcOut = fulFrc;
            }

            k++;
            if (*emlrtBreakCheckR2012bFlagVar != 0) {
              emlrtBreakCheckR2012b(sp);
            }
          }
        }
      }
    }
  }

  /*  end of function */
}
Example #9
0
void b_Acoeff(const emlrtStack *sp, real_T ksi, real_T j, const emxArray_real_T *
              x, real_T t, const emxArray_real_T *gridT, emxArray_real_T *vals)
{
  emxArray_real_T *b;
  emxArray_real_T *r8;
  int32_T b_x;
  int32_T i;
  emxArray_boolean_T *b_t;
  real_T c_x;
  emxArray_boolean_T *c_t;
  emxArray_real_T *z0;
  emxArray_real_T *d_x;
  emxArray_real_T *e_x;
  emxArray_real_T *r9;
  int32_T b_b[2];
  int32_T f_x[2];
  emxArray_real_T *g_x;
  emxArray_real_T *r10;
  const mxArray *y;
  static const int32_T iv16[2] = { 1, 45 };

  const mxArray *m6;
  char_T cv18[45];
  static const char_T cv19[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D',
    'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p',
    'a', 'n', 's', 'i', 'o', 'n' };

  const mxArray *b_y;
  static const int32_T iv17[2] = { 1, 21 };

  char_T cv20[21];
  static const char_T cv21[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' };

  emxArray_boolean_T *d_t;
  real_T h_x;
  emxArray_boolean_T *e_t;
  emxArray_real_T *i_x;
  emxArray_real_T *r11;
  emxArray_real_T *j_x;
  emxArray_real_T *r12;
  emxArray_real_T *z1;
  int32_T b_z0[2];
  emxArray_real_T *c_z0;
  emxArray_real_T *k_x;
  const mxArray *c_y;
  static const int32_T iv18[2] = { 1, 45 };

  const mxArray *d_y;
  static const int32_T iv19[2] = { 1, 21 };

  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &b_st;
  d_st.tls = b_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &b, 2, &bb_emlrtRTEI, true);
  emxInit_real_T(sp, &r8, 2, &bb_emlrtRTEI, true);

  /*  evaluate the coefficient A at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  b_x = gridT->size[1];
  i = (int32_T)emlrtIntegerCheckFastR2012b(j, &emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &d_emlrtBCI,
       sp) - 1]) {
    b_x = vals->size[0] * vals->size[1];
    vals->size[0] = 1;
    vals->size[1] = 1;
    emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof(real_T),
                      &bb_emlrtRTEI);
    vals->data[0] = 0.0;
  } else {
    emxInit_boolean_T(sp, &b_t, 2, &bb_emlrtRTEI, true);
    b_x = b_t->size[0] * b_t->size[1];
    b_t->size[0] = 1;
    b_t->size[1] = 2 + x->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)b_t, b_x, (int32_T)sizeof
                      (boolean_T), &bb_emlrtRTEI);
    b_x = gridT->size[1];
    i = (int32_T)j;
    b_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
      &e_emlrtBCI, sp) - 1]);
    b_x = gridT->size[1];
    i = (int32_T)((uint32_T)j + 1U);
    b_t->data[b_t->size[0]] = (t <= gridT->
      data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &f_emlrtBCI, sp) - 1]);
    i = x->size[1];
    for (b_x = 0; b_x < i; b_x++) {
      b_t->data[b_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] == ksi);
    }

    st.site = &pe_emlrtRSI;
    if (all(&st, b_t)) {
      b_x = gridT->size[1];
      i = (int32_T)j;
      emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &c_emlrtBCI, sp);
      c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
      st.site = &emlrtRSI;
      if (c_x < 0.0) {
        b_st.site = &f_emlrtRSI;
        eml_error(&b_st);
      }

      b_x = vals->size[0] * vals->size[1];
      vals->size[0] = 1;
      vals->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                        (real_T), &bb_emlrtRTEI);
      vals->data[0] = muDoubleScalarSqrt(c_x);
    } else {
      emxInit_boolean_T(sp, &c_t, 2, &bb_emlrtRTEI, true);
      b_x = c_t->size[0] * c_t->size[1];
      c_t->size[0] = 1;
      c_t->size[1] = 2 + x->size[1];
      emxEnsureCapacity(sp, (emxArray__common *)c_t, b_x, (int32_T)sizeof
                        (boolean_T), &bb_emlrtRTEI);
      b_x = gridT->size[1];
      i = (int32_T)j;
      c_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
        b_x, &g_emlrtBCI, sp) - 1]);
      b_x = gridT->size[1];
      i = (int32_T)((uint32_T)j + 1U);
      c_t->data[c_t->size[0]] = (t <= gridT->
        data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &h_emlrtBCI, sp) - 1]);
      i = x->size[1];
      for (b_x = 0; b_x < i; b_x++) {
        c_t->data[c_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] != ksi);
      }

      emxInit_real_T(sp, &z0, 2, &cb_emlrtRTEI, true);
      emxInit_real_T(sp, &d_x, 2, &bb_emlrtRTEI, true);
      st.site = &qe_emlrtRSI;
      if (all(&st, c_t)) {
        st.site = &b_emlrtRSI;
        b_x = gridT->size[1];
        i = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
          &m_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        emxInit_real_T(&st, &e_x, 2, &bb_emlrtRTEI, true);
        b_x = e_x->size[0] * e_x->size[1];
        e_x->size[0] = 1;
        e_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)e_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          e_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r9, 2, &bb_emlrtRTEI, true);
        b_abs(sp, e_x, r9);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r9->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r9->size[0] * r9->size[1];
        emxFree_real_T(&e_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r9->data[b_x];
        }

        emxFree_real_T(&r9);
        rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
        st.site = &re_emlrtRSI;
        mpower(&st, z0, d_x);
        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] = -d_x->data[b_x];
        }

        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        b->size[1] = d_x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof(real_T),
                          &bb_emlrtRTEI);
        i = d_x->size[0] * d_x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] = d_x->data[b_x];
        }

        for (i = 0; i < d_x->size[1]; i++) {
          b->data[i] = muDoubleScalarExp(b->data[i]);
        }

        st.site = &re_emlrtRSI;
        b_mrdivide(&st, b, z0);
        for (b_x = 0; b_x < 2; b_x++) {
          i = d_x->size[0] * d_x->size[1];
          d_x->size[b_x] = z0->size[b_x];
          emxEnsureCapacity(sp, (emxArray__common *)d_x, i, (int32_T)sizeof
                            (real_T), &ab_emlrtRTEI);
        }

        for (i = 0; i < z0->size[1]; i++) {
          d_x->data[i] = scalar_erf(z0->data[i]);
        }

        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] *= 1.7724538509055159;
        }

        for (b_x = 0; b_x < 2; b_x++) {
          b_b[b_x] = b->size[b_x];
        }

        for (b_x = 0; b_x < 2; b_x++) {
          f_x[b_x] = d_x->size[b_x];
        }

        emxInit_real_T(sp, &g_x, 2, &bb_emlrtRTEI, true);
        emlrtSizeEqCheck2DFastR2012b(b_b, f_x, &o_emlrtECI, sp);
        b_x = g_x->size[0] * g_x->size[1];
        g_x->size[0] = 1;
        g_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)g_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          g_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r10, 2, &bb_emlrtRTEI, true);
        b_abs(sp, g_x, r10);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r10->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r10->size[0] * r10->size[1];
        emxFree_real_T(&g_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r10->data[b_x];
        }

        emxFree_real_T(&r10);
        rdivide(sp, r8, 3.5449077018110318, vals);
        st.site = &re_emlrtRSI;
        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[0];
        b_x = b->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] -= d_x->data[b_x];
        }

        b_st.site = &he_emlrtRSI;
        if (!(vals->size[1] == 1)) {
          if ((vals->size[1] == 1) || (b->size[1] == 1)) {
            y = NULL;
            m6 = emlrtCreateCharArray(2, iv16);
            for (i = 0; i < 45; i++) {
              cv18[i] = cv19[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
            emlrtAssign(&y, m6);
            c_st.site = &fh_emlrtRSI;
            d_st.site = &vg_emlrtRSI;
            b_error(&c_st, message(&d_st, y, &j_emlrtMCI), &k_emlrtMCI);
          } else {
            b_y = NULL;
            m6 = emlrtCreateCharArray(2, iv17);
            for (i = 0; i < 21; i++) {
              cv20[i] = cv21[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
            emlrtAssign(&b_y, m6);
            c_st.site = &gh_emlrtRSI;
            d_st.site = &wg_emlrtRSI;
            b_error(&c_st, message(&d_st, b_y, &l_emlrtMCI), &m_emlrtMCI);
          }
        }

        c_x = vals->data[0];
        b_x = vals->size[0] * vals->size[1];
        vals->size[0] = 1;
        vals->size[1] = b->size[1];
        emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
        }
      } else {
        emxInit_boolean_T(sp, &d_t, 2, &bb_emlrtRTEI, true);
        b_x = d_t->size[0] * d_t->size[1];
        d_t->size[0] = 1;
        d_t->size[1] = 1 + x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)d_t, b_x, (int32_T)sizeof
                          (boolean_T), &bb_emlrtRTEI);
        b_x = gridT->size[1];
        i = (int32_T)((uint32_T)j + 1U);
        d_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          b_x, &i_emlrtBCI, sp) - 1]);
        i = x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          d_t->data[d_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] ==
            ksi);
        }

        st.site = &se_emlrtRSI;
        if (all(&st, d_t)) {
          b_x = gridT->size[1];
          i = (int32_T)j;
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &b_emlrtBCI, sp);
          c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
          b_x = gridT->size[1];
          i = (int32_T)(j + 1.0);
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &emlrtBCI, sp);
          h_x = (t - gridT->data[(int32_T)(j + 1.0) - 1]) / 3.1415926535897931;
          st.site = &c_emlrtRSI;
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &c_emlrtRSI;
          if (h_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          b_x = vals->size[0] * vals->size[1];
          vals->size[0] = 1;
          vals->size[1] = 1;
          emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                            (real_T), &bb_emlrtRTEI);
          vals->data[0] = muDoubleScalarSqrt(c_x) - muDoubleScalarSqrt(h_x);
        } else {
          emxInit_boolean_T(sp, &e_t, 2, &bb_emlrtRTEI, true);
          b_x = e_t->size[0] * e_t->size[1];
          e_t->size[0] = 1;
          e_t->size[1] = 1 + x->size[1];
          emxEnsureCapacity(sp, (emxArray__common *)e_t, b_x, (int32_T)sizeof
                            (boolean_T), &bb_emlrtRTEI);
          b_x = gridT->size[1];
          i = (int32_T)((uint32_T)j + 1U);
          e_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
            b_x, &j_emlrtBCI, sp) - 1]);
          i = x->size[1];
          for (b_x = 0; b_x < i; b_x++) {
            e_t->data[e_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] !=
              ksi);
          }

          st.site = &te_emlrtRSI;
          if (all(&st, e_t)) {
            st.site = &d_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)j;
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &k_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &i_x, 2, &bb_emlrtRTEI, true);
            b_x = i_x->size[0] * i_x->size[1];
            i_x->size[0] = 1;
            i_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)i_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              i_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r11, 2, &bb_emlrtRTEI, true);
            b_abs(sp, i_x, r11);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r11->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r11->size[0] * r11->size[1];
            emxFree_real_T(&i_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r11->data[b_x];
            }

            emxFree_real_T(&r11);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
            st.site = &e_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)((uint32_T)j + 1U);
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &l_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &j_x, 2, &bb_emlrtRTEI, true);
            b_x = j_x->size[0] * j_x->size[1];
            j_x->size[0] = 1;
            j_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)j_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              j_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r12, 2, &bb_emlrtRTEI, true);
            b_abs(sp, j_x, r12);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r12->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r12->size[0] * r12->size[1];
            emxFree_real_T(&j_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r12->data[b_x];
            }

            emxFree_real_T(&r12);
            emxInit_real_T(sp, &z1, 2, &db_emlrtRTEI, true);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z1);
            st.site = &ue_emlrtRSI;
            mpower(&st, z0, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            b->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              b->data[i] = muDoubleScalarExp(b->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, b, z0);
            st.site = &ue_emlrtRSI;
            mpower(&st, z1, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              r8->data[i] = muDoubleScalarExp(r8->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, r8, z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = r8->size[b_x];
            }

            emxInit_real_T(sp, &c_z0, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = c_z0->size[0] * c_z0->size[1];
            c_z0->size[0] = 1;
            c_z0->size[1] = z0->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)c_z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0] * z0->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              c_z0->data[b_x] = z0->data[b_x];
            }

            b_erf(sp, c_z0, z0);
            b_erf(sp, z1, d_x);
            emxFree_real_T(&c_z0);
            emxFree_real_T(&z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              f_x[b_x] = d_x->size[b_x];
            }

            emlrtSizeEqCheck2DFastR2012b(b_z0, f_x, &n_emlrtECI, sp);
            b_x = z0->size[0] * z0->size[1];
            z0->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0];
            b_x = z0->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              z0->data[b_x] = 1.7724538509055159 * (z0->data[b_x] - d_x->
                data[b_x]);
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            emxInit_real_T(sp, &k_x, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = k_x->size[0] * k_x->size[1];
            k_x->size[0] = 1;
            k_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)k_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              k_x->data[b_x] = x->data[b_x] - ksi;
            }

            b_abs(sp, k_x, d_x);
            rdivide(sp, d_x, 3.5449077018110318, vals);
            st.site = &ue_emlrtRSI;
            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = b->size[0];
            b_x = b->size[1];
            i *= b_x;
            emxFree_real_T(&k_x);
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = (b->data[b_x] - r8->data[b_x]) + z0->data[b_x];
            }

            b_st.site = &he_emlrtRSI;
            if (!(vals->size[1] == 1)) {
              if ((vals->size[1] == 1) || (b->size[1] == 1)) {
                c_y = NULL;
                m6 = emlrtCreateCharArray(2, iv18);
                for (i = 0; i < 45; i++) {
                  cv18[i] = cv19[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
                emlrtAssign(&c_y, m6);
                c_st.site = &fh_emlrtRSI;
                d_st.site = &vg_emlrtRSI;
                b_error(&c_st, message(&d_st, c_y, &j_emlrtMCI), &k_emlrtMCI);
              } else {
                d_y = NULL;
                m6 = emlrtCreateCharArray(2, iv19);
                for (i = 0; i < 21; i++) {
                  cv20[i] = cv21[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
                emlrtAssign(&d_y, m6);
                c_st.site = &gh_emlrtRSI;
                d_st.site = &wg_emlrtRSI;
                b_error(&c_st, message(&d_st, d_y, &l_emlrtMCI), &m_emlrtMCI);
              }
            }

            c_x = vals->data[0];
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = b->size[1];
            emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)
                              sizeof(real_T), &bb_emlrtRTEI);
            i = b->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
            }
          } else {
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            vals->data[0] = 0.0;
          }

          emxFree_boolean_T(&e_t);
        }

        emxFree_boolean_T(&d_t);
      }

      emxFree_boolean_T(&c_t);
      emxFree_real_T(&d_x);
      emxFree_real_T(&z0);
    }

    emxFree_boolean_T(&b_t);
  }

  emxFree_real_T(&r8);
  emxFree_real_T(&b);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Example #10
0
/* Function Definitions */
real_T Acoeff(const emlrtStack *sp, real_T ksi, real_T j, real_T x, real_T t,
              const emxArray_real_T *gridT)
{
  real_T vals;
  int32_T k;
  int32_T i0;
  boolean_T b_x[3];
  boolean_T y;
  boolean_T exitg4;
  real_T c_x;
  boolean_T exitg3;
  real_T z0;
  boolean_T d_x[2];
  boolean_T exitg2;
  real_T z1;
  boolean_T exitg1;
  emlrtStack st;
  emlrtStack b_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;

  /*  evaluate the coefficient A at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  k = gridT->size[1];
  i0 = (int32_T)emlrtIntegerCheckFastR2012b(j, &emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &d_emlrtBCI,
       sp) - 1]) {
    vals = 0.0;
  } else {
    k = gridT->size[1];
    i0 = (int32_T)j;
    b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
               &e_emlrtBCI, sp) - 1]);
    k = gridT->size[1];
    i0 = (int32_T)((uint32_T)j + 1U);
    b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
               &f_emlrtBCI, sp) - 1]);
    b_x[2] = (x == ksi);
    y = true;
    k = 0;
    exitg4 = false;
    while ((!exitg4) && (k < 3)) {
      if (b_x[k] == 0) {
        y = false;
        exitg4 = true;
      } else {
        k++;
      }
    }

    if (y) {
      k = gridT->size[1];
      i0 = (int32_T)j;
      emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &c_emlrtBCI, sp);
      c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
      st.site = &emlrtRSI;
      if (c_x < 0.0) {
        b_st.site = &f_emlrtRSI;
        eml_error(&b_st);
      }

      vals = muDoubleScalarSqrt(c_x);
    } else {
      k = gridT->size[1];
      i0 = (int32_T)j;
      b_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                 &g_emlrtBCI, sp) - 1]);
      k = gridT->size[1];
      i0 = (int32_T)((uint32_T)j + 1U);
      b_x[1] = (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                 &h_emlrtBCI, sp) - 1]);
      b_x[2] = (x != ksi);
      y = true;
      k = 0;
      exitg3 = false;
      while ((!exitg3) && (k < 3)) {
        if (b_x[k] == 0) {
          y = false;
          exitg3 = true;
        } else {
          k++;
        }
      }

      if (y) {
        st.site = &b_emlrtRSI;
        k = gridT->size[1];
        i0 = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
          &m_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        z0 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
        vals = muDoubleScalarAbs(x - ksi) / 3.5449077018110318 *
          (muDoubleScalarExp(-(z0 * z0)) / z0 - 1.7724538509055159 * scalar_erf
           (z0));
      } else {
        k = gridT->size[1];
        i0 = (int32_T)((uint32_T)j + 1U);
        d_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                   &i_emlrtBCI, sp) - 1]);
        d_x[1] = (x == ksi);
        y = true;
        k = 0;
        exitg2 = false;
        while ((!exitg2) && (k < 2)) {
          if (d_x[k] == 0) {
            y = false;
            exitg2 = true;
          } else {
            k++;
          }
        }

        if (y) {
          k = gridT->size[1];
          i0 = (int32_T)j;
          emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &b_emlrtBCI, sp);
          c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
          k = gridT->size[1];
          i0 = (int32_T)(j + 1.0);
          emlrtDynamicBoundsCheckFastR2012b(i0, 1, k, &emlrtBCI, sp);
          z1 = (t - gridT->data[(int32_T)(j + 1.0) - 1]) / 3.1415926535897931;
          st.site = &c_emlrtRSI;
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &c_emlrtRSI;
          if (z1 < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          vals = muDoubleScalarSqrt(c_x) - muDoubleScalarSqrt(z1);
        } else {
          k = gridT->size[1];
          i0 = (int32_T)((uint32_T)j + 1U);
          d_x[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
                     &j_emlrtBCI, sp) - 1]);
          d_x[1] = (x != ksi);
          y = true;
          k = 0;
          exitg1 = false;
          while ((!exitg1) && (k < 2)) {
            if (d_x[k] == 0) {
              y = false;
              exitg1 = true;
            } else {
              k++;
            }
          }

          if (y) {
            st.site = &d_emlrtRSI;
            k = gridT->size[1];
            i0 = (int32_T)j;
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
              &k_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            z0 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
            st.site = &e_emlrtRSI;
            k = gridT->size[1];
            i0 = (int32_T)((uint32_T)j + 1U);
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i0, 1, k,
              &l_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            z1 = muDoubleScalarAbs(x - ksi) / (2.0 * muDoubleScalarSqrt(c_x));
            vals = muDoubleScalarAbs(x - ksi) / 3.5449077018110318 *
              ((muDoubleScalarExp(-(z0 * z0)) / z0 - muDoubleScalarExp(-(z1 * z1))
                / z1) + 1.7724538509055159 * (b_scalar_erf(z0) - b_scalar_erf(z1)));
          } else {
            vals = 0.0;
          }
        }
      }
    }
  }

  return vals;
}
Example #11
0
real_T logpdf(const emxArray_real_T *x, const emxArray_real_T *A, real_T C)
{
  real_T f;
  emxArray_real_T *a;
  int32_T i2;
  int32_T i;
  const mxArray *y;
  static const int32_T iv2[2] = { 1, 45 };

  const mxArray *m0;
  char_T cv1[45];
  static const char_T cv2[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D',
    'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p',
    'a', 'n', 's', 'i', 'o', 'n' };

  const mxArray *b_y;
  static const int32_T iv3[2] = { 1, 21 };

  char_T cv3[21];
  static const char_T cv4[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' };

  emxArray_real_T *c_y;
  int32_T loop_ub;
  int32_T i3;
  uint32_T unnamed_idx_0;
  real_T alpha1;
  real_T beta1;
  char_T TRANSB;
  char_T TRANSA;
  ptrdiff_t m_t;
  ptrdiff_t n_t;
  ptrdiff_t k_t;
  ptrdiff_t lda_t;
  ptrdiff_t ldb_t;
  ptrdiff_t ldc_t;
  double * alpha1_t;
  double * Aia0_t;
  double * Bib0_t;
  double * beta1_t;
  double * Cic0_t;
  emxArray_real_T *b_x;
  boolean_T overflow;
  boolean_T p;
  int32_T exitg1;
  const mxArray *d_y;
  static const int32_T iv4[2] = { 1, 30 };

  char_T cv5[30];
  static const char_T cv6[30] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 's', 'u', 'm', '_', 's', 'p', 'e', 'c', 'i', 'a',
    'l', 'E', 'm', 'p', 't', 'y' };

  const mxArray *e_y;
  static const int32_T iv5[2] = { 1, 36 };

  char_T cv7[36];
  static const char_T cv8[36] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'a', 'u', 't', 'o', 'D', 'i', 'm', 'I', 'n', 'c',
    'o', 'm', 'p', 'a', 't', 'i', 'b', 'i', 'l', 'i', 't', 'y' };

  emxArray_real_T *b_a;
  const mxArray *f_y;
  static const int32_T iv6[2] = { 1, 45 };

  const mxArray *g_y;
  static const int32_T iv7[2] = { 1, 21 };

  emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal);
  emxInit_real_T(&a, 2, &e_emlrtRTEI, TRUE);
  emlrtPushRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal);
  i2 = a->size[0] * a->size[1];
  a->size[0] = A->size[0];
  a->size[1] = A->size[1];
  emxEnsureCapacity((emxArray__common *)a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = A->size[0] * A->size[1];
  for (i2 = 0; i2 < i; i2++) {
    a->data[i2] = -A->data[i2];
  }

  emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if (!(a->size[1] == x->size[0])) {
    if (((a->size[0] == 1) && (a->size[1] == 1)) || (x->size[0] == 1)) {
      emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
      y = NULL;
      m0 = mxCreateCharArray(2, iv2);
      for (i = 0; i < 45; i++) {
        cv1[i] = cv2[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1);
      emlrtAssign(&y, m0);
      error(message(y, &b_emlrtMCI), &c_emlrtMCI);
      emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    } else {
      emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
      b_y = NULL;
      m0 = mxCreateCharArray(2, iv3);
      for (i = 0; i < 21; i++) {
        cv3[i] = cv4[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3);
      emlrtAssign(&b_y, m0);
      error(message(b_y, &d_emlrtMCI), &e_emlrtMCI);
      emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  b_emxInit_real_T(&c_y, 1, &e_emlrtRTEI, TRUE);
  if ((a->size[1] == 1) || (x->size[0] == 1)) {
    i2 = c_y->size[0];
    c_y->size[0] = a->size[0];
    emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                      &e_emlrtRTEI);
    i = a->size[0];
    for (i2 = 0; i2 < i; i2++) {
      c_y->data[i2] = 0.0;
      loop_ub = a->size[1];
      for (i3 = 0; i3 < loop_ub; i3++) {
        c_y->data[i2] += a->data[i2 + a->size[0] * i3] * x->data[i3];
      }
    }
  } else {
    unnamed_idx_0 = (uint32_T)a->size[0];
    emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    i2 = c_y->size[0];
    c_y->size[0] = (int32_T)unnamed_idx_0;
    emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                      &e_emlrtRTEI);
    i = (int32_T)unnamed_idx_0;
    for (i2 = 0; i2 < i; i2++) {
      c_y->data[i2] = 0.0;
    }

    if ((a->size[0] < 1) || (a->size[1] < 1)) {
    } else {
      emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
      alpha1 = 1.0;
      beta1 = 0.0;
      TRANSB = 'N';
      TRANSA = 'N';
      emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      m_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      n_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      k_t = (ptrdiff_t)(a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      lda_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      ldb_t = (ptrdiff_t)(a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      ldc_t = (ptrdiff_t)(a->size[0]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal);
      alpha1_t = (double *)(&alpha1);
      emlrtPopRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
      Aia0_t = (double *)(&a->data[0]);
      emlrtPopRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
      Bib0_t = (double *)(&x->data[0]);
      emlrtPopRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
      beta1_t = (double *)(&beta1);
      emlrtPopRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
      Cic0_t = (double *)(&c_y->data[0]);
      emlrtPopRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t,
            &ldb_t, beta1_t, Cic0_t, &ldc_t);
      emlrtPopRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal);
  }

  emxFree_real_T(&a);
  b_emxInit_real_T(&b_x, 1, &e_emlrtRTEI, TRUE);
  i2 = b_x->size[0];
  b_x->size[0] = c_y->size[0];
  emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = c_y->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_x->data[i2] = c_y->data[i2];
  }

  for (i = 0; i < c_y->size[0]; i++) {
    b_x->data[i] = muDoubleScalarExp(b_x->data[i]);
  }

  i2 = b_x->size[0];
  emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = b_x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_x->data[i2]++;
  }

  i2 = c_y->size[0];
  c_y->size[0] = b_x->size[0];
  emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = b_x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    c_y->data[i2] = b_x->data[i2];
  }

  for (i = 0; i < b_x->size[0]; i++) {
    if (b_x->data[i] < 0.0) {
      emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
      eml_error();
      emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  for (i = 0; i < b_x->size[0]; i++) {
    c_y->data[i] = muDoubleScalarLog(c_y->data[i]);
  }

  emxFree_real_T(&b_x);
  overflow = FALSE;
  p = FALSE;
  i = 0;
  do {
    exitg1 = 0;
    if (i < 2) {
      if (i + 1 <= 1) {
        i2 = c_y->size[0];
      } else {
        i2 = 1;
      }

      if (i2 != 0) {
        exitg1 = 1;
      } else {
        i++;
      }
    } else {
      p = TRUE;
      exitg1 = 1;
    }
  } while (exitg1 == 0);

  if (!p) {
  } else {
    overflow = TRUE;
  }

  if (!overflow) {
  } else {
    emlrtPushRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
    d_y = NULL;
    m0 = mxCreateCharArray(2, iv4);
    for (i = 0; i < 30; i++) {
      cv5[i] = cv6[i];
    }

    emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 30, m0, cv5);
    emlrtAssign(&d_y, m0);
    error(message(d_y, &h_emlrtMCI), &i_emlrtMCI);
    emlrtPopRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal);
  }

  if ((c_y->size[0] == 1) || (c_y->size[0] != 1)) {
    overflow = TRUE;
  } else {
    overflow = FALSE;
  }

  if (overflow) {
  } else {
    emlrtPushRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
    e_y = NULL;
    m0 = mxCreateCharArray(2, iv5);
    for (i = 0; i < 36; i++) {
      cv7[i] = cv8[i];
    }

    emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 36, m0, cv7);
    emlrtAssign(&e_y, m0);
    error(message(e_y, &j_emlrtMCI), &k_emlrtMCI);
    emlrtPopRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal);
  }

  if (c_y->size[0] == 0) {
    alpha1 = 0.0;
  } else {
    alpha1 = c_y->data[0];
    emlrtPushRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
    if (2 > c_y->size[0]) {
      overflow = FALSE;
    } else {
      overflow = (c_y->size[0] > 2147483646);
    }

    if (overflow) {
      emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
      check_forloop_overflow_error();
      emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal);
    for (i = 2; i <= c_y->size[0]; i++) {
      alpha1 += c_y->data[i - 1];
    }
  }

  emxFree_real_T(&c_y);
  emxInit_real_T(&b_a, 2, &e_emlrtRTEI, TRUE);
  i2 = b_a->size[0] * b_a->size[1];
  b_a->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = x->size[0];
  i2 = b_a->size[0] * b_a->size[1];
  b_a->size[1] = i;
  emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T),
                    &e_emlrtRTEI);
  i = x->size[0];
  for (i2 = 0; i2 < i; i2++) {
    b_a->data[i2] = x->data[i2];
  }

  emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if (!(b_a->size[1] == x->size[0])) {
    if ((b_a->size[1] == 1) || (x->size[0] == 1)) {
      emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
      f_y = NULL;
      m0 = mxCreateCharArray(2, iv6);
      for (i = 0; i < 45; i++) {
        cv1[i] = cv2[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1);
      emlrtAssign(&f_y, m0);
      error(message(f_y, &b_emlrtMCI), &c_emlrtMCI);
      emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal);
    } else {
      emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
      g_y = NULL;
      m0 = mxCreateCharArray(2, iv7);
      for (i = 0; i < 21; i++) {
        cv3[i] = cv4[i];
      }

      emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3);
      emlrtAssign(&g_y, m0);
      error(message(g_y, &d_emlrtMCI), &e_emlrtMCI);
      emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal);
    }
  }

  emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal);
  if ((b_a->size[1] == 1) || (x->size[0] == 1)) {
    beta1 = 0.0;
    for (i2 = 0; i2 < b_a->size[1]; i2++) {
      beta1 += b_a->data[b_a->size[0] * i2] * x->data[i2];
    }
  } else {
    emlrtPushRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPushRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
    if (b_a->size[1] < 1) {
      beta1 = 0.0;
    } else {
      emlrtPushRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      n_t = (ptrdiff_t)(b_a->size[1]);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      m_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      k_t = (ptrdiff_t)(1);
      emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPopRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
      alpha1_t = (double *)(&b_a->data[0]);
      emlrtPopRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal);
      emlrtPushRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
      Aia0_t = (double *)(&x->data[0]);
      emlrtPopRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal);
      beta1 = ddot(&n_t, alpha1_t, &m_t, Aia0_t, &k_t);
      emlrtPopRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal);
    }

    emlrtPopRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal);
    emlrtPopRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal);
  }

  emxFree_real_T(&b_a);
  f = -C * alpha1 - 0.5 * beta1;
  emlrtPopRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal);
  emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal);
  return f;
}