The code below should solve a heat transfer problem with Robin boundary conditions, but with the heat transfer coefficient being a function of the local heat flux:
import numpy as np
from dolfin import *
mesh = UnitSquareMesh(32, 32)
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
ds = Measure('ds', domain=mesh, subdomain_data=boundaries)
class Base_face(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[1], 0)
base_face = Base_face()
base_face.mark(boundaries, 1)
class Top_face(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[1], 1)
top_face = Top_face()
top_face.mark(boundaries, 2)
# Build function space
V = FunctionSpace(mesh, 'CG', 1)
T = TrialFunction(V)
s = TestFunction(V)
n = FacetNormal(mesh)
k = Constant(1.0)
Tref = Constant(0.0)
f = Constant(1.0)
#HTC = Constant(1.0)
HTC = Expression('20. * pow(abs(dot(n, k*grad(T))), 0.67 )')
bcs = []
F = (
- inner( k * grad(T), grad(s)) * dx
- HTC * (T - Tref) * s * ds(1)
+ f * s * ds(2)
)
a, L = lhs(F), rhs(F)
# Create VTK files for visualization output
vtkfile_T = File('Temperature.pvd')
T = Function(V, name='Temperature')
solve(a == L, T, bcs, solver_parameters={'linear_solver':'mumps'})
# Save solution to file (VTK)
vtkfile_T << T
However because of HTC = Expression('20. * pow(abs(dot(n, k*grad(T))), 0.67 )')
I get the error
------------------- Start compiler output ------------------------
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp: In member function 'virtual void dolfin::dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45::eval(Eigen::Ref<Eigen::Matrix<double, -1, 1> >, Eigen::Ref<const Eigen::Matrix<double, -1, 1> >) const':
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp:61:41: error: 'n' was not declared in this scope; did you mean 'yn'?
61 | values[0] = 20. * pow(abs(dot(n, k*grad(T))), 0.67 );
| ^
| yn
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp:61:44: error: 'k' was not declared in this scope
61 | values[0] = 20. * pow(abs(dot(n, k*grad(T))), 0.67 );
| ^
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp:61:51: error: 'T' was not declared in this scope
61 | values[0] = 20. * pow(abs(dot(n, k*grad(T))), 0.67 );
| ^
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp:61:46: error: 'grad' was not declared in this scope
61 | values[0] = 20. * pow(abs(dot(n, k*grad(T))), 0.67 );
| ^~~~
/tmp/tmp42fb9sup/dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45.cpp:61:37: error: 'dot' was not declared in this scope
61 | values[0] = 20. * pow(abs(dot(n, k*grad(T))), 0.67 );
| ^~~
------------------- End compiler output ------------------------
Compilation failed! Sources, command, and errors have been written to: /home/chbrago/Documents/Fenics/Heat_Spreading/jitfailure-dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45
Traceback (most recent call last):
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/jit/jit.py", line 165, in compile_class
module, signature = dijitso_jit(cpp_data, module_name, params,
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
return local_jit(*args, **kwargs)
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/jit/jit.py", line 103, in dijitso_jit
return dijitso.jit(*args, **kwargs)
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dijitso/jit.py", line 216, in jit
raise DijitsoError("Dijitso JIT compilation failed, see '%s' for details"
dijitso.jit.DijitsoError: Dijitso JIT compilation failed, see '/home/chbrago/Documents/Fenics/Heat_Spreading/jitfailure-dolfin_expression_e5fd8dcbbb9e14a75c40244a34f14c45' for details
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/chbrago/Documents/Fenics/Heat_Spreading/test_Fenics_HTC-q.py", line 31, in <module>
HTC = Expression('20. * pow(abs(dot(n, k*grad(T))), 0.67 )')
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/function/expression.py", line 400, in __init__
self._cpp_object = jit.compile_expression(cpp_code, params)
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/function/jit.py", line 158, in compile_expression
expression = compile_class(cpp_data, mpi_comm=mpi_comm)
File "/home/chbrago/.conda/envs/cadquery/lib/python3.9/site-packages/dolfin/jit/jit.py", line 170, in compile_class
raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso