Ejemplo n.º 1
0
        public override object Read(string path)
        {
            var    obj  = new TurbinePropertiesData();
            string text = Load(path);

            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();

                switch (identifier)
                {
                case "NumBl":
                    obj.NumBl = rootEntryNode.GetBasicValInt();
                    break;

                case "TipRad":
                    obj.TipRad = rootEntryNode.GetBasicValDecimal();
                    break;

                case "HubRad":
                    obj.HubRad = rootEntryNode.GetBasicValDecimal();
                    break;

                case "UndSling":
                    obj.UndSling = rootEntryNode.GetBasicValDecimal();
                    break;

                case "OverHang":
                    obj.OverHang = rootEntryNode.GetBasicValDecimal();
                    break;

                case "TowerHt":
                    obj.TowerHt = rootEntryNode.GetBasicValDecimal();
                    break;

                case "Twr2Shft":
                    obj.Twr2Shft = rootEntryNode.GetBasicValDecimal();
                    break;

                case "ShftTilt":
                    obj.ShftTilt = rootEntryNode.GetBasicValDecimal();
                    break;

                case "PreCone":
                {
                    var dict  = rootEntryNode.GetDictArrayBody();
                    var array = dict.GetArrayOfDecimal();
                    obj.PreCone = new Vertice(array[0], array[1], array[2]);
                }
                break;

                case "GBRatio":
                    obj.GBRatio = rootEntryNode.GetBasicValDecimal();;
                    break;

                case "GenIner":
                    obj.GenIner = rootEntryNode.GetBasicValDecimal();
                    break;

                case "HubIner":
                    obj.HubIner = rootEntryNode.GetBasicValDecimal();
                    break;

                case "BladeIner":
                    obj.BladeIner = rootEntryNode.GetBasicValDecimal();
                    break;

                case "TorqueControllerType":
                    obj.TorqueControllerType = rootEntryNode.GetBasicValEnum <ControllerType>();
                    break;

                case "YawControllerType":
                    obj.YawControllerType = rootEntryNode.GetBasicValEnum <ControllerType>();
                    break;

                case "PitchControllerType":
                    obj.PitchControllerType = rootEntryNode.GetBasicValEnum <ControllerType>();
                    break;

                case "TorqueControllerParams":
                    obj.torqueControllerParams = TorqueControllerParamsHandler(rootEntryNode.GetDictContent());
                    break;

                case "PitchControllerParams":
                    obj.pitchControllerParams = PitchControllerParamsHandler(rootEntryNode.GetDictContent());
                    break;

                case "Airfoils":
                {
                    var dict = rootEntryNode.GetDictArrayBody();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var item = new AirfoilBlade();
                        item.AirfoilName = dict.ChildNodes[i].ChildNodes[0].Token.Text.Replace("\"", "");
                        item.Blade       = new List <Vertice>();
                        obj.airfoilBlade.Add(item);
                    }
                }
                break;

                case "BladeData":
                {
                    var dict = rootEntryNode.GetDictArrayBody();
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var array_head = dict.ChildNodes[i].ChildNodes[0].ChildNodes[1].ChildNodes;
                        if (array_head.Count > 3)
                        {
                            var airfoil_id = Convert.ToInt32(array_head[3].ChildNodes[0].Token.Value);
                            if ((airfoil_id >= 0) && (airfoil_id < obj.airfoilBlade.Count))
                            {
                                var blade_prop = new Vertice();
                                blade_prop.X = Convert.ToDecimal(array_head[0].ChildNodes[0].Token.Value);
                                blade_prop.Y = Convert.ToDecimal(array_head[1].ChildNodes[0].Token.Value);
                                blade_prop.Z = Convert.ToDecimal(array_head[2].ChildNodes[0].Token.Value);
                                obj.airfoilBlade[airfoil_id].Blade.Add(blade_prop);
                            }
                        }
                    }
                }
                break;
                }
            }

            return(obj);
        }
        public override object Read(string path)
        {
            var obj = new TurbinePropertiesData();
            string text;

            if (!File.Exists(path))
            {
                if (!useDefault) return obj;
                WriteToFile(path, DefaultData);
            }

            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();

                switch ( identifier )
                {
                    case "NumBl":
                        obj.NumBl = rootEntryNode.GetBasicValInt();
                        break;
                    case "TipRad":
                        obj.TipRad = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "HubRad":
                        obj.HubRad = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "UndSling":
                        obj.UndSling = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "OverHang":
                        obj.OverHang = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "TowerHt":
                        obj.TowerHt = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "Twr2Shft":
                        obj.Twr2Shft = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "ShftTilt":
                        obj.ShftTilt = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "PreCone":
                        {
                            var dict = rootEntryNode.GetDictArrayBody();
                            var array = dict.GetArrayOfDecimal();
                            obj.PreCone = new Vertice( array[0], array[1], array[2]);
                        }
                        break;
                    case "GBRatio":
                        obj.GBRatio = rootEntryNode.GetBasicValDecimal();;
                        break;
                    case "GenIner":
                        obj.GenIner = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "HubIner":
                        obj.HubIner = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "BladeIner":
                        obj.BladeIner = rootEntryNode.GetBasicValDecimal();
                        break;
                    case "TorqueControllerType":
                        obj.TorqueControllerType = rootEntryNode.GetBasicValEnum<ControllerType>();
                        break;
                    case "YawControllerType":
                        obj.YawControllerType = rootEntryNode.GetBasicValEnum<ControllerType>();
                        break;
                    case "PitchControllerType":
                        obj.PitchControllerType = rootEntryNode.GetBasicValEnum<ControllerType>();
                        break;
                    case "TorqueControllerParams":
                        obj.torqueControllerParams = TorqueControllerParamsHandler(rootEntryNode.GetDictContent());
                        break;
                    case "PitchControllerParams":
                        obj.pitchControllerParams = PitchControllerParamsHandler(rootEntryNode.GetDictContent());
                        break;
                    case "Airfoils":
                        {
                            var dict = rootEntryNode.GetDictArrayBody();
                            for (int i = 0; i < dict.ChildNodes.Count; i++)
                            {
                                var item = new AirfoilBlade();
                                item.AirfoilName = dict.ChildNodes[i].ChildNodes[0].Token.Text.Replace("\"", "");
                                item.Blade = new List<Vertice>();
                                obj.airfoilBlade.Add(item);
                            }
                        }
                        break;
                    case "BladeData":
                        {
                            var dict = rootEntryNode.GetDictArrayBody();
                            for (int i = 0; i < dict.ChildNodes.Count; i++)
                            {
                                var array_head = dict.ChildNodes[i].ChildNodes[0].ChildNodes[1].ChildNodes;
                                if (array_head.Count > 3)
                                {
                                    var airfoil_id = Convert.ToInt32(array_head[3].ChildNodes[0].Token.Value);
                                    if ((airfoil_id >= 0) && (airfoil_id < obj.airfoilBlade.Count))
                                    {
                                        var blade_prop = new Vertice();
                                        blade_prop.X = Convert.ToDecimal(array_head[0].ChildNodes[0].Token.Value);
                                        blade_prop.Y = Convert.ToDecimal(array_head[1].ChildNodes[0].Token.Value);
                                        blade_prop.Z = Convert.ToDecimal(array_head[2].ChildNodes[0].Token.Value);
                                        obj.airfoilBlade[airfoil_id].Blade.Add(blade_prop);
                                    }
                                }
                            }
                        }
                        break;
                }
            }

            return obj;
        }
