NuTo
Numerics Tool
MoistureTransport_Setup.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "nuto/mechanics/MechanicsEnums.h"
5 #include "nuto/mechanics/elements/ElementBase.h"
6 #include "nuto/mechanics/nodes/NodeBase.h"
7 #include "nuto/mechanics/structures/unstructured/Structure.h"
8 #include "nuto/mechanics/timeIntegration/NewmarkDirect.h"
9 #include "nuto/mechanics/mesh/MeshGenerator.h"
10 #include "nuto/mechanics/constitutive/staticData/DataMoistureTransport.h"
11 #include "nuto/mechanics/constitutive/laws/MoistureTransport.h"
12 #include "nuto/mechanics/sections/SectionPlane.h"
13 #include "nuto/mechanics/sections/SectionTruss.h"
14 #include "nuto/mechanics/timeIntegration/postProcessing/PostProcessor.h"
15 
17 
18 
19 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20 // Setup Preprocessor
21 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 
23 
24 /*---------------------------------------------*\
25 |* DEFINES *|
26 \*---------------------------------------------*/
27 
28 
29 // --- Time integration scheme
30 // ---------------------------
31 
32 #define RES_TOLERANCE 1e-18
33 #define MAX_ITERATION 40
34 
35 
36 // --- Processor/OpenMp
37 // --------------------
38 
39 #ifdef _OPENMP
40 #define TESTNUM_PROC 4
41 #elif HAVE_PARDISO
42 #define TESTNUM_PROC 4
43 #else
44 #define TESTNUM_PROC 1
45 #endif
46 
47 
48 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 // Setup structs
50 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 
52 /*---------------------------------------------*\
53 |* time *|
54 \*---------------------------------------------*/
55 
57 {
58  double delta_t = 1.0 / 1.0 * 1.0 * 24.0 * 60.0 * 60.0;
59  double t_write = 1.0 / 1.0 * 1.0 * 24.0 * 60.0 * 60.0;
60  double t_final = 20.0 / 1.0 * 1.0 * 24.0 * 60.0 * 60.0;
61  double BC_TransitionTime = 24.0 * 60.0 * 60.0;
62 };
63 
64 /*---------------------------------------------*\
65 |* moisture transport *|
66 \*---------------------------------------------*/
67 
69 {
70  // general
71  bool EnableModiefiedTangentialStiffness = false;
72 
73  double InitialRelativeHumidity = 1.0; // VHIRTHAMTODO --- Set to 0.95
75  double MassExchangeRate = 3.42e-7;
76  double PoreVolumeFraction = 0.25;
77  double DiffusionCoefficientRH = 3.9e-12; // VHIRTHAMTODO ---> Vapor phase / Water phase ersetzen durch WVF und RH
78  double DiffusionExponentRH = 1.0;
79  double DensitySaturatedWaterVapor = 0.0173;
80  double DensityWater = 999.97;
81  double DiffusionCoefficientWV = 1.17e-7;
82  double DiffusionExponentWV = 2.0;
83 
84  // boundary condition
85  double BoundaryEnvironmentalRH = 0.45;
86  double BoundaryDiffusionCoefficientRH = 1.0e-10 * 1000;
87  double BoundaryDiffusionCoefficientWV = 1.0e-7 * 1000;
88 
89  // sorption isotherms
90  bool EnableSorptionHysteresis = false;
92  double GradientCorrectionDesorptionAdsorpion = 0.26;
93  double GradientCorrectionAdsorpionDesorption = 0.56;
94  Eigen::Vector4d AdsorptionCoeffs = Eigen::Vector4d::Zero();
95  Eigen::Vector4d DesorptionCoeffs = Eigen::Vector4d::Zero();
96 
97  int ConstitutiveLawID = 0;
98  NuTo::Structure& mS;
99 
100  // ctor
101  MoistureTransportControl(NuTo::Structure& rS)
102  : mS(rS)
103  {
104  // Values fitted from figure in Johannessons paper
105  AdsorptionCoeffs(0) = 0.0;
106  AdsorptionCoeffs(1) = 0.19692057340725558;
107  AdsorptionCoeffs(2) = -0.28253538941816925;
108  AdsorptionCoeffs(3) = 0.22661481601091368;
109 
110  DesorptionCoeffs(0) = 0.0;
111  DesorptionCoeffs(1) = 0.26719233184420238;
112  DesorptionCoeffs(2) = -0.41030868184510738;
113  DesorptionCoeffs(3) = 0.32511635000090505;
114 
115  ConstitutiveLawID = mS.ConstitutiveLawCreate("Moisture_Transport");
116  }
117 
118 public:
120  {
121  // set variables
122  mS.ConstitutiveLawSetParameterBool(ConstitutiveLawID, "ENABLE_MODIFIED_TANGENTIAL_STIFFNESS",
123  EnableModiefiedTangentialStiffness);
124  mS.ConstitutiveLawSetParameterBool(ConstitutiveLawID, "enable_sorption_hysteresis", EnableSorptionHysteresis);
125 
126  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "BOUNDARY_DIFFUSION_COEFFICIENT_RH",
127  BoundaryDiffusionCoefficientRH);
128  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "BOUNDARY_DIFFUSION_COEFFICIENT_WV",
129  BoundaryDiffusionCoefficientWV);
130  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DENSITY_WATER", DensityWater);
131  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DIFFUSION_COEFFICIENT_RH", DiffusionCoefficientRH);
132  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DIFFUSION_COEFFICIENT_WV", DiffusionCoefficientWV);
133  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DIFFUSION_EXPONENT_RH", DiffusionExponentRH);
134  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DIFFUSION_EXPONENT_WV", DiffusionExponentWV);
135  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "GRADIENT_CORRECTION_ADSORPTION_DESORPTION",
136  GradientCorrectionAdsorpionDesorption);
137  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "GRADIENT_CORRECTION_DESORPTION_ADSORPTION",
138  GradientCorrectionDesorptionAdsorpion);
139  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "MASS_EXCHANGE_RATE", MassExchangeRate);
140  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "PORE_VOLUME_FRACTION", PoreVolumeFraction);
141  mS.ConstitutiveLawSetParameterDouble(ConstitutiveLawID, "DENSITY_SATURATED_WATER_VAPOR",
142  DensitySaturatedWaterVapor);
143 
144  mS.ConstitutiveLawSetParameterFullVectorDouble(ConstitutiveLawID, "polynomial_COEFFICIENTS_ADSORPTION",
145  AdsorptionCoeffs);
146  mS.ConstitutiveLawSetParameterFullVectorDouble(ConstitutiveLawID, "POLYNOMIAL_COEFFICIENTS_DESORPTION",
147  DesorptionCoeffs);
148 
149 
150  // Calculate equilibrium water volume fraction
151  InitialWaterVolumeFraction = mS.ConstitutiveLawGetEquilibriumWaterVolumeFraction(
152  ConstitutiveLawID, InitialRelativeHumidity, DesorptionCoeffs);
153  }
154 
155 
156 public:
158  {
159  unsigned int NNodes = mS.GetNumNodes();
160 
161  for (unsigned int i = 0; i < NNodes; i++)
162  {
163 
164 
165  if (mS.NodeGetNodePtr(i)->GetNum(NuTo::Node::eDof::RELATIVEHUMIDITY) != 0)
166  {
167  mS.NodeGetNodePtr(i)->Set(NuTo::Node::eDof::RELATIVEHUMIDITY, 0, InitialRelativeHumidity);
168  }
169  if (mS.NodeGetNodePtr(i)->GetNum(NuTo::Node::eDof::WATERVOLUMEFRACTION) != 0)
170  {
171  mS.NodeGetNodePtr(i)->Set(NuTo::Node::eDof::WATERVOLUMEFRACTION, 0, InitialWaterVolumeFraction);
172  }
173  }
174  }
175 
177  {
178  using namespace NuTo::Constitutive::StaticData;
179  for (int i = 0; i < mS.GetNumElements(); i++)
180  {
181  for (int theIP = 0; theIP < mS.ElementGetElementPtr(i)->GetNumIntegrationPoints(); theIP++)
182  {
183  auto& moistureData = mS.ElementGetElementPtr(i)
184  ->GetIPData()
185  .GetIPConstitutiveLaw(theIP)
186  .GetData<NuTo::MoistureTransport>()
187  .GetData();
188  moistureData.SetLastSorptionCoeff(mS.ConstitutiveLawGetParameterFullVectorDouble(
189  ConstitutiveLawID,
190  NuTo::Constitutive::eConstitutiveParameter::POLYNOMIAL_COEFFICIENTS_DESORPTION));
191  moistureData.SetCurrentSorptionCoeff(mS.ConstitutiveLawGetParameterFullVectorDouble(
192  ConstitutiveLawID,
193  NuTo::Constitutive::eConstitutiveParameter::POLYNOMIAL_COEFFICIENTS_DESORPTION));
194  moistureData.SetLastRelHumValue(InitialRelativeHumidity);
195  moistureData.SetDesorption(SorptionHistoryDesorption);
196  }
197  }
198  }
199 };
200 
201 
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 // Setup Functions
204 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 
206 
207 /*---------------------------------------------*\
208 |* boundary elements *|
209 \*---------------------------------------------*/
210 
211 template <int TDim>
212 void SetupConstrainedNodeBoundaryElements(NuTo::Structure& rS,
213  std::function<bool(NuTo::NodeBase*)> rFunctionGetBoundaryNode,
214  std::function<double(double)> rBoundaryConstraintFunction)
215 {
216  int nGrpBE = rS.GroupCreate("NODES");
217  rS.GroupAddNodeFunction(nGrpBE, rFunctionGetBoundaryNode);
218 
219  int eGrpBE = rS.GroupCreate("ELEMENTS");
220  rS.GroupAddElementsFromNodes(eGrpBE, nGrpBE, false);
221 
222  std::set<NuTo::Node::eDof> controlNodeDofs;
223  controlNodeDofs.insert(NuTo::Node::eDof::RELATIVEHUMIDITY);
224 
225  int boundaryControlNodeID = rS.NodeCreateDOFs(controlNodeDofs);
226  NuTo::NodeBase* controlNodePtr = rS.NodeGetNodePtr(boundaryControlNodeID);
227  int groupBoundaryElements = rS.BoundaryElementsCreate(eGrpBE, nGrpBE, controlNodePtr);
228 
229  rS.Constraints().Add(NuTo::Node::eDof::RELATIVEHUMIDITY,
230  NuTo::Constraint::Value(*controlNodePtr, rBoundaryConstraintFunction));
231 
232  // Set Integration type - default not sufficient
233  std::vector<int> boundaryElementIDs;
234  rS.ElementGroupGetMembers(groupBoundaryElements, boundaryElementIDs);
235 
236 
237  for (int elementId : boundaryElementIDs)
238  {
239  NuTo::ElementBase* elementPtr = rS.ElementGetElementPtr(elementId);
240  switch (TDim)
241  {
242  case 1:
243  elementPtr->SetIntegrationType(
244  *rS.GetPtrIntegrationType(NuTo::eIntegrationType::IntegrationType0DBoundary));
245  break;
246  case 2:
247  elementPtr->SetIntegrationType(
248  *rS.GetPtrIntegrationType(NuTo::eIntegrationType::IntegrationType1D2NGauss2Ip));
249  break;
250  case 3:
251  elementPtr->SetIntegrationType(
252  *rS.GetPtrIntegrationType(NuTo::eIntegrationType::IntegrationType2D4NGauss4Ip));
253  break;
254  default:
255  throw NuTo::Exception(__PRETTY_FUNCTION__, "Invalid dimension");
256  }
257  }
258 }
259 
260 
261 /*---------------------------------------------*\
262 |* integration type *|
263 \*---------------------------------------------*/
264 
265 template <int TDim>
266 void SetupIntegrationType(NuTo::Structure& rS, int rIPT)
267 {
268  switch (TDim)
269  {
270  case 1:
271  rS.InterpolationTypeSetIntegrationType(rIPT, NuTo::eIntegrationType::IntegrationType1D2NGauss2Ip);
272  break;
273  case 2:
274  rS.InterpolationTypeSetIntegrationType(rIPT, NuTo::eIntegrationType::IntegrationType2D4NGauss4Ip);
275  break;
276  case 3:
277  rS.InterpolationTypeSetIntegrationType(rIPT, NuTo::eIntegrationType::IntegrationType3D8NGauss2x2x2Ip);
278  break;
279  default:
280  throw NuTo::Exception(__PRETTY_FUNCTION__, "Invalid dimension");
281  }
282 }
283 
284 
285 /*---------------------------------------------*\
286 |* multi processor setup *|
287 \*---------------------------------------------*/
288 
289 
290 inline void SetupMultiProcessor(NuTo::Structure& rS)
291 {
292 
293  rS.SetNumProcessors(TESTNUM_PROC);
294 #ifdef _OPENMP
295  std::cout << "OpenMP enabled" << std::endl;
296  rS.CalculateMaximumIndependentSets();
297 #endif
298 }
299 
300 
301 /*---------------------------------------------*\
302 |* section *|
303 \*---------------------------------------------*/
304 
305 template <int TDim>
306 std::shared_ptr<NuTo::Section> SetupSection(NuTo::Structure& rS, double rAreaThickness = 1.0)
307 {
308  switch (TDim)
309  {
310  case 1:
311  {
312  auto Sec = NuTo::SectionTruss::Create(rAreaThickness);
313  rS.ElementTotalSetSection(Sec);
314  return Sec;
315  }
316 
317  case 2:
318  {
319  auto Sec = NuTo::SectionPlane::Create(rAreaThickness, false);
320  rS.ElementTotalSetSection(Sec);
321  return Sec;
322  }
323 
324  case 3:
325  {
326  // there is no need to attach a section to 3D elements
327  // to make this function work with arbitrary dimensions, we just attach a dummy truss
328  auto Sec = NuTo::SectionTruss::Create(-42.0);
329  rS.ElementTotalSetSection(Sec);
330  return Sec;
331  }
332 
333  default:
334  throw NuTo::Exception(__PRETTY_FUNCTION__, "Invalid dimension");
335  }
336 }
337 
338 /*---------------------------------------------*\
339 |* structure *|
340 \*---------------------------------------------*/
341 
342 template <int TDim>
343 inline void SetupStructure(NuTo::Structure& rS, std::string rTestName)
344 {
345  rS.SetNumTimeDerivatives(1);
346  rS.SetShowTime(false);
347 
348  NuTo::Logger& Log = rS.GetLogger();
349  Log.SetQuiet(false);
350  Log.OpenFile(rTestName + ".log");
351 }
352 
353 
354 /*---------------------------------------------*\
355 |* time integration *|
356 \*---------------------------------------------*/
357 
358 inline void SetupTimeIntegration(NuTo::NewmarkDirect& rTI, const TimeControl& rTC, const std::string& rResultDir)
359 {
360  rTI.SetPerformLineSearch(false);
361  rTI.SetVerboseLevel(0);
362  rTI.SetToleranceResidual(NuTo::Node::eDof::RELATIVEHUMIDITY, RES_TOLERANCE);
363  rTI.SetToleranceResidual(NuTo::Node::eDof::WATERVOLUMEFRACTION, RES_TOLERANCE);
364  rTI.SetMaxNumIterations(MAX_ITERATION);
365 
366  rTI.SetTimeStep(rTC.delta_t);
367  rTI.PostProcessing().SetMinTimeStepPlot(rTC.t_write);
368 
369  rTI.PostProcessing().SetResultDirectory(rResultDir, true);
370 }
371 
372 /*---------------------------------------------*\
373 |* visualize *|
374 \*---------------------------------------------*/
375 
376 inline void SetupVisualize(NuTo::Structure& rS)
377 {
378  int visGrp = rS.GroupCreate(NuTo::eGroupId::Elements);
379  rS.GroupAddElementsTotal(visGrp);
380 
381  rS.AddVisualizationComponent(visGrp, NuTo::eVisualizeWhat::RELATIVE_HUMIDITY);
382  rS.AddVisualizationComponent(visGrp, NuTo::eVisualizeWhat::WATER_VOLUME_FRACTION);
383 }
visualize water volume fraction
NuTo::Structure & mS
Definition: MoistureTransport_Setup.h:98
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
NNodes
Definition: MultiPhysics2D.cpp:305
bool SorptionHistoryDesorption
Definition: MultiPhysics2D.cpp:98
void SetupVisualize(NuTo::Structure &rS)
Definition: MoistureTransport_Setup.h:376
double MassExchangeRate
Definition: MultiPhysics2D.cpp:85
void SetupIntegrationType(NuTo::Structure &rS, int rIPT)
Definition: MoistureTransport_Setup.h:266
void SetupMultiProcessor(NuTo::Structure &rS)
Definition: MoistureTransport_Setup.h:290
visualize relative humidity
void SetParametersConstitutiveLaw()
Definition: MoistureTransport_Setup.h:119
void SetupTimeIntegration(NuTo::NewmarkDirect &rTI, const TimeControl &rTC, const std::string &rResultDir)
Definition: MoistureTransport_Setup.h:358
MoistureTransportControl(NuTo::Structure &rS)
Definition: MoistureTransport_Setup.h:101
void OpenFile(std::string filename)
..open file
Definition: Logger.cpp:12
double delta_t
Definition: MoistureTransport_Setup.h:58
double InitialWaterVolumeFraction
Definition: MultiPhysics2D.cpp:74
void ApplyInitialNodalValues()
Definition: MoistureTransport_Setup.h:157
#define TESTNUM_PROC
Definition: MoistureTransport_Setup.h:44
#define MAX_ITERATION
Definition: MoistureTransport_Setup.h:33
double BC_TransitionTime
Definition: MoistureTransport_Setup.h:61
void SetupStaticData()
Definition: MoistureTransport_Setup.h:176
void SetQuiet(bool isQuiet)
..sets the output to be forwarded to the console (false) or only to the file (true) ...
Definition: Logger.cpp:27
Definition: MoistureTransport_Setup.h:68
logger class for redirecting output to different locations/files
Definition: Logger.h:12
double t_final
Definition: MoistureTransport_Setup.h:60
double InitialRelativeHumidity
Definition: MultiPhysics2D.cpp:73
std::shared_ptr< NuTo::Section > SetupSection(NuTo::Structure &rS, double rAreaThickness=1.0)
Definition: MoistureTransport_Setup.h:306
void SetupConstrainedNodeBoundaryElements(NuTo::Structure &rS, std::function< bool(NuTo::NodeBase *)> rFunctionGetBoundaryNode, std::function< double(double)> rBoundaryConstraintFunction)
Definition: MoistureTransport_Setup.h:212
void SetupStructure(NuTo::Structure &rS, std::string rTestName)
Definition: MoistureTransport_Setup.h:343
Equation Value(const NodeSimple &node, double value)
Constraint single value node.
Definition: ConstraintCompanion.cpp:100
Definition: MoistureTransport_Setup.h:56
#define RES_TOLERANCE
Definition: MoistureTransport_Setup.h:32
double t_write
Definition: MoistureTransport_Setup.h:59