Hey everyone
I made a progress bar by using tqdm. However, I find that when I am running my code, the calculation details are also displayed, which makes everything roll pretty fast and I have to hold it to see my progress bar. I wonder whether there is any way to hide the white part in the picture. So only the progress bar is displayed
dokken
November 20, 2022, 6:32am
2
Thank you very much for the reply. However, I am still confused about what I should do to set the log_level of info in order to hide it.
Do I just use
set_log_level(LogLevel.info)
in my code? Would you explain a bit more about how to do it? Thank you very much!
dokken
November 20, 2022, 7:41am
4
Thank you for the reply. However, I am using Dolfin. Is it still the same?
dokken
November 20, 2022, 8:09am
6
Thank you very much! The issue it solved. I hope you are having a great day!
Hey. I had a new issue today. For my code to solve Dirichlet BC set_log_level(40)
works pretty well. However, for another version of my code, which uses Neumann BC. The info is still displayed(shown in the picture) It is because they use different Newtonsolver?
dokken
November 20, 2022, 8:04pm
11
As you have not provided an example that reproduces the issue, there is no way of helping you further.
from dolfin import *
import matplotlib.pyplot as plt
from tqdm import tqdm
import random
import numpy as np
set_log_level(40)
# Define 1D mesh and space
mesh = IntervalMesh(10000, 0, 10)
Element1 = FiniteElement("CG", mesh.ufl_cell(), 1)
Element2 = FiniteElement("CG", mesh.ufl_cell(), 1)
W_elem = MixedElement([Element1, Element2])
ME = FunctionSpace(mesh, W_elem)
# Define functions
u_old = Function(ME)
u_new = Function(ME)
theta_old, vy_old = split(u_old)
theta_new, vy_new = split(u_new)
vy_mid = 0.5 * vy_old + 0.5 * vy_new
theta_mid = 0.5 * theta_old + 0.5 * theta_new
tf = TestFunction(ME)
q, v = split(tf)
kapa_ga = 1
lamb = 1.5
f1 = lamb * cos(2 * theta_mid)
dt = 0.01
# Boundary condition
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(ME.sub(1), Constant(0), boundary)
# Initial Condition
class InitialConditions(UserExpression):
def eval(self, values, x):
values[0] = 1.57 + 0.001 * random.gauss(0, 1)
values[1] = 0
def value_shape(self):
return (2,)
# Set initial conditions to old function
u_init = InitialConditions()
theta_list = []
vy_list = []
alpha_list = []
vy_steady_list = []
i_list = []
p_list = []
k_list = []
for k in tqdm(range(-160, -79, 10), desc="Alpha progress"):
set_log_level(LogLevel.PROGRESS)
theta_list = []
vy_list = []
u_old.interpolate(u_init)
alpha = k
t = 0.0
T = 1000 * dt
for t in tqdm(np.arange(0.0, 10.01, 0.01), desc="Time progress"):
f2 = alpha * cos(2 * theta_new)
# Weak statement of the equations
F0 = (theta_new - theta_old) / dt * q * dx + kapa_ga * theta_mid.dx(0) * q.dx(0) * dx - 0.5 * (
f1 + 1) * vy_mid.dx(
0) * q * dx
F1 = (-vy_new.dx(0) * v.dx(0)) * dx + f2 * theta_new.dx(0) * v * dx
F = F0 + F1
solve(F == 0, u_new, bc)
u_old.vector()[:] = u_new.vector()
u_copy = Function(ME)
u_copy.vector()[:] = u_new.vector()
theta_list.append(u_copy.split()[0])
vy_list.append(u_copy.split()[1])
p1 = assemble(((theta_list[999] - theta_list[949]) ** 2) * dx)
p2 = assemble((theta_list[999] ** 2) * dx)
p3 = p1 / p2
k_list.append(k)
p_list.append(p3)
alpha_list.append(theta_list[999])
vy_steady_list.append(vy_list[999])
# Show parameters
print(k_list)
print(p_list)
# Plot
for i in range(0, len(alpha_list)):
plot(alpha_list[i])
plt.legend(k_list)
plt.title("Theta for L=10 Neumann BC")
plt.show()
for i in range(0, len(vy_steady_list)):
plot(vy_steady_list[i])
plt.legend(k_list)
plt.ylim(-300, 300)
plt.title("Vy for L=10 Neumann BC")
plt.show()
This is the example code and one of the outputs during the process is this, where the info is still displayed.
dokken
November 20, 2022, 8:24pm
13
You are changing the LogLevel inside the for loop.
I see. I ignored a previous mistake. I thought I deleted this code. Now it is working. Thank you very much for your help!