示例#1
0
def solve(r):
    """
    Solve the tracer transport problem for a given source radius.
    """
    tp = AdaptiveSteadyProblem(op, print_progress=False)
    tp.set_initial_condition()
    tp.fields[0].tracer_source_2d = set_tracer_source(r)
    tp.setup_solver_forward_step(0)
    tp.solve_forward_step(0)
    return tp.fwd_solution_tracer
示例#2
0
    os.path.join(os.path.dirname(__file__), 'outputs', 'fixed_mesh', 'hdf5'))
qois = {'aligned': [], 'offset': []}
num_cells = []
dofs = []
qois_exact = {'aligned': [], 'offset': []}

# 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
示例#3
0
args = parser.parse_args()

# Set parameters
family = args.family or 'cg'
assert family in ('cg', 'dg')
kwargs = {
    'level': int(args.level or 0),
    'plot_pvd': False,
    'debug': bool(args.debug or False),
}
op = PointDischarge2dOptions(approach='fixed_mesh', **kwargs)
op.tracer_family = family
op.stabilisation_tracer = args.stabilisation
op.anisotropic_stabilisation = bool(args.anisotropic_stabilisation or False)
op.di = os.path.join(op.di, args.stabilisation or args.family)

# Get analytical solution
tp = AdaptiveSteadyProblem(op)
analytical = op.analytical_solution(tp.Q[0])

# Plot
fig, axes = plt.subplots(figsize=(8, 3))
levels = np.linspace(0, 3, 50)
tc = tricontourf(analytical, axes=axes, levels=levels, cmap='coolwarm')
cbar = fig.colorbar(tc, ax=axes, orientation="horizontal", pad=0.1)
cbar.set_ticks(np.linspace(0, 3, 7))
axes.set_xticks(np.linspace(0, 50, 6))
axes.xaxis.tick_top()
axes.set_yticks(np.linspace(0, 10, 3))
savefig("analytical_solution", op.di, extensions=["jpg"])
示例#4
0
from firedrake import *

from time import perf_counter

from adapt_utils.steady.solver import AdaptiveSteadyProblem
from adapt_utils.steady.test_cases.point_discharge2d.options import PointDischarge2dOptions

# Solve forward problem
op = PointDischarge2dOptions(approach='dwr', level=2)
op.tracer_family = 'cg'  # TODO: 'dg'
op.stabilisation_tracer = 'supg'  # TODO: 'lax_friedrichs'
op.anisotropic_stabilisation = True  # TODO: False
tp = AdaptiveSteadyProblem(op)
tp.solve_forward()

# Compute error
c = op.analytical_solution(tp.Q[0])
c_h = tp.fwd_solution_tracer
e = c.copy(deepcopy=True)
e -= c_h

# Evaluate QoI and create effectivity index function
Je = assemble(op.set_qoi_kernel(op.default_mesh) * e * dx(degree=12))
I_eff = lambda eta: abs(eta / Je)

# TODO: Global enrichment using hp-refinement
# tic = perf_counter()
# GE_hp_indicator = tp.dwr_indicator('tracer', mode='GE_hp')
# GE_hp = tp.estimators['dwr'][0]
# GE_hp_time = perf_counter() - tic
示例#5
0
    'level': int(args.level or 1),
    'aligned': not offset,
    'plot_pvd': False,
    'debug': bool(args.debug or 0),
}
methods = ('GE_hp', 'GE_h', 'GE_p', 'DQ')
assert args.enrichment_method in methods
plot_dir = create_directory('plots')
op = PointDischarge2dOptions(**kwargs)
op.tracer_family = 'cg'
op.stabilisation_tracer = 'supg'
op.anisotropic_stabilisation = True
op.enrichment_method = args.enrichment_method

# Evaluate error indicator field
tp = AdaptiveSteadyProblem(op, print_progress=False)
tp.solve_forward()
tp.solve_adjoint()
tp.indicate_error('tracer')
minpower = -15
maxpower = -3
minvalue = 1.0001*10**minpower
maxvalue = 0.9999*10**maxpower
indicator = interpolate(min_value(max_value(tp.indicator[op.enrichment_method], minvalue), maxvalue), tp.P0[0])
indicator.dat.data[:] = np.log10(indicator.dat.data)
powers = np.linspace(minpower, maxpower, 50)

# Plot indicator field
fig, axes = plt.subplots(figsize=(8, 2.5))
tc = tricontourf(indicator, axes=axes, levels=powers, cmap='coolwarm')
axes.set_xticks([])
    'debug': bool(args.debug or False),
}
op = PointDischarge2dOptions(approach='fixed_mesh', **kwargs)
op.tracer_family = 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
alignment = 'offset' if offset else 'aligned'
op.di = create_directory(os.path.join(op.di, op.stabilisation_tracer or family, alignment))

# TODO: Limiters?


# --- Solve forward

tp = AdaptiveSteadyProblem(op, print_progress=False)
n = FacetNormal(tp.mesh)
D = tp.fields[0].horizontal_diffusivity
h = D.copy(deepcopy=True)
h.assign(0.1)

timestamp = perf_counter()
tp.solve_forward()
myprint("{:.4f}".format(perf_counter() - timestamp), time)


J = tp.quantity_of_interest()


def reduced_functional(m):
    """
示例#7
0
# --- Set parameters

family = args.family or 'cg'
assert family in ('cg', 'dg')
kwargs = {
    'level': int(args.level or 0),
    'anisotropic_stabilisation': bool(args.anisotropic_stabilisation or False),
    'plot_pvd': True,
    'debug': bool(args.debug or False),
}
op = PointDischarge2dOptions(approach=args.load_mesh or 'fixed_mesh', **kwargs)
op.tracer_family = 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
op.di = os.path.join(op.di, op.stabilisation_tracer or family)
if args.load_mesh is not None:
    op.default_mesh = load_mesh("mesh", fpath=op.di)

# TODO: Limiters?


# --- Solve

tp = AdaptiveSteadyProblem(op)
tp.solve_forward()

# Export to HDF5
op.plot_pvd = False
export_field(tp.fwd_solution_tracer, "Tracer", "finite_element", fpath=op.di, op=op)