예제 #1
0
real CostFunction::f1dim(const real x)
{
	int j;
	real f1 = 0.0;
	for (j=0; j<nState; j++) xt[j] = tempState[j] + x*tempGradient[j];
	f1 = funcValue(xt);
	return f1;
}
예제 #2
0
TacFunctionPtr TacFunction::createFunction(IdentifierPtr name, DeclarationsPtr arguments, TypePtr returnType)
{
    TacFunctionPtr func(new TacFunction(name->id.value(), arguments, returnType));
    TacValuePtr funcValue(new FunctionTacValue(func));

    func->parent = this;

    children.push_back(func);
    symbols.push_back(funcValue);

    return func;
}
예제 #3
0
void CostFunction::conjugateGradient(real* q, real* xi, const real ftol, real fret)
{
	const int ITMAX = 2000;
	const real EPS = 1.0e-18;
	int j, its;
	real gg, gam, fq, dgg;
	
	real* g = new real[nState];
	real* h = new real[nState];

	fq = funcValue(q);
	funcGradient(q, xi);
	for (j=0; j<nState; j++) {
		g[j] = -xi[j];
		xi[j] = h[j] = g[j];
	}
	for (its=0; its<ITMAX; its++) {
		cout << "\t\tIteration: " << its << "\tJ: " << fq << endl;
		dlinmin(q, xi, fret);
		if (2.0*fabs(fret-fq) <= ftol*(fabs(fret)+fabs(fq)+EPS)) {
			cout << "\tMinimum J: " << fret << endl;
			cout << "\tFound minimum in " << its << " iterations." << endl;
			delete[] g;
			delete[] h;
			return;
		}
		fq = fret;
		funcGradient(q, xi);
		dgg = gg = 0.0;
		for (j=0; j<nState; j++) {
			gg += g[j]*g[j];
			dgg += (xi[j]+g[j])*xi[j];
		}
		if (gg == 0.0) {
			return;
		}
		gam = dgg/gg;
		for (j=0; j<nState; j++) {
			g[j] = -xi[j];
			xi[j] = h[j] = g[j] + gam*h[j];
		}
	}
	// Got here there were too many iterations
	delete[] g;
	delete[] h;
	cout << "Iterations exceeded in inner minimization loop" << endl;
	return;
}
예제 #4
0
파일: ForcingFn.C 프로젝트: ChaliZhg/moose
Real
ForcingFn::computeQpResidual()
{
  return -funcValue() * _test[_i][_qp];
}