public void WriteSimx() { var now = DateTime.Now; string revisionDate = now.ToString("yyyy-MM-dd HH:mm:ss"); string filePath = Path.Combine(Path.GetDirectoryName(MainSettings.Inx), MainSettings.Name + ".simx"); string[] empty = { }; XmlTextWriter xWriter = new XmlTextWriter(filePath, Encoding.UTF8); xWriter.WriteStartElement("ENVI-MET_Datafile"); xWriter.WriteString(NEWLINE); // Header section string headerTitle = "Header"; string[] headerTag = new string[] { "filetype", "version", "revisiondate", "remark", "encryptionlevel" }; string[] headerValue = new string[] { "SIMX", "2", revisionDate, "Created with lb_envimet", "0" }; Inx.CreateXmlSection(xWriter, headerTitle, headerTag, headerValue, 0, empty); // Main section string mainTitle = "mainData"; string[] mainTag = new string[] { "simName", "INXFile", "filebaseName", "outDir", "startDate", "startTime", "simDuration", "windSpeed", "windDir", "z0", "T_H", "Q_H", "Q_2m" }; string[] mainValue = new string[] { MainSettings.Name, Path.GetFileName(MainSettings.Inx), MainSettings.Name, " ", MainSettings.StartDate, MainSettings.StartTime, MainSettings.SimDuration.ToString(), MainSettings.WindSpeed.ToString(), MainSettings.WindDir.ToString(), MainSettings.Roughness.ToString(), MainSettings.InitialTemperature.ToString(), MainSettings.SpecificHumidity.ToString(), MainSettings.RelativeHumidity.ToString() }; Inx.CreateXmlSection(xWriter, mainTitle, mainTag, mainValue, 0, empty); if (SimpleForcing != null && FullForcing == null) { string sfTitle = "SimpleForcing"; string[] sfTag = new string[] { "TAir", "Qrel" }; string[] sfValue = new string[] { SimpleForcing.Temperature, SimpleForcing.RelativeHumidity }; Inx.CreateXmlSection(xWriter, sfTitle, sfTag, sfValue, 0, empty); } if (TThread != null) { string parallelTitle = "TThread"; string[] parallelTag = new string[] { "UseTThread_CallMain", "TThreadPRIO" }; string[] parallelValue = new string[] { TThread.UseTreading.ToString(), TThread.TThreadpriority.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (ModelTiming != null) { string parallelTitle = "ModelTiming"; string[] parallelTag = new string[] { "surfaceSteps", "flowSteps", "radiationSteps", "plantSteps", "sourcesSteps" }; string[] parallelValue = new string[] { ModelTiming.SurfaceSteps.ToString(), ModelTiming.FlowSteps.ToString(), ModelTiming.RadiationSteps.ToString(), ModelTiming.PlantSteps.ToString(), ModelTiming.SourcesSteps.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (SoilSettings != null) { string parallelTitle = "Soil"; string[] parallelTag = new string[] { "tempUpperlayer", "tempMiddlelayer", "tempDeeplayer", "tempBedrockLayer", "waterUpperlayer", "waterMiddlelayer", "waterDeeplayer", "waterBedrockLayer" }; string[] parallelValue = new string[] { SoilSettings.TempUpperlayer.ToString("n6"), SoilSettings.TempMiddlelayer.ToString("n6"), SoilSettings.TempDeeplayer.ToString("n6"), SoilSettings.TempBedrockLayer.ToString("n6"), SoilSettings.WaterUpperlayer.ToString("n6"), SoilSettings.WaterMiddlelayer.ToString("n6"), SoilSettings.WaterDeeplayer.ToString("n6"), SoilSettings.WaterBedrockLayer.ToString("n6") }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (Sources != null) { string parallelTitle = "Sources"; string[] parallelTag = new string[] { "userPolluName", "userPolluType", "userPartDiameter", "userPartDensity", "multipleSources", "activeChem", "isoprene" }; string[] parallelValue = new string[] { Sources.UserPolluName, Sources.UserPolluType.ToString(), Sources.UserPartDiameter.ToString(), Sources.UserPartDensity.ToString(), Sources.MultipleSources.ToString(), Sources.ActiveChem.ToString(), Sources.ISOPRENE }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (Turbulence != null) { string parallelTitle = "Turbulence"; string[] parallelTag = new string[] { "turbulenceModel" }; string[] parallelValue = new string[] { Turbulence.TurbulenceModel.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (TimeSteps != null) { string parallelTitle = "TimeSteps"; string[] parallelTag = new string[] { "sunheight_step01", "sunheight_step02", "dt_step00", "dt_step01", "dt_step02" }; string[] parallelValue = new string[] { TimeSteps.SunheightStep01.ToString("n6"), TimeSteps.SunheightStep02.ToString("n6"), TimeSteps.DtStep00.ToString("n6"), TimeSteps.DtStep01.ToString("n6"), TimeSteps.DtStep02.ToString("n6") }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (OutputSettings != null) { string parallelTitle = "OutputSettings"; string[] parallelTag = new string[] { "mainFiles", "textFiles", "netCDF", "netCDFAllDataInOneFile", "inclNestingGrids" }; string[] parallelValue = new string[] { OutputSettings.MainFiles.ToString(), OutputSettings.TextFiles.ToString(), OutputSettings.NetCDF.ToString(), OutputSettings.NetCDFAllDataInOneFile.ToString(), "0" }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (Cloud != null && FullForcing == null) { string parallelTitle = "Clouds"; string[] parallelTag = new string[] { "lowClouds", "middleClouds", "highClouds" }; string[] parallelValue = new string[] { Cloud.LowClouds.ToString("n6"), Cloud.MiddleClouds.ToString("n6"), Cloud.HighClouds.ToString("n6") }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (Background != null) { string parallelTitle = "Background"; string[] parallelTag = new string[] { "userSpec", "NO", "NO2", "O3", "PM_10", "PM_2_5" }; string[] parallelValue = new string[] { Background.UserSpec.ToString("n6"), Background.No.ToString("n6"), Background.No2.ToString("n6"), Background.O3.ToString("n6"), Background.Pm10.ToString("n6"), Background.Pm25.ToString("n6") }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (SolarAdjust != null && FullForcing == null) { string parallelTitle = "SolarAdjust"; string[] parallelTag = new string[] { "SWFactor" }; string[] parallelValue = new string[] { SolarAdjust.SWfactor.ToString("n6") }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (BuildingSettings != null) { string parallelTitle = "Building"; string[] parallelTag = new string[] { "indoorTemp", "indoorConst" }; string[] parallelValue = new string[] { BuildingSettings.IndoorTemp.ToString("n6"), BuildingSettings.IndoorConst.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (IVS != null) { string parallelTitle = "IVS"; string[] parallelTag = new string[] { "IVSOn", "IVSMem" }; string[] parallelValue = new string[] { IVS.IVSOn.ToString(), IVS.IVSMem.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (ParallelCPU != null) { string parallelTitle = "Parallel"; string[] parallelTag = new string[] { "CPUdemand" }; string[] parallelValue = new string[] { ParallelCPU.CPU }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (SOR != null) { string parallelTitle = "SOR"; string[] parallelTag = new string[] { "SORMode" }; string[] parallelValue = new string[] { SOR.SORMode.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (InflowAvg != null) { string parallelTitle = "InflowAvg"; string[] parallelTag = new string[] { "inflowAvg" }; string[] parallelValue = new string[] { InflowAvg.Avg.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (PlantSetting != null) { string parallelTitle = "PlantModel"; string[] parallelTag = new string[] { "CO2BackgroundPPM", "LeafTransmittance", "TreeCalendar" }; string[] parallelValue = new string[] { PlantSetting.CO2.ToString(), PlantSetting.LeafTransmittance.ToString(), PlantSetting.TreeCalendar.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (Facades != null) { string parallelTitle = "Facades"; string[] parallelTag = new string[] { "FacadeMode" }; string[] parallelValue = new string[] { Facades.FacadeMode.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (LBC != null && (SimpleForcing == null || FullForcing == null)) { string parallelTitle = "LBC"; string[] parallelTag = new string[] { "LBC_TQ", "LBC_TKE" }; string[] parallelValue = new string[] { LBC.TemperatureHumidity.ToString(), LBC.Turbolence.ToString() }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } if (FullForcing != null) { string parallelTitle = "FullForcing"; string[] parallelTag = new string[] { "fileName", "forceT", "forceQ", "forceWind", "forcePrecip", "forceRadClouds", "interpolationMethod", "nudging", "nudgingFactor", "minFlowsteps", "limitWind2500", "maxWind2500", "z_0" }; string[] parallelValue = new string[] { FullForcing.FileName, FullForcing.ForceTemperature.ToString(), FullForcing.ForceRelativeHumidity.ToString(), FullForcing.ForceWind.ToString(), FullForcing.ForcePrecipitation.ToString(), FullForcing.ForceRadClouds.ToString(), FullForcing.INTERPOLATION_METHOD, FullForcing.NUDGING, FullForcing.NUNDGING_FACTOR, FullForcing.MinFlowsteps.ToString(), FullForcing.LimitWind2500.ToString(), FullForcing.MaxWind2500.ToString(), FullForcing.Z_0 }; Inx.CreateXmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty); } xWriter.WriteEndElement(); xWriter.Close(); }
public static void INXwriteMethod(string path, Preparation preparation) { // preparation var now = DateTime.Now; string revisionDate = now.ToString("yyyy-MM-dd HH:mm:ss"); const string NewLine = "\n"; var grid = (Grid)preparation.EnvimetPart["grid"]; var building = (Tuple <Dictionary <string, string>, List <string[]> >)preparation.EnvimetPart["building"]; var dem = (Tuple <Point3d[], string, string>)preparation.EnvimetPart["dem"]; var plant3d = (List <string[]>)preparation.EnvimetPart["plant3d"]; var receptors = (List <string[]>)preparation.EnvimetPart["receptors"]; var nestingGrid = (NestingGrid)preparation.EnvimetPart["nestingGrid"]; var simpleplants2D = (string)preparation.EnvimetPart["simpleplants2D"]; var soils2D = (string)preparation.EnvimetPart["soils2D"]; var sources2D = (string)preparation.EnvimetPart["sources2D"]; var simpleW = (string)preparation.EnvimetPart["simpleW"]; var location = (Location)preparation.EnvimetPart["location"]; var envimetZeroMatrix = (string)preparation.EnvimetPart["envimetZeroMatrix"]; var envimetEmptyMatrix = (string)preparation.EnvimetPart["envimetEmptyMatrix"]; var emptySoilMatrix = (string)preparation.EnvimetPart["emptySoilMatrix"]; // unwrap buildings string buildingNumberMatrix = building.Item1["buildingNumberMatrix"]; string wallDBMatrix = building.Item1["wallDBMatrix"]; string greenDBMatrix = building.Item1["greenDBMatrix"]; string topMatrix = building.Item1["topMatrix"]; string bottomMatrix = building.Item1["bottomMatrix"]; string fixedMatrix = building.Item1["fixedMatrix"]; string idMatrix = building.Item1["idMatrix"]; var greenInfo = building.Item2; // unwrap dem string dem2d = dem.Item3; string terrainflag = dem.Item2; // start with xml XmlTextWriter xWriter = new XmlTextWriter(path, Encoding.UTF8); xWriter.WriteStartElement("ENVI-MET_Datafile"); xWriter.WriteString(NewLine + " "); string[] empty = { }; // section Header string headerTitle = "Header"; string[] headerTag = new string[] { "filetype", "version", "revisiondate", "remark", "encryptionlevel" }; string[] headerValue = new string[] { "INPX ENVI-met Area Input File", "401", revisionDate, "Created with lb_envimet", "0" }; Inx.CreateXmlSection(xWriter, headerTitle, headerTag, headerValue, 0, empty); // section baseData string baseDataTitle = "baseData"; string[] baseDataTag = new string[] { "modelDescription", "modelAuthor" }; string[] baseDataValue = new string[] { " A brave new area ", " DragonFly envimet " }; Inx.CreateXmlSection(xWriter, baseDataTitle, baseDataTag, baseDataValue, 0, empty); // section modelGeometry // preparation telescope / splitted grid string useSplitting = null; string verticalStretch = null; string startStretch = null; string grids3DK = null; string gridsZ = null; string useTelescoping = null; string gridsI = (grid.NumX).ToString(); string gridsJ = (grid.NumY).ToString(); string[] attribute2dElements = { "matrix-data", gridsI, gridsJ }; string dx = grid.DimX.ToString("n5"); string dy = grid.DimY.ToString("n5"); string dz = grid.DimZ.ToString("n5"); if (grid.Telescope > 0) { useTelescoping = "1"; useSplitting = "0"; verticalStretch = grid.Telescope.ToString(); startStretch = grid.StartTelescopeHeight.ToString(); grids3DK = gridsZ = grid.NumZ.ToString(); if (grid.CombineGridType) { useSplitting = "1"; gridsZ = grid.NumZ.ToString(); grids3DK = (grid.NumZ + Grid.FIRST_CELL_COMBINED_GRID).ToString(); } } else { useTelescoping = "0"; useSplitting = "1"; verticalStretch = "0"; startStretch = "0"; gridsZ = grid.NumZ.ToString(); grids3DK = grids3DK = (grid.NumZ + Grid.FIRST_CELL_COMBINED_GRID).ToString(); } string modelGeometryTitle = "modelGeometry"; string[] modelGeometryTag = new string[] { "grids-I", "grids-J", "grids-Z", "dx", "dy", "dz-base", "useTelescoping_grid", "useSplitting", "verticalStretch", "startStretch", "has3DModel", "isFull3DDesign" }; string[] modelGeometryValue = new string[] { gridsI, gridsJ, gridsZ, dx, dy, dz, useTelescoping, useSplitting, verticalStretch, startStretch, "1", "1" }; Inx.CreateXmlSection(xWriter, modelGeometryTitle, modelGeometryTag, modelGeometryValue, 0, empty); // section nestingArea string nestingAreaTitle = "nestingArea"; string[] nestingAreaTag = new string[] { "numberNestinggrids", "soilProfileA", "soilProfileB" }; string[] nestingAreaValue = new string[] { nestingGrid.NumNestingGrid.ToString(), nestingGrid.SoilProfileA, nestingGrid.SoilProfileB }; Inx.CreateXmlSection(xWriter, nestingAreaTitle, nestingAreaTag, nestingAreaValue, 0, empty); // section locationData string locationDataTitle = "locationData"; string[] locationDataTag = new string[] { "modelRotation", "projectionSystem", "realworldLowerLeft_X", "realworldLowerLeft_Y", "locationName", "location_Longitude", "location_Latitude", "locationTimeZone_Name", "locationTimeZone_Longitude" }; string[] locationDataValue = new string[] { location.ModelRotation.ToString("n5"), " ", " 0.00000 ", " 0.00000 ", location.LocationName, location.Longitude.ToString(), location.Latitude.ToString(), location.TimeZone, location.ReferenceLongitude.ToString("n5") }; Inx.CreateXmlSection(xWriter, locationDataTitle, locationDataTag, locationDataValue, 0, empty); // section defaultSettings string defaultSettingsTitle = "defaultSettings"; string[] defaultSettingsTag = new string[] { "commonWallMaterial", "commonRoofMaterial" }; string[] defaultSettingsValue = new string[] { Material.CommonWallMaterial, Material.CommonRoofMaterial }; Inx.CreateXmlSection(xWriter, defaultSettingsTitle, defaultSettingsTag, defaultSettingsValue, 0, empty); // section buildings2D string buildings2DTitle = "buildings2D"; string[] buildings2DTag = new string[] { "zTop", "zBottom", "buildingNr", "fixedheight" }; string[] buildings2DValue = new string[] { NewLine + topMatrix, NewLine + bottomMatrix, NewLine + idMatrix, NewLine + fixedMatrix }; Inx.CreateXmlSection(xWriter, buildings2DTitle, buildings2DTag, buildings2DValue, 1, attribute2dElements); // section simpleplants2D string simpleplants2DTitle = "simpleplants2D"; string[] simpleplants2DTag = new string[] { "ID_plants1D" }; string[] simpleplants2DValue = new string[] { NewLine + simpleplants2D }; Inx.CreateXmlSection(xWriter, simpleplants2DTitle, simpleplants2DTag, simpleplants2DValue, 1, attribute2dElements); // section plant3d if (plant3d.Count > 0) { for (int i = 0; i < plant3d.Count; i++) { string plants3DTitle = "3Dplants"; string[] plants3DTag = new string[] { "rootcell_i", "rootcell_j", "rootcell_k", "plantID", "name", "observe" }; string[] plants3DValue = new string[] { plant3d[i][0], plant3d[i][1], plant3d[i][2], plant3d[i][3], plant3d[i][4], plant3d[i][5] }; Inx.CreateXmlSection(xWriter, plants3DTitle, plants3DTag, plants3DValue, 0, empty); } } // section receptors if (receptors.Count > 0) { for (int i = 0; i < receptors.Count; i++) { string receptorsTitle = "Receptors"; string[] receptorsTag = new string[] { "cell_i", "cell_j", "name" }; string[] receptorsValue = new string[] { receptors[i][0], receptors[i][1], receptors[i][2] }; Inx.CreateXmlSection(xWriter, receptorsTitle, receptorsTag, receptorsValue, 0, empty); } } // section soils2D string soils2DTitle = "soils2D"; string[] soils2DTag = new string[] { "ID_soilprofile" }; string[] soils2DValue = new string[] { NewLine + soils2D }; Inx.CreateXmlSection(xWriter, soils2DTitle, soils2DTag, soils2DValue, 1, attribute2dElements); // section dem string demTitle = "dem"; string[] demDTag = new string[] { "terrainheight" }; string[] demValue = new string[] { NewLine + dem2d }; Inx.CreateXmlSection(xWriter, demTitle, demDTag, demValue, 1, attribute2dElements); // section sources2D string sources2DTitle = "sources2D"; string[] sources2DTag = new string[] { "ID_sources" }; string[] sources2DValue = new string[] { NewLine + sources2D }; Inx.CreateXmlSection(xWriter, sources2DTitle, sources2DTag, sources2DValue, 1, attribute2dElements); // section receptors2D (does not exist anymore) //string receptors2DTitle = "receptors2D"; //string[] receptors2DTag = new string[] { "ID_receptors" }; //string[] receptors2DValue = new string[] { NewLine + envimetEmptyMatrix }; //Inx.CreateXmlSection(xWriter, receptors2DTitle, receptors2DTag, receptors2DValue, 1, attribute2dElements); // section additionalData (maybe next release) string additionalDataTitle = "additionalData"; string[] additionalDataTag = new string[] { "db_link_point", "db_link_area" }; string[] additionalDataValue = new string[] { NewLine + envimetEmptyMatrix, NewLine + envimetEmptyMatrix }; Inx.CreateXmlSection(xWriter, additionalDataTitle, additionalDataTag, additionalDataValue, 1, attribute2dElements); // section building if (wallDBMatrix != NewLine) { foreach (string[] green in greenInfo) { string buildinginfoTitle = "Buildinginfo"; string[] buildinginfoTag = new string[] { "BuildingInternalNr", "BuildingName", "BuildingWallMaterial", "BuildingRoofMaterial", "BuildingFacadeGreening", "BuildingRoofGreening" }; string[] buildinginfoValue = green; Inx.CreateXmlSection(xWriter, buildinginfoTitle, buildinginfoTag, buildinginfoValue, 0, empty); } } // section modelGeometry3D // preparation string grids3D_I = gridsI; string grids3D_J = gridsJ; string grids3D_K = grids3DK; string[] attribute3dElementsBuilding = { "sparematrix-3D", gridsI, gridsJ, grids3DK, "0" }; string[] attribute3dElementsTerrain = { "sparematrix-3D", gridsI, gridsJ, grids3DK, "0.00000" }; string[] attribute3dElementsWallDB = { "sparematrix-3D", gridsI, gridsJ, grids3DK, "" }; string modelGeometry3DTitle = "modelGeometry3D"; string[] modelGeometry3DTag = new string[] { "grids3D-I", "grids3D-J", "grids3D-K" }; string[] modelGeometry3DValue = new string[] { gridsI, gridsJ, grids3DK }; Inx.CreateXmlSection(xWriter, modelGeometry3DTitle, modelGeometry3DTag, modelGeometry3DValue, 0, empty); // section buildings3D string buildings3DTitle = "buildings3D"; string[] buildings3DTag = new string[] { "buildingFlagAndNr" }; string[] buildings3DValue = new string[] { NewLine + buildingNumberMatrix }; Inx.CreateXmlSection(xWriter, buildings3DTitle, buildings3DTag, buildings3DValue, 2, attribute3dElementsBuilding); // section dem3D string dem3DTitle = "dem3D"; string[] dem3DTag = new string[] { "terrainflag" }; string[] dem3DValue = new string[] { NewLine + terrainflag }; Inx.CreateXmlSection(xWriter, dem3DTitle, dem3DTag, dem3DValue, 2, attribute3dElementsTerrain); // section WallDB string WallDBTitle = "WallDB"; string[] WallDBTag = new string[] { "ID_wallDB" }; string[] WallDBValue = new string[] { NewLine + wallDBMatrix }; Inx.CreateXmlSection(xWriter, WallDBTitle, WallDBTag, WallDBValue, 2, attribute3dElementsWallDB); // section SingleWallDB string SingleWallDBTitle = "SingleWallDB"; string[] SingleWallDBTag = new string[] { "ID_singlewallDB" }; string[] SingleWallDBValue = new string[] { NewLine + simpleW }; Inx.CreateXmlSection(xWriter, SingleWallDBTitle, SingleWallDBTag, SingleWallDBValue, 2, attribute3dElementsWallDB); // section GreeningDB string GreeningDBTitle = "GreeningDB"; string[] GreeningDBTag = new string[] { "ID_GreeningDB" }; string[] GreeningDBValue = null; if (greenDBMatrix != null) { GreeningDBValue = new string[] { NewLine + greenDBMatrix }; } else { GreeningDBValue = new string[] { " " }; } Inx.CreateXmlSection(xWriter, GreeningDBTitle, GreeningDBTag, GreeningDBValue, 2, attribute3dElementsWallDB); xWriter.WriteEndElement(); xWriter.Close(); }