Hello everyone (and most importantly, hello @hschindl!),
I am currently working on a tool to generate/read/merge gas files (any feedback on this is very welcome!) and I am facing some issues when merging a large amount of gas files.
In particular, in order to simulate a mixture for a large number of electric field points (n), I have split the simulation in n jobs each with a single electric field point (please, if there is any potential issue with this appoach let me know!). Afterwards my idea is to merge the files into a single one in a similar fashion to this example.
The following code attempts to do this:
// main.cpp
#include <algorithm>
#include <filesystem>
#include <iostream>
#include <string>
#include "Garfield/MediumMagboltz.hh"
using namespace std;
using namespace Garfield;
std::vector<double> GetElectricFieldValues(MediumMagboltz& gas) {
vector<double> electricField, magneticField, angle;
gas.GetFieldGrid(electricField, magneticField, angle);
// sort electric field in case it's not ordered
sort(electricField.begin(), electricField.end());
return electricField;
}
int main() {
string path = "/root/C4H10-10.0-Ar/";
string mergeOutput = "/tmp/merge.gas";
vector<string> files;
for (const auto& entry: std::filesystem::directory_iterator(path)) {
if (entry.path().extension() != ".gas") {
continue;
}
files.emplace_back(entry.path());
}
cout << "number of gas files: " << files.size() << endl;
for (int i = 0; i < files.size() - 1; i++) {
MediumMagboltz gas;
if (i == 0) {
// in the first iteration the merge file does not exist yet
gas.LoadGasFile(files[0]);
} else {
gas.LoadGasFile(mergeOutput);
}
cout << "Electric field values for base gas file: " << files[i];
for (const auto& value: GetElectricFieldValues(gas)) {
cout << " " << value;
}
cout << endl;
{
MediumMagboltz gasToMerge;
gasToMerge.LoadGasFile(files[i + 1]);
cout << "Electric field values for gas file to merge: " << files[i + 1];
for (const auto& value: GetElectricFieldValues(gasToMerge)) {
cout << " " << value;
}
cout << endl;
}
constexpr bool replaceOld = false;
gas.MergeGasFile(files[i + 1], replaceOld);
gas.WriteGasFile(mergeOutput);
}
MediumMagboltz gas;
gas.LoadGasFile(mergeOutput);
cout << "Electric field values for merged gas file: " << mergeOutput;
for (const auto& value: GetElectricFieldValues(gas)) {
cout << " " << value;
}
cout << endl;
cout << "Number of electric field values: " << GetElectricFieldValues(gas).size() << endl;
return 0;
}
# CMakeLists.txt
find_package(Garfield REQUIRED)
add_executable(demo main.cpp)
target_link_libraries(demo PUBLIC Garfield::Garfield)
The code will print the electric field values present in each file, which matches the substring in the filename.
The issue is that some electric field values are missing from the merged file, there are warnings for some iterations (Keeping existing data for E = 4445 V/cm, not using data from the file.
etc.) warning that the value for e-field is already present on the file (but this is not the case!), when the warning appears there is no new e-field value added.
I attach the same gas files I used for testing, perhaps there is a problem on the files?
gas.tar.gz (451.5 KB)
Possibly I am overlooking something very fundamental (maybe it makes no sense to simulate for a single e-field point?) but I am a bit lost, any help is welcome.
Thanks!
Luis