FEniCS-preCICE: Coupling FEniCS to other Simulation Software

The new software FEniCS-preCICE is a middle software layer, sitting in between the existing finite-element library FEniCS and the coupling library preCICE. The middle layer simplifies coupling (existing) FEniCS application codes to other simulation software via preCICE. To this end, FEniCS-preCICE converts between FEniCS and preCICE mesh and data structures, provides easy-to-use coupling conditions, and manages data checkpointing for implicit coupling. The new software is a library itself and follows a FEniCS-native style. Only a few lines of additional code are necessary to prepare a FEniCS application code for coupling. We illustrate the functionality of FEniCS-preCICE by two examples: a FEniCS heat conduction code coupled to OpenFOAM and a FEniCS linear elasticity code coupled to SU2. The results of both scenarios are compared with other simulation software showing good agreement.


Motivation and significance
Enabling simulations to play a significant role in answering the great research challenges of our time -let it be nuclear fusion, personalized medicine or climate prediction -requires the efficient interplay of diverse simulation software [1].Ideally, single simulation components may be treated as black boxes and may easily be plugged together or exchanged.The software preCICE [2] helps to do exactly that: It can be used to glue together arbitrary many of such black-box simulation components.In the following, we refer to these components as participants of a coupled simulation.preCICE focuses mainly on mesh-based discretizations of PDE models as participants.The finite element software FEniCS [3,4] is a popular choice to solve such PDE models in rather compact Python scripts.We call such a Python script a FEniCS application code.In this paper, we develop and document a new software called FEniCS-preCICE adapter, which allows researchers to easily couple FEniCS application codes to other simulation software by using preCICE.preCICE itself is a library.Thus, for coupling, a participant needs to call the API of preCICE in its source code.Due to the high abstraction level of the preCICE API, the necessary changes to a participant's source code are minimally invasive.These changes are typically realized in a so-called adapter -an additional class, module, or callback library of the participant's source code.An adapter defines the coupling meshes, handles coupling boundary conditions, and realizes the steering of the coupling.Till around 2016, preCICE users had to write their own adapters for codes they wanted to couple.As many users coupled the same codes, they had to solve the same problems, and continuously reinvented the wheel.Therefore, official, stand-alone, general-purpose adapters for widely used software (e.g. for OpenFOAM [5] or SU2 [6]) were first introduced in [7] to end the waste of precious human development resources.These developments have significantly contributed to the usability and popularity of preCICE and, thus, to the process of scientific discovery.
In this paper, we follow the same lines of argumentation and introduce a stand-alone, general-purpose adapter for FEniCS.We follow a FEniCS-native style, which makes the entry barrier for users of FEniCS as low as possible.The adapter can be easily integrated in existing FEniCS codes.The distributed-memory parallelization of FEniCS is supported out of the box.FEniCS itself is not a single simulation code, but a library as well.This makes a general-purpose adapter a challenging task.We, therefore, restrict the generality: we focus on 2D surface-coupled problems and study time-dependent fluid-structure interaction (FSI) and conjugate heat transfer (CHT) as examples.The proposed software design, however, is easy to extend, in particular to 3D scenarios and to volume-coupled problems.
FEniCS has already been used to solve FSI or more general multi-physics problems in a monolithic fashion [8][9][10].To this end, the library multiphenics1 provides FEniCS-tools to solve multi-physics problems.The interaction of the different physical phenomena is modeled through a large coupled equation system that is solved using FEniCS.Very often conforming meshes are required across the different physical domains.We, however, follow a partitioned approach, which allows to combine several specialized single-physics participants to solve overall multi-physics problems.FEniCS has already been coupled in a partitioned fashion to reaktoro [11] to simulate reactive transport or to other instances of FEniCS to allow for non-conforming meshes in FSI [12].In this paper, we present a software for coupling of FEniCS-based applications to arbitrary other simulation software via preCICE.
We describe the software in sufficient detail in Section 2. This includes an overview of the software architecture, a detailed description of the software's functionality, an exemplary use of its API, and a brief overview of used testing approaches.We give two illustrative use cases of the FEniCS-preCICE adapter in Section 3: a conjugate heat transfer simulation with FEniCS and OpenFOAM and a fluid-structure interaction with FEniCS and SU2.Afterwards, we discuss the impact of the new software in Section 4.

