Closed shyams2 closed 6 years ago
compute_moments
is used to return the density, that is used.dq1, dq2
. However, I think we can make an addition to the test folder to have a utils.py
file which can contain functions to evaluate dq1
and dq2
.petsc4py.init(sys.argv)
to the beginning of the file executed.python filename.py
:
python main.py -ksp_monitor -ksp_type cg
this is what I did:
Changed the headers in bolt/lib/nonlinear_solver/tests/test_compute_electrostatic_fields.py
to
import numpy as np
import arrayfire as af
import petsc4py
import sys
from petsc4py import PETSc
from bolt.lib.nonlinear_solver.EM_fields_solver.electrostatic \
import compute_electrostatic_fields
petsc4py.init(sys.argv)
Then I ran the code using :
py.test test_compute_electrostatic_fields.py -ksp_monitor
No ksp output was generated
Then I tried calling the test function explicitly at the bottom of the file using:
test_compute_electrostatic_fields()
and then running the code using:
python test_compute_electrostatic_fields.py -ksp_monitor
No ksp output was generated.
Please help.
Can you also add import petsc4py, sys; petsc4py.init(sys.argv)
to the beginning of bolt/lib/nonlinear_solver/EM_fields_solver/electrostatic.py
, and run python test_compute_electrostatic_fields.py -ksp_monitor
.
It should now be printing residual norm values of each iteration.
This is what I have in test_compute_electrostatic_fields.py
:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
In this test we check that the 2D Poisson solver
works as intended. For this purpose, we assign
a density distribution for which the analytical
solution for electrostatic fields may be computed.
This solution is then checked against the solution
given by the KSP solver
"""
import sys
import petsc4py
petsc4py.init(sys.argv)
import numpy as np
import arrayfire as af
from petsc4py import PETSc
from bolt.lib.nonlinear_solver.EM_fields_solver.electrostatic \
import compute_electrostatic_fields
and in electrostatic.py
:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc
import arrayfire as af
import numpy as np
from numpy.fft import fftfreq
I'm running using python test_compute_electrostatic_fields.py -ksp_monitor
and I get no output.
p.s. I also added test_compute_electrostatic_fields()
at the end of test_compute_electrostatic_fields.py
so that the function gets called when running using the above command.
Dealt with in #37
In
bolt/lib/nonlinear_solver/tests/test_compute_electrostatic_fields.py
compute_moments()
to return the density that the solver will see?Is there a way to compute the following using a pre-written function from the library (which takes as input
q1_start
,q1_end
,q2_start
,q2_end
,N_q1
,N_q2
):I'm noticing that the above segment is used in a lot of tests and it'd be good to avoid code duplication. We should use a function that is already tested to do the above, if such a function is available in the library.