コード例 #1
0
ファイル: ForegroundModel.cpp プロジェクト: BigShows/mantid
 /**
  * Called when an attribute value is set
  * @param name :: The name of the attribute
  * @param attr :: The value of the attribute
  */
 void ForegroundModel::setAttribute(const std::string & name, const API::IFunction::Attribute & attr)
 {
   if(name == FORM_FACTOR_ION)
   {
     setFormFactorIon(attr.asString());
   }
 }
コード例 #2
0
/**
 * Cache some frequently used attributes
 * @param name :: The name of the attribute
 * @param value :: It's value
 */
void TobyFitResolutionModel::setAttribute(
    const std::string &name, const API::IFunction::Attribute &value) {
    MDResolutionConvolution::setAttribute(name, value);
    if (name == MC_MIN_NAME)
        m_mcLoopMin = value.asInt();
    else if (name == MC_MAX_NAME)
        m_mcLoopMax = value.asInt();
    else if (name == MC_LOOP_TOL)
        m_mcRelErrorTol = value.asDouble();
    else if (name == MC_TYPE) {
        m_mcType = value.asInt();
        if (m_mcType > 4 || m_mcType < 0) {
            throw std::invalid_argument("TobyFitResolutionModel: Invalid MCType "
                                        "argument, valid values are 0-4. Current "
                                        "value=" +
                                        boost::lexical_cast<std::string>(m_mcType));
        }
    } else if (name == CRYSTAL_MOSAIC) {
        m_mosaicActive = (value.asInt() != 0);
    } else if (name == FOREGROUNDONLY_NAME) {
        m_foregroundOnly = (value.asInt() != 0);
    } else {
        for (auto &iter : m_yvector) {
            iter.setAttribute(name, value);
        }
    }
}
コード例 #3
0
ファイル: BSpline.cpp プロジェクト: nimgould/mantid
/** Set an attribute for the function
 *
 * @param attName :: The name of the attribute to set
 * @param att :: The attribute to set
 */
void BSpline::setAttribute(const std::string &attName,
                           const API::IFunction::Attribute &att) {
  bool isUniform = attName == "Uniform" && att.asBool();

  storeAttributeValue(attName, att);

  if (attName == "BreakPoints" || isUniform || attName == "StartX" ||
      attName == "EndX") {
    resetKnots();
  } else if (attName == "NBreak" || attName == "Order") {
    resetGSLObjects();
    resetParameters();
    resetKnots();
  }
}
コード例 #4
0
/**
 *  Set a value to a named attribute
 *  @param name :: The name of the attribute
 *  @param value :: The value of the attribute
 */
void ResolutionConvolvedCrossSection::setAttribute(
    const std::string &name, const API::IFunction::Attribute &value) {
    storeAttributeValue(name, value);
    const std::string fgModelName = getAttribute(FOREGROUND_ATTR).asString();
    const std::string convolutionType = getAttribute(RESOLUTION_ATTR).asString();

    if (!convolutionType.empty() && !fgModelName.empty()) {
        setupResolutionFunction(convolutionType, fgModelName);
    }
    if (name == SIMULATION_ATTR)
        m_simulation = value.asBool();
    else if (name != FOREGROUND_ATTR && name != RESOLUTION_ATTR) {
        m_convolution->setAttribute(name, value);
    }
}
コード例 #5
0
ファイル: Polynomial.cpp プロジェクト: mkoennecke/mantid
/** Set Attribute
 * @param attName :: The attribute name. If it is not "n" exception is thrown.
 * @param att :: An int attribute containing the new value. The value cannot be
 * negative.
 * (identical to Polynomial)
 */
void Polynomial::setAttribute(const std::string &attName,
                              const API::IFunction::Attribute &att) {
  if (attName == "n") {
    // set the polynomial order
    if (m_n >= 0) {
      clearAllParameters();
    }
    m_n = att.asInt();
    if (m_n < 0) {
      throw std::invalid_argument(
          "Polynomial: polynomial order cannot be negative.");
    }
    for (int i = 0; i <= m_n; ++i) {
      std::string parName = "A" + boost::lexical_cast<std::string>(i);
      declareParameter(parName);
    }
  }
}
コード例 #6
0
ファイル: CubicSpline.cpp プロジェクト: BigShows/mantid
    /** Set an attribute for the function
     *
     * @param attName :: The name of the attribute to set
     * @param att :: The attribute to set
     */
    void CubicSpline::setAttribute(const std::string& attName, const API::IFunction::Attribute& att)
    {

      if (attName == "n")
      {
        //get the new and old number of data points
        int n = att.asInt();
        int oldN = getAttribute("n").asInt();

        //check that the number of data points is in a valid range
        if (n > oldN)
        {
          //get the name of the last x data point
          std::string oldXName = "x" + boost::lexical_cast<std::string>(oldN - 1);
          double oldX = getAttribute(oldXName).asDouble();

          //reallocate gsl object to new size
          reallocGSLObjects(n);

          //create blank a number of new blank parameters and attributes
          for (int i = oldN; i < n; ++i)
          {
            std::string num = boost::lexical_cast<std::string>(i);

            std::string newXName = "x" + num;
            std::string newYName = "y" + num;

            declareAttribute(newXName, Attribute(oldX + static_cast<double>(i - oldN + 1)));
            declareParameter(newYName, 0);
          }

          //flag that the spline + derivatives will now need to be recalculated
          m_recalculateSpline = true;
        }
        else if (n < oldN)
        {
          throw std::invalid_argument("Cubic Spline: Can't decrease the number of attributes");
        }
      }

      storeAttributeValue(attName, att);
    }
