Program Listing for File input.hpp

Return to documentation for file (src/input/input.hpp)

#pragma once

#include <fstream>
#include <iostream>
#include <string>
#include <vector>

#include "mesh.hpp"
#include "output.hpp"

namespace lili::input {
enum class InputType {
  None,
  Initial,
  Restart,
  TestParticle
};

enum class PPosDist {
  Stationary,
  Uniform
};

enum class PVelDist {
  Maxwellian
};

std::string InputTypeToString(InputType input_type);

class InputParticles {
 public:
  // Constructor
  InputParticles() {
    n = 0;
    n_track = 0;
    dl_track = 0;
    dtrack_save = 0;
    q = 0.;
    m = 0.;
    name = "";

    pos_dist = PPosDist::Stationary;
    pos_dist_param = {};

    vel_dist = PVelDist::Maxwellian;
    vel_dist_param = {};
    vel_offset = {0., 0., 0.};
  }

  void Print();

  std::string name;

  int n;
  double q;
  double m;

  int n_track;
  int dl_track;
  int dtrack_save;

  PPosDist pos_dist;
  std::vector<double>
      pos_dist_param;
  PVelDist vel_dist;
  std::vector<double>
      vel_dist_param;
  std::vector<double> vel_offset;
};

class InputLoopTask {
 public:
  // Constructor
  InputLoopTask() {
    name = "";
    type = "";
  }

  std::string name;
  std::string type;
};

class InputLoop {
 public:
  // Constructor
  InputLoop() {
    n_loop = 0;
    dt = 0.;
    tasks = {};
  }

  int n_loop;
  double dt;
  std::vector<InputLoopTask> tasks;
};

class Input {
 public:
  // Constructor
  Input();

  Input(const char* in_file);

  Input(const Input& input);

  Input(Input&& input) noexcept : Input() { swap(*this, input); };

  // Destructor
  ~Input() = default;

  friend void swap(Input& first, Input& second);

  // Operators
  Input& operator=(Input other) {
    swap(*this, other);
    return *this;
  }

  // Getters
  std::string input_file() const { return input_file_; }
  std::string problem_name() const { return problem_name_; }
  std::string restart_file() const { return restart_file_; }
  InputType input_type() const { return input_type_; }
  lili::mesh::MeshSize mesh() const { return mesh_; }
  std::vector<InputParticles> particles() const { return particles_; }
  InputLoop loop() const { return loop_; }

  // Setters
  std::string& input_file() { return input_file_; }
  std::string& problem_name() { return problem_name_; }
  std::string& restart_file() { return restart_file_; }
  InputType& input_type() { return input_type_; }
  lili::mesh::MeshSize& mesh() { return mesh_; }
  std::vector<InputParticles>& particles() { return particles_; }
  InputLoop& loop() { return loop_; }

  void Parse();

  void Print(lili::output::LiliCout& lout) {
    lout << "Input file    : " << input_file_ << std::endl;
    lout << "Problem name  : " << problem_name_ << std::endl;
    lout << "Input type    : " << lili::input::InputTypeToString(input_type_)
         << std::endl;
    lili::mesh::PrintMeshSize(mesh_, lout);
    lout << "========= Particle information =========" << std::endl;
    for (auto& p : particles_) {
      p.Print();
    }
    lout << "=========== Loop information ===========" << std::endl;
    lout << "  n_loop      : " << loop_.n_loop << std::endl;
    lout << "  dt          : " << loop_.dt << std::endl;
    lout << "  Tasks       : " << std::endl;
    for (auto& t : loop_.tasks) {
      lout << "    Name      : " << t.name << std::endl;
      lout << "      Type    : " << t.type << std::endl;
    }
  }

 private:
  std::string input_file_;
  std::string problem_name_;
  std::string restart_file_;

  InputType input_type_;

  lili::mesh::MeshSize mesh_;
  std::vector<InputParticles> particles_;
  InputLoop loop_;
};

// Function declaration
Input ParseArguments(int argc, char** argv, lili::output::LiliCout& lout);
}  // namespace lili::input