Software description
The FEniCS-preCICE adapter might be considered an unusual research software.It is neither a stand-alone single program, nor a library that can be used in such a program.Instead, it is a middle layer software between two large software packages: the finite element library FEniCS and the coupling library preCICE.Furthermore, a coupled simulation, by definition, consists of multiple participants, which brings even more software packages to the table.When describing the FEniCS-preCICE adapter, it is therefore essential to describe how the new software interfaces with these other software packages.In Section 2.1, we give an overview of the overall software architecture alongside a brief introduction to the individual packages: preCICE, FEniCS, and the FEniCS-preCICE adapter.Afterwards, in Section 2.2, we give detailed information on the API of the FEniCS-preCICE adapter and its functionality.A short example code in Section 2.3 completes the software description.Last, in Section 2.4, we explain how the new software is tested.
The software is developed on github2 and the source code is publicly available under LGPL-3.0license.A Python package is published and maintained on PyPI3 .

Software Architecture
Figure 1 gives an overview on how all software layers play together in a coupled simulation using the FEniCS-preCICE adapter.The user provides a FEniCS application code (solver.py),which uses FEniCS (import fenics) for solving a certain PDE model with a finite element method.Additionally, the application code imports the FEniCS-preCICE adapter (import fenicsprecice), which is a Python package itself, for coupling to other simulation software.The adapter, in turn, imports preCICE (import precice) -more specifically the Python bindings of preCICE.Finally, preCICE handles the coupling to other simulation software, for example OpenFOAM or SU2.Let us have a closer look at the individual packages.preCICE provides three building blocks for coupling mesh-based PDE solvers: 1) Methods for data mapping between non-matching meshes.2) Fixed-point acceleration methods to stabilize coupled equation systems.between participants, which are separate executables, potentially running on different nodes in a heterogeneous compute cluster.preCICE is a library and follows a peer-to-peer coupling concept -no central server-like entity is required.The library is written in C++, but also offers bindings in Python generated from the C++ API with Cython [13].As input and output arguments, the Python bindings use primitive Python data types as well as NumPy arrays [14].preCICE is configured at run time through an xml file describing a complete coupled simulation setup 4 .
FEniCS is a finite element Python package with an extensive C++ implementation named DOLFIN under the hood.Its API uses a high abstraction level.FEniCS provides functionality and data structures for generating and managing meshes.On top of meshes, various finite element spaces can be created.Weak forms of arbitrary PDEs can then be defined in a very compact notation.In Section 2.3, we give a brief code example, which illustrates the FEniCS API.The FEniCS-preCICE adapter has been tested and developed using FEniCS 2019.1.0.For more information on FEniCS, we refer the reader to [4].
FEniCS-preCICE provides an API for coupling a FEniCS application code using preCICE.This means, the FEniCS application code calls the FEniCS-preCICE adapter, which in turn calls preCICE.Some of the API calls of the FEniCS-preCICE adapter are simply redirected to preCICE.For other API calls, the adapter provides substantial functionality, for example for conversion of data structures.We give a detailed explanation of the API of the adapter in Section 2.2.The adapter is configured through a .jsonfile, which describes what data is written and read by the adapter.For simplification, currently only one read and one write data field on a single coupling mesh is technically supported by the adapter, whereas the preCICE API offers more flexibility.An extension in this direction is planned.Furthermore, FEniCS-preCICE was only tested with continuous Galerkin first and second order finite elements, while FEniCS provides a broad range of available finite element spaces, including higher order and discontinuous Galerkin.

Software Functionalities
The FEniCS-preCICE adapter uses a central Adapter object as handle to its API.We list the important parts of the API in Listing 1 and describe individual member functions of Adapter step by step in the following.To follow all implementation details of this section requires some previous knowledge of FEniCS.
Adapter initialization (lines 4 -13) The constructor of Adapter creates and configures the adapter object.The object is initialized by calling initialize, where the argument coupling_subdomain is the domain boundary where data should be coupled.Two optional arguments exist to configure the coupling: For one-way coupling either a read_function_space or a write_object must be provided -depending on whether the participant reads or writes data.For two-way coupling both arguments are required.Listing 1: API of the FEniCS-preCICE adapter (excerpt).The actual implementation is sketched, whenever it is short enough.
A FEniCS FunctionSpace is provided for the read_function_space and the write_object to provide the coupling mesh as well as the type of function (scalar/vector, order) to the adapter.If the user wants to provide initial write data, a FEniCS Function can be provided as write_object.

