diff --git a/modules/Workflow/whale/main.py b/modules/Workflow/whale/main.py index 785254c56..75fa6194c 100644 --- a/modules/Workflow/whale/main.py +++ b/modules/Workflow/whale/main.py @@ -2293,7 +2293,7 @@ def preprocess_inputs( # noqa: C901 # This time, (1) we do it only for python; (2) added try statement try: - if command.startswith('python'): + if command.startswith('python') and self.run_type == 'set_up': if platform.system() == 'Windows': driver_script += 'if %errorlevel% neq 0 exit /b -1 \n' #TODO ANYONE: This variable is not defined. Check This please. (Added by Sina) else: @@ -2461,7 +2461,7 @@ def create_driver_file( # noqa: C901 # This time, (1) we do it only for python; (2) added try statement # try: - if 'python' in command_list[0].lower(): + if 'python' in command_list[0].lower() and self.run_type == 'set_up': if platform.system() == 'Windows': driver_script += 'if %errorlevel% neq 0 exit /b -1 \n' else: diff --git a/modules/createEVENT/IsolatedBuildingCFD/IsolatedBuildingCFD.py b/modules/createEVENT/IsolatedBuildingCFD/IsolatedBuildingCFD.py index 39a43943b..0c2d99aa1 100644 --- a/modules/createEVENT/IsolatedBuildingCFD/IsolatedBuildingCFD.py +++ b/modules/createEVENT/IsolatedBuildingCFD/IsolatedBuildingCFD.py @@ -350,7 +350,12 @@ def scale_event(filename_aim, filename_event): except (json.JSONDecodeError, IOError) as e: print(f"Error IsolatedBuilldingCFD::scale_event processing files: {e}") - +def GetFloorsCount(BIMFilePath): # noqa: N802, N803, D103 + with open(BIMFilePath) as BIMFile: # noqa: PTH123, N806 + bim = json.load(BIMFile) + + return int(bim['GeneralInformation']['stories']) + if __name__ == "__main__": """ @@ -366,17 +371,34 @@ def scale_event(filename_aim, filename_event): parser.add_argument("--getRV", action="store_true", help="used to get random variable, if not multiply EVENT by gs") + # #parsing arguments + # arguments, unknowns = parser.parse_known_args() + + # # [forcesOutputName, floors, startTime, lengthScale, velocityScale] = ReadBIM(arguments.bim) + + # # GetOpenFOAMEvent(arguments.case, forcesOutputName, floors, startTime, lengthScale, velocityScale) + + # if not arguments.getRV: + + # scale_event(filename_aim = arguments.filenameAIM, filename_event = arguments.filenameEVENT) + #parsing arguments arguments, unknowns = parser.parse_known_args() - # [forcesOutputName, floors, startTime, lengthScale, velocityScale] = ReadBIM(arguments.bim) - - # GetOpenFOAMEvent(arguments.case, forcesOutputName, floors, startTime, lengthScale, velocityScale) + if arguments.getRV == True: # noqa: E712 + # Read the number of floors + # floorsCount = GetFloorsCount(arguments.filenameAIM) # noqa: N816 + floorsCount = GetFloorsCount(arguments.filenameAIM) # noqa: N816 + forces = [] + for i in range(floorsCount): # noqa: B007 + forces.append(FloorForces()) # noqa: PERF401 + # write the event file + writeEVENT(forces, arguments.filenameEVENT) if not arguments.getRV: - scale_event(filename_aim = arguments.filenameAIM, filename_event = arguments.filenameEVENT) + diff --git a/modules/createEVENT/stochasticWave/Jonswap.py b/modules/createEVENT/stochasticWave/Jonswap.py index 2fa3f3919..a68033edc 100644 --- a/modules/createEVENT/stochasticWave/Jonswap.py +++ b/modules/createEVENT/stochasticWave/Jonswap.py @@ -29,14 +29,14 @@ input_args = sys.argv[1:] - print( # noqa: T201 - 'Jonswap.py - Backend-script post_process_sensors.py running: ' - + str(sys.argv[0]) - ) - print( # noqa: T201 - 'post_process_sensors.py - Backend-script post_process_sensors.py received input args: ' - + str(input_args) - ) + # print( # noqa: T201 + # 'Jonswap.py - Backend-script post_process_sensors.py running: ' + # + str(sys.argv[0]) + # ) + # print( # noqa: T201 + # 'post_process_sensors.py - Backend-script post_process_sensors.py received input args: ' + # + str(input_args) + # ) inputFile = sys.argv[1] # noqa: N816 outputPath = sys.argv[2] # noqa: N816 @@ -47,7 +47,7 @@ with open(inputFile, encoding='utf-8') as BIMFile: # noqa: PTH123 bim = json.load(BIMFile) for event_id in range(1): - print('Running a sample simulation with JSON input parameters') # noqa: T201 + # print('Running a sample simulation with JSON input parameters') # noqa: T201 g = 9.80665 # gravity [m/s^2] rho = 1000.0 # water density @@ -165,7 +165,7 @@ # if (si == seeds[-1]): - print('Saving wave spectra and time series') # noqa: T201 + # print('Saving wave spectra and time series') # noqa: T201 spectra_df = pd.DataFrame() spectra_df['Frequency'] = freq diff --git a/modules/createEVENT/stochasticWave/StochasticWave.py b/modules/createEVENT/stochasticWave/StochasticWave.py index 89c6ea9a0..b02372541 100644 --- a/modules/createEVENT/stochasticWave/StochasticWave.py +++ b/modules/createEVENT/stochasticWave/StochasticWave.py @@ -196,9 +196,9 @@ def readRV(aimFilePath='AIM.json', eventFilePath='EVENT.json'): # noqa: D103, N addFloorForceToEvent( timeSeriesArray, patternsArray, floorForces.X, 'X', floor, deltaT ) - addFloorForceToEvent( - timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT - ) + # addFloorForceToEvent( + # timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT + # ) addFloorPressure(pressureArray, floor) eventDict['Events'].append(event_json) @@ -237,9 +237,9 @@ def writeEVENT(forces, eventFilePath, deltaT=1.0): # noqa: D103, N802, N803 addFloorForceToEvent( timeSeriesArray, patternsArray, floorForces.X, 'X', floor, deltaT ) - addFloorForceToEvent( - timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT - ) + # addFloorForceToEvent( + # timeSeriesArray, patternsArray, floorForces.Y, 'Y', floor, deltaT + # ) addFloorPressure(pressureArray, floor) with open(eventFilePath, 'w', encoding='utf-8') as f: # noqa: PTH123 diff --git a/modules/performFEM/surrogateGP/gpPredict.py b/modules/performFEM/surrogateGP/gpPredict.py index 7eea8ebdd..e73f7df9e 100644 --- a/modules/performFEM/surrogateGP/gpPredict.py +++ b/modules/performFEM/surrogateGP/gpPredict.py @@ -10,8 +10,8 @@ from scipy.stats import lognorm, norm from sklearn.linear_model import LinearRegression -errFileName = os.path.join(os.getcwd(), 'workflow.err') # noqa: N816, PTH109, PTH118 -sys.stderr = open(errFileName, 'a') # noqa: SIM115, PTH123 +# errFileName = os.path.join(os.getcwd(), 'workflow.err') # noqa: N816, PTH109, PTH118 +# sys.stderr = open(errFileName, 'a') # noqa: SIM115, PTH123 try: moduleName = 'GPy' # noqa: N816 diff --git a/modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py b/modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py index 0acad0a3d..4ee257924 100644 --- a/modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py +++ b/modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py @@ -78,10 +78,17 @@ def create_event(asset_file: str, event_grid_file: str, workflow_input: str, do_ # open input file & get Regional Event data # + # candidate paths json_path = os.path.join(os.getcwd(), workflow_input) - with open(json_path, 'r') as f: - data = json.load(f) + if not os.path.exists(json_path): + json_path = os.path.join(os.path.dirname(os.getcwd()), workflow_input) + + if os.path.isfile(json_path): + with open(json_path, 'r') as f: + data = json.load(f) + else: + raise FileNotFoundError(f"Could not find {workflow_input} in current or parent directory") regional_event = data.get("RegionalEvent") diff --git a/modules/performUQ/common/extractEDP.cpp b/modules/performUQ/common/extractEDP.cpp index 5e7b2c2ab..d833a3360 100644 --- a/modules/performUQ/common/extractEDP.cpp +++ b/modules/performUQ/common/extractEDP.cpp @@ -40,7 +40,7 @@ int main(int argc, const char **argv) int numValues = json_array_size(sType); for (int i=0; i #include #include -#include +#include #include using std::string; -using std::vector; +using std::deque; /* ***************** params.in example ****** { DAKOTA_VARS = 2 } @@ -47,14 +47,15 @@ int main(int argc, char **argv) } // - // vectors that will contain strinmgs to search for & their replacement + // deques that will contain strinmgs to search for & their replacement // - vector original; - vector replace; - vector originalLength; - vector replacementLength; - + deque original; + deque replace; + deque originalLength; + deque replacementLength; + deque rvNames; // original string of random variable names + // // from params file, 1) read # of RV and 2) then read RV names and values // @@ -63,6 +64,8 @@ int main(int argc, char **argv) int numRVs = 0; string line; while (getline(params, line)) { + + std::istringstream buf(line); std::istream_iterator beg(buf), end; vector tokens(beg, end); // done! @@ -75,12 +78,35 @@ int main(int argc, char **argv) } else { // subsequent lines contain RV and value .. add to string vectors - string rvName = "\"RV." + tokens.at(1) + "\""; // add SimCenter delimiters begin="RV. & end=" + string rvName = tokens.at(1); // add SimCenter delimiters begin="RV. &\ end=" string rvValue = tokens.at(3); + // check if an existing rvName starts as a substring of current + bool subStringExists = false; + for (size_t i = 0; i < rvNames.size(); ++i) { + const std::string& s1 = rvName[i]; + if (rvName.find(s1) == 0) { + subStringExists = true; + break; // No need to check further if found + } + } + } + + if (subStringExists == false) { + rvNames.push_back(rvName); + rvName = "\"RV." + rvName + "\""; // add SimCenter delimiters begin="RV. &\ end=" original.push_back(rvName); replace.push_back(rvValue); originalLength.push_back(rvName.length()); replacementLength.push_back(rvValue.length()); + + } else { + rvNames.push_front(rvName); + rvName = "\"RV." + rvName + "\""; + replace.push_front(rvValue); + originalLength.push_front(rvName.length()); + replacementLength.push_front(rvValue.length()); + + } // std::cerr << rvName << " " << rvValue << "\n"; }