Cardinal
NekRSProblemBase.h
Go to the documentation of this file.
1 /********************************************************************/
2 /* SOFTWARE COPYRIGHT NOTIFICATION */
3 /* Cardinal */
4 /* */
5 /* (c) 2021 UChicago Argonne, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by UChicago Argonne, LLC */
9 /* Under Contract No. DE-AC02-06CH11357 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* Prepared by Battelle Energy Alliance, LLC */
13 /* Under Contract No. DE-AC07-05ID14517 */
14 /* With the U. S. Department of Energy */
15 /* */
16 /* See LICENSE for full restrictions */
17 /********************************************************************/
18 
19 #pragma once
20 
21 #include "CardinalProblem.h"
22 #include "NekInterface.h"
23 #include "NekTimeStepper.h"
24 #include "NekScalarValue.h"
25 #include "NekRSMesh.h"
26 #include "Transient.h"
27 #include "TimeStepper.h"
28 
29 #include <memory>
30 #include "inipp.hpp"
31 #include "nekrs.hpp"
32 
41 {
42 public:
43  NekRSProblemBase(const InputParameters & params);
44 
45  static InputParameters validParams();
46 
48 
54  bool isDataTransferHappening(ExternalProblem::Direction direction);
55 
62 
67  unsigned int firstReservedUsrwrkSlot() const { return _first_reserved_usrwrk_slot; }
68 
70  void sendScalarValuesToNek();
71 
74 
82  void mapFaceDataToNekFace(const unsigned int & e, const unsigned int & var_num,
83  const Real & multiplier, double ** outgoing_data);
84 
92  void mapVolumeDataToNekVolume(const unsigned int & e, const unsigned int & var_num,
93  const Real & multiplier, double ** outgoing_data);
94 
111  void mapFaceDataToNekVolume(const unsigned int & e, const unsigned int & var_num,
112  const Real & multiplier, double ** outgoing_data);
113 
119  void writeFieldFile(const Real & time, const int & step) const;
120 
127  virtual void adjustNekSolution() {}
128 
136  virtual bool isOutputStep() const;
137 
138  virtual void initialSetup() override;
139 
140  virtual void externalSolve() override;
141 
142  virtual bool converged(unsigned int) override { return true; }
143 
144  virtual void addExternalVariables() override;
145 
146  virtual void syncSolutions(ExternalProblem::Direction direction) override;
147 
152  virtual bool nondimensional() const { return _nondimensional; }
153 
158  virtual const bool hasMovingNekMesh() const { return false; }
159 
164  virtual bool synchronizeIn();
165 
170  virtual bool synchronizeOut();
171 
176  double L_ref() const { return _L_ref; }
177 
182  unsigned int nUsrWrkSlots() const { return _n_usrwrk_slots; }
183 
184 protected:
188  void copyScratchToDevice();
189 
195  void interpolateBoundarySolutionToNek(double * incoming_moose_value,
196  double * outgoing_nek_value);
197 
204  void interpolateVolumeSolutionToNek(const int elem_id, double * incoming_moose_value,
205  double * outgoing_nek_value);
206 
217  void writeVolumeSolution(const int elem_id,
218  const field::NekWriteEnum & field,
219  double * T,
220  const std::vector<double> * add = nullptr);
221 
229  void writeBoundarySolution(const int elem_id, const field::NekWriteEnum & field, double * T);
230 
236  void volumeSolution(const field::NekFieldEnum & f, double * T);
237 
243  void boundarySolution(const field::NekFieldEnum & f, double * T);
244 
247 
253  virtual void fillAuxVariable(const unsigned int var_number, const double * value);
254 
258  virtual void extractOutputs();
259 
264  virtual InputParameters getExternalVariableParameters();
265 
271  virtual void addTemperatureVariable();
272 
273  std::unique_ptr<NumericVector<Number>> _serialized_solution;
274 
280  std::string fieldFilePrefix(const int & number) const;
281 
283  const std::string & _casename;
284 
315  const bool & _nondimensional;
316 
318  const Real & _U_ref;
319 
321  const Real & _T_ref;
322 
324  const Real & _dT_ref;
325 
327  const Real & _L_ref;
328 
330  const Real & _rho_0;
331 
333  const Real & _Cp_0;
334 
349  const bool & _write_fld_files;
350 
353 
362  unsigned int _n_usrwrk_slots;
363 
365  const unsigned int & _constant_interval;
366 
369 
371  const unsigned int & _first_reserved_usrwrk_slot;
372 
375 
378 
381 
384 
387 
389  const std::vector<int> * _boundary = nullptr;
390 
392  bool _volume;
393 
395  double _start_time;
396 
399 
405 
408 
410  Transient * _transient_executioner = nullptr;
411 
417 
419  const MultiMooseEnum * _outputs = nullptr;
420 
422  std::vector<std::string> _var_names;
423 
425  std::vector<unsigned int> _external_vars;
426 
428  std::string _var_string;
429 
431  double * _external_data = nullptr;
432 
435 
437  const PostprocessorValue * _transfer_in = nullptr;
438 
440  double * _interpolation_outgoing = nullptr;
441 
443  double * _interpolation_incoming = nullptr;
444 
447 
450 
452  const std::vector<unsigned int> * _usrwrk_output = nullptr;
453 
455  const std::vector<std::string> * _usrwrk_output_prefix = nullptr;
456 
459 
461  double _elapsedTime;
462 
465 
468 
509 
511  std::vector<std::string> _usrwrk_indices;
512 
514  std::vector<NekScalarValue *> _nek_uos;
515 
517  static bool _first;
518 
520  unsigned int _scratch_counter;
521 
523  unsigned int _n_uo_slots;
524 };
bool _volume
Whether the mesh contains volume-based coupling.
Definition: NekRSProblemBase.h:392
NekTimeStepper * _timestepper
The time stepper used for selection of time step size.
Definition: NekRSProblemBase.h:407
unsigned int _n_uo_slots
Number of scratch space slots used for NekScalarValue usage.
Definition: NekRSProblemBase.h:523
unsigned int _minimum_scratch_size_for_coupling
Minimum allowable scratch space size, strictly what is needed by Cardinal for coupling.
Definition: NekRSProblemBase.h:446
virtual void syncSolutions(ExternalProblem::Direction direction) override
std::vector< NekScalarValue * > _nek_uos
Userobjects containing stochastic input data.
Definition: NekRSProblemBase.h:514
NekWriteEnum
Enumeration of possible fields to write in nekRS.
Definition: CardinalEnums.h:105
const unsigned int & _constant_interval
For constant synchronization intervals, the desired frequency (in units of Nek time steps)
Definition: NekRSProblemBase.h:365
virtual InputParameters getExternalVariableParameters()
Definition: NekRSMesh.h:50
void writeFieldFile(const Real &time, const int &step) const
virtual const bool hasMovingNekMesh() const
Definition: NekRSProblemBase.h:158
Transient * _transient_executioner
Underlying executioner.
Definition: NekRSProblemBase.h:410
const std::vector< int > * _boundary
Boundary IDs through which to couple nekRS and MOOSE.
Definition: NekRSProblemBase.h:389
unsigned int _n_usrwrk_slots
Definition: NekRSProblemBase.h:362
NekRSMesh * _nek_mesh
Definition: NekRSProblemBase.h:404
const PostprocessorValue * _transfer_in
Postprocessor containing the signal of when a synchronization has occurred.
Definition: NekRSProblemBase.h:437
const bool & _write_fld_files
Definition: NekRSProblemBase.h:349
void writeBoundarySolution(const int elem_id, const field::NekWriteEnum &field, double *T)
const Real & _Cp_0
Reference isobaric specific heat capacity.
Definition: NekRSProblemBase.h:333
int _n_surface_elems
Number of surface elements in the data transfer mesh, across all processes.
Definition: NekRSProblemBase.h:374
double _elapsedStepSum
Sum of the elapsed time in NekRS solves.
Definition: NekRSProblemBase.h:458
Definition: CardinalEnums.h:86
void initializeInterpolationMatrices()
Initialize interpolation matrices for transfers in/out of nekRS.
const MultiMooseEnum * _outputs
NekRS solution fields to output to the mesh mirror.
Definition: NekRSProblemBase.h:419
synchronization::SynchronizationEnum _synchronization_interval
When to synchronize the NekRS solution with the mesh mirror.
Definition: NekRSProblemBase.h:508
void boundarySolution(const field::NekFieldEnum &f, double *T)
int _moose_Nq
For the MOOSE mesh, the number of quadrature points in each coordinate direction.
Definition: NekRSProblemBase.h:449
const Real & _T_ref
Reference characteristic temperature.
Definition: NekRSProblemBase.h:321
int _n_volume_elems
Number of volume elements in the data transfer mesh, across all processes.
Definition: NekRSProblemBase.h:380
virtual bool nondimensional() const
Definition: NekRSProblemBase.h:152
void writeVolumeSolution(const int elem_id, const field::NekWriteEnum &field, double *T, const std::vector< double > *add=nullptr)
const bool & _nondimensional
Whether the nekRS solution is performed in nondimensional scales.
Definition: NekRSProblemBase.h:315
virtual bool synchronizeOut()
static InputParameters validParams()
virtual void externalSolve() override
virtual bool isOutputStep() const
Whether nekRS should write an output file for the current time step.
const std::vector< std::string > * _usrwrk_output_prefix
Filename prefix to use for naming the field files containing the nrs->o_usrwrk array slots.
Definition: NekRSProblemBase.h:455
virtual void adjustNekSolution()
Definition: NekRSProblemBase.h:127
std::vector< unsigned int > _external_vars
Numeric identifiers for the external variables.
Definition: NekRSProblemBase.h:425
SynchronizationEnum
Definition: CardinalEnums.h:59
double L_ref() const
Definition: NekRSProblemBase.h:176
int _n_vertices_per_volume
Number of vertices per volume element of the transfer mesh.
Definition: NekRSProblemBase.h:383
void mapFaceDataToNekVolume(const unsigned int &e, const unsigned int &var_num, const Real &multiplier, double **outgoing_data)
Map nodal points on a MOOSE face element to the GLL points on a Nek volume element.
virtual void addTemperatureVariable()
unsigned int nUsrWrkSlots() const
Definition: NekRSProblemBase.h:182
Definition: CardinalProblem.h:26
const Real & _U_ref
Reference characteristic velocity.
Definition: NekRSProblemBase.h:318
const std::string & _casename
NekRS casename.
Definition: NekRSProblemBase.h:283
double * _interpolation_outgoing
Vandermonde interpolation matrix (for outgoing transfers)
Definition: NekRSProblemBase.h:440
const Real & _dT_ref
Reference characteristic temperature delta.
Definition: NekRSProblemBase.h:324
double _tSolveStepMax
Maximum step solve time.
Definition: NekRSProblemBase.h:467
void getNekScalarValueUserObjects()
Setup to fetch NekScalarValue user objects for sending scalar values into NekRS scratch space.
void interpolateBoundarySolutionToNek(double *incoming_moose_value, double *outgoing_nek_value)
int _n_points
Number of points for interpolated fields on the MOOSE mesh.
Definition: NekRSProblemBase.h:434
virtual void fillAuxVariable(const unsigned int var_number, const double *value)
const unsigned int & _first_reserved_usrwrk_slot
First slice in usrwrk for Cardinal to read/write data from.
Definition: NekRSProblemBase.h:371
const bool & _skip_final_field_file
Whether to skip writing a field file on NekRS's last time steo.
Definition: NekRSProblemBase.h:368
int _n_vertices_per_surface
Number of vertices per surface element of the transfer mesh.
Definition: NekRSProblemBase.h:377
const bool & _disable_fld_file_output
Whether to turn off all field file writing.
Definition: NekRSProblemBase.h:352
int _n_vertices_per_elem
Number of vertices per element in the data transfer mesh, which depends on whether boundary/volume co...
Definition: NekRSProblemBase.h:386
virtual bool converged(unsigned int) override
Definition: NekRSProblemBase.h:142
std::vector< std::string > _var_names
Names of external variables when extracting the NekRS solution.
Definition: NekRSProblemBase.h:422
virtual void addExternalVariables() override
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:89
void sendScalarValuesToNek()
Send values from NekScalarValue userobjects to NekRS.
Definition: NekRSProblemBase.h:40
void mapFaceDataToNekFace(const unsigned int &e, const unsigned int &var_num, const Real &multiplier, double **outgoing_data)
double _tSolveStepMin
Minimum step solve time.
Definition: NekRSProblemBase.h:464
virtual void extractOutputs()
bool _needs_interpolation
Definition: NekRSProblemBase.h:416
double * _interpolation_incoming
Vandermonde interpolation matrix (for incoming transfers)
Definition: NekRSProblemBase.h:443
void interpolateVolumeSolutionToNek(const int elem_id, double *incoming_moose_value, double *outgoing_nek_value)
unsigned int minimumScratchSizeForCoupling() const
Definition: NekRSProblemBase.h:61
bool isDataTransferHappening(ExternalProblem::Direction direction)
const Real & _rho_0
Reference density.
Definition: NekRSProblemBase.h:330
unsigned int _scratch_counter
Counter for any potential NekScalarValue objects in the input file.
Definition: NekRSProblemBase.h:520
std::string fieldFilePrefix(const int &number) const
virtual bool synchronizeIn()
double _start_time
Start time of the simulation based on NekRS's .par file.
Definition: NekRSProblemBase.h:395
bool _is_output_step
Whether the most recent time step was an output file writing step.
Definition: NekRSProblemBase.h:398
const std::vector< unsigned int > * _usrwrk_output
Slots in the nrs->o_usrwrk array to write to a field file.
Definition: NekRSProblemBase.h:452
double * _external_data
Scratch space to place external NekRS fields before writing into auxiliary variables.
Definition: NekRSProblemBase.h:431
static bool _first
flag to indicate whether this is the first pass to serialize the solution
Definition: NekRSProblemBase.h:517
void mapVolumeDataToNekVolume(const unsigned int &e, const unsigned int &var_num, const Real &multiplier, double **outgoing_data)
std::unique_ptr< NumericVector< Number > > _serialized_solution
Definition: NekRSProblemBase.h:273
std::vector< std::string > _usrwrk_indices
quantities to write to nrs->usrwrk (and the order to write them)
Definition: NekRSProblemBase.h:511
unsigned int firstReservedUsrwrkSlot() const
Definition: NekRSProblemBase.h:67
std::string _var_string
Descriptive string for the variables extracted from NekRS.
Definition: NekRSProblemBase.h:428
void volumeSolution(const field::NekFieldEnum &f, double *T)
const Real & _L_ref
Reference characteristic length.
Definition: NekRSProblemBase.h:327
virtual void initialSetup() override
double _elapsedTime
Sum of the total elapsed time in NekRS solves.
Definition: NekRSProblemBase.h:461
Time stepper that reads time step information directly from nekRS.
Definition: NekTimeStepper.h:37
NekRSProblemBase(const InputParameters &params)
void copyScratchToDevice()