Data access (line 15 -20)
The user can call write_data and read_data to write data to or read data from preCICE, respectively.The argument write_function provided to write_data is a FEniCS Function, which the adapter samples at the coupling mesh.Calling read_data returns a dict data that contains coupling mesh points and associated data.It can be used to directly update coupling expressions or point sources.
Coupling consistent quantities via expressions (lines 22 -28) To enforce coupling boundary conditions, we need to distinguish two types of coupling data: quantities that require consistent data mapping (e.g.temperature, heat flux, or force per unit volume) and quantities that require conservative data mapping (e.g.forces).Let us first consider boundary conditions for consistent quantities.For this case, FEniCS' Expression has proven to be the right tool.This object is very flexible and can be used in many different ways -not only for boundary conditions.The FEniCS book [4]  For coupling boundaries, however, such a continuous representations needs to be constructed from the nodal values given by preCICE.To this end, the adapter provides a CouplingExpression which inherits from FEniCS' UserExpression.The continuous representation is constructed using an interpolation routine following the approach suggested in [15], where first a polynomial least-squares fit is constructed followed by a radial-basis function interpolation.For the radial-basis function interpolation, we use routines from SciPy [16].This interpolation is not to be confused with the data mapping that preCICE uses.An uninitialized CouplingExpression is created and returned by create_coupling_expression.It is initialized or updated by calling update_coupling_expression and providing the dict data obtained from read_data.
Coupling conservative quantities via point sources (lines 30 -32) Boundary conditions for conservative quantities can be realized by point-wise boundary conditions [17].To this end, FEniCS offers PointSource(V, p, magnitude), which can be applied to the equation system by PointSource.apply(rhs).Here, V is a function space, p the coordinates where the point source is applied, and magnitude the magnitude of the point source.get_point_sources allows the user to obtain point sources at the individual coupling mesh points; again by providing the dict data obtained from read_data.Please note that, contrary to a CouplingExpression, which is created once and then updated via a pointer-like access pattern, a PointSource is just overwritten.
Checkpointing (lines 34 -40) For implicit coupling (also known as strong or tight coupling), each time step (or even multiple time steps within a so-called time window) needs to be repeated iteratively until the coupling residual drops below a defined threshold.preCICE handles the convergence measurement, the iteration control, and the acceleration of the implicit coupling loop.The responsibility of the adapter is to provide a mechanism to go backwards in time.This is realized by storing and retrieving checkpoints of the complete solver state.To this end, the adapter offers methods store_checkpoint and retrieve_checkpoint, which are designed such that a user cannot accidentally destroy or overwrite checkpoints.
Steering (lines 42 -43) Steering methods, which allow to control the time and the coupling loop (advance and several others), are all directly forwarded to preCICE.We refer to the documentation of the Python bindings of preCICE 5 for details.
Parallelization FEniCS supports distributed-memory parallelization based on MPI: mpiexec -np numberOfRanks python3 solver.py The FEniCS-preCICE adapter directly supports this parallelization.We want to note a few necessary implementation details.In most cases, the domain decomposition of FEniCS does not yield a situation where all parallel ranks are located at the coupling boundary.Nevertheless to allow for a single implementation for serial and parallel cases, the adapter object is created and initialized on all ranks.If the domain of a rank is not connected to the coupling boundary, the rank is considered as an inactive rank from the perspective of the adapter.A further technical challenge results arbitrary coupling partner FEniCS, OpenFOAM, ...
coupling mesh name: FEniCSMesh write data name: HeatFlux read data name: Temperature from the ghost communication layers in FEniCS.As standard for the finite element method, vertices at the domain boundaries are duplicated on all connected ranks.However, only one rank has the ownership of a specific vertex.At the coupling boundary, only the rank which owns a vertex defines it as part of the coupling mesh for preCICE.Thus, in the adapter, each rank can only read new values from preCICE on the vertices it owns.The reconstruction of the coupling boundary condition, however, requires values also at non-owned vertices.To exchange these values between ranks, the adapter uses its own communication step after reading values from preCICE.The MPI wrapper shipped with FEniCS cannot be used here because the communication needs to take place after data is read from preCICE and before it is updated in FEniCS.The current parallel implementation, however, only supports boundary conditions defined in the form of expressions.Generating point source objects in parallel cannot be supported due to a known problem in FEniCS.

Example: A Simple Coupled Heat Transfer Solver
To complete the explanation of the software architecture and the API in the last sections, we now show a simple, but almost complete example application code solver.py.The example we study is the time-dependent heat equation and is borrowed from the FEniCS tutorials [18].
We define one edge of the squared domain as a Dirichlet coupling boundary.Through this boundary, our example code could be coupled to another FEniCS application code solving the time-dependent heat equation as well, which would render the overall problem into a simple partitioned heat equation.Alternatively, the coupling partner could also be a fluid solver, which would result in a conjugate heat transfer scenario.We show the results of such an example in Section 3.1.The setup is illustrated in Figure 2. In the following, we first look briefly at the adapter configuration and, afterwards, we discuss the application code.

Configuration of the Adapter
Listing 2 shows the configuration file of our example.The coupling participant is named FEniCS and the associated coupling mesh FEniCSMesh.The participant reads temperature values from preCICE and uses them to construct a Dirichlet boundary condition at the coupling boundary.Finally, the participant writes heat flux values to preCICE, which are explicitly computed as gradients of the temperature field.

Application Code
Listing 3 shows the almost complete application code of our example.Let us first have a look at the FEniCS code parts.Lines 5 and 6 define the geometry and mesh.Afterwards, lines 9 and 10 define the (quadratic) function space as well as trial and test functions, which are then used in line 25 to define the weak form of the time-dependent heat equation.For After solving the linear system, heat fluxes are extracted from the new solution (using the VectorFunctionSpace from line 11) and written to preCICE in lines 36 and 37.Then, finally the actual coupling is advanced.Here, preCICE returns an upper limit for the next timestep size, which is enforced in line 34.

Testing
The complex software architecture of the FEniCS-preCICE adapter as introduced in Section 2.1 makes testing the software more involved than testing most other research software.First, the FEniCS-preCICE adapter is a middle software layer -it is called by a FEniCS application code and calls in turn preCICE (via its Python bindings).Second, a coupled simulation needs at least two participants, thus at least two layered software stacks, of which the FEniCS-preCICE adapter could be part of one or both.Both concepts are not unusual in software engineering in general.Thus, there are known techniques for testing, such as mocking [19].The concepts are, however, uncommon for research codes, which typically only consist of stand-alone executables or libraries.We apply two different approaches to test the FEniCS-preCICE adapter.
The first approach tests the software in a complete coupled setup.We couple two FEniCS application codes to keep the number of dependencies small.We take the example we just introduced in the previous section and couple it with its counterpart -a time-dependent heat equation with a Neumann coupling boundary condition.We could then compare the results of this partitioned heat equation with those of a single-domain heat equation in FEniCS.We follow, however, an even simpler approach (similar to the FEniCS tutorials [18]): We construct a manufactured solution with linear dependency in time and quadratic dependency in space.As we use P 2 finite elements and first-order time integration, the discretization can recover the exact solution for arbitrary (coarse) space and time resolutions 6 .The only remaining error component is the coupling error, which can be controlled by the coupling convergence measures in every timestep.Tightening the thresholds reduces the error until machine precision 7 .In preCICE nomenclature, we refer to such a test with multiple participants and preCICE as a dependency as a system test.
The second approach to test the FEniCS-preCICE adapter regards the software as an isolated unit -independent of any other coupled participant and even independent of preCICE itself.To this end, we use a mocked up version of the Python bindings of preCICE.This allows us to test individual functions of the adapter, which then call the mocked up dummy implementation instead of preCICE itself.To illustrate the concept, Listing 4 gives an example on how to test the adapter function read_data.Line 2 imports the mock object MockedPrecice.In line 4, we use patch from unittest.mock8 to replace the real implementation of preCICE with the mock object.This means that in line 8 and indirectly in line 9, not the real preCICE, but the mock object is imported.The test can be run without preCICE being installed on the test system.In line 13, we use MagicMock to define the behavior of the mocked preCICE function read_block_scalar_data.We then can test whether read_data converts to and returns the correct data in line 22.
MagicMock also allows us to record the arguments a mocked function receives.We, finally, use this functionality in line 28 to also test whether preCICE receives the correct input arguments from the adapter.

Illustrative Examples
We give two examples to showcase how the FEniCS-preCICE adapter can be used in practice.First, in Section 3.1, a heat conduction solver in FEniCS is coupled to an OpenFOAM fluid solver for conjugate heat transfer (CHT).Afterwards, in Section 3.2, a linear elasticity solver in FEniCS is coupled to an SU2 fluid solver for fluid-structure interaction (FSI).We deliberately pick two different applications of FEniCS (heat transfer and structural mechanics) and two different coupling partners (OpenFOAM, SU2) to show the wide applicability of the new adapter.For both setups, we use simple geometries.These geometrical setups are offered as preCICE tutorials for many different participant combinations (FEniCS, OpenFOAM, SU2, deal.II, Nutils, Code Aster, CalculiX).FEniCS-preCICE adapter release v1.0.19 is used in these examples.

Conjugate heat transfer with FEniCS and OpenFOAM
As a simple CHT test case, we consider a flow over a heated plate10 inspired by [21].Figure 3a sketches the domain and lists all physical parameters.Heat conduction in the plate in the lower part of the domain is simulated with FEniCS, using a very similar application code as already explained in Section 2.3.On top of the plate, we simulate an fluid flow from left to right with the OpenFOAM [22] solver buoyantPimpleFoam.To couple OpenFOAM, we make use of the OpenFOAM-preCICE adapter11 [23].We use a Dirichlet-Neumann coupling: The solid participant (FEniCS) receives temperature values from the fluid participant and uses them as Dirichlet boundary condition at the coupling interface.The fluid participant (OpenFOAM), on the other hand, receives heat flux values from the solid participant and uses them as Neumann boundary condition.For the Dirichlet boundary condition in FEniCS, we use a FEniCS expression as described in Section 2.2.To map coupling data between non-matching meshes at the coupling interface, we use a nearest-neighbor mapping (in preCICE).Figure 3b shows the temperature distribution of the coupled simulation after approaching steady-state.To verify our results, we compare the OpenFOAM-FEniCS coupling to an already existing OpenFOAM-OpenFOAM coupling.For comparable mesh resolutions, the results match very well, see Figure 3c.As a simple FSI test case, we consider a wall-mounted elastic flap in a channel flow 12 .Figure 4a sketches the domain and lists all physical parameters.To simulate the elastic flap, we use a linear elasticity code in FEniCS, which was developed in the Bachelor thesis of Richard Hertrich [17] following an example from [24].In the fluid domain, we use the compressible Euler solver of SU2 [6].To couple SU2, we make use of the SU2-preCICE adapter 13  To map coupling data between non-matching meshes at the coupling interface, we again use a nearest-neighbor mapping (in preCICE).Figure 4b shows the fluid velocity at maximum deformation of the beam.To verify our results, we compare the SU2-FEniCS coupling to an already existing SU2-deal.II coupling.We use deal.II v9.2 [26] and the preCICE-deal.II adapter 14 .For comparable mesh resolutions, the results match once again very well, see Figure Figure 4c.

Impact
The FEniCS-preCICE adapter enables the coupling of existing FEniCS application codes to other simulation software in only a few lines of code.In particular, this holds for simulation software for which preCICE adapters already exist such as OpenFOAM, SU2, or deal.II.Application scientists can now focus on coupled problems from the physical perspective and let the FEniCS-preCICE adapter handle the technical aspects: converting mesh and data structures, handling coupling conditions, or checkpointing for implicit coupling.
The increase in opportunities works in both directions: Not only existing FEniCS users can now easily connect to the preCICE community and other simulation software, but also other communities (e.g. the large OpenFOAM community) can now directly benefit from FEniCS.
We want to illustrate the range of opportunities with three examples: • Within the collaborative research center 1313 [27] several porous media applications are studied, such as the hydromechanical coupling of fractures and porous media.The current implementation is based on FEniCS and preCICE [28] as it lowers the implementation hurdles compared to previous implementations based on DUNE [29].Furthermore, basing the implementation on FEniCS and preCICE immediately enables parallel computing capabilities.The current realization, however, uses the preCICE API directly from the application code.Using the new FEniCS-preCICE adapter instead will lead to a more idiomatic incorporation of preCICE into the coupled FEniCS codes allowing the researchers to rather focus on the implementation and evaluation of their models than the coupling itself.Some extensions of the adapter will be necessary, however, to tackle mixed-dimensional problems as they appear in hydromechanical coupling simulations.
• Together with researchers from Helmholtz-Zentrum Geesthacht and HSU Hamburg, we are currently investigating the coupling of electro-chemistry models to fracture mechanics to simulate corrosion 15 .For both fields, promising models [30] or codes in FEniCS [31] exist.In contrast to both examples in Section 3, a volume coupling will be necessary.Since the adapter treats coupling conditions as general FEniCS Expressions, however, an extension to volume coupling will be straight forward.
• The layered design created by the FEniCS-preCICE adapter makes it also possible to easily prototype and test new numerical coupling algorithms, such as quasi-Newton waveform iteration in [20].Here, an additional layer between the adapter and preCICE was used to implement and test a waveform data structure separately.
In view of the rapid growth of the preCICE community and the popularity of FEniCS, we expect significant interest in the adapter in the next years.At this point in time (March 2021), preCICE is used by more than 80 research groups 16 , spread over academia, non-academic research centers, and industry.

