def __init__(self, varying_parameters=Parameters("{}")): BaseAnalysis.__init__(self, varying_parameters) final_time = self.project_parameters.AddEmptyValue( "FinalTime").GetDouble() L = 0.0048 # the channel width center_x = 0.0044 self.bbox_watcher = SDEM.BoundingBoxRule(0.0, 2 * final_time, center_x - L, center_x + L, -0.007, -0.002, -0.005, 0.001)
def __init__(self, real_field_type, fixed_mesh_option): self.real_field_type = real_field_type self.fixed_mesh_option = fixed_mesh_option if (self.real_field_type == 0): self.force_formula = SDEM.TimeDependantForceField(2) self.porosity_default_value = 1.0 self.force_default_vector = Array3() self.force_default_vector[0] = 0.0 self.force_default_vector[1] = 0.0 self.force_default_vector[2] = 0.0 self.porosity_formula = self.force_formula.GetPorosityField() self.b_box_rule = SDEM.BoundingBoxRule() self.b_box_rule.SetTimeBoundingInterval(0, 3) self.b_box_rule.SetYBoundingInterval(-1, 1) self.domain = SDEM.SpaceTimeSet() self.domain.AddAndRule(self.b_box_rule) self.porosity_field_utility = SDEM.FieldUtility(self.domain) self.force_field_utility = SDEM.FieldUtility(self.domain)
def RecordParticlesInBox(self, bounding_box = SDEM.BoundingBoxRule()): self.bounding_box = bounding_box time = self.model_part.ProcessInfo[Kratos.TIME] def IsInside(node): is_a_particle = node.IsNot(Kratos.BLOCKED) is_inside = self.bounding_box.CheckIfRuleIsMet(time, node.X, node.Y, node.Z) return is_a_particle and is_inside nodes_inside = [node for node in self.model_part.Nodes if IsInside(node)] Ids_inside = np.array([node.Id for node in nodes_inside]) X0s_inside = np.array([node.X0 for node in nodes_inside]) Y0s_inside = np.array([node.Y0 for node in nodes_inside]) Z0s_inside = np.array([node.Z0 for node in nodes_inside]) radii_inside = np.array([node.GetSolutionStepValue(Kratos.RADIUS) for node in nodes_inside]) if len(radii_inside): mean_radius = sum(radii_inside) / len(radii_inside) else: mean_radius = 1.0 with h5py.File(self.main_path + '/particles_snapshots.hdf5') as f: prerun_fluid_file_name = self.prerun_fluid_file_name.split('/')[- 1] current_fluid = CreateGroup(f, prerun_fluid_file_name, overwrite_previous = False) # snapshot_name = 't=' + str(round(time, 3)) + '_RADIUS=' + str(round(mean_radius, 4)) + '_in_box' snapshot_name = str(len(current_fluid.items()) + 1) self.run_code = prerun_fluid_file_name.strip('.hdf5') + '_' + snapshot_name snapshot = CreateGroup(current_fluid, snapshot_name) snapshot.attrs['time'] = time snapshot.attrs['particles_nondimensional_radius'] = mean_radius # storing the input parameters for this run, the one corresponding # to the current pre-calculated fluid for k, v in ((k, v) for k, v in json.loads(self.parameters.WriteJsonString()).items() if 'comment' not in k): snapshot.attrs[k] = v names = ['Id', 'X0', 'Y0', 'Z0', 'RADIUS'] data = [Ids_inside, X0s_inside, Y0s_inside, Z0s_inside, radii_inside] for dset_name, datum in zip(names, data): CreateDataset(snapshot, dset_name, datum)