Skip to content
Snippets Groups Projects
Select Git revision
2 results Searching

main.cpp

Blame
  • main.cpp 12.98 KiB
    #include "gmsh.h"
    
    #include <gmshddm/Formulation.h>
    #include <gmshddm/GmshDdm.h>
    #include <gmshddm/MPIInterface.h>
    #include <gmshfem/Message.h>
    
    using namespace gmshddm;
    using namespace gmshddm::common;
    using namespace gmshddm::domain;
    using namespace gmshddm::problem;
    using namespace gmshddm::field;
    using namespace gmshddm::mpi;
    
    using namespace gmshfem;
    using namespace gmshfem::domain;
    using namespace gmshfem::equation;
    using namespace gmshfem::problem;
    using namespace gmshfem::field;
    using namespace gmshfem::function;
    using namespace gmshfem::post;
    
    #include <cstring>
    #include <fstream>
    #include <sstream>
    
    static std::string freqToStr(double f) {
      char buffer[100];
      sprintf(buffer, "%.2f", f);
      return std::string(buffer);
    }
    
    struct sourcePosition{
      double x;
      double y;
      sourcePosition(double x, double y) : x(x), y(y) {}
    };
    
    std::vector<sourcePosition> readSources(const std::string& path) {
        std::ifstream inFile(path);
        std::vector<sourcePosition> positions;
    
        if (!inFile.is_open()) {
            throw std::runtime_error("Unable to open file: " + path);
        }
    
        std::string line;
        int lineNumber = 0;
        while (std::getline(inFile, line)) {
            lineNumber++;
            std::istringstream lineStream(line);
            double x, y;
            char delimiter;
    
            if (lineStream >> x >> delimiter >> y && delimiter == ';') {
                positions.push_back({x, y});
            } else {
                throw std::runtime_error("Invalid line format in file: " + path + " at line " + std::to_string(lineNumber));
            }
        }
    
        inFile.close();
        return positions;
    }
    
    
    /**
     * Returns ID of the domains containing the source
    */
    std::vector<int> mesh(double L, double H, double x0, double y0, const std::vector<sourcePosition>& sourcePositions, unsigned nX = 2, unsigned nY = 2, double lc = 0.1) {