Create simulNDT.cpp
This commit is contained in:
120
UTSR/simulNDT.cpp
Normal file
120
UTSR/simulNDT.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <functional>
|
||||
|
||||
struct ScanData {
|
||||
std::vector<double> timeScale;
|
||||
struct CscanData {
|
||||
int AscanPoints;
|
||||
double TsGate;
|
||||
double TendGate;
|
||||
std::vector<double> X;
|
||||
int Rows;
|
||||
double Cl;
|
||||
double Cs;
|
||||
double Density;
|
||||
double Frequency;
|
||||
double Bandwidth;
|
||||
char WaveType;
|
||||
double BeamAngle;
|
||||
double ProbeDiameter;
|
||||
std::string DefectType;
|
||||
double PosX;
|
||||
double PosY;
|
||||
double DepthCentre;
|
||||
double Diameter;
|
||||
double Height;
|
||||
double Tilt;
|
||||
double MaxSignal;
|
||||
double MaxSdtRef;
|
||||
double Y;
|
||||
int Cols;
|
||||
std::vector<std::vector<double>> CscanValues;
|
||||
double Wavelength;
|
||||
double Nearfield;
|
||||
double ProbeEllipX;
|
||||
double ProbeEllipY;
|
||||
double TrueAngle;
|
||||
double CalValue;
|
||||
} CscanData;
|
||||
std::vector<std::vector<double>> AscanValues;
|
||||
};
|
||||
|
||||
struct Setup {
|
||||
// Define the setup structure here
|
||||
// This is a placeholder and should be filled with actual fields
|
||||
};
|
||||
|
||||
std::pair<ScanData, Setup> simulNDT(const std::map<std::string, std::variant<double, std::string, bool>>& args) {
|
||||
ScanData scanData;
|
||||
Setup setup;
|
||||
|
||||
// Parse input arguments
|
||||
double TsGate = std::get<double>(args.at("TsGate"));
|
||||
double TendGate = std::get<double>(args.at("TendGate"));
|
||||
double deltaT = std::get<double>(args.at("deltaT"));
|
||||
// ... Parse other arguments similarly
|
||||
|
||||
// Create timeScale element
|
||||
for (double t = TsGate; t <= TendGate; t += deltaT) {
|
||||
scanData.timeScale.push_back(t);
|
||||
}
|
||||
|
||||
// Define the time window for simulation
|
||||
std::vector<double> t;
|
||||
for (double time = TsGate; time <= TendGate; time += deltaT) {
|
||||
t.push_back(time);
|
||||
}
|
||||
int nt = t.size();
|
||||
int idxTsGate = std::lower_bound(t.begin(), t.end(), TsGate) - t.begin() - 1;
|
||||
int idxTendGate = std::lower_bound(t.begin(), t.end(), TendGate) - t.begin();
|
||||
|
||||
// Update scanData with arguments values
|
||||
scanData.CscanData.AscanPoints = scanData.timeScale.size();
|
||||
scanData.CscanData.TsGate = TsGate;
|
||||
scanData.CscanData.TendGate = TendGate;
|
||||
|
||||
// ... Update other fields of scanData.CscanData
|
||||
|
||||
// Create AscanValues element
|
||||
scanData.AscanValues.resize(scanData.CscanData.AscanPoints, std::vector<double>(scanData.CscanData.Rows, 0.0));
|
||||
|
||||
// Create default simulation setup
|
||||
setup = setup_maker(); // Assuming this function is defined elsewhere
|
||||
|
||||
// Define the frequency window for simulation
|
||||
std::vector<double> f;
|
||||
for (int i = -nt/2; i < nt/2; ++i) {
|
||||
f.push_back(i / (deltaT * nt));
|
||||
}
|
||||
setup.f = std::vector<double>(f.begin() + nt/2 + 1, f.end());
|
||||
|
||||
// Adjust material parameters
|
||||
// ... Adjust setup parameters
|
||||
|
||||
// Perform the simulation
|
||||
if (std::get<bool>(args.at("simul"))) {
|
||||
// ... Perform simulation
|
||||
}
|
||||
|
||||
return {scanData, setup};
|
||||
}
|
||||
/*
|
||||
|
||||
This C++ code provides a basic structure for the `simulNDT` function. Note that some parts are left as placeholders or comments, as the full implementation would require additional context and supporting functions. The code uses C++ standard library containers and algorithms where appropriate.
|
||||
|
||||
Key points:
|
||||
1. The `ScanData` and `Setup` structures are defined to hold the data.
|
||||
2. The function takes a map of string keys to variants (to allow different types of arguments) instead of using variable arguments.
|
||||
3. Standard C++ containers (`vector`, `map`) are used instead of Matlab arrays.
|
||||
4. C++ algorithms like `lower_bound` are used for operations like finding indices.
|
||||
5. The simulation loop is not fully implemented as it depends on functions not provided in the original code.
|
||||
|
||||
To complete this implementation, you would need to define the missing functions (like `setup_maker`, `SDH_PE_MM`, `TG_PE_MM`, `IFourierT`) and fill in the details of the simulation loop.
|
||||
|
||||
*/
|
Reference in New Issue
Block a user