  In many areas of science and engineering, it is a common task to infer
physical fields from sparse observations. This paper presents the DAFI code
intended as a flexible framework for two broad classes of such inverse
problems: data assimilation and field inversion. DAFI generalizes these diverse
problems into a general formulation and solves it with ensemble Kalman filters,
a family of ensemble-based, derivative-free, Bayesian methods. This Bayesian
approach has the added advantage of providing built-in uncertainty
quantification. Moreover, the code provides tools for performing common tasks
related to random fields, as well as I/O utilities for integration with the
open-source finite volume tool OpenFOAM. The code capabilities are showcased
through several test cases including state and parameter estimation for the
Lorenz dynamic system, field inversion for the diffusion equations, and
uncertainty quantification. The object-oriented nature of the code allows for
easily interchanging different solution methods and different physics problems.
It provides a simple interface for the users to supply their domain-specific
physics models. Finally, the code can be used as a test-bed for new
ensemble-based data assimilation and field inversion methods.
