Beispiel #1
0
def Initialize(params_loc=None):
    """
    This function initialized the windse parameters.

    Parameters
    ----------
        params_loc : str
            the location of the parameter yaml file.

    Returns
    -------
        params : windse.Parameters
            an overloaded dict containing all parameters.
    """
    parser = argparse.ArgumentParser(
        usage="windse run [options] params",
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument(
        "params",
        nargs='?',
        help='path to yaml file containing the WindSE parameters')
    parser.add_argument(
        '-p',
        dest='updated_parameters',
        action='append',
        default=[],
        help='use this to override a parameter in the yaml file')
    args, unknown = parser.parse_known_args()

    if params_loc is None:
        ### Check if parameters was provided ###
        if args.params is None:
            params_loc = "params.yaml"
            print("Using default parameter location: ./params.yaml")
        else:
            params_loc = args.params
            print("Using parameter location: " + params_loc)

    ### Initialize WindSE ###
    windse.initialize(params_loc, updated_parameters=args.updated_parameters)

    params = windse.windse_parameters

    return params
Beispiel #2
0
params["general"]["name"] = "Box_Domain_Test"

### Set Box Parameters ###
Lx = 1000.0
Ly = 1000.0
Lz = 500
params["domain"]["type"] = "box"
params["domain"]["x_range"] = [-Lx, Lx]
params["domain"]["y_range"] = [-Ly, Ly]
params["domain"]["z_range"] = [0.0, Lz]
params["domain"]["nx"] = 24
params["domain"]["ny"] = 24
params["domain"]["nz"] = 6

### Initialize Parameters using those set above ###
windse.initialize(params)

### Create the Domain Object ###
dom = windse.BoxDomain()

### Check if the object is as expected ###
dom.Save()

### Create unit for integration ###
V = FiniteElement('Lagrange', dom.mesh.ufl_cell(), 1)
V = FunctionSpace(dom.mesh, V)
u = Function(V)
u.vector()[:] = 1.0


### Calculate inflow integral ###
Beispiel #3
0
params = windse.windse_parameters

### Set General Parameters ###
params["general"]["name"] = "Circle_Domain_Test"

### Set Box Parameters ###
radius = 1200
params["domain"]["type"] = "circle"
params["domain"]["mesh_type"] = "mshr"
params["domain"]["radius"] = radius
params["domain"]["center"] = [0.0, 0.0]
params["domain"]["nt"] = 100
params["domain"]["res"] = 100

### Initialize Parameters using those set above ###
windse.initialize(None)

### Create the Domain Object ###
dom = windse.CircleDomain()

### Check if the object is as expected ###
dom.Save()

### Check the number of verts and cells ###
if dom.mesh.num_cells() != 39300:
    raise ValueError(
        "Box domain constructed with unexpected number of cells: " +
        repr(dom.mesh.num_cells()))
if dom.mesh.num_vertices() != 19865:
    raise ValueError(
        "Box domain constructed with unexpected number of vertices: " +
Beispiel #4
0
from dolfin import *
from dolfin_adjoint import *
import windse
import numpy as np

parameters['form_compiler']['quadrature_degree'] = 6
set_log_level(20)

### Create an Instance of the Options ###
options = windse.initialize("params3Dterrain.yaml")

### Generate Domain ###
dom = windse.ImportedDomain()
# dom = windse.BoxDomain()

### Generate Wind Farm ###
farm = windse.GridWindFarm(dom)
# farm = windse.RandomWindFarm(dom)

# farm.Plot(False)

### Warp the mesh and refine ###
# dom.Warp(200,0.75)
region = [[-1000, 1500], [-1000, 1000], [0, 300]]
dom.Refine(1, region=region)
# dom.Save()

print(len(dom.mesh.coordinates()[:]))
print(len(farm.dom.mesh.coordinates()[:]))
print(print(farm.dom.mesh.hmin()))
# exit()
Beispiel #5
0
import windse

### Initialize WindSE ###
windse.initialize("params.yaml")

### Generate Domain ###
dom = windse.BoxDomain()
dom.Save()

### Generate Wind Farm ###
farm = windse.RandomWindFarm(dom)
farm.Plot(False)

### Function Space ###
fs = windse.LinearFunctionSpace(dom)

### Setup Boundary Conditions ###
bc = windse.PowerInflow(dom,fs)

### Generate the problem ###
problem = windse.StabilizedProblem(dom,farm,fs,bc)

### Solve ###
solver = windse.SteadySolver(problem)
solver.Solve()

### Output Results ###
solver.Save()
solver.Plot()
Beispiel #6
0
from dolfin import *
from dolfin_adjoint import *
import windse
import numpy as np
import inspect

parameters['form_compiler']['quadrature_degree'] = 6
set_log_level(20)

### Create an Instance of the Options ###
options = windse.initialize("GOparams.yaml")

### Generate Domain ###
dom = windse.ImportedDomain()

### Generate Wind Farm ###
farm = windse.GridWindFarm(dom)
farm.Plot(False)

### Warp the mesh and refine ###
region = [[-1000, 1500], [-1000, 1000], [0, 300]]
# dom.Refine(1)
dom.Refine(1, region=region)
dom.Save()

### Function Space ###
fs = windse.LinearFunctionSpace(dom)

### Setup Boundary Conditions ###
bc = windse.PowerInflow(dom, fs)
Beispiel #7
0
from dolfin import *
from dolfin_adjoint import *
import windse
import numpy as np

parameters['form_compiler']['quadrature_degree'] = 6
set_log_level(20)

### Initialize WindSE ###
windse.initialize("params_small.yaml")

### Generate Domain ###
dom = windse.BoxDomain()

### Generate Wind Farm ###
# farm = windse.RandomWindFarm(dom)
farm = windse.GridWindFarm(dom)

# farm.Plot(False)

dom.Warp(250,0.75)
region = [farm.ex_x,farm.ex_y,[0,250]]
dom.Refine(1,region=region)
# dom.Save()

### Refine Around the Turbines
farm.RefineTurbines(num=1,radius_multiplyer=1.3) 

### Function Space ###
fs = windse.LinearFunctionSpace(dom)
Beispiel #8
0
def run_action(params_loc=None):
    tick = time.time()

    ### unload windse if previously loaded ###
    if "windse" in sys.modules.keys():
        del sys.modules["windse"]
        mods_to_remove = []
        for k in sys.modules.keys():
            if "windse." in k:
                mods_to_remove.append(k)
        for i in range(len(mods_to_remove)):
            del sys.modules[mods_to_remove[i]]

    import windse

    parser = argparse.ArgumentParser(
        usage="windse run [options] params",
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument(
        "params",
        nargs='?',
        help='path to yaml file containing the WindSE parameters')
    parser.add_argument(
        '-p',
        dest='updated_parameters',
        action='append',
        default=[],
        help='use this to override a parameter in the yaml file')
    args, unknown = parser.parse_known_args()

    if params_loc is None:
        ### Check if parameters was provided ###
        if args.params is None:
            params_loc = "params.yaml"
            print("Using default parameter location: ./params.yaml")
        else:
            params_loc = args.params
            print("Using parameter location: " + params_loc)

    ### Initialize WindSE ###
    windse.initialize(params_loc, updated_parameters=args.updated_parameters)

    params = windse.windse_parameters

    ### Setup the Domain ###
    if params["domain"].get("interpolated", False):
        dom_dict = {
            "box": windse.InterpolatedBoxDomain,
            "cylinder": windse.InterpolatedCylinderDomain
        }
    else:
        dom_dict = {
            "box": windse.BoxDomain,
            "rectangle": windse.RectangleDomain,
            "cylinder": windse.CylinderDomain,
            "circle": windse.CircleDomain,
            "imported": windse.ImportedDomain
        }
    dom = dom_dict[params["domain"]["type"]]()

    ### Setup the Wind farm ###
    farm_dict = {
        "grid": windse.GridWindFarm,
        "random": windse.RandomWindFarm,
        "imported": windse.ImportedWindFarm
    }
    farm = farm_dict[params["wind_farm"]["type"]](dom)
    farm.Plot(params["wind_farm"].get("display", False))

    ### Move and refine the mesh
    if "refine" in params.keys():
        warp_type = params["refine"].get("warp_type", None)
        warp_strength = params["refine"].get("warp_strength", None)
        warp_height = params["refine"].get("warp_height", None)
        warp_percent = params["refine"].get("warp_percent", None)
        farm_num = params["refine"].get("farm_num", 0)
        farm_type = params["refine"].get("farm_type", "square")
        farm_factor = params["refine"].get("farm_factor", 1.0)
        farm_radius = params["refine"].get("farm_radius", None)
        refine_custom = params["refine"].get("refine_custom", None)
        turbine_num = params["refine"].get("turbine_num", 0)
        turbine_factor = params["refine"].get("turbine_factor", 1.0)

        if warp_type == "smooth":
            dom.WarpSmooth(warp_strength)
        elif warp_type == "split":
            dom.WarpSplit(warp_height, warp_percent)

        if refine_custom is not None:
            for refine_data in refine_custom:
                if refine_data[1] == "full":
                    dom.Refine(refine_data[0])
                else:
                    region = farm.CalculateFarmRegion(refine_data[1],
                                                      length=refine_data[2])
                    dom.Refine(refine_data[0],
                               region=region,
                               region_type=refine_data[1])

        if farm_num > 0:
            region = farm.CalculateFarmRegion(farm_type,
                                              farm_factor,
                                              length=farm_radius)
            dom.Refine(farm_num, region=region, region_type=farm_type)

        if turbine_num > 0:
            farm.RefineTurbines(turbine_num, turbine_factor)

    ### Finalize the Domain ###
    dom.Finalize()

    # dom.Save()
    # exit()
    ### Function Space ###
    func_dict = {
        "linear": windse.LinearFunctionSpace,
        "taylor_hood": windse.TaylorHoodFunctionSpace
    }
    fs = func_dict[params["function_space"]["type"]](dom)

    # dom.Save()
    # exit()

    ### Setup Boundary Conditions ###
    bc_dict = {
        "uniform": windse.UniformInflow,
        "power": windse.PowerInflow,
        "log": windse.LogLayerInflow
    }
    bc = bc_dict[params["boundary_condition"]["vel_profile"]](dom, fs, farm)

    ### Generate the problem ###
    prob_dict = {
        "stabilized": windse.StabilizedProblem,
        "taylor_hood": windse.TaylorHoodProblem
    }
    problem = prob_dict[params["problem"]["type"]](dom, farm, fs,
                                                   bc)  #,opt=opt)

    ### Solve ###
    solve_dict = {
        "steady": windse.SteadySolver,
        "multiangle": windse.MultiAngleSolver,
        "importedvelocity": windse.TimeSeriesSolver
    }
    solver = solve_dict[params["solver"]["type"]](problem)
    solver.Solve()

    # import dolfin_adjoint as da
    # tape = da.get_working_tape()
    # tape.visualise()
    # exit()

    ### Perform Optimization ###
    if params.get("optimization", {}):
        opt = windse.Optimizer(solver)
        if params["optimization"].get("taylor_test", False):
            opt.TaylorTest()

        if params["optimization"].get("optimize", True):
            opt.Optimize()

        if params["optimization"].get("gradient", True):
            opt.Gradient()

    tock = time.time()
    runtime = tock - tick
    print("Run Complete: {:1.2f} s".format(runtime))

    return runtime