get_current_datetime_as_string[source]

get_current_datetime_as_string()

Determines and returns a string containing the current date and time.

create_dir[source]

create_dir(name:str, path:str='.', prepend_date:bool=False)

Creates a new directory, optionally prepended with the current datetime. If the directory already exists, then nothing happens. Returns a string that is the path to the directory.

Type Default Details
name str The name of the directory that should be created.
path str . The path where the directory should be created.
prepend_date bool False Whether to preprend the directory name with the date and time of its creation. Ensures unique directory names.

save_dict_as_txt[source]

save_dict_as_txt(my_dict:dict, dir_path:str, file_name:str)

Saves a python dictionary as a txt file.

Type Default Details
my_dict dict The dictionary that should be saved.
dir_path str The path where the directory should be saved.
file_name str The name of the txt file that should be created.

cast_to_problem[source]

cast_to_problem(problem_or_solution:Union[ForwardRef('dl4to.problem.Problem'), ForwardRef('dl4to.solution.Solution')])

Accepts a problem or a solution object as input and returns a problem. If the input is a problem, then the problem is simply returned without modification. If it is a solution, then solution.problem is returned.

Type Default Details
problem_or_solution typing.Union[ForwardRef('dl4to.problem.Problem'), ForwardRef('dl4to.solution.Solution')] A problem or solution object.

cast_to_solution[source]

cast_to_solution(problem_or_solution:Union[ForwardRef('dl4to.problem.Problem'), ForwardRef('dl4to.solution.Solution')])

Accepts a problem or a solution object as input and returns a solution. If the input is a problem, then problem.trivial_solution. If the input is a solution, then it is simply returned without modification.

Type Default Details
problem_or_solution typing.Union[ForwardRef('dl4to.problem.Problem'), ForwardRef('dl4to.solution.Solution')] A problem or solution object.

cast_to_problems[source]

cast_to_problems(problems_or_solutions:list)

Accepts as input a list containing problem and solutions object. Returns a list that only contains problem objects, where the solution objects have been transformed into problems via solution.problem.

Type Default Details
problems_or_solutions list A list containing problem and solution objects.

cast_to_solutions[source]

cast_to_solutions(problems_or_solutions:list)

Accepts as input a list containing problem and solutions object. Returns a list that only contains solution objects, where the problem objects have been transformed into solutions via problem.trivial_solution.

Type Default Details
problems_or_solutions list A list containing problem and solution objects.

get_dataloader[source]

get_dataloader(dataset:dl4to.datasets.TopoDataset, batch_size:int=1, shuffle:bool=True, num_workers:int=0)

Returns a torch.utils.data.DataLoader object for dataset.

Type Default Details
dataset dl4to.datasets.TopoDataset The dataset for which the dataloader should be created.
batch_size int 1 The batch size for the dataloader.
shuffle bool True Whether the dataloader should shuffle the samples.
num_workers int 0 The number of GPU workers, if trained on a GPU.

get_σ_vm[source]

get_σ_vm(σ:Tensor, ε:float=1e-09)

Calculates the von Mises stresses from the 9-channel stress tensor σ and returns them in a 1-channel torch.Tensor object.

Type Default Details
σ Tensor The stress tensor from which the von Mises stresses should be computed.
ε float 1e-09 A small value that ensures numerically stable results.