Esempio n. 1
0
    def get_basis_functions(self, prob=None):
        """
        Assemble a dictionary containing lists of Okada basis functions on each subfault.

        Each basis function associated with a subfault has active controls set to zero on all other
        subfaults and only one non-zero active control on the subfault itself, set to one. All passive
        controls retain the value that they hold before assembly.
        """
        from adapt_utils.unsteady.solver import AdaptiveProblem

        prob = prob or AdaptiveProblem(self)
        self._basis_functions = {}

        # Stash the control parameters and zero out all active ones
        tmp = self.control_parameters.copy()
        for control in self.active_controls:
            self.control_parameters[control] = np.zeros(self.num_subfaults)

        # Loop over active controls on each subfault and compute the associated basis functions
        msg = "INIT: Assembling Okada basis function array with active controls {:}..."
        print_output(msg.format(self.active_controls))
        msg = "INIT: Assembling '{:s}' basis function on subfault {:d}/{:d}..."
        for control in self.active_controls:
            self._basis_functions[control] = []
            for i, subfault in enumerate(self.subfaults):
                self.print_debug(msg.format(control, i, self.num_subfaults),
                                 mode='full')
                self.control_parameters[control][i] = 1
                self.set_initial_condition(prob,
                                           annotate_source=False,
                                           subtract_from_bathymetry=False)
                self._basis_functions[control].append(
                    prob.fwd_solutions[0].copy(deepcopy=True))
                self.control_parameters[control][i] = 0
        self.control_parameters = tmp
Esempio n. 2
0
    'ny': fac_y,
    'plot_pvd': True,
    'input_dir': inputdir,
    'output_dir': outputdir,
    'nonlinear_method': 'relaxation',
    'r_adapt_rtol': tol_value,
    # Spatial discretisation
    'family': 'dg-dg',
    'stabilisation': None,
    'stabilisation_sediment': None,
    'friction': 'manning'
}

op = BeachOptions(**kwargs)
assert op.num_meshes == 1
swp = AdaptiveProblem(op)


def gradient_interface_monitor(mesh,
                               alpha=alpha,
                               beta=beta,
                               gamma=gamma,
                               K=kappa):
    """
    Monitor function focused around the steep_gradient (budd acta numerica)

    NOTE: Defined on the *computational* mesh.

    """
    P1 = FunctionSpace(mesh, "CG", 1)
Esempio n. 3
0
    'approach': 'fixed_mesh',

    # Discretisation
    'tracer_family': args.family or 'dg',
    'stabilisation_tracer': args.stabilisation,
    'use_limiter_for_tracers': bool(args.limiters or True),
    'use_tracer_conservative_form': bool(args.conservative or False),

    # Misc
    'debug': bool(args.debug or False),
}


# --- Create solver and copy initial solution

ep = AdaptiveProblem(CosinePrescribedVelocityOptions(**kwargs))
ep.set_initial_condition()
init_sol = ep.fwd_solutions_tracer[0].copy(deepcopy=True)
init_norm = norm(init_sol)


# --- Eulerian interpretation

ep.solve_forward()
final_sol_eulerian = ep.fwd_solutions_tracer[-1]
relative_error_eulerian = abs(errornorm(init_sol, final_sol_eulerian)/init_norm)
print_output("Relative error in Eulerian case:   {:.2f}%".format(100*relative_error_eulerian))


# --- Lagrangian interpretation
Esempio n. 4
0
    op = TohokuBoxBasisOptions(**kwargs)
    op.di = di
    op.plot_pvd = plot_pvd

    # Bookkeeping for storing total variation
    num_cells.append(op.default_mesh.num_cells())
    gauges = list(op.gauges.keys())
    if errors['timeseries'] == {}:
        errors['timeseries'] = {gauge: [] for gauge in gauges}
        errors['timeseries_smooth'] = {gauge: [] for gauge in gauges}
    N = int(np.ceil(np.sqrt(len(gauges))))

    # Interpolate initial condition from [Saito et al. 2011] into a P1 space on the current mesh
    op_saito = TohokuOptions(mesh=op.default_mesh, **kwargs)
    swp_saito = AdaptiveProblem(op_saito,
                                nonlinear=nonlinear,
                                print_progress=op.debug)
    ic_saito = op_saito.set_initial_condition(swp_saito)

    # Project Saito's initial condition into the box basis
    swp_box = AdaptiveProblem(op, nonlinear=nonlinear, print_progress=op.debug)
    op.project(swp_box, ic_saito)
    op.set_initial_condition(swp_box)
    ic_box = project(swp_box.fwd_solutions[0].split()[1], swp_box.P1[0])

    # Load or save timeseries, as appropriate
    if plot_only:
        for gauge in gauges:
            for options, name in zip((op_saito, op),
                                     ('original', 'projected')):
                for tt in errors:
Esempio n. 5
0
num_meshes = int(args.num_meshes or 50)
op.end_time /= num_meshes
dt_per_mesh = int(op.end_time / op.dt)
end_time = op.end_time
dtc = Constant(op.dt)
if metric_advection:
    op.di = os.path.join(op.di, 'metric_advection')
else:
    op.di = os.path.join(op.di, 'on_the_fly')
if plot_pvd:
    tracer_file = File(os.path.join(op.di, 'tracer.pvd'))
theta = Constant(0.5)

# Generate initial mesh
tic = perf_counter()
tp = AdaptiveProblem(op)
for i in range(op.num_adapt):
    print("INITIAL MESH STEP {:d}".format(i))
    tp.set_initial_condition()
    c = tp.fwd_solution_tracer
    M = steady_metric(c,
                      V=tp.P1_ten[0],
                      normalise=True,
                      enforce_constraints=True,
                      op=op)
    tp = AdaptiveProblem(op, meshes=adapt(tp.mesh, M))
tp.set_initial_condition()

# Time loop
dofs = []
num_cells = []