Skip to content

Commit 6e9280c

Browse files
authored
Merge pull request #509 from lanl/jmm/ref-in-crtp
switch to const ref for CRTP then allow lambda to copy capture
2 parents 5f11f37 + 3d105ea commit 6e9280c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [[PR502]](https://github.com/lanl/singularity-eos/pull/502) Expose split tables to Fortran interface
1414

1515
### Infrastructure (changes irrelevant to downstream codes)
16+
- [[PR509]](https://github.com/lanl/singularity-eos/pull/509) Remove extraneous copies in base class
1617
- [[PR504]](https://github.com/lanl/singularity-eos/pull/504) Add Fortran interface documentation
1718

1819
### Removed (removing behavior/API/varaibles/...)

singularity-eos/eos/eos_base.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ class EosBase {
200200
// Generic evaluator
201201
template <typename Functor_t>
202202
PORTABLE_INLINE_FUNCTION void EvaluateDevice(const Functor_t f) const {
203-
const CRTP copy = *(static_cast<CRTP const *>(this));
203+
const CRTP &copy = *(static_cast<CRTP const *>(this));
204204
f(copy);
205205
}
206206
template <typename Functor_t>
207207
void EvaluateHost(Functor_t &f) const {
208-
const CRTP copy = *(static_cast<CRTP const *>(this));
208+
const CRTP &copy = *(static_cast<CRTP const *>(this));
209209
f(copy);
210210
}
211211

@@ -247,7 +247,7 @@ class EosBase {
247247
PORTABLE_INLINE_FUNCTION Real GibbsFreeEnergyFromDensityTemperature(
248248
const Real rho, const Real T,
249249
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
250-
const CRTP copy = *(static_cast<CRTP const *>(this));
250+
const CRTP &copy = *(static_cast<CRTP const *>(this));
251251
Real sie = copy.InternalEnergyFromDensityTemperature(rho, T, lambda);
252252
Real P = copy.PressureFromDensityTemperature(rho, T, lambda);
253253
Real S = copy.EntropyFromDensityTemperature(rho, T, lambda);
@@ -257,7 +257,7 @@ class EosBase {
257257
PORTABLE_INLINE_FUNCTION Real GibbsFreeEnergyFromDensityInternalEnergy(
258258
const Real rho, const Real sie,
259259
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
260-
const CRTP copy = *(static_cast<CRTP const *>(this));
260+
const CRTP &copy = *(static_cast<CRTP const *>(this));
261261
Real T = copy.TemperatureFromDensityInternalEnergy(rho, sie, lambda);
262262
Real P = copy.PressureFromDensityTemperature(rho, T, lambda);
263263
Real S = copy.EntropyFromDensityTemperature(rho, T, lambda);
@@ -272,7 +272,7 @@ class EosBase {
272272
LambdaIndexer &&lambdas) const {
273273
static auto const name = SG_MEMBER_FUNC_NAME();
274274
static auto const cname = name.c_str();
275-
CRTP copy = *(static_cast<CRTP const *>(this));
275+
const CRTP &copy = *(static_cast<CRTP const *>(this));
276276
portableFor(
277277
cname, 0, num, PORTABLE_LAMBDA(const int i) {
278278
temperatures[i] =
@@ -307,7 +307,7 @@ class EosBase {
307307
LambdaIndexer &&lambdas) const {
308308
static auto const name = SG_MEMBER_FUNC_NAME();
309309
static auto const cname = name.c_str();
310-
CRTP copy = *(static_cast<CRTP const *>(this));
310+
const CRTP &copy = *(static_cast<CRTP const *>(this));
311311
portableFor(
312312
cname, 0, num, PORTABLE_LAMBDA(const int i) {
313313
sies[i] = copy.InternalEnergyFromDensityTemperature(rhos[i], temperatures[i],
@@ -342,7 +342,7 @@ class EosBase {
342342
LambdaIndexer &&lambdas) const {
343343
static auto const name = SG_MEMBER_FUNC_NAME();
344344
static auto const cname = name.c_str();
345-
CRTP copy = *(static_cast<CRTP const *>(this));
345+
const CRTP &copy = *(static_cast<CRTP const *>(this));
346346
portableFor(
347347
cname, 0, num, PORTABLE_LAMBDA(const int i) {
348348
pressures[i] =
@@ -375,7 +375,7 @@ class EosBase {
375375
LambdaIndexer &&lambdas) const {
376376
static auto const name = SG_MEMBER_FUNC_NAME();
377377
static auto const cname = name.c_str();
378-
CRTP copy = *(static_cast<CRTP const *>(this));
378+
const CRTP &copy = *(static_cast<CRTP const *>(this));
379379
portableFor(
380380
cname, 0, num, PORTABLE_LAMBDA(const int i) {
381381
pressures[i] =
@@ -406,7 +406,7 @@ class EosBase {
406406
const int num, LambdaIndexer &&lambdas) const {
407407
static auto const name = SG_MEMBER_FUNC_NAME();
408408
static auto const cname = name.c_str();
409-
CRTP copy = *(static_cast<CRTP const *>(this));
409+
const CRTP &copy = *(static_cast<CRTP const *>(this));
410410
portableFor(
411411
cname, 0, num, PORTABLE_LAMBDA(const int i) {
412412
sies[i] = copy.MinInternalEnergyFromDensity(rhos[i], lambdas[i]);
@@ -436,7 +436,7 @@ class EosBase {
436436
LambdaIndexer &&lambdas) const {
437437
static auto const name = SG_MEMBER_FUNC_NAME();
438438
static auto const cname = name.c_str();
439-
CRTP copy = *(static_cast<CRTP const *>(this));
439+
const CRTP &copy = *(static_cast<CRTP const *>(this));
440440
portableFor(
441441
cname, 0, num, PORTABLE_LAMBDA(const int i) {
442442
entropies[i] =
@@ -469,7 +469,7 @@ class EosBase {
469469
LambdaIndexer &&lambdas) const {
470470
static auto const name = SG_MEMBER_FUNC_NAME();
471471
static auto const cname = name.c_str();
472-
CRTP copy = *(static_cast<CRTP const *>(this));
472+
const CRTP &copy = *(static_cast<CRTP const *>(this));
473473
portableFor(
474474
cname, 0, num, PORTABLE_LAMBDA(const int i) {
475475
entropies[i] =
@@ -501,7 +501,7 @@ class EosBase {
501501
LambdaIndexer &&lambdas) const {
502502
static auto const name = SG_MEMBER_FUNC_NAME();
503503
static auto const cname = name.c_str();
504-
CRTP copy = *(static_cast<CRTP const *>(this));
504+
const CRTP &copy = *(static_cast<CRTP const *>(this));
505505
portableFor(
506506
cname, 0, num, PORTABLE_LAMBDA(const int i) {
507507
cvs[i] = copy.SpecificHeatFromDensityTemperature(rhos[i], temperatures[i],
@@ -536,7 +536,7 @@ class EosBase {
536536
LambdaIndexer &&lambdas) const {
537537
static auto const name = SG_MEMBER_FUNC_NAME();
538538
static auto const cname = name.c_str();
539-
CRTP copy = *(static_cast<CRTP const *>(this));
539+
const CRTP &copy = *(static_cast<CRTP const *>(this));
540540
portableFor(
541541
cname, 0, num, PORTABLE_LAMBDA(const int i) {
542542
cvs[i] =
@@ -569,7 +569,7 @@ class EosBase {
569569
LambdaIndexer &&lambdas) const {
570570
static auto const name = SG_MEMBER_FUNC_NAME();
571571
static auto const cname = name.c_str();
572-
CRTP copy = *(static_cast<CRTP const *>(this));
572+
const CRTP &copy = *(static_cast<CRTP const *>(this));
573573
portableFor(
574574
cname, 0, num, PORTABLE_LAMBDA(const int i) {
575575
bmods[i] = copy.BulkModulusFromDensityTemperature(rhos[i], temperatures[i],
@@ -604,7 +604,7 @@ class EosBase {
604604
LambdaIndexer &&lambdas) const {
605605
static auto const name = SG_MEMBER_FUNC_NAME();
606606
static auto const cname = name.c_str();
607-
CRTP copy = *(static_cast<CRTP const *>(this));
607+
const CRTP &copy = *(static_cast<CRTP const *>(this));
608608
portableFor(
609609
cname, 0, num, PORTABLE_LAMBDA(const int i) {
610610
bmods[i] =

0 commit comments

Comments
 (0)