Subdomain post-processing

Hi,

Suppose in subdomain-poisson example after solving the equation, I want to define a function and output it. For example, my function is,

\text{post} = \begin{cases}2u & \text{subdomain 0} \\u^2 & \text{subdomain 1}\end{cases}

In the same link as above, postprocessing is pretty easy when we are also integrating, but in my case, there is no integration, just a simple conditional function.

Thanks a lot for all the help,
Amir

I assume u is the solution to your Finite element problem? If so, you can create a custom projection with the following variational forms:

u, v = TrialFunction(V), TestFunction(V)
a=inner(u,v)*dx
L=inner(uh**2,v)*dx(domain=mesh, subdomain_data=mf, subdomain_id=1) + inner(2*uh, v)* dx(domain=mesh, subdomain_data=mf, subdomain_id=0)
u_post =Function(V)
solve(a==L, u_post)

Where uh is the solution to your original problem. Note that you might want to use a DG-space for the projection, as u**2!=2u could happen at the interface between the domains.
To visualize DG functions, use XDMFFile.write_checkpoint and open it in paraview.

1 Like