Skip to content

CLI

Usage

cli-ouput

Command: mpcforces-extractor extract

The main command is the extract command. This command will extract the mpc forces from the mpcf file and will output the summed up forces per connected part. The ouptput will be a text file with the summed up forces per connected part.

Additionally the tcl code needed for visualizing the connected parts in HyperMesh will be generated. The tcl code will be saved in the same directory as the output file in the subfolder tcl-visualization.

The command wants you to provide the path to the .fem model file as well as the path to the .mpcf file. Lastly, the output file path is needed. The blocksize is optional and is needed for reading the files. The default value is 8 (8 chars per field in line). For long ouptut it is recommended to increase the blocksize to 16 (not tested).

Command: mpcforces-extractor visualize

The command visualize visualizes the connected parts in HyperMesh. The command wants you to provide the path to the .fem model file as well as the path to the output directory. The tcl file is the output of the extract command. Know issue: If a compornent in the hypermesh model is named part1, part2, etc. the tcl script might not work as intended. This is due to the fact that the tcl script is using the part name to create the groups.

Source Code

extract

Extracts the mpc forces and also writes the tcl lines for visualization

Source code in mpcforces_extractor\cli\extract.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@extractor_cmd.callback()
def extract(
    input_path_fem: str = typer.Argument(..., help="Path to the .fem file (model)"),
    input_path_mpcf: str = typer.Argument(..., help="Path to the .mpcf file"),
    output_path: str = typer.Argument(..., help="Path to the output folder"),
    blocksize: int = typer.Option(8, help="Blocksize for the MPC forces"),
):
    """
    Extracts the mpc forces and also writes the tcl lines for visualization
    """

    # Check if the files exist, if not raise an error
    if not Path(input_path_fem).exists():
        raise FileNotFoundError(f"File {input_path_fem} not found")
    if not Path(input_path_mpcf).exists():
        raise FileNotFoundError(f"File {input_path_mpcf} not found")

    # Extract the forces
    mpc_force_extractor = MPCForceExtractor(
        input_path_fem, input_path_mpcf, output_path
    )
    mpc_force_extractor.build_fem_and_subcase_data(blocksize)

    # Write Summary
    summary_writer = SummaryWriter(
        mpc_force_extractor, mpc_force_extractor.output_folder
    )
    summary_writer.add_header()
    summary_writer.add_mpc_lines()
    summary_writer.write_lines()

visualize

Visualizes the connected parts of the model by moving them into separate components

Source code in mpcforces_extractor\cli\visualize.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@visualize_cmd.callback()
def visualize(
    input_path_fem: str = typer.Argument(..., help="Path to the .fem file (model)"),
    output_path: str = typer.Argument(..., help="Path to the output folder"),
    blocksize: int = typer.Option(8, help="Blocksize for the MPC forces"),
):
    """
    Visualizes the connected parts of the model by moving them into separate components
    """

    # Check if the files exist, if not raise an error
    if not Path(input_path_fem).exists():
        raise FileNotFoundError(f"File {input_path_fem} not found")

    # Visualize the connected parts
    start_time = time.time()
    output_vis = os.path.join(output_path, "tcl_visualization")

    # Read the fem file
    reader = FemFileReader(input_path_fem, blocksize)
    reader.create_entities()

    # Visualize
    visualizer = VisualizerConnectedParts(output_vis)
    visualizer.output_tcl_lines_for_part_vis()

    print("TCL visualization lines written to", output_vis)
    print("..took ", round(time.time() - start_time, 2), "seconds")