VertexCFD  0.0-dev
VertexCFD_IncompressibleLSVOFClosureModelFactory_impl.hpp
1 #ifndef VERTEXCFD_INCOMPRESSIBLELSVOFCLOSUREMODELFACTORY_IMPL_HPP
2 #define VERTEXCFD_INCOMPRESSIBLELSVOFCLOSUREMODELFACTORY_IMPL_HPP
3 
4 #include "utils/VertexCFD_Utils_PhaseIndex.hpp"
5 #include "utils/VertexCFD_Utils_ScalarToVector.hpp"
6 
7 #include "closure_models/VertexCFD_Closure_ConstantVectorField.hpp"
8 #include "closure_models/VertexCFD_Closure_MetricTensor.hpp"
9 #include "closure_models/VertexCFD_Closure_MetricTensorElementLength.hpp"
10 #include "closure_models/VertexCFD_Closure_VariableOldValue.hpp"
11 
12 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleCLSEpsilon.hpp"
13 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleCLSLambda.hpp"
14 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleCLSNonReconstructedNormal.hpp"
15 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleCLSRegularization.hpp"
16 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleCLSSign.hpp"
17 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFArtificialCompression.hpp"
18 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFBubbleExact.hpp"
19 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFBuoyancySource.hpp"
20 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFConvectiveFlux.hpp"
21 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFErrorNorms.hpp"
22 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFNthPhaseFraction.hpp"
23 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFScalarConvectiveFlux.hpp"
24 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFScalarTimeDerivative.hpp"
25 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFSurfaceTensionForce.hpp"
26 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFTimeDerivative.hpp"
27 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFVariableProperties.hpp"
28 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFViscousFlux.hpp"
29 #include "incompressible_lsvof_solver/closure_models/VertexCFD_Closure_IncompressibleLSVOFVortexVelocity.hpp"
30 
31 #include "incompressible_solver/closure_models/VertexCFD_Closure_IncompressibleLocalTimeStepSize.hpp"
32 
33 #include <Teuchos_RCP.hpp>
34 #include <Teuchos_StandardParameterEntryValidators.hpp>
35 
36 #include <string>
37 
38 namespace VertexCFD
39 {
40 namespace ClosureModel
41 {
42 //---------------------------------------------------------------------------//
43 template<class EvalType, int NumSpaceDim>
44 void IncompressibleLSVOFFactory<EvalType, NumSpaceDim>::buildClosureModel(
45  const std::string& closure_type,
46  const Teuchos::RCP<panzer::IntegrationRule>& ir,
47  const Teuchos::ParameterList& /*user_params*/,
48  const Teuchos::ParameterList& closure_params,
49  const Teuchos::RCP<panzer::GlobalData>& /*global_data*/,
50  bool& found_model,
51  std::string& error_msg,
52  Teuchos::RCP<std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>>
53  evaluators)
54 {
55  // Check if closure is built by default
56  if (isDefaultClosureModel(closure_type))
57  {
58  found_model = true;
59  }
60  // Build optional closures
61  else
62  {
63  // Constant vortex velocity field
64  if (closure_type == "IncompressibleLSVOFVortexVelocity")
65  {
66  const auto eval_vof_vortex = Teuchos::rcp(
67  new IncompressibleLSVOFVortexVelocity<EvalType,
68  panzer::Traits,
69  num_space_dim>(
70  *ir, closure_params));
71 
72  evaluators->push_back(eval_vof_vortex);
73 
74  found_model = true;
75  }
76 
77  // Constant Vector Field
78  if (closure_type == "IncompressibleLSVOFConstantVectorField")
79  {
80  auto eval = Teuchos::rcp(
81  new ConstantVectorField<EvalType, panzer::Traits, num_space_dim>(
82  *ir, closure_params));
83  evaluators->push_back(eval);
84  found_model = true;
85  }
86 
87  // Error norms
88  if (closure_type == "IncompressibleLSVOFErrorNorms")
89  {
90  // Create error evaluator
91  const auto eval_vof_errors = Teuchos::rcp(
92  new IncompressibleLSVOFErrorNorms<EvalType,
93  panzer::Traits,
94  num_space_dim>(
95  *ir, closure_params));
96 
97  evaluators->push_back(eval_vof_errors);
98 
99  found_model = true;
100  }
101 
102  // Bubble exact solution
103  if (closure_type == "IncompressibleLSVOFBubbleExact")
104  {
105  const auto eval_bubble_exact = Teuchos::rcp(
106  new IncompressibleLSVOFBubbleExact<EvalType,
107  panzer::Traits,
108  num_space_dim>(
109  *ir, closure_params));
110 
111  evaluators->push_back(eval_bubble_exact);
112 
113  found_model = true;
114  }
115  }
116 
117  // If model not found, add to error message and return
118  error_msg += "Default IncompressibleLSVOF closure models:\n";
119  error_msg += "IncompressibleCLSEpsilon\n";
120  error_msg += "IncompressibleCLSLambda\n";
121  error_msg += "IncompressibleCLSNonReconstructedNormal\n";
122  error_msg += "IncompressibleCLSRegularization\n";
123  error_msg += "IncompressibleCLSSign\n";
124  error_msg += "IncompressibleLocalTimeStepSize\n";
125  error_msg += "IncompressibleLSVOFArtificialCompression\n";
126  error_msg += "IncompressibleLSVOFBuoyancySource\n";
127  error_msg += "IncompressibleLSVOFConvectiveFlux\n";
128  error_msg += "IncompressibleLSVOFNthPhaseFraction\n";
129  error_msg += "IncompressibleLSVOFScalarConvectiveFlux\n";
130  error_msg += "IncompressibleLSVOFSurfaceTensionForce\n";
131  error_msg += "IncompressibleLSVOFTimeDerivative\n";
132  error_msg += "IncompressibleLSVOFVariableProperties\n";
133  error_msg += "IncompressibleLSVOFViscousFlux\n";
134  // Add optional closure models
135  error_msg += "\nOptional IncompressibleLSVOF closure models:\n";
136  error_msg += "IncompressibleLSVOFBubbleExact\n";
137  error_msg += "IncompressibleLSVOFConstantVectorField\n";
138  error_msg += "IncompressibleLSVOFErrorNorms\n";
139  error_msg += "IncompressibleLSVOFVortexVelocity\n";
140 }
141 
142 //---------------------------------------------------------------------------//
143 template<class EvalType, int NumSpaceDim>
144 void IncompressibleLSVOFFactory<EvalType, NumSpaceDim>::buildDefaultClosureModels(
145  const Teuchos::RCP<panzer::IntegrationRule>& ir,
146  const Teuchos::ParameterList& closure_model_list,
147  const Teuchos::ParameterList& user_params,
148  const Teuchos::RCP<panzer::GlobalData>& global_data,
149  Teuchos::RCP<std::vector<Teuchos::RCP<PHX::Evaluator<panzer::Traits>>>>
150  evaluators)
151 {
152  // Get closure properties from closure model list
153  Teuchos::ParameterList lsvof_params
154  = closure_model_list.sublist("LSVOF_Properties");
155 
156  // Check that model type is valid
157  const auto type_validator = Teuchos::rcp(
158  new Teuchos::StringToIntegralParameterEntryValidator<LSVOFModelType>(
159  Teuchos::tuple<std::string>("None", "CLS", "VOF"), "None"));
160 
161  const LSVOFModelType lsvof_model_name = type_validator->getIntegralValue(
162  lsvof_params.get<std::string>("LSVOF Model"));
163 
164  if (lsvof_model_name == LSVOFModelType::None)
165  {
166  std::string msg = "Error: LSVOF Model cannot be missing";
167  msg += " or set to 'None' when Closure Factory Type is set to 'LSVOF'.";
168 
169  throw std::runtime_error(msg);
170  }
171 
172  // Boolean for solving just LSVOF scalar equations
173  const bool build_lsvofmom_equ
174  = lsvof_params.isType<bool>("Build LSVOF Navier-Stokes Equations")
175  ? lsvof_params.get<bool>("Build LSVOF Navier-Stokes Equations")
176  : true;
177 
178  // Number of phases
179  const int num_phases = lsvof_params.get<int>("Number of Phases");
180  const int num_lsvof_dofs = num_phases - 1;
181 
182  if (num_phases < 2)
183  {
184  const std::string msg = "Must have 2 or more phases for LSVOF model.";
185 
186  throw std::runtime_error(msg);
187  }
188  else if (num_phases > 2)
189  {
190  const std::string msg
191  = "More than 2 phases not currently supported in LSVOF model.";
192 
193  throw std::runtime_error(msg);
194  }
195 
196  // List of phase names
197  std::vector<std::string> phase_names;
198 
199  // Booleans for considering buoyancy force and surface tension
200  const bool _build_lsvof_buoyancy_source
201  = lsvof_params.get<bool>("Build LSVOF Buoyancy Source", true);
202 
203  const bool _build_lsvof_surface_tension
204  = lsvof_params.get<bool>("Build LSVOF Surface Tension", true);
205 
206  // Add closure models for LSVOF transport equations here
207  if (lsvof_model_name == LSVOFModelType::VOF)
208  {
209  for (int n = 1; n <= num_phases; ++n)
210  {
211  Teuchos::ParameterList vof_names_list;
212 
213  const std::string list_name = "Phase " + std::to_string(n);
214 
215  Teuchos::ParameterList phase_list = lsvof_params.sublist(list_name);
216 
217  const std::string phase_name
218  = phase_list.get<std::string>("Phase Name");
219  const std::string phase_fraction_name = "alpha_" + phase_name;
220 
221  vof_names_list.set("Field Name", phase_fraction_name);
222  vof_names_list.set("Equation Name",
223  phase_fraction_name + "_equation");
224 
225  // Create closure models for N - 1 phase fraction transport
226  // equations
227  if (n < num_phases)
228  {
229  phase_names.push_back(phase_fraction_name);
230 
231  // Time derivative
232  const auto eval_vof_dqdt = Teuchos::rcp(
233  new IncompressibleLSVOFScalarTimeDerivative<EvalType,
234  panzer::Traits>(
235  *ir,
236  phase_fraction_name,
237  phase_fraction_name + "_equation"));
238 
239  evaluators->push_back(eval_vof_dqdt);
240 
241  // Convective flux
242  const auto eval_vof_conv = Teuchos::rcp(
243  new IncompressibleLSVOFScalarConvectiveFlux<EvalType,
244  panzer::Traits,
245  num_space_dim>(
246  *ir,
247  n - 1,
248  num_lsvof_dofs,
249  phase_fraction_name + "_equation"));
250 
251  evaluators->push_back(eval_vof_conv);
252 
253  // Artificial Compression term
254  const auto eval_vof_compress = Teuchos::rcp(
255  new IncompressibleLSVOFArtificialCompression<EvalType,
256  panzer::Traits,
257  num_space_dim>(
258  *ir,
259  lsvof_params,
260  phase_fraction_name,
261  phase_fraction_name + "_equation"));
262 
263  evaluators->push_back(eval_vof_compress);
264 
265  // TODO: add compressive flux, source terms, etc. as they
266  // are created.
267  }
268  else
269  {
270  // Create combined array of phase fraction fields
271  const bool include_time_deriv = true;
272  const bool include_grads = false;
273  const auto phase_vec
274  = Utils::ScalarToVector<EvalType, PhaseIndex>::createFromList(
275  *ir,
276  "volume_fractions",
277  phase_names,
278  include_time_deriv,
279  include_grads);
280 
281  evaluators->push_back(phase_vec);
282 
283  phase_names.push_back(phase_fraction_name);
284 
285  // Closure that calculate phase fraction for Nth phase:
286  // $\alpha_n = 1.0 - \alpha_1 - ... - \alpha_{n-1}$
287  const auto eval_nth_phase = Teuchos::rcp(
288  new IncompressibleLSVOFNthPhaseFraction<EvalType,
289  panzer::Traits>(
290  *ir, phase_names));
291 
292  evaluators->push_back(eval_nth_phase);
293  }
294  }
295  }
296  else if (lsvof_model_name == LSVOFModelType::CLS)
297  {
298  // Construct list of phase names
299  for (int n = 1; n <= num_phases; ++n)
300  {
301  Teuchos::ParameterList phase_list
302  = lsvof_params.sublist("Phase " + std::to_string(n));
303 
304  const std::string phase_name
305  = phase_list.get<std::string>("Phase Name");
306 
307  phase_names.push_back(phase_name);
308  }
309 
310  // Check for interface normal reconstruction
311  const auto type_validator = Teuchos::rcp(
312  new Teuchos::StringToIntegralParameterEntryValidator<
313  LSNormalReconstructionType>(Teuchos::tuple<std::string>("NonRe"
314  "const"
315  "ructe"
316  "d"),
317  "NonReconstructed"));
318 
319  const LSNormalReconstructionType reconstruction_type
320  = type_validator->getIntegralValue(lsvof_params.get<std::string>(
321  "LS Normal Reconstruction Type"));
322 
323  // Automatically build metric tensor element length
324  const auto eval_mt
325  = Teuchos::rcp(new MetricTensor<EvalType, panzer::Traits>(*ir));
326 
327  evaluators->push_back(eval_mt);
328 
329  const auto eval_mt_el = Teuchos::rcp(
330  new MetricTensorElementLength<EvalType, panzer::Traits>(*ir));
331 
332  evaluators->push_back(eval_mt_el);
333 
334  // Interface thickness, epsilon
335  const auto eval_cls_epsilon = Teuchos::rcp(
336  new IncompressibleCLSEpsilon<EvalType, panzer::Traits, num_space_dim>(
337  *ir, lsvof_params));
338 
339  evaluators->push_back(eval_cls_epsilon);
340 
341  // Save phi field values from previous stage for time derivative and
342  // convective flux (when Crank-Nicolson option is used)
343  const auto eval_phi_star = Teuchos::rcp(
344  new VariableOldValue<EvalType, panzer::Traits>(*ir, lsvof_params));
345 
346  evaluators->push_back(eval_phi_star);
347 
348  // Smoothed sign function
349  const auto eval_cls_sign = Teuchos::rcp(
350  new IncompressibleCLSSign<EvalType, panzer::Traits>(*ir));
351 
352  evaluators->push_back(eval_cls_sign);
353 
354  // Regularization parameter, lambda
355  const auto eval_cls_lambda = Teuchos::rcp(
356  new IncompressibleCLSLambda<EvalType, panzer::Traits, num_space_dim>(
357  *ir, lsvof_params, global_data));
358 
359  evaluators->push_back(eval_cls_lambda);
360 
361  // Interface normal
362  if (reconstruction_type == LSNormalReconstructionType::NonReconstructed)
363  {
364  const auto eval_cls_q = Teuchos::rcp(
365  new IncompressibleCLSNonReconstructedNormal<EvalType,
366  panzer::Traits,
367  num_space_dim>(*ir));
368 
369  evaluators->push_back(eval_cls_q);
370  }
371 
372  // Regularization term
373  const auto eval_cls_reg = Teuchos::rcp(
374  new IncompressibleCLSRegularization<EvalType,
375  panzer::Traits,
376  num_space_dim>(*ir));
377 
378  evaluators->push_back(eval_cls_reg);
379  }
380 
381  // Material properties closure model
382  const auto eval_lsvof_props = Teuchos::rcp(
383  new IncompressibleLSVOFVariableProperties<EvalType, panzer::Traits>(
384  *ir, lsvof_params, phase_names));
385 
386  evaluators->push_back(eval_lsvof_props);
387 
388  // Add closure models for Navier-Stokes equations
389  if (build_lsvofmom_equ)
390  {
391  const auto eval_ns_dqdt = Teuchos::rcp(
392  new IncompressibleLSVOFTimeDerivative<EvalType,
393  panzer::Traits,
394  num_space_dim>(
395  *ir, lsvof_params));
396 
397  evaluators->push_back(eval_ns_dqdt);
398 
399  const auto eval_ns_conv = Teuchos::rcp(
400  new IncompressibleLSVOFConvectiveFlux<EvalType,
401  panzer::Traits,
402  num_space_dim>(*ir));
403 
404  evaluators->push_back(eval_ns_conv);
405 
406  const auto eval_ns_visc
407  = Teuchos::rcp(new IncompressibleLSVOFViscousFlux<EvalType,
408  panzer::Traits,
409  num_space_dim>(
410  *ir, lsvof_params));
411 
412  evaluators->push_back(eval_ns_visc);
413 
414  // Buoyancy
415  if (_build_lsvof_buoyancy_source)
416  {
417  const auto eval_ns_buo = Teuchos::rcp(
418  new IncompressibleLSVOFBuoyancySource<EvalType,
419  panzer::Traits,
420  num_space_dim>(
421  *ir, user_params));
422 
423  evaluators->push_back(eval_ns_buo);
424  }
425 
426  // Surface Tension
427  if (_build_lsvof_surface_tension)
428  {
429  const auto eval_ns_surf = Teuchos::rcp(
430  new IncompressibleLSVOFSurfaceTensionForce<EvalType,
431  panzer::Traits,
432  num_space_dim>(
433  *ir, lsvof_params, phase_names));
434 
435  evaluators->push_back(eval_ns_surf);
436  }
437  }
438 
439  // Closures required for global evaluators
440  const auto eval_local_dt = Teuchos::rcp(
441  new IncompressibleLocalTimeStepSize<EvalType, panzer::Traits, num_space_dim>(
442  *ir));
443 
444  evaluators->push_back(eval_local_dt);
445 }
446 
447 //---------------------------------------------------------------------------//
448 template<class EvalType, int NumSpaceDim>
449 bool IncompressibleLSVOFFactory<EvalType, NumSpaceDim>::isDefaultClosureModel(
450  const std::string& closure_type)
451 {
452  std::vector<std::string> default_closures;
453 
454  default_closures.push_back("IncompressibleCLSEpsilon");
455  default_closures.push_back("IncompressibleCLSLambda");
456  default_closures.push_back("IncompressibleCLSSign");
457  default_closures.push_back("IncompressibleLocalTimeStepSize");
458  default_closures.push_back("IncompressibleLSVOFArtificialCompression");
459  default_closures.push_back("IncompressibleLSVOFBuoyancySource");
460  default_closures.push_back("IncompressibleLSVOFConvectiveFlux");
461  default_closures.push_back("IncompressibleLSVOFProperties");
462  default_closures.push_back("IncompressibleLSVOFScalarConvectiveFlux");
463  default_closures.push_back("IncompressibleLSVOFSurfaceTensionForce");
464  default_closures.push_back("IncompressibleLSVOFTimeDerivative");
465  default_closures.push_back("IncompressibleLSVOFVariableProperties");
466  default_closures.push_back("IncompressibleLSVOFViscousFlux");
467 
468  for (const auto& closure : default_closures)
469  {
470  if (closure == closure_type)
471  return true;
472  }
473 
474  return false;
475 }
476 //---------------------------------------------------------------------------//
477 } // end namespace ClosureModel
478 } // end namespace VertexCFD
479 
480 #endif // end VERTEXCFD_INCOMPRESSIBLELSVOFCLOSUREMODELFACTORY_IMPL_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23