Example #1
0
 public void test_project_properly_load_gws_file()
 {
     WSProject project = new WSProject(project_file.FullName);
     string gws_filepath = "gws_test.gws";
     FileInfo gws_file = new FileInfo(gws_filepath);
     bool check = project.load_gws(gws_file.FullName);
     string expected_file_path = project.file.Directory.FullName + "\\dtm\\grid.gws";
     string sourceContent = File.ReadAllText(gws_file.FullName);
     string destinationContent = File.ReadAllText(expected_file_path);
     Assert.AreEqual(sourceContent, destinationContent);
     //
 }
Example #2
0
 public void test_project_load_gws_proper_file_referencing_in_project_terrainRanOnCurrentGws()
 {
     WSProject project = new WSProject(project_file.FullName);
     string gws_filepath = "gws_test.gws";
     FileInfo gws_file = new FileInfo(gws_filepath);
     project.terrainRanOnCurrentGws = true;
     bool check = project.load_gws(gws_file.FullName);
     Assert.AreEqual(false, project.terrainRanOnCurrentGws);
 }
Example #3
0
 public void test_project_load_gws_proper_file_renaming_2()
 {
     WSProject project = new WSProject(project_file.FullName);
     string gws_filepath = "gws_test.gws";
     FileInfo bws_file = new FileInfo(gws_filepath);
     bool check = project.load_gws(bws_file.FullName);
     bool check2 = project.load_gws(bws_file.FullName);
     string expected_file_path = project.file.Directory.FullName + "\\dtm\\grid.backup_fbatch_1.gws";
     FileInfo expected_file = new FileInfo(expected_file_path);
     Assert.IsTrue(expected_file.Exists);
     //
 }
