Cardinal
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 "nrs.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 
54 int Nscalar();
55 
58 
61 
62 dfloat * host_x();
63 dfloat * host_y();
64 dfloat * host_z();
65 
66 nrs_t * nrsPtr();
67 
68 dfloat * getSgeo();
69 dfloat * getVgeo();
70 
78 
79 void copyDeviceToHost();
80 
85 void computeWallDistance(const std::vector<int> & boundary_id);
86 
92 std::vector<dfloat> yPlus(const std::vector<int> & boundary_id);
93 
99 std::vector<dfloat> viscousDrag(const std::vector<int> & boundary);
100 
105 void setAbsoluteTol(double tol);
106 
113 Real scratchUnits(const int slot);
114 
119 void nondimensional(const bool n);
120 
125 void setRelativeTol(double tol);
126 
134 void setNekSetupTime(const double & time);
135 
140 double getNekSetupTime();
141 
146 void setStartTime(const double & start);
147 
152 bool isInitialized();
153 
163 void write_usrwrk_field_file(const int & size,
164  const int & index,
165  const int & slot,
166  const std::string & prefix,
167  const dfloat & time,
168  const int & step,
169  const bool & write_coords);
170 
177 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
178 
185 void buildOnly(int buildOnly);
186 
191 int buildOnly();
192 
196 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
197 
202 bool hasCHT();
203 
208 bool hasMovingMesh();
209 
214 bool hasVariableDt();
215 
220 bool hasBlendingSolver();
221 
226 bool hasUserMeshSolver();
227 
232 bool endControlElapsedTime();
233 
238 bool endControlTime();
239 
244 bool endControlNumSteps();
245 
252 int scalarFieldOffset();
253 
258 int velocityFieldOffset();
259 
264 int fieldOffset();
265 
272 mesh_t * entireMesh();
273 
278 mesh_t * flowMesh();
279 
284 mesh_t * temperatureMesh();
285 
291 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
292 
297 int commRank();
298 
303 int commSize();
304 
310 
315 bool hasTemperatureSolve();
316 
322 bool hasScalarVariable(int scalarId);
323 
328 bool hasHeatSourceKernel();
329 
334 bool scratchAvailable();
335 
340 void initializeScratch(const unsigned int & n_slots);
341 
343 void freeScratch();
344 
350 double viscosity();
351 
357 double Pr();
358 
361 
362 template <typename T>
363 void allgatherv(const std::vector<int> & base_counts,
364  const T * input,
365  T * output,
366  const int multiplier = 1);
367 
375 void displacementAndCounts(const std::vector<int> & base_counts,
376  int * counts,
377  int * displacement,
378  const int multiplier);
379 
387 void interpolationMatrix(double * I, int starting_points, int ending_points);
388 
399  double * scratch, const double * I, double * x, int N, double * Ix, int M);
400 
408 Point centroidFace(int local_elem_id, int local_face_id);
409 
415 Point centroid(int local_elem_id);
416 
423 Point gllPoint(int local_elem_id, int local_node_id);
424 
433 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
434 
442 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
443  const std::vector<int> & boundary,
444  const nek_mesh::NekMeshEnum pp_mesh);
445 
452 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
453 
459 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
460 
467 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
468 
476 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
477  const nek_mesh::NekMeshEnum pp_mesh);
478 
484 double volume(const nek_mesh::NekMeshEnum pp_mesh);
485 
490 void dimensionalizeVolume(double & integral);
491 
496 void dimensionalizeArea(double & integral);
497 
505  const Real & volume,
506  double & integral);
507 
514 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
515  const Real & area,
516  double & integral);
517 
525 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
526  const std::vector<int> & boundary_id,
527  double & integral,
528  const nek_mesh::NekMeshEnum pp_mesh);
529 
537 double volumeIntegral(const field::NekFieldEnum & integrand,
538  const double & volume,
539  const nek_mesh::NekMeshEnum pp_mesh);
540 
547 double massFlowrate(const std::vector<int> & boundary_id,
548  const nek_mesh::NekMeshEnum pp_mesh);
549 
557 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
558  const field::NekFieldEnum & integrand,
559  const nek_mesh::NekMeshEnum pp_mesh);
560 
570 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
571 
578 double heatFluxIntegral(const std::vector<int> & boundary_id,
579  const nek_mesh::NekMeshEnum pp_mesh);
580 
586 void limitTemperature(const double * min_T, const double * max_T);
587 
596 void gradient(const int offset,
597  const int e,
598  const double * f,
599  double * grad_f,
600  const nek_mesh::NekMeshEnum pp_mesh);
601 
610  const nek_mesh::NekMeshEnum pp_mesh,
611  const bool max);
612 
621 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
622  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
623 
628 int Nfaces();
629 
635 bool isHeatFluxBoundary(const int boundary);
636 
642 bool isMovingMeshBoundary(const int boundary);
643 
649 bool isTemperatureBoundary(const int boundary);
650 
656 const std::string temperatureBoundaryType(const int boundary);
657 
662 int polynomialOrder();
663 
668 int Nelements();
669 
674 int dim();
675 
683 int NfaceVertices();
684 
689 int NboundaryFaces();
690 
695 int NboundaryID();
696 
704 bool
705 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
706 
712 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
713 
719 {
720  double U_ref = 1;
721  double T_ref = 0;
722  double dT_ref = 1;
723  double P_ref = 1;
724  double L_ref = 1;
725  double A_ref = 1;
726  double V_ref = 1;
727  double rho_ref = 1;
728  double Cp_ref = 1;
729  double flux_ref = 1;
730  double source_ref = 1;
731  double t_ref = 1;
732  double s01_ref = 0;
733  double ds01_ref = 1;
734  double s02_ref = 0;
735  double ds02_ref = 1;
736  double s03_ref = 0;
737  double ds03_ref = 1;
738 };
739 
745 double (*solutionPointer(const field::NekFieldEnum & field))(int, int);
746 double (*solutionPointer(const field::NekWriteEnum & field))(int, int);
747 
753 int scalarSlot(const int id);
754 
760 double get_scalar01(const int id, const int surf_offset);
761 
767 double get_scalar02(const int id, const int surf_offset);
768 
774 double get_scalar03(const int id, const int surf_offset);
775 
781 double get_usrwrk00(const int id, const int surf_offset);
782 
788 double get_usrwrk01(const int id, const int surf_offset);
789 
795 double get_usrwrk02(const int id, const int surf_offset);
796 
802 double get_temperature(const int id, const int surf_offset);
803 
809 double get_pressure(const int id, const int surf_offset);
810 
816 double get_unity(const int id, const int surf_offset);
817 
823 double get_velocity_x(const int id, const int surf_offset);
824 
830 double get_velocity_y(const int id, const int surf_offset);
831 
837 double get_velocity_z(const int id, const int surf_offset);
838 
844 double get_velocity(const int id, const int surf_offset);
845 
851 double get_velocity_x_squared(const int id, const int surf_offset);
852 
858 double get_velocity_y_squared(const int id, const int surf_offset);
859 
865 double get_velocity_z_squared(const int id, const int surf_offset);
866 
882 void initializeDimensionalScales(const double U,
883  const double T,
884  const double dT,
885  const double L,
886  const double rho,
887  const double Cp,
888  const double s01,
889  const double ds01,
890  const double s02,
891  const double ds02,
892  const double s03,
893  const double ds03);
894 
909 
923 
928 double referenceLength();
929 
934 double referenceTime();
935 
940 double referenceArea();
941 
946 double referenceVolume();
947 
948 // useful concept from Stack Overflow for templating MPI calls
949 template <typename T>
950 MPI_Datatype resolveType();
951 
959 template <typename T>
960 void
961 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
962 {
963  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
964  int * displacement = (int *)calloc(commSize(), sizeof(int));
965  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
966 
967  MPI_Allgatherv(input,
968  recvCounts[commRank()],
969  resolveType<T>(),
970  output,
971  (const int *)recvCounts,
972  (const int *)displacement,
973  resolveType<T>(),
974  platform->comm.mpiComm());
975 
976  free(recvCounts);
977  free(displacement);
978 }
979 
981 
982 // Accessors for NekRS host arrays
983 std::tuple<dfloat *, dfloat *, dfloat *> host_xyz();
984 std::vector<dfloat> & host_U();
985 std::vector<dfloat> & host_P();
986 std::vector<dfloat> & host_S();
987 dfloat * host_wrk();
988 
989 mesh_t * createMesh2(mesh_t * _mesh, int Nc);
990 
991 } // end namespace nekrs
Cardinal-specific nekRS API.
Definition: NekUility.C:21
MPI_Datatype resolveType()
std::vector< dfloat > & host_U()
void setStartTime(const double &start)
Definition: NekInterface.h:718
double sideMassFluxWeightedIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
bool endControlNumSteps()
double referenceArea()
double get_velocity(const int id, const int surf_offset)
double ds03_ref
Definition: NekInterface.h:737
void storeBoundaryCoupling(const std::vector< int > &boundary_id, int &N)
int Nscalar()
dfloat * host_wrk()
double Pr()
double referenceVolume()
double get_scalar01(const int id, const int surf_offset)
bool hasCHT()
std::tuple< dfloat *, dfloat *, dfloat * > host_xyz()
mesh_t * flowMesh()
void initializeScratch(const unsigned int &n_slots)
double get_usrwrk01(const int id, const int surf_offset)
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:117
double P_ref
Definition: NekInterface.h:723
double get_velocity_x_squared(const int id, const int surf_offset)
double A_ref
Definition: NekInterface.h:725
int polynomialOrder()
void dimensionalizeVolume(double &integral)
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)
double V_ref
Definition: NekInterface.h:726
bool isMovingMeshBoundary(const int boundary)
double volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh)
int commRank()
double viscosity()
std::vector< dfloat > & host_S()
bool hasUserMeshSolver()
void displacementAndCounts(const std::vector< int > &base_counts, int *counts, int *displacement, const int multiplier)
int Nelements()
nrs_t * nrsPtr()
double get_velocity_x(const int id, const int surf_offset)
dfloat * host_x()
int Nfaces()
double source_ref
Definition: NekInterface.h:730
Definition: CardinalEnums.h:92
double T_ref
Definition: NekInterface.h:721
dfloat * host_y()
bool isTemperatureBoundary(const int boundary)
Real nondimensionalAdditive(const field::NekFieldEnum &field)
double(*)(int, int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:745
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)
bool hasTemperatureSolve()
NekMeshEnum
Definition: CardinalEnums.h:51
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)
void scaleUsrwrk(const unsigned int &slot, const dfloat &value)
double get_velocity_z_squared(const int id, const int surf_offset)
bool hasHeatSourceKernel()
int scalarSlot(const int id)
double L_ref
Definition: NekInterface.h:724
bool isInitialized()
double referenceLength()
Definition: CardinalEnums.h:151
double volume(const nek_mesh::NekMeshEnum pp_mesh)
void limitTemperature(const double *min_T, const double *max_T)
bool hasBlendingSolver()
double get_scalar03(const int id, const int surf_offset)
double sideIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
std::vector< dfloat > & host_P()
const std::string temperatureBoundaryType(const int boundary)
int dim()
double ds02_ref
Definition: NekInterface.h:735
double pressureSurfaceForce(const std::vector< int > &boundary_id, const Point &direction, const nek_mesh::NekMeshEnum pp_mesh)
bool endControlTime()
void write_field_file(const std::string &prefix, const dfloat time, const int &step)
double get_velocity_y(const int id, const int surf_offset)
double flux_ref
Definition: NekInterface.h:729
dfloat * host_z()
bool hasTemperatureVariable()
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:961
Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id)
int commSize()
bool isHeatFluxBoundary(const int boundary)
void initializeNekHostArrays()
std::vector< dfloat > viscousDrag(const std::vector< int > &boundary)
double get_unity(const int id, const int surf_offset)
double area(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
double get_usrwrk02(const int id, const int surf_offset)
int NboundaryID()
void write_usrwrk_field_file(const int &size, const int &index, const int &slot, const std::string &prefix, const dfloat &time, const int &step, const bool &write_coords)
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:731
double Cp_ref
Definition: NekInterface.h:728
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:95
double getNekSetupTime()
void copyDeviceToHost()
double s01_ref
Definition: NekInterface.h:732
void buildOnly(int buildOnly)
double ds01_ref
Definition: NekInterface.h:733
void updateHostMeshParameters()
Update the mesh parameters on host.
int fieldOffset()
Real scratchUnits(const int slot)
void freeScratch()
Free the scratch space.
Real nondimensionalDivisor(const field::NekFieldEnum &field)
Return the reference divisor scale that defines the non-dimensional field.
void dimensionalizeVolumeIntegral(const field::NekFieldEnum &integrand, const Real &volume, double &integral)
double s02_ref
Definition: NekInterface.h:734
bool hasMovingMesh()
void checkFieldValidity(const field::NekFieldEnum &field)
double heatFluxIntegral(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
mesh_t * createMesh2(mesh_t *_mesh, int Nc)
double get_pressure(const int id, const int surf_offset)
void interpolationMatrix(double *I, int starting_points, int ending_points)
int NboundaryFaces()
void initializeHostMeshParameters()
Allocate memory for the host mesh parameters.
double U_ref
Definition: NekInterface.h:720
void setNekSetupTime(const double &time)
void setAbsoluteTol(double tol)
bool validBoundaryIDs(const std::vector< int > &boundary_id, int &first_invalid_id, int &n_boundaries)
double get_temperature(const int id, const int surf_offset)
double s03_ref
Definition: NekInterface.h:736
void nondimensional(const bool n)
void computeWallDistance(const std::vector< int > &boundary_id)
bool endControlElapsedTime()
double get_usrwrk00(const int id, const int surf_offset)
mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh)
dfloat * getVgeo()
double rho_ref
Definition: NekInterface.h:727
bool hasScalarVariable(int scalarId)
Definition: CardinalEnums.h:130
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:722
double usrwrkVolumeIntegral(const unsigned int &slot, const nek_mesh::NekMeshEnum pp_mesh)
std::vector< dfloat > yPlus(const std::vector< int > &boundary_id)
double get_scalar02(const int id, const int surf_offset)
int scalarFieldOffset()
Point centroid(int local_elem_id)
double get_velocity_z(const int id, const int surf_offset)
void interpolateVolumeHex3D(const double *I, double *x, int N, double *Ix, int M)
void gradient(const int offset, const int e, const double *f, double *grad_f, const nek_mesh::NekMeshEnum pp_mesh)
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)
double get_velocity_y_squared(const int id, const int surf_offset)