public override object Read(string path)
        {
            var obj = new TurbineArrayPropFASTData();
            string text;
            using (var reader = new StreamReader(path))
            {
                text = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(text);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                if (identifier.Equals("general"))
                {
                    var dict = rootEntryNode.GetDictContent();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var node = dict.ChildNodes[i].ChildNodes[0];
                        var id = node.GetEntryIdentifier();
                        switch (id)
                        {
                            case "yawAngle":
                                obj.general.yawAngle = node.GetBasicValDecimal();
                                break;
                            case "numberofBld":
                                obj.general.numberofBld = node.GetBasicValInt();
                                break;
                            case "numberofBldPts":
                                obj.general.numberofBldPts = node.GetBasicValInt();
                                break;
                            case "rotorDiameter":
                                obj.general.rotorDiameter = node.GetBasicValDecimal();
                                break;
                            case "epsilon":
                                obj.general.epsilon = node.GetBasicValDecimal();
                                break;
                            case "smearRadius":
                                obj.general.smearRadius = node.GetBasicValDecimal();
                                break;
                            case "effectiveRadiusFactor":
                                obj.general.effectiveRadiusFactor = node.GetBasicValDecimal();
                                break;
                            case "pointInterpType":
                                obj.general.pointInterpType = node.GetBasicValInt();
                                break;
                        }
                    }
                }
                else if (identifier.StartsWith("turbine"))
                {
                    var instance = new TurbineInstanceFAST();
                    var dict = rootEntryNode.GetDictContent();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var node = dict.ChildNodes[i].ChildNodes[0];
                        var id = node.GetEntryIdentifier();
                        switch ( id )
                        {
                            case "refx":
                                instance.refx = node.GetBasicValDecimal();
                                break;
                            case "refy":
                                instance.refy = node.GetBasicValDecimal();
                                break;
                            case "refz":
                                instance.refz = node.GetBasicValDecimal();
                                break;
                            case "hubz":
                                instance.hubz = node.GetBasicValDecimal();
                                break;
                        }
                    }
                    obj.turbine.Add(instance);
                }
            }
            return obj;
        }
Esempio n. 2
0
        public override object Read(string path)
        {
            var    obj = new TurbineArrayPropFASTData();
            string text;

            using (var reader = new StreamReader(path))
            {
                text = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser  = new Parser(grammar);
            var tree    = parser.Parse(text);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                if (identifier.Equals("general"))
                {
                    var dict = rootEntryNode.GetDictContent();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var node = dict.ChildNodes[i].ChildNodes[0];
                        var id   = node.GetEntryIdentifier();
                        switch (id)
                        {
                        case "yawAngle":
                            obj.general.yawAngle = node.GetBasicValDecimal();
                            break;

                        case "numberofBld":
                            obj.general.numberofBld = node.GetBasicValInt();
                            break;

                        case "numberofBldPts":
                            obj.general.numberofBldPts = node.GetBasicValInt();
                            break;

                        case "rotorDiameter":
                            obj.general.rotorDiameter = node.GetBasicValDecimal();
                            break;

                        case "epsilon":
                            obj.general.epsilon = node.GetBasicValDecimal();
                            break;

                        case "smearRadius":
                            obj.general.smearRadius = node.GetBasicValDecimal();
                            break;

                        case "effectiveRadiusFactor":
                            obj.general.effectiveRadiusFactor = node.GetBasicValDecimal();
                            break;

                        case "pointInterpType":
                            obj.general.pointInterpType = node.GetBasicValInt();
                            break;
                        }
                    }
                }
                else if (identifier.StartsWith("turbine"))
                {
                    var instance = new TurbineInstanceFAST();
                    var dict     = rootEntryNode.GetDictContent();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var node = dict.ChildNodes[i].ChildNodes[0];
                        var id   = node.GetEntryIdentifier();
                        switch (id)
                        {
                        case "refx":
                            instance.refx = node.GetBasicValDecimal();
                            break;

                        case "refy":
                            instance.refy = node.GetBasicValDecimal();
                            break;

                        case "refz":
                            instance.refz = node.GetBasicValDecimal();
                            break;

                        case "hubz":
                            instance.hubz = node.GetBasicValDecimal();
                            break;
                        }
                    }
                    obj.turbine.Add(instance);
                }
            }
            return(obj);
        }