abaqus_batch_pack.strategies module

class abaqus_batch_pack.strategies.ExtractionStrategy[source]

Bases: ABC

ExtractionStrategy defines how to extract results from the simulation.

abstract extract(context: AbaqusCalculation) dict[source]

Execute the extraction logic and return a dictionary of results.

class abaqus_batch_pack.strategies.InpModifyStrategy(base_inp_path, data_params)[source]

Bases: PreparationStrategy

Prepare the job by modify a current INP file.

Properties in the INP file must be defined as placeholders like {{property_name}}.

base_inp_path

The path to the base INP file.

Type:

str

data_params

A dictionary of parameters to replace in the INP file.

Type:

dict

Example INP file:
*MATERIAL, NAME=STEEL
*ELASTIC
{{youngs_modulus}}, 0.3
*SOLID SECTION, ELSET=TRUSS, MATERIAL=STEEL
1.0
*STEP, NAME=Step-1
*STATIC
*BOUNDARY
1, 1, 3, 0.
*CLOAD
2, 1, {{load_magnitude}}
prepare(context: AbaqusCalculation) bool[source]

Generate one INP file in context.output_dir

class abaqus_batch_pack.strategies.JobWorkflowStrategy[source]

Bases: ABC

Defines the interface for job workflow strategies.

abstract execute(context: AbaqusCalculation) dict[source]

Execute the complete workflow and return a dictionary of results.

class abaqus_batch_pack.strategies.ModelGenerationStrategy(model_script_path, script_params)[source]

Bases: PreparationStrategy

Prepare the job by running a model generation script. This script should generate an INP file in the context.output_dir.

model_script_path

The path to the model generation script.

Type:

str

script_params

A dictionary of parameters to pass to the script.

Type:

dict

prepare(context: AbaqusCalculation) bool[source]

Generate one INP file in context.output_dir

class abaqus_batch_pack.strategies.ModelPropertiesExtractionStrategy(hooks)[source]

Bases: ExtractionStrategy

Extract results from INP files using user-defined scripts.

Execution Environment:
  • abaqus cae noGui=…

  • python (if abaqpy is installed)

Command-line Interface:
  • Use argparse to parse arguments

  • Required:
    • –inp_path

    • –tasks_json

Standard Output:
  • Use sys.__stdout__.write(json.dumps(result)) to redirect output

Example

import argparse, sys
from abaqus import mdb

if __name__ == "__main__":
        parser = argparse.ArgumentParser()
        parser.add_argument('--inp_path', type=str, required=True)
        parser.add_argument('--tasks_json', type=str, required=True)

        # ... add your custom args like --node_label ...
        args, unknown = parser.parse_known_args()
        extract_with_your_script(args.inp_path, args.tasks_json, **kwargs)

def extract_with_your_script(inp_path, tasks_json, **kwargs):
        try:
                with open(tasks_json_path, 'r', encoding='utf-8') as f:
                        task_list = json.load(f)

                mdb.ModelFromInputFile()

                for task in task_list:
                        result_name = task['result_name']
                        try:
                                results[result_name] = 123.45
                        except Exception as e:
                                results[result_name] = None
                                sys.__stderr__.write(f"  - Sub-task '{result_name}' failed: {e}\n")

                mdb.close()
                sys.__stdout__.write(json.dumps(results, indent=4) + "\n")

        except Exception as e:
                sys.__stderr__.write(f"Fatal error in xxxx.py: {e}\n")
                sys.exit(1)
extract(context: AbaqusCalculation) dict[source]

Execute the extraction logic and return a dictionary of results.

class abaqus_batch_pack.strategies.ModularWorkflowStrategy(preparation_strategy: PreparationStrategy, pre_extraction_strategies: List[ExtractionStrategy], post_extraction_strategies: List[ExtractionStrategy])[source]

Bases: JobWorkflowStrategy

ModularWorkflowStrategy is designed to handle complex workflows by separating preparation, job execution and extraction into distinct strategies.

Module:

  • Preparation: Prepare the job and export an INP file ready for Abaqus.

  • Execution: Run the Abaqus job using the prepared INP file.

  • Extraction: Extract results from INP/ODB file after the job is complete.

