2010-04-21 09:18:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_sse.h"
|
|
|
|
|
|
|
|
//! \brief construct an Engine_sse instance
|
|
|
|
//! it's the responsibility of the caller to free the returned pointer
|
2010-04-21 13:38:15 +00:00
|
|
|
Engine_sse* Engine_sse::New(const Operator_sse* op)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
|
|
|
Engine_sse* e = new Engine_sse(op);
|
|
|
|
e->Init();
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2010-04-21 13:38:15 +00:00
|
|
|
Engine_sse::Engine_sse(const Operator_sse* op) : Engine(op)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
2010-05-17 11:08:27 +00:00
|
|
|
m_type = SSE;
|
2010-04-21 09:18:22 +00:00
|
|
|
Op = op;
|
2010-05-11 20:54:08 +00:00
|
|
|
f4_volt = 0;
|
|
|
|
f4_curr = 0;
|
2010-05-01 10:57:43 +00:00
|
|
|
numVectors = ceil((double)numLines[2]/4.0);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine_sse::~Engine_sse()
|
|
|
|
{
|
2010-05-11 20:54:08 +00:00
|
|
|
Reset();
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine_sse::Init()
|
|
|
|
{
|
2010-05-11 15:59:00 +00:00
|
|
|
Engine::Init();
|
|
|
|
|
|
|
|
Delete_N_3DArray(volt,numLines);
|
|
|
|
volt=NULL; // not used
|
|
|
|
Delete_N_3DArray(curr,numLines);
|
|
|
|
curr=NULL; // not used
|
|
|
|
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_volt = Create_N_3DArray_v4sf(numLines);
|
|
|
|
f4_curr = Create_N_3DArray_v4sf(numLines);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine_sse::Reset()
|
|
|
|
{
|
2010-05-11 20:54:08 +00:00
|
|
|
Engine::Reset();
|
2010-04-30 17:41:44 +00:00
|
|
|
Delete_N_3DArray_v4sf(f4_volt,numLines);
|
|
|
|
f4_volt = 0;
|
|
|
|
Delete_N_3DArray_v4sf(f4_curr,numLines);
|
|
|
|
f4_curr = 0;
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
2010-05-09 18:27:17 +00:00
|
|
|
void Engine_sse::UpdateVoltages(unsigned int startX, unsigned int numX)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
2010-04-21 12:29:02 +00:00
|
|
|
unsigned int pos[3];
|
|
|
|
bool shift[2];
|
|
|
|
f4vector temp;
|
2010-04-21 09:18:22 +00:00
|
|
|
|
2010-05-09 18:27:17 +00:00
|
|
|
pos[0] = startX;
|
|
|
|
for (unsigned int posX=0;posX<numX;++posX)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
|
|
|
shift[0]=pos[0];
|
|
|
|
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
|
|
|
|
{
|
|
|
|
shift[1]=pos[1];
|
2010-05-01 11:06:13 +00:00
|
|
|
for (pos[2]=1;pos[2]<numVectors;++pos[2])
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
2010-04-21 12:29:02 +00:00
|
|
|
// x-polarization
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_volt[0][pos[0]][pos[1]][pos[2]].v *= Op->f4_vv[0][pos[0]][pos[1]][pos[2]].v;
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_volt[0][pos[0]][pos[1]][pos[2]].v += Op->f4_vi[0][pos[0]][pos[1]][pos[2]].v * ( f4_curr[2][pos[0]][pos[1]][pos[2]].v - f4_curr[2][pos[0]][pos[1]-shift[1]][pos[2]].v - f4_curr[1][pos[0]][pos[1]][pos[2]].v + f4_curr[1][pos[0]][pos[1]][pos[2]-1].v );
|
2010-04-21 09:18:22 +00:00
|
|
|
|
2010-04-21 12:29:02 +00:00
|
|
|
// y-polarization
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_volt[1][pos[0]][pos[1]][pos[2]].v *= Op->f4_vv[1][pos[0]][pos[1]][pos[2]].v;
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_volt[1][pos[0]][pos[1]][pos[2]].v += Op->f4_vi[1][pos[0]][pos[1]][pos[2]].v * ( f4_curr[0][pos[0]][pos[1]][pos[2]].v - f4_curr[0][pos[0]][pos[1]][pos[2]-1].v - f4_curr[2][pos[0]][pos[1]][pos[2]].v + f4_curr[2][pos[0]-shift[0]][pos[1]][pos[2]].v);
|
2010-04-21 09:18:22 +00:00
|
|
|
|
2010-04-21 12:29:02 +00:00
|
|
|
// z-polarization
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_volt[2][pos[0]][pos[1]][pos[2]].v *= Op->f4_vv[2][pos[0]][pos[1]][pos[2]].v;
|
|
|
|
f4_volt[2][pos[0]][pos[1]][pos[2]].v += Op->f4_vi[2][pos[0]][pos[1]][pos[2]].v * ( f4_curr[1][pos[0]][pos[1]][pos[2]].v - f4_curr[1][pos[0]-shift[0]][pos[1]][pos[2]].v - f4_curr[0][pos[0]][pos[1]][pos[2]].v + f4_curr[0][pos[0]][pos[1]-shift[1]][pos[2]].v);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
2010-05-01 10:57:43 +00:00
|
|
|
|
|
|
|
// for pos[2] = 0
|
|
|
|
// x-polarization
|
|
|
|
temp.f[0] = 0;
|
2010-05-01 11:06:13 +00:00
|
|
|
temp.f[1] = f4_curr[1][pos[0]][pos[1]][numVectors-1].f[0];
|
|
|
|
temp.f[2] = f4_curr[1][pos[0]][pos[1]][numVectors-1].f[1];
|
|
|
|
temp.f[3] = f4_curr[1][pos[0]][pos[1]][numVectors-1].f[2];
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_volt[0][pos[0]][pos[1]][0].v *= Op->f4_vv[0][pos[0]][pos[1]][0].v;
|
|
|
|
f4_volt[0][pos[0]][pos[1]][0].v += Op->f4_vi[0][pos[0]][pos[1]][0].v * ( f4_curr[2][pos[0]][pos[1]][0].v - f4_curr[2][pos[0]][pos[1]-shift[1]][0].v - f4_curr[1][pos[0]][pos[1]][0].v + temp.v );
|
|
|
|
|
|
|
|
// y-polarization
|
|
|
|
temp.f[0] = 0;
|
2010-05-01 11:06:13 +00:00
|
|
|
temp.f[1] = f4_curr[0][pos[0]][pos[1]][numVectors-1].f[0];
|
|
|
|
temp.f[2] = f4_curr[0][pos[0]][pos[1]][numVectors-1].f[1];
|
|
|
|
temp.f[3] = f4_curr[0][pos[0]][pos[1]][numVectors-1].f[2];
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_volt[1][pos[0]][pos[1]][0].v *= Op->f4_vv[1][pos[0]][pos[1]][0].v;
|
|
|
|
f4_volt[1][pos[0]][pos[1]][0].v += Op->f4_vi[1][pos[0]][pos[1]][0].v * ( f4_curr[0][pos[0]][pos[1]][0].v - temp.v - f4_curr[2][pos[0]][pos[1]][0].v + f4_curr[2][pos[0]-shift[0]][pos[1]][0].v);
|
|
|
|
|
|
|
|
// z-polarization
|
|
|
|
f4_volt[2][pos[0]][pos[1]][0].v *= Op->f4_vv[2][pos[0]][pos[1]][0].v;
|
|
|
|
f4_volt[2][pos[0]][pos[1]][0].v += Op->f4_vi[2][pos[0]][pos[1]][0].v * ( f4_curr[1][pos[0]][pos[1]][0].v - f4_curr[1][pos[0]-shift[0]][pos[1]][0].v - f4_curr[0][pos[0]][pos[1]][0].v + f4_curr[0][pos[0]][pos[1]-shift[1]][0].v);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
2010-05-09 18:27:17 +00:00
|
|
|
++pos[0];
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-09 18:27:17 +00:00
|
|
|
void Engine_sse::UpdateCurrents(unsigned int startX, unsigned int numX)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
2010-04-21 12:29:02 +00:00
|
|
|
unsigned int pos[5];
|
|
|
|
f4vector temp;
|
|
|
|
|
2010-05-09 18:27:17 +00:00
|
|
|
pos[0] = startX;
|
|
|
|
for (unsigned int posX=0;posX<numX;++posX)
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
|
|
|
for (pos[1]=0;pos[1]<numLines[1]-1;++pos[1])
|
|
|
|
{
|
2010-05-01 11:06:13 +00:00
|
|
|
for (pos[2]=0;pos[2]<numVectors-1;++pos[2])
|
2010-04-21 09:18:22 +00:00
|
|
|
{
|
2010-04-21 12:29:02 +00:00
|
|
|
// x-pol
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_curr[0][pos[0]][pos[1]][pos[2]].v *= Op->f4_ii[0][pos[0]][pos[1]][pos[2]].v;
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_curr[0][pos[0]][pos[1]][pos[2]].v += Op->f4_iv[0][pos[0]][pos[1]][pos[2]].v * ( f4_volt[2][pos[0]][pos[1]][pos[2]].v - f4_volt[2][pos[0]][pos[1]+1][pos[2]].v - f4_volt[1][pos[0]][pos[1]][pos[2]].v + f4_volt[1][pos[0]][pos[1]][pos[2]+1].v);
|
2010-04-21 12:29:02 +00:00
|
|
|
|
|
|
|
// y-pol
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_curr[1][pos[0]][pos[1]][pos[2]].v *= Op->f4_ii[1][pos[0]][pos[1]][pos[2]].v;
|
2010-05-01 10:57:43 +00:00
|
|
|
f4_curr[1][pos[0]][pos[1]][pos[2]].v += Op->f4_iv[1][pos[0]][pos[1]][pos[2]].v * ( f4_volt[0][pos[0]][pos[1]][pos[2]].v - f4_volt[0][pos[0]][pos[1]][pos[2]+1].v - f4_volt[2][pos[0]][pos[1]][pos[2]].v + f4_volt[2][pos[0]+1][pos[1]][pos[2]].v);
|
2010-04-21 12:29:02 +00:00
|
|
|
|
|
|
|
// z-pol
|
2010-04-30 17:41:44 +00:00
|
|
|
f4_curr[2][pos[0]][pos[1]][pos[2]].v *= Op->f4_ii[2][pos[0]][pos[1]][pos[2]].v;
|
|
|
|
f4_curr[2][pos[0]][pos[1]][pos[2]].v += Op->f4_iv[2][pos[0]][pos[1]][pos[2]].v * ( f4_volt[1][pos[0]][pos[1]][pos[2]].v - f4_volt[1][pos[0]+1][pos[1]][pos[2]].v - f4_volt[0][pos[0]][pos[1]][pos[2]].v + f4_volt[0][pos[0]][pos[1]+1][pos[2]].v);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
2010-05-01 10:57:43 +00:00
|
|
|
|
2010-05-01 11:06:13 +00:00
|
|
|
// for pos[2] = numVectors-1
|
2010-05-01 10:57:43 +00:00
|
|
|
// x-pol
|
|
|
|
temp.f[0] = f4_volt[1][pos[0]][pos[1]][0].f[1];
|
|
|
|
temp.f[1] = f4_volt[1][pos[0]][pos[1]][0].f[2];
|
|
|
|
temp.f[2] = f4_volt[1][pos[0]][pos[1]][0].f[3];
|
|
|
|
temp.f[3] = 0;
|
2010-05-01 11:06:13 +00:00
|
|
|
f4_curr[0][pos[0]][pos[1]][numVectors-1].v *= Op->f4_ii[0][pos[0]][pos[1]][numVectors-1].v;
|
|
|
|
f4_curr[0][pos[0]][pos[1]][numVectors-1].v += Op->f4_iv[0][pos[0]][pos[1]][numVectors-1].v * ( f4_volt[2][pos[0]][pos[1]][numVectors-1].v - f4_volt[2][pos[0]][pos[1]+1][numVectors-1].v - f4_volt[1][pos[0]][pos[1]][numVectors-1].v + temp.v);
|
2010-05-01 10:57:43 +00:00
|
|
|
|
|
|
|
// y-pol
|
|
|
|
temp.f[0] = f4_volt[0][pos[0]][pos[1]][0].f[1];
|
|
|
|
temp.f[1] = f4_volt[0][pos[0]][pos[1]][0].f[2];
|
|
|
|
temp.f[2] = f4_volt[0][pos[0]][pos[1]][0].f[3];
|
|
|
|
temp.f[3] = 0;
|
2010-05-01 11:06:13 +00:00
|
|
|
f4_curr[1][pos[0]][pos[1]][numVectors-1].v *= Op->f4_ii[1][pos[0]][pos[1]][numVectors-1].v;
|
|
|
|
f4_curr[1][pos[0]][pos[1]][numVectors-1].v += Op->f4_iv[1][pos[0]][pos[1]][numVectors-1].v * ( f4_volt[0][pos[0]][pos[1]][numVectors-1].v - temp.v - f4_volt[2][pos[0]][pos[1]][numVectors-1].v + f4_volt[2][pos[0]+1][pos[1]][numVectors-1].v);
|
2010-05-01 10:57:43 +00:00
|
|
|
|
|
|
|
// z-pol
|
2010-05-01 11:06:13 +00:00
|
|
|
f4_curr[2][pos[0]][pos[1]][numVectors-1].v *= Op->f4_ii[2][pos[0]][pos[1]][numVectors-1].v;
|
|
|
|
f4_curr[2][pos[0]][pos[1]][numVectors-1].v += Op->f4_iv[2][pos[0]][pos[1]][numVectors-1].v * ( f4_volt[1][pos[0]][pos[1]][numVectors-1].v - f4_volt[1][pos[0]+1][pos[1]][numVectors-1].v - f4_volt[0][pos[0]][pos[1]][numVectors-1].v + f4_volt[0][pos[0]][pos[1]+1][numVectors-1].v);
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
2010-05-09 18:27:17 +00:00
|
|
|
++pos[0];
|
2010-04-21 09:18:22 +00:00
|
|
|
}
|
|
|
|
}
|