Skip to content

Commit 6e46751

Browse files
Merge pull request #75 from EXP-code/pyEXPbessel
Implementation of Bessel support in pyEXP [WIP]
2 parents bcc60aa + aef851a commit 6e46751

33 files changed

Lines changed: 1375 additions & 474 deletions

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ execute_process(
187187
OUTPUT_STRIP_TRAILING_WHITESPACE
188188
)
189189

190+
# Git submodule updates
191+
execute_process(
192+
COMMAND git submodule update --init --recursive
193+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
194+
RESULT_VARIABLE GIT_SUBMOD_RESULT
195+
)
196+
197+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
198+
message(FATAL_ERROR "git submodule update --init --recursive failed ${GIT_SUBMOD_RESULT}, please checkout submodules")
199+
else()
200+
message(STATUS "Submodules updated successfully - good")
201+
endif()
202+
190203
# Get the latest abbreviated commit hash of the working branch
191204
execute_process(
192205
COMMAND git rev-parse HEAD

expui/BasisFactory.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ namespace BasisClasses
175175
if ( !name.compare("sphereSL") ) {
176176
basis = std::make_shared<SphericalSL>(conf);
177177
}
178+
else if ( !name.compare("bessel") ) {
179+
basis = std::make_shared<Bessel>(conf);
180+
}
178181
else if ( !name.compare("cylinder") ) {
179182
basis = std::make_shared<Cylindrical>(conf);
180183
}

expui/BiorthBasis.H

Lines changed: 171 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <ParticleReader.H>
1212
#include <Coefficients.H>
13+
#include <BiorthBess.H>
1314
#include <BasisFactory.H>
1415
#include <BiorthCube.H>
1516
#include <SLGridMP2.H>
@@ -60,7 +61,6 @@ namespace BasisClasses
6061
virtual std::vector<double>
6162
sph_eval(double r, double costh, double phi) = 0;
6263

63-
6464
//! Evaluate fields in cylindrical coordinates in centered coordinate system
6565
virtual std::vector<double>
6666
cyl_eval(double r, double costh, double phi) = 0;
@@ -164,56 +164,24 @@ namespace BasisClasses
164164
};
165165

