voltage probes: better voltage integration with direction

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
pull/81/head
Thorsten Liebig 2021-08-25 19:05:11 +02:00
parent 2a7506482c
commit bad842a710
8 changed files with 54 additions and 17 deletions

View File

@ -16,6 +16,7 @@
*/ */
#include "processvoltage.h" #include "processvoltage.h"
#include "FDTD/engine_interface_fdtd.h"
#include <iomanip> #include <iomanip>
ProcessVoltage::ProcessVoltage(Engine_Interface_Base* eng_if) : ProcessIntegral(eng_if) ProcessVoltage::ProcessVoltage(Engine_Interface_Base* eng_if) : ProcessIntegral(eng_if)
@ -33,6 +34,12 @@ std::string ProcessVoltage::GetIntegralName(int row) const
return "unknown"; return "unknown";
} }
void ProcessVoltage::DefineStartStopCoord(double* dstart, double* dstop)
{
Op->SnapToMesh(dstart, start, m_dualMesh, false, m_start_inside);
Op->SnapToMesh(dstop, stop, m_dualMesh, false, m_stop_inside);
}
double ProcessVoltage::CalcIntegral() double ProcessVoltage::CalcIntegral()
{ {
//integrate voltages from start to stop on a line //integrate voltages from start to stop on a line

View File

@ -31,6 +31,8 @@ public:
virtual std::string GetIntegralName(int row) const; virtual std::string GetIntegralName(int row) const;
virtual void DefineStartStopCoord(double* dstart, double* dstop);
virtual double CalcIntegral(); virtual double CalcIntegral();
protected: protected:

View File

@ -199,6 +199,12 @@ double* Engine_Interface_FDTD::GetRawInterpolatedDualField(const unsigned int* p
double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const
{ {
if ((start[0]!=stop[0] + start[1]!=stop[1] + start[2]!=stop[2])!=1)
{
cerr << "Engine_Interface_FDTD::CalcVoltageIntegral: Error, only a 1D/line integration is allowed" << endl;
return 0;
}
//cerr << "CalcVoltageIntegral" << start[0] << ", " << start[1] << ", " << start[2] << " -> " << stop[0] << ", " << stop[1] << ", " << stop[2] << ", " << endl;
double result=0; double result=0;
for (int n=0; n<3; ++n) for (int n=0; n<3; ++n)
{ {
@ -207,6 +213,7 @@ double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, con
unsigned int pos[3]={start[0],start[1],start[2]}; unsigned int pos[3]={start[0],start[1],start[2]};
for (; pos[n]<stop[n]; ++pos[n]) for (; pos[n]<stop[n]; ++pos[n])
result += m_Eng->GetVolt(n,pos[0],pos[1],pos[2]); result += m_Eng->GetVolt(n,pos[0],pos[1],pos[2]);
} }
else else
{ {
@ -218,6 +225,34 @@ double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, con
return result; return result;
} }
//double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const
//{
// //cerr << "CalcVoltageIntegral" << start[0] << ", " << start[1] << ", " << start[2] << " -> " << stop[0] << ", " << stop[1] << ", " << stop[2] << ", " << endl;
// double result=0;
// //unsigned int pos[3]={min(start[0],stop[0]),min(start[1],stop[1]),min(start[2],stop[2])};
// unsigned int pos[3]={start[0],start[1],start[2]};
// for (int n=0; n<3; ++n)
// {
// if (start[n]<stop[n])
// {
// for (; pos[n]<stop[n]; ++pos[n])
// {
// //cerr << "at pos: " << n << ": " << pos[0] << ", " << pos[1] << ", " << pos[2] << endl;
// result += m_Eng->GetVolt(n,pos[0],pos[1],pos[2]);
// }
// }
// else
// {
// for (--pos[n]; pos[n]>=stop[n]; --pos[n])
// {
// //cerr << "at neg: " << n << ": " << pos[0] << ", " << pos[1] << ", " << pos[2] << endl;
// result -= m_Eng->GetVolt(n,pos[0],pos[1],pos[2]);
// }
// }
// pos[n] = stop[n];
// }
// return result;
//}
double Engine_Interface_FDTD::GetRawField(unsigned int n, const unsigned int* pos, int type) const double Engine_Interface_FDTD::GetRawField(unsigned int n, const unsigned int* pos, int type) const
{ {

View File

@ -187,7 +187,7 @@ width_add_stop(idx_width) = (nstop(idx_width)-nstart(idx_width))/2+gap_width;
weight = 0.5; weight = 0.5;
% create the voltage-probes % create the voltage-probes
port.U_filename{1,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'A1']; port.U_filename{1,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'A1'];
CSX = AddProbe( CSX, port.U_filename{1,1}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{1,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{1,1}, prio, v1_start-width_add_start, v1_stop-width_add_stop); CSX = AddBox( CSX, port.U_filename{1,1}, prio, v1_start-width_add_start, v1_stop-width_add_stop);
port.U_filename{1,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'A2']; port.U_filename{1,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'A2'];
@ -196,7 +196,7 @@ CSX = AddBox( CSX, port.U_filename{1,2}, prio, v1_start+width_add_start, v1_stop
port.U_filename{2,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'B1']; port.U_filename{2,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'B1'];
CSX = AddProbe( CSX, port.U_filename{2,1}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{2,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{2,1}, prio, v2_start-width_add_start, v2_stop-width_add_stop ); CSX = AddBox( CSX, port.U_filename{2,1}, prio, v2_start-width_add_start, v2_stop-width_add_stop );
port.U_filename{2,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B2']; port.U_filename{2,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B2'];
@ -205,7 +205,7 @@ CSX = AddBox( CSX, port.U_filename{2,2}, prio, v2_start+width_add_start, v2_stop
port.U_filename{3,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'C1']; port.U_filename{3,1} = [PortNamePrefix 'port_ut' num2str(portnr) 'C1'];
CSX = AddProbe( CSX, port.U_filename{3,1}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{3,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{3,1}, prio, v3_start-width_add_start, v3_stop-width_add_stop ); CSX = AddBox( CSX, port.U_filename{3,1}, prio, v3_start-width_add_start, v3_stop-width_add_stop );
port.U_filename{3,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'C2']; port.U_filename{3,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'C2'];

View File

@ -115,7 +115,7 @@ u_start(n_dir) = start(n_dir);
u_stop(n_dir) = stop(n_dir); u_stop(n_dir) = stop(n_dir);
port.U_filename = [PortNamePrefix 'port_ut' int2str(portnr)]; port.U_filename = [PortNamePrefix 'port_ut' int2str(portnr)];
CSX = AddProbe(CSX, port.U_filename, 0, 'weight', -direction*V_Probe_Weight); CSX = AddProbe(CSX, port.U_filename, 0, 'weight', -1*V_Probe_Weight);
CSX = AddBox(CSX, port.U_filename, prio, u_start, u_stop); CSX = AddBox(CSX, port.U_filename, prio, u_start, u_stop);
i_start = start; i_start = start;

View File

@ -136,13 +136,6 @@ else
direction = -1; direction = -1;
end end
% direction of propagation
if stop(idx_height)-start(idx_height) > 0
upsidedown = +1;
else
upsidedown = -1;
end
% create the metal/material for the MSL % create the metal/material for the MSL
MSL_start = start; MSL_start = start;
MSL_stop = stop; MSL_stop = stop;
@ -206,7 +199,7 @@ end
% create the probes % create the probes
port.U_filename{1} = [PortNamePrefix 'port_ut' num2str(portnr) 'A']; port.U_filename{1} = [PortNamePrefix 'port_ut' num2str(portnr) 'A'];
% weight = sign(stop(idx_height)-start(idx_height)) % weight = sign(stop(idx_height)-start(idx_height))
weight = upsidedown; weight = 1;
CSX = AddProbe( CSX, port.U_filename{1}, 0, 'weight', weight ); CSX = AddProbe( CSX, port.U_filename{1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{1}, prio, v1_start, v1_stop ); CSX = AddBox( CSX, port.U_filename{1}, prio, v1_start, v1_stop );
port.U_filename{2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B']; port.U_filename{2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B'];

View File

@ -189,7 +189,7 @@ CSX = AddProbe( CSX, port.U_filename{1,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{1,1}, prio, v1_start, v1_stop+height_vector); CSX = AddBox( CSX, port.U_filename{1,1}, prio, v1_start, v1_stop+height_vector);
port.U_filename{1,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'A2']; port.U_filename{1,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'A2'];
CSX = AddProbe( CSX, port.U_filename{1,2}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{1,2}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{1,2}, prio, v1_start, v1_stop-height_vector); CSX = AddBox( CSX, port.U_filename{1,2}, prio, v1_start, v1_stop-height_vector);
@ -198,7 +198,7 @@ CSX = AddProbe( CSX, port.U_filename{2,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{2,1}, prio, v2_start, v2_stop+height_vector ); CSX = AddBox( CSX, port.U_filename{2,1}, prio, v2_start, v2_stop+height_vector );
port.U_filename{2,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B2']; port.U_filename{2,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B2'];
CSX = AddProbe( CSX, port.U_filename{2,2}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{2,2}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{2,2}, prio, v2_start, v2_stop-height_vector ); CSX = AddBox( CSX, port.U_filename{2,2}, prio, v2_start, v2_stop-height_vector );
@ -207,7 +207,7 @@ CSX = AddProbe( CSX, port.U_filename{3,1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{3,1}, prio, v3_start, v3_stop+height_vector ); CSX = AddBox( CSX, port.U_filename{3,1}, prio, v3_start, v3_stop+height_vector );
port.U_filename{3,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'C2']; port.U_filename{3,2} = [PortNamePrefix 'port_ut' num2str(portnr) 'C2'];
CSX = AddProbe( CSX, port.U_filename{3,2}, 0, 'weight', -1*weight ); CSX = AddProbe( CSX, port.U_filename{3,2}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{3,2}, prio, v3_start, v3_stop-height_vector ); CSX = AddBox( CSX, port.U_filename{3,2}, prio, v3_start, v3_stop-height_vector );
% calculate position of the current probes % calculate position of the current probes

View File

@ -175,7 +175,7 @@ class LumpedPort(Port):
u_start[self.exc_ny] = self.start[self.exc_ny] u_start[self.exc_ny] = self.start[self.exc_ny]
u_stop = 0.5*(self.start+self.stop) u_stop = 0.5*(self.start+self.stop)
u_stop[self.exc_ny] = self.stop[self.exc_ny] u_stop[self.exc_ny] = self.stop[self.exc_ny]
u_probe = CSX.AddProbe(self.U_filenames[0], p_type=0, weight=-1*self.direction) u_probe = CSX.AddProbe(self.U_filenames[0], p_type=0, weight=-1)
u_probe.AddBox(u_start, u_stop) u_probe.AddBox(u_start, u_stop)
self.I_filenames = [self.lbl_temp.format('it'), ] self.I_filenames = [self.lbl_temp.format('it'), ]
@ -259,7 +259,7 @@ class MSLPort(Port):
u_stop[self.exc_ny] = self.stop [self.exc_ny] u_stop[self.exc_ny] = self.stop [self.exc_ny]
u_name = self.lbl_temp.format('ut') + suffix[n] u_name = self.lbl_temp.format('ut') + suffix[n]
self.U_filenames.append(u_name) self.U_filenames.append(u_name)
u_probe = CSX.AddProbe(u_name, p_type=0, weight=self.upside_down) u_probe = CSX.AddProbe(u_name, p_type=0)
u_probe.AddBox(u_start, u_stop) u_probe.AddBox(u_start, u_stop)
i_prope_pos = u_prope_pos[0:2] + np.diff(u_prope_pos)/2.0 i_prope_pos = u_prope_pos[0:2] + np.diff(u_prope_pos)/2.0