Skip to content

Commit 2efb7da

Browse files
Merge pull request #124 from EXP-code/fixAccelFunc
Fix accel func and add center manipulation tools. See thread for full discussion.
2 parents 8b18297 + aafec0f commit 2efb7da

File tree

5 files changed

+107
-4
lines changed

5 files changed

+107
-4
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25) # Needed for CUDA, MPI, and CTest features
22

33
project(
44
EXP
5-
VERSION "7.8.1"
5+
VERSION "7.8.2"
66
HOMEPAGE_URL https://github.com/EXP-code/EXP
77
LANGUAGES C CXX Fortran)
88

expui/BasisFactory.H

+2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ namespace BasisClasses
263263
std::vector<std::string> getFieldLabels(void)
264264
{ return getFieldLabels(coordinates); }
265265

266+
//! Get the basis expansion center
267+
std::vector<double> getCenter() { return coefctr; }
266268
};
267269

268270
using BasisPtr = std::shared_ptr<Basis>;

expui/BiorthBasis.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -3685,11 +3685,17 @@ namespace BasisClasses
36853685
//
36863686
auto basis = std::get<0>(mod);
36873687

3688+
// Get expansion center
3689+
//
3690+
auto ctr = basis->getCenter();
3691+
36883692
// Get fields
36893693
//
36903694
int rows = accel.rows();
36913695
for (int n=0; n<rows; n++) {
3692-
auto v = basis->getFields(ps(n, 0), ps(n, 1), ps(n, 2));
3696+
auto v = basis->getFields(ps(n, 0) - ctr[0],
3697+
ps(n, 1) - ctr[1],
3698+
ps(n, 2) - ctr[2]);
36933699
// First 6 fields are density and potential, follewed by acceleration
36943700
for (int k=0; k<3; k++) accel(n, k) += v[6+k] - basis->pseudo(k);
36953701
}

expui/CoefStruct.H

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace CoefClasses
2727
Eigen::VectorXcd store;
2828

2929
//! Center data
30-
std::vector<double> ctr;
30+
std::vector<double> ctr= {0.0, 0.0, 0.0};
3131

3232
//! Destructor
3333
virtual ~CoefStruct() {}
@@ -62,6 +62,26 @@ namespace CoefClasses
6262
//! Read-only access to coefficient data (no copy)
6363
Eigen::Ref<const Eigen::VectorXcd> getCoefs() { return store; }
6464

65+
//! Set new center data (no copy)
66+
void setCenter(std::vector<double>& STORE)
67+
{
68+
if (STORE.size() != ctr.size())
69+
throw std::invalid_argument("CoefStruct::setCenter: center vector size does not match");
70+
ctr = STORE;
71+
}
72+
73+
//! Read-only access to center (no copy)
74+
std::vector<double> getCenter() { return ctr; }
75+
76+
//! Set coefficient time (no copy)
77+
void setTime(double& STORE)
78+
{
79+
time = STORE;
80+
}
81+
82+
//! Read-only access to center (no copy)
83+
double getTime() { return time; }
84+
6585
};
6686

6787
//! Specialization of CoefStruct for spheres

pyEXP/CoefWrappers.cc

+76-1
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,86 @@ void CoefficientClasses(py::module &m) {
712712
str
713713
geometry type
714714
)")
715-
.def_readwrite("time", &CoefStruct::time,
715+
.def_readonly("time", &CoefStruct::time,
716716
R"(
717717
float
718718
data's time stamp
719719
)")
720+
.def_readonly("center", &CoefStruct::ctr,
721+
R"(
722+
float
723+
data's center value
724+
)")
725+
.def("getCoefTime", &CoefStruct::getTime,
726+
R"(
727+
Read-only access to the coefficient time
728+
729+
Returns
730+
-------
731+
numpy.ndarray
732+
vector of center data
733+
734+
See also
735+
--------
736+
setCoefTime : read-write access to the coefficient time
737+
)")
738+
.def("setCoefTime",
739+
static_cast<void (CoefStruct::*)(double&)>(&CoefStruct::setTime),
740+
py::arg("tval"),
741+
R"(
742+
Set the coefficient time
743+
744+
Parameters
745+
----------
746+
tval : float
747+
time value
748+
749+
Returns
750+
-------
751+
None
752+
753+
Notes
754+
-----
755+
756+
See also
757+
--------
758+
getCenter : read-only access to coefficient time
759+
)")
760+
.def("getCoefCenter", &CoefStruct::getCenter,
761+
R"(
762+
Read-only access to the center data
763+
764+
Returns
765+
-------
766+
numpy.ndarray
767+
vector of center data
768+
769+
See also
770+
--------
771+
setCenter : read-write access to the center data
772+
)")
773+
.def("setCoefCenter",
774+
static_cast<void (CoefStruct::*)(std::vector<double>&)>(&CoefStruct::setCenter),
775+
py::arg("mat"),
776+
R"(
777+
Set the center vector
778+
779+
Parameters
780+
----------
781+
mat : numpy.ndarray
782+
center vector
783+
784+
Returns
785+
-------
786+
None
787+
788+
Notes
789+
-----
790+
791+
See also
792+
--------
793+
getCenter : read-only access to center data
794+
)")
720795
.def("getCoefs", &CoefStruct::getCoefs,
721796
R"(
722797
Read-only access to the underlying data store

0 commit comments

Comments
 (0)