# Setting up diffusion with integral B.C. in Fenics

I'm trying to model diffusion through a cylindrical domain $$D = \{ (x,y,z) : x^2 + y^2 \leq 1, \;\; 0 \leq z \leq 1\}$$.

The is an initial concentration of the diffusant at the upper flat surface, say $$C(x,y,z=1) = C_{init}$$, and initially zero concentration within the domain.

The diffusant can move through both the $$z=0$$ and $$z=1$$ interfaces; there is no flux through the vertical walls.

The diffusion equation is $$\frac{\partial C}{\partial t} = \Delta C.$$

The boundary conditions are the problem: $$\frac{\partial C}{\partial t} (x, y, z=0, t) = K_0 \int_{z=0 \text{ cap}} \frac{\partial C}{\partial z} \;dS,$$ $$\frac{\partial C}{\partial t} (x, y, z=1, t) = K_1 \int_{z=1 \text{ cap}} \frac{\partial C}{\partial z} \;dS.$$ These come from assuming that the diffusion through the end caps occurs into finite-volume chambers, and the accumulated diffusant affects the rate of diffusion across the boundary. The $$K_i$$ are constants.

Trying to set up the variational formulation for Fenics, with $$C_N$$ equal to the concentration at time step $$N$$, I get

$$\int_D \frac{C_{N} - C_{N-1}}{\Delta t} v \; dV + \int_D \nabla C_N \cdot \nabla v \; d V - \int_{\partial D} v \nabla C_N\; d S = 0,$$

or equivalently $$\int_D \frac{C_{N} - C_{N-1}}{\Delta t} v \; dV + \int_D \nabla C_N \cdot \nabla v \; d V - \int_{z=1 \text{ cap}} v \frac{\partial C_N}{\partial z}\; d S + \int_{z=0 \text{ cap}} v \frac{\partial C_N}{\partial z}\; d S= 0.$$

I don't know where to go from here. The boundary conditions tell about the integral of $$\partial C / \partial z$$ over the caps, but I don't know how to translate that into information about the integral against $$v$$ over the caps. Any advice would be welcome.

N.B.: I know that the problem I've stated is essentially one dimensional, and can be solved that way. The problem I'm actually interested in has a more complex domain, so I gave a simpler version that should capture the B.C. issue.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8408302,"math_prob":0.9999336,"size":1939,"snap":"2021-43-2021-49","text_gpt3_token_len":619,"char_repetition_ratio":0.15503876,"word_repetition_ratio":0.13293052,"special_character_ratio":0.3310985,"punctuation_ratio":0.1308642,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999933,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-24T00:37:14Z\",\"WARC-Record-ID\":\"<urn:uuid:9244458a-15f9-4dc2-82e4-3973005b2573>\",\"Content-Length\":\"155261\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:101747b2-6b0b-46c5-9cb4-963145576213>\",\"WARC-Concurrent-To\":\"<urn:uuid:1269b605-6c04-4292-a3b8-819eed0e1461>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://scicomp.stackexchange.com/questions/33600/setting-up-diffusion-with-integral-b-c-in-fenics\",\"WARC-Payload-Digest\":\"sha1:OHH2T64E7NUMLNVZ2L6YIREPG4GZYG4G\",\"WARC-Block-Digest\":\"sha1:VHU6QDUI2EWH5DAVMMQTMQ4C2F2GC2VP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585828.15_warc_CC-MAIN-20211023224247-20211024014247-00024.warc.gz\"}"}