@@ -151,7 +151,6 @@ def _bvh_query_distance(
151
151
sdf_hit_point : wp .array (dtype = wp .vec3f ),
152
152
sdf_hit_point_id : wp .array (dtype = wp .int32 ),
153
153
):
154
-
155
154
"""
156
155
Computes the signed distance from each point in the given array `points`
157
156
to the mesh represented by `mesh`,within the maximum distance `max_dist`,
@@ -690,7 +689,11 @@ def __init__(
690
689
self .air_density = torch .full ((1 , 1 ), 1.205 , dtype = torch .float32 ).to (
691
690
self .device
692
691
)
693
- self .num_vol_vars , self .num_surf_vars = self .get_num_variables ()
692
+ (
693
+ self .num_vol_vars ,
694
+ self .num_surf_vars ,
695
+ self .num_global_features ,
696
+ ) = self .get_num_variables ()
694
697
self .model = None
695
698
self .grid_resolution = torch .tensor (self .cfg .model .interp_res ).to (self .device )
696
699
self .vol_factors = None
@@ -755,28 +758,25 @@ def load_bounding_box(self):
755
758
self .bounding_box_surface_min_max = [c_min , c_max ]
756
759
757
760
def load_volume_scaling_factors (self ):
758
- vol_factors = np .array (
759
- [
760
- [2.2642279 , 2.2397292 , 1.8689916 , 0.7547227 ],
761
- [- 1.2899836 , - 2.2787743 , - 1.866153 , - 2.7116761 ],
762
- ],
763
- dtype = np .float32 ,
761
+ scaling_param_path = self .cfg .eval .scaling_param_path
762
+ vol_factors_path = os .path .join (
763
+ scaling_param_path , "volume_scaling_factors.npy"
764
764
)
765
765
766
+ vol_factors = np .load (vol_factors_path , allow_pickle = True )
766
767
vol_factors = torch .from_numpy (vol_factors ).to (self .device )
767
768
768
769
return vol_factors
769
770
770
771
def load_surface_scaling_factors (self ):
771
- surf_factors = np .array (
772
- [
773
- [0.8215038 , 0.01063187 , 0.01514608 , 0.01327803 ],
774
- [- 2.1505525 , - 0.01865184 , - 0.01514422 , - 0.0121509 ],
775
- ],
776
- dtype = np .float32 ,
772
+ scaling_param_path = self .cfg .eval .scaling_param_path
773
+ surf_factors_path = os .path .join (
774
+ scaling_param_path , "surface_scaling_factors.npy"
777
775
)
778
776
777
+ surf_factors = np .load (surf_factors_path , allow_pickle = True )
779
778
surf_factors = torch .from_numpy (surf_factors ).to (self .device )
779
+
780
780
return surf_factors
781
781
782
782
def read_stl (self ):
@@ -842,14 +842,28 @@ def get_num_variables(self):
842
842
num_surf_vars += 3
843
843
else :
844
844
num_surf_vars += 1
845
- return num_vol_vars , num_surf_vars
845
+
846
+ num_global_features = 0
847
+ global_params_names = list (cfg .variables .global_parameters .keys ())
848
+ for param in global_params_names :
849
+ if cfg .variables .global_parameters [param ].type == "vector" :
850
+ num_global_features += len (
851
+ cfg .variables .global_parameters [param ].reference
852
+ )
853
+ elif cfg .variables .global_parameters [param ].type == "scalar" :
854
+ num_global_features += 1
855
+ else :
856
+ raise ValueError (f"Unknown global parameter type" )
857
+
858
+ return num_vol_vars , num_surf_vars , num_global_features
846
859
847
860
def initialize_model (self , model_path ):
848
861
model = (
849
862
DoMINO (
850
863
input_features = 3 ,
851
864
output_features_vol = self .num_vol_vars ,
852
865
output_features_surf = self .num_surf_vars ,
866
+ global_features = self .num_global_features ,
853
867
model_parameters = self .cfg .model ,
854
868
)
855
869
.to (self .device )
@@ -1358,6 +1372,21 @@ def compute_solution_on_surface(
1358
1372
inlet_velocity ,
1359
1373
air_density ,
1360
1374
):
1375
+ """
1376
+ Global parameters: For this particular case, the model was trained on single velocity/density values
1377
+ across all simulations. Hence, global_params_values and global_params_reference are the same.
1378
+ """
1379
+ global_params_values = torch .cat (
1380
+ (inlet_velocity , air_density ), axis = 1
1381
+ ) # (1, 2)
1382
+ global_params_values = torch .unsqueeze (global_params_values , - 1 ) # (1, 2, 1)
1383
+
1384
+ global_params_reference = torch .cat (
1385
+ (inlet_velocity , air_density ), axis = 1
1386
+ ) # (1, 2)
1387
+ global_params_reference = torch .unsqueeze (
1388
+ global_params_reference , - 1
1389
+ ) # (1, 2, 1)
1361
1390
1362
1391
if self .dist .world_size == 1 :
1363
1392
geo_encoding_local = model .geo_encoding_local (
@@ -1383,8 +1412,8 @@ def compute_solution_on_surface(
1383
1412
surface_neighbors_normals ,
1384
1413
surface_areas ,
1385
1414
surface_neighbors_areas ,
1386
- inlet_velocity ,
1387
- air_density ,
1415
+ global_params_values ,
1416
+ global_params_reference ,
1388
1417
)
1389
1418
else :
1390
1419
pos_encoding = model .module .position_encoder (
@@ -1399,8 +1428,8 @@ def compute_solution_on_surface(
1399
1428
surface_neighbors_normals ,
1400
1429
surface_areas ,
1401
1430
surface_neighbors_areas ,
1402
- inlet_velocity ,
1403
- air_density ,
1431
+ global_params_values ,
1432
+ global_params_reference ,
1404
1433
)
1405
1434
1406
1435
return tpredictions_batch
@@ -1420,6 +1449,19 @@ def compute_solution_in_volume(
1420
1449
air_density ,
1421
1450
):
1422
1451
1452
+ ## Global parameters
1453
+ global_params_values = torch .cat (
1454
+ (inlet_velocity , air_density ), axis = 1
1455
+ ) # (1, 2)
1456
+ global_params_values = torch .unsqueeze (global_params_values , - 1 ) # (1, 2, 1)
1457
+
1458
+ global_params_reference = torch .cat (
1459
+ (inlet_velocity , air_density ), axis = 1
1460
+ ) # (1, 2)
1461
+ global_params_reference = torch .unsqueeze (
1462
+ global_params_reference , - 1
1463
+ ) # (1, 2, 1)
1464
+
1423
1465
if self .dist .world_size == 1 :
1424
1466
geo_encoding_local = model .geo_encoding_local (
1425
1467
geo_encoding , volume_mesh_centers , p_grid , mode = "volume"
@@ -1441,8 +1483,8 @@ def compute_solution_in_volume(
1441
1483
volume_mesh_centers ,
1442
1484
geo_encoding_local ,
1443
1485
pos_encoding ,
1444
- inlet_velocity ,
1445
- air_density ,
1486
+ global_params_values ,
1487
+ global_params_reference ,
1446
1488
num_sample_points = self .stencil_size ,
1447
1489
eval_mode = "volume" ,
1448
1490
)
@@ -1454,8 +1496,8 @@ def compute_solution_in_volume(
1454
1496
volume_mesh_centers ,
1455
1497
geo_encoding_local ,
1456
1498
pos_encoding ,
1457
- inlet_velocity ,
1458
- air_density ,
1499
+ global_params_values ,
1500
+ global_params_reference ,
1459
1501
num_sample_points = self .stencil_size ,
1460
1502
eval_mode = "volume" ,
1461
1503
)
@@ -1481,8 +1523,8 @@ def compute_solution_in_volume(
1481
1523
1482
1524
domino = dominoInference (cfg , dist , False )
1483
1525
domino .initialize_model (
1484
- model_path = "/lustre/rranade/modulus_dev/modulus_forked/modulus/examples/cfd/external_aerodynamics/domino/outputs/AWS_Dataset/19/ models/DoMINO.0.201 .pt"
1485
- )
1526
+ model_path = "/lustre/models/DoMINO.0.7 .pt"
1527
+ ) ## Replace the model path with location of the trained model
1486
1528
1487
1529
for count , dirname in enumerate (dirnames_per_gpu ):
1488
1530
# print(f"Processing file {dirname}")
@@ -1525,9 +1567,8 @@ def compute_solution_in_volume(
1525
1567
"Lift:" ,
1526
1568
out_dict ["lift_force" ],
1527
1569
)
1528
- vtp_path = f"/lustre/rranade/modulus_dev/modulus_forked/modulus/examples/cfd/external_aerodynamics/ domino/pred_{ dirname } _4.vtp"
1570
+ vtp_path = f"/lustre/snidhan/physicsnemo-work/ domino-global-param-runs/stl-results /pred_{ dirname } _4.vtp"
1529
1571
domino .mesh_stl .save (vtp_path )
1530
- # vtp_path = f"/lustre/rranade/modulus_dev/modulus_demo/modulus_rishi/modulus/examples/cfd/external_aerodynamics/domino_gtc_demo/sensitivity_pred_{dirname}.vtp"
1531
1572
reader = vtk .vtkXMLPolyDataReader ()
1532
1573
reader .SetFileName (f"{ vtp_path } " )
1533
1574
reader .Update ()
0 commit comments