Esempio n. 1
0
void Basis2D::fillCoefficients(const double* u, double* coefficients) {
  int N1 = basis1->getRank();
  int N2 = basis2->getRank();
  // The easy coordinates...
  for (int iCoord2 = 0; iCoord2 < N2; iCoord2++) {
    int index = functionIndex(0, iCoord2);
    // Pointer arithmetic.
    basis1->fillCoefficients(u + index, coefficients + index);
  }
  // The complicated coordinates...
  double coeffs1d[N2];
  double coeffs2d[N2];
  for (int iCoord1 = 0; iCoord1 < N1; iCoord1++) {
    // Copy 1d coefficients
    for (int iCoord2 = 0; iCoord2 < N2; iCoord2++) {
      int index = functionIndex(iCoord1, iCoord2);
      coeffs1d[iCoord2] = coefficients[index];
    }
    basis2->fillCoefficients(coeffs1d, coeffs2d);
    // Copy the 2d coefficients into the coefficients array.
    for (int iCoord2 = 0; iCoord2 < N2; iCoord2++) {
      int index = functionIndex(iCoord1, iCoord2);
      coefficients[index] = coeffs2d[iCoord2];
    }
  }
}
Esempio n. 2
0
/// Returns the name of active parameter i
std::string CompositeFunction::nameOfActive(size_t i) const {
  size_t iFun = functionIndex(i);
  std::ostringstream ostr;
  ostr << 'f' << iFun << '.'
       << m_functions[iFun]->nameOfActive(i - m_paramOffsets[iFun]);
  return ostr.str();
}
Esempio n. 3
0
double* Basis2D::tensorInterpolate(const double* u, const double* coord1,
    int n1, const double* coord2, int n2) {
  int nCoord1 = basis1->getRank();
  int nCoord2 = basis2->getRank();
  double* uInterpolatedAlongCoord2[nCoord1];
  for (int iCoord1 = 0; iCoord1 < nCoord1; iCoord1++) {
    double uConstCoord1[nCoord2];
    for (int iCoord2 = 0; iCoord2 < nCoord2; iCoord2++) {
      int index = functionIndex(iCoord1, iCoord2);
      uConstCoord1[iCoord2] = u[index];
    }
    uInterpolatedAlongCoord2[iCoord1] = 
      basis2->interpolate(uConstCoord1, coord2, n2);
  }
  double* uInterpolated = new double[n1*n2];
  for (int i2 = 0; i2 < n2; i2++) {
    double uConstCoord2[nCoord1];
    for (int iCoord1 = 0; iCoord1 < nCoord1; iCoord1++) {
      uConstCoord2[iCoord1] = uInterpolatedAlongCoord2[iCoord1][i2];
    }
    double* uInterpolatedAlongCoord1 = 
      basis1->interpolate(uConstCoord2, coord1, n1);
    for (int i1 = 0; i1 < n1; i1++) {
      int index = i2*n1 + i1; // Copied from functionIndex...
      uInterpolated[index] = uInterpolatedAlongCoord1[i1];
    }
    //delete[] uInterpolatedAlongCoord1;
  }
  for (int i = 0; i < nCoord1; i++) delete[] uInterpolatedAlongCoord2[i];
  //delete[] uInterpolatedAlongCoord2;
  return uInterpolated;
}
Esempio n. 4
0
/** Get the tie of i-th parameter
 * @param i :: The parameter index
 * @return A pointer to the tie.
 */
ParameterTie *CompositeFunction::getTie(size_t i) const {
  auto tie = IFunction::getTie(i);
  if (tie == nullptr) {
    size_t iFun = functionIndex(i);
    tie = m_functions[iFun]->getTie(i - m_paramOffsets[iFun]);
  }
  return tie;
}
Esempio n. 5
0
/// Get constraint
/// @param i :: the index
/// @return A pointer to the constraint
IConstraint *CompositeFunction::getConstraint(size_t i) const {
  auto constraint = IFunction::getConstraint(i);
  if (constraint == nullptr) {
    size_t iFun = functionIndex(i);
    constraint = m_functions[iFun]->getConstraint(i - m_paramOffsets[iFun]);
  }
  return constraint;
}
Esempio n. 6
0
/** Removes i-th parameter's tie if it is tied or does nothing.
 * @param i :: The index of the tied parameter.
 * @return True if successfull
 */
bool CompositeFunction::removeTie(size_t i) {
  bool foundAndRemovedTie = IFunction::removeTie(i);
  if (!foundAndRemovedTie) {
    size_t iFun = functionIndex(i);
    bool res = m_functions[iFun]->removeTie(i - m_paramOffsets[iFun]);
    return res;
  }
  return foundAndRemovedTie;
}
Esempio n. 7
0
/** Returns the index of parameter i as it declared in its function
 * @param i :: The parameter index
 * @param recursive :: If true call parameterLocalName recusively until
 *    a non-composite function is reached.
 * @return The local index of the parameter
 */
