Skip to content

Commit

Permalink
Clean up compute beta for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ahurta92 committed Jul 1, 2024
1 parent 95a33f1 commit 58a606d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
31 changes: 31 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"configurations": [
{
"name": "C/C++: g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "gdb"
}
],
"version": "2.0.0"
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
"C_Cpp.default.compilerPath": "/gpfs/software/gcc/11.2.0/bin/g++"
}
25 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/gpfs/software/gcc/11.2.0/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
40 changes: 12 additions & 28 deletions src/apps/molresponse/FrequencyResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,37 +607,14 @@ std::pair<Tensor<double>, std::vector<std::string>> QuadraticResponse::compute_b
auto dipole_vectors = create_dipole(); // x y z
truncate(world, dipole_vectors, true);

std::vector<int> indices_A;
std::vector<int> indices_BC;

if (BC_left.num_states() == 4)
{
indices_A = {0, 0, 0, 1, 1, 1, 2, 2, 2, 0};
indices_BC = {0, 1, 2, 0, 1, 2, 0, 1, 2, 3};
}
else if (BC_left.num_states() == 6)
{
indices_A = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2};
indices_BC = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5};
}
else
{
indices_A = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2};
indices_BC = {0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8};
}

int num_elements = indices_A.size();

int num_elements = XA.num_states()* BC_left.num_states();
std::vector<std::string> beta_indices(num_elements);


Tensor<double> beta(num_elements);


for (int i = 0; i < num_elements; i++)
{
auto a = indices_A[i];
auto bc = indices_BC[i];
int i=0;
for(int a =0; a<XA.num_states();a++){
for(int bc =0; bc<BC_left.num_states();bc++){

auto one = dot(world, BC_left.x[bc], BC_right.x[bc] * dipole_vectors[a], false);
auto two = dot(world, BC_left.y[bc], BC_right.y[bc] * dipole_vectors[a], false);
Expand All @@ -650,9 +627,16 @@ std::pair<Tensor<double>, std::vector<std::string>> QuadraticResponse::compute_b
world.gop.fence();
beta[i] = one.trace() + two.trace() + three.trace() + four.trace() + five.trace() + six.trace();
beta_indices[i] = xyz[a] + bc_directions[bc];
i++;
world.gop.fence();
}
}

for (int i = 0; i < num_elements; i++)
{
if (world.rank() == 0 and r_params.print_level() >= 1)
{
print("beta[", beta_indices[i], "] = ", beta[i]);
print("i = ",i," beta[", beta_indices[i], "] = ", beta[i]);
}
}
world.gop.fence();
Expand Down
2 changes: 1 addition & 1 deletion src/apps/molresponse/FrequencyResponse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class QuadraticResponse : public ResponseBase
std::vector<int> index_B;
std::vector<int> index_C;
std::vector<std::string> bc_directions;
std::vector<std::string> a{"X", "Y", "Z"};
std::vector<std::string> a_directions{"X", "Y", "Z"};
bool indicies_set;

std::map<int, std::string> xyz = {{0, "X"}, {1, "Y"}, {2, "Z"}};
Expand Down

0 comments on commit 58a606d

Please sign in to comment.