Exemplo n.º 1
0
        /// <summary>
        ///     Creates a new dimension by two known dimensions.
        /// </summary>
        private IDimension CreateNewDimension(IDimension amountDimension, IDimension sizeDimension)
        {
            var dimName = SBMLConstants.DIMENSION + amountDimension.Name + SBMLConstants.DIVIDE + sizeDimension.Name;

            if (_dimensionDictionary.ContainsKey(dimName))
            {
                return(_dimensionDictionary[dimName]);
            }
            if (_moBiDimensionFactory.Dimensions.Any(dim => dim.Name == dimName))
            {
                return(_moBiDimensionFactory.Dimension(dimName));
            }

            var newBaseDimRepresentation = CreateNewBaseDimRepresentation(amountDimension.BaseRepresentation, sizeDimension.BaseRepresentation);
            var newFactor    = GetNewFactor(amountDimension, sizeDimension); //Faktoren dividieren
            var baseUnitName = SBMLConstants.SBML_BASE_UNIT + amountDimension.DisplayName + SBMLConstants.DIVIDE + sizeDimension.Name;
            var unitName     = SBMLConstants.UNIT + amountDimension.Name + SBMLConstants.DIVIDE + sizeDimension.Name;
            var newBaseUnit  = new Unit(baseUnitName, 1, 0)
            {
                Visible = false
            };
            var newDim  = new Dimension(newBaseDimRepresentation, dimName, newBaseUnit.Name);
            var newUnit = new Unit(unitName, newFactor, 0);

            newDim.AddUnit(newUnit);
            _dimensionDictionary.Add(dimName, newDim);
            var tmp = _moBiDimensionFactory.Dimensions.Count();

            _moBiDimensionFactory.AddDimension(newDim);
            var tmp2 = _moBiDimensionFactory.Dimensions.Any(dim => dim.Name == newDim.Name);

            return(newDim);
        }
        public ICommand SetAlternativeParameterUnit(IParameter parameter, Unit newUnit)
        {
            if (simulationsAreUsingAlternativeContaining(parameter))
            {
                return(_parameterTask.SetParameterUnit(parameter, newUnit));
            }

            return(_parameterTask.SetParameterUnitWithoutBuildingBlockChange(parameter, newUnit));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Converts a SBML UnitDefinition into a MoBi Unit.
        /// </summary>
        public IDimension ConvertUnit(UnitDefinition unitDefinition)
        {
            var sbmlUnit  = unitDefinition.getId();
            var dimension = _moBiDimensionFactory.TryGetDimensionCaseInsensitive(sbmlUnit);

            if (dimension != Constants.Dimension.NO_DIMENSION)
            {
                _sbmlInformation.MobiDimension[sbmlUnit] = dimension;
                return(dimension);
            }

            var newFactor = 1.0;
            var unitsList = new List <Unit>();
            var brList    = new List <BaseDimensionRepresentation>();

            for (long i = 0; i < unitDefinition.getNumUnits(); i++)
            {
                var mobiUnit = SBMLBaseUnitToMoBi(unitDefinition.getUnit(i));
                if (mobiUnit == null)
                {
                    continue;
                }
                var unitDimension = _moBiDimensionFactory.DimensionForUnit(mobiUnit.Name);
                var unitBr        = unitDimension.BaseRepresentation;
                unitBr = SetExponents(unitDefinition, unitBr, i);
                brList.Add(unitBr);

                if (Math.Abs(newFactor) < 0.0001)
                {
                    newFactor = unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                else
                {
                    newFactor = newFactor * unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                unitsList.Add(mobiUnit);
            }

            var baseDimensionRepresentation = CreateBaseDimRepresentationExponents(brList);

            IDimension newDim = new Dimension(baseDimensionRepresentation, String.Format("SBML_{0}", unitDefinition.getId()), String.Format("SBML_{0}_BaseUnit", unitDefinition.getId()));

            var newBaseUnit = newDim.BaseUnit;

            newBaseUnit.Visible = false;
            var newUnit = new Unit(unitDefinition.getId(), newFactor, 0);

            newDim.AddUnit(newUnit);
            newDim.DefaultUnit = newUnit;

            _sbmlInformation.MobiDimension[sbmlUnit] = newDim;
            if (_moBiDimensionFactory.Dimensions.All(dim => dim.Name != newDim.Name))
            {
                _moBiDimensionFactory.AddDimension(newDim);
            }
            return(newDim);
        }
Exemplo n.º 4
0
        public void AddUnit(int kind, double exponent, double multiplier, double scale, IDictionary <int, Unit> baseUnitsDictionary)
        {
            if (!baseUnitsDictionary.ContainsKey(kind))
            {
                return;
            }

            if (exponent < 0)
            {
                _inverse = baseUnitsDictionary[kind];
            }
            else
            {
                _direct = baseUnitsDictionary[kind];
            }

            Rate *= multiplier * Math.Pow(10, scale);
        }