Esempio n. 1
0
 public bool ChangePatchName(string oldName, string newName)
 {
     /*
      * FoamDictionaryListFile f = new FoamDictionaryListFile(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));
      * f.Read();
      * if (!f.Dictionary.IsNull)
      * {
      *   FoamDictionary d = f.Dictionary.Item(oldName);
      *   f.Dictionary.RemoveChild(oldName);
      *   f.Dictionary.SetChild(newName, d);
      * }
      * f.Write();
      */
     try
     {
         StreamReader sr   = new StreamReader(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));
         string       code = sr.ReadToEnd();
         sr.Close();
         code = code.Replace(oldName, newName);
         File.Delete(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));
         StreamWriter sw = new StreamWriter(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName), false);
         sw.Write(code);
         sw.Close();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 2
0
        private static string _SaveCase(Case cas, string meshVxtFilePath, string saveFilePath, IMonitor mon = null)
        {
            string root = Path.GetDirectoryName(meshVxtFilePath);
            string mesh = FoamConst.GetPolyMeshPath(root);
            string desc = FoamConst.GetDescFilePath(root);
            string res  = CaseToBinFile(cas, desc, mon);

            if (res != "ok")
            {
                return(res);
            }
            return(Zip.CompressDirectory(mesh, saveFilePath));
        }
Esempio n. 3
0
        public List <string> GetAllPatchNames()
        {
            List <string>          names = new List <string>();
            FoamDictionaryListFile f     = new FoamDictionaryListFile(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));

            f.Read();
            if (!f.Dictionary.IsNull)
            {
                foreach (KeyValuePair <string, FoamDictionary> k in f.Dictionary)
                {
                    names.Add(k.Key);
                }
            }
            return(names);
        }
Esempio n. 4
0
        private static string _ConvertCase(string caseFileName, string templeteFileName, string runDirName, IMonitor mon)
        {
            string res = Zip.UncomporessZip(templeteFileName, runDirName);

            if (res != "ok")
            {
                var err = string.Format("加载模板文件失败:\r\n  模板文件名:{0}\r\n  加载目标位置:{1}\r\n  错误描述:{2}", templeteFileName, runDirName, res);
                Err(mon, err);
                return(err);
            }
            else
            {
                Log(mon, string.Format("加载模板文件完成:\r\n  模板文件名:{0}", templeteFileName));
            }
            string meshDir = FoamConst.GetPolyMeshPath(runDirName);

            if (!Directory.Exists(meshDir))
            {
                Directory.CreateDirectory(meshDir);
            }
            res = Zip.UncomporessZip(caseFileName, meshDir);
            if (res != "ok")
            {
                var err = string.Format("加载工程文件失败:\r\n  工程文件名:{0}\r\n  错误描述:{1}", caseFileName, res);
                Err(mon, err);
                return(err);
            }
            else
            {
                Log(mon, string.Format("加载工程文件完成:\r\n  工程文件名:{0}\r\n", caseFileName));
            }
            Case cas = null;

            res = CaseReader.BinFileToCase(ref cas, FoamConst.GetDescFilePath(runDirName), mon);
            if (cas == null)
            {
                var err = string.Format("非法工程文件格式:\r\n  工程文件名:{0}", caseFileName);
                Err(mon, err);
                return(err);
            }
            else
            {
                cas.Write(runDirName, mon);
                Log(mon, "工程结算环境配置完成");
                return("ok");
            }
        }
Esempio n. 5
0
        public void SetBoundaryType(string name, BoundaryType bt)
        {
            FoamDictionaryListFile f = new FoamDictionaryListFile(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));

            f.Read();
            if (!f.Dictionary.IsNull)
            {
                foreach (KeyValuePair <string, FoamDictionary> k in f.Dictionary)
                {
                    if (k.Key == name)
                    {
                        FoamDictionary cv = k.Value;
                        cv.SetChild("type", bt.ToString());
                        cv.RemoveChild("inGroups");
                    }
                }
            }
            f.Write();
        }
Esempio n. 6
0
        public List <string> GetPatchNamesByType(string typeName)
        {
            List <string>          names = new List <string>();
            FoamDictionaryListFile f     = new FoamDictionaryListFile(FoamConst.GetBoundaryFileNameFromVxt(vxtFileName));

            f.Read();
            if (!f.Dictionary.IsNull)
            {
                foreach (KeyValuePair <string, FoamDictionary> k in f.Dictionary)
                {
                    FoamDictionary cv = k.Value;
                    if (cv.Child("type").Data == typeName)
                    {
                        names.Add(k.Key);
                    }
                }
            }
            return(names);
        }