size_t CompositeFunction::parameterLocalIndex(size_t i, bool recursive) const {
  size_t iFun = functionIndex(i);
  auto localIndex = i - m_paramOffsets[iFun];
  if (recursive) {
    auto cf = dynamic_cast<const CompositeFunction *>(m_functions[iFun].get());
    if (cf) {
      return cf->parameterLocalIndex(localIndex, recursive);
    }
  }
  return localIndex;
}
Esempio n. 8
0
/** Remove a constraint
 * @param parName :: The name of a parameter which constarint to remove.
 */
void CompositeFunction::removeConstraint(const std::string &parName) {
  auto i = parameterIndex(parName);
  auto constraint = IFunction::getConstraint(i);
  if (constraint != nullptr) {
    IFunction::removeConstraint(parName);
  } else {
    size_t iPar = parameterIndex(parName);
    size_t iFun = functionIndex(iPar);
    getFunction(iFun)->removeConstraint(parameterLocalName(iPar));
  }
}
Esempio n. 9
0
bool QgsExpression::registerFunction( QgsExpressionFunction *function, bool transferOwnership )
{
  int fnIdx = functionIndex( function->name() );
  if ( fnIdx != -1 )
  {
    return false;
  }
  QgsExpression::sFunctions.append( function );
  if ( transferOwnership )
    QgsExpression::sOwnedFunctions.append( function );
  return true;
}
Esempio n. 10
0
/** Returns the name of parameter i as it declared in its function
 * @param i :: The parameter index
 * @param recursive :: If true call parameterLocalName recusively until
 *    a non-composite function is reached.
 * @return The pure parameter name (without the function identifier f#.)
 */
std::string CompositeFunction::parameterLocalName(size_t i,
                                                  bool recursive) const {
  size_t iFun = functionIndex(i);
  auto localIndex = i - m_paramOffsets[iFun];
  auto localFunction = m_functions[iFun].get();
  if (recursive) {
    auto cf = dynamic_cast<const CompositeFunction *>(localFunction);
    if (cf) {
      return cf->parameterLocalName(localIndex, recursive);
    }
  }
  return localFunction->parameterName(localIndex);
}
Esempio n. 11
0
const double* Basis2D::getDifferentiationMatrices() {
  if (differentiationMatrices == NULL) {
    int n1 = basis1->getRank();
    int n2 = basis2->getRank();
    int n2D = n1*n2;
    //Instantiate and zero the matrices.
    delete[] differentiationMatrices;
    differentiationMatrices = new double[2*n2D*n2D];
    for (int i = 0; i < 2*n2D*n2D; i++) differentiationMatrices[i] = 0.;

    const double* diff1 = basis1->getDifferentiationMatrix();
    const double* diff2 = basis2->getDifferentiationMatrix();
    for (int iCoord1 = 0; iCoord1 < n1; iCoord1++) {
      for (int iCoord2 = 0; iCoord2 < n2; iCoord2++) {
        int iRow = functionIndex(iCoord1,iCoord2);
        // The derivative along COORD1.
        // In this case the derivative only depends on function values that
        // share the same value of coord2.
        for (int jCoord1 = 0; jCoord1 < n1; jCoord1++) {
          int iCol = functionIndex(jCoord1, iCoord2);
          int iMatrix = matrixIndex(iRow, iCol);
          int i1D = basis1->index(iCoord1, jCoord1);
          differentiationMatrices[iMatrix] = diff1[i1D];
        }
        // The derivative along COORD2.
        // In this case the derivative only depends on function values that
        // share the same value of coord1.
        for (int jCoord2 = 0; jCoord2 < n2; jCoord2++) {
          int iCol = functionIndex(iCoord1, jCoord2);
          int iMatrix = matrixIndex(iRow, iCol);
          int i1D = basis2->index(iCoord2, jCoord2);
          differentiationMatrices[iMatrix + n2D*n2D] = diff2[i1D];
        }
      }
    }
  }
  return differentiationMatrices;
}
Esempio n. 12
0
bool QgsExpression::unregisterFunction( const QString &name )
{
  // You can never override the built in functions.
  if ( QgsExpression::BuiltinFunctions().contains( name ) )
  {
    return false;
  }
  int fnIdx = functionIndex( name );
  if ( fnIdx != -1 )
  {
    QgsExpression::sFunctions.removeAt( fnIdx );
    return true;
  }
  return false;
}
Esempio n. 13
0
/** Get the tie of i-th parameter
 * @param i :: The parameter index
 * @return A pointer to the tie.
 */
ParameterTie *CompositeFunction::getTie(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->getTie(i - m_paramOffsets[iFun]);
}
Esempio n. 14
0
/**
 * Attaches a tie to this function. The attached tie is owned by the function.
 * @param tie :: A pointer to a new tie
 */
void CompositeFunction::addTie(ParameterTie *tie) {
  size_t i = getParameterIndex(*tie);
  size_t iFun = functionIndex(i);
  m_functions[iFun]->addTie(tie);
}
Esempio n. 15
0
/** Add a constraint
 *  @param ic :: Pointer to a constraint.
 */
