@@ -3,44 +3,6 @@ Utility functions for the FEMTools.jl module.
33These functions provide various utilities for file management, logging, etc.
44"""
55
6- struct TimestampLogger <: AbstractLogger
7- logger:: AbstractLogger
8- end
9-
10- Logging. min_enabled_level (logger:: TimestampLogger ) = Logging. min_enabled_level (logger. logger)
11- Logging. shouldlog (logger:: TimestampLogger , level, _module, group, id) =
12- Logging. shouldlog (logger. logger, level, _module, group, id)
13-
14- function Logging. handle_message (logger:: TimestampLogger , level, message, _module, group, id,
15- filepath, line; kwargs... )
16- timestamp = Dates. format (now (), " yyyy-mm-dd HH:MM:SS" )
17- new_message = " [$timestamp ] $message "
18- Logging. handle_message (logger. logger, level, new_message, _module, group, id,
19- filepath, line; kwargs... )
20- end
21-
22- function setup_fem_logging (verbosity:: Int , logfile:: Union{String,Nothing} = nothing )
23- level = verbosity >= 2 ? Logging. Debug :
24- verbosity == 1 ? Logging. Info : Logging. Warn
25-
26- # Create console logger
27- console_logger = ConsoleLogger (stderr , level)
28-
29- if isnothing (logfile)
30- # Log to console only
31- global_logger (TimestampLogger (console_logger))
32- else
33- # Try to set up file logging with fallback to console-only
34- try
35- file_logger = FileLogger (logfile, level)
36- combined_logger = TeeLogger (console_logger, file_logger)
37- global_logger (TimestampLogger (combined_logger))
38- catch e
39- @warn " Failed to set up file logging to $logfile : $e "
40- global_logger (TimestampLogger (console_logger))
41- end
42- end
43- end
446
457"""
468$(TYPEDSIGNATURES)
@@ -247,4 +209,22 @@ function map_verbosity_to_gmsh(verbosity::Int)
247209 else # Warn
248210 return 1 # Gmsh Errors level
249211 end
250- end
212+ end
213+
214+ function calc_domain_size (earth_params:: EarthModel , f:: Vector{<:Float64} ; min_radius= 5.0 , max_radius= 5000.0 )
215+ # Find the earth layer with the highest resistivity to determine the domain size
216+ if isempty (earth_params. layers)
217+ error (" EarthModel has no layers defined." )
218+ end
219+
220+ # Find the index of the layer with the maximum resistivity at the first frequency
221+ max_rho_idx = argmax ([layer. rho_g[1 ] for layer in earth_params. layers])
222+ target_layer = earth_params. layers[max_rho_idx]
223+
224+ rho_g = target_layer. rho_g[1 ]
225+ mu_g = target_layer. mu_g[1 ]
226+ freq = first (f) # Use the first frequency for the calculation
227+ skin_depth_earth = abs (sqrt (rho_g / (1im * 2 * pi * freq * mu_g)))
228+ return clamp (skin_depth_earth, min_radius, max_radius)
229+ end
230+
0 commit comments