Utils¶
A few helper functions for users and developer.
-
complex_wrapper(func)[source]¶ Wraps complex valued function into 2 dimensional function for easier handling.
Parameters: func (callable) – Returns: 2dim function handle, taking x = (re(x), im(x) and returning [re(func(x), im(func(x)].
-
create_animation(input_file_mask='', input_file_names=None, target_format='.mp4')[source]¶ Create an animation from the given files.
If no file names are given, a file selection dialog will appear.
Parameters: - input_file_mask (basestring) – file name mask with c-style format string
- input_file_names (iterable) – names of the files
Returns: animation file
-
create_dir(dir_name)[source]¶ Create a directory with name
dir_namerelative to the current path if it doesn’t already exist and return its full path.Parameters: dir_name (str) – Directory name. Returns: Full absolute path of the created directory. Return type: str
-
evaluate_placeholder_function(placeholder, input_values)[source]¶ Evaluate a given placeholder object, that contains functions.
Parameters: - placeholder – Instance of
FieldVariable,TestFunctionorScalarFunction. - input_values – Values to evaluate at.
Returns: numpy.ndarrayof results.- placeholder – Instance of
-
find_roots(function, n_roots, grid, rtol=0, atol=1e-07, show_plot=False, complex=False)[source]¶ Searches roots of the given function in the interval [0, area_end] and checks them with aid of rtol for uniqueness. It will return the exact amount of roots given by n_roots or raise ValueError. It is assumed that functions roots are distributed approximately homogeneously, if that is not the case you should increase the keyword-argument points_per_root.
In Detail py:function:fsolve is used to find initial candidates for roots of f(x). If a root satisfies the criteria given by atol and rtol it is added. If it is already in the list, a comprehension between the already present entries error and the current error is performed. If the newly calculated root comes with a smaller error it supersedes the present entry.
Parameters: - function – Function handle for f(x) whose roots shall be found.
- n_roots – Number of roots to find.
- grid – numpy.ndarray (first dimension should fit the input dimension of the provided func) of values where to start searching.
- rtol – Magnitude to be exceeded for the difference of two roots to be unique f(r1) - f(r2) > 10^rtol.
- atol – Absolute tolerance to zero f(root) < atol.
- show_plot – Shows a debug plot containing the given functions behavior completed by the extracted roots.
Returns: numpy.ndarray of roots.
-
get_inn_domain_transformation_matrix(k1, k2, mode='n_plus_1')[source]¶ Returns the transformation matrix M. M is one part of a transformation
x = My + Ty
where x is the field variable of an interior point controlled parabolic system and y is the field variable of an boundary controlled parabolic system. T is a (Fredholm-) integral transformation (which can be approximated with M).
Parameters: - k1 –
- k2 –
- mode –
Available modes:
- ‘n_plus_1’: M.shape = (n+1,n+1), w = (w(0),...,w(n))^T, w in {x,y}
- ‘2n’: M.shape = (2n,2n), w = (w(0),...,w(n),...,w(1))^T, w in {x,y}
Returns: Transformation matrix M.
Return type: numpy.array
-
get_parabolic_dirichlet_weak_form(init_func_label, test_func_label, input, param, spatial_domain)[source]¶
-
get_parabolic_robin_backstepping_controller(state, approx_state, d_approx_state, approx_target_state, d_approx_target_state, integral_kernel_zz, original_beta, target_beta, trajectory=None, scale=None)[source]¶
-
get_parabolic_robin_weak_form(init_func_label, test_func_label, input, param, spatial_domain, actuation_type_point=None)[source]¶
-
scale_equation_term_list(eqt_list, factor)[source]¶ Temporary function, as long
pyinduct.placeholder.EquationTermcan only be scaled individually. Return a scaled copy of eqt_list.Parameters: - eqt_list (list) – List of
pyinduct.placeholder.EquationTerms - factor (numbers.Number) – Scale factor.
Returns: Scaled copy of
pyinduct.placeholder.EquationTerms (eqt_list).- eqt_list (list) – List of
-
split_domain(n, a_desired, l, mode='coprime')[source]¶ Consider a domain [0,l] which is divided into the two sub domains [0,a] and [a,l] with:
-the discretization l_0 = l/n
-and a partition a+b=l.
respectively k1+k2=n is calculated so that n is odd and a=k1*l_0 is close to a_desired modes:
- ‘force_k2_as_prime_number’: k2 is an prime number (k1,k2 are coprime)
- ‘coprime’: k1,k2 are coprime
- ‘one_even_one_odd’: just meet the specification from the doc (default)
Parameters: - n –
- a_desired –
- l –
- mode –