How to use a trained model for optimization thru a function

Hi, I have trained a flow past airfoil problem with parameterization for the angle of attack AoA.

Supposed I want to find the AoA which gives the highest lift within the range which I did the training.

Thru the PointwiseMonitor, I can compute the lift force using this:

force_p1 = PointwiseMonitor(
        airfoil1_geo.sample_boundary(1000),
        output_names=["p"],
        metrics={
            "force_x_p1": lambda var: torch.sum(-2.*var["normal_x"] * var["area"] * var["p"]),
            "force_y_p1": lambda var: torch.sum(-2.*var["normal_y"] * var["area"] * var["p"]),
        },
        nodes=nodes,
    )
    domain.add_monitor(force_p1)

However it is given as an output after every 1000 steps in a csv file during training.

Is there anyway I can create a function in Modulus which gives me the lift given my inputs such as AoA? In this way, I can use many different types of optimizers to get my AoA for max lift.

Of course, I think I can also read from the csv file to get the lift but it will be very slow with all the i/o.

Thanks.

1 Like

Any one have experience in this area?

Thanks.

Hi @tsltaywb

If you’re model is already trained and you just want to run a forward pass you could use the point monitor you have with the trainer solver.eval() function (can use this instead for the solver.solve() function).

This is a bit of a hidden API of the solver/trainer class that can be used to perform just one pass of the validators / inferencers / monitors you’ve added.

There is also the more manual pure PyTorch approach of writing an inference script from scratch, but if your output quantity relies on some gradient calculations then its best you stick with running a monitor / inferencer in Modulus.