execute(context: AbaqusCalculation) dict[source]
Parameters:

context (AbaqusCalculation) – A AbaqusCalculation instance

Returns:

Dict including results/errors

Return type:

dict

class abaqus_batch_pack.strategies.MonolithicWorkflowStrategy(script_path, params)[source]

Bases: JobWorkflowStrategy

MonolithicWorkflowStrategy suites for simple tasks where all operations can be handled in a single script.

Operations include: - Create part - Create materials - Create section - Create assembly - Create step - Create load - Create mesh - Run Abaqus job - Extract results

Refer to the Cantilever Example for more details.

Execution Environment:
  • Run with abaqus cae noGUI= or python (if abaqpy is installed)

Command-Line Interface:
  • Must use argparse to parse arguments

  • Must accept a –job_name argument passed by the framework, and use it as the name of the Abaqus Job (mdb.Job(name=…))

  • May accept any custom arguments (e.g. –length, –height, etc.)

Standard Output (stdout):
  • Must be the only way to return results to the framework

  • On successful execution, print a single valid JSON string

  • It is recommended to include a “status”: “COMPLETED” key in the JSON

Example

import argparse, json, sys, abaqus

parser = argparse.ArgumentParser()
parser.add_argument('--job_name', required=True)
# --- Add your own arguments ---
parser.add_argument('--my_param', type=float, required=True)
args = parser.parse_args()

try:
        # 1. Abaqus modeling...
        # 2. Create and run job with args.job_name
        mdb.Job(name=args.job_name, ...)
        mdb.jobs[args.job_name].submit()
        mdb.jobs[args.job_name].waitForCompletion()
        # 3. Open ODB and post-process...
        results = {'status': 'COMPLETED', 'my_result': 123.45}
        # 4. Print JSON result
        print(json.dumps(results))
except Exception as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)
execute(context: AbaqusCalculation) dict[source]
Parameters:

context (AbaqusCalculation) – A AbaqusCalculation instance

Returns:

Dict including results/errors

Return type:

dict

class abaqus_batch_pack.strategies.OdbExtractionStrategy(hooks)[source]

Bases: ExtractionStrategy

Extract results from ODB files using user-defined scripts.

Execution Environment:
  • abaqus python

  • python (if abaqpy is installed)

Command-line Interface:
  • Use argparse to parse arguments

  • Required:
    • –odb_path: Path to the ODB file

    • –tasks_json: Path to a JSON file containing tasks to extract

Standard Output:
  • Use sys.__stdout__.write(json.dumps(result)) to redirect output

Example

import argparse, sys, json
import odbAccess

if __name__ == "__main__":
        parser = argparse.ArgumentParser()
        parser.add_argument('--odb_path', type=str, required=True)
        parser.add_argument('--tasks_json', type=str, required=True)

        # ... add your custom args like --node_label ...
        args, unknown = parser.parse_known_args()
        extract_with_your_script(args.odb_path, args.tasks_json, **kwargs)

def extract_with_your_script(odb_path, tasks_json, **kwargs):
        try:
                # Retrieve tasks
                with open(tasks_json_path, 'r', encoding='utf-8') as f:
                        task_list = json.load(f)

                odb = odbAccess.openOdb(args.odb_path)

                for task in task_list:
                        result_name = task['result_name']
                        try:
                                results[result_name] = 123.45
                        except Exception as e:
                                results[result_name] = None
                                sys.__stderr__.write(f"  - Sub-task '{result_name}' failed: {e}\n")

                odb.close()
                sys.__stdout__.write(json.dumps(results, indent=4) + "\n")

        except Exception as e:
                sys.__stderr__.write(f"Fatal error in xxxx.py: {e}\n")
                sys.exit(1)
extract(context: AbaqusCalculation) dict[source]

Execute the extraction logic and return a dictionary of results.

class abaqus_batch_pack.strategies.PreparationStrategy[source]

Bases: ABC

PreparationStrategy prepares the job with generating an INP file.

abstract prepare(context: AbaqusCalculation) bool[source]

Generate one INP file in context.output_dir