sintefmath / JutulDarcy.jl

Darcy flow and reservoir simulator based on Jutul.jl
https://sintefmath.github.io/JutulDarcy.jl/dev
MIT License
80 stars 18 forks source link

DisableControl() and compute_well_qoi #73

Open miguelcorralesg opened 4 days ago

miguelcorralesg commented 4 days ago

Hi Olav,

I'm trying to create an observation well to later use in an objective function alongside BottomHolePressureTarget. Based on previous discussions (in the issues thread with other user), you suggested using DisabledControl() to set up an observation well. However, when I implement the following and attempt to obtain the gradients, they come out as zero:

obs_1 = setup_well(g, K, [(1, ny, 1)], name = :Observation_1)
obs_ctrl = DisabledControl()
controls[:Observation_1] = obs_ctrl

function objective_function(model, state, Δt, step_i, forces)
    trat = JutulDarcy.compute_well_qoi(model, state, forces, :Observation_1, BottomHolePressureTarget)
    return (Δt * trat) / total_time
end

data_domain_with_gradients = JutulDarcy.reservoir_sensitivities(case, results, objective_function, include_parameters = true);
dk_obs1_bhp = data_domain_with_gradients[:permeability]

On the other hand, if I set the observation well with ProducerControl and DisabledTarget() (or set the target to zero), my gradient values are non-zero following the same objective function as before.

Could you please comment on whether the objective function is correctly set when using an observation well? or Are there any other potential issues or considerations I should be aware of?

moyner commented 4 days ago

I think there might be a subtle issue here where the disabled control will return a zero value for BHP. I think if you retrieve the BHP manually it will work:

bhp = first(state[:Observation_1].Pressure)

Going via the QOI code is not necessary in this case, since it does not make too much sense for observational wells.

You could also skip adding the observation well and instead do p = state.Reservoir.Pressure[some_cell] if you want to work with a grid-cell pressure.

miguelcorralesg commented 4 days ago

Thank you for your response. My main point was that using the L2 norm as an objective function for observation wells helps to match more observed data, which is why I’m using the compute_well_qoifunction, so I was hoping the function will do the job.

I found a workaround by setting the observation well as a producer and disabling the rate (idk if this is more appropriate), which allows me to obtain the gradient values (and not just zero values). However, as you suggested, accessing something like state.Reservoir.Pressure[some_cell] could also be a viable approach.

Thanks again!

moyner commented 4 days ago

I think both approaches will yield the same result, the main issue is that DisabledControl specifically skips computing the QOI - since it assumes that no pressure control is possible.