I am working with complex grid and coefficient functions and compositions thereof. In the final calculation, only the real part has physical significance. To speed up the evaluation, I would like to compile the resulting CoefficientFunctions.
I took the following steps:
Define complex CF
Take real part
Compile
Efficiently evaluate
Then the following error gets thrown: netgen.libngpy._meshing.NgException: no real evaluate for ConstantCF-Complex
I am using:
python version: 3.13.1
ngsolve version: 6.2.2406
A Minimum Working Example is given below. I also included a similar example of such an error for complex ScaleCF. MWE_ngsolve_eval_complexCF.py (615 Bytes)
I believe that this is a bug. If this is intended behaviour, then I would like to know how to do this properly.
the CompiledCF evaluates all steps in real, or all steps in complex arithmetic, the type of the final result decides. You can swap your step 2 with step 3 to evaluate everything with complex numbers:
B = A.Compile(realcompile=True).real
I want to add that complex compile is not heavily used, since time-harmonic problems usually don’t have complicated expressions. Let us know if you have an use case where the un-compiled evaluate is the bottleneck.
Some background of my use case. I am writing a semi-analytical perturbative computational model using NGSolve. In this model, the nonlinear equations are divided into a sequence of ordered linear problems (assuming the nonlinearities are small). In this approach, solutions of lower-order problems are needed as forcing in subsequent higher-order problems. This dependence on previously computed solutions together with the semi-analytical expressions can become quite time consuming when using the un-compiled evaluate when solving the higher-order problems. Using an intermediate projection using Set or Project on a GridFunction makes solving the higher-order bilinear form take fractions of a second compared to tens of minutes. But then the projection step takes most time and may introduce small projection errors.