Automatic construction of numerical adjoints and applications