@@ -240,24 +240,25 @@ double pcmsolver_compute_polarization_energy(pcmsolver_context_t * context,
240
240
const char * mep_name,
241
241
const char * asc_name) {
242
242
return (
243
- AS_TYPE (pcm::Meddle, context)->computePolarizationEnergy (mep_name, asc_name));
243
+ AS_TYPE (pcm::Meddle, context)
244
+ ->computePolarizationEnergy (std::string (mep_name), std::string (asc_name)));
244
245
}
245
- double pcm::Meddle::computePolarizationEnergy (const char * mep_name,
246
- const char * asc_name) const {
246
+ double pcm::Meddle::computePolarizationEnergy (const std::string & mep_name,
247
+ const std::string & asc_name) const {
247
248
// Dot product of MEP and ASC surface function
248
- double energy =
249
- functions_[std::string (mep_name)].dot (functions_[std::string (asc_name)]);
249
+ double energy = functions_[mep_name].dot (functions_[asc_name]);
250
250
return (energy / 2.0 );
251
251
}
252
252
253
253
double pcmsolver_get_asc_dipole (pcmsolver_context_t * context,
254
254
const char * asc_name,
255
255
double dipole[]) {
256
- return (AS_TYPE (pcm::Meddle, context)->getASCDipole (asc_name, dipole));
256
+ return (
257
+ AS_TYPE (pcm::Meddle, context)->getASCDipole (std::string (asc_name), dipole));
257
258
}
258
- double pcm::Meddle::getASCDipole (const char * asc_name, double dipole[]) const {
259
- Eigen::Vector3d asc_dipole =
260
- cavity_->elementCenter () * functions_[std::string ( asc_name) ];
259
+ double pcm::Meddle::getASCDipole (const std::string & asc_name,
260
+ double dipole[]) const {
261
+ Eigen::Vector3d asc_dipole = cavity_->elementCenter () * functions_[asc_name];
261
262
// Bind to host-allocated array
262
263
Eigen::Map<Eigen::Vector3d>(dipole, 3 , 1 ) = asc_dipole;
263
264
return asc_dipole.norm ();
@@ -268,25 +269,23 @@ void pcmsolver_compute_asc(pcmsolver_context_t * context,
268
269
const char * asc_name,
269
270
int irrep) {
270
271
TIMER_ON (" pcmsolver_compute_asc" );
271
- AS_TYPE (pcm::Meddle, context)->computeASC (mep_name, asc_name, irrep);
272
+ AS_TYPE (pcm::Meddle, context)
273
+ ->computeASC (std::string (mep_name), std::string (asc_name), irrep);
272
274
TIMER_OFF (" pcmsolver_compute_asc" );
273
275
}
274
- void pcm::Meddle::computeASC (const char * mep_name,
275
- const char * asc_name,
276
+ void pcm::Meddle::computeASC (const std::string & mep_name,
277
+ const std::string & asc_name,
276
278
int irrep) const {
277
- std::string MEP (mep_name);
278
- std::string ASC (asc_name);
279
-
280
279
// Get the proper iterators
281
- SurfaceFunctionMapConstIter iter_pot = functions_.find (MEP );
280
+ SurfaceFunctionMapConstIter iter_pot = functions_.find (mep_name );
282
281
Eigen::VectorXd asc = K_0_->computeCharge (iter_pot->second , irrep);
283
282
// Renormalize
284
283
asc /= double (cavity_->pointGroup ().nrIrrep ());
285
284
// Insert it into the map
286
- if (functions_.count (ASC ) == 1 ) { // Key in map already
287
- functions_[ASC ] = asc;
285
+ if (functions_.count (asc_name ) == 1 ) { // Key in map already
286
+ functions_[asc_name ] = asc;
288
287
} else { // Create key-value pair
289
- functions_.insert (std::make_pair (ASC , asc));
288
+ functions_.insert (std::make_pair (asc_name , asc));
290
289
}
291
290
}
292
291
@@ -295,17 +294,15 @@ void pcmsolver_compute_response_asc(pcmsolver_context_t * context,
295
294
const char * asc_name,
296
295
int irrep) {
297
296
TIMER_ON (" pcmsolver_compute_response_asc" );
298
- AS_TYPE (pcm::Meddle, context)->computeResponseASC (mep_name, asc_name, irrep);
297
+ AS_TYPE (pcm::Meddle, context)
298
+ ->computeResponseASC (std::string (mep_name), std::string (asc_name), irrep);
299
299
TIMER_OFF (" pcmsolver_compute_response_asc" );
300
300
}
301
- void pcm::Meddle::computeResponseASC (const char * mep_name,
302
- const char * asc_name,
301
+ void pcm::Meddle::computeResponseASC (const std::string & mep_name,
302
+ const std::string & asc_name,
303
303
int irrep) const {
304
- std::string MEP (mep_name);
305
- std::string ASC (asc_name);
306
-
307
304
// Get the proper iterators
308
- SurfaceFunctionMapConstIter iter_pot = functions_.find (MEP );
305
+ SurfaceFunctionMapConstIter iter_pot = functions_.find (mep_name );
309
306
Eigen::VectorXd asc (cavity_->size ());
310
307
if (hasDynamic_) {
311
308
asc = K_d_->computeCharge (iter_pot->second , irrep);
@@ -314,10 +311,10 @@ void pcm::Meddle::computeResponseASC(const char * mep_name,
314
311
}
315
312
// Renormalize
316
313
asc /= double (cavity_->pointGroup ().nrIrrep ());
317
- if (functions_.count (ASC ) == 1 ) { // Key in map already
318
- functions_[ASC ] = asc;
314
+ if (functions_.count (asc_name ) == 1 ) { // Key in map already
315
+ functions_[asc_name ] = asc;
319
316
} else { // Create key-value pair
320
- functions_.insert (std::make_pair (ASC , asc));
317
+ functions_.insert (std::make_pair (asc_name , asc));
321
318
}
322
319
}
323
320
@@ -326,20 +323,18 @@ void pcmsolver_get_surface_function(pcmsolver_context_t * context,
326
323
double values[],
327
324
const char * name) {
328
325
TIMER_ON (" pcmsolver_get_surface_function" );
329
- AS_TYPE (pcm::Meddle, context)->getSurfaceFunction (size, values, name);
326
+ AS_TYPE (pcm::Meddle, context)->getSurfaceFunction (size, values, std::string ( name) );
330
327
TIMER_OFF (" pcmsolver_get_surface_function" );
331
328
}
332
329
void pcm::Meddle::getSurfaceFunction (PCMSolverIndex size,
333
330
double values[],
334
- const char * name) const {
335
- std::string functionName (name);
331
+ const std::string & name) const {
336
332
if (cavity_->size () != size)
337
- PCMSOLVER_ERROR (" The " + functionName +
338
- " SurfaceFunction is bigger than the cavity!" );
333
+ PCMSOLVER_ERROR (" The " + name + " SurfaceFunction is bigger than the cavity!" );
339
334
340
- SurfaceFunctionMapConstIter iter = functions_.find (functionName );
335
+ SurfaceFunctionMapConstIter iter = functions_.find (name );
341
336
if (iter == functions_.end ())
342
- PCMSOLVER_ERROR (" The " + functionName + " SurfaceFunction does not exist." );
337
+ PCMSOLVER_ERROR (" The " + name + " SurfaceFunction does not exist." );
343
338
344
339
Eigen::Map<Eigen::VectorXd>(values, size, 1 ) = iter->second ;
345
340
}
@@ -349,35 +344,32 @@ void pcmsolver_set_surface_function(pcmsolver_context_t * context,
349
344
double values[],
350
345
const char * name) {
351
346
TIMER_ON (" pcmsolver_set_surface_function" );
352
- AS_TYPE (pcm::Meddle, context)->setSurfaceFunction (size, values, name);
347
+ AS_TYPE (pcm::Meddle, context)->setSurfaceFunction (size, values, std::string ( name) );
353
348
TIMER_OFF (" pcmsolver_set_surface_function" );
354
349
}
355
350
void pcm::Meddle::setSurfaceFunction (PCMSolverIndex size,
356
351
double values[],
357
- const char * name) const {
358
- std::string functionName (name);
352
+ const std::string & name) const {
359
353
if (cavity_->size () != size)
360
- PCMSOLVER_ERROR (" The " + functionName +
361
- " SurfaceFunction is bigger than the cavity!" );
354
+ PCMSOLVER_ERROR (" The " + name + " SurfaceFunction is bigger than the cavity!" );
362
355
363
356
Eigen::VectorXd func = Eigen::Map<Eigen::VectorXd>(values, size, 1 );
364
- if (functions_.count (functionName ) == 1 ) { // Key in map already
365
- functions_[functionName ] = func;
357
+ if (functions_.count (name ) == 1 ) { // Key in map already
358
+ functions_[name ] = func;
366
359
} else {
367
- functions_.insert (std::make_pair (functionName , func));
360
+ functions_.insert (std::make_pair (name , func));
368
361
}
369
362
}
370
363
371
364
void pcmsolver_print_surface_function (pcmsolver_context_t * context,
372
365
const char * name) {
373
- AS_TYPE (pcm::Meddle, context)->printSurfaceFunction (name);
366
+ AS_TYPE (pcm::Meddle, context)->printSurfaceFunction (std::string ( name) );
374
367
}
375
- void pcm::Meddle::printSurfaceFunction (const char * name) const {
376
- std::string functionName (name);
377
- if (functions_.count (functionName) == 1 ) { // Key in map already
368
+ void pcm::Meddle::printSurfaceFunction (const std::string & name) const {
369
+ if (functions_.count (name) == 1 ) { // Key in map already
378
370
std::ostringstream print_sf;
379
371
Eigen::IOFormat fmt (Eigen::FullPrecision);
380
- print_sf << functions_[functionName ].format (fmt) << std::endl;
372
+ print_sf << functions_[name ].format (fmt) << std::endl;
381
373
hostWriter_ (print_sf);
382
374
} else {
383
375
PCMSOLVER_ERROR (" You are trying to print a nonexistent SurfaceFunction!" );
@@ -400,29 +392,28 @@ void pcm::Meddle::saveSurfaceFunctions() const {
400
392
401
393
void pcmsolver_save_surface_function (pcmsolver_context_t * context,
402
394
const char * name) {
403
- AS_TYPE (pcm::Meddle, context)->saveSurfaceFunction (name);
395
+ AS_TYPE (pcm::Meddle, context)->saveSurfaceFunction (std::string ( name) );
404
396
}
405
- void pcm::Meddle::saveSurfaceFunction (const char * name) const {
397
+ void pcm::Meddle::saveSurfaceFunction (const std::string & name) const {
406
398
SurfaceFunctionMapConstIter it = functions_.find (name);
407
- cnpy::custom::npy_save (std::string ( name) + " .npy" , it->second );
399
+ cnpy::custom::npy_save (name + " .npy" , it->second );
408
400
}
409
401
410
402
void pcmsolver_load_surface_function (pcmsolver_context_t * context,
411
403
const char * name) {
412
- AS_TYPE (pcm::Meddle, context)->loadSurfaceFunction (name);
404
+ AS_TYPE (pcm::Meddle, context)->loadSurfaceFunction (std::string ( name) );
413
405
}
414
- void pcm::Meddle::loadSurfaceFunction (const char * name) const {
415
- std::string functionName (name);
416
- hostWriter_ (" \n Loading surface function " + functionName + " from .npy file" );
417
- Eigen::VectorXd values = cnpy::custom::npy_load<double >(functionName + " .npy" );
406
+ void pcm::Meddle::loadSurfaceFunction (const std::string & name) const {
407
+ hostWriter_ (" \n Loading surface function " + name + " from .npy file" );
408
+ Eigen::VectorXd values = cnpy::custom::npy_load<double >(name + " .npy" );
418
409
if (values.size () != cavity_->size ())
419
- PCMSOLVER_ERROR (" The loaded " + functionName +
410
+ PCMSOLVER_ERROR (" The loaded " + name +
420
411
" surface function is bigger than the cavity!" );
421
412
// Append to global map
422
- if (functions_.count (functionName ) == 1 ) { // Key in map already
423
- functions_[functionName ] = values;
413
+ if (functions_.count (name ) == 1 ) { // Key in map already
414
+ functions_[name ] = values;
424
415
} else {
425
- functions_.insert (std::make_pair (functionName , values));
416
+ functions_.insert (std::make_pair (name , values));
426
417
}
427
418
}
428
419
0 commit comments