diff --git a/FDTD/engine.cpp b/FDTD/engine.cpp index 5c7561e..eb05a67 100644 --- a/FDTD/engine.cpp +++ b/FDTD/engine.cpp @@ -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]numLines[0];++pos[0]) + for (pos[0]=0;pos[0]numLines[1];++pos[1]) + for (pos[1]=0;pos[1]numLines[2];++pos[2]) + for (pos[2]=0;pos[2]numLines[0]-1;++pos[0]) + for (pos[0]=0;pos[0]numLines[1]-1;++pos[1]) + for (pos[1]=0;pos[1]numLines[2]-1;++pos[2]) + for (pos[2]=0;pos[2]numLines[0] / (float)m_numThreads); + unsigned int linesPerThread = round((float)numLines[0] / (float)m_numThreads); for (unsigned int n=0; nnumLines[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]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 @@ -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]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 diff --git a/FDTD/operator.cpp b/FDTD/operator.cpp index 5c7eed1..559f7f6 100644 --- a/FDTD/operator.cpp +++ b/FDTD/operator.cpp @@ -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][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][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;iGetNumberOfLines(n)-1; } - //x-current if (m_start_inside[1] && m_start_inside[2]) for (unsigned int i=start[0];inumLines[0];++pos[0]) + for (pos[0]=0;pos[0]GetNumberOfLines(0);++pos[0]) { - for (pos[1]=0;pos[1]numLines[1];++pos[1]) + for (pos[1]=0;pos[1]GetNumberOfLines(1);++pos[1]) { - for (pos[2]=0;pos[2]numLines[2];++pos[2]) + for (pos[2]=0;pos[2]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]]);