Skip to content

Commit

Permalink
Merge pull request #557 from patrick432/energy-per-spins-repair
Browse files Browse the repository at this point in the history
repair Image_Write_Energy_per_Spin and include it into the python int…
  • Loading branch information
MSallermann authored Mar 25, 2020
2 parents ac3b318 + 12fb122 commit 8f89c90
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
22 changes: 21 additions & 1 deletion core/python/spirit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,24 @@ def eigenmodes_write(p_state, filename, fileformat=FILEFORMAT_OVF_TEXT, comment=
"""Write the eigenmodes of a spin system to file, if they have been already calculated."""
_Eigenmodes_Write(ctypes.c_void_p(p_state), ctypes.c_char_p(filename.encode('utf-8')),
ctypes.c_int(fileformat), ctypes.c_char_p(comment.encode('utf-8')),
ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
ctypes.c_int(idx_image), ctypes.c_int(idx_chain))


_Image_Write_Energy_per_Spin = _spirit.IO_Image_Write_Energy_per_Spin
_Image_Write_Energy_per_Spin.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int,
ctypes.c_int, ctypes.c_int]
_Eigenmodes_Write.restype = None
def Image_Write_Energy_per_Spin(p_state, filename, fileformat=FILEFORMAT_OVF_TEXT, idx_image=-1, idx_chain=-1):
"""Write the energies per spin to a file.
Arguments:
- `p_state`: state pointer
- `filename`: the name of the file to append to
Keyword arguments
- `fileformat`: the format in which to write the data (default: OVF text)
"""
_Image_Write_Energy_per_Spin(ctypes.c_void_p(p_state), ctypes.c_char_p(filename.encode('utf-8')),
ctypes.c_int(fileformat), ctypes.c_int(idx_image), ctypes.c_int(idx_chain))
9 changes: 5 additions & 4 deletions core/src/Spirit/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ try
std::vector<std::pair<std::string, scalarfield>> contributions_spins(0);
system.UpdateEnergy();
system.hamiltonian->Energy_Contributions_per_Spin(spins, contributions_spins);
int datasize = (1+contributions_spins.size())*system.nos;
int dataperspin = 1+contributions_spins.size();
int datasize = dataperspin*system.nos;
scalarfield data(datasize, 0);
for( int ispin=0; ispin<system.nos; ++ispin )
{
Expand All @@ -861,10 +862,10 @@ try
for( auto& contribution : contributions_spins )
{
E_spin += contribution.second[ispin];
data[ispin+j] = contribution.second[ispin];
data[ispin*dataperspin+j] = contribution.second[ispin];
++j;
}
data[ispin] = E_spin;
data[ispin*dataperspin] = E_spin;
}

try
Expand Down Expand Up @@ -1220,4 +1221,4 @@ try
catch( ... )
{
spirit_handle_exception_api(idx_image, idx_chain);
}
}
6 changes: 5 additions & 1 deletion core/src/engine/Hamiltonian_Heisenberg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ namespace Engine

void Hamiltonian_Heisenberg::Energy_Contributions_per_Spin(const vectorfield & spins, std::vector<std::pair<std::string, scalarfield>> & contributions)
{
if( contributions.size() != this->energy_contributions_per_spin.size() )
{
contributions = this->energy_contributions_per_spin;
}
int nos = spins.size();
for (auto& pair : contributions)
{
Expand Down Expand Up @@ -1282,4 +1286,4 @@ namespace Engine
const std::string& Hamiltonian_Heisenberg::Name() { return name; }
}

#endif
#endif

0 comments on commit 8f89c90

Please sign in to comment.