📄 radarfdtd.cpp
字号:
/* time */
ReadNextLine(configFile, string);
sscanf(string, "%g\n", &a);
dt = (PRECISION) a;
/* range checking: must not be 0 */
if (fabs(dt) < LIMIT)
{
warningStop = 1;
fprintf(stderr, "WARNING: timestep is 0!\n");
}
/* when to call the output routine for 'output.dat' */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &timeToPlotReceiver);
/* range checking: must not be negative */
if (timeToPlotReceiver < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: receiver plot divider is less than 0!\n");
}
/* when to call the output routine for a snapshot */
ReadNextLine(configFile, string);
sscanf(string, "%d %d %d %d\n", &timeToPlotSnapshot, &snapshotPlane, &snapshotPosition, &snapshotMode);
/* range checking: must not be negative */
if (timeToPlotSnapshot < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot plot divider is less than 0!\n");
}
if ((snapshotPlane < 1) || (snapshotPlane > 3))
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot plane number is not valid!\n");
}
switch(snapshotPlane)
{
case 1:
if ((snapshotPosition < 0) || (snapshotPosition >= nx))
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot plane position is out of range!\n");
}
break;
case 2:
if ((snapshotPosition < 0) || (snapshotPosition >= ny))
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot plane position is out of range!\n");
}
break;
case 3:
if ((snapshotPosition < 0) || (snapshotPosition >= nz))
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot plane position is out of range!\n");
}
break;
default:;
}
if ((snapshotMode < 0) || (snapshotMode > 7))
{
warningStop = 1;
fprintf(stderr, "WARNING: snapshot mode is not valid!\n"); // error
}
/* width of pmls */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &pmlWidth);
/* range checking: must not be negative */
if (pmlWidth < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: number of PM-Layers is less than 0!\n");
}
/* materials, first maximum number of materials */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &maxMaterials);
/* range checking: must not be negative */
if (maxMaterials < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: number different materials is less than 0!\n");
}
/* allocate that much memory */
materialConstants = (PRECISION **) malloc((maxMaterials+2) * sizeof(PRECISION *));
if (materialConstants == NULL)
{
fprintf(stderr, "I cannot allocate memory for the constants.\n");
exit(1);
}
for (i=0; i<maxMaterials+2; i++)
{
materialConstants[i] = (PRECISION *) malloc(9 * sizeof(PRECISION));
if (materialConstants[i] == NULL)
{
fprintf(stderr, "I cannot allocate memory for the constants.\n");
exit(1);
}
for(j=0; j<9; j++)
materialConstants[i][j] = 0.0;
}
/* read that number of materials */
maxEpsilon = 1;
for(i=0; i<maxMaterials; i++)
{
ReadNextLine(configFile, string);
sscanf(string, "%g %g\n", &a, &b);
materialConstants[i+2][0] = (PRECISION) a;
materialConstants[i+2][1] = (PRECISION) b;
if (maxEpsilon < a) maxEpsilon = a;
/* range checking: must not be negative */
if (a < 0.0)
{
warningStop = 1;
fprintf(stderr, "WARNING: epsilon for material %d is less than 0!\n", i);
}
if (b < 0.0)
{
warningStop = 1;
fprintf(stderr, "WARNING: sigma for material %d is less than 0!\n", i);
}
}
/* allocate memory for materials */
material = MyAllocShortInt(nx, ny, nz,&storage);
/* number of boxes */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &numberOfBoxes);
for(h=0; h<numberOfBoxes; h++)
{
ReadNextLine(configFile, string);
sscanf(string, "%d %d %d %d %d %d %d\n", &boxStartX, &boxStartY, &boxStartZ, &boxEndX, &boxEndY, &boxEndZ, ¤tMaterial);
/* range checking: must be within simspace */
if (\
(boxStartX >= 0) && (boxStartX < nx) && \
(boxStartY >= 0) && (boxStartY < ny) && \
(boxStartZ >= 0) && (boxStartZ < nz) && \
(boxEndX >= 0) && (boxEndX < nx) && \
(boxEndY >= 0) && (boxEndY < ny) && \
(boxEndZ >= 0) && (boxEndZ < nz) && \
(boxStartX <= boxEndX) && (boxStartY <= boxEndY) && (boxStartZ <= boxEndZ))
{
for(i=boxStartX; i<=boxEndX; i++)
for(j=boxStartY; j<=boxEndY; j++)
for(k=boxStartZ; k<=boxEndZ; k++)
material[i][j][k] = currentMaterial;
}
else
{
warningStop = 1;
fprintf(stderr, "WARNING: error in material box #%d coordinated\n", h);
}
}
/* how many transmitter boxes are used? */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &numberOfTransmitterBoxes);
/* range checking: must not be negative */
if (numberOfTransmitterBoxes < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: number of receiver boxes is less than 0!\n");
}
/* get some temporary memory */
tmpTransmitter = (int **) malloc(numberOfTransmitterBoxes * sizeof(int *));
if (tmpTransmitter == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
for(h=0; h<numberOfTransmitterBoxes; h++)
{
tmpTransmitter[h] = (int *) malloc(8 * sizeof(int));
if (tmpTransmitter[h] == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
}
maxTransmitter = 0;
for(h=0; h<numberOfTransmitterBoxes; h++)
{
ReadNextLine(configFile, string);
sscanf(string, "%d %d %d %d %d %d %d\n", &tmpTransmitter[h][0], &tmpTransmitter[h][1], &tmpTransmitter[h][2], &tmpTransmitter[h][3], &tmpTransmitter[h][4], &tmpTransmitter[h][5], &tmpTransmitter[h][6]);
}
for(h=0; h<numberOfTransmitterBoxes; h++)
{
if (\
(tmpTransmitter[h][0] >= 0) && (tmpTransmitter[h][0] < nx) && \
(tmpTransmitter[h][1] >= 0) && (tmpTransmitter[h][1] < ny) && \
(tmpTransmitter[h][2] >= 0) && (tmpTransmitter[h][2] < nz) && \
(tmpTransmitter[h][3] >= 0) && (tmpTransmitter[h][3] < nx) && \
(tmpTransmitter[h][4] >= 0) && (tmpTransmitter[h][4] < ny) && \
(tmpTransmitter[h][5] >= 0) && (tmpTransmitter[h][5] < nz) && \
(tmpTransmitter[h][0] <= tmpTransmitter[h][3]) && (tmpTransmitter[h][1] <= tmpTransmitter[h][4]) && (tmpTransmitter[h][2] <= tmpTransmitter[h][5]) && \
(tmpTransmitter[h][6] > 0) \
)
{
for(i=tmpTransmitter[h][0]; i<=tmpTransmitter[h][3]; i+=tmpTransmitter[h][6])
for(j=tmpTransmitter[h][1]; j<=tmpTransmitter[h][4]; j+=tmpTransmitter[h][6])
for(k=tmpTransmitter[h][2]; k<=tmpTransmitter[h][5]; k+=tmpTransmitter[h][6])
maxTransmitter++;
transmitter = (int **) malloc(maxTransmitter * sizeof(int *));
if (transmitter == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
for(i=0; i<maxTransmitter; i++)
{
transmitter[i] = (int *) malloc(3 * sizeof(int));
if (transmitter[i] == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
}
tmpCounter = 0;
for(i=tmpTransmitter[h][0]; i<=tmpTransmitter[h][3]; i+=tmpTransmitter[h][6])
for(j=tmpTransmitter[h][1]; j<=tmpTransmitter[h][4]; j+=tmpTransmitter[h][6])
for(k=tmpTransmitter[h][2]; k<=tmpTransmitter[h][5]; k+=tmpTransmitter[h][6])
{
transmitter[tmpCounter][0] = i;
transmitter[tmpCounter][1] = j;
transmitter[tmpCounter][2] = k;
tmpCounter++;
}
}
else
{
warningStop = 1;
fprintf(stderr, "WARNING: error in transmitter box #%d coordinates \n", h);
}
}
for(h=0; h<numberOfTransmitterBoxes; h++)
free(tmpTransmitter[h]);
free(tmpTransmitter);
/* which transmitter mode is used? */
ReadNextLine(configFile, string);
sscanf(string, "%d %f %f %f %f %d\n", &transmitterMode, &a, &b, &c, &d, &transmitterStimulusComponent);
transmitterAmplitude = (PRECISION) a;
transmitterCharacteristicTime = (PRECISION) b;
transmitterFrequency = (PRECISION) c;
transmitterParameter = (PRECISION) d;
/* range checking: ONLY THE LAST COMPONENT IS CURRENTLY CHECKED!!! */
if ((transmitterStimulusComponent < 0) || (transmitterStimulusComponent > 2))
{
warningStop = 1;
fprintf(stderr, "WARNING: stimulus component of the transmitter is out of range\n");
}
/* how many receiving boxes are used? */
ReadNextLine(configFile, string);
sscanf(string, "%d\n", &numberOfReceiverBoxes);
/* range checking: must not be negative */
if (numberOfReceiverBoxes < 0)
{
warningStop = 1;
fprintf(stderr, "WARNING: number of receiver boxes is less than 0!\n");
}
/* get some temporary memory */
tmpReceiver = (int **) malloc(numberOfReceiverBoxes * sizeof(int *));
if (tmpReceiver == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
for(h=0; h<numberOfReceiverBoxes; h++)
{
tmpReceiver[h] = (int *) malloc(8 * sizeof(int));
if (tmpReceiver[h] == NULL)
{
fprintf(stderr, "Not enough memory available!\n");
exit(1);
}
}
maxReceiver = 0;
for(h=0; h<numberOfReceiverBoxes; h++)
{
ReadNextLine(configFile, string);
sscanf(string, "%d %d %d %d %d %d %d %d\n", &tmpReceiver[h][0], &tmpReceiver[h][1], &tmpReceiver[h][2], &tmpReceiver[h][3], &tmpReceiver[h][4], &tmpReceiver[h][5], &tmpReceiver[h][6], &tmpReceiver[h][7]);
}
for(h=0; h<numberOfReceiverBoxes; h++)
{
if (\
(tmpReceiver[h][0] >= 0) && (tmpReceiver[h][0] < nx) && \
(tmpReceiver[h][1] >= 0) && (tmpReceiver[h][1] < ny) && \
(tmpReceiver[h][2] >= 0) && (tmpReceiver[h][2] < nz) && \
(tmpReceiver[h][3] >= 0) && (tmpReceiver[h][3] < nx) && \
(tmpReceiver[h][4] >= 0) && (tmpReceiver[h][4] < ny) && \
(tmpReceiver[h][5] >= 0) && (tmpReceiver[h][5] < nz) && \
(tmpReceiver[h][0] <= tmpReceiver[h][3]) && (tmpReceiver[h][1] <= tmpReceiver[h][4]) && (tmpReceiver[h][2] <= tmpReceiver[h][5]) && \
(tmpReceiver[h][6] >= 0) && (tmpReceiver[h][6] <= 7) && \
(tmpReceiver[h][7] > 0) \
)
{
for(i=tmpReceiver[h][0]; i<=tmpReceiver[h][3]; i+=tmpReceiver[h][7])
for(j=tmpReceiver[h][1]; j<=tmpReceiver[h][4]; j+=tmpReceiver[h][7])
for(k=tmpReceiver[h][2]; k<=tmpReceiver[h][5]; k+=tmpReceiver[h][7])
maxReceiver++;
receiver = (int **) malloc(maxReceiver * sizeof(int *));
if (receiver == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -