Esempio n. 1
0
Astnode *term()
{
    Astnode *fnode  = factor();
    Astnode *t1node = term1();

    return create_node(OP_MUL, fnode, t1node);
}
Esempio n. 2
0
int term()
{
    /* term -> factor term1 */

    factor();
    term1();
}
Esempio n. 3
0
bool parserCls::exprssion(void)
{exprFound=false;needOperand=false;exprErrorFlag=false;
 noTokenInExpr = 0 ; term1();
 if(exprErrorFlag)
	return false;
 return  true;;
}
Esempio n. 4
0
int term1()
{
	/* newly added
	 * term1 -> TIMES factor term1
	 * 		  | TIMES factor term2
	 * 		  | term2
	 */
	 
	if(match(TIMES))
	{
		advance();
		factor();
		if(match(TIMES))
		{
			advance();
			factor();
			term1();
			printf("*\n");
		}
		term_prime();
		printf("*\n");
	}
	else
	{
		term_prime();
	}
}
Esempio n. 5
0
void parserCls::recursiveLparen(void)
{tokenContainCls tc1=getCurToken();//save the Lparen token for error Reprot
 int curNoTok1 = noTokenInExpr;	getToken();// get next token after (
 if(term1() )
 { EtokenType  lt1= getTokenType();
	if(lt1 != Rparen) errorRecursLparen(1, tc1);
	else if(noTokenInExpr-curNoTok1 == 0) errorRecursLparen(0, tc1);
	else	getToken();
 }
}
const Real GreensFunction2DAbs::p_int_theta_first(const Real r,
                                                  const Real theta,
                                                  const Real t) const
{
    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real minusDt(-1e0 * this->getD() * t);

    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term3(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r_alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r_alpha_n  = gsl_sf_bessel_J0(r * alpha_n);
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(alpha_n * alpha_n * minusDt);
        term2 = J0_r_alpha_n * J0_r0_alpha_n;
        term3 = J1_a_alpha_n * J1_a_alpha_n;

        term = term1 * term2 / term3;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. n = " << n << " first term" << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;

//         return (sum / (M_PI * a * a));
    return (theta * sum / (M_PI * a * a));
}
const Real GreensFunction2DAbs::p_int_r(const Real r, const Real t) const
{
    //speed of convergence is too slow
    if(r == 0e0) return 0e0;

    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real Dt(this->getD() * t);
    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term3(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_r_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_r_alpha_n  = gsl_sf_bessel_J1(r * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(-1e0 * alpha_n * alpha_n * Dt);
        term2 = r * J1_r_alpha_n * J0_r0_alpha_n;
        term3 = (alpha_n * J1_a_alpha_n * J1_a_alpha_n);

        term = term1 * term2 / term3;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. " << n << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;

    return (2e0 * sum / (a*a));
}
Esempio n. 8
0
Astnode *term1()
{
    Astnode *fnode;
    Astnode *t1node;

    switch (g_token.type) {
    case MUL:
        next_token();
        fnode  = factor();
        t1node = term1();

        return create_node(OP_MUL, t1node, fnode);
    case DIV:
        next_token();
        fnode  = factor();
        t1node = term1();

        return create_node(OP_DIV, t1node, fnode);
    }

    return create_numbernode(1);
}
Esempio n. 9
0
int term_prime()
{
    /* term2 -> TIMES factor term1
     * 		  | epsilon
     */

    if( match( DIV ) )
    {
	    advance();
        factor();
        printf("\\\n");
        term1();
    }
}
const Real GreensFunction2DAbs::p_survival(const Real t) const
{
    // when t == 0.0, return value become eventually 1.0,
    // but the speed of convergence is too slow.
    if(t == 0.0) return 1.0;

    const Real r_0(this->getr0());
    const Real a(this->geta());
    const Real Dt(this->getD() * t);
    const Integer num_term_use(100);
    const Real threshold(CUTOFF);

    Real sum(0e0);
    Real term1(0e0);
    Real term2(0e0);
    Real term(0e0);

    Real a_alpha_n(0e0);
    Real alpha_n(0e0);
    Real J0_r0_alpha_n(0e0);
    Real J1_a_alpha_n(0e0);

    Integer n(1);
    for(; n < num_term_use; ++n)
    {
        a_alpha_n = gsl_sf_bessel_zero_J0(n);
        alpha_n = a_alpha_n / a;
        J0_r0_alpha_n = gsl_sf_bessel_J0(r_0 * alpha_n);
        J1_a_alpha_n  = gsl_sf_bessel_J1(a_alpha_n);

        term1 = std::exp(-1e0 * alpha_n * alpha_n * Dt) * J0_r0_alpha_n;
        term2 = alpha_n * J1_a_alpha_n;
        term = term1 / term2;
        sum += term;

//             std::cout << "sum " << sum << ", term" << term << std::endl;

        if(fabs(term/sum) < threshold)
        {
//                 std::cout << "normal exit. " << n << std::endl;
            break;
        }
    }
    if(n == num_term_use)
        std::cout << "warning: use term over num_term_use" << std::endl;
    return (2e0 * sum / a);
}
Esempio n. 11
0
/// fa+b,c+d)
/// f is the name of function
// one error not checked f(a,,b)
bool parserCls::addFunction(tokenContainCls &lTc1)
{ lTc1.type = FunctionName; addOperand(lTc1);bool bb2 = true ;
  bool bb3=false;EtokenType  lt1;int iiExpr12=0,indexX=noTokenInExpr++;
  addOperand(lTc1); // for stack for change after end
 do{ if(bb3)	addOperand();
	  else 	 bb3 = true ;

	  getToken();// get next token after (
	  if(!term1() ){ bb2 = false   ;break ;}
	  if((noTokenInExpr-2) > (indexX))
			iiExpr12++;
	  lt1= getTokenType();
 }while((lt1==Comma));
 if(bb2) if(lt1 != Rparen)
	 {bb2 = false; errorRecursLparen(1, lTc1);}
 else {addOperator();getToken();}
 tokenContainCls lTc2(iiExpr12,1);
  addOperator(indexX, lTc2);
 return bb2 ;
}
Esempio n. 12
0
int term(big_int *a)
{
    big_int *b = NULL;
    int result = 0;

    b = big_int_create(1);
    if (b == NULL) {
        printf("error when creating [b]\n");
        result = 1;
        goto done;
    }

    if (term1(a)) {
        result = 2;
        goto done;
    }

    while (1) {
        switch ((int) curr_lex.token) {
            case '*' :
                match('*');
                if (term1(b)) {
                    result = 3;
                    goto done;
                }
                if (is_mod) {
                    if (big_int_mulmod(a, b, module, a)) {
                        printf("error in big_int_mulmod()\n");
                        result = 4;
                        goto done;
                    }
                } else {
                    if (big_int_mul(a, b, a)) {
                        printf("error in big_int_mul()\n");
                        result = 5;
                        goto done;
                    }
                }
                continue;
            case '/' : case DIV1 :
                match(curr_lex.token);
                if (term1(b)) {
                    result = 6;
                    goto done;
                }
                if (is_zero(b)) {
                    printf("division by zero\n");
                    result = 7;
                    goto done;
                }
                if (is_mod) {
                    switch (big_int_divmod(a, b, module, a)) {
                    case 0: break;
                    case 2:
                        printf("GCD(b, modulus) != 1\n");
                        result = 8;
                        goto done;
                    default :
                        printf("error in big_int_divmod()\n");
                        result = 8;
                        goto done;
                    }
                } else {
                    if (big_int_div(a, b, a)) {
                        printf("error in big_int_div()\n");
                        result = 9;
                        goto done;
                    }
                }
                continue;
            case '%' : case MOD1 :
                match(curr_lex.token);
                if (term1(b)) {
                    result = 10;
                    goto done;
                }
                if (is_zero(b)) {
                    printf("division by zero\n");
                    result = 11;
                    goto done;
                }
                if (big_int_mod(a, b, a)) {
                    printf("error in big_int_mod()\n");
                    result = 12;
                    goto done;
                }
                continue;
            default :
                goto done;
        }
    }

done:
    big_int_destroy(b);
    return result;
}
BoundaryOperator<BasisFunctionType, ResultType>
modifiedHelmholtz3dSyntheticHypersingularBoundaryOperator(
    const shared_ptr<const Context<BasisFunctionType, ResultType>> &context,
    const shared_ptr<const Space<BasisFunctionType>> &domain,
    const shared_ptr<const Space<BasisFunctionType>> &range,
    const shared_ptr<const Space<BasisFunctionType>> &dualToRange,
    KernelType waveNumber, std::string label, int internalSymmetry,
    bool useInterpolation, int interpPtsPerWavelength,
    const BoundaryOperator<BasisFunctionType, ResultType> &externalSlp) {
  typedef typename ScalarTraits<BasisFunctionType>::RealType CoordinateType;

  typedef Fiber::ScalarFunctionValueFunctor<CoordinateType> ValueFunctor;
  typedef Fiber::ScalarFunctionValueTimesNormalFunctor<CoordinateType>
      ValueTimesNormalFunctor;
  typedef Fiber::SurfaceCurl3dFunctor<CoordinateType> CurlFunctor;
  typedef Fiber::SingleComponentTestTrialIntegrandFunctor<
      BasisFunctionType, ResultType> IntegrandFunctor;

  typedef GeneralElementaryLocalOperator<BasisFunctionType, ResultType> LocalOp;
  typedef SyntheticIntegralOperator<BasisFunctionType, ResultType> SyntheticOp;

  if (!domain || !range || !dualToRange)
    throw std::invalid_argument(
        "modifiedHelmholtz3dSyntheticHypersingularBoundaryOperator(): "
        "domain, range and dualToRange must not be null");

  shared_ptr<const Space<BasisFunctionType>> newDomain = domain;
  shared_ptr<const Space<BasisFunctionType>> newDualToRange = dualToRange;

  bool isBarycentric =
      (domain->isBarycentric() || dualToRange->isBarycentric());

  if (isBarycentric) {
    newDomain = domain->barycentricSpace(domain);
    newDualToRange = dualToRange->barycentricSpace(dualToRange);
  }

  shared_ptr<const Context<BasisFunctionType, ResultType>> internalContext,
      auxContext;
  SyntheticOp::getContextsForInternalAndAuxiliaryOperators(
      context, internalContext, auxContext);
  shared_ptr<const Space<BasisFunctionType>> internalTrialSpace =
      newDomain->discontinuousSpace(newDomain);
  shared_ptr<const Space<BasisFunctionType>> internalTestSpace =
      newDualToRange->discontinuousSpace(newDualToRange);

  // Note: we don't really need to care about ranges and duals to domains of
  // the internal operator. The only range space that matters is that of the
  // leftmost operator in the product.

  const char xyz[] = "xyz";
  const size_t dimWorld = 3;

  if (label.empty())
    label =
        AbstractBoundaryOperator<BasisFunctionType, ResultType>::uniqueLabel();

  BoundaryOperator<BasisFunctionType, ResultType> slp;
  if (!externalSlp.isInitialized()) {

    slp = modifiedHelmholtz3dSingleLayerBoundaryOperator<
        BasisFunctionType, KernelType, ResultType>(
        internalContext, internalTrialSpace,
        internalTestSpace /* or whatever */, internalTestSpace, waveNumber,
        "(" + label + ")_internal_SLP", internalSymmetry, useInterpolation,
        interpPtsPerWavelength);
  } else {

    slp = externalSlp;
  }

  // symmetry of the decomposition
  int syntheseSymmetry = 0; // symmetry of the decomposition
  if (newDomain == newDualToRange && internalTrialSpace == internalTestSpace)
    syntheseSymmetry =
        HERMITIAN | (boost::is_complex<BasisFunctionType>() ? 0 : SYMMETRIC);

  std::vector<BoundaryOperator<BasisFunctionType, ResultType>> testLocalOps;
  std::vector<BoundaryOperator<BasisFunctionType, ResultType>> trialLocalOps;
  testLocalOps.resize(dimWorld);
  for (size_t i = 0; i < dimWorld; ++i)
    testLocalOps[i] = BoundaryOperator<BasisFunctionType, ResultType>(
        auxContext, boost::make_shared<LocalOp>(
                        internalTestSpace, range, newDualToRange,
                        ("(" + label + ")_test_curl_") + xyz[i], NO_SYMMETRY,
                        CurlFunctor(), ValueFunctor(), IntegrandFunctor(i, 0)));

  if (!syntheseSymmetry) {
    trialLocalOps.resize(dimWorld);
    for (size_t i = 0; i < dimWorld; ++i)
      trialLocalOps[i] = BoundaryOperator<BasisFunctionType, ResultType>(
          auxContext,
          boost::make_shared<LocalOp>(
              newDomain, internalTrialSpace /* or whatever */,
              internalTrialSpace, ("(" + label + ")_trial_curl_") + xyz[i],
              NO_SYMMETRY, ValueFunctor(), CurlFunctor(),
              IntegrandFunctor(0, i)));
  }
  // It might be more prudent to distinguish between the symmetry of the total
  // operator and the symmetry of the decomposition
  BoundaryOperator<BasisFunctionType, ResultType> term0(
      context, boost::make_shared<SyntheticOp>(testLocalOps, slp, trialLocalOps,
                                               label, syntheseSymmetry));

  for (size_t i = 0; i < dimWorld; ++i)
    testLocalOps[i] = BoundaryOperator<BasisFunctionType, ResultType>(
        auxContext,
        boost::make_shared<LocalOp>(
            internalTestSpace, range, newDualToRange,
            ("(" + label + ")_test_k_value_n_") + xyz[i], NO_SYMMETRY,
            ValueTimesNormalFunctor(), ValueFunctor(), IntegrandFunctor(i, 0)));
  if (!syntheseSymmetry)
    for (size_t i = 0; i < dimWorld; ++i)
      trialLocalOps[i] = BoundaryOperator<BasisFunctionType, ResultType>(
          auxContext,
          boost::make_shared<LocalOp>(
              newDomain, internalTrialSpace /* or whatever */,
              internalTrialSpace, ("(" + label + ")_trial_k_value_n_") + xyz[i],
              NO_SYMMETRY, ValueFunctor(), ValueTimesNormalFunctor(),
              IntegrandFunctor(0, i)));
  BoundaryOperator<BasisFunctionType, ResultType> slp_waveNumberSq =
      (waveNumber * waveNumber) * slp;
  BoundaryOperator<BasisFunctionType, ResultType> term1(
      context,
      boost::make_shared<SyntheticOp>(testLocalOps, slp_waveNumberSq,
                                      trialLocalOps, label, syntheseSymmetry));

  return term0 + term1;
}