PolyFEM
Loading...
Searching...
No Matches
Units.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4
5#include <spdlog/fmt/ostr.h>
6
7#include <string>
8
9namespace polyfem
10{
11 class Units
12 {
13 public:
14 void init(const json &json);
15
16 static double convert(const json &val, const std::string &unit_type);
17 static double convert(const double val, const std::string &unit, const std::string &unit_type);
18
19 const std::string &length() const { return length_; }
20 const std::string &mass() const { return mass_; }
21 const std::string &time() const { return time_; }
24
25 std::string stress() const { return fmt::format("{}/({}*{}^2)", mass_, length_, time_); }
26 std::string density() const { return fmt::format("{}/{}^3", mass_, length_); }
27 std::string velocity() const { return fmt::format("{}/{}", length_, time_); }
28 std::string acceleration() const { return fmt::format("{}/{}^2", length_, time_); }
29 std::string force() const { return fmt::format("{}*{}", mass_, acceleration()); }
30 std::string pressure() const { return fmt::format("{}*{}/{}", mass_, acceleration(), length_); }
31 std::string energy() const { return fmt::format("{}*{}^2/{}^2", mass_, length_, time_); }
32 std::string viscosity() const { return fmt::format("{}/{}^2*{}", force(), length_, time_); }
33
34 private:
35 std::string length_ = "m";
36 std::string mass_ = "kg";
37 std::string time_ = "s";
39 };
40} // namespace polyfem
double val
Definition Assembler.cpp:86
double characteristic_length_
Definition Units.hpp:38
std::string force() const
Definition Units.hpp:29
std::string time_
Definition Units.hpp:37
std::string stress() const
Definition Units.hpp:25
void init(const json &json)
Definition Units.cpp:9
double & characteristic_length()
Definition Units.hpp:23
std::string viscosity() const
Definition Units.hpp:32
std::string mass_
Definition Units.hpp:36
double characteristic_length() const
Definition Units.hpp:22
std::string energy() const
Definition Units.hpp:31
const std::string & mass() const
Definition Units.hpp:20
std::string pressure() const
Definition Units.hpp:30
std::string velocity() const
Definition Units.hpp:27
static double convert(const json &val, const std::string &unit_type)
Definition Units.cpp:31
std::string length_
Definition Units.hpp:35
const std::string & time() const
Definition Units.hpp:21
std::string acceleration() const
Definition Units.hpp:28
std::string density() const
Definition Units.hpp:26
const std::string & length() const
Definition Units.hpp:19
nlohmann::json json
Definition Common.hpp:9