1010from .PDELoss import PDELoss
1111from .JoinedDataset import JoinedDataset
1212from .HPMLoss import HPMLoss
13+ from .Adaptive_Sampler import AdaptiveSampler
1314from torch .autograd import grad as grad
1415from PINNFramework .callbacks import CallbackList
1516
@@ -96,11 +97,14 @@ def __init__(self, model: torch.nn.Module, input_dimension: int, output_dimensio
9697 self .is_hpm = False
9798 else :
9899 raise TypeError ("PDE loss has to be an instance of a PDE Loss class" )
99-
100+
100101 if isinstance (pde_loss , HPMLoss ):
101102 self .is_hpm = True
102103 if self .use_gpu :
103104 self .pde_loss .hpm_model .cuda ()
105+
106+ if isinstance (pde_loss .geometry .sampler , AdaptiveSampler ):
107+ self .pde_loss .geometry .sampler .device = torch .device ("cuda" if self .use_gpu else "cpu" )
104108
105109 if isinstance (initial_condition , InitialCondition ):
106110 self .initial_condition = initial_condition
@@ -110,12 +114,12 @@ def __init__(self, model: torch.nn.Module, input_dimension: int, output_dimensio
110114 if not len (initial_condition .dataset ):
111115 raise ValueError ("Initial condition dataset is empty" )
112116
113- if not len (pde_loss .dataset ):
114- raise ValueError ("PDE dataset is empty" )
115-
117+ if not len (pde_loss .geometry ):
118+ raise ValueError ("Geometry is empty" )
119+
116120 joined_datasets = {
117121 initial_condition .name : initial_condition .dataset ,
118- pde_loss .name : pde_loss .dataset
122+ pde_loss .name : pde_loss .geometry
119123 }
120124 if self .rank == 0 :
121125 self .loss_log [initial_condition .name ] = float (0.0 ) # adding initial condition to the loss_log
@@ -318,14 +322,14 @@ def pinn_loss(self, training_data, track_gradient=False, annealing=False):
318322 # unpack training data
319323 # ============== PDE LOSS ============== "
320324 if type (training_data [self .pde_loss .name ]) is not list :
321- pde_loss = self .pde_loss (training_data [self .pde_loss .name ][0 ].type (self .dtype ), self .model )
325+ pde_loss = self .pde_loss (training_data [self .pde_loss .name ][0 ].type (self .dtype ), self .model )
322326 if annealing or track_gradient :
323327 self .loss_gradients_storage [self .pde_loss .name ] = self .loss_gradients (pde_loss )
324328 pinn_loss = pinn_loss + self .pde_loss .weight * pde_loss
325329 if self .rank == 0 :
326330 self .loss_log [self .pde_loss .name ] = pde_loss + self .loss_log [self .pde_loss .name ]
327331 else :
328- raise ValueError ("Training Data for PDE data is a single tensor consists of residual points " )
332+ raise ValueError ("Training Data for PDE data is either a single tensor consisting of residual points or a concatenation of residual points and corresponding weights " )
329333
330334 # ============== INITIAL CONDITION ============== "
331335 if type (training_data [self .initial_condition .name ]) is list :
@@ -673,4 +677,4 @@ def take_snapshot(model, file_path, device, n_points):
673677 # convert all tensors to numpy arrays and save as VTK data
674678 grid = [x .numpy (), y .numpy (), z .numpy ()]
675679 output = output .view (n_points ).to ('cpu' ).numpy ()
676- imageToVTK (file_path , grid , pointData = {"model output" : output })
680+ imageToVTK (file_path , grid , pointData = {"model output" : output })
0 commit comments