Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poisson solver debugging [WIP] #32

Closed
wants to merge 2 commits into from
Closed

Conversation

shyams2
Copy link
Contributor

@shyams2 shyams2 commented Sep 22, 2017

No description provided.

@mchandra mchandra changed the title WIP Poisson solver debugging Poisson solver debugging [WIP] Sep 22, 2017
@mchandra
Copy link
Contributor

mchandra commented Sep 22, 2017

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.
3. How do you enable verbose output for the KSP solver? I remember you managed to do it in an ipython notebook at some point.
4. How to pass command line options into the KSP solver?

@shyams2
Copy link
Contributor Author

shyams2 commented Sep 23, 2017

  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
Copy link
Contributor

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
Copy link
Contributor Author

shyams2 commented Sep 25, 2017

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
Copy link
Contributor

mchandra commented Sep 25, 2017

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
Copy link
Contributor Author

shyams2 commented Oct 11, 2017

Dealt with in #37

@shyams2 shyams2 closed this Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants