"""G3DDisplay static class"""
import os
from typing import Any
from .info import G3DInfo
from g3d.defs import CodeType
[docs]
class G3DDisplay:
"""G3D display placeholder"""
__verbose = False
__print_splash = True
__silent = False
__print_iterations = False
__scrw = 80
__plot_edges = False
__progress_bar = False
@property
def verbose(self) -> bool:
"""verbose = True => more printed output (default value = False)"""
return type(self).__verbose
@verbose.setter
def verbose(self, b: bool) -> None:
type(self).__verbose = b
if type(self).__verbose:
type(self).__silent = False
@property
def print_iterations(self) -> bool:
"""print_iterations = True => residuals will be printed every
iteration (default value = False)"""
return type(self).__print_iterations
@print_iterations.setter
def print_iterations(self, b: bool) -> None:
type(self).__print_iterations = b
@property
def progress_bar(self) -> bool:
"""progress_bar = True => progress bar will be printed to std out
(default value = False)"""
return type(self).__progress_bar
@progress_bar.setter
def progress_bar(self, b: bool) -> None:
type(self).__progress_bar = b
@property
def print_splash(self) -> bool:
"""print_splash = True => code splash (logo) will be printed
on solver start (default value = True)"""
return type(self).__print_splash
@print_splash.setter
def print_splash(self, b: bool) -> None:
type(self).__print_splash = b
@property
def silent(self) -> bool:
"""silent = True => limited solver output (default value = False)"""
return type(self).__silent
@silent.setter
def silent(self, b: bool) -> None:
type(self).__silent = b
if type(self).__silent:
type(self).__verbose = False
type(self).__print_splash = False
else:
type(self).__print_splash = True
@property
def scrw(self) -> int:
"""screen width (default value = 80)"""
return type(self).__scrw
@scrw.setter
def scrw(self, w: int) -> None:
type(self).__scrw = w
@property
def plot_edges(self) -> bool:
"""plot_edges = True => mesh block edges will be printed on
mesh plot (default value = False)"""
return type(self).__plot_edges
@plot_edges.setter
def plot_edges(self, b: bool) -> None:
type(self).__plot_edges = b
[docs]
def hline(self, *args: Any, **kwargs: Any) -> None:
"""
prints horizontal line on screen
input: args, kwargs
args: dash (default = '-'), scrw (default = 80 or earlier specified scrw value)
kwargs: 'dashes', 'scrw'
example: hline(args, kwargs)
"""
dashes = '-'
scrw = None
if len(args) > 0:
dashes = args[0]
if len(args) > 1:
scrw = args[1]
for key, value in kwargs.items():
if key == 'dashes':
dashes = value
if key == 'scrw':
scrw = value
if scrw is None:
scrw = type(self).__scrw
print(dashes * scrw)
# def header(self, info='test header'):
[docs]
@staticmethod
def logo() -> None:
"""
prints logo to std out
logos defined for CFLOW, G3DMESH & G3DFLOW
input: no input
example: logo()
"""
g3d_info = G3DInfo()
if g3d_info.code_type is CodeType.EMBEDDED:
return
print('')
if g3d_info.code_type is CodeType.CALCULATOR:
# style small slant https://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=CFLOW
print(' ___________ ____ _ __')
print(' / ___/ __/ / / __ \\ | /| / /')
print(' / /__/ _// /__/ /_/ / |/ |/ / ')
print(' \\___/_/ /____/\\____/|__/|__/ ')
elif g3d_info.code_type is CodeType.MESHER:
# style small slant https://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=G3DMESH
print('')
print(' _________ ___ __ _____________ __')
print(' / ___/_ // _ \\/ |/ / __/ __/ // /')
print(' / (_ //_ </ // / /|_/ / _/_\\ \\/ _ / ')
print(' \\___/____/____/_/ /_/___/___/_//_/ ')
else:
# style small slant https://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=G3DFLOW
print('')
print(' _________ ___ ______ ____ _ __')
print(' / ___/_ // _ \\/ __/ / / __ \\ | /| / /')
print(' / (_ //_ </ // / _// /__/ /_/ / |/ |/ / ')
print(' \\___/____/____/_/ /____/\\____/|__/|__/ ')
print('')
print(' %s' % g3d_info.info_str)
print('')
print(' %s' % g3d_info.code_description)
if len(g3d_info.code_sub_description):
print(' %s' % g3d_info.code_sub_description)
print('')
if os.environ.get('__USE_CUDA', '0') == '1':
print(' CUDA enabled')
print('')
[docs]
@staticmethod
def author():
"""
prints author/developer information to std out
input: no input
example: author()
"""
g3d_info = G3DInfo()
print('')
for line in g3d_info.author:
print(' ' + line)
print('')
[docs]
def splash(self) -> None:
"""
prints code splash to std out
logo (code specific), code version & author information
input: no input
example: splash()
"""
if type(self).__print_splash:
self.hline('=')
self.logo()
self.author()
self.hline('=')
type(self).__print_splash = False