Example #1
0
        /// <summary>
        /// Initialize the model
        /// </summary>
        /// <param name="modelObject">the model object.</param>
        /// <param name="simulator">the loaded simulator.</param>
        public static void InitializeModel(EcellModel modelObject, WrappedSimulator simulator)
        {
            bool isWarn = false;
            string errMsg = MessageResources.WarnLoadDM + "\n";
            Dictionary<string, object> processPropertyDic = new Dictionary<string, object>();

            // Initialize object
            foreach (EcellObject obj in modelObject.Children)
            {
                // Initialize Stepper
                if (obj is EcellStepper)
                {
                    try
                    {
                        simulator.CreateStepper(obj.Classname, obj.Key);
                    }
                    catch (Exception e)
                    {
                        errMsg += obj.FullID + ":" + e.Message + "\n";
                        Trace.WriteLine(e.ToString());
                        isWarn = true;
                    }
                    foreach (EcellData data in obj.Value)
                    {
                        simulator.LoadStepperProperty(
                            obj.Key,
                            data.Name,
                            data.Value.Value);
                    }
                }
                else if (obj is EcellSystem)
                {
                    // Initialize System
                    if (!obj.Key.Equals(Constants.delimiterPath))
                    {
                        try
                        {
                            simulator.CreateEntity(
                                    obj.Classname,
                                    obj.FullID);
                        }
                        catch (Exception e)
                        {
                            throw new EmlParseException("Failed to create a System entity", e);
                        }
                    }
                    foreach (EcellData data in obj.Value)
                    {
                        simulator.LoadEntityProperty(
                            data.EntityPath,
                            data.Value.Value);
                    }

                    // Initialize Entity
                    foreach (EcellObject entity in obj.Children)
                    {
                        if (entity.Type.Equals(EcellObject.TEXT))
                            continue;
                        bool isCreated = true;
                        // 4 "EcellCoreLib"
                        try
                        {
                            simulator.CreateEntity(
                                entity.Classname,
                                entity.FullID);
                        }
                        catch (Exception e)
                        {
                            errMsg += entity.FullID + ":" + e.Message + "\n";
                            Trace.WriteLine(e.ToString());
                            isCreated = false;
                            isWarn = true;
                        }

                        foreach (EcellData data in entity.Value)
                        {
                            string entityPath = data.EntityPath;
                            if (obj.Type.Equals(Constants.xpathVariable))
                            {
                                if (isCreated == true)
                                    simulator.LoadEntityProperty(entityPath, data.Value.Value);
                            }
                            else
                            {
                                processPropertyDic[entityPath] = data.Value.Value;
                            }
                        }
                    }
                }
            }
            //
            List<string> removeList = new List<string>();
            foreach (KeyValuePair<string, object> pair in processPropertyDic)
            {
                try
                {
                    simulator.LoadEntityProperty(pair.Key, pair.Value);
                }
                catch (WrappedException e)
                {
                    isWarn = true;
                    errMsg += pair.Key + ":" + e.Message + "\n";
                }
                if (pair.Key.EndsWith(Constants.xpathVRL))
                    removeList.Add(pair.Key);
            }
            foreach (string entityPath in removeList)
            {
                processPropertyDic.Remove(entityPath);
            }
            if (isWarn)
            {
                modelObject.ErrMsg = errMsg;
            }
        }
