custemx 0.9.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- custemx/Types table.md +45 -0
- custemx/__init__.py +183 -0
- custemx/custemx_config.json +21 -0
- custemx/fe/__init__.py +38 -0
- custemx/fe/fe_class.py +922 -0
- custemx/fe/fe_forms.py +372 -0
- custemx/fe/fe_lib.py +514 -0
- custemx/fe/primary_fields.py +126 -0
- custemx/inv/__init__.py +15 -0
- custemx/inv/fop_class.py +815 -0
- custemx/inv/inv_class.py +547 -0
- custemx/inv/run_fwd.sh +17 -0
- custemx/inv/run_fwd_from_config.py +42 -0
- custemx/inv/setup_persistent_workers.py +77 -0
- custemx/io/__init__.py +23 -0
- custemx/io/mesh_io.py +481 -0
- custemx/io/misc_io.py +905 -0
- custemx/io/mt_edi_io.py +537 -0
- custemx/io/result_io.py +326 -0
- custemx/meshtools/__init__.py +25 -0
- custemx/meshtools/bathy_tools.py +1109 -0
- custemx/meshtools/dem_interpolator.py +347 -0
- custemx/meshtools/icosphere.py +303 -0
- custemx/meshtools/interface_mesh.py +13 -0
- custemx/meshtools/invmesh_tools.py +391 -0
- custemx/meshtools/mesh_utils.py +186 -0
- custemx/meshtools/meshgen_tools.py +2901 -0
- custemx/meshtools/meshgen_utils.py +1457 -0
- custemx/misc/__init__.py +20 -0
- custemx/misc/decorators.py +206 -0
- custemx/misc/errors.py +57 -0
- custemx/misc/logfile.py +341 -0
- custemx/misc/semi_analytic.py +459 -0
- custemx/misc/tools.py +776 -0
- custemx/misc/unit_test.py +132 -0
- custemx/mod/__init__.py +12 -0
- custemx/mod/mod_class.py +694 -0
- custemx/mod/mp_class.py +541 -0
- custemx/mod/post_proc.py +879 -0
- custemx/plot/__init__.py +11 -0
- custemx/plot/plot_class.py +105 -0
- custemx/plot/plot_lib.py +309 -0
- custemx/solver/__init__.py +12 -0
- custemx/solver/solver_classes.py +859 -0
- custemx-0.9.5.1.dist-info/METADATA +93 -0
- custemx-0.9.5.1.dist-info/RECORD +117 -0
- custemx-0.9.5.1.dist-info/WHEEL +5 -0
- custemx-0.9.5.1.dist-info/top_level.txt +4 -0
- emtools/__init__.py +11 -0
- emtools/base.py +1583 -0
- emtools/csem.py +560 -0
- emtools/modeling.py +52 -0
- emtools/mt.py +612 -0
- emtools/plotting.py +226 -0
- emtools/survey.py +766 -0
- emtools/utils.py +385 -0
- pyhed/IO/__init__.py +29 -0
- pyhed/IO/saveload.py +325 -0
- pyhed/IO/vtk.py +247 -0
- pyhed/__init__.py +157 -0
- pyhed/__version__ +1 -0
- pyhed/apps/app_test.py +46 -0
- pyhed/apps/secondaryFieldCalculation.py +101 -0
- pyhed/apps/secondaryFieldCalculation.sh +45 -0
- pyhed/apps/totalFieldCalculation.py +64 -0
- pyhed/apps/totalFieldCalculation.sh +41 -0
- pyhed/apps/totalFieldInterpolation.py +120 -0
- pyhed/apps/totalFieldInterpolation.sh +45 -0
- pyhed/config.py +453 -0
- pyhed/hed/__init__.py +34 -0
- pyhed/hed/hed_bib.py +966 -0
- pyhed/hed/hed_para.py +178 -0
- pyhed/hed/libHED.py +1448 -0
- pyhed/hed/reference/__init__.py +24 -0
- pyhed/hed/reference/dipole1d.py +362 -0
- pyhed/hed/reference/homogeneous_fullspace.py +69 -0
- pyhed/hed/reference/homogeneous_halfspace.py +134 -0
- pyhed/loop/__init__.py +34 -0
- pyhed/loop/loop_bib.py +5387 -0
- pyhed/loop/loop_para.py +642 -0
- pyhed/misc/__init__.py +54 -0
- pyhed/misc/console_call.py +389 -0
- pyhed/misc/load_save.py +124 -0
- pyhed/misc/matrixWrapper.py +79 -0
- pyhed/misc/mesh_tools.py +169 -0
- pyhed/misc/mpi_tools.py +221 -0
- pyhed/misc/para_lib.py +134 -0
- pyhed/misc/poly_tools.py +148 -0
- pyhed/misc/test_class.py +34 -0
- pyhed/misc/timer.py +149 -0
- pyhed/misc/toolbox.py +553 -0
- pyhed/misc/vec.py +1120 -0
- pyhed/plot/__init__.py +25 -0
- pyhed/plot/plotHankel.py +66 -0
- pyhed/plot/plot_bib.py +935 -0
- pytest/conftest.py +20 -0
- pytest/mwe/11_csem_fwd/mwe_hed.py +44 -0
- pytest/mwe/test_mwe.py +22 -0
- pytest/test_assembly.py +146 -0
- pytest/test_boundary_detection.py +266 -0
- pytest/test_class_init.py +49 -0
- pytest/test_fem_io.py +59 -0
- pytest/test_fwd_emdata.py +207 -0
- pytest/test_get_from_all.py +84 -0
- pytest/test_locate_transmitter.py +49 -0
- pytest/test_logfile_lifecycle.py +391 -0
- pytest/test_mesh_io.py +201 -0
- pytest/test_mesh_utils.py +42 -0
- pytest/test_meshes/minimalistic.h5 +0 -0
- pytest/test_meshes/minimalistic.xdmf +23 -0
- pytest/test_meshes/minimalistic_para.json +102 -0
- pytest/test_meshgen_cylinder.py +38 -0
- pytest/test_mp_io.py +170 -0
- pytest/test_mt_edi_io.py +114 -0
- pytest/test_multi_fwd.py +75 -0
- pytest/test_multiclass.json +53 -0
- pytest/test_petsc_prefix_stack.py +97 -0
custemx/Types table.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Types table
|
|
2
|
+
|
|
3
|
+
# Numpy
|
|
4
|
+
np.ndarray:
|
|
5
|
+
Numpy Array
|
|
6
|
+
|
|
7
|
+
# Petsc
|
|
8
|
+
petsc4py.PETSc.Mat
|
|
9
|
+
System matrix
|
|
10
|
+
|
|
11
|
+
petsc4py.PETSc.Vec
|
|
12
|
+
Right hand side
|
|
13
|
+
|
|
14
|
+
# dolfinx
|
|
15
|
+
dfx.mesh.Mesh
|
|
16
|
+
Dolfinx Mesh
|
|
17
|
+
|
|
18
|
+
dfx.mesh.MeshTags
|
|
19
|
+
Marker for a mesh
|
|
20
|
+
|
|
21
|
+
dfx.fem.Constant
|
|
22
|
+
Constant function on a mesh
|
|
23
|
+
|
|
24
|
+
dfx.fem.FunctionSpace
|
|
25
|
+
Function space for dof definition
|
|
26
|
+
|
|
27
|
+
dfx.fem.function.Function
|
|
28
|
+
Empty dolfinx function for coeffiecients
|
|
29
|
+
|
|
30
|
+
# UFL
|
|
31
|
+
ufl.argument.Argument
|
|
32
|
+
e.g. u = ufl.TrialFunction(V)
|
|
33
|
+
e.g. v = ufl.TestFunction(V)
|
|
34
|
+
|
|
35
|
+
# pyGIMLi
|
|
36
|
+
pg.Mesh
|
|
37
|
+
pyGIMLi mesh
|
|
38
|
+
|
|
39
|
+
# MPI
|
|
40
|
+
mpi4py.MPI.Intracomm
|
|
41
|
+
Communicator for the different MPI processes
|
|
42
|
+
|
|
43
|
+
# custEMx
|
|
44
|
+
cx.mod.ModelParameter
|
|
45
|
+
Model parameter class instance
|
custemx/__init__.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@author: Rochlitz & Skibbe
|
|
5
|
+
|
|
6
|
+
Main initialization file for the custEMx module.
|
|
7
|
+
Imports submodules and configuration file as well as the logger instance.
|
|
8
|
+
"""
|
|
9
|
+
import logging
|
|
10
|
+
import dolfinx as dx
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
import tempfile
|
|
13
|
+
import json
|
|
14
|
+
import mpi4py.MPI as MPI
|
|
15
|
+
from logging.handlers import MemoryHandler
|
|
16
|
+
|
|
17
|
+
# CONFIG
|
|
18
|
+
class _cfg():
|
|
19
|
+
""" Class for handling the configuration of the custemx module."""
|
|
20
|
+
def __init__(self, config='custemx_config.json') -> dict:
|
|
21
|
+
# dolfinx mesh partitioner
|
|
22
|
+
self._partitioner = None
|
|
23
|
+
with open(Path(__file__).with_name(config), 'r') as infile:
|
|
24
|
+
self._cfg = json.load(infile)
|
|
25
|
+
|
|
26
|
+
for key in self._cfg.keys():
|
|
27
|
+
setattr(self, key, self._cfg[key])
|
|
28
|
+
|
|
29
|
+
if not hasattr(self, 'global_timeout') or self.global_timeout == 0:
|
|
30
|
+
self.global_timeout = None
|
|
31
|
+
|
|
32
|
+
self.basepath = Path(__file__).parent
|
|
33
|
+
self.testpath = self.basepath.parent.joinpath('pytest')
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def partitioner(self):
|
|
37
|
+
"""Get the mesh partitioner for dolfinx meshes."""
|
|
38
|
+
if self._partitioner is None:
|
|
39
|
+
# FIXME allow ordering in module config
|
|
40
|
+
try:
|
|
41
|
+
from dolfinx.graph import partitioner_scotch
|
|
42
|
+
log.info('Use partitioner "Scotch"')
|
|
43
|
+
use_partitioner = partitioner_scotch()
|
|
44
|
+
except ImportError:
|
|
45
|
+
try:
|
|
46
|
+
from dolfinx.graph import partitioner_kahip
|
|
47
|
+
log.info('Use partitioner "Kahip"')
|
|
48
|
+
use_partitioner = partitioner_kahip()
|
|
49
|
+
except ImportError:
|
|
50
|
+
try:
|
|
51
|
+
from dolfinx.graph import partitioner_parmetis
|
|
52
|
+
log.info('Use partitioner "Parmetis"')
|
|
53
|
+
use_partitioner = partitioner_parmetis()
|
|
54
|
+
except ImportError:
|
|
55
|
+
pass
|
|
56
|
+
finally:
|
|
57
|
+
if use_partitioner is not None:
|
|
58
|
+
self._partitioner =\
|
|
59
|
+
dx.mesh.create_cell_partitioner(use_partitioner)
|
|
60
|
+
return self._partitioner
|
|
61
|
+
|
|
62
|
+
cfg = _cfg()
|
|
63
|
+
|
|
64
|
+
# LOGGER
|
|
65
|
+
log = logging.getLogger('cx')
|
|
66
|
+
_MEMORY_EXPORT_FMT = '%(asctime)s %(message)s'
|
|
67
|
+
_MEMORY_EXPORT_DATEFMT = '%Y-%m-%d %H:%M:%S'
|
|
68
|
+
|
|
69
|
+
# Custom logging level between INFO (20) and WARNING (30)
|
|
70
|
+
NOTICE = 25
|
|
71
|
+
logging.addLevelName(NOTICE, "NOTICE")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _notice(self, message, *args, **kwargs):
|
|
75
|
+
if self.isEnabledFor(NOTICE):
|
|
76
|
+
self._log(NOTICE, message, args, **kwargs)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _log_line(self, char="-", length=80):
|
|
80
|
+
if MPI.COMM_WORLD.rank == 0:
|
|
81
|
+
"""Print a separator line without logging prefix."""
|
|
82
|
+
if log.level < 24:
|
|
83
|
+
print(char * length, flush=True)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _log_header(self, text, char="-", length=80):
|
|
87
|
+
if MPI.COMM_WORLD.rank == 0:
|
|
88
|
+
"""Print header lines without logging prefix."""
|
|
89
|
+
if log.level < 24:
|
|
90
|
+
print(char * length, flush=True)
|
|
91
|
+
print(text, flush=True)
|
|
92
|
+
print(char * length, flush=True)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _ensure_root_console_handler(root_logger):
|
|
96
|
+
"""Set the formatter of all root console handlers."""
|
|
97
|
+
|
|
98
|
+
if not root_logger.handlers:
|
|
99
|
+
root_logger.addHandler(logging.StreamHandler())
|
|
100
|
+
|
|
101
|
+
elif len(root_logger.handlers) > 1:
|
|
102
|
+
root_logger.handlers = [root_logger.handlers[0]]
|
|
103
|
+
|
|
104
|
+
for handler in root_logger.handlers:
|
|
105
|
+
if isinstance(handler, logging.StreamHandler):
|
|
106
|
+
handler.setFormatter(
|
|
107
|
+
logging.Formatter(
|
|
108
|
+
fmt='CX - %(levelname)s - %(asctime)s - %(message)s',
|
|
109
|
+
datefmt='%H:%M:%S'))
|
|
110
|
+
|
|
111
|
+
def _ensure_memory_handler(logger):
|
|
112
|
+
"""Keep one MemoryHandler on cx logger for logfile message export."""
|
|
113
|
+
memory_handlers = [h for h in logger.handlers if
|
|
114
|
+
isinstance(h, MemoryHandler)]
|
|
115
|
+
if memory_handlers:
|
|
116
|
+
memory_handler = memory_handlers[0]
|
|
117
|
+
else:
|
|
118
|
+
memory_handler = MemoryHandler(
|
|
119
|
+
capacity=99999,
|
|
120
|
+
flushLevel=logging.CRITICAL,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
memory_handler.setLevel(logging.NOTSET)
|
|
124
|
+
memory_handler.setFormatter(
|
|
125
|
+
logging.Formatter(
|
|
126
|
+
fmt=_MEMORY_EXPORT_FMT,
|
|
127
|
+
datefmt=_MEMORY_EXPORT_DATEFMT,
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Keep cx handler setup minimal and deterministic: memory capture locally,
|
|
132
|
+
# console output through root logger propagation.
|
|
133
|
+
logger.handlers = [memory_handler]
|
|
134
|
+
logger.propagate = True
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _get_memory_messages(logger):
|
|
138
|
+
"""Return buffered messages from cx MemoryHandler."""
|
|
139
|
+
memory_handler = next(
|
|
140
|
+
(h for h in logger.handlers if isinstance(h, MemoryHandler)),
|
|
141
|
+
None,
|
|
142
|
+
)
|
|
143
|
+
messages = []
|
|
144
|
+
if memory_handler is not None:
|
|
145
|
+
for record in memory_handler.buffer:
|
|
146
|
+
try:
|
|
147
|
+
messages.append(memory_handler.formatter.format(record))
|
|
148
|
+
except Exception:
|
|
149
|
+
messages.append(record.getMessage())
|
|
150
|
+
return messages
|
|
151
|
+
|
|
152
|
+
logging.Logger.notice = _notice
|
|
153
|
+
log.get_messages = lambda: _get_memory_messages(log)
|
|
154
|
+
log.line = _log_line.__get__(log, logging.Logger)
|
|
155
|
+
log.header = _log_header.__get__(log, logging.Logger)
|
|
156
|
+
log.setLevel(cfg.log_level)
|
|
157
|
+
|
|
158
|
+
if MPI.COMM_WORLD.rank != 0:
|
|
159
|
+
log.setLevel(40)
|
|
160
|
+
|
|
161
|
+
# VERSION
|
|
162
|
+
try:
|
|
163
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
164
|
+
__version__ = version("custemx")
|
|
165
|
+
except PackageNotFoundError:
|
|
166
|
+
__version__ = None
|
|
167
|
+
|
|
168
|
+
# SUBMODULES
|
|
169
|
+
from . import mod
|
|
170
|
+
from . import misc
|
|
171
|
+
from . import plot
|
|
172
|
+
from . import fe
|
|
173
|
+
from . import meshtools
|
|
174
|
+
from . import io
|
|
175
|
+
from . import solver
|
|
176
|
+
from . import inv
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
_ensure_root_console_handler(log.root)
|
|
180
|
+
_ensure_memory_handler(log)
|
|
181
|
+
|
|
182
|
+
# init default model parameters
|
|
183
|
+
mod.update_default_model_parameter(version=__version__)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"log_level": 20,
|
|
3
|
+
"max_cpu": 64,
|
|
4
|
+
"cpu_per_task": 16,
|
|
5
|
+
"global_timeout": 86400,
|
|
6
|
+
"inner_maxiter_warning": 50,
|
|
7
|
+
"petsc_options": {
|
|
8
|
+
"mumps": {
|
|
9
|
+
"ksp_type": "preonly",
|
|
10
|
+
"mat_mumps_cntl_1": 1e-8,
|
|
11
|
+
"mat_mumps_cntl_2": 1e-8,
|
|
12
|
+
"mat_mumps_icntl_8": 0,
|
|
13
|
+
"mat_mumps_icntl_14": 80,
|
|
14
|
+
"mat_mumps_icntl_48": 0,
|
|
15
|
+
"pc_factor_reuse_ordering": true,
|
|
16
|
+
"pc_factor_reuse_fill": true,
|
|
17
|
+
"pc_type": "cholesky",
|
|
18
|
+
"pc_factor_mat_solver_type": "mumps"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
custemx/fe/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is part of custemx.
|
|
3
|
+
Licensed under the GNU LGPLv3, see LICENSE for details.
|
|
4
|
+
|
|
5
|
+
Authors: Nico Skibbe, Raphael Rochlitz
|
|
6
|
+
|
|
7
|
+
Public finite-element formulations and helper exports.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .fe_class import BaseFormulation
|
|
11
|
+
from .fe_forms import FormEFD
|
|
12
|
+
from .fe_lib import (
|
|
13
|
+
LocalAssembler,
|
|
14
|
+
adjust_parameter,
|
|
15
|
+
check_attributes,
|
|
16
|
+
check_cell_markers,
|
|
17
|
+
create_delta_sigma,
|
|
18
|
+
eval_current_dir,
|
|
19
|
+
find_source_dofs_geometrical,
|
|
20
|
+
get_boundary_dofs,
|
|
21
|
+
parameter_to_array,
|
|
22
|
+
)
|
|
23
|
+
from .primary_fields import PF
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"BaseFormulation",
|
|
27
|
+
"FormEFD",
|
|
28
|
+
"LocalAssembler",
|
|
29
|
+
"adjust_parameter",
|
|
30
|
+
"check_attributes",
|
|
31
|
+
"check_cell_markers",
|
|
32
|
+
"create_delta_sigma",
|
|
33
|
+
"eval_current_dir",
|
|
34
|
+
"find_source_dofs_geometrical",
|
|
35
|
+
"get_boundary_dofs",
|
|
36
|
+
"parameter_to_array",
|
|
37
|
+
"PF",
|
|
38
|
+
]
|