예제 #1
0
파일: OptHOM.cpp 프로젝트: iyer-arvind/gmsh
void OptHOM::evalObjGrad(const alglib::real_1d_array &x, double &Obj,
                         alglib::real_1d_array &gradObj)
{
  NEVAL++;
  mesh.updateMesh(x.getcontent());

  Obj = 0.;
  for (int i = 0; i < gradObj.length(); i++) gradObj[i] = 0.;

  //  printf("Computing Obj : ");
  /// control Jacobians
  addJacObjGrad(Obj, gradObj);
  /// Control distance to the straight sided mesh
  addDistObjGrad(lambda, Obj, gradObj);

  if(_optimizeMetricMin)
    addMetricMinObjGrad(Obj, gradObj);
  if(_optimizeCAD)
    addBndObjGrad(lambda3, Obj, gradObj);

  //  printf("Obj = %12.5E\n",Obj);

  if ((minJac > barrier_min) && (maxJac < barrier_max || !_optimizeBarrierMax) && (maxDistCAD < distance_max|| !_optimizeCAD) ) {
    Msg::Info("Reached %s (%g %g) requirements, setting null gradient",
              _optimizeMetricMin ? "svd" : "jacobian", minJac, maxJac);
    Obj = 0.;
    for (int i = 0; i < gradObj.length(); i++) gradObj[i] = 0.;
  }
}
예제 #2
0
파일: LinReg.cpp 프로젝트: cfdickmann/utils
void fv(const alglib::real_1d_array &x, alglib::real_1d_array &fi, void *ptr) {
	auto R = (LinReg*) (ptr);
	vector<double> koeff(x.length());
	for (size_t i = 0; i < koeff.size(); ++i)
		koeff[i] = x[i];

	for (int i = 0; i < (int) fi.length(); ++i)
		fi[i] = R->lin_comb(koeff, R->f, R->x[i]) - R->y[i];
}
예제 #3
0
void MeshOpt::evalObjGrad(const alglib::real_1d_array &x, double &obj,
                                         alglib::real_1d_array &gradObj)
{
  patch.updateMesh(x.getcontent());
  _objFunc->compute(obj, gradObj);
  if (_objFunc->targetReached()) {
    if (_verbose > 2) Msg::Info("Reached target values, setting null gradient");
    obj = 0.;
    for (int i = 0; i < gradObj.length(); i++) gradObj[i] = 0.;
  }
}
예제 #4
0
bool ObjectiveFunction::compute(double &obj, alglib::real_1d_array &gradObj)
{
  obj = 0.;
  for (int i = 0; i < gradObj.length(); i++) gradObj[i] = 0.;
  bool ok = true;
  for (std::vector<ObjContrib*>::iterator it=begin(); it!=end(); it++)
    ok &= (*it)->addContrib(obj, gradObj);
  return ok;
}
예제 #5
0
파일: OptHOM.cpp 프로젝트: iyer-arvind/gmsh
void OptHOM::calcScale(alglib::real_1d_array &scale)
{
  scale.setlength(mesh.nPC());

  // Calculate scale
  for (int iFV = 0; iFV < mesh.nFV(); iFV++) {
    std::vector<double> scaleFV(mesh.nPCFV(iFV),1.);
    mesh.pcScale(iFV,scaleFV);
    for (int iPC = 0; iPC < mesh.nPCFV(iFV); iPC++)
      scale[mesh.indPCFV(iFV,iPC)] = scaleFV[iPC];
  }
}