Boundedness of network output

Hello,

I’m trying to extend the Navier-Stokes PDEs to multiphase flows using Volume Of Fluid (VOF) approach, as it is done here. This requires to compute an auxiliary variable ‘alpha’ that represents the volume fraction of fluid (e.g. water), and that is bounded between 0 and 1.

I’m looking for a way to specify a sigmoid activation function for this output only, leaving the other output activations unchanged. However, I can’t see a simple way to implement that with Modulus. Is there a way to do that?

Thank you,
Michele

Hi @michele.messina.95

Thanks for using Modulus!

My recommended approach would be to define a temporary version of this variable (alpha_hat). You neural network model will predict this variable plus others (e.g. u,v,p,alpha_hat). Now we define a custom node that goes from alpha_hatalpha. E.g.

class AlphaConverter(nn.Module):
    def forward(self, in_vars: Dict[str, Tensor]) -> Dict[str, Tensor]:
        return {"alpha": torch.sigmoid(in_vars["alpha_hat"])}

alpha_node = Node(['alpha_hat'], ['alpha'], AlphaConverter())

Then just add this to your node list and keep all your PDEs / loss functions the same. Operating through temporary variables / fields to make more customized outputs should be very flexible.

This is working well! Thank you for your quick reply.

Michele

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.