Equation Manager

Python module for an equation manager.


Detailed Class Documentation

class antares.eqmanager.kernel.eqmanager.EqManager(modeling)

Class of Equation Manager.

Kernel of formula management.

__init__(modeling)

Constructor.

Parameters

modeling (str) – The name of a set of equations. This modeling contains equations that can be found in the directory that has the same name under the directory named formula. eg: the modeling internal must be in the directory formula

Variables
  • _models (dict) – The dictionary that contains all modeling. A modeling is a dictionary with the key files. The value of the key files is a list of filenames (without extension) in which the functions are defined.

  • _results (dict) – Store the result of each computed formula to avoid recomputation.

  • _functions (dict) –

    The function dictionary has keys functions and args. The value of the key functions is a python function object. The value of the key args is a list of input names that are the arguments of the function.

    ex: {'c':  {'function': <function ...>,
                'args': ['ro', 'psta', 'gamma']}}.
    

model

Store the current modeling of the computer.

Type

str or None

results(name)

Return the result of the formula.

Parameters

name (str) – The name of a variable.

remove_result(elt)

Remove an element from the stored results.

Parameters

elt (tuple(str, str)) – Formated variable name.

remove_results(safe=None)

Remove all the stored results except those given as args.

Parameters

safe (list(tuple(str, str))) – Protected variable names.

add_located_input(inputs)

Add inputs that will be used in a known formula.

Parameters

inputs (dict) – Set of items to consider as inputs.

ex: inputs = {(‘ro’, ‘node’): array([ 1.3, 1.3]),

(‘roE’, ‘node’): array([ 253312.5, 259812.5])}

add_input(**kwargs)

Add an input that will be used in a known formula.

Parameters

inputs (depend on each value.) – Set of items to consider as inputs.

get_str_computed_formulae()

Return a string with known formulae.

get_list_computed_formulae()

Return the list of computed formulae.

get_str_formula_names()

Return a string with known formula names.

get_list_formula_names()

Return the list of known formula names.

get_formula_name_synonyms()

Return the synonyms of known formula names.

get_computable_formulae()

Return a string with computable formulae.

change_model(modeling, species_database=None)

Change the modeling of the equation manager.

Parameters

modeling (str) – The name of a set of equations.

set_formula(formula)

Set a new formula in the modeling.

Parameters

formula (str) – The name of the new formula.

Operations available are in _numpy_operators.

add_function(new_func)

Set a new function in the modeling.

Parameters

new_func (func) – a python function.

compute(variable)

Get the result of the given variable.

Launch computation if needed.

Parameters

variable (tuple(str, str)) – The name and the location of the variable to compute.

Returns

The value of the formula.

Return type

Depending on the formula.

_handle_syn(missing_var, loc)

Perform operations to use synonyms of input variables.

Parameters
  • missing_var (list(var)) – The name of variables that have not been found so far.

  • loc (str in ['node', 'cell']) – The location of the variables.

Returns

True if no variables are missing (false otherwise).

Return type

bool

_check_formula(formula, checked_vars=None)

Check if all dependencies of the given formula are available.

Parameters

formula (function or str) – The formula function or the formula name to be checked.

Returns

True if the formula can be computed (false otherwise), and the missing formula/var values.

Return type

bool, list(str)

_compute(formula, loc)

Return the value of the given formula computation.

Launch computation of dependencies if needed.

Parameters
  • formula (:obj: function) – The formula to compute.

  • loc (str in ['node', 'cell']) – The location of the variable.

Returns

The value of the computation.

Return type

Depending on the formula.

_store_function(name, obj)

Store the function object in the dictionary.

Parameters
  • name (str) – Name of the function.

  • obj (:obj:function) – Function object.

  • container (dict) – Dictionary of functions.

_create_function_from_string(equation)

Create a function object from a string.

Parameters

equation (str) – The literal expression of the equation.

_find_var_and_symbols(equation)

Find variables and symbols needed by the equation.

Parameters

equation (str) – The literal expression of the equation.

_load_species_data(needed_vars)

Load species database.

Parameters

needed_vars (list(str)) – Names of variables.

_get_all_formula_dependencies(formula)

Get all dependencies of the formula.

Parameters

formula (str) – The formula name.

Returns

The list of variables used to compute the formula.

Return type

list(str)


Equation Modeling

Python module for the modeling of equations.

A modeling is defined as a set of equations governing a flow or any other physical phenomenon.

As example, you can defined a modeling incompressible that will contain all the equations you choose to define this physics.

Equation files

Functions of a particular modeling are defined in files in a path associated this modeling. e.g.: equations.py in formula/internal contains the functions associated to the modeling internal.

Functions

Each function defines a variable or a set of variables.

  • If it is a single variable, then the name of the function is the name of the variable.

e.g.:

def u(rhou, rho):
    return rhou/rho
  • If it is a set of variables, then the name of the function is simply a name.

e.g.:

def cons_abs(rhov, rhow):
    return {'rhov': rhov,
            'rhow': rhow}

The body of the function can be as complex as you want. You can query databases, read files, perform Newton algorithms, etc.

The arguments of the function are either variable names or function names.


Detailed Class Documentation

class antares.eqmanager.kernel.eqmodeling.EqModeling

Class of EqModeling.

This class read and store all modeling available.

__init__()

Constructor.

Variables

_models (dict) – Store all modeling information. The dictionary that contains all equation modeling. A particular modeling is a dictionary with the keys files. The value of the key files is a list of filenames (without extension) in which the functions are defined.

_load_formula()

Read all formula files (python files).

Read all files that include a function definition.

Return models

The dictionary that contains all equation modeling.

  • At the input, a modeling is a dictionary with the key files. The value of the key files is a list of filenames (without extension) in which the functions are defined.

  • At the output, a modeling has also key functions and synonyms. The value of the key functions is a dictionary with the keys corresponding to the name of each function of the modeling. Each function name corresponds to a dictionary with a key function and a value of a function object. The value of the key synonyms is a dictionary with the keys corresponding to the name of each variable that have been chosen to write the equations of the modeling. Each variable name corresponds to a dictionary of synonyms.

Rtype models

dict

At the input:
  {'compressible':   {'files': ['equations', 'complement_1']},
   'incompressible': {'files': ['equations']}}
At the output:
  {'compressible':
      {'files': ['equations', 'complement_1'],
       'functions': {'c': {'function': <function c at 0x>},
                     'Cp': {'function': <function Cp at 0x>},
                     'E': {'function': <function E at 0x>}}},
   'incompressible':
      {'files': ['equations'],
       'functions': {'c': {'function': <function c at 0x>},
                     'u': {'function': <function u at 0x>}}}}