hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
json.cc
Go to the documentation of this file.
1#include "utils/json.h"
2
3#include <filesystem>
4#include <fstream>
5#include <nlohmann/json.hpp>
6#include <stdexcept>
7
8using nlohmann::json;
9
10namespace hummingbird {
11json JSONFromFile(const std::string filename) {
12 std::filesystem::path file_path = filename;
13 std::ifstream fs_file(filename);
14 if (!fs_file.is_open()) {
15 std::filesystem::path absolute_path = std::filesystem::absolute(file_path);
16 throw std::runtime_error("Could not open mesh file: " +
17 absolute_path.string());
18 }
19
20 return json::parse(fs_file);
21}
22} // namespace hummingbird
json JSONFromFile(const std::string filename)
Create a json object from a string. Will throw an error if the file could not be opened.
Definition json.cc:11