MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / test_code_gen

Function test_code_gen

tests/pytest/test_shapeoptimization.py:210–238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208
209@pytest.mark.slow
210def test_code_gen():
211 mesh = Mesh(unit_cube.GenerateMesh(maxh=0.3))
212
213 VEC = VectorH1(mesh,order=1)
214 Phi,Psi = VEC.TnT()
215 gfvh = GridFunction(VEC)
216 gfvh.Set(CF( (x,y*x,x*y*z) ),definedon=mesh.Boundaries(".*"))
217 gfh = GridFunction(H1(mesh,order=1))
218 gfh.Set(x*y*z,definedon=mesh.Boundaries(".*"))
219
220 gfhc = GridFunction(HCurl(mesh,order=1))
221 gfhc.Set(CF( (x,y*x,x*y*z) ),definedon=mesh.Boundaries(".*"))
222 gfhd = GridFunction(HDivSurface(mesh,order=1))
223 gfhd.Set(CF( (x,y*x,x*y*z) ),definedon=mesh.Boundaries(".*"))
224
225
226 n = specialcf.normal(3)
227
228 functions = [(CF(1)*ds).DiffShape(Psi),(Trace(Grad(n))*ds).DiffShape(Psi),(CF(1)*ds(element_boundary=True)).DiffShape(Psi), (Trace(Grad(gfvh).Trace())*ds).DiffShape(Psi), ((Grad(gfh).Trace())**2*ds).DiffShape(Psi), (curl(gfhc).Trace()*gfhc.Trace()*ds).DiffShape(Psi),(div(gfhd).Trace()*gfhd.Trace()*gfhd.Trace()*ds).DiffShape(Psi)]
229
230
231 for cf in functions:
232 cfs = [ cf.Compile(), cf.Compile(True, wait=True)]
233 for f in cfs:
234 lf = BilinearForm(VEC)
235 lf += Variation(cf-f)
236 assert lf.Energy(gfvh.vec) == approx(0)
237
238 return
239
240if __name__ == "__main__":
241 test_diff()

Callers 1

Calls 11

TraceFunction · 0.85
GradFunction · 0.85
curlFunction · 0.85
divFunction · 0.85
BilinearFormClass · 0.85
VariationClass · 0.85
GridFunctionClass · 0.50
SetMethod · 0.45
DiffShapeMethod · 0.45
CompileMethod · 0.45
EnergyMethod · 0.45

Tested by

no test coverage detected