Loading [MathJax]/extensions/tex2jax.js
Cardinal
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
NekInterface.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 "CardinalEnums.h"
22 #include "MooseTypes.h"
23 #include "NekBoundaryCoupling.h"
24 #include "NekVolumeCoupling.h"
25 
26 #include "inipp.hpp"
27 #include "nekrs.hpp"
28 #include "bcMap.hpp"
29 #include "udf.hpp"
30 #include "inipp.hpp"
31 #include "mesh.h"
32 
33 #include "libmesh/point.h"
34 
35 #include <string>
36 #include <vector>
37 
45 namespace nekrs
46 {
47 
48 static int build_only;
49 
52 
55 
56 dfloat * getSgeo();
57 dfloat * getVgeo();
58 
65 
70 void setAbsoluteTol(double tol);
71 
78 Real scratchUnits(const int slot);
79 
84 void nondimensional(const bool n);
85 
90 void setRelativeTol(double tol);
91 
98 
106 void setNekSetupTime(const double & time);
107 
112 double getNekSetupTime();
113 
118 void setStartTime(const double & start);
119 
124 bool isInitialized();
125 
135 void write_usrwrk_field_file(const int & slot, const std::string & prefix, const dfloat & time, const int & step, const bool & write_coords);
136 
143 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
144 
151 void buildOnly(int buildOnly);
152 
157 int buildOnly();
158 
162 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
163 
168 bool hasCHT();
169 
174 bool hasMovingMesh();
175 
180 bool hasVariableDt();
181 
186 bool hasBlendingSolver();
187 
192 bool hasUserMeshSolver();
193 
198 bool endControlElapsedTime();
199 
204 bool endControlTime();
205 
210 bool endControlNumSteps();
211 
218 int scalarFieldOffset();
219 
224 int velocityFieldOffset();
225 
230 int fieldOffset();
231 
238 mesh_t * entireMesh();
239 
244 mesh_t * flowMesh();
245 
250 mesh_t * temperatureMesh();
251 
257 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
258 
263 int commRank();
264 
269 int commSize();
270 
276 
281 bool hasTemperatureSolve();
282 
288 bool hasScalarVariable(int scalarId);
289 
294 bool hasHeatSourceKernel();
295 
300 bool scratchAvailable();
301 
306 void initializeScratch(const unsigned int & n_slots);
307 
309 void freeScratch();
310 
316 double viscosity();
317 
323 double Pr();
324 
327 
328 template <typename T>
329 void allgatherv(const std::vector<int> & base_counts,
330  const T * input,
331  T * output,
332  const int multiplier = 1);
333 
341 void displacementAndCounts(const std::vector<int> & base_counts,
342  int * counts,
343  int * displacement,
344  const int multiplier);
345 
353 void interpolationMatrix(double * I, int starting_points, int ending_points);
354 
365  double * scratch, const double * I, double * x, int N, double * Ix, int M);
366 
374 Point centroidFace(int local_elem_id, int local_face_id);
375 
381 Point centroid(int local_elem_id);
382 
389 Point gllPoint(int local_elem_id, int local_node_id);
390 
399 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
400 
408 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
409  const std::vector<int> & boundary,
410  const nek_mesh::NekMeshEnum pp_mesh);
411 
418 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
419 
425 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
426 
436 bool normalizeFluxBySideset(const NekBoundaryCoupling & nek_boundary_coupling,
437  const std::vector<int> & boundary,
438  const std::vector<double> & moose_integral,
439  std::vector<double> & nek_integral,
440  double & normalized_nek_integral);
441 
451 bool normalizeFlux(const NekBoundaryCoupling & nek_boundary_coupling,
452  const std::vector<int> & boundary,
453  const double moose_integral,
454  double nek_integral,
455  double & normalized_nek_integral);
456 
463 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
464 
472 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
473  const nek_mesh::NekMeshEnum pp_mesh);
474 
480 double volume(const nek_mesh::NekMeshEnum pp_mesh);
481 
486 void dimensionalizeVolume(double & integral);
487 
492 void dimensionalizeArea(double & integral);
493 
501  const Real & volume,
502  double & integral);
503 
510 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
511  const Real & area,
512  double & integral);
513 
521 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
522  const std::vector<int> & boundary_id,
523  double & integral,
524  const nek_mesh::NekMeshEnum pp_mesh);
525 
533 double volumeIntegral(const field::NekFieldEnum & integrand,
534  const double & volume,
535  const nek_mesh::NekMeshEnum pp_mesh);
536 
543 double massFlowrate(const std::vector<int> & boundary_id,
544  const nek_mesh::NekMeshEnum pp_mesh);
545 
553 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
554  const field::NekFieldEnum & integrand,
555  const nek_mesh::NekMeshEnum pp_mesh);
556 
566 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
567 
574 double heatFluxIntegral(const std::vector<int> & boundary_id,
575  const nek_mesh::NekMeshEnum pp_mesh);
576 
582 void limitTemperature(const double * min_T, const double * max_T);
583 
591 void gradient(const int offset, const double * f, double * grad_f,
592  const nek_mesh::NekMeshEnum pp_mesh);
593 
602  const nek_mesh::NekMeshEnum pp_mesh,
603  const bool max);
604 
613 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
614  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
615 
620 int Nfaces();
621 
627 bool isHeatFluxBoundary(const int boundary);
628 
634 bool isMovingMeshBoundary(const int boundary);
635 
641 bool isTemperatureBoundary(const int boundary);
642 
648 const std::string temperatureBoundaryType(const int boundary);
649 
654 int polynomialOrder();
655 
660 int Nelements();
661 
666 int dim();
667 
675 int NfaceVertices();
676 
681 int NboundaryFaces();
682 
687 int NboundaryID();
688 
696 bool
697 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
698 
704 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
705 
711 {
713  int flux = -1;
714 
716  int heat_source = -1;
717 
719  int mesh_velocity_x = -1;
720 
722  int mesh_velocity_y = -1;
723 
725  int mesh_velocity_z = -1;
726 
729 
732 
735 
738 
741 };
742 
748 {
749  double U_ref = 1;
750  double T_ref = 0;
751  double dT_ref = 1;
752  double P_ref = 1;
753  double L_ref = 1;
754  double A_ref = 1;
755  double V_ref = 1;
756  double rho_ref = 1;
757  double Cp_ref = 1;
758  double flux_ref = 1;
759  double source_ref = 1;
760  double t_ref = 1;
761  double s01_ref = 0;
762  double ds01_ref = 1;
763  double s02_ref = 0;
764  double ds02_ref = 1;
765  double s03_ref = 0;
766  double ds03_ref = 1;
767 };
768 
774 double (*solutionPointer(const field::NekFieldEnum & field))(int);
775 
780 void (*solutionPointer(const field::NekWriteEnum & field))(int, dfloat);
781 
787 double scalar01(const int id);
788 
794 double scalar02(const int id);
795 
801 double scalar03(const int id);
802 
808 double usrwrk00(const int id);
809 
815 double usrwrk01(const int id);
816 
822 double usrwrk02(const int id);
823 
829 double temperature(const int id);
830 
836 double pressure(const int id);
837 
843 double unity(const int id);
844 
850 double velocity_x(const int id);
851 
857 double velocity_y(const int id);
858 
864 double velocity_z(const int id);
865 
871 double velocity(const int id);
872 
878 double velocity_x_squared(const int id);
879 
885 double velocity_y_squared(const int id);
886 
892 double velocity_z_squared(const int id);
893 
899 void flux(const int id, const dfloat value);
900 
906 void heat_source(const int id, const dfloat value);
907 
913 void x_displacement(const int id, const dfloat value);
914 
920 void y_displacement(const int id, const dfloat value);
921 
927 void z_displacement(const int id, const dfloat value);
928 
938 void initializeDimensionalScales(const double U,
939  const double T,
940  const double dT,
941  const double L,
942  const double rho,
943  const double Cp,
944  const double s01,
945  const double ds01,
946  const double s02,
947  const double ds02,
948  const double s03,
949  const double ds03);
950 
964 void dimensionalize(const field::NekFieldEnum & field, double & value);
965 
970 double referenceFlux();
971 
976 double referenceSource();
977 
982 double referenceLength();
983 
988 double referencePressure();
989 
994 double referenceTime();
995 
1000 double referenceVelocity();
1001 
1006 double referenceArea();
1007 
1012 double referenceVolume();
1013 
1014 // useful concept from Stack Overflow for templating MPI calls
1015 template <typename T>
1016 MPI_Datatype resolveType();
1017 
1025 template <typename T>
1026 void
1027 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
1028 {
1029  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
1030  int * displacement = (int *)calloc(commSize(), sizeof(int));
1031  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
1032 
1033  MPI_Allgatherv(input,
1034  recvCounts[commRank()],
1035  resolveType<T>(),
1036  output,
1037  (const int *)recvCounts,
1038  (const int *)displacement,
1039  resolveType<T>(),
1040  platform->comm.mpiComm);
1041 
1042  free(recvCounts);
1043  free(displacement);
1044 }
1045 
1046 } // end namespace nekrs
double unity(const int id)
Cardinal-specific nekRS API.
Definition: NekUility.C:21
MPI_Datatype resolveType()
void setStartTime(const double &start)
double velocity_x(const int id)
double usrwrk00(const int id)
int mesh_velocity_z
z-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:725
Definition: NekInterface.h:747
double sideMassFluxWeightedIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
bool endControlNumSteps()
double referenceArea()
double ds03_ref
Definition: NekInterface.h:766
void storeBoundaryCoupling(const std::vector< int > &boundary_id, int &N)
double Pr()
double referenceVolume()
bool hasCHT()
mesh_t * flowMesh()
void initializeScratch(const unsigned int &n_slots)
double velocity(const int id)
double massFlowrate(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
NekWriteEnum
Enumeration of possible fields to write in nekRS.
Definition: CardinalEnums.h:116
double P_ref
Definition: NekInterface.h:752
double A_ref
Definition: NekInterface.h:754
int polynomialOrder()
void dimensionalizeVolume(double &integral)
double velocity_z(const int id)
void write_usrwrk_field_file(const int &slot, const std::string &prefix, const dfloat &time, const int &step, const bool &write_coords)
Point centroidFace(int local_elem_id, int local_face_id)
double volumeExtremeValue(const field::NekFieldEnum &field, const nek_mesh::NekMeshEnum pp_mesh, const bool max)
int boundary_temperature
boundary temperature (for separate domain coupling)
Definition: NekInterface.h:731
double V_ref
Definition: NekInterface.h:755
bool isMovingMeshBoundary(const int boundary)
double volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh)
int commRank()
void flux(const int id, const dfloat value)
int heat_source
volumetric heat source (for volumetric heating)
Definition: NekInterface.h:716
double viscosity()
bool hasUserMeshSolver()
void displacementAndCounts(const std::vector< int > &base_counts, int *counts, int *displacement, const int multiplier)
int Nelements()
double scalar03(const int id)
double pressure(const int id)
double usrwrk02(const int id)
void heat_source(const int id, const dfloat value)
double referenceVelocity()
int Nfaces()
double source_ref
Definition: NekInterface.h:759
Definition: CardinalEnums.h:91
double T_ref
Definition: NekInterface.h:750
bool isTemperatureBoundary(const int boundary)
void copyDeformationToDevice()
Copy the deformation from host to device.
bool scratchAvailable()
void setRelativeTol(double tol)
void dimensionalizeArea(double &integral)
bool hasVariableDt()
void interpolateSurfaceFaceHex3D(double *scratch, const double *I, double *x, int N, double *Ix, int M)
void y_displacement(const int id, const dfloat value)
int mesh_velocity_x
x-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:719
bool hasTemperatureSolve()
NekMeshEnum
Definition: CardinalEnums.h:50
void initializeDimensionalScales(const double U, const double T, const double dT, const double L, const double rho, const double Cp, const double s01, const double ds01, const double s02, const double ds02, const double s03, const double ds03)
int boundary_scalar03
boundary scalar03 (for separate domain coupling)
Definition: NekInterface.h:740
void scaleUsrwrk(const unsigned int &slot, const dfloat &value)
bool hasHeatSourceKernel()
int boundary_velocity
boundary velocity (for separate domain coupling)
Definition: NekInterface.h:728
bool normalizeFlux(const NekBoundaryCoupling &nek_boundary_coupling, const std::vector< int > &boundary, const double moose_integral, double nek_integral, double &normalized_nek_integral)
Real referenceAdditiveScale(const field::NekFieldEnum &field)
double L_ref
Definition: NekInterface.h:753
void dimensionalize(const field::NekFieldEnum &field, double &value)
Dimensionalize a field by multiplying the nondimensional form by the reference.
bool isInitialized()
double referenceLength()
Definition: CardinalEnums.h:134
double volume(const nek_mesh::NekMeshEnum pp_mesh)
void limitTemperature(const double *min_T, const double *max_T)
int boundary_scalar01
boundary scalar01 (for separate domain coupling)
Definition: NekInterface.h:734
bool hasBlendingSolver()
double sideIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
double scalar02(const int id)
const std::string temperatureBoundaryType(const int boundary)
int dim()
double ds02_ref
Definition: NekInterface.h:764
double(*)(int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:774
double pressureSurfaceForce(const std::vector< int > &boundary_id, const Point &direction, const nek_mesh::NekMeshEnum pp_mesh)
bool endControlTime()
double velocity_y_squared(const int id)
void write_field_file(const std::string &prefix, const dfloat time, const int &step)
double flux_ref
Definition: NekInterface.h:758
bool hasTemperatureVariable()
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:1027
Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id)
int commSize()
bool isHeatFluxBoundary(const int boundary)
double area(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
int NboundaryID()
double usrwrk01(const int id)
double referenceTime()
mesh_t * temperatureMesh()
Point gllPoint(int local_elem_id, int local_node_id)
int velocityFieldOffset()
int NfaceVertices()
Number of vertices required to define an element face Vertices refer to the points required to place ...
double t_ref
Definition: NekInterface.h:760
double Cp_ref
Definition: NekInterface.h:757
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:94
double getNekSetupTime()
Definition: NekInterface.h:710
double temperature(const int id)
Definition: NekBoundaryCoupling.h:29
double s01_ref
Definition: NekInterface.h:761
void buildOnly(int buildOnly)
double ds01_ref
Definition: NekInterface.h:762
void updateHostMeshParameters()
Update the mesh parameters on host.
int fieldOffset()
Real scratchUnits(const int slot)
void freeScratch()
Free the scratch space.
void dimensionalizeVolumeIntegral(const field::NekFieldEnum &integrand, const Real &volume, double &integral)
double s02_ref
Definition: NekInterface.h:763
bool hasMovingMesh()
void checkFieldValidity(const field::NekFieldEnum &field)
double heatFluxIntegral(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
void interpolationMatrix(double *I, int starting_points, int ending_points)
int NboundaryFaces()
void initializeHostMeshParameters()
Allocate memory for the host mesh parameters.
double scalar01(const int id)
double U_ref
Definition: NekInterface.h:749
double velocity_y(const int id)
double velocity_x_squared(const int id)
void setNekSetupTime(const double &time)
int boundary_scalar02
boundary scalar02 (for separate domain coupling)
Definition: NekInterface.h:737
void setAbsoluteTol(double tol)
bool validBoundaryIDs(const std::vector< int > &boundary_id, int &first_invalid_id, int &n_boundaries)
double referencePressure()
int flux
boundary heat flux (for conjugate heat transfer)
Definition: NekInterface.h:713
double referenceSource()
double s03_ref
Definition: NekInterface.h:765
void x_displacement(const int id, const dfloat value)
void nondimensional(const bool n)
bool endControlElapsedTime()
mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh)
dfloat * getVgeo()
void gradient(const int offset, const double *f, double *grad_f, const nek_mesh::NekMeshEnum pp_mesh)
double rho_ref
Definition: NekInterface.h:756
bool hasScalarVariable(int scalarId)
void z_displacement(const int id, const dfloat value)
std::vector< double > usrwrkSideIntegral(const unsigned int &slot, const std::vector< int > &boundary, const nek_mesh::NekMeshEnum pp_mesh)
double dT_ref
Definition: NekInterface.h:751
double usrwrkVolumeIntegral(const unsigned int &slot, const nek_mesh::NekMeshEnum pp_mesh)
double velocity_z_squared(const int id)
int scalarFieldOffset()
Point centroid(int local_elem_id)
double referenceFlux()
int mesh_velocity_y
y-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:722
void interpolateVolumeHex3D(const double *I, double *x, int N, double *Ix, int M)
bool normalizeFluxBySideset(const NekBoundaryCoupling &nek_boundary_coupling, const std::vector< int > &boundary, const std::vector< double > &moose_integral, std::vector< double > &nek_integral, double &normalized_nek_integral)
dfloat * getSgeo()
mesh_t * entireMesh()
void dimensionalizeSideIntegral(const field::NekFieldEnum &integrand, const Real &area, double &integral)
double sideExtremeValue(const std::vector< int > &boundary_id, const field::NekFieldEnum &field, const nek_mesh::NekMeshEnum pp_mesh, const bool max)