public List <string> GetSolidNameList(string fileName) { try { var res = new List <string>(); int i = 0; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("solid")) { string name = line.Replace("solid", "").Trim(); res.Add(name == "" ? "solid" + (i++) : name); } } sr.Close(); fs.Close(); return(res); } catch (Exception e) { if (mon != null) { mon.ErrorLine(e.Message); } return(null); } }
public override bool Read(string fileName, IMonitor mon = null) { try { unitList.Clear(); vtkSTLReader reader = vtkSTLReader.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); reader.SetFileName(fileName); mapper.SetInputConnection(reader.GetOutputPort()); StlUnit unit = new StlUnit("Stl." + Path.GetFileNameWithoutExtension(fileName)); unit.Actor.SetMapper(mapper); unitList.Add(unit); reader.Dispose(); mapper.Dispose(); return(true); } catch (Exception e) { if (mon != null) { mon.ErrorLine(e.Message); } return(false); } }
public override bool Update(Dictionary <string, FoamDictionary> dicts, IMonitor mon = null) { try { dicts["U"].SetChild(PatchName, CommonPatch.slip(mon)); dicts["p"].SetChild(PatchName, CommonPatch.zeroGradient(mon)); dicts["k"].SetChild(PatchName, CommonPatch.kqRWallFunction(mon)); dicts["epsilon"].SetChild(PatchName, CommonPatch.epsilonWallFunction(mon)); dicts["nut"].SetChild(PatchName, CommonPatch.nutkWallFunction(mon)); return(true); } catch (Exception e) { mon.ErrorLine(e.Message); return(false); } }
public override bool Update(Dictionary <string, FoamDictionary> dicts, IMonitor mon = null) { //throw new NotImplementedException(); try { dicts["U"].SetChild(PatchName, CommonPatch.zeroGradient(mon)); dicts["p"].SetChild(PatchName, CommonPatch.uniformFixedValue <double>(0.0, mon)); dicts["k"].SetChild(PatchName, CommonPatch.zeroGradient(mon)); dicts["epsilon"].SetChild(PatchName, CommonPatch.zeroGradient(mon)); dicts["nut"].SetChild(PatchName, CommonPatch.calculated(mon)); return(true); } catch (Exception e) { mon.ErrorLine(e.Message); return(false); } }
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); } }
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); }