Esempio n. 7
0
        public bool Write(string foamRootPathName, IMonitor monitor)
        {
            var f = new FoamDictionaryFile(FoamConst.GetConstantChildPathName(foamRootPathName, "tracerProperties"), monitor);

            f.Read();
            var d = f.Dictionary;

            d.SetChild("Sc", "Sc [0 0 0 0 0 0 0] " + Sc.ToString());
            d.SetChild("tracerPhaseName", "steel");
            f.Write();
            f = new FoamDictionaryFile(FoamConst.GetFvSolutionFileName(foamRootPathName), monitor);
            f.Read();
            d = f.Dictionary.Child("PIMPLE");
            d.SetChild("solveTracer", SolveTracer ? "yes" : "no");
            f.Write();
            foreach (var inj in Injects)
            {
                inj.Write(foamRootPathName, monitor);
            }
            return(true);
        }
Esempio n. 8
0
        public bool Write(string foamRootPathName, IMonitor monitor)
        {
            FoamDictionaryFile f = new FoamDictionaryFile(FoamConst.GetFvOptionsPath(foamRootPathName), monitor);

            f.Read();
            var d = f.Dictionary.GetByUrl("options").AddChild(Name);

            d.SetChild("type", "scalarSemiImplicitSource");
            d.SetChild("timeStart", StartTime);
            d.SetChild("duration", Duration);
            d.SetChild("selectionMode", "points");
            FoamDictionary points = new FoamDictionary(true, monitor);

            points.SetChild("0", Location.ToString());
            d.SetChild("points", points);
            d.SetChild("volumeMode", "absolute");
            FoamDictionary injectionRateSuSp = new FoamDictionary(monitor);

            injectionRateSuSp.SetChild("tracer", "(1 0)");
            d.SetChild("injectionRateSuSp", injectionRateSuSp);
            f.Write();
            return(true);
        }
Esempio n. 9
0
        private void OnOpenMesh(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                if (!FoamMeshVerifier.VerifyDirectory(fbd.SelectedPath))
                {
                    MessageBox.Show("网格验证失败,路径:\n" + fbd.SelectedPath, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorLine("网格验证失败,路径: " + fbd.SelectedPath);
                    return;
                }
                else
                {
                    CaseModified        = true;
                    currentMeshFileName = FoamConst.GetVxtFilePath(fbd.SelectedPath);
                    File.Create(currentMeshFileName);
                    FillBoundaryTreeNode();
                    InitCaseBoundary();
                    foamViewer_main.SetMeshFileName(currentMeshFileName);
                }
            }
        }
Esempio n. 10
0
        public override bool Write(string foamRootPathName, IMonitor monitor)
        {
            base.Write(foamRootPathName, monitor);
            FoamDictionaryFile controlFile = new FoamDictionaryFile(FoamConst.GetControlDictFileName(foamRootPathName), monitor);

            controlFile.Read();
            FoamDictionary dfun = controlFile.Dictionary.GetByUrl("functions");
            FoamDictionary m    = new FoamDictionary(monitor);

            m.SetChild("type", "probes");
            m.SetChild("functionObjectLibs", "(\"libsampling.dll\")");
            m.SetChild("probeLocations", string.Format("({0})", Location.ToString()));
            FoamDictionary fields = new FoamDictionary(true, monitor);

            foreach (var f in Fields)
            {
                fields.SetChild(f, f);
            }
            m.SetChild("fields", fields);
            dfun.SetChild(Name, m);
            controlFile.Write();
            return(true);
        }
Esempio n. 11
0
 public bool Write(string foamRootPathName, IMonitor monitor = null)
 {
     try
     {
         string             dictFileName = FoamConst.GetCfMeshDictFileName(foamRootPathName);
         FoamDictionaryFile f            = new FoamDictionaryFile(dictFileName, monitor);
         f.Read();
         f.Dictionary.SetChild("surfaceFile", "\"surface.stl\"");
         f.Dictionary.SetChild("maxCellSize", MaxCellSize);
         f.Dictionary.SetChild("minCellSize", MinCellSize);
         f.Dictionary.SetChild("boundaryCellSize", BoundaryCellSize);
         f.Dictionary.SetChild("enforceGeometryConstraints", EnforceGeometryConstraints ? "1" : "0");
         FoamDictionary dLocalRefine = f.Dictionary.GetByUrl("localRefinement");
         dLocalRefine.Clear();
         foreach (LocalRefinementSubDict l in LocalRefine)
         {
             l.ToFoamDictionary(dLocalRefine);
         }
         FoamDictionary dObjectRefine = f.Dictionary.GetByUrl("objectRefinements");
         dObjectRefine.Clear();
         foreach (ObjectRefinementSubDict o in ObjectRefine)
         {
             o.ToFoamDictionary(dObjectRefine);
         }
         FoamDictionary dSurfaceRefine = f.Dictionary.GetByUrl("surfaceMeshRefinement");
         dSurfaceRefine.Clear();
         foreach (SurfaceRefinementSubDict s in SurfaceRefine)
         {
             s.ToFoamDictionary(dSurfaceRefine);
         }
         FoamDictionary dPatchName = f.Dictionary.GetByUrl("renameBoundary");
         dPatchName.Clear();
         dPatchName.SetChild("defaultName", "walls");
         dPatchName.SetChild("defaultType", "wall");
         FoamDictionary dNewPatchNames = dPatchName.GetByUrl("newPatchNames");
         dNewPatchNames.Clear();
         foreach (PatchConfigSubDict p in PatchConfig)
         {
             p.ToFoamDictionary(dNewPatchNames);
         }
         FoamDictionary dBoundaryLayers = f.Dictionary.GetByUrl("boundaryLayers");
         dBoundaryLayers.Clear();
         if (GlobalBoundaryLayerParameters.NLayers != 0)
         {
             GlobalBoundaryLayerParameters.ToFoamDictionary(dBoundaryLayers);
         }
         FoamDictionary dPatchBoundaryLayers = dBoundaryLayers.GetByUrl("patchBoundaryLayers");
         dPatchBoundaryLayers.Clear();
         foreach (PatchBoundaryLayerSubDict p in PatchBoundaryLayerParameters)
         {
             p.ToFoamDictionary(dPatchBoundaryLayers);
         }
         f.Write(dictFileName);
         return(true);
     }
     catch (Exception e)
     {
         if (monitor != null)
         {
             monitor.ErrorLine(e.Message);
         }
         return(false);
     }
 }
