FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetPanelSetup.h
1#pragma once
2
20#include "../hydrodynamics/PanelLoadLaw.h"
21#include "NetElement3NForces.h"
22#include "NetElementDef.h"
23#include "NetSolidity.h"
24
25#include <algorithm>
26#include <fhsim/ISimObjectLogger.h>
27#include <fhsim/simobject/ISimObjectCreator.h>
28#include <stdexcept>
29#include <string>
30#include <variant>
31#include <vector>
32
33namespace net_panel_setup
34{
35
38{
39 hydrodynamics::PanelLoadLaw law;
41};
42
52inline PanelHydrodynamics ReadPanelHydrodynamics(ISimObjectCreator* creator, const std::string& structureName)
53{
54 PanelHydrodynamics hydrodynamics {hydrodynamics::ReadPanelLoadLaw(creator), hydrodynamics::ReadFluid(creator)};
55 if (!hydrodynamics::Accepts(hydrodynamics.law, net_element_forces::kFlowReference)) {
56 const std::string message = "The HydroModel does not accept the free-stream velocity that " + structureName + " supplies.";
57 creator->ReportParameterError("HydroModel", message);
58 throw std::invalid_argument(message);
59 }
60 return hydrodynamics;
61}
62
73inline net_solidity::PanelSolidity ReadSolidityRule(ISimObjectCreator* creator, double& solidityParameter)
74{
76 std::string modelName;
77 creator->GetStringParam("SolidityModel", modelName, "MeshOpening");
78 if (!net_solidity::ParseSolidityModel(modelName, rule.model)) {
79 const std::string message = "Unknown SolidityModel \"" + modelName + "\"; expected Fixed or MeshOpening.";
80 creator->ReportParameterError("SolidityModel", message);
81 throw std::invalid_argument(message);
82 }
83 creator->GetDoubleParam("KnotFactor", &rule.knotFactor, net_solidity::kDefaultKnotFactor);
84 creator->GetDoubleParam("Solidity", &solidityParameter, 0.0);
85 if (!(rule.knotFactor > 0.0)) {
86 const std::string message = "KnotFactor must be positive, not " + std::to_string(rule.knotFactor) + "; the mesh opening solidity would be negative.";
87 creator->ReportParameterError("KnotFactor", message);
88 throw std::invalid_argument(message);
89 }
90 if (!(solidityParameter >= 0.0 && solidityParameter < 1.0)) {
91 const std::string message = "Solidity must be in (0, 1), or absent, not " + std::to_string(solidityParameter) + ".";
92 creator->ReportParameterError("Solidity", message);
93 throw std::invalid_argument(message);
94 }
95 return rule;
96}
97
109inline net_solidity::PanelSolidity ElementSolidityRule(const net_solidity::PanelSolidity& rule,
110 double solidityParameter, const NetElementDef& panel, int element, ISimObjectCreator* creator)
111{
112 net_solidity::PanelSolidity elementRule = rule;
113 if (elementRule.model != net_solidity::SolidityModel::Fixed) {
114 return elementRule;
115 }
116 const bool fromSn = panel.solidity > 0;
117 elementRule.fixed = fromSn ? panel.solidity : solidityParameter;
118 if (!(elementRule.fixed > 0 && elementRule.fixed < 1)) {
119 const std::string element1 = "element " + std::to_string(element + 1);
120 const std::string found = fromSn ? element1 + " has Sn = " + std::to_string(elementRule.fixed) + ", outside (0, 1)."
121 : (solidityParameter > 0 ? element1 + " has no Sn, and Solidity = " + std::to_string(solidityParameter) + " is outside (0, 1)."
122 : element1 + " has neither.");
123 const std::string message = "SolidityModel Fixed needs the Solidity parameter or an Sn attribute in (0, 1) on every net element; " + found;
124 creator->ReportParameterError("Solidity", message);
125 throw std::invalid_argument(message);
126 }
127 return elementRule;
128}
129
142inline void RequireBarDirections(bool hasBarDirections, int element, ISimObjectCreator* creator)
143{
144 if (hasBarDirections) {
145 return;
146 }
147 const std::string message = "Net panel " + std::to_string(element + 1) + " has collinear mesh coordinates (zero mesh determinant), so it has no bar directions; every HydroModel needs them.";
148 creator->ReportParameterError("HydroModel", message);
149 throw std::invalid_argument(message);
150}
151
158inline void WarnIfSolidityOutsideFitRange(const hydrodynamics::PanelLoadLaw& law,
159 std::vector<double> solidities, ISimObjectLogger& logger)
160{
161 std::sort(solidities.begin(), solidities.end());
162 solidities.erase(std::unique(solidities.begin(), solidities.end()), solidities.end());
163 for (const double solidity : solidities)
164 hydrodynamics::WarnIfOutsideFitRange(law, solidity, logger);
165}
166
174inline void WarnIfSolidityExtremesOutsideFitRange(const hydrodynamics::PanelLoadLaw& law,
175 const std::vector<double>& solidities, ISimObjectLogger& logger)
176{
177 if (solidities.empty()) {
178 return;
179 }
180 const auto extremes = std::minmax_element(solidities.begin(), solidities.end());
181 WarnIfSolidityOutsideFitRange(law, {*extremes.first, *extremes.second}, logger);
182}
183
184} // namespace net_panel_setup
Class containing the description of a net panel and methods necessary for taking this over to triangu...
Definition NetElementDef.h:22
double solidity
The net file's optional Sn attribute, for SolidityModel Fixed; 0 when absent. Refinement copies it to...
Definition NetElementDef.h:33
Fluid properties.
Definition PanelLoadTypes.h:34
The panel load law and the fluid shared by all panels of a structure.
Definition NetPanelSetup.h:38
hydrodynamics::Fluid fluid
From Rho and Nu.
Definition NetPanelSetup.h:40
hydrodynamics::PanelLoadLaw law
From HydroModel and the law's parameters.
Definition NetPanelSetup.h:39
The solidity rule of one panel.
Definition NetSolidity.h:104
SolidityModel model
Which rule applies.
Definition NetSolidity.h:105
double fixed
Sₙ for Fixed, dimensionless.
Definition NetSolidity.h:106
double knotFactor
K for MeshOpening.
Definition NetSolidity.h:107