# Numerical Coupling between a FEM Code and the FVM Code OpenFOAM Using the MED Library
## 4 Numerical Results
### Conjugate Heat Transfer (CHT)
#### 4.2.1 Boundary Data Transfer Algorithm  
A boundary data transfer algorithm is necessary to replicate numerically the setups where the heat exchange between the fluid and solid subdomains is not uniform. As stated in the introductory part, a possibility would be to solve the whole domain with a single code that implements both physics. In this work, however, we chose the strategy of using well-established codes for robustness and accuracy, so a suitable strategy must be developed to exchange data between codes when they share a boundary region.  
The method used for the coupling application involving boundary data transfer follows a procedure similar to the algorithm described in Section 4.1.1. In this scenario, we  
Figure 10: Geometrical configurations of the CHT problem: on the left is the domain with the solid wall thickness equal to \(t_{1}\), and on the right it is equal to \(t_{2}\).  
aim to couple the boundary between the solid and the fluid region within a 2D problem. Hence, the interface structures consist of a 1D mesh for FEMuS and a 2D mesh for OpenFOAM. After the interfaces and the meshes are created, the fields to be exchanged are initialized. In this instance, the fields to be transferred between the codes are the temperature at the boundary and the wall heat flux through the same boundary. Thus, we generate two MED fields for storing FEMuS data: a cell-wise heat flux field (qs_P0_1 Dmesh) and a temperature field (temp_P0_1 Dmesh). Similarly, corresponding MED fields are initialized for OpenFOAM: qs_P0_2 Dmesh and temp_P0_2 Dmesh.  
At the beginning of the time loop, OpenFOAM solves the governing equation for the fluid and the temperature equations. It then computes the wall heat flux to be transferred to FEMuS. The qs_P0_2 Dmesh is first extracted from the solution of OpenFOAM with the function get_field_from_OpenFOAM() and then stored in a MED field over the corresponding mesh. The heat flux provided by OpenFOAM is interpolated over the target mesh to obtain the target field qs_P0_1 Dmesh. This field is then written into the FEMuS solver as a nonhomogeneous Neumann boundary condition using the set_field_to_femus() routine. It is worth noting that the \(P_{0}\) to \(P_{2}\) interpolation is needed before the solution is written into the boundary since the field provided by OpenFOAM has a cell-wise approximation. The updated boundary condition is then used by FEMuS to solve the temperature equation within the solid domain, as described in (4). After obtaining the temperature solution in the solid, the get_field_from_femus() function is invoked to retrieve the solution at the boundary domain. With the inverse mapping, this solution is first converted into a \(P_{0}\) field and then interpolated over the OpenFOAM boundary to yield the temp_P0_2 Dmesh field. This field is used as a Dirichlet boundary condition for OpenFOAM as the boundary temperature is updated using the set_field_to_OpenFOAM() routine. At this stage, control is turned back to OpenFOAM, where it continues the task of solving its equations in the following time step.