Example #2
0
        /// <summary>
        /// Loads the "Process" and the "Variable" to the "EcellCoreLib".
        /// </summary>
        /// <param name="entityList">The list of the "Process" and the "Variable"</param>
        /// <param name="simulator">The simulator</param>
        /// <param name="loggerList">The list of the "Logger"</param>
        /// <param name="processPropertyDic">The dictionary of the process property</param>
        /// <param name="initialCondition">The dictionary of the initial condition</param>
        /// <param name="setPropertyDic">The dictionary of property.</param>
        private static void LoadEntity(
            WrappedSimulator simulator,
            List<EcellObject> entityList,
            List<string> loggerList,
            Dictionary<string, object> processPropertyDic,
            Dictionary<string, double> initialCondition,
            Dictionary<string, object> setPropertyDic)
        {
            if (entityList == null || entityList.Count <= 0)
                return;

            foreach (EcellObject entity in entityList)
            {
                if (entity is EcellText)
                    continue;
                simulator.CreateEntity(
                    entity.Classname,
                    entity.FullID);
                if (entity.Value == null || entity.Value.Count <= 0)
                    continue;

                foreach (EcellData ecellData in entity.Value)
                {
                    EcellValue value = ecellData.Value;
                    if (string.IsNullOrEmpty(ecellData.Name)
                            || value == null
                            || (value.IsString && ((string)value).Length == 0))
                    {
                        continue;
                    }

                    if (ecellData.Logged)
                    {
                        loggerList.Add(ecellData.EntityPath);
                    }

                    if (value.IsDouble
                        && (Double.IsInfinity((double)value) || Double.IsNaN((double)value)))
                    {
                        continue;
                    }
                    if (ecellData.Saveable)
                    {
                        if (ecellData.EntityPath.EndsWith(Constants.xpathVRL))
                        {
                            processPropertyDic[ecellData.EntityPath] = value.Value;
                        }
                        else
                        {
                            if (ecellData.EntityPath.EndsWith("FluxDistributionList"))
                                continue;
                            simulator.LoadEntityProperty(
                                ecellData.EntityPath,
                                value.Value);
                        }
                    }
                    else if (ecellData.Settable)
                    {
                        setPropertyDic[ecellData.EntityPath] = value.Value;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Loads the "System" 2 the "ECellCoreLib".
        /// </summary>
        /// <param name="simulator">The simulator</param>
        /// <param name="systemList">The list of "System"</param>
        /// <param name="loggerList">The list of the "Logger"</param>
        /// <param name="initialCondition">The dictionary of initial condition.</param>
        /// <param name="setPropertyDic">The dictionary of simulation library.</param>
        private static void LoadSystem(
            WrappedSimulator simulator,
            List<EcellObject> systemList,
            List<string> loggerList,
            Dictionary<string, double> initialCondition,
            Dictionary<string, object> setPropertyDic)
        {
            Debug.Assert(systemList != null && systemList.Count > 0);

            bool existSystem = false;
            Dictionary<string, object> processPropertyDic = new Dictionary<string, object>();

            foreach (EcellObject system in systemList)
            {
                if (system == null)
                    continue;

                existSystem = true;
                if (!system.Key.Equals(Constants.delimiterPath))
                {
                    simulator.CreateEntity(
                        system.Classname,
                        system.FullID);
                }
                // 4 property
                if (system.Value == null || system.Value.Count <= 0)
                    continue;

                foreach (EcellData ecellData in system.Value)
                {
                    if (ecellData.Name == null || ecellData.Name.Length <= 0
                        || ecellData.Value == null)
                    {
                        continue;
                    }
                    EcellValue value = ecellData.Value;
                    if (ecellData.Saveable)
                    {
                        simulator.LoadEntityProperty(
                            ecellData.EntityPath,
                            value.Value);
                    }
                    else if (ecellData.Settable)
                    {
                        setPropertyDic[ecellData.EntityPath] = value.Value;
                    }
                    if (ecellData.Logged)
                    {
                        loggerList.Add(ecellData.EntityPath);
                    }
                }
                // 4 children
                if (system.Children == null || system.Children.Count <= 0)
                    continue;
                LoadEntity(
                    simulator,
                    system.Children,
                    loggerList,
                    processPropertyDic,
                    initialCondition,
                    setPropertyDic);
            }
            if (processPropertyDic.Count > 0)
            {
                // The "VariableReferenceList" is previously loaded.
                string[] keys = null;
                processPropertyDic.Keys.CopyTo(keys = new string[processPropertyDic.Keys.Count], 0);
                foreach (string entityPath in keys)
                {
                    if (entityPath.EndsWith(Constants.xpathVRL))
                    {
                        simulator.LoadEntityProperty(entityPath, processPropertyDic[entityPath]);
                        processPropertyDic.Remove(entityPath);
                    }
                }
                foreach (string entityPath in processPropertyDic.Keys)
                {
                    if (!entityPath.EndsWith("Fixed"))
                    {
                        simulator.LoadEntityProperty(entityPath, processPropertyDic[entityPath]);
                    }
                }
            }
            Debug.Assert(existSystem);
        }
Example #4
0
        /// <summary>
        /// Creates the dummy simulator 4 property lists.
        /// </summary>
        /// <param name="simulator">The dummy simulator</param>
        /// <param name="defaultProcess">The dm name of "Process"</param>
        /// <param name="defaultStepper">The dm name of "Stepper"</param>
        private static void BuildDefaultSimulator(
            WrappedSimulator simulator, string defaultProcess, string defaultStepper)
        {
            try
            {
                // Set DefaultProcess if null
                if (defaultProcess == null)
                    defaultProcess = Constants.DefaultProcessName;
                // Set DefaultStepper if null
                if (defaultStepper == null)
                    defaultStepper = Constants.DefaultStepperName;

                //
                simulator.CreateStepper(defaultStepper, Constants.textKey);
                simulator.CreateEntity(
                    Constants.xpathVariable,
                    Constants.xpathVariable + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                    );
                simulator.CreateEntity(
                    defaultProcess,
                    Constants.xpathProcess + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                );
                simulator.LoadEntityProperty(
                    Constants.xpathSystem +  "::/:" + Constants.xpathStepperID,
                    new string[] { Constants.textKey }
                );
                simulator.LoadEntityProperty(
                    Util.BuildFullPN(
                        Constants.xpathVariable,
                        Constants.delimiterPath,
                        Constants.xpathSize.ToUpper(),
                        Constants.xpathValue
                    ),
                    new string[] { "0.1" }
                );
                simulator.Initialize();
            }
            catch (Exception ex)
            {
                throw new EcellException(
                    MessageResources.ErrCombiStepProc, ex);
            }
        }