BaseModelWrapper

Bases: BlueMathModel

Base class for numerical models wrappers.

Attributes:
  • templates_dir (str) –

    The directory where the templates are stored.

  • templates_name (List[str]) –

    The names of the templates.

  • model_parameters (dict) –

    The parameters to be used in the templates.

  • output_dir (str) –

    The directory where the output files will be saved.

  • env (Environment) –

    The Jinja2 environment.

  • cases_dirs (List[str]) –

    The list with cases directories.

  • cases_context (List[dict]) –

    The list with cases context.

Methods:

Name Description
_check_parameters_type

Check if the parameters have the correct type.

_exec_bash_commands

Execute bash commands.

create_cases_context_one_by_one

Create an array of dictionaries with the combinations of values from the input dictionary, one by one.

create_cases_context_all_combinations

Create an array of dictionaries with each possible combination of values from the input dictionary.

render_file_from_template

Render a file from a template.

write_array_in_file

Write an array in a file.

copy_files

Copy file(s) from source to destination.

build_cases

Create the cases folders and render the input files.

run_cases

Run the cases.

run_model

Run the model for a specific case (abstract method).

__init__(templates_dir, templates_name, model_parameters, output_dir, default_parameters=None)

Initialize the BaseModelWrapper.

Parameters:
  • templates_dir (str) –

    The directory where the templates are stored.

  • templates_name (list) –

    The names of the templates.

  • model_parameters (dict) –

    The parameters to be used in the templates.

  • output_dir (str) –

    The directory where the output files will be saved.

  • default_parameters (dict, default: None ) –

    The default parameters type for the model. If None, the parameters will not be checked. Default is None.

build_cases(mode='all_combinations')

Create the cases folders and render the input files.

Parameters:
  • mode (str, default: 'all_combinations' ) –

    The mode to create the cases. Can be "all_combinations" or "one_by_one". Default is "all_combinations".

copy_files(src, dst)

Copy file(s) from source to destination.

Parameters:
  • src (str) –

    The source file.

  • dst (str) –

    The destination file.

create_cases_context_all_combinations()

Create an array of dictionaries with each possible combination of values from the input dictionary.

Returns:
  • array_of_contexts( list ) –

    A list of dictionaries, each representing a unique combination of parameter values.

create_cases_context_one_by_one()

Create an array of dictionaries with the combinations of values from the input dictionary, one by one.

Returns:
  • array_of_contexts( list ) –

    A list of dictionaries, each representing a unique combination of parameter values.

render_file_from_template(template_name, context, output_filename=None)

Render a file from a template.

Parameters:
  • template_name (str) –

    The name of the template file.

  • context (dict) –

    The context to be used in the template.

  • output_filename (str, default: None ) –

    The name of the output file. If None, it will be saved in the output directory with the same name as the template. Default is None.

run_cases()

Run the cases.

run_model(case_dir) abstractmethod

Run the model.

Parameters:
  • case_dir (str) –

    The directory of the case.

write_array_in_file(array, filename)

Write an array in a file.

Parameters:
  • array (ndarray) –

    The array to be written. Can be 1D or 2D.

  • filename (str) –

    The name of the file.