Input and Output
The Input/Output (IO) class is responsible to save and interact with optimization results. Resuls saved include the history of the cost function and the constraints values the simulation mesh, the raw density parameter \(p\), the filtered density parameter \(\bar{p}\) or solver input or output variables.
IO class is a properties of the crafter and is assessed through crafter.IO.
Output
- class HydrOpTop.IO.IO(filename='HydrOpTop', logfile='out.txt', fileformat='vtu')
Default initializer of the Input/Output class.
By default, output optimization results (i.e. density parameter p) in file
HydrOpTop.vtuand keep a trace of the history of the cost function and constraints inHydrOpTop.txt.Methods available:
- correct_dataset_length(X, val_at=None)
Correct X_dataset if not of the size of the mesh. Usable when parametrized cells is lower than the whole mesh If X not linked to val_at (different size), output NaN val_at 0 based
- define_output_file(filename)
- Description:
Define the output file name (without its extension) where to save the optimization results. Extension are automatically added based on output file format chosen (see method
define_output_format)- Parameters:
filename(str): the output file name (default=``”HydrOpTop”`` )
- define_output_format(f)
- Description:
Set the output format.
- Parameters:
f(str): the format. Must be one of["med", "vtu", "xdmf"]
- define_output_log(filename)
- Decription:
Define the output file name (with extension) where the history of the cost function value and constraints are stored.
- Parameters:
filename(str): the filename (default:"out.txt")
- no_output_initial()
- Description:
By default, HydrOpTop output the initial density parameters and other programmed variables. This command cancel this behavior.
- Parameters:
No parameters.
- output_every_iteration(n)
- Decription:
Specify to output the density parameter \(p\) every \(n\) iteration in file and format specified in
define_output_file()anddefine_output_format()methods.- Parameters:
n(int): the iteration interval, ex.n=2for every two iteration.
- output_gradient()
- Description:
Enable writing the gradient of the objective function relative to the density parameter \(p\) in the output file.
- Parameters:
No parameters
- output_gradient_constraints()
- Description:
Enable writing the gradient of the constraints relative to the density parameter \(p\).
- Parameters:
No Parameters
- output_material_properties()
- Description:
Enable writing the material properties at parametrized cells.
- Parameters:
No parameters
- plot_convergence_history(include_constraints=False, save_fig_to=None)
- Description:
Plot the convergence history of the optimization (cost function and constraints)
- Parameters:
include_constraints(bool): Visualize evolution of constraints values (default:False)save_fig_to(str): Save figure to the given file (optional, default: not saved but showed)
- write_fields_to_file(X, filename, Xname=None, at_ids=None)
- Description:
Output the field datas given in the list X using
MeshIOpython library. For a simple datasetxto write, useX=[x].- Parameters:
X(list of numpy array): The list of field datas to outputfilename(str): The name of the output file. Note, the format is deduced from the file extension.Xname(list of str): The dataset names. Must be ordered the same as X.at_ids(numpy array): If the X datasets does not span the whole simulation domain, theat_idsarray give the point/cell ids corresponding to the given data.
Input
Simulation results can be