custEM.misc package¶
Submodules¶
custEM.misc.anomaly_expressions module¶
Created on Mon Jun 13 15:14:20 2016
@author: Rochlitz.R
custEM.misc.misc module¶
@author: Rochlitz.R
-
class
custEM.misc.misc.
DirichletBoundary
(*args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
-
class
custEM.misc.misc.
Ground
(*args, **kwargs)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
-
custEM.misc.misc.
block_print
()[source]¶ Supress all prints in the command prompt until enable_print() is called.
-
custEM.misc.misc.
check_approach_and_file_format
(approach, file_format, path, logger)[source]¶ Utility function that checks if a valid modeling approach is chosen (avoid typos) and if HFD5 format is supported.
- approach, type str
- approach specification (see MOD class)
- file_format, type str or None
- if None, used h5 if supported, otherwise xml for data export
- path, type str
- path to custEM.misc directory, forwarded internally
- ‘h5 or ‘xml’, type str
- file format specification
-
custEM.misc.misc.
check_if_model_exists
(out_name, overwrite, load_existing, logger=None)[source]¶ Utility function that checks if a finite element model already exists, which can either be overwritten or the calculation can be aborted.
- See ‘MOD’ class description
-
custEM.misc.misc.
dump_csr
(fname, values, column_indices, row_pointers, size)[source]¶ Utility function that dumps a PETSCMatrix as a sparse csr-matrix to the hard disc.
- fname, type str
- export name of the matrix without the suffix ‘.csr’
- values, type array
- values of matrix elements
- column_indices, type array
- column indices
- row_pointers, type array
- row_pointers
- size, type int
- size (length) of the square matrix
-
custEM.misc.misc.
enable_print
()[source]¶ Enable prints in the command prompt after block_print() was called.
-
custEM.misc.misc.
get_coordinates
(FS)[source]¶ Return coordinates of a lagrange VectorFunctionSpace as numpy array.
- FS, type class
- FunctionSpaces instance
- xyz, type numpy array
- array or dof coordinates with shape (n, 3)
-
custEM.misc.misc.
logger_print
(logger, lvl, string, val=None, pre_dash=True, post_dash=False, barrier=True, root_only=True)[source]¶ Utility function that prints only from root process in mpi mode.
- logger, type logger from logging module
- default custEM logger
- lvl, type int
- debug_level for custEM code
- string, type str
- string that should be printed
- val = None, various types
- a value that should be printed after the “message”
- pre_dash = True, type bool
- flag that controls if a dashed line shoul be printed before the “message”
- post_dash = False, type bool
- flag that controls if a dashed line shoul be printed before the “message”
- barrier = True, type bool
- enable or disable multi-processing barrier (synchronize mpi processes)
- root_only = True, type bool
- log “message” only with root process or each single one
-
custEM.misc.misc.
make_directories
(r_dir, m_dir, approach, para_dir=None, m_dir_only=False)[source]¶ Initialize the export directories if not existing.
- see MOD class description
- para_dir = None, type str
- if None, the default para_dir is ‘m_dir/_para’; otherwise, the parameter directory will be initializied according to specified path
- m_dir_only = False, type bool
- initialize only the main mesh directory or also the main results directory
-
custEM.misc.misc.
mpi_print
(string, val=None, pre_dash=True, post_dash=False, barrier=True)[source]¶ Utility function that prints only from root process in mpi mode.
- string, type str
- string that should be printed
- val = None, various types
- a value that should be printed after the “message”
- pre_dash = True, type bool
- Flag that controls if a dashed line shoul be printed before the “message”
- post_dash = False, type bool
- Flag that controls if a dashed line shoul be printed before the “message”
- barrier = True, type bool
- Enable or disable multi-processing barrier (synchronize all mpi processes)
-
custEM.misc.misc.
petsc_transfer_function
(source_func, target_func, cache=False, q=None)[source]¶ Build Petsc transfer matrix to interpolate between different meshes in parallel.
Note, this function will crash without error notice if there are more mpi processes used than there are dof in the target mesh.
- source_func, type dolfin function
- data function on source interpolation mesh
- target func, tpye dolfin function
- data function on target interpolation mesh
- fi = 0, type int
- iteration index over frequencies
-
custEM.misc.misc.
read_h5
(mpi_comm, var, fname, counter=None, ri='data')[source]¶ Utility function to write data files in parallel in h5 format.
- mpi_cw, type MPI communicator
- communicator attributes for internal usage, FEniCS version dependent
- var, type dolfin function
- data which should be imported, e.g., the E-field solution E_t_r
- fname, type str
- destination file name, containing also the export path
- counter = None, type int
- specify the index of the data functions if more than one solution (e.g., multiple Tx or times) should be imported from the same h5 file
- ri = ‘data’, type str
- specify a tag to name the data function in the h5 file container; e.g., ‘real’ and ‘imag’ can be used to access both parts of the complex field in the same file, reducing the I/O overhead
-
custEM.misc.misc.
read_paths
(file_name)[source]¶ Utility function that imports the default ‘r_dir’ and ‘m_dir’ attributes for the ‘MOD’ instance from file.
Note, these attributes are always overwritten if the keyword arguments ‘r_dir’ or ‘m_dir’ are set manually by initializing the ‘MOD’ instance with theses keyword arguments.
- file_name, type str
- file name of the file which contains the paths, forwarded internally
- results_dir, type str
- main results directory
- mesh_dir, type str
- main mesh directory
-
custEM.misc.misc.
resort_coordinates
(c1, c2)[source]¶ Resort two arrays with overall identical row entries but different order.
- c1/c2, type numpy_arrays
- two data arrays of shape (n, 3)
- c1_sort and c2_sort, type numpy_arrays
- index arrays which can be used to resort data from array 1 to array 2 and vice versa.
-
custEM.misc.misc.
root_write
(writing_function)[source]¶ Utility function that stores data to file only from root process in mpi mode.
- writing_function, type python function
- a function for writing e.g. data or json files
-
custEM.misc.misc.
run_multiple_serial
(script_name, *serial_args)[source]¶ Utility function which is nearly identical to run_serial. The only difference is that a communicator object ic is returned that can be used for multi-threading of several serial runs.
A synchronisation with all communicators can be foreced from the root process in mpi mode by collecting all communicator objects in a list and by using the “Barrier” and “Disconnect” mpi4py methods before continuing.
- script_name, type str
- name of the python script that should be called in serial
- *serial_args, type python list
- list of input console arguments for the python script
- ic, type MPI intercommunicator object
- communicator object to communicate with spawned process
-
custEM.misc.misc.
run_serial
(script_name, *serial_args)[source]¶ Utility function that calls a script in serial from root process in mpi mode.
- script_name, type str
- name of the python script that should be called in serial
- *serial_args, type python list
- list of input console arguments for the python script
-
custEM.misc.misc.
specify_td_export_strings
(FE)[source]¶ Utility function for specifying time-domain export names.
- FE, type class
- FE approach instance (e.g., E_vector)
- E_str, H_str, mode, type str
- data name suffixes to differ between shut-on and shut-off processes and impulse or step-response modeling with the implicite Euler method
-
custEM.misc.misc.
write_h5
(mpi_comm, var, fname, counter=None, new=True, append=False, close=True, f=None, ri='data')[source]¶ Utility function to write data files in parallel in ‘h5’ format.
- mpi_cw, type MPI communicator
- communicator attributes for internal usage, FEniCS version dependent
- var, type dolfin function
- data which should be exported, e.g., the E-field solution E_t_r
- fname, type str
- destination file name, containing also the export path
- counter = None, type int
- specify the index of the data functions if more than one solution (e.g., multiple Tx or times) should be stored in the same h5 file.
- new = True, type bool
- open new h5 file, otherwise, continue writing into f
- close = True, type bool
- close h5 file or leave it open for writing further solutions
- f = None, type str
- filename to continue writing in an opened, existing file; this makes only sense if counter is not None or 0
- ri = ‘data’, type str
- specify a tag to name the data function in the h5 file container; e.g., ‘real’ and ‘imag’ can be used to store both parts of the complex field in one file, reducing the I/O overhead
- f, type str
- file name of export file if not closed
custEM.misc.profiler module¶
@author: Rochlitz.R
-
custEM.misc.profiler.
export_config_file
(PP)[source]¶ Write model parameters - mainly MP and FE instance dictionaries - to file in the specified export directory (out_dir) using JSON.
- PP, type class
- PostProcessing instance
-
custEM.misc.profiler.
export_resource_file
(PP)[source]¶ Write consumed computational resources and times to file in the specified export directory (out_dir) using JSON.
- PP, type class
- PostProcessing instance
-
custEM.misc.profiler.
get_logger
(log_level, profiler, out_path)[source]¶ Initialize logger for all custEM prints during simulations. The information in the command promt will be printed corresponding to the specified debug_level level in the MOD class. Furthermore, a log file is stored in the export directory of the results if profiler=True, using always the debug level for the log files.
- log_level, type str or int
- specify log_level, see MOD class description
- profiler, type bool
- flag to set if log-field should be created or not
- out_path, type bool
- path where log-file should be created
-
custEM.misc.profiler.
max_mem
(total=True, to_store=False, logger=None, fmt='GiB')[source]¶ Print the maximum memory requirements, either for each MPI process or in total.
- total=True, type bool
- Flag if memory consumption should be printed in total or per process
- to_store = False, type bool
- set True if value should be returned
custEM.misc.pyhed_calculations module¶
@author: Rochlitz.R
-
class
custEM.misc.pyhed_calculations.
PHC
(config_file)[source]¶ Bases:
object
PyhedCalculations (PHC) class for reference solution calculated with pyhed sub-module of COMET library.
- calc_reference()
- calucalte semi-analytic reference solution for given 1D CSEM setup-
Load a config file (JSON format) from a custEM modeling to obtain the Tx information and calculate results for E and/or H on specified coordinates.
>>> from custEM.misc import pyhed_calculations as ph >>> calculator = ph.PHC("CONFIG_FILE") >>> calculator.calc_reference(np.array([0., 100., 0.]), 'EH', max_procs=4)
-
calc_reference
(coords, EH, freq=None, max_procs=1)[source]¶ Calculate semi-analytic reference solution for 1D CSEm setups.
- coords, type array of shape (:, 3)
- array of target coordinates
- EH, type str
- specify either ‘E’ for electric or ‘H’ for magnetic fields
- max_procs = 1, type int
- allowed number of processes for pyhed internal multiprocessing
custEM.misc.synthetic_definitions module¶
@author: Rochlitz.R
-
custEM.misc.synthetic_definitions.
almost_flat_topo
(x, y, h=0.1)[source]¶ Almost flat topo specified as function for mesh generation tests.
-
custEM.misc.synthetic_definitions.
anti_cone_bathy
(x, y, h=1000.0, z=0.0)[source]¶ Example topography with a cone hole for testing bathy-tools.
-
custEM.misc.synthetic_definitions.
borehole_tx
()[source]¶ Description of Tx grounded in two different boreholes.
-
custEM.misc.synthetic_definitions.
cone_bathy
(x, y, h=1000.0, z=0.0)[source]¶ Example topography with a cone hill for testing bathy-tools.
-
custEM.misc.synthetic_definitions.
double_cone_bathy
(x, y, h=1000.0, sigma=1.0, zl=0.0)[source]¶ Example topography with two cones for testing bathy-tools.
-
custEM.misc.synthetic_definitions.
example_2_loop_tx
()[source]¶ Crooked loop Tx description for frequency-domain example 2
-
custEM.misc.synthetic_definitions.
example_4_topo_cos_sin
(x, y, h=200.0)[source]¶ Example topography for frequency-domain example 4, x- and y-directed cosine/sine topography.
-
custEM.misc.synthetic_definitions.
flat_topo
(x, y, h=0.0)[source]¶ Flat topo specified as function for implementation tests.
-
custEM.misc.synthetic_definitions.
gaussian_topo
(x, y, h=3000000000.0, sigma=1000.0, z=0.0, x_off=0.0, y_off=0.0)[source]¶ Example topography with hill descriped as gaussian function.
-
custEM.misc.synthetic_definitions.
gaussian_topo_hole
(x, y, h=3000000000.0, sigma=1000.0, x_off=0.0, y_off=0.0)[source]¶ Example topography with hole descriped as gaussian function.
-
custEM.misc.synthetic_definitions.
pyramid_topo
(x, y, h=1000.0, slope=1.0, z_off=0.0, x_off=0.0, y_off=0.0)[source]¶ Pyramid-shaped topography.
-
custEM.misc.synthetic_definitions.
roof_topo
(x, y, h=1000.0, slope=1.0, z_off=0.0, x_off=0.0, ylim=[-1000.0, 1000.0])[source]¶ Pyramid-shaped topography with cutted top (roof).
-
custEM.misc.synthetic_definitions.
sample_topo_func
(x, y, h=100.0)[source]¶ Example sine topography for test scripts.
-
custEM.misc.synthetic_definitions.
subtopo_func1
(x, y, h=200.0)[source]¶ Example sine-shaped subsurface topography in x-direction.
-
custEM.misc.synthetic_definitions.
subtopo_func2
(x, y, h=0.1)[source]¶ Slope of subsurface layer in y-direction.
-
custEM.misc.synthetic_definitions.
surface_anomly_outcrop_1
()[source]¶ Example outcrop polygon for surface anomaly.
-
custEM.misc.synthetic_definitions.
surface_anomly_outcrop_2
()[source]¶ Example outcrop polygon for surface anomaly.
-
custEM.misc.synthetic_definitions.
surface_anomly_outcrop_3
()[source]¶ Example outcrop polygon for surface anomaly.
-
custEM.misc.synthetic_definitions.
topo_func1
(x, y, h=100.0)[source]¶ Example cosine-topography in y-direction.
-
custEM.misc.synthetic_definitions.
topo_func3
(x, y, h=200.0)[source]¶ Example sine-topography in y-direction.
Module contents¶
misc¶
Submodules:
- misc for general utility functions used in all submodules
- profiler for analysing model and performance statistics
- pyhed_calculations for calling pyhed
- synthetic_definitions for defining supporting python functions
- anomaly_expressions for defining anomalies with FEniCS, deprecated