FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
WakeCommon.h
1#pragma once
2
12#include <cmath>
13#include <fhsim/simobject/ISimObjectCreator.h>
14#include <initializer_list>
15#include <sstream>
16#include <string>
17
18namespace environment::wake
19{
20
31template<typename Error = std::runtime_error>
32void Require(bool valid, ISimObjectCreator* creator, const std::string& objectName, const std::string& name, const std::string& rule)
33{
34 if (valid)
35 return;
36 creator->ReportParameterError(name, rule);
37 throw Error((objectName.empty() ? "" : objectName + ": ") + name + " " + rule);
38}
39
50inline void LogIgnoredWithoutCastWake(ISimObjectCreator* creator, std::initializer_list<const char*> names)
51{
52 for (const char* name : names)
53 if (creator->GetParamSize(name) > 0)
54 creator->LogParameterInfo(name, "ignored: CastWake is not true, so this object casts no wake.");
55}
56
58inline double Norm(const double v[3])
59{
60 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
61}
62
64inline double Dot(const double a[3], const double b[3])
65{
66 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
67}
68
70inline void Cross(const double a[3], const double b[3], double out[3])
71{
72 out[0] = a[1] * b[2] - a[2] * b[1];
73 out[1] = a[2] * b[0] - a[0] * b[2];
74 out[2] = a[0] * b[1] - a[1] * b[0];
75}
76
78inline std::string Format(double value)
79{
80 std::ostringstream text;
81 text << value;
82 return text.str();
83}
84
86inline std::string FormatVector(const double v[3])
87{
88 return "(" + Format(v[0]) + ", " + Format(v[1]) + ", " + Format(v[2]) + ")";
89}
90
91} // namespace environment::wake