Conclusions
The new software FEniCS-preCICE allows to couple FEniCS application codes to other simulation software via pre-CICE.Our motivation was to make such external coupling as easy as possible for existing FEniCS users.To this end, we hid technical coupling complexity, such as parallel data structures, data conversion, or checkpointing, within the new middle software layer.We were able to implement FEniCS-preCICE as a library and to follow a FEniCS-native style.This allows users of FEniCS to couple existing FEniCS application codes to other simulation software by only adding a few easy-to-understand lines of code.We illustrated the potential by coupling 2D FEniCS application codes to OpenFOAM and SU2 to simulate conjugate heat transfer and fluid-structure interaction problems.The design of the new software already envisions future extensions to other coupled problems (e.g.volume coupling) and to 3D scenarios.The impact of the new software should be significant.We already mentioned two projects that plan to use the software in the future: coupling fracture mechanics to porous media flow and coupling fracture mechanics to electro-chemistry models.FEniCS itself is currently undergoing a major redesign named DOLFIN-X.Initial investigation showed that it should be possible to easily port FEniCS-preCICE to DOLFIN-X, which we want to realize in future work.We wish to confirm that there are no known conflicts of interest associated with this publication and there has been no significant financial support for this work that could have influenced its outcome.

Figure 2 :
Figure 2: Unit square Ω, where heat equation is solved by the FEniCS participant.Dirichlet boundary conditions are applied on Γ. Coupling happens on Γ C , where another Dirichlet boundary condition is applied and heat flux is sampled to establish the coupling.
Geometric setup and physical parameters.All boundaries except the inflow and outflow boundary (Γ inflow , Γ outflow ), the hot bottom of the plate (Γ hot ) and the coupling interface (Γ C ) are insulated.(b) Steady-state temperature distribution.For better visualization, the depicted meshes are 5 times coarser than in reality.Steady-state temperature profile along a line 0.01m above and parallel to the coupling interface Γ C,no-slip .Both profiles differ by a relative l2 error of 7.61 • 10 −5 .

Figure 3 :
Figure 3: Conjugate heat transfer testcase [25].We again use a Dirichlet-Neumann coupling: The fluid participant (SU2) receives displacement values from the fluid participant, computes velocity values from the displacement values, and uses the velocity values as Dirichlet boundary condition at the coupling interface.The solid participant (FEniCS), on the other hand, receives force values from the fluid participant and uses them as Neumann boundary condition.For the Neumann boundary condition in FEniCS, we now use point sources as described in Section 2.2.

3 •
10 3 kg/m 3 (a) Geometric setup and physical parameters.(b) Velocity field of fluid domain Tip displacement in x direction of the elastic flap over time.Both curves differ by a relative l2 error of 8.17 • 10 −3 .

Figure 4 :
Figure 4: Fluid-structure interaction test case gives many examples how to use an expression for both, Dirichlet and Neumann boundary conditions.An essential Dirichlet boundary condition, for instance, can be defined by FEniCS' DirichletBC.However, expressions can also be used directly in the weak form, for instance for Neumann boundary conditions (... + expr * v * ds) or for volume terms (... + expr * v * dx).Here, expr is an Expression, v the test function, and ds and dx a surface and volume integration element.Normally, for boundary conditions, expressions are explicitly given as symbolic expressions (e.g. Expression('sin(x[0]) + cos(x[1])')).
Adapter configuration file precice-adapter-config.json time integration, an implicit Euler scheme is used.Furthermore, lines 12 and 13 define Dirichlet boundary conditions at the non-coupling boundary.The discretized linear system is solved in every timestep in line 35.The highlighted lines show the code related to the coupling.We import FEniCS-preCICE in line 2. Line 7 defines a subdomain as coupling boundary.Then, lines 15 to 18 create the handle to the adapter, initialize it with a read and write function space used for two-way coupling, and create the Dirichlet coupling boundary condition.In line 28, the time loop control is handed over to preCICE.If required, data checkpoints are written in lines 29 and 30 and read in lines 40 to 43.Temperature values are read from preCICE in line 32 and used to update the coupling boundary condition in line 33.