Skip to content

Commit

Permalink
update front scripts examples 3 4 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrbortolotti committed Jan 2, 2025
1 parent 9a99005 commit 00f02c7
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 118 deletions.
70 changes: 22 additions & 48 deletions examples/03_NREL5MW_OC3_spar/weis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,38 @@
import sys

from weis.glue_code.runWEIS import run_weis
from weis.glue_code.weis_args import weis_args, get_max_procs, set_modopt_procs
from openmdao.utils.mpi import MPI

# Parse args
args = weis_args()

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = os.path.join(run_dir, 'nrel5mw-spar_oc3.yaml')
fname_modeling_options = os.path.join(run_dir, 'modeling_options.yaml')
fname_analysis_options = os.path.join(run_dir, 'analysis_options.yaml')

import argparse
# Set up argument parser
parser = argparse.ArgumentParser(description="Run WEIS driver with flag prepping for MPI run.")
# Add the flag
parser.add_argument("--preMPI", type=bool, default=False, help="Flag for preprocessing MPI settings (True or False).")
parser.add_argument("--maxnP", type=int, default=1, help="Maximum number of processors available.")
# Parse the arguments
args, _ = parser.parse_known_args()
# Use the flag in your script
if args.preMPI:
print("Preprocessor flag is set to True. Running preprocessing setting up MPI run.")
else:
print("Preprocessor flag is set to False. Run WEIS now.")

tt = time.time()
maxnP = get_max_procs(args)

# Set max number of processes, either set by user or extracted from MPI
if args.preMPI:
maxnP = args.maxnP
else:
if MPI:
maxnP = MPI.COMM_WORLD.Get_size()
else:
maxnP = 1

if args.preMPI:
_, _, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)
else:
if MPI:
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = {}
modeling_override['General'] = {}
modeling_override['General']['openfast_configuration'] = {}
modeling_override['General']['openfast_configuration']['nFD'] = modeling_options['General']['openfast_configuration']['nFD']
modeling_override['General']['openfast_configuration']['nOFp'] = modeling_options['General']['openfast_configuration']['nOFp']
else:
modeling_override = None
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override)
modeling_override = None
if MPI:
# Pre-compute number of cores needed in this run
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = set_modopt_procs(modeling_options)

# Run WEIS for real now
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override,
prepMPI=args.preMPI)

if MPI:
rank = MPI.COMM_WORLD.Get_rank()
Expand Down
35 changes: 28 additions & 7 deletions examples/03_NREL5MW_OC3_spar/weis_freq_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@
import sys

from weis.glue_code.runWEIS import run_weis
from weis.glue_code.weis_args import weis_args, get_max_procs, set_modopt_procs
from openmdao.utils.mpi import MPI

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = run_dir + os.sep + "nrel5mw-spar_oc3.yaml"
fname_modeling_options = run_dir + os.sep + "modeling_options_freq.yaml"
fname_analysis_options = run_dir + os.sep + "analysis_options_noopt.yaml"
# Parse args
args = weis_args()

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = os.path.join(run_dir, 'nrel5mw-spar_oc3.yaml')
fname_modeling_options = os.path.join(run_dir, 'modeling_options_freq.yaml')
fname_analysis_options = os.path.join(run_dir, 'analysis_options_noopt.yaml')

tt = time.time()
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input, fname_modeling_options, fname_analysis_options)
maxnP = get_max_procs(args)

modeling_override = None
if MPI:
# Pre-compute number of cores needed in this run
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = set_modopt_procs(modeling_options)

# Run WEIS for real now
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override,
prepMPI=args.preMPI)

if MPI:
rank = MPI.COMM_WORLD.Get_rank()
else:
rank = 0
if rank == 0:
if rank == 0 and args.preMPI == False:
print("Run time: %f"%(time.time()-tt))
sys.stdout.flush()
35 changes: 28 additions & 7 deletions examples/04_NREL5MW_OC4_semi/weis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@
import sys

from weis.glue_code.runWEIS import run_weis
from weis.glue_code.weis_args import weis_args, get_max_procs, set_modopt_procs
from openmdao.utils.mpi import MPI

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = run_dir + os.sep + "nrel5mw-semi_oc4.yaml"
fname_modeling_options = run_dir + os.sep + "modeling_options.yaml"
fname_analysis_options = run_dir + os.sep + "analysis_options.yaml"
# Parse args
args = weis_args()

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = os.path.join(run_dir, 'nrel5mw-semi_oc4.yaml')
fname_modeling_options = os.path.join(run_dir, 'modeling_options.yaml')
fname_analysis_options = os.path.join(run_dir, 'analysis_options.yaml')