Ejemplo n.º 3
0
 public void Save(string path)
 {
     var p = new TurbinePropertiesData()
                 {
                     BladeIner = BladeIner,
                     GBRatio = GBRatio,
                     GenIner = GenIner,
                     HubIner = HubIner,
                     HubRad = HubRad,
                     NumBl = NumBl,
                     OverHang = OverHang,
                     ShftTilt = ShftTilt,
                     TipRad = TipRad,
                     TowerHt = TowerHt,
                     Twr2Shft = Twr2Shft,
                     UndSling = UndSling,
                     PitchControllerType = PitchControllerType,
                     TorqueControllerType = TorqueControllerType,
                     YawControllerType = YawControllerType,
                     PreCone = new Vertice()
                                   {
                                       X = PreCone.X,
                                       Y = PreCone.Y,
                                       Z = PreCone.Z
                                   },
                     pitchControllerParams = new PitchControllerParams()
                                                 {
                                                     PitchControlEndPitch = PitchControlEndPitch,
                                                     PitchControlEndSpeed = PitchControlEndSpeed,
                                                     PitchControlStartPitch = PitchControlStartPitch,
                                                     PitchControlStartSpeed = PitchControlStartSpeed,
                                                     RateLimitPitch = RateLimitPitch
                                                 },
                     torqueControllerParams = new TorqueControllerParams()
                                                  {
                                                      CutInGenSpeed = CutInGenSpeed,
                                                      CutInGenTorque = CutInGenTorque,
                                                      KGen = KGen,
                                                      RateLimitGenTorque = RateLimitGenTorque,
                                                      RatedGenSpeed = RatedGenSpeed,
                                                      RatedGenTorque = RatedGenTorque,
                                                      Region2EndGenSpeed = Region2EndGenSpeed,
                                                      Region2StartGenSpeed = Region2StartGenSpeed,
                                                      TorqueControllerRelax = TorqueControllerRelax
                                                  },
                     airfoilBlade = new List<AirfoilBlade>()
                 };
     foreach (var airFoil in airfoilBlade)
     {
         var x = new AirfoilBlade()
                     {
                         AirfoilName = airFoil.AirfoilName,
                         Blade = new List<Vertice>()
                     };
         foreach( var blade in airFoil.Blade)
         {
             x.Blade.Add( new Vertice(blade.X, blade.Y, blade.Z));
         }
         p.airfoilBlade.Add(x);
     }
     _fileHandler.FileName = PropName;
     _fileHandler.Write(_fileHandler.GetPath(path), p);
 }