def main(fullDir, subDir): print("") print('\033[95m' + '\033[1m' + "NCSU Subdomain Modeling for ADCIRC+SWAN" + '\033[0m') print("") print("Generating input files for the subdomain at", subDir) # Initialize the full and subdomains full = Domain(fullDir) sub = Domain(subDir) # Read subdomain shape file: shape = SubShape(sub.dir) # Extract fort.14: if not os.path.exists(full.dir + "fort.14"): print("ERROR: No fort.14 file exists at", full.dir) exit() else: extractFort14(full, sub, shape) # Extract fort.13: if os.path.exists(full.dir + "fort.13"): extractFort13(full, sub) # Generate fort.015: writeFort015(sub) # Generate py.140 and py.141 writeNewToOld(sub) # Copy SWAN input files if full.isCoupledAdcircSwan(): copySwanFiles(full, sub) # The final log message: print("\nSubdomain input files are now ready.") print('\033[91m' + "\nImportant Note:" + '\033[0m') print("fort.15 and meteorological files have to be generated manually ") print("by the user as described in Subdomain Modeling User Guide.\n")
def remap( full_dir, sub_dir, py140=None ): full = Domain( full_dir ) sub = Domain( sub_dir ) full.readFort14() sub.readFort14() sub.readPy140() print '\t Creating new nodal map' full_map = map_nodal_location(full.nodes) sub_boundaries = set( sub.nbdv ) sub_nodes = [(i, sub.nodes[i]) for i in sub_boundaries] map_to_refined = [] for i, node in sub_nodes: try: full_node = find_mapping( full_map, node ) map_to_refined.append((full_node, i)) except NoMatchError: print 'Unable to find match for node ' + str(i) print 'EXITING - Remapping unsuccessful' exit() if py140 is None: outfile = sub.dir + 'py.140' else: outfile = py140 with open( outfile, 'w' ) as f: f.write('new to old\n') for old, new in map_to_refined: f.write(str(new) + '\t' + str(old) + '\n')
def getSubdomains(): subdomains = [] subDirs = [] while True: # Get the subdomain directory: subDir = raw_input('Enter the directory of a subdomain ' + '(Type "done" when finished):\n') # Check if the user is done: if subDir.lower() == "done" or subDir.lower() == '"done"': print "\nThe following subdomains are added: " for sub in subdomains: print " ", sub.dir break # Format the subdomain directory entered by the user: if len(subDir) == 0: continue else: subDir = subDir.strip() if not subDir[-1] == '/': subDir = subDir + '/' # Check if the subdomain is added before: if subDir in subDirs: print "The subdomain at", subDir, "is already added!" continue # Check if the subdomain directory is valid: if not os.path.exists(subDir): print '\033[91m' + "\nWARNING:" + '\033[0m' print "Subdomain is NOT added! The directory " + subDir + " does not exist." continue # Read the input files: try: sub = Domain(subDir) sub.readFort14() sub.readPy140() subdomains.append(sub) except IOError: print "\nERROR: Couldn't read the input files (fort.14 and py.140 ) of" print " the subdomain at", sub.dir print "Exiting..." exit() subDirs.append(subDir) # Check if any subdomain is added: if len(subdomains) == 0: print "\nERROR: No subdomain has been added!\nExiting...\n" exit() return subdomains
def main(fullColdDir, fullHotDir, subdir, sbtiminc): # Print header: print "" print '\033[95m'+'\033[1m'+"NCSU Subdomain Modeling for ADCIRC+SWAN"+'\033[0m' print "" print "Generating ADCIRC boundary conditions files for the subdomain at",subdir,"\n" # Instantiate and prepare the full domains: fullCold = Domain(fullColdDir) fullHot = Domain(fullHotDir) prepFull(fullCold) prepFull(fullHot) # Instantiate and prepare the subdomain: sub = Domain(subdir) sub.readFort14() sub.readPy140() # Check whether full domains are inconsistent checkFullDomains(fullCold, fullHot) # Convert sbtiminc to integer if sbtiminc==None: sbtiminc = fullCold.nspoolgs else: sbtiminc = int(sbtiminc) # Check if sbtiminc is a multiple of NSPOOLGS: if not (sbtiminc%fullCold.nspoolgs == 0): print '\033[91m'+"\nWARNING!"+'\033[0m' print "The parameter sbtiminc (="+str(sbtiminc)+") is not a multiple of "+\ "the full domain parameter nspoolgs (="+str(fullCold.nspoolgs)+")" print "Setting sbtiminc to",fullCold.nspoolgs sbtiminc = fullCold.nspoolgs print "\n\t Writing fort.019 at",sub.dir,"\n" # Open subdomain b.c. file: sub.openFort019(sbtiminc,(fullCold.nrtimesteps+fullHot.nrtimesteps) ) # First, write the boundary conditions from the cold started full domain: print "\n\tWriting boundary conditions from cold-started full domain...\n" if fullCold.runtype=="s": for i in range(fullCold.nrtimesteps): fullCold.readFort065() sub.writeFort019(fullCold) #print out percentage if i%1000==0: sys.stdout.write('\r') sys.stdout.write("%d%%" %(100*(i+1)/fullCold.nrtimesteps)) sys.stdout.flush() else: for i in range(fullCold.nrtimesteps): fullCold.readFort065_parallel() if i==0: sub.createProcMapping(fullCold) sub.writeFort019_parallel(fullCold) #print out percentage if i%1000==0: sys.stdout.write('\r') sys.stdout.write("%d%%" %(100*(i+1)/fullCold.nrtimesteps)) sys.stdout.flush() sys.stdout.write('\r') sys.stdout.write("100%") sys.stdout.flush() print "\n\tWriting boundary conditions from hot-started full domain...\n" if fullHot.runtype=="s": for i in range(fullHot.nrtimesteps): fullHot.readFort065() sub.writeFort019(fullHot) #print out percentage if i%1000==0: sys.stdout.write('\r') sys.stdout.write("%d%%" %(100*(i+1)/fullHot.nrtimesteps)) sys.stdout.flush() sub.writeFort019(fullHot) else: for i in range(fullHot.nrtimesteps): fullHot.readFort065_parallel() if i==0: sub.createProcMapping(fullHot) sub.writeFort019_parallel(fullHot) #print out percentage if i%1000==0: sys.stdout.write('\r') sys.stdout.write("%d%%" %(100*(i+1)/fullHot.nrtimesteps)) sys.stdout.flush() sub.writeFort019_parallel(fullHot) sys.stdout.write('\r') sys.stdout.write("100%") sys.stdout.flush() sub.fort019.close() print "\n\nADCIRC boundary conditions for the subdomain at",sub.dir,"are now ready.\n" if fullCold.isCoupledAdcircSwan(): print '\033[91m'+"\nImportant Note:"+'\033[0m' print "After preprocessing the subdomain using adcprep, run genbcs4swan.py script" print "to generate SWAN b.c. files."
def main(fulldir, subdir, sbtiminc): # Print header: print "" print '\033[95m' + '\033[1m' + "NCSU Subdomain Modeling for ADCIRC+SWAN" + '\033[0m' print "" print "Generating ADCIRC boundary conditions files for the subdomain at", subdir, "\n" # Instantiate the domains: full = Domain(fulldir) sub = Domain(subdir) # Get the runtype runtype = "s" isSerialRun = os.path.exists(full.dir + "fort.065") isParallelRun = os.path.exists(full.dir + "PE0000/fort.065") if isSerialRun and (not isParallelRun): runtype = "s" elif isParallelRun and (not isSerialRun): runtype = "p" else: while True: runtype = raw_input('Enter the type of the full domain run '+ \ '("p" for parallel, or "s" for serial):\n') if runtype == 'p' or runtype == 's': break elif runtype == '"p"': runtype = 'p' break elif runtype == '"s"': runtype = 's' break else: print '\033[91m' + "\nInvalid key!" + '\033[0m' # Read input files: full.readFort14() if runtype == "p": full.readFort80() sub.readFort14() sub.readPy140() # Open full domain fort.065 if runtype == "s": full.openFort065() else: full.openFort065_parallel() # Convert sbtiminc to integer if sbtiminc == None: sbtiminc = full.nspoolgs else: sbtiminc = int(sbtiminc) # Check if sbtiminc is a multiple of NSPOOLGS: if not (sbtiminc % full.nspoolgs == 0): print '\033[91m' + "\nWARNING!" + '\033[0m' print "The parameter sbtiminc (="+str(sbtiminc)+") is not a multiple of "+\ "the full domain parameter nspoolgs (="+str(full.nspoolgs)+")" print "Setting sbtiminc to", full.nspoolgs sbtiminc = full.nspoolgs print "\n\t Writing fort.019 at", sub.dir, "\n" # Open subdomain b.c. file: sub.openFort019(sbtiminc, full.nrtimesteps) # Write the boundary conditions: if runtype == "s": for i in range(full.nrtimesteps): full.readFort065() sub.writeFort019(full) #print out percentage if i % 1000 == 0: sys.stdout.write('\r') sys.stdout.write("%d%%" % (100 * (i + 1) / full.nrtimesteps)) sys.stdout.flush() sub.writeFort019(full) else: for i in range(full.nrtimesteps): full.readFort065_parallel() if i == 0: sub.createProcMapping(full) sub.writeFort019_parallel(full) #print out percentage if i % 1000 == 0: sys.stdout.write('\r') sys.stdout.write("%d%%" % (100 * (i + 1) / full.nrtimesteps)) sys.stdout.flush() sub.writeFort019_parallel(full) sys.stdout.write('\r') sys.stdout.write("100%") sys.stdout.flush() sub.fort019.close() print "\n\nADCIRC boundary conditions for the subdomain at", sub.dir, "are now ready.\n" if full.isCoupledAdcircSwan(): print '\033[91m' + "\nImportant Note:" + '\033[0m' print "After preprocessing the subdomain using adcprep, run genbcs4swan.py script" print "to generate SWAN b.c. files."
def main(fulldir): print "" print '\033[95m' + '\033[1m' + "NCSU Subdomain Modeling for ADCIRC+SWAN" + '\033[0m' print "" print "Preparing the full domain at", fulldir, "for an ADCIRC run.\n" full = Domain(fulldir) # Remove the existing fort.015: if os.path.exists(full.dir + "fort.015"): os.remove(full.dir + "fort.015") # Determine the list of nodes to be recorded for subdomain boundary conditions: subdomains = [] predetermine = None while True: predetermine = raw_input( "Specify predefined subdomains? (y or n). [Default: y] \n") if predetermine.lower() == 'y' or predetermine.lower() == 'n': break elif len(predetermine) == 0: predetermine = 'y' break else: print "Invalid key:", predetermine, "\n" if predetermine == 'y': # Get the list of predetermined subdomains from CLI: subdomains = getSubdomains() else: # Record all of the full domain nodes: print '\033[91m' + "\nWARNING:" + '\033[0m' print "If no predefined subdomain is provided, full domain ADCIRC run will" print "record ALL nodes to provide boundary conditions for any future subdomain." print "This will require substantial amount of resources." while True: cont = raw_input("\nContinue? (y or n):\n") if len(cont) > 0 and cont.lower() == 'y': break elif len(cont) > 0 and cont.lower() == 'n': print "Exiting..." exit() else: print "Invalid key:", cont, "\n" # nspoolgs: the number of timesteps at which subdomain boundary conditions are to be recorded: nspoolgs = raw_input( "\nEnter NSPOOLGS (no. of timesteps at which b.c. are to be recorded)." " [Default=100]:\n") try: nspoolgs = str(int(nspoolgs)) except: nspoolgs = str(100) print "NSPOOLGS is set to 100.\n" # Read full fort.14 full.readFort14() # Generate a new fort.015 file writeFort015(full, nspoolgs, subdomains) # If an ADCIRC+SWAN run, make additional adjustments: if full.isCoupledAdcircSwan(): # Write SWAN b.c. recording stations list file writeSwanStationsFile(full, subdomains) # Modify fort26 (SWAN control file): modifyFort26(full, subdomains) # The final log message: print "\nThe full domain is now ready." # Check if the full domain is coupled and preprocessed: if full.isCoupledAdcircSwan() and full.isPartitioned(): print '\033[91m' + "\nImportant Note:" + '\033[0m' print "The full domain is previously preprocessed. Re-run adcprep to make sure "+\ "that partitioned fort.26 files are up-to-date.\n" # Check if fort.15 has subdomainModeling namespace: full15 = open(full.dir + "fort.15") subNamespace = False for line in full15: if line.split()[0].lower() == "&subdomainmodeling": subNamespace = True break full15.close() if not subNamespace: print '\033[91m' + "WARNING:" + '\033[0m' print "Full domain fort.15 file does not include subdomainModeling namespace." print "Add the following line to the end of fort.15 file to activate subdomain modeling:" print "&subdomainModeling subdomainOn=T /" print ""