diff --git a/CMakeLists.txt b/CMakeLists.txt index e3048e172ec5808808beffb81255608c3303d6f5..802ddd2d8aebaa966c96e6c6e8fb02b5c5469a11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,10 @@ endif(NOT GMSH_INC) list(APPEND EXTRA_INCS ${GMSH_INC}) list(APPEND EXTRA_LIBS ${GMSH_LIB}) +# Yaml-cpp +find_package(yaml-cpp REQUIRED) + + # GmshFem find_library(GMSHFEM_LIB gmshfem) @@ -222,6 +226,7 @@ include_directories(${EXTRA_INCS}) file( GLOB LIB_SOURCES contrib/blossom5v2.05/*.cpp contrib/blossom5v2.05/*/*.cpp common/*/*/*.cpp common/*/*.cpp common/*.cpp specific/*/*/*.cpp specific/*/*.cpp specific/*.cpp) file( GLOB LIB_HEADERS contrib/blossom5v2.05/*.h contrib/blossom5v2.05/*/*.h common/*/*/*.h common/*/*.h common/*.h specific/*/*/*.h specific/*/*.h specific/*.h) add_library( fwi ${LIB_SOURCES} ${LIB_HEADERS}) +target_link_libraries(fwi yaml-cpp) add_executable( synthetics synthetics.cpp ${EXTRA_INCS}) target_link_libraries( synthetics fwi ${EXTRA_LIBS}) diff --git a/specific/configuration/flexible_acquisition.cpp b/specific/configuration/flexible_acquisition.cpp index 5f74d8505cd34d5b016a3f5c55cf1b602321ddb4..3dc2df32e888bfe33f0906c2f28ddb4a5021d074 100644 --- a/specific/configuration/flexible_acquisition.cpp +++ b/specific/configuration/flexible_acquisition.cpp @@ -18,6 +18,7 @@ #include "../../common/data/element.h" #include "../wave/correlation.h" #include "flexible_acquisition.h" +#include "yaml_interface.h" namespace gmodel = gmsh::model; namespace factory = gmsh::model::geo; @@ -54,13 +55,34 @@ namespace flexible_acquisition throw common::Exception("A geometric parameter could not be found."); } - // Setup E/R - _er_positions.emplace_back(0.4, -0.5); - _er_positions.emplace_back(0.5, -0.5); - _er_positions.emplace_back(0.6, -0.5); + // SETUP FROM YAML + // TODO read path + + ShotsConfigurationYAML shotsConfig("shots.yaml"); + _ns = shotsConfig.numShots(); + + // Configure points + for (const auto &coords: shotsConfig.points()) { + _er_positions.push_back(coords); + } + mesh(); + + // Configure shots + for (unsigned s = 0; s < shotsConfig.numShots(); ++s) + { + _emitter.push_back(shotsConfig.emitters(s)); + _receiver.push_back(shotsConfig.receivers(s)); + } + + for (unsigned p = 0; p < _er_positions.size(); ++p) { + _point.push_back("emitter_receiver_"+std::to_string(p)); + _points |= _point[p]; + } + + /* * DOMAIN */ @@ -72,7 +94,6 @@ namespace flexible_acquisition _supersurface[Support::BLK] = Domain("supersurface"); _supersurface[Support::BND] = Domain("supersurface_bnd"); - // TODO: define as supersurface and subsurface std::string unknownRegion = "subsurface"; gmshFem.userDefinedParameter(unknownRegion, "unknown"); if (unknownRegion == "subsurface") @@ -95,21 +116,6 @@ namespace flexible_acquisition _wave_omega[Support::BLK] = _model_known[Support::BLK] | _model_unknown[Support::BLK]; _wave_omega[Support::BND] = _model_known[Support::BND] | _model_unknown[Support::BND]; - for (unsigned p = 0; p < _er_positions.size(); ++p) { - _point.push_back("emitter_receiver_"+std::to_string(p)); - _points |= _point[p]; - } - - // Setup number of emitters etc. TODO: make some points only receivers - _ns = _er_positions.size(); - for (unsigned s = 0; s < _ns; ++s) { - _emitter.push_back({s}); - } - - // TMP: each emitter is its receptor - for (unsigned s = 0; s < _ns; ++s) { - _receiver.push_back({s}); - } diff --git a/specific/configuration/yaml_interface.h b/specific/configuration/yaml_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..3d144763b871967e1210d4778d5e27154b872cd6 --- /dev/null +++ b/specific/configuration/yaml_interface.h @@ -0,0 +1,100 @@ +#ifndef H_YAML_INTERFACE_SHOTS +#define H_YAML_INTERFACE_SHOTS + +#include <vector> +#include <string> +#include <utility> +#include "yaml-cpp/yaml.h" + +// TODO: refactor (abstract + impl) + +class ShotsConfigurationInterface //(abstract) +{ + public: + using Coordinates = std::pair<double, double>; + + /** + * Describe the number of shots + */ + virtual unsigned numShots() const = 0; + + /** + * Describe the number of points + */ + virtual unsigned numPoints() const = 0; + + /** + * emitters(s) is the list of enabled emitters in shot "s". + * Array must be of size numShots() + */ + virtual const std::vector<unsigned> &emitters(unsigned shot) const = 0; + + /** + * receivers(s) is the list of enabled receivers in shot "s". + * Array must be of size numShots() + */ + virtual const std::vector<unsigned> &receivers(unsigned shot) const = 0; + + /** + * List of all points + * Array must be of size numPoints() + */ + virtual const std::vector<Coordinates> &points() const = 0; +}; + +class ShotsConfigurationYAML : public ShotsConfigurationInterface { + private: + std::vector<std::vector<unsigned>> _emitters, _receivers; + std::vector<ShotsConfigurationInterface::Coordinates> _points; + + public: + + ShotsConfigurationYAML(const std::string& path) { + YAML::Node config = YAML::LoadFile(path); + + for (const auto &coord : config["coordinates"]) + { + double x = coord[0].as<double>(); + double y = coord[1].as<double>(); + _points.emplace_back(x, y); + } + + for (const auto &shot : config["shots"]) { + std::vector<unsigned> emitters, receivers; + for (const auto &emitter : shot["emitters"]) + { + emitters.push_back(emitter.as<int>()); + } + for (const auto &receiver : shot["receivers"]) + { + receivers.push_back(receiver.as<int>()); + } + + _emitters.push_back(std::move(emitters)); + _receivers.push_back(std::move(receivers)); + } + } + + virtual unsigned numShots() const override { + return _emitters.size(); + } + + virtual unsigned numPoints() const override { + return _points.size(); + } + + virtual const std::vector<unsigned> &emitters(unsigned shot) const override { + return _emitters.at(shot); + } + + virtual const std::vector<unsigned> &receivers(unsigned shot) const override { + return _receivers.at(shot); + } + + virtual const std::vector<Coordinates> &points() const override { + return _points; + } + +}; + +#endif \ No newline at end of file