{"id":21323397,"url":"https://github.com/sag2021/ndsm","last_synced_at":"2026-03-19T19:54:01.872Z","repository":{"id":260977492,"uuid":"874574973","full_name":"sag2021/ndsm","owner":"sag2021","description":"Multigrid vector-potential solver ","archived":false,"fork":false,"pushed_at":"2024-11-04T01:06:35.000Z","size":696,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T12:11:38.913Z","etag":null,"topics":["finite-difference","magnetic-field","multigrid","n-dimensional","openmp-parallelization","solar-physics","vector-potential"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sag2021.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T04:43:51.000Z","updated_at":"2024-11-04T01:06:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"4079128f-04c4-4ef2-9a5b-04d4a1cde1f1","html_url":"https://github.com/sag2021/ndsm","commit_stats":null,"previous_names":["sag2021/ndsm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sag2021%2Fndsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sag2021%2Fndsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sag2021%2Fndsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sag2021%2Fndsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sag2021","download_url":"https://codeload.github.com/sag2021/ndsm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801687,"owners_count":20350108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finite-difference","magnetic-field","multigrid","n-dimensional","openmp-parallelization","solar-physics","vector-potential"],"created_at":"2024-11-21T20:23:45.084Z","updated_at":"2026-01-02T09:33:02.103Z","avatar_url":"https://github.com/sag2021.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Code description\n\nCode computes the potential (current-free) magnetic field on a rectilinear mesh in a Cartesian box, given\nthe normal component of the magnetic field on each boundary face. The solution is computed using geometric multrigrid applied\nto a finite-difference scheme. The method computes the magnetic field via a vector potential formulation.  The code returns both the vector \npotential in Coulomb gauge and the corresponding magnetic field.\n\nThe code uses a second-order finite-difference scheme for the discretization. In principle, this \nmeans that the numerical truncation error should decrease as the square of the mesh spacing. \n\nThe backbone of the code is a set of modules for solving Poisson's equation in N dimensions\nusing geometric multigrid. This multigrid solver was written first, and then the vector potential\ncode was added later.The name of the code NDSM is derived from the original set of modules, i.e.\nN-Dimensional Solver Multigrid (NDSM). The vector-potential module, however, is specifically \ndesigned for 3D, but leverages the more general N-dimensional backend. \n\nCode is written in Fortran 2003 and tested using the gfortran 8.3.0 compiler. It has only been\ntested on a Linux platform. \n\nAn earlier version of this code was used and is decribed in the paper Yang K.E., Wheatland M.S., and Gilchrist S.A.: 2020, ApJ,984,151. \nPaper DOI: 10.3847/1538-4357/ab8810\n\n# Mesh and dimensions\n\nThe mesh is rectilinear, i.e. it is described by three mesh vectors x,y,z. These are assumed\nto have fixed spacing. The code makes no explicit assumptions about the units of either B or A, although the\nlength scales are non-dimensional. \n\n# Vector Potential Gauge \n\nThe vector potential is computed in the Coulomb gauge. However, note that in a box,\nthe Coulomb gauge is not necessarily unique when the boundary conditions are on the normal component\nof the magnetic field. The NDSM code makes a particular choice in resolving this ambiguity. See\nthe paper and the notes for more details. \n\n# Convergence \n\nThe multigrid method arrives at a solution via iteration. \nWhen convergence is poor, the output of the code may not accurately represent the \nsolution to the underlying boundary-value problem (see ndsm_notes.pdf for details of the BVP). \nThis has several consequences. Firstly, the magnetic field may not be a potential field, and significant electric \ncurrents may exist within the volume. Secondly, the normal component of the magnetic \nfield may not match the normal component specified as boundary conditions.\n\n## Metric\n\nTwo metrics are available for measuring the convergence of the solution: \nthe max or mean difference between iterations. By default, the max is used. \n\nThe max is sensitive to failure of convergence at any point, and therefore may be inappropriate\nfor many practical problems, but is useful for testing. The mean is a \nmore robust convergence metric and may be more appropriate for practical problems. \n\nSetting mean=True, will use the mean rather than the max. \n\n## Tolerances\n\nThe code has two tolerance parameters that determine when to stop\niterating. \n\n### vc\\_tol\n\nThe V cycle iteration stops when the max/mean difference is less than\nvc\\_tol. If vc\\_tol is large, the code may return quickly, but the solution\nmay not be an accurate solution of the BVP.\n\n### ex\\_tol\n\nThe multrigrid method requires solution of a BVP on the coarsest mesh. \nThis is solved via relaxation. The relaxation stops when the change in \nsolution is less than ex_tol. Setting this to a large value will\nresult in inefficient V cycles, because the BVP is not being accurately\nsolved at each V cycle iteration.\n\n### Choice of vc\\_tol and ex\\_tol\n\nWhen testing the code on analytic solutions, both vc\\_tol and ex\\_tol\ncan be set to very small values. The default values defined in ndsm.py \nreflect values used for testing.\n\nFor some practical problems, the change in solution between iterations\nmay never reach the desired value of vc_tol: the solution is not improving\nwith additional V cycles. In this case, the iteration\nwill run until ncycles\\_max is reached. This may take a long time \ndepending on how ncycles\\_max is chosen. A warning will be printed \nif the code returns without achieving vc\\_tol. \n\nSetting a large value for vc\\_tol (and ex\\_tol) may prevent the \ncode from running to ncycles\\_max, but a large value of vc\\_tol\nin particular will mean the solutions is poorly converged: the numerical\nsolution is not an accurate solution of the underlying boundary-value problem.\n\n\n# Compile shared library\n\nThe core Fortran code builds a shared library. \n\nRunning make will build the shared library, called ndsm.so by default.\n\n# OpenMP\n\nThe code is parallelized using the OpenMP standard. However, it should compile and run without OpenMP,\nit will just be very slow on a multicore machine. \n\n# REAL and INTEGER Types\n\nThe core Fortran modules are written with a real type defined in NDSM_ROOT as REAL(FP). By default\nthis is set to C_DOUBLE. This can be changed to any supported Fortran real type without\nbreaking anything in the Fortran modules, however the Python interface only works with a real type\nthat is intercompatible with C_DOUBLE. \n\nSimilarly, the basic integer type used throughout the code is INTEGER(IT), with IT = C_INT64_T. \nThis again can be changed without resulting compiler errors. However, making the int size too small\nmay lead to overflow if large meshes are used, since the total number of mesh points is stored as a signed\nFortran integer. In addition, changing IT will break the Python wrapper. \n\n# Python \n\nThe shared library can be called via the ndsm.py module. The module calls the subroutines\nin the shared library using the Python ctypes module. The shared library needs to be compiled\nfirst and either exist in sys.path, or else the explicit path to the shared library needs to\nbe passed as an argument to the function (see the docstring). \n\nThe basic Python module only requires numpy and ctypes. Some of the tests require more \nmodules, e.g. matplotlib. \n\n# Tests \n\nThe repository contains code for running a number of integration and unit tests. Some are \nwritten in Fortran, while others are written in Python. The main integration test is designed\nto demonstrate that the truncation error has the correct scaling with mesh spacing. This is \na basic test of correctness for the method. \n\nThe truncation error is estimated by applying the code to a known analytic test case and computing metrics\nfor the difference between the numerical and analytic solutions. The error metrics used are the max. \nand mean magnitude of the difference between the numerical and analytic vector fields. For a correctly \nimplemented second-order scheme, (generally) both these metrics should decrease with the square of the mesh spacing\n(for a uniform mesh). The max. error in particular may not achieve second order scaling for certain problems. \n\nA more complete description of the testing and results is included in the notes. \n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsag2021%2Fndsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsag2021%2Fndsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsag2021%2Fndsm/lists"}