openEMS/FDTD/processvoltage.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

#include "processvoltage.h"
ProcessVoltage::ProcessVoltage(Operator* op, Engine* eng) : Processing(op, eng)
{
}
ProcessVoltage::~ProcessVoltage()
{
file.close();
}
void ProcessVoltage::OpenFile(string outfile)
{
if (file.is_open()) file.close();
file.open(outfile.c_str());
if (file.is_open()==false)
{
cerr << "Can't open file: " << outfile << endl;
return;
}
}
void ProcessVoltage::Process()
{
2010-03-02 18:01:03 +00:00
if (Enabled==false) return;
FDTD_FLOAT voltage=0;
unsigned int pos[3]={start[0],start[1],start[2]};
// cerr << Eng->volt[1][pos[0]][pos[1]][pos[2]] << endl;
for (int n=0;n<3;++n)
{
if (start[n]<stop[n])
{
for (;pos[n]<stop[n];++pos[n])
{
voltage+=Eng->volt[n][pos[0]][pos[1]][pos[2]];
// cerr << n << " " << pos[0] << " " << pos[1] << " " << pos[2] << " " << Eng->volt[n][pos[0]][pos[1]][pos[2]] << endl;
}
}
else
{
for (;pos[n]>stop[n];--pos[n])
voltage-=Eng->volt[n][pos[0]][pos[1]][pos[2]];
}
}
// cerr << voltage << endl;
voltages.push_back(voltage);
2010-03-01 19:50:42 +00:00
file << (double)Eng->numTS*Op->GetTimestep() << "\t" << voltage << endl;
}