void CompositeFunction::addConstraint(IConstraint *ic) {
  size_t i = getParameterIndex(*ic);
  size_t iFun = functionIndex(i);
  getFunction(iFun)->addConstraint(ic);
}
Esempio n. 16
0
/// Get constraint
/// @param i :: the index
/// @return A pointer to the constraint
IConstraint *CompositeFunction::getConstraint(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->getConstraint(i - m_paramOffsets[iFun]);
}
Esempio n. 17
0
/** Remove a constraint
 * @param parName :: The name of a parameter which constarint to remove.
 */
void CompositeFunction::removeConstraint(const std::string &parName) {
  size_t iPar = parameterIndex(parName);
  size_t iFun = functionIndex(iPar);
  getFunction(iFun)->removeConstraint(parameterLocalName(iPar));
}
Esempio n. 18
0
bool QgsExpression::isFunctionName( const QString &name )
{
  return functionIndex( name ) != -1;
}
Esempio n. 19
0
/**
 * Get the fitting error for a parameter
 * @param i :: The index of a parameter
 * @return :: the error
 */
double CompositeFunction::getError(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->getError(i - m_paramOffsets[iFun]);
}
Esempio n. 20
0
/// Change status of parameter
void CompositeFunction::setParameterStatus(size_t i,
                                           IFunction::ParameterStatus status) {
  size_t iFun = functionIndex(i);
  m_functions[iFun]->setParameterStatus(i - m_paramOffsets[iFun], status);
}
Esempio n. 21
0
/// Returns the description of active parameter i
std::string CompositeFunction::descriptionOfActive(size_t i) const {
  size_t iFun = functionIndex(i);
  std::ostringstream ostr;
  ostr << m_functions[iFun]->descriptionOfActive(i - m_paramOffsets[iFun]);
  return ostr.str();
}
Esempio n. 22
0
/** Removes i-th parameter's tie if it is tied or does nothing.
 * @param i :: The index of the tied parameter.
 * @return True if successfull
 */
bool CompositeFunction::removeTie(size_t i) {
  size_t iFun = functionIndex(i);
  bool res = m_functions[iFun]->removeTie(i - m_paramOffsets[iFun]);
  return res;
}
Esempio n. 23
0
/** Sets a new value to the i-th parameter.
 *  @param i :: The parameter index
 *  @param value :: The new value
 *  @param explicitlySet :: A boolean falgging the parameter as explicitly set
 * (by user)
 */
void CompositeFunction::setParameter(size_t i, const double &value,
                                     bool explicitlySet) {
  size_t iFun = functionIndex(i);
  m_functions[iFun]->setParameter(i - m_paramOffsets[iFun], value,
                                  explicitlySet);
}
Esempio n. 24
0
/**
 * Set the fitting error for a parameter
 * @param i :: The index of a parameter
 * @param err :: The error value to set
 */
void CompositeFunction::setError(size_t i, double err) {
  size_t iFun = functionIndex(i);
  m_functions[iFun]->setError(i - m_paramOffsets[iFun], err);
}
Esempio n. 25
0
/** Checks if a constraint has been explicitly set
 *  @param i :: The parameter index
 *  @return true if the function is explicitly set
 */
bool CompositeFunction::isExplicitlySet(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->isExplicitlySet(i - m_paramOffsets[iFun]);
}
Esempio n. 26
0
/// Get status of parameter
IFunction::ParameterStatus
CompositeFunction::getParameterStatus(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->getParameterStatus(i - m_paramOffsets[iFun]);
}
Esempio n. 27
0
/// Value of i-th active parameter. Override this method to make fitted
/// parameters different from the declared
double CompositeFunction::activeParameter(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->activeParameter(i - m_paramOffsets[iFun]);
}
Esempio n. 28
0
/** Sets a new description to the i-th parameter.
 *  @param i :: The parameter index
 *  @param description :: The new description
 */
void CompositeFunction::setParameterDescription(
    size_t i, const std::string &description) {
  size_t iFun = functionIndex(i);
  m_functions[iFun]->setParameterDescription(i - m_paramOffsets[iFun],
                                             description);
}
Esempio n. 29
0
/// Set new value of i-th active parameter. Override this method to make fitted
/// parameters different from the declared
void CompositeFunction::setActiveParameter(size_t i, double value) {
  size_t iFun = functionIndex(i);
  m_functions[iFun]->setActiveParameter(i - m_paramOffsets[iFun], value);
}
Esempio n. 30
0
/** Returns the name of parameter i as it declared in its function
 * @param i :: The parameter index
 * @return The pure parameter name (without the function identifier f#.)
 */
std::string CompositeFunction::parameterLocalName(size_t i) const {
  size_t iFun = functionIndex(i);
  return m_functions[iFun]->parameterName(i - m_paramOffsets[iFun]);
}