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 #include "Function.h"
26 
27 #include "inipp.hpp"
28 #include "nekrs.hpp"
29 #include "nrs.hpp"
30 #include "udf.hpp"
31 #include "inipp.hpp"
32 #include "mesh.h"
33 
34 #include "libmesh/point.h"
35 
36 #include <string>
37 #include <vector>
38 
46 namespace nekrs
47 {
48 
49 static int build_only;
50 
55 int Nscalar();
56 
59 
62 
63 dfloat * host_x();
64 dfloat * host_y();
65 dfloat * host_z();
66 
67 nrs_t * nrsPtr();
68 
69 dfloat * getSgeo();
70 dfloat * getVgeo();
71 
79 
80 void copyDeviceToHost();
81 
86 void computeWallDistance(const std::vector<int> & boundary_id);
87 
93 std::vector<dfloat> yPlus(const std::vector<int> & boundary_id);
94 
100 std::vector<dfloat> viscousDrag(const std::vector<int> & boundary);
101 
106 void setAbsoluteTol(double tol);
107 
114 Real scratchUnits(const int slot);
115 
120 void nondimensional(const bool n);
121 
126 void setRelativeTol(double tol);
127 
135 void setNekSetupTime(const double & time);
136 
141 double getNekSetupTime();
142 
147 void setStartTime(const double & start);
148 
153 bool isInitialized();
154 
164 void write_usrwrk_field_file(const int & size,
165  const int & index,
166  const int & slot,
167  const std::string & prefix,
168  const dfloat & time,
169  const int & step,
170  const bool & write_coords);
171 
178 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
179 
186 void buildOnly(int buildOnly);
187 
192 int buildOnly();
193 
197 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
198 
203 bool hasCHT();
204 
209 bool hasMovingMesh();
210 
215 bool hasVariableDt();
216 
221 bool hasBlendingSolver();
222 
227 bool hasUserMeshSolver();
228 
233 bool endControlElapsedTime();
234 
239 bool endControlTime();
240 
245 bool endControlNumSteps();
246 
253 int scalarFieldOffset();
254 
259 int velocityFieldOffset();
260 
265 int fieldOffset();
266 
273 mesh_t * entireMesh();
274 
279 mesh_t * flowMesh();
280 
285 mesh_t * temperatureMesh();
286 
292 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
293 
298 int commRank();
299 
304 int commSize();
305 
311 
316 bool hasTemperatureSolve();
317 
323 bool hasScalarVariable(int scalarId);
324 
329 bool hasHeatSourceKernel();
330 
335 bool scratchAvailable();
336 
341 void initializeScratch(const unsigned int & n_slots);
342 
344 void freeScratch();
345 
351 double viscosity();
352 
358 double Pr();
359 
362 
363 template <typename T>
364 void allgatherv(const std::vector<int> & base_counts,
365  const T * input,
366  T * output,
367  const int multiplier = 1);
368 
376 void displacementAndCounts(const std::vector<int> & base_counts,
377  int * counts,
378  int * displacement,
379  const int multiplier);
380 
388 void interpolationMatrix(double * I, int starting_points, int ending_points);
389 
400  double * scratch, const double * I, double * x, int N, double * Ix, int M);
401 
409 Point centroidFace(int local_elem_id, int local_face_id);
410 
416 Point centroid(int local_elem_id);
417 
424 Point gllPoint(int local_elem_id, int local_node_id);
425 
434 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
435 
443 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
444  const std::vector<int> & boundary,
445  const nek_mesh::NekMeshEnum pp_mesh);
446 
453 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
454 
460 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
461 
468 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
469 
477 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
478  const nek_mesh::NekMeshEnum pp_mesh);
479 
485 double volume(const nek_mesh::NekMeshEnum pp_mesh);
486 
491 void dimensionalizeVolume(double & integral);
492 
497 void dimensionalizeArea(double & integral);
498 
506  const Real & volume,
507  double & integral);
508 
515 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
516  const Real & area,
517  double & integral);
518 
526 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
527  const std::vector<int> & boundary_id,
528  double & integral,
529  const nek_mesh::NekMeshEnum pp_mesh);
530 
540 double functionVolumeIntegral(const field::NekFieldEnum & integrand,
541  const double & volume,
542  const nek_mesh::NekMeshEnum pp_mesh,
543  const Function * function,
544  const Real & time);
545 
555 double volumeIntegral(const field::NekFieldEnum & integrand,
556  const double & volume,
557  const nek_mesh::NekMeshEnum pp_mesh,
558  const Function * function,
559  const Real & time);
560 
569 double evaluateFunctionOnMesh(const Function * f, const Real time, const int id);
570 
580 double volumeNorm(const field::NekFieldEnum & integrand,
581  const nek_mesh::NekMeshEnum pp_mesh,
582  const Function * function,
583  const Real & time,
584  const Real & N);
585 
592 double massFlowrate(const std::vector<int> & boundary_id,
593  const nek_mesh::NekMeshEnum pp_mesh);
594 
602 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
603  const field::NekFieldEnum & integrand,
604  const nek_mesh::NekMeshEnum pp_mesh);
605 
615 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
616 
623 double heatFluxIntegral(const std::vector<int> & boundary_id,
624  const nek_mesh::NekMeshEnum pp_mesh);
625 
631 void limitTemperature(const double * min_T, const double * max_T);
632 
641 void gradient(const int offset,
642  const int e,
643  const double * f,
644  double * grad_f,
645  const nek_mesh::NekMeshEnum pp_mesh);
646 
657  const nek_mesh::NekMeshEnum pp_mesh,
658  const Function * function,
659  const Real & time,
660  const bool max);
661 
670 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
671  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
672 
677 int Nfaces();
678 
684 bool isHeatFluxBoundary(const int boundary);
685 
691 bool isMovingMeshBoundary(const int boundary);
692 
698 bool isTemperatureBoundary(const int boundary);
699 
705 const std::string temperatureBoundaryType(const int boundary);
706 
711 int polynomialOrder();
712 
717 int Nelements();
718 
723 int dim();
724 
732 int NfaceVertices();
733 
738 int NboundaryFaces();
739 
744 int NboundaryID();
745 
753 bool
754 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
755 
761 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
762 
768 {
769  double U_ref = 1;
770  double T_ref = 0;
771  double dT_ref = 1;
772  double P_ref = 1;
773  double L_ref = 1;
774  double A_ref = 1;
775  double V_ref = 1;
776  double rho_ref = 1;
777  double Cp_ref = 1;
778  double flux_ref = 1;
779  double source_ref = 1;
780  double t_ref = 1;
781  double s01_ref = 0;
782  double ds01_ref = 1;
783  double s02_ref = 0;
784  double ds02_ref = 1;
785  double s03_ref = 0;
786  double ds03_ref = 1;
787 };
788 
794 double (*solutionPointer(const field::NekFieldEnum & field))(int, int);
795 double (*solutionPointer(const field::NekWriteEnum & field))(int, int);
796 
802 int scalarSlot(const int id);
803 
809 double get_scalar01(const int id, const int surf_offset);
810 
816 double get_scalar02(const int id, const int surf_offset);
817 
823 double get_scalar03(const int id, const int surf_offset);
824 
830 double get_usrwrk00(const int id, const int surf_offset);
831 
837 double get_usrwrk01(const int id, const int surf_offset);
838 
844 double get_usrwrk02(const int id, const int surf_offset);
845 
851 double get_temperature(const int id, const int surf_offset);
852 
858 double get_pressure(const int id, const int surf_offset);
859 
865 double get_zero(const int id, const int surf_offset);
866 
872 double get_unity(const int id, const int surf_offset);
873 
879 double get_velocity_x(const int id, const int surf_offset);
880 
886 double get_velocity_y(const int id, const int surf_offset);
887 
893 double get_velocity_z(const int id, const int surf_offset);
894 
900 double get_velocity(const int id, const int surf_offset);
901 
907 double get_velocity_x_squared(const int id, const int surf_offset);
908 
914 double get_velocity_y_squared(const int id, const int surf_offset);
915 
921 double get_velocity_z_squared(const int id, const int surf_offset);
922 
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 
965 
979 
984 double referenceLength();
985 
990 double referenceTime();
991 
996 double referenceArea();
997 
1002 double referenceVolume();
1003 
1004 // useful concept from Stack Overflow for templating MPI calls
1005 template <typename T>
1006 MPI_Datatype resolveType();
1007 
1015 template <typename T>
1016 void
1017 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
1018 {
1019  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
1020  int * displacement = (int *)calloc(commSize(), sizeof(int));
1021  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
1022 
1023  MPI_Allgatherv(input,
1024  recvCounts[commRank()],
1025  resolveType<T>(),
1026  output,
1027  (const int *)recvCounts,
1028  (const int *)displacement,
1029  resolveType<T>(),
1030  platform->comm.mpiComm());
1031 
1032  free(recvCounts);
1033  free(displacement);
1034 }
1035 
1037 
1038 // Accessors for NekRS host arrays
1039 std::tuple<dfloat *, dfloat *, dfloat *> host_xyz();
1040 std::vector<dfloat> & host_U();
1041 std::vector<dfloat> & host_P();
1042 std::vector<dfloat> & host_S();
1043 dfloat * host_wrk();
1044 
1045 mesh_t * createMesh2(mesh_t * _mesh, int Nc);
1046 
1047 } // 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:767
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:786
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 volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh, const Function *function, const Real &time)
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:118
double volumeNorm(const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh, const Function *function, const Real &time, const Real &N)
double P_ref
Definition: NekInterface.h:772
double get_velocity_x_squared(const int id, const int surf_offset)
double A_ref
Definition: NekInterface.h:774
int polynomialOrder()
void dimensionalizeVolume(double &integral)
Point centroidFace(int local_elem_id, int local_face_id)
double evaluateFunctionOnMesh(const Function *f, const Real time, const int id)
double V_ref
Definition: NekInterface.h:775
bool isMovingMeshBoundary(const int boundary)
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)
double get_zero(const int id, const int surf_offset)
dfloat * host_x()
int Nfaces()
double source_ref
Definition: NekInterface.h:779
Definition: CardinalEnums.h:92
double T_ref
Definition: NekInterface.h:770
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:794
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:773
bool isInitialized()
double referenceLength()
Definition: CardinalEnums.h:152
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:784
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:778
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:1017
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)
double functionVolumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh, const Function *function, const Real &time)
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:780
double Cp_ref
Definition: NekInterface.h:777
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:95
double getNekSetupTime()
void copyDeviceToHost()
double s01_ref
Definition: NekInterface.h:781
void buildOnly(int buildOnly)
double ds01_ref
Definition: NekInterface.h:782
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:783
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:769
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:785
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:776
bool hasScalarVariable(int scalarId)
Definition: CardinalEnums.h:131
double volumeExtremeValue(const field::NekFieldEnum &field, const nek_mesh::NekMeshEnum pp_mesh, const Function *function, const Real &time, const bool max)
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:771
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)