Example #1
0
IFunction_sptr IqtFit::createUserFunction(const QString &name, bool tie) {
  IFunction_sptr result =
      FunctionFactory::Instance().createFunction("UserFunction");
  std::string formula;

  if (name.startsWith("Exp")) {
    formula = "Intensity*exp(-(x/Tau))";
  } else {
    formula = "Intensity*exp(-(x/Tau)^Beta)";
  }

  IFunction::Attribute att(formula);
  result->setAttribute("Formula", att);

  QList<QtProperty *> props = m_properties[name]->subProperties();
  for (int i = 0; i < props.size(); i++) {
    std::string name = props[i]->propertyName().toStdString();
    result->setParameter(name, m_dblManager->value(props[i]));

    // add tie if parameter is fixed
    if (tie || !props[i]->subProperties().isEmpty()) {
      std::string value = props[i]->valueText().toStdString();
      result->tie(name, value);
    }
  }

  result->applyTies();
  return result;
}
Example #2
0
/**
 * @param fun :: The function
 * @param expr :: The tie expression: parName = TieString
 */
void FunctionFactoryImpl::addTie(IFunction_sptr fun,
                                 const Expression &expr) const {
  if (expr.size() > 1) { // if size > 2 it is interpreted as setting a tie (last
    // expr.term) to multiple parameters, e.g
    // f1.alpha = f2.alpha = f3.alpha = f0.beta^2/2
    const std::string value = expr[expr.size() - 1].str();
    for (size_t i = expr.size() - 1; i != 0;) {
      --i;
      fun->tie(expr[i].name(), value);
    }
  }
}