Example #1
0
 void *calc(int idx)
 {
     if (calcCurrent(idx)) {
         m_val = m_op.eval(*(Ti *)m_child->calc(idx));
     }
     return (void *)&m_val;
 }
Example #2
0
 void *calc(int x, int y, int z, int w)
 {
     if (calcCurrent(x, y, z, w)) {
         m_val = m_op.eval(*(Ti *)m_child->calc(x, y, z, w));
     }
     return (void *)(&m_val);
 }
float CalcProcessor::calculate(QString formula)
{
    formula = pTranslator.translate(formula);
    numbersStack.clear();
    QString word = "";
    bool isEditing = false;

    for (int i = 0; i < formula.size(); i++)
    {
        if (isInteger(formula.at(i)))
        {
            word.push_back(formula.at(i));
            isEditing = true;
        }
        if (isOperator(formula.at(i)))
        {
            numbersStack.push(QString::number(
                                   calcCurrent(numbersStack.pop().toFloat(),
                                               numbersStack.pop().toFloat(),
                                               formula.at(i))));
        }
        if (formula.at(i) == QChar(' ') && isEditing)
        {
            numbersStack.push(word);
            word.clear();
            isEditing = false;
        }
    }

    return numbersStack.pop().toFloat();
}
Example #4
0
CSSM_RETURN ocspdCrlRefresh(
	CSSM_DL_DB_HANDLE	dlDbHand,
	CSSM_CL_HANDLE		clHand,
	unsigned			staleDays,
	unsigned			expireOverlapSeconds,
	bool				purgeAll,
	bool				fullCryptoVerify,
	bool				doRefresh)		// false: just purge stale entries
{
	CSSM_TP_HANDLE	tpHand = 0;
	CSSM_CSP_HANDLE cspHand = 0;
	CSSM_RETURN		crtn = CSSM_OK;
	
	assert((dlDbHand.DLHandle != 0) &&
		   (dlDbHand.DBHandle != 0) &&
		   (clHand != 0));
		   
	if(staleDays == 0) {
		staleDays = DEFAULT_STALE_DAYS;
	}
	if(expireOverlapSeconds == 0) {
		expireOverlapSeconds = DEFAULT_EXPIRE_OVERLAP_SECONDS;
	}
	
	if(fullCryptoVerify) {
		/* also need TP, CSP */
		cspHand = attachCommon(&gGuidAppleCSP, CSSM_SERVICE_CSP);
		if(cspHand == 0) {
			Syslog::alert("Error loading AppleCSP");
			return CSSMERR_CSSM_ADDIN_LOAD_FAILED;
		}
		tpHand = attachCommon(&gGuidAppleX509TP, CSSM_SERVICE_TP);
		if(tpHand == 0) {
			Syslog::alert("Error loading AppleX509TP");
			crtn = CSSMERR_CSSM_ADDIN_LOAD_FAILED;
			goto errOut;
		}
	}
	/* subsequent errors to errOut: */
	
	/* fetch all CRLs from the keychain */
	CrlInfo		**crlInfo;
	unsigned	numCrls;
	
	crtn = fetchAllCrls(dlDbHand, fullCryptoVerify, crlInfo, numCrls);
	if(crtn) {
		ocspdErrorLog("ocspdCrlRefresh: Error reading CRLs.");
		return crtn;
	}
	ocspdCrlDebug("ocspdCrlRefresh: %u CRLs found", numCrls);
	
	/* basic validation */
	validateCrls(crlInfo, numCrls);
	
	/* Optional full crypto validation */
	if(fullCryptoVerify) {
		cryptoValidateCrls(crlInfo, numCrls, tpHand, cspHand, clHand, 
			dlDbHand.DLHandle);
	}
	
	/* update the validity time flags on the CRLs */
	if(calcCurrent(crlInfo, numCrls, expireOverlapSeconds,
			staleDays * SECONDS_PER_DAY)) {
		ocspdErrorLog("ocspdCrlRefresh: Error calculating CRL times.");
		crtn = CSSMERR_TP_INTERNAL_ERROR;
		goto errOut;
	}
	
	if(purgeAll) {
		/* mark all of them stale */
		purgeAllCrls(crlInfo, numCrls);
	}
	
	/* 
	 * Delete all bad CRLs from DB. We do this before the refresh in 
	 * case of the purgeAll option, in which case we really want to 
	 * insert newly fetched CRLs in the DB even if they appear to 
	 * be trhe same as the ones they're replacing.
	 */
	deleteBadCrls(crlInfo, numCrls);
	
	/* refresh the out-of-date CRLs */
	if(doRefresh) {
		refreshExpiredCrls(crlInfo, numCrls, clHand);
	}
	
	/* clean up */
	for(unsigned dex=0; dex<numCrls; dex++) {
		delete crlInfo[dex];
	}
	free(crlInfo);

errOut:
	if(cspHand) {
		detachCommon(&gGuidAppleCSP, cspHand);
	}
	if(tpHand) {
		detachCommon(&gGuidAppleX509TP, tpHand);
	}
	return crtn;
}
int main(int argc, char* argv[]) {
  if ( argc != 10 ) {
    printf("Usage: %s inFile diffuseFile forceFile timestep time kT perturbation outPeriod outPrefix\n", argv[0]);
    return 0;
  }
  const char* inFile = argv[1];
  const char* diffuseFile = argv[2];
  const char* forceFile = argv[3];
  double timestep = strtod(argv[4], NULL);
  double tim = strtod(argv[5], NULL);
  double kT = strtod(argv[6], NULL);
  double perturbation = strtod(argv[7], NULL);
  int outPeriod = atoi(argv[argc-2]);
  const char* outPrefix = argv[argc-1];

  printf("perturbation %g\n", perturbation);

  bool periodic = false;

  // Load the diffusivity and force.
  PiecewiseCubic diffuse(diffuseFile, periodic);
  PiecewiseCubic force(forceFile, periodic);

  // Load the solution domain.
  PiecewiseCubic init(inFile, periodic);
  const int n = init.length();
  double* prob = new double[n];
  for (int i = 0; i < n; i++) prob[i] = init.get(i);
  // For storing the current.
  PiecewiseCubic curr(init);

  // Prepare to do the finite difference.
  int steps = int(ceil(tim/timestep));
  if (steps == 0) {
    fprintf(stderr, "No steps!\n");
    exit(-1);
  }
  if (outPeriod <= 0) outPeriod = steps;
  int cycles = steps/outPeriod;
  printf("steps %d\n", steps);
  printf("cycles %d\n", cycles);

  // The main object.
  CrankNicholsonSolver solver(&init, timestep, kT, 1.0, 1.0-perturbation);

  // Initialize the clock.
  clock_t clockInit = clock();

  char outFile[256];
  for (int c = 0; c < cycles; c++) {
    // Write the output.
    init.reset(prob, init.getPeriodic());
    snprintf(outFile, 256, "%s.%d.dat", outPrefix, c);
    init.write(outFile);

    snprintf(outFile, 256, "%s.%d.curr", outPrefix, c);
    calcCurrent(curr, init, diffuse, force, kT);
    curr.write(outFile);

    snprintf(outFile, 256, "%s.%d.resisty", outPrefix, c);
    calcResistivity(curr, init, diffuse, force, kT);
    curr.write(outFile);

    solver.solve(prob, outPeriod, &diffuse, &force, NULL);
  }

  init.reset(prob, init.getPeriodic());
  snprintf(outFile, 256, "%s.final.dat", outPrefix);
  init.write(outFile);
  printf("value1 %g\n", prob[n/2]);
  
  printf("\nRun time: %.4g s\n", double(clock()-clockInit)/CLOCKS_PER_SEC);

  delete[] prob;
  return 0;
}