108std::pair<std::vector<double>, std::vector<double>>
getRaySolution(mfem::GridFunction& u, mfem::Mesh&
mesh,
109 const std::vector<double>& rayDirection,
110 int numSamples, std::string filename) {
111 serif::config::Config&
config = serif::config::Config::getInstance();
113 quill::Logger* logger = logManager.
getLogger(
"log");
114 LOG_INFO(logger,
"Getting ray solution...");
118 bool makeDir =
config.get<
bool>(
"Probe:GetRaySolution:MakeDir",
true);
119 std::filesystem::path path = filename;
122 std::filesystem::path dir = path.parent_path();
123 if (!std::filesystem::exists(dir)) {
124 LOG_INFO(logger,
"Creating directory {}", dir.string());
125 std::filesystem::create_directories(dir);
128 if (!std::filesystem::exists(path.parent_path())) {
129 throw(std::runtime_error(
"Directory " + path.parent_path().string() +
" does not exist"));
133 std::vector<double> samples;
134 samples.reserve(numSamples);
135 double x, y, z, r, sampleValue;
137 mfem::Vector rayOrigin(3); rayOrigin = 0.0;
138 mfem::DenseMatrix rayPoints(3, numSamples);
139 std::vector<double> radialPoints;
140 radialPoints.reserve(numSamples);
141 mfem::ElementTransformation* Trans =
nullptr;
142 mfem::Vector physicalCoords;
144 for (
int i = 0; i < numSamples; i++) {
145 r = i * radius / numSamples;
147 x = r * std::sin(rayDirection[0]) * std::cos(rayDirection[1]);
148 y = r * std::sin(rayDirection[0]) * std::sin(rayDirection[1]);
149 z = r * std::cos(rayDirection[0]);
155 mfem::Array<int> elementIds;
156 mfem::Array<mfem::IntegrationPoint> ips;
157 mesh.FindPoints(rayPoints, elementIds, ips);
158 for (
int i = 0; i < elementIds.Size(); i++) {
159 Trans =
mesh.GetElementTransformation(elementIds[i]);
160 Trans->Transform(ips[i], physicalCoords);
161 double r = std::sqrt(physicalCoords[0] * physicalCoords[0] +
162 physicalCoords[1] * physicalCoords[1] +
163 physicalCoords[2] * physicalCoords[2]);
164 radialPoints.push_back(r);
166 int elementId = elementIds[i];
167 mfem::IntegrationPoint ip = ips[i];
168 if (elementId >= 0) {
169 sampleValue = u.GetValue(elementId, ip);
170 LOG_DEBUG(logger,
"Probe::getRaySolution() : Ray point {} found in element {} with r={:0.2f} and theta={:0.2f}", i, elementId, r, sampleValue);
171 samples.push_back(sampleValue);
173 LOG_INFO(logger,
"Probe::getRaySolution() : Ray point {} not found", i);
174 samples.push_back(0.0);
177 std::pair<std::vector<double>, std::vector<double>> samplesPair(radialPoints, samples);
179 if (!filename.empty()) {
180 std::ofstream file(filename);
181 if (file.is_open()) {
183 for (
int i = 0; i < numSamples; i++) {
184 file << samplesPair.first[i] <<
"," << samplesPair.second[i] <<
"\n";
189 throw(std::runtime_error(
"Could not open file " + filename));
196std::pair<std::vector<double>, std::vector<double>>
getRaySolution(mfem::Vector &vec, mfem::FiniteElementSpace &fes,
197 const std::vector<double>& rayDirection,
198 int numSamples, std::string filename) {
199 mfem::GridFunction gf(&fes);
203 return getRaySolution(gf, *fes.GetMesh(), rayDirection, numSamples, filename);