Loading sample_simulation_mcvine/base/geometry-program.py 0 → 100644 +52 −0 Original line number Diff line number Diff line import numpy as np from instrument.geometry.pml import weave from instrument.geometry import shapes, operations from instrument.geometry.pml.Renderer import Renderer as base class FileIncRenderer(base): def _renderDocument(self, body): self.onGeometry(body) return def header(self): return [] def footer(self): return [] def end(self): return def sample_cylinder(radius, height, file_location, file_name): """ Generates an XML file for a sample cylinder geometry. Parameters: - radius (float): Radius of the sample cylinder in mm. - height (float): Height of the sample cylinder in mm. - file_location (str): Location where the file will be saved. - file_name (str): Name of the XML file to generate. """ # Define the sample geometry sample_cylinder = shapes.cylinder(radius="{}*mm".format(radius), height="{}*mm".format(height)) sample_cylinder_beam = operations.rotate(sample_cylinder, beam="1", angle="90.*deg") # Full path for the file file_path = f"{file_location}/{file_name}" # Write the geometry to the specified file with open(file_path, 'wt') as file: weave( sample_cylinder_beam, file, print_docs=False, renderer=FileIncRenderer(), author='' ) print(f"Sample geometry XML written to {file_path}") # Example usage #generate_sample_geometry_file( # radius=1, # mm # height=1, # mm # file_location="grid_SQ", # Directory location # file_name="sample.xml" # Output file name #) Loading
sample_simulation_mcvine/base/geometry-program.py 0 → 100644 +52 −0 Original line number Diff line number Diff line import numpy as np from instrument.geometry.pml import weave from instrument.geometry import shapes, operations from instrument.geometry.pml.Renderer import Renderer as base class FileIncRenderer(base): def _renderDocument(self, body): self.onGeometry(body) return def header(self): return [] def footer(self): return [] def end(self): return def sample_cylinder(radius, height, file_location, file_name): """ Generates an XML file for a sample cylinder geometry. Parameters: - radius (float): Radius of the sample cylinder in mm. - height (float): Height of the sample cylinder in mm. - file_location (str): Location where the file will be saved. - file_name (str): Name of the XML file to generate. """ # Define the sample geometry sample_cylinder = shapes.cylinder(radius="{}*mm".format(radius), height="{}*mm".format(height)) sample_cylinder_beam = operations.rotate(sample_cylinder, beam="1", angle="90.*deg") # Full path for the file file_path = f"{file_location}/{file_name}" # Write the geometry to the specified file with open(file_path, 'wt') as file: weave( sample_cylinder_beam, file, print_docs=False, renderer=FileIncRenderer(), author='' ) print(f"Sample geometry XML written to {file_path}") # Example usage #generate_sample_geometry_file( # radius=1, # mm # height=1, # mm # file_location="grid_SQ", # Directory location # file_name="sample.xml" # Output file name #)