pyrrha package¶
Subpackages¶
Submodules¶
pyrrha.constants module¶
Constants definitions.
pyrrha.method module¶
Public module.
-
class
pyrrha.method.
FiniteElement2D
¶ Bases:
pyrrha.method.Method
Class to instance Method.
class to define a specific Numerical Method.
-
gen_system
(K, C, F, x_node, icone, model)¶ Assembling elementary contribution.
- Parameters
K (float matrix) – K diffusion matrix of the system.
C (float matrix) – C mass matrix of the system.
F (float array) – F vector of the system.
x_node (float matrix) – mesh nodes coordinates.
icone (int matrix) – mesh connectivity elements.
model (dictionary) – constants of the physical model.
- Returns
K (float matrix) – final diffusion matrix.
C (float matrix) – final mass matrix.
F (float vector) – final model independent vector.
-
classmethod
get_initial_values
(seed=None)¶ Create a dictionary containing random values array.
- Parameters
seed – seed for the random arrays/numbers generator.
- Returns
dictionary with random value.
-
classmethod
get_pipeline
()¶ Return tuple of implemmented method with their parameters.
-
abstract
heat_dirichlet
(K, F, dirichlet)¶ Abstract method to apply the Dirichlet condition.
The Dirichlet conditions are applied to modify the K matrix and F vector of de system based in data Dirichlet matrix.
- Parameters
K (float matrix) – K matrix of the system.
F (float array) – F vector of the system.
dirichlet (float matrix) – data dirichlet matrix.
- Returns
- Return type
modified K maxtrix and F vector
-
abstract
heat_initialize
(n_nodes)¶ Abstract method to initialize the matrix and vector of the system.
- Parameters
n_nodes (int) – number of mesh noodes.
- Returns
matrix K with n_nodes rows and n_nodes columns and vector F with
n_nodes rows.
-
abstract
heat_neumann
(F, neumann, x_node)¶ Abstract method to apply the Neumann condition.
The Neumann conditions are applied to modify the F vector of de system based in data Neumman matrix.
- Parameters
F (float array) – F vector of the system.
neumann (float matrix) – data Neumann matrix.
x_node (float matrix) – mesh nodes coordinates.
- Returns
- Return type
modified F vector
-
heat_pcond
(F, x_node, icone, pun)¶ Apply point source.
- Parameters
F (float array) – F vector of the system.
x_node (float matrix) – mesh nodes coordinates.
icone (int matrix) – mesh connectivity elements.
pun (float matrix) – heat source puntual data matrix.
- Returns
F – model independent vector.
- Return type
float vector
-
abstract
heat_robin
(K, F, robin, x_node)¶ Abstract method to apply the Robin condition.
The Robin conditions are applied to modify the K matrix and F vector of de system based in data Robin matrix.
- Parameters
K (float matrix) – K matrix of the system.
F (float array) – F vector of the system.
robin (float matrix) – data Robin matrix.
x_node (float matrix) – mesh nodes coordinates.
- Returns
- Return type
modified K maxtrix and F vector
-
heat_solve
(K, C, F, x_node, icone, model)¶ Solve the direct system equations.
- Parameters
K (float matrix) – K diffusion matrix of the system.
C (float matrix) – C mass matrix of the system.
F (float array) – F vector of the system.
x_node (float matrix) – mesh nodes coordinates.
icone (int matrix) – mesh connectivity elements.
model (dictionary) – constants of the physical model.
- Returns
phi (float vector) – model temperature solution.
q (float matrix) – model flux solution.
-
run
(n_nodes, x_node, icone, model, dirichlet, neumann, robin, pun)¶ Run all steps of the numerical method.
- Parameters
n_nodes (int) – number of mesh noodes.
x_node (float matrix) – mesh nodes coordinates.
icone (int matrix) – mesh connectivity elements.
model (dictionary) – constants of the physical model.
dirichlet (float matrix) – data dirichlet matrix.
neumann (float matrix) – data Neumann matrix.
robin (float matrix) – data Robin matrix.
pun (float matrix) – heat source puntual data matrix
- Returns
k (float matrix) – final diffusion matrix.
c (float matrix) – final mass matrix.
f (float vector) – final model independent vector.
phi (float vector) – model temperature solution.
q (float matrix) – model flux solution.
-
-
class
pyrrha.method.
Method
¶ Bases:
abc.ABC
Abstract Class to implement Numerical Method.
class inherited from ABC
-
abstract classmethod
get_initial_values
(seed=None)¶ Abstract method to initialize the instances with initial values.
- Parameters
seed (int) – optional seed for the random arrays/numbers generator.
- Returns
- Return type
dictionary with random values.
-
abstract classmethod
get_pipeline
()¶ Abstract method to get pipeline.
-
abstract
run
()¶ Abstract method to run all steps of the numerical method.
- Returns
- Return type
vector with phi solution.
-
abstract classmethod
pyrrha.pyrrha module¶
pyrrha Command Line Interface.
-
class
pyrrha.pyrrha.
CLI
¶ Bases:
object
Pyrrha console client.
-
footnotes
= 'MIT License.\nCopyright (c) 2020.\nDiego Sklar, Constanza Quaglia, Franco Matzkin.'¶
-
generate
(base, output='')¶ Generate template from given base class.
- Parameters
output (str) – The name of the generated class
base (str) – The name of the base file
-
get_commands
()¶ Return CLI commands.
- Returns
Typer app with the valid CLI commands
- Return type
Typer
-
validate
(file, method=None)¶ Validate implemented class or method.
- Parameters
file (str) – Implementation file path.
method (str (optional)) – Method name to validate.
- Returns
Report with the validation info.
- Return type
-
version
()¶ Print pyrrha version.
-
-
pyrrha.pyrrha.
main
()¶ Run the pyrrha CLI interface.
pyrrha.report module¶
Report handling.
-
class
pyrrha.report.
Report
¶ Bases:
object
Report class.
Store and show the status of pyrrha validations.
-
add_error_type
(method_name, pos=0)¶ Add error type result to the report.
- Parameters
method_name (str) – Name of the executed method.
pos (int) – Position in the output tuple.
-
add_shape_error
(method_name, pos=0)¶ Add shape error result to the report.
- Parameters
method_name (str) – Name of the executed method.
pos (int) – Position in the output tuple.
-
add_success
(method_name, pos=0)¶ Add successful result to the report.
- Parameters
method_name (str) – Name of the executed method.
pos (int) – Position in the output tuple.
-
add_value_error
(method_name, pos=0)¶ Add value error result to the report.
- Parameters
method_name (str) – Name of the executed method.
pos (int) – Position in the output tuple.
-
pyrrha.runner module¶
Runner class for method/class comparison.
The Runner class allows to compare two different implementations of a certain abstract class, by comparing a particular method only, or the whole set of abstract methods that need to be implemented.
-
class
pyrrha.runner.
Runner
(programmed_class, implementations, seed=None)¶ Bases:
object
Load the implementation of a certain class looking its inheritance.
- Parameters
programmed_class (Method) – Implementation of a base class.
implementations (dict) – Dictionary containing the base classes as keys and the correct implementations as values.
seed (int) – Seed for the random generation.
-
implementations
¶ Implementations of the base class for comparing with the programmed classes.
- Type
dict
-
base_method
¶ Parent of programmed_class
- Type
class
-
method_impl
¶ Sibling of programmed_class, which will be used for comparing.
- Type
class
-
values
¶ Dictionary of initial arrays used for testing the classes methods.
- Type
dict
-
compare_elements
(e_p, e_i, method_name, pos=0)¶ Compare outputs elements and save to report.
Compare elements from two methods outputs directly. They can be arrays or numbers. This function is meant to be called from compare_results, in where tuple checks are also performed. The results will be stored in self.report.
- Parameters
e_p (Output of the programmed class.) –
e_i (Output of the implementation.) –
method_name (Method to test.) –
pos (Position in the output tuple (zero if it doesn't come from a) –
tuple) –
-
compare_method_with_impl
(method_name, args)¶ Run the same method in both implementations and compare results.
Given a particular method and its args, check both implementations results. The result will be stored in self.report.
- Parameters
method_name (Implemented method.) –
args (List of strings containing the method arguments.) –
-
compare_results
(res_p, res_i, method_name)¶ Compare two outputs depending of its type.
From both implementations outputs, compare types, shapes and values and save the comparison statuses in the report.
- Parameters
res_p (Output of the programmed class.) –
res_i (Output of the implementation.) –
method_name (Compared method.) –
-
static
error_type
(res_p, res_i)¶ Type error output checking.
Compare types and tuple lenghts of the outputs and return True if they are not the same.
- Parameters
res_p (Programmed class output.) –
res_i (Implemented class output.) –
- Returns
True if the dims/shapes aren’t equal.
- Return type
bool
-
search_implementation
(programmed_class)¶ Locate the parent class implementation of a particular class.
Search the parent class implementation in the implementations dictionary.
- Parameters
programmed_class (Programmed class to validate. This Class inherits) –
a base class, that should be present in the implementations (from) –
dictionary. –
- Returns
Tuple containing base class and implementation.
- Return type
tuple
-
validate_class
()¶ Obtain the method pipeline and compare both implementations.
Validate the class comparing all the methods outputs according to the pipeline established in the abstract parent class. The pipeline is a list of tuples composed of the abstract methods, that need to be implemented with their corresponding arguments as a list of strings. The compare_method_with_impl method will be called, which will compare the results of the previously set classes.
- Returns
Report of the comparisons performed
- Return type
-
validate_method
(method_name)¶ Validate a single method against the implementation.
Compare the output of a given implemented method with the output of a previous set implementation. The result will be stored in self.report.
- Parameters
method_name (Method to compare) –
pyrrha.template_generator module¶
Public module.
-
class
pyrrha.template_generator.
TemplateGenerator
¶ Bases:
abc.ABC
Class to generate Template Class of Numerical Method.
class inherited from ABC
-
static
gen_template
(cls)¶ Generate the template according to the class received.
- Parameters
cls (class) – class received.
- Returns
- Return type
string with template generated.
-
static
Module contents¶
Pyrrha.
pyrrha is a tool for helping in the developement and testing of Computational Mechanics methods.