Example #4
0
        public ExcelBatch(WSProject referenceProject, FileInfo excelBatchFile)
        {
            // controllo l-esistenza del file excel
            if (verifyExcelFile(excelBatchFile) && verifyProjectFiles(excelBatchFile, referenceProject))
            {
                // setto la directory
                // riempo l'experimentBatch
                Workbook book = Workbook.Load(excelBatchFile.FullName);
                Worksheet sheet = book.Worksheets[0];
                string batteryName = sheet.Cells[0, 1].StringValue;
                double numberOfEsperiments = Convert.ToInt32(sheet.Cells[1, 1].Value);
                Worksheet results_geom = book.Worksheets[1];
                results_geom.Cells[0, 0] = new Cell("UCRT Profiles for Geometrical Grading");
                Worksheet results_ke_geom = book.Worksheets[2];
                results_ke_geom.Cells[0, 0] = new Cell("KE Profiles for Geometrical Grading");
                Worksheet results_zcen_geom = book.Worksheets[3];
                results_zcen_geom.Cells[0, 0] = new Cell("Z Profiles for Geometrical Grading");
                Worksheet results_arit = book.Worksheets[4];
                results_arit.Cells[0, 0] = new Cell("UCRT Profiles for Aritmetical Grading");
                Worksheet results_ke_arit = book.Worksheets[5];
                results_ke_arit.Cells[0, 0] = new Cell("KE Profiles for Aritmetical Grading");
                Worksheet results_zcen_arit = book.Worksheets[6];
                results_zcen_arit.Cells[0, 0] = new Cell("Z Profiles for Aritmetical Grading");
                Worksheet results_tem1_arit = book.Worksheets[7];
                results_tem1_arit.Cells[0, 0] = new Cell("TEM1 Profiles for Aritmetical Grading");
                Worksheet results_tem1_geom = book.Worksheets[8];
                results_tem1_geom.Cells[0, 0] = new Cell("TEM1 Profiles for Geometrical Grading");
                Console.WriteLine("Total simulations in the excel :"+ numberOfEsperiments);
                for (int i = 0; i < numberOfEsperiments; i++)
                {
                  int todo = Convert.ToInt32(sheet.Cells[6, i + 1].Value);

                  if (todo == 0)
                  {
                      Console.WriteLine("Skipping case : " + i);
                  }

                  if( todo == 1 || todo == 2)
                  {
                    Console.WriteLine("Running case : " + i + " todo " + todo);
                    WSProject testcase = null;
                    WSProject testcase_arit = null;

                    bool restart = false;
                    string testCasetargetDirectory = excelBatchFile.Directory.FullName + "\\" + batteryName + "_" + sheet.Cells[7, i + 1].StringValue;
                    double z0_convergence_treshold = Convert.ToDouble(sheet.Cells[14, i + 1].Value);
                    int z0_convergence_sweeps = Convert.ToInt32(sheet.Cells[15, i + 1].Value);
                    int z0_cycles_to_be_checked = Convert.ToInt32(sheet.Cells[16, i + 1].Value);

                    int z0_monitoring_x = Convert.ToInt32(sheet.Cells[17, i + 1].Value);
                    int z0_monioring_y = Convert.ToInt32(sheet.Cells[18, i + 1].Value);
                    int nx = Convert.ToInt32(sheet.Cells[8, i + 1].Value);
                    int nj = Convert.ToInt32(sheet.Cells[9, i + 1].Value);
                    int verticalResolution = Convert.ToInt32(sheet.Cells[10, i + 1].Value);
                    float totalHeight = (float)Convert.ToDouble(sheet.Cells[11, i + 1].Value);

                    float roughness = (float)Convert.ToDouble(sheet.Cells[12, i + 1].Value);

                    double heithFirstLayerGeometrical = Convert.ToDouble(sheet.Cells[21, i + 1].Value);

                    RefinementGenerator.GeometricalGrading geom_refinement = new RefinementGenerator.GeometricalGrading(heithFirstLayerGeometrical, totalHeight, verticalResolution);

                    if (todo == 1) {

                    testcase = new WSProject(referenceProject.file.FullName, testCasetargetDirectory+"_geom");
                    testcase.load_parameters_from_excel(sheet);
                    #region read batch case parameters

                    FileInfo gwsfile = new FileInfo(excelBatchFile.Directory.FullName + "\\gws_files\\" + sheet.Cells[12, i + 1].ToString());
                    testcase.parameters.CFD.Height = totalHeight;
                    testcase.parameters.DTM.Roughness = roughness;

                    testcase.save();
                    testcase.load_gws(gwsfile.FullName);
                    // run the case of geometrical grid..

                    geom_refinement.Rectangle(testcase,"autogenerated_geometrical_bws_"+nx+"_"+nj, testcase.parameters.DTM.XMax,testcase.parameters.DTM.YMax,nx,nj);
                    #endregion
                    testcase.run(1);
                    }
                   else if (todo == 2)
                    {
                       restart = true;
                       z0_convergence_treshold = Convert.ToDouble(sheet.Cells[37, i + 1].Value);
                       z0_convergence_sweeps = Convert.ToInt32(sheet.Cells[38, i + 1].Value);
                       z0_cycles_to_be_checked = Convert.ToInt32(sheet.Cells[39, i + 1].Value);
                       FileInfo geometrico = new FileInfo(testCasetargetDirectory + "_geom\\" + referenceProject.file.Name);
                       testcase = new WSProject(geometrico.FullName);
                   }

                    Console.WriteLine("...G");
                    double[] z0results_geom = testcase.run_windfield_z0_conv(z0_convergence_treshold,z0_convergence_sweeps,z0_cycles_to_be_checked,z0_monitoring_x,z0_monioring_y, restart);
                    int resultRowShift = 0;
                    if (todo == 2) { resultRowShift = 21;}
                    #region write results geometrical

                    // write results
                    sheet.Cells[20 + resultRowShift, i + 1] = new Cell(geom_refinement.expansionFactor);
                    //height first cell
                    sheet.Cells[21 + resultRowShift, i + 1] = new Cell(geom_refinement.heightFirstLayer);
                    //z0
                    ////  { z0 , (u*/k) , sigma, r2 , sigmaz0 }
                    sheet.Cells[22 + resultRowShift, i + 1] = new Cell(z0results_geom[0]);
                    //sigma z0
                    sheet.Cells[23 + resultRowShift, i + 1] = new Cell(z0results_geom[4]);
                    //r2
                    sheet.Cells[24 + resultRowShift, i + 1] = new Cell(z0results_geom[3]);

                    // add ustar
                    double ustar_geom = MyMath.ustar_neutral(testcase.parameters.WindField.VelocityBoundaryLayer, testcase.parameters.WindField.HeightBoundaryLayer, testcase.parameters.DTM.Roughness, 0.4);
                    if (testcase.parameters.WindField.Temperature == 1)
                    {
                        ustar_geom = MyMath.ustar_neutral(testcase.parameters.WindField.WindspeedInReferenceHeight, testcase.parameters.WindField.ReferenceHeight, testcase.parameters.DTM.Roughness, 0.4);
                    }
                    sheet.Cells[25 + resultRowShift, i + 1] = new Cell(ustar_geom);

                    //add the project to the dictionary

                    book.Save(excelBatchFile.FullName);
                    #endregion
                    #region write profiles geometrical

                    // write the profile in the profiles file
                    double[] profile_geom = testcase.WField[270].ucrt(z0_monitoring_x, z0_monioring_y);
                    double[] zcen_geom = testcase.WField[270].zcen(z0_monitoring_x, z0_monioring_y);
                    double[] profile_geom_ke = testcase.WField[270].ke(z0_monitoring_x, z0_monioring_y);
                    double[] theoretical_mo_neural_geom = MyMath.mo_neutral_u(zcen_geom, 0.4, ustar_geom, roughness);
                    double rmse_geom = MyMath.rmse(profile_geom, theoretical_mo_neural_geom);
                    sheet.Cells[26 + resultRowShift, i + 1] = new Cell(rmse_geom);

                    results_geom.Cells[1, i] = new Cell(i + 1);
                    results_zcen_geom.Cells[1, i] = new Cell(i + 1);
                    results_ke_geom.Cells[1, i] = new Cell(i + 1);
                    for (int count = 0; count < profile_geom.Length; count++)
                    {
                       results_geom.Cells[count+3, i] = new Cell(profile_geom[count]);
                       results_zcen_geom.Cells[count+3, i] = new Cell(zcen_geom[count]);
                       results_ke_geom.Cells[count + 3, i] = new Cell(profile_geom_ke[count]);
                    }
                    if (testcase.parameters.WindField.Temperature == 1)
                    {
                        double[] profile_geom_tem1 = testcase.WField[270].tem1(z0_monitoring_x, z0_monioring_y);
                        for (int count = 0; count < profile_geom.Length; count++)
                        {
                            results_tem1_geom.Cells[count + 3, i] = new Cell(profile_geom_tem1[count]);
                        }
                    }
                    book.Save(excelBatchFile.FullName);
                    #endregion

                    Console.WriteLine("...A");
                    RefinementGenerator.AritmeticalGrading arit_refinement = new RefinementGenerator.AritmeticalGrading(geom_refinement.expansionFactor, geom_refinement.numbersOfVericalLayer, geom_refinement.totalHeight);
                    if (todo == 1)
                    {
                        // duplicate the project
                        testcase_arit = new WSProject(testcase.file.FullName, testCasetargetDirectory + "_arit");
                        // create the bws
                        // assign the bws
                        arit_refinement.Rectangle(testcase_arit, "autogenerated_aritmeical_bws_" + nx + "_" + nj, testcase_arit.parameters.DTM.XMax, testcase_arit.parameters.DTM.YMax, nx, nj);
                        // run terrain
                        testcase_arit.run(1);
                        // run the project
                    }
                    else if (todo == 2)
                    {
                        z0_convergence_treshold = Convert.ToDouble(sheet.Cells[37, i + 1].Value);
                        z0_convergence_sweeps = Convert.ToInt32(sheet.Cells[38, i + 1].Value);
                        z0_cycles_to_be_checked = Convert.ToInt32(sheet.Cells[39, i + 1].Value);
                        FileInfo aritmetico = new FileInfo(testCasetargetDirectory + "_arit\\" + referenceProject.file.Name);
                        testcase_arit = new WSProject(aritmetico.FullName);
                    }

                    double[] z0results_arit = testcase_arit.run_windfield_z0_conv(z0_convergence_treshold, z0_convergence_sweeps, z0_cycles_to_be_checked, z0_monitoring_x, z0_monioring_y,restart);

                    #region write resuls aritmetical

                    // write he results z0
                    sheet.Cells[28 + resultRowShift, i + 1] = new Cell(arit_refinement.heightDistributionFactor);
                    //height first cell
                    sheet.Cells[29 + resultRowShift, i + 1] = new Cell(arit_refinement.heightFirstLayer);
                    //z0
                    ////  { z0 , (u*/k) , sigma, r2 , sigmaz0 }
                    sheet.Cells[30 + resultRowShift, i + 1] = new Cell(z0results_arit[0]);
                    //sigma z0
                    sheet.Cells[31 + resultRowShift, i + 1] = new Cell(z0results_arit[4]);
                    //r2
                    sheet.Cells[32 + resultRowShift, i + 1] = new Cell(z0results_arit[3]);

                    // add ustar
                    double ustar_arit = MyMath.ustar_neutral(testcase_arit.parameters.WindField.VelocityBoundaryLayer, testcase_arit.parameters.WindField.HeightBoundaryLayer, testcase_arit.parameters.DTM.Roughness, 0.4);
                    if (testcase.parameters.WindField.Temperature == 1)
                    {
                        ustar_arit = MyMath.ustar_neutral(testcase_arit.parameters.WindField.WindspeedInReferenceHeight, testcase_arit.parameters.WindField.ReferenceHeight, testcase_arit.parameters.DTM.Roughness, 0.4);
                    }
                    sheet.Cells[25 + resultRowShift, i + 1] = new Cell(ustar_geom);

                    sheet.Cells[33 + resultRowShift, i + 1] = new Cell(ustar_arit);

                    //add the project to the dictionary
                    book.Save(excelBatchFile.FullName);
                    #endregion

                    #region write profiles aritmetical

                    // write the profile in the profiles file
                    double[] profile_arit = testcase_arit.WField[270].ucrt(z0_monitoring_x, z0_monioring_y);
                    double[] zcen_arit = testcase_arit.WField[270].zcen(z0_monitoring_x, z0_monioring_y);
                    double[] profile_arit_ke = testcase_arit.WField[270].ke(z0_monitoring_x, z0_monioring_y);

                    // add rmse
                    double[] theoretical_mo_neural_arit = MyMath.mo_neutral_u(zcen_arit, 0.4, ustar_arit, roughness);
                    double rmse_arit = MyMath.rmse(profile_arit, theoretical_mo_neural_arit);
                    sheet.Cells[34 + resultRowShift, i + 1] = new Cell(rmse_arit);

                    results_arit.Cells[1, i] = new Cell(i + 1);
                    results_zcen_arit.Cells[1, i] = new Cell(i + 1);
                    results_ke_arit.Cells[1, i] = new Cell(i + 1);
                    for (int count = 0; count < profile_arit.Length; count++)
                    {
                        results_arit.Cells[count+3, i] = new Cell(profile_arit[count]);
                        results_zcen_arit.Cells[count+3, i] = new Cell(zcen_arit[count]);
                        results_ke_arit.Cells[count+3, i] = new Cell(profile_arit_ke[count]);

                    }

                    if (testcase.parameters.WindField.Temperature == 1)
                    {
                        double[] profile_arit_tem1 = testcase_arit.WField[270].tem1(z0_monitoring_x, z0_monioring_y);
                        for (int count = 0; count < profile_arit.Length; count++)
                        {
                            results_tem1_arit.Cells[count + 3, i] = new Cell(profile_arit_tem1[count]);
                        }
                    }
                    book.Save(excelBatchFile.FullName);
                    //add the project to the dictionary
                    #endregion

                 }
                }
              }

            else
            {
                throw new System.ArgumentException("Some error occurred regarding the excel file");
            }
        }