Esempio n. 12
0
 public static bool VerifyDirectory(string dir)
 {
     return(Directory.Exists(FoamConst.GetConstantPath(dir)) &&
            Directory.Exists(FoamConst.GetPolyMeshPath(dir)) &&
            File.Exists(Path.Combine(FoamConst.GetPolyMeshPath(dir), "points")));
 }
Esempio n. 13
0
        public bool Write(string foamRootPathName, IMonitor monitor)
        {
            bool res = true;

            try
            {
                Dictionary <string, FoamDictionary>     boundaryFieldDict = new Dictionary <string, FoamDictionary>();
                Dictionary <string, FoamDictionaryFile> fieldFoamFile     = new Dictionary <string, FoamDictionaryFile>();
                boundaryFieldDict.Clear();
                fieldFoamFile.Clear();
                foreach (string field in GlobalModelObject.fieldNames)
                {
                    FoamDictionaryFile f = new FoamDictionaryFile(FoamConst.GetZeroFieldFileName(foamRootPathName, field), monitor);
                    f.Read();
                    fieldFoamFile.Add(field, f);
                    boundaryFieldDict.Add(field, f.Dictionary.GetByUrl("boundaryField"));
                }
                foreach (BoundaryBase b in Boundarys)
                {
                    PolyMesh mesh = new PolyMesh(FoamConst.GetVxtFilePath(foamRootPathName));
                    if (b is Inlet || b is Outlet)
                    {
                        mesh.SetBoundaryType(b.PatchName, PolyMesh.BoundaryType.patch);
                    }
                    else if (b is Tplc.Model.Boundary.Wall)
                    {
                        mesh.SetBoundaryType(b.PatchName, PolyMesh.BoundaryType.wall);
                    }
                    res = b.Update(boundaryFieldDict);
                    if (!res)
                    {
                        if (monitor != null)
                        {
                            monitor.ErrorLine("Write boundary to foam error, boundary: " + b.PatchName);
                        }
                        return(false);
                    }
                }
                foreach (FoamDictionaryFile f in fieldFoamFile.Values)
                {
                    f.Write();
                }
                res = MaterialProperty.Write(foamRootPathName, monitor);
                if (!res)
                {
                    if (monitor != null)
                    {
                        monitor.ErrorLine("Write gas proprety to foam error !");
                    }
                    return(false);
                }
                res = InitlizeValue.Write(foamRootPathName, monitor);
                if (!res)
                {
                    if (monitor != null)
                    {
                        monitor.ErrorLine("Write initlize value to foam error !");
                    }
                    return(false);
                }
                res = ResidualContorl.Write(foamRootPathName, monitor);
                if (!res)
                {
                    if (monitor != null)
                    {
                        monitor.ErrorLine("Write residual control to foam error !");
                    }
                    return(false);
                }
                res = SolveContorl.Write(foamRootPathName, monitor);
                if (!res)
                {
                    if (monitor != null)
                    {
                        monitor.ErrorLine("Write solve control to foam error !");
                    }
                    return(false);
                }
                res = RelaxationFactors.Write(foamRootPathName, monitor);
                if (!res)
                {
                    if (monitor != null)
                    {
                        monitor.ErrorLine("Write Relaxation factors to foam error !");
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (monitor != null)
                {
                    monitor.ErrorLine("Update case error : " + e.Message);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 14
0
 public PatchReader(string vxtFileName, IMonitor mon = null)
 {
     this.boundaryFile = Path.Combine(FoamConst.GetPolyMeshPath(FoamConst.GetCaseRootFromVxt(vxtFileName)), "boundary");
     monitor           = mon;
 }