tt = time.time()
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input, fname_modeling_options, fname_analysis_options)
maxnP = get_max_procs(args)

modeling_override = None
if MPI:
# Pre-compute number of cores needed in this run
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = set_modopt_procs(modeling_options)

# Run WEIS for real now
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override,
prepMPI=args.preMPI)

if MPI:
rank = MPI.COMM_WORLD.Get_rank()
else:
rank = 0
if rank == 0:
if rank == 0 and args.preMPI == False:
print("Run time: %f"%(time.time()-tt))
sys.stdout.flush()
35 changes: 28 additions & 7 deletions examples/04_NREL5MW_OC4_semi/weis_freq_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@
import sys

from weis.glue_code.runWEIS import run_weis
from weis.glue_code.weis_args import weis_args, get_max_procs, set_modopt_procs
from openmdao.utils.mpi import MPI

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = run_dir + os.sep + "nrel5mw-semi_oc4.yaml"
fname_modeling_options = run_dir + os.sep + "modeling_options_freq.yaml"
fname_analysis_options = run_dir + os.sep + "analysis_options.yaml"
# Parse args
args = weis_args()

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = os.path.join(run_dir, 'nrel5mw-semi_oc4.yaml')
fname_modeling_options = os.path.join(run_dir, 'modeling_options_freq.yaml')
fname_analysis_options = os.path.join(run_dir, 'analysis_options.yaml')

tt = time.time()
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input, fname_modeling_options, fname_analysis_options)
maxnP = get_max_procs(args)

modeling_override = None
if MPI:
# Pre-compute number of cores needed in this run
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = set_modopt_procs(modeling_options)

# Run WEIS for real now
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override,
prepMPI=args.preMPI)

if MPI:
rank = MPI.COMM_WORLD.Get_rank()
else:
rank = 0
if rank == 0:
if rank == 0 and args.preMPI == False:
print("Run time: %f"%(time.time()-tt))
sys.stdout.flush()
72 changes: 23 additions & 49 deletions examples/05_IEA-3.4-130-RWT/weis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,39 @@
import time
import sys

from weis.glue_code.runWEIS import run_weis
from weis.glue_code.runWEIS import run_weis
from weis.glue_code.weis_args import weis_args, get_max_procs, set_modopt_procs
from openmdao.utils.mpi import MPI

# Parse args
args = weis_args()

## File management
run_dir = os.path.dirname( os.path.realpath(__file__) )
fname_wt_input = os.path.join(run_dir, 'IEA-3p4-130-RWT.yaml')
fname_modeling_options = os.path.join(run_dir, 'modeling_options.yaml')
fname_analysis_options = os.path.join(run_dir, 'analysis_options.yaml')

import argparse
# Set up argument parser
parser = argparse.ArgumentParser(description="Run WEIS driver with flag prepping for MPI run.")
# Add the flag
parser.add_argument("--preMPI", type=bool, default=False, help="Flag for preprocessing MPI settings (True or False).")
parser.add_argument("--maxnP", type=int, default=1, help="Maximum number of processors available.")
# Parse the arguments
args, _ = parser.parse_known_args()
# Use the flag in your script
if args.preMPI:
print("Preprocessor flag is set to True. Running preprocessing setting up MPI run.")
else:
print("Preprocessor flag is set to False. Run WEIS now.")

tt = time.time()
maxnP = get_max_procs(args)

# Set max number of processes, either set by user or extracted from MPI
if args.preMPI:
maxnP = args.maxnP
else:
if MPI:
maxnP = MPI.COMM_WORLD.Get_size()
else:
maxnP = 1

if args.preMPI:
_, _, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)
else:
if MPI:
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = {}
modeling_override['General'] = {}
modeling_override['General']['openfast_configuration'] = {}
modeling_override['General']['openfast_configuration']['nFD'] = modeling_options['General']['openfast_configuration']['nFD']
modeling_override['General']['openfast_configuration']['nOFp'] = modeling_options['General']['openfast_configuration']['nOFp']
else:
modeling_override = None
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override)
modeling_override = None
if MPI:
# Pre-compute number of cores needed in this run
_, modeling_options, _ = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
prepMPI=True,
maxnP = maxnP)

modeling_override = set_modopt_procs(modeling_options)

# Run WEIS for real now
wt_opt, modeling_options, opt_options = run_weis(fname_wt_input,
fname_modeling_options,
fname_analysis_options,
modeling_override=modeling_override,
prepMPI=args.preMPI)

if MPI:
rank = MPI.COMM_WORLD.Get_rank()
Expand Down

0 comments on commit 00f02c7

Please sign in to comment.