QuazarTech / Bolt

A Fast Solver Framework For Kinetic Theories
GNU General Public License v3.0
7 stars 5 forks source link

Poisson solver debugging [WIP] #32

Closed shyams2 closed 6 years ago

mchandra commented 7 years ago

In bolt/lib/nonlinear_solver/tests/test_compute_electrostatic_fields.py

  1. Is the purpose of compute_moments() to return the density that the solver will see?
  2. 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):

        self.dq1 = (self.q1_end - self.q1_start) / self.N_q1
        self.dq2 = (self.q2_end - self.q2_start) / self.N_q2
    
        self.N_ghost = np.random.randint(3, 5)
    
        self.q1 = self.q1_start \
                  + (0.5 + np.arange(-self.N_ghost,
                                     self.N_q1 + self.N_ghost
                                    )
                    ) * self.dq1
    
        self.q2 = self.q2_start \
                  + (0.5 + np.arange(-self.N_ghost,
                                     self.N_q2 + self.N_ghost
                                    )
                    ) * self.dq2
    
        self.q2, self.q1 = np.meshgrid(self.q2, self.q1)
        self.q2, self.q1 = af.to_array(self.q2), af.to_array(self.q1)

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.

  1. How do you enable verbose output for the KSP solver? I remember you managed to do it in an ipython notebook at some point.
  2. How to pass command line options into the KSP solver?
shyams2 commented 7 years ago
  1. Yes. compute_moments is used to return the density, that is used.
  2. No. There isn't any function in the library to compute 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.
  3. I managed to get it working on an independent python file. Not an ipython notebook. For this, you need to add petsc4py.init(sys.argv) to the beginning of the file executed.
  4. All arguments are passed after python filename.py: python main.py -ksp_monitor -ksp_type cg
mchandra commented 7 years ago

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.

shyams2 commented 7 years ago

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.

mchandra commented 7 years ago

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.

shyams2 commented 6 years ago

Dealt with in #37