Average value of solution across boundary of mesh

Hi everyone,

I am currently trying to find the average value of my solution Temp across the surface of my 2D mesh. But I am unsure how I can accomplish this.

Here is the example I have so far:

from __future__ import print_function
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
from dolfin import *
from ufl import as_tensor
from ufl import Index
import math
from scipy.optimize import curve_fit
from mpi4py import MPI

mesh = UnitCubeMesh(16,16,16)

Space = FunctionSpace(mesh, ā€˜Pā€™, 1)
Temp = project(Expression(ā€œ10*x[0]+100*x[1]+ x[2]ā€, degree=3), Space)

class marker(SubDomain):
    def inside(self, x, on_boundary):
        return near(x[2], 1) and on_boundary

Is there an inbuilt function that I can use this to find the average of Temp across the face of my mesh at the given boundary?

How about creating a MeshFunction based on your marker,say tag all facets to integrate over with 1, and do the following:

mf = dolfin.MeshFunction("size_t", mesh, mesh.topology().dim()-1)
marker().mark(mf, 1)
ds1 = dolfin.Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=1)
1 Like

How is this done using Dolfinx?

See for instance https://jsdokken.com/dolfinx-tutorial/chapter3/robin_neumann_dirichlet.html: search for the word meshtags (which replaced dolfin.MeshFunction) and assemble_scalar (which replace dolfin.assemble)