Access function for number of Lines

pull/1/head
Thorsten Liebig 2010-04-11 23:42:54 +02:00
parent bd315b1c21
commit 3b29514d16
7 changed files with 54 additions and 28 deletions

View File

@ -30,25 +30,29 @@ Engine* Engine::New(const Operator* op)
Engine::Engine(const Operator* op)
{
Op = op;
for (int n=0;n<3;++n)
{
numLines[n] = Op->GetNumberOfLines(n);
}
}
Engine::~Engine()
{
Reset();
this->Reset();
}
void Engine::Init()
{
numTS = 0;
volt = Create_N_3DArray(Op->numLines);
curr = Create_N_3DArray(Op->numLines);
volt = Create_N_3DArray(numLines);
curr = Create_N_3DArray(numLines);
}
void Engine::Reset()
{
Delete_N_3DArray(volt,Op->numLines);
Delete_N_3DArray(volt,numLines);
volt=NULL;
Delete_N_3DArray(curr,Op->numLines);
Delete_N_3DArray(curr,numLines);
curr=NULL;
}
@ -58,13 +62,13 @@ inline void Engine::UpdateVoltages()
bool shift[3];
//voltage updates
for (pos[0]=0;pos[0]<Op->numLines[0];++pos[0])
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
shift[0]=pos[0];
for (pos[1]=0;pos[1]<Op->numLines[1];++pos[1])
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
shift[1]=pos[1];
for (pos[2]=0;pos[2]<Op->numLines[2];++pos[2])
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
shift[2]=pos[2];
//do the updates here
@ -100,11 +104,11 @@ inline void Engine::ApplyVoltageExcite()
inline void Engine::UpdateCurrents()
{
unsigned int pos[3];
for (pos[0]=0;pos[0]<Op->numLines[0]-1;++pos[0])
for (pos[0]=0;pos[0]<numLines[0]-1;++pos[0])
{
for (pos[1]=0;pos[1]<Op->numLines[1]-1;++pos[1])
for (pos[1]=0;pos[1]<numLines[1]-1;++pos[1])
{
for (pos[2]=0;pos[2]<Op->numLines[2]-1;++pos[2])
for (pos[2]=0;pos[2]<numLines[2]-1;++pos[2])
{
//do the updates here
//for x

View File

@ -46,6 +46,8 @@ protected:
virtual inline void UpdateCurrents();
virtual inline void ApplyCurrentExcite();
unsigned int numLines[3];
FDTD_FLOAT**** volt;
FDTD_FLOAT**** curr;
unsigned int numTS;

View File

@ -87,14 +87,14 @@ void Engine_Multithread::Init()
m_startBarrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
m_stopBarrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
unsigned int linesPerThread = round((float)Op->numLines[0] / (float)m_numThreads);
unsigned int linesPerThread = round((float)numLines[0] / (float)m_numThreads);
for (unsigned int n=0; n<m_numThreads; n++) {
unsigned int start = n * linesPerThread;
unsigned int stop = (n+1) * linesPerThread - 1;
unsigned int stop_h = stop;
if (n == m_numThreads-1) {
// last thread
stop = Op->numLines[0]-1;
stop = numLines[0]-1;
stop_h = stop-1;
}
//NS_Engine_Multithread::DBG().cout() << "###DEBUG## Thread " << n << ": start=" << start << " stop=" << stop << " stop_h=" << stop_h << std::endl;
@ -176,10 +176,10 @@ void thread::operator()()
for (pos[0]=m_start;pos[0]<=m_stop;++pos[0])
{
shift[0]=pos[0];
for (pos[1]=0;pos[1]<m_enginePtr->Op->numLines[1];++pos[1])
for (pos[1]=0;pos[1]<m_enginePtr->numLines[1];++pos[1])
{
shift[1]=pos[1];
for (pos[2]=0;pos[2]<m_enginePtr->Op->numLines[2];++pos[2])
for (pos[2]=0;pos[2]<m_enginePtr->numLines[2];++pos[2])
{
shift[2]=pos[2];
//do the updates here
@ -218,9 +218,9 @@ void thread::operator()()
//current updates
for (pos[0]=m_start;pos[0]<=m_stop_h;++pos[0])
{
for (pos[1]=0;pos[1]<m_enginePtr->Op->numLines[1]-1;++pos[1])
for (pos[1]=0;pos[1]<m_enginePtr->numLines[1]-1;++pos[1])
{
for (pos[2]=0;pos[2]<m_enginePtr->Op->numLines[2]-1;++pos[2])
for (pos[2]=0;pos[2]<m_enginePtr->numLines[2]-1;++pos[2])
{
//do the updates here
//for x

View File

@ -105,15 +105,32 @@ unsigned int Operator::CalcNyquistNum(double fmax)
bool Operator::SnapToMesh(double* dcoord, unsigned int* uicoord, bool lower, bool* inside)
{
bool ok=true;
unsigned int numLines[3];
for (int n=0;n<3;++n)
{
numLines[n] = GetNumberOfLines(n);
if (inside) //set defaults
inside[n] = true;
uicoord[n]=0;
if (dcoord[n]<discLines[n][0]) {ok=false;uicoord[n]=0; if (inside) inside[n] = false;}
else if (dcoord[n]==discLines[n][0]) {uicoord[n]=0;}
else if (dcoord[n]>discLines[n][numLines[n]-1]) {ok=false;uicoord[n]=numLines[n]-1; if (lower) uicoord[n]=numLines[n]-2; if (inside) inside[n] = false; }
else if (dcoord[n]==discLines[n][numLines[n]-1]) {uicoord[n]=numLines[n]-1; if (lower) uicoord[n]=numLines[n]-2;}
if (dcoord[n]<discLines[n][0])
{
ok=false;uicoord[n]=0;
if (inside) inside[n] = false;
}
else if (dcoord[n]==discLines[n][0])
uicoord[n]=0;
else if (dcoord[n]>discLines[n][numLines[n]-1])
{
ok=false;
uicoord[n]=numLines[n]-1;
if (lower) uicoord[n]=numLines[n]-2;
if (inside) inside[n] = false;
}
else if (dcoord[n]==discLines[n][numLines[n]-1])
{
uicoord[n]=numLines[n]-1;
if (lower) uicoord[n]=numLines[n]-2;
}
else
for (unsigned int i=1;i<numLines[n];++i)
{
@ -516,7 +533,6 @@ void Operator::ApplyElectricBC(bool* dirs)
{
if (dirs==NULL) return;
unsigned int pos[3];
unsigned int ipos;
for (int n=0;n<3;++n)
{
int nP = (n+1)%3;

View File

@ -56,6 +56,8 @@ public:
double GetTimestep() const {return dT;};
double GetNumberCells() const;
virtual unsigned int GetNumberOfLines(int ny) const {return numLines[ny];}
void SetNyquistNum(unsigned int nyquist) {m_nyquistTS=nyquist;}
unsigned int GetNyquistNum() const {return m_nyquistTS;};
unsigned int CalcNyquistNum(double fmax);
@ -108,9 +110,10 @@ protected:
double* EC_L[3];
double* EC_R[3];
// engine/post-proc needs access
public:
unsigned int numLines[3];
// engine/post-proc needs access
public:
double* discLines[3];
double gridDelta;
AdrOp* MainOp;

View File

@ -66,8 +66,9 @@ int ProcessCurrent::Process()
m_start_inside[n] = m_stop_inside[n];
m_stop_inside[n] = b_help;
}
if (m_stop_inside[n]==false) // integrate up to the wall, Operator::SnapToMesh would give numLines[n]-2
stop[n]=Op->GetNumberOfLines(n)-1;
}
//x-current
if (m_start_inside[1] && m_start_inside[2])
for (unsigned int i=start[0];i<stop[0];++i)

View File

@ -173,11 +173,11 @@ double ProcessFields::CalcTotalEnergy()
double energy=0;
if (Eng==NULL) return 0.0;
unsigned int pos[3];
for (pos[0]=0;pos[0]<Op->numLines[0];++pos[0])
for (pos[0]=0;pos[0]<Op->GetNumberOfLines(0);++pos[0])
{
for (pos[1]=0;pos[1]<Op->numLines[1];++pos[1])
for (pos[1]=0;pos[1]<Op->GetNumberOfLines(1);++pos[1])
{
for (pos[2]=0;pos[2]<Op->numLines[2];++pos[2])
for (pos[2]=0;pos[2]<Op->GetNumberOfLines(2);++pos[2])
{
energy+=fabs(volt[0][pos[0]][pos[1]][pos[2]] * curr[1][pos[0]][pos[1]][pos[2]]);
energy+=fabs(volt[0][pos[0]][pos[1]][pos[2]] * curr[2][pos[0]][pos[1]][pos[2]]);