#
# Laser and mirrors convection-diffusion experiment with known diffusivity and convectivity
#
import laser_and_mirrors_aux
from measures import DiscreteMeasure_2_f64
from pointsource_pde import Problem, RegTerm
from pointsource_pde.compose import (
    ComposeFnWithOperator,
    InjectSecond,
)

# Give name to the problem
name = "laser_and_mirrors"

# Override algorithm settings
algorithm_overrides = laser_and_mirrors_aux.algorithm_overrides


# Setup routine
def setup(prefix):
    dat, auxtrue, μ_bound, μ_true, plot_factory = laser_and_mirrors_aux.generic_setup(
        prefix
    )

    μ0 = DiscreteMeasure_2_f64([])

    reg = RegTerm.NonnegRadon(
        10e-7  # 5e-7  # 3e-7
    )

    dat_simple = ComposeFnWithOperator(dat, InjectSecond(auxtrue), xbound=μ_bound)
    dat_simple.curvature_bound_components = lambda: (None, None)
    print("Initial value:", dat_simple.apply(μ0))
    print("Value at true μ:", dat_simple.apply(μ_true))

    return Problem(
        dataterm=dat_simple, regterm=reg, μinit=μ0, plot_factory=plot_factory
    )
