Exemple #1
0
# Loop over mesh hierarchy
for level in range(num_levels):

    # Solve PDE
    op = PointDischarge2dOptions(level=level, aligned=True)
    op.tracer_family = args.family
    stabilisation = args.stabilisation or 'supg'
    op.stabilisation_tracer = None if stabilisation == 'none' else stabilisation
    op.anisotropic_stabilisation = False if args.anisotropic_stabilisation == '0' else True
    tp = AdaptiveSteadyProblem(op)
    tp.solve_forward()

    # Print element count
    num_cells.append(tp.mesh.num_cells())
    dofs.append(tp.mesh.num_vertices())
    print_output("\nMesh {:d} in the hierarchy".format(level + 1))
    print_output("    Number of elements  : {:d}".format(num_cells[-1]))

    # Evaluate QoI in aligned case
    qois['aligned'].append(tp.quantity_of_interest())
    print_output("    Aligned QoI: {:.5f}".format(qois['aligned'][-1]))
    qois_exact['aligned'].append(op.analytical_qoi())
    print_output("    (Exact     : {:.5f})".format(qois_exact['aligned'][-1]))

    # Evaluate QoI in offset case
    op.__init__(level=level, aligned=False)
    qois['offset'].append(tp.quantity_of_interest())
    print_output("    Offset QoI : {:.5f}".format(qois['offset'][-1]))
    qois_exact['offset'].append(op.analytical_qoi())
    print_output("    (Exact     : {:.5f})".format(qois_exact['offset'][-1]))
Exemple #2
0
# Get filenames
ext = family
if ext == 'dg':
    if stabilisation in ('lf', 'LF', 'lax_friedrichs'):
        ext += '_lf'
else:
    if stabilisation in ('su', 'SU'):
        ext += '_su'
    if stabilisation in ('supg', 'SUPG'):
        ext += '_supg'
    if anisotropic_stabilisation:
        ext += '_anisotropic'
approach = args.approach or 'dwr'
if approach == 'fixed_mesh':
    print_output("Nothing to run.")
    sys.exit(0)
elif 'isotropic_dwr' in approach:
    ext += '_{:.0f}'.format(alpha)
else:
    ext += '_inf' if p == 'inf' else '_{:.0f}'.format(p)
fname = 'qoi_{:s}'.format(ext)

both = approach == 'dwr_both' or 'int' in approach or 'avg' in approach
adjoint = 'adjoint' in approach or both
kwargs = {
    'level': level,

    # QoI
    'aligned': not offset,
Exemple #3
0
ramp_dir = create_directory(os.path.join(data_dir, "ramp"))
data_dir = create_directory(os.path.join(data_dir, approach, index_str))
op.spun = np.all([
    os.path.isfile(os.path.join(ramp_dir, f + ".h5"))
    for f in ('velocity', 'elevation')
])
sea_water_density = 1030.0
power_watts = [np.array([]) for i in range(15)]
if op.spun:
    for i, turbine in enumerate(op.farm_ids):
        fname = os.path.join(ramp_dir,
                             "power_output_{:d}_00000.npy".format(turbine))
        power_watts[i] = np.append(power_watts[i],
                                   np.load(fname) * sea_water_density)
else:
    print_output("Spin-up data not found. Spinning up now.")
    op.end_time += op.T_ramp

# --- Run model

# Create solver object
swp = AdaptiveTurbineProblem(op,
                             callback_dir=data_dir,
                             ramp_dir=ramp_dir,
                             load_mesh=load_mesh)

# Plot bathymetry and viscosity
swp.bathymetry_file.write(swp.bathymetry[0])
File(os.path.join(op.di,
                  "viscosity.pvd")).write(swp.fields[0].horizontal_viscosity)

# --- Run model

# Run forward model and save QoI timeseries
if not plot_only:
    if not op.spun:
        raise ValueError("Please spin up the simulation before applying mesh adaptation.")
    swp = AdaptiveTurbineProblem(op, meshes=load_mesh, callback_dir=op.di, ramp_dir=ramp_dir)

    # Solve forward problem
    cpu_timestamp = perf_counter()
    swp.run_hessian_based(save_mesh=True)
    cpu_time = perf_counter() - cpu_timestamp
    msg = "Total CPU time: {:.1f} seconds / {:.1f} minutes / {:.3f} hours"
    print_output(msg.format(cpu_time, cpu_time/60, cpu_time/3600))
    print_output("Average power output of array: {:.1f}W".format(swp.average_power_output()))

# Do not attempt to plot in parallel
nproc = COMM_WORLD.size
if nproc > 1:
    msg = "Will not attempt to plot with {:d} processors. Run again in serial flagging -plot_only."
    print_output(msg.format(nproc))
    sys.exit(0)
elif not plot_any:
    sys.exit(0)
plt.rc('font', **{'size': 18})

# Adjust timeseries to account for density of water and assemble as an array
power_watts = [np.array([]) for i in range(15)]
for i, turbine in enumerate(op.farm_ids):
    swp.transfer_forward_solution(i)

    # Checkpoint solution at start of mesh iteration
    swp.save_to_checkpoint(swp.fwd_solutions[i], mode=mode)
    if i == swp.num_meshes-1:
        continue

    # Create forward solver
    swp.setup_solver_forward_step(i)

    # Solve forward problem
    cpu_timestamp = perf_counter()
    swp.solve_forward_step(i)
    cpu_time = perf_counter() - cpu_timestamp
    msg = "CPU time for forward solve {:d}: {:.1f} seconds / {:.1f} minutes / {:.3f} hours"
    print_output(msg.format(i, cpu_time, cpu_time/60, cpu_time/3600))
    average_power = swp.quantity_of_interest()
    print_output("Average power output of array: {:.1f}W".format(average_power))

    # Free forward solver
    swp.free_solver_forward_step(i)

if not spun:
    op.end_time -= op.T_ramp


# --- Adjoint solve

swp.checkpointing = True
for i in reversed(range(swp.num_meshes)):