using functions for CoefficientFunction

More
4 years 4 months ago #2972 by sm22
Hello NGSolve,

I need to use a coefficient function that depends on the spatial coordinates. I tried the following:
Code:
#!/usr/bin/env python # coding: utf-8 # import netgen.gui from ngsolve import * from netgen.csg import * from netgen.geom2d import unit_square # initialise mpi comm = mpi_world rank = comm.rank nproc= comm.size mesh = Mesh(unit_square.GenerateMesh(maxh=0.2)) # fes = H1(mesh, complex=True, order=2) u = fes.TrialFunction() v = fes.TestFunction() R=0.8 class myCoeff: def __init__(self): self.R = R def eval(self, value, x): outside = ( x >= R ) coeff = 1. / (x - R) value = outside * coeff C = CoefficientFunction(myCoeff) # want to use a coefficient in the bilinear form: # a = BilinearForm (fes, symmetric=True) # a += SymbolicBFI (C*grad(u)*grad(v))

But the class can not be an argument for the CoefficientFunction. How to incorporate slightly involved functions such as the one above to be used in bilinear form? Thank you!!
More
4 years 4 months ago #2974 by mneunteufel
Hi sm22,

the IfPos CoefficientFunction should work
Code:
IfPos(x-R,1/(x-R),0)

see also the documentation for CoefficientFunctions . If you need a fancy CoefficientFunction which is not available there is the possibility to define your own CoefficientFunction in C++ and then to export it to Python, see this link .

Best
Michael
Time to create page: 0.091 seconds