When assigning values to a CF on solids, CF on faces is also change

Hi there,

I want to define a CF with different values inside the mesh (solids) and on the boundaries (faces). I expect that if I only assign values to the solids, the values on the faces remain unchanged (zero by default), but in the example below, the values on two faces are also changed. Please see the attached screenshot. As you see in the image, the top and right faces of the ‘part1’ material have different values than zero. Would be highly appreciated if anyone could help with this, please.

from ngsolve import *
from netgen.geom2d import SplineGeometry
from ngsolve.webgui import Draw
from netgen.occ import *
from netgen.csg import *
from ngsolve.solvers import *
#import matplotlib.pyplot as plt
import numpy as np
from ngsolve.krylovspace import CGSolver

box1 = Box((0,0,0), (2.2,2,1))
box2 = Box((0,0,0), (2.2,-1,1))
box3 = Box((0,0,1), (2.2,-1.01,3))
box4 = Box((0,-1,-2), (3,-3,7))

box1.solids.name = 'part1'
box2.solids.name = 'part2'
box3.solids.name = 'part3'
box4.solids.name = 'subsoil'

geo_conc = Glue([box1,box2,box3])
geo_conc_soil = Compound([geo_conc, box4])
geo = OCCGeometry(geo_conc_soil)
mesh = Mesh(geo.GenerateMesh(maxh = 0.5))

cfVals= {'part1':0, 'part2':30, 'part3':40, 'subsoil':50}
cf = CoefficientFunction([tttl[mat] for mat in mesh.GetMaterials()])

Draw(cf,mesh)

Regards
HA

That’s a common pitfall:

A CoefficientFunction has one value per Region, where Region can be a volume-region (material), or boundary region. The CF does not know itself whether its index refers to volume or boundary indix, it comes from the context it is used.

Use BoundaryFromVolumeCF(cf) if you want to draw the volume-values at the boundary.

Thanks Joachim! Very helpful.