コード例 #7
0
ファイル: DynamicKuboToyabe.cpp プロジェクト: dezed/mantid
/** Set Attribute
 * @param attName :: The attribute name. If it is not "eps" exception is thrown.
 * @param att :: A double attribute containing a new positive value.
 */
void DynamicKuboToyabe::setAttribute(const std::string &attName,
                                     const API::IFunction::Attribute &att) {
  if (attName == "BinWidth") {

    double newVal = att.asDouble();

    if (newVal < 0) {
      clearAllParameters();
      throw std::invalid_argument(
          "DKT: Attribute BinWidth cannot be negative.");

    } else if (newVal < m_minEps) {
      clearAllParameters();
      std::stringstream ss;
      ss << "DKT: Attribute BinWidth too small (BinWidth < "
         << std::setprecision(3) << m_minEps << ")";
      throw std::invalid_argument(ss.str());

    } else if (newVal > m_maxEps) {
      clearAllParameters();
      std::stringstream ss;
      ss << "DKT: Attribute BinWidth too large (BinWidth > "
         << std::setprecision(3) << m_maxEps << ")";
      throw std::invalid_argument(ss.str());
    }

    if (!nParams()) {
      init();
    }
    m_eps = newVal;

  } else {
    throw std::invalid_argument("DynamicKuboToyabe: Unknown attribute " +
                                attName);
  }
}
コード例 #8
0
  /** Set Attribute
   * @param attName :: The attribute name. If it is not "nlayer" exception is thrown.
   * @param att :: An int attribute containing the new value. The value cannot be negative.
   * (identical to ReflectivityMulf)
   */
  void ReflectivityMulf::setAttribute(const std::string& attName,const API::IFunction::Attribute& att)
  {
    storeAttributeValue(attName,att);
    if (attName == "nlayer")
    {
      m_nlayer = att.asInt();
      if (m_nlayer < 0)
      {
        throw std::invalid_argument("ReflectivityMulf: reflectivity number of layers cannot be negative.");
      }

      // get the current parameter values using the old value of nlayer
      vector<double> coeff(m_nlayer*3+7, 0.0);
      for (int i = 0; i < 7; ++i)
        coeff[i] = getParameter(i);

      if(m_nlayer > m_nlayer_old){  
        for (int i = 0; i < m_nlayer_old; ++i)
        {
          coeff[7+i*3] = getParameter(7+i*3);
          coeff[8+i*3] = getParameter(8+i*3);
          coeff[9+i*3] = getParameter(9+i*3);
        }
        // fill in the missing values if m_nlayer>m_nlayer_old
        for (int i = m_nlayer_old; i < m_nlayer; ++i)
        {
          coeff[7+i*3] = 0.0;
          coeff[8+i*3] = 0.0;
          coeff[9+i*3] = 0.0;
        }
      }else {
        for (int i = 0; i < m_nlayer; ++i)
        {
          coeff[7+i*3] = getParameter(7+i*3);
          coeff[8+i*3] = getParameter(8+i*3);
          coeff[9+i*3] = getParameter(9+i*3);
        }
      }
      // now update the value of nlayer_old
      m_nlayer_old=m_nlayer;


      // set the reflectivity layers
      if (m_nlayer >= 0)
      {
        clearAllParameters();
      }
    
      declareParameter("Theta",coeff[0]);
      declareParameter("ScaleFactor",coeff[1]);
      declareParameter("AirSLD",coeff[2]);
      declareParameter("BulkSLD",coeff[3]);
      declareParameter("Roughness",coeff[4]);
      declareParameter("BackGround",coeff[5]);
      declareParameter("Resolution",coeff[6]);

      for(int i=0; i<m_nlayer; ++i)
      {
        std::string parName = "SLD_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[7+i*3]);
        parName = "d_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[8+i*3]);
        parName = "Rough_Layer" + boost::lexical_cast<std::string>(i);
        declareParameter(parName,coeff[9+i*3]);
      }
    }
  }