166166
/**
167-
Uses SLGridSph basis to evaluate expansion coeffients and provide
168-
potential and density basis fields
167+
An abstract spherical basis to evaluate expansion coeffients and
168+
provide potential and density basis fields
169169
*/
170-
class SphericalSL : public BiorthBasis
170+
class Spherical : public BiorthBasis
171171
{
172172

173173
public:
174174

175175
using BasisMap = std::map<std::string, Eigen::VectorXd>;
176176
using BasisArray = std::vector<std::vector<BasisMap>>;
177177

178-
private:
178+
protected:
179179

180180
//! Helper for constructor
181181
void initialize();
182182

183-
std::shared_ptr<SLGridSph> sl;
184-
std::shared_ptr<SphericalModelTable> mod;
185-
186-
std::string model_file;
187-
int lmax, nmax, cmap, numr;
188-
double rmin, rmax, rmap;
189-
190-
bool NO_L0, NO_L1, EVEN_L, EVEN_M, M0_only;
191-
192-
std::vector<Eigen::MatrixXd> potd, dpot, dpt2, dend;
193-
std::vector<Eigen::MatrixXd> legs, dlegs, d2legs;
194-
195-
Eigen::MatrixXd factorial;
196-
Eigen::MatrixXd expcoef;
197-
double scale;
198-
int N1, N2;
199-
int used;
200-
201-
using matT = std::vector<Eigen::MatrixXd>;
202-
using vecT = std::vector<Eigen::VectorXd>;
203-
204-
double totalMass;
205-
int npart;
206-
207-
Eigen::VectorXd work;
208-
209-
//! For coefficient writing
210-
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
211-
EigenColMajor;
212-
213-
protected:
214-
215-
//! Load coefficients into the new CoefStruct
216-
virtual void load_coefs(CoefClasses::CoefStrPtr coefs, double time);
183+
//! Load coefficients for a particular time
184+
virtual void load_coefs(CoefClasses::CoefStrPtr coef, double time);
217185

218186
//! Set coefficients
219187
virtual void set_coefs(CoefClasses::CoefStrPtr coefs);
@@ -222,7 +190,7 @@ namespace BasisClasses
222190
static const std::set<std::string> valid_keys;
223191

224192
//! Return readable class name
225-
virtual const std::string classname() { return "SphericalSL";}
193+
virtual const std::string classname() { return "Spherical";}
226194

227195
//! Subspace index
228196
virtual const std::string harmonic() { return "l";}
@@ -239,16 +207,60 @@ namespace BasisClasses
239207
virtual std::vector<double>
240208
cyl_eval(double R, double z, double phi);
241209

210+
//@{
211+
//! Required basis members
212+
213+
//! Get potential
214+
virtual void get_pot(Eigen::MatrixXd& tab, double x) = 0;
215+
216+
//! Get density
217+
virtual void get_dens(Eigen::MatrixXd& tab, double x) = 0;
218+
219+
//! Get force
220+
virtual void get_force(Eigen::MatrixXd& tab, double x) = 0;
221+
222+
//@}
223+
224+
//@{
225+
//! Internal parameters and storage
226+
int lmax, nmax, cmap, numr;
227+
double rmin, rmax, rmap;
228+
229+
bool NO_L0, NO_L1, EVEN_L, EVEN_M, M0_only;
230+
231+
std::vector<Eigen::MatrixXd> potd, dpot, dpt2, dend;
232+
std::vector<Eigen::MatrixXd> legs, dlegs, d2legs;
233+
234+
Eigen::MatrixXd factorial;
235+
Eigen::MatrixXd expcoef;
236+
double scale;
237+
int N1, N2;
238+
int used;
239+
240+
using matT = std::vector<Eigen::MatrixXd>;
241+
using vecT = std::vector<Eigen::VectorXd>;
242+
243+
double totalMass;
244+
int npart;
245+
246+
Eigen::VectorXd work;
247+
248+
//! For coefficient writing
249+
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
250+
EigenColMajor;
251+
252+
//@}
253+
242254
public:
243255

244256
//! Constructor from YAML node
245-
SphericalSL(const YAML::Node& conf);
257+
Spherical(const YAML::Node& conf, const std::string& forceID);
246258

247259
//! Constructor from YAML string
248-
SphericalSL(const std::string& confstr);
260+
Spherical(const std::string& confstr, const std::string& forceID);
249261

250262
//! Destructor
251-
virtual ~SphericalSL(void) {}
263+
virtual ~Spherical(void) {}
252264

253265
//! Print and return the cache parameters
254266
static std::map<std::string, std::string>
@@ -276,29 +288,134 @@ namespace BasisClasses
276288
int getNmax() { return nmax; }
277289

278290
//! Return potential-density pair of a vector of a vector of 1d
279-
//! basis-function grids for SphericalSL, logarithmically spaced
280-
//! between [logxmin, logxmax] (base 10).
281-
BasisArray getBasis
282-
(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);
291+
//! basis-function grids for Spherical [rmin, rmax]
292+
virtual BasisArray getBasis
293+
(double rmin=0.0, double rax=1.0, int numgrid=2000);
283294

284295
//! Compute the orthogonality of the basis by returning inner
285296
//! produce matrices
286-
std::vector<Eigen::MatrixXd> orthoCheck(int knots=40)
287-
{
288-
return sl->orthoCheck(knots);
289-
}
297+
virtual std::vector<Eigen::MatrixXd> orthoCheck(int knots) = 0;
290298

291299
//! Biorthogonality sanity check
292300
bool orthoTest(int knots=100)
293301
{
294-
auto [ret, worst, lworst] = orthoCompute(sl->orthoCheck(knots));
302+
auto [ret, worst, lworst] = orthoCompute(orthoCheck(knots));
295303
// For the CTest log
296-
std::cout << "SphericalSL::orthoTest: worst=" << worst << std::endl;
304+
std::cout << "Spherical::orthoTest: worst=" << worst << std::endl;
297305
return ret;
298306
}
299307

300308
};
309+
310+
/**
311+
Uses SLGridSph basis to evaluate expansion coeffients and provide
312+
potential and density basis fields
313+
*/
314+
class SphericalSL : public Spherical
315+
{
316+
317+
protected:
318+
319+
//! Helper for constructor
320+
void initialize();
321+
322+
static const std::set<std::string> valid_keys;
323+
324+
std::shared_ptr<SLGridSph> sl;
325+
std::shared_ptr<SphericalModelTable> mod;
326+
327+
std::string model_file;
328+
329+
//! Return readable class name
330+
const std::string classname() { return "SphericalSL";}
331+
332+
// Get potential
333+
void get_pot(Eigen::MatrixXd& tab, double r)
334+
{ sl->get_pot(tab, r); }
335+
336+
// Get density
337+
void get_dens(Eigen::MatrixXd& tab, double r)
338+
{ sl->get_dens(tab, r); }
339+
340+
// Get force
341+
void get_force(Eigen::MatrixXd& tab, double r)
342+
{ sl->get_force(tab, r); }
343+
344+
public:
345+
346+
//! Constructor from YAML node
347+
SphericalSL(const YAML::Node& conf);
348+
349+
//! Constructor from YAML string
350+
SphericalSL(const std::string& confstr);
351+
352+
//! Destructor
353+
virtual ~SphericalSL(void) {}
354+
355+
//! Return potential-density pair of a vector of a vector of 1d
356+
//! basis-function grids for SphericalSL, logarithmically spaced
357+
//! between [logxmin, logxmax] (base 10).
358+
BasisArray getBasis(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);
359+
360+
//! Compute the orthogonality of the basis by returning inner
361+
//! produce matrices
362+
std::vector<Eigen::MatrixXd> orthoCheck(int knots=40)
363+
{ return sl->orthoCheck(knots); }
364+
};
365+
366+
/**
367+
Uses Bessel basis to evaluate expansion coeffients and provide
368+
potential and density basis fields
369+
*/
370+
class Bessel : public Spherical
371+
{
372+
373+
protected:
374+
375+
//! Helper for constructor
376+
void initialize();
377+
378+
static const std::set<std::string> valid_keys;
379+
380+
//! Return readable class name
381+
const std::string classname() { return "Bessel";}
382+
383+
//! Grid size for Bessel function table
384+
int rnum = 2000;
385+
386+
//! Biorthgonal Bessel function generator
387+
std::shared_ptr<BiorthBess> bess;
388+
389+
// Get potential
390+
void get_pot(Eigen::MatrixXd& tab, double r)
391+
{ bess->get_potl(r, tab); }
392+
393+
// Get density
394+
void get_dens(Eigen::MatrixXd& tab, double r)
395+
{ bess->get_dens(r, tab); }
396+
397+
// Get force
398+
void get_force(Eigen::MatrixXd& tab, double r)
399+
{ bess->get_dpotl(r, tab); }
400+
401+
public:
402+
403+
//! Constructor from YAML node
404+
Bessel(const YAML::Node& conf);
405+
406+
//! Constructor from YAML string
407+
Bessel(const std::string& confstr);
408+
409+
//! Destructor
410+
virtual ~Bessel(void) {}
411+
412+
//! Compute the orthogonality of the basis by returning inner
413+
//! produce matrices
414+
std::vector<Eigen::MatrixXd> orthoCheck(int knots=40)
415+
{ return bess->orthoCheck(knots); }
416+
};
301417

418+
302419
/**
303420
Uses the BiorthCyl basis to evaluate expansion coeffients and
304421
provide potential and density basis fields
@@ -408,8 +525,7 @@ namespace BasisClasses
408525
//! Return a vector of a vector of 1d basis-function grids for
409526
//! FlatDisk, logarithmically spaced between [logxmin, logxmax]
410527
//! (base 10).
411-
BasisArray getBasis
412-
(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);
528+
BasisArray getBasis(double logxmin=-3.0, double logxmax=0.5, int numgrid=2000);
413529

414530
//! Compute the orthogonality of the basis by returning inner
415531
//! produce matrices

0 commit comments

Comments
 (0)