FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetPanelSetup.h
1#pragma once
2
20#include <fhsim_environment/hydrodynamics/PanelLoadLaw.h>
21#include "NetElement3NForces.h"
22#include "NetElementDef.h"
23#include <fhsim_environment/hydrodynamics/NetSolidity.h>
24
25#include <algorithm>
26#include <fhsim/ISimObjectLogger.h>
27#include <fhsim/simobject/ISimObjectCreator.h>
28#include <sstream>
29#include <stdexcept>
30#include <string>
31#include <variant>
32#include <vector>
33
34namespace net_panel_setup
35{
36
39{
40 hydrodynamics::PanelLoadLaw law;
41 hydrodynamics::Fluid fluid;
42};
43
53inline PanelHydrodynamics ReadPanelHydrodynamics(ISimObjectCreator* creator, const std::string& structureName)
54{
55 PanelHydrodynamics hydrodynamics {hydrodynamics::ReadPanelLoadLaw(creator), hydrodynamics::ReadFluid(creator)};
56 if (!hydrodynamics::Accepts(hydrodynamics.law, net_element_forces::kFlowReference)) {
57 const std::string message = "The HydroModel does not accept the free-stream velocity that " + structureName + " supplies.";
58 creator->ReportParameterError("HydroModel", message);
59 throw std::invalid_argument(message);
60 }
61 return hydrodynamics;
62}
63
74inline net_solidity::PanelSolidity ReadSolidityRule(ISimObjectCreator* creator, double& solidityParameter)
75{
76 net_solidity::PanelSolidity rule;
77 std::string modelName;
78 creator->GetStringParam("SolidityModel", modelName, "MeshOpening");
79 if (!net_solidity::ParseSolidityModel(modelName, rule.model)) {
80 const std::string message = "Unknown SolidityModel \"" + modelName + "\"; expected Fixed or MeshOpening.";
81 creator->ReportParameterError("SolidityModel", message);
82 throw std::invalid_argument(message);
83 }
84 creator->GetDoubleParam("KnotFactor", &rule.knotFactor, net_solidity::kDefaultKnotFactor);
85 creator->GetDoubleParam("Solidity", &solidityParameter, 0.0);
86 if (!(rule.knotFactor > 0.0)) {
87 const std::string message = "KnotFactor must be positive, not " + std::to_string(rule.knotFactor) + "; the mesh opening solidity would be negative.";
88 creator->ReportParameterError("KnotFactor", message);
89 throw std::invalid_argument(message);
90 }
91 if (!(solidityParameter >= 0.0 && solidityParameter < 1.0)) {
92 const std::string message = "Solidity must be in (0, 1), or absent, not " + std::to_string(solidityParameter) + ".";
93 creator->ReportParameterError("Solidity", message);
94 throw std::invalid_argument(message);
95 }
96 return rule;
97}
98
110inline net_solidity::PanelSolidity ElementSolidityRule(const net_solidity::PanelSolidity& rule,
111 double solidityParameter, const NetElementDef& panel, int element, ISimObjectCreator* creator)
112{
113 net_solidity::PanelSolidity elementRule = rule;
114 if (elementRule.model != net_solidity::SolidityModel::Fixed) {
115 return elementRule;
116 }
117 const bool fromSn = panel.solidity > 0;
118 elementRule.fixed = fromSn ? panel.solidity : solidityParameter;
119 if (!(elementRule.fixed > 0 && elementRule.fixed < 1)) {
120 const std::string element1 = "element " + std::to_string(element + 1);
121 const std::string found = fromSn ? element1 + " has Sn = " + std::to_string(elementRule.fixed) + ", outside (0, 1)."
122 : (solidityParameter > 0 ? element1 + " has no Sn, and Solidity = " + std::to_string(solidityParameter) + " is outside (0, 1)."
123 : element1 + " has neither.");
124 const std::string message = "SolidityModel Fixed needs the Solidity parameter or an Sn attribute in (0, 1) on every net element; " + found;
125 creator->ReportParameterError("Solidity", message);
126 throw std::invalid_argument(message);
127 }
128 return elementRule;
129}
130
143inline void RequireBarDirections(bool hasBarDirections, int element, ISimObjectCreator* creator)
144{
145 if (hasBarDirections) {
146 return;
147 }
148 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.";
149 creator->ReportParameterError("HydroModel", message);
150 throw std::invalid_argument(message);
151}
152
159inline void WarnIfSolidityOutsideFitRange(const hydrodynamics::PanelLoadLaw& law,
160 std::vector<double> solidities, ISimObjectLogger& logger)
161{
162 std::sort(solidities.begin(), solidities.end());
163 solidities.erase(std::unique(solidities.begin(), solidities.end()), solidities.end());
164 for (const double solidity : solidities)
165 hydrodynamics::WarnIfOutsideFitRange(law, solidity, logger);
166}
167
175inline void WarnIfSolidityExtremesOutsideFitRange(const hydrodynamics::PanelLoadLaw& law,
176 const std::vector<double>& solidities, ISimObjectLogger& logger)
177{
178 if (solidities.empty()) {
179 return;
180 }
181 const auto extremes = std::minmax_element(solidities.begin(), solidities.end());
182 WarnIfSolidityOutsideFitRange(law, {*extremes.first, *extremes.second}, logger);
183}
184
195inline void WarnIfLegacyDampingRatio(double dampingRatio, ISimObjectLogger& logger)
196{
197 constexpr double kLargestUsualRatio = 2.0;
198 if (dampingRatio <= kLargestUsualRatio) {
199 return;
200 }
201 std::ostringstream message;
202 message << "Warning: NetDampingRatio = " << dampingRatio
203 << ". Its meaning changed in fhsim_marine_elements 3.1.4: it now is the damping ratio of the panel's stiffest stretch mode (1 = critical), "
204 "so values above 2 overdamp the net and shorten the time step. Inputs written for the old meaning (often 5) should use 1.";
205 logger.LogInfo(message.str());
206}
207
208} // namespace net_panel_setup
Class containing the description of a net panel and methods necessary for taking this over to triangu...
Definition NetElementDef.h:24
double solidity
The net file's optional Sn attribute, for SolidityModel Fixed; 0 when absent. Refinement copies it to...
Definition NetElementDef.h:35
The panel load law and the fluid shared by all panels of a structure.
Definition NetPanelSetup.h:39
hydrodynamics::Fluid fluid
From Rho and Nu.
Definition NetPanelSetup.h:41
hydrodynamics::PanelLoadLaw law
From HydroModel and the law's parameters.
Definition NetPanelSetup.h:40