1010abstract type AbstractNonlinearSolveBaseAPI end # Mostly used for pretty-printing
1111
1212function Base. show (io:: IO , :: MIME"text/plain" , alg:: AbstractNonlinearSolveBaseAPI )
13- main_name = nameof (typeof (alg))
14- modifiers = String[]
15- for field in fieldnames (typeof (alg))
16- val = getfield (alg, field)
17- Utils. is_default_value (val, field, getfield (alg, field)) && continue
18- push! (modifiers, " $(field) = $(val) " )
19- end
20- print (io, " $(main_name) ($(join (modifiers, " , " )) )" )
13+ print (io, Utils. clean_sprint_struct (alg))
2114 return
2215end
2316
@@ -198,12 +191,9 @@ Abstract Type for all NonlinearSolveBase Algorithms.
198191
199192 - `concrete_jac(alg)`: whether or not the algorithm uses a concrete Jacobian. Defaults
200193 to `nothing`.
201- - `get_name(alg)`: get the name of the algorithm.
202194"""
203195abstract type AbstractNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
204196
205- get_name (alg:: AbstractNonlinearSolveAlgorithm ) = Utils. safe_getproperty (alg, Val (:name ))
206-
207197"""
208198 concrete_jac(alg::AbstractNonlinearSolveAlgorithm)::Bool
209199
@@ -218,6 +208,18 @@ concrete_jac(v::Bool) = v
218208concrete_jac (:: Val{false} ) = false
219209concrete_jac (:: Val{true} ) = true
220210
211+ function Base. show (io:: IO , :: MIME"text/plain" , alg:: AbstractNonlinearSolveAlgorithm )
212+ print (io, Utils. clean_sprint_struct (alg, 0 ))
213+ return
214+ end
215+
216+ function show_nonlinearsolve_algorithm (
217+ io:: IO , alg:: AbstractNonlinearSolveAlgorithm , name, indent:: Int = 0
218+ )
219+ print (io, name)
220+ print (io, Utils. clean_sprint_struct (alg, indent))
221+ end
222+
221223"""
222224 AbstractNonlinearSolveCache
223225
@@ -299,30 +301,34 @@ function Base.setindex!(cache::AbstractNonlinearSolveCache, val, sym)
299301 return SII. setu (cache, sym)(cache, val)
300302end
301303
302- # XXX : Implement this
303- # function Base.show(io::IO, cache::AbstractNonlinearSolveCache)
304- # __show_cache(io, cache, 0)
305- # end
306-
307- # function __show_cache(io::IO, cache::AbstractNonlinearSolveCache, indent = 0)
308- # println(io, "$(nameof(typeof(cache)))(")
309- # __show_algorithm(io, cache.alg,
310- # (" "^(indent + 4)) * "alg = " * string(get_name(cache.alg)), indent + 4)
311-
312- # ustr = sprint(show, get_u(cache); context = (:compact => true, :limit => true))
313- # println(io, ",\n" * (" "^(indent + 4)) * "u = $(ustr),")
314-
315- # residstr = sprint(show, get_fu(cache); context = (:compact => true, :limit => true))
316- # println(io, (" "^(indent + 4)) * "residual = $(residstr),")
317-
318- # normstr = sprint(
319- # show, norm(get_fu(cache), Inf); context = (:compact => true, :limit => true))
320- # println(io, (" "^(indent + 4)) * "inf-norm(residual) = $(normstr),")
304+ function Base. show (io:: IO , :: MIME"text/plain" , cache:: AbstractNonlinearSolveCache )
305+ return show_nonlinearsolve_cache (io, cache)
306+ end
321307
322- # println(io, " "^(indent + 4) * "nsteps = ", cache.stats.nsteps, ",")
323- # println(io, " "^(indent + 4) * "retcode = ", cache.retcode)
324- # print(io, " "^(indent) * ")")
325- # end
308+ function show_nonlinearsolve_cache (io:: IO , cache:: AbstractNonlinearSolveCache , indent = 0 )
309+ println (io, " $(nameof (typeof (cache))) (" )
310+ show_nonlinearsolve_algorithm (
311+ io,
312+ cache. alg,
313+ (" " ^ (indent + 4 )) * " alg = " ,
314+ indent + 4
315+ )
316+
317+ ustr = sprint (show, get_u (cache); context = (:compact => true , :limit => true ))
318+ println (io, " ,\n " * (" " ^ (indent + 4 )) * " u = $(ustr) ," )
319+
320+ residstr = sprint (show, get_fu (cache); context = (:compact => true , :limit => true ))
321+ println (io, (" " ^ (indent + 4 )) * " residual = $(residstr) ," )
322+
323+ normstr = sprint (
324+ show, norm (get_fu (cache), Inf ); context = (:compact => true , :limit => true )
325+ )
326+ println (io, (" " ^ (indent + 4 )) * " inf-norm(residual) = $(normstr) ," )
327+
328+ println (io, " " ^ (indent + 4 ) * " nsteps = " , cache. stats. nsteps, " ," )
329+ println (io, " " ^ (indent + 4 ) * " retcode = " , cache. retcode)
330+ print (io, " " ^ (indent) * " )" )
331+ end
326332
327333"""
328334 AbstractLinearSolverCache
0 commit comments