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 "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 
99 void setNekSetupTime(const double & time);
100 
105 double getNekSetupTime();
106 
111 void setStartTime(const double & start);
112 
117 bool isInitialized();
118 
128 void write_usrwrk_field_file(const int & slot, const std::string & prefix, const dfloat & time, const int & step, const bool & write_coords);
129 
136 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
137 
144 void buildOnly(int buildOnly);
145 
150 int buildOnly();
151 
155 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
156 
161 bool hasCHT();
162 
167 bool hasMovingMesh();
168 
173 bool hasVariableDt();
174 
179 bool hasBlendingSolver();
180 
185 bool hasUserMeshSolver();
186 
191 bool endControlElapsedTime();
192 
197 bool endControlTime();
198 
203 bool endControlNumSteps();
204 
211 int scalarFieldOffset();
212 
217 int velocityFieldOffset();
218 
223 int fieldOffset();
224 
231 mesh_t * entireMesh();
232 
237 mesh_t * flowMesh();
238 
243 mesh_t * temperatureMesh();
244 
250 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
251 
256 int commRank();
257 
262 int commSize();
263 
269 
274 bool hasTemperatureSolve();
275 
281 bool hasScalarVariable(int scalarId);
282 
287 bool hasHeatSourceKernel();
288 
293 bool scratchAvailable();
294 
299 void initializeScratch(const unsigned int & n_slots);
300 
302 void freeScratch();
303 
309 double viscosity();
310 
316 double Pr();
317 
320 
321 template <typename T>
322 void allgatherv(const std::vector<int> & base_counts,
323  const T * input,
324  T * output,
325  const int multiplier = 1);
326 
334 void displacementAndCounts(const std::vector<int> & base_counts,
335  int * counts,
336  int * displacement,
337  const int multiplier);
338 
346 void interpolationMatrix(double * I, int starting_points, int ending_points);
347 
358  double * scratch, const double * I, double * x, int N, double * Ix, int M);
359 
367 Point centroidFace(int local_elem_id, int local_face_id);
368 
374 Point centroid(int local_elem_id);
375 
382 Point gllPoint(int local_elem_id, int local_node_id);
383 
392 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
393 
401 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
402  const std::vector<int> & boundary,
403  const nek_mesh::NekMeshEnum pp_mesh);
404 
411 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
412 
418 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
419 
426 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
427 
435 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
436  const nek_mesh::NekMeshEnum pp_mesh);
437 
443 double volume(const nek_mesh::NekMeshEnum pp_mesh);
444 
449 void dimensionalizeVolume(double & integral);
450 
455 void dimensionalizeArea(double & integral);
456 
464  const Real & volume,
465  double & integral);
466 
473 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
474  const Real & area,
475  double & integral);
476 
484 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
485  const std::vector<int> & boundary_id,
486  double & integral,
487  const nek_mesh::NekMeshEnum pp_mesh);
488 
496 double volumeIntegral(const field::NekFieldEnum & integrand,
497  const double & volume,
498  const nek_mesh::NekMeshEnum pp_mesh);
499 
506 double massFlowrate(const std::vector<int> & boundary_id,
507  const nek_mesh::NekMeshEnum pp_mesh);
508 
516 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
517  const field::NekFieldEnum & integrand,
518  const nek_mesh::NekMeshEnum pp_mesh);
519 
529 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
530 
537 double heatFluxIntegral(const std::vector<int> & boundary_id,
538  const nek_mesh::NekMeshEnum pp_mesh);
539 
545 void limitTemperature(const double * min_T, const double * max_T);
546 
555 void gradient(const int offset,
556  const int e,
557  const double * f,
558  double * grad_f,
559  const nek_mesh::NekMeshEnum pp_mesh);
560 
569  const nek_mesh::NekMeshEnum pp_mesh,
570  const bool max);
571 
580 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
581  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
582 
587 int Nfaces();
588 
594 bool isHeatFluxBoundary(const int boundary);
595 
601 bool isMovingMeshBoundary(const int boundary);
602 
608 bool isTemperatureBoundary(const int boundary);
609 
615 const std::string temperatureBoundaryType(const int boundary);
616 
621 int polynomialOrder();
622 
627 int Nelements();
628 
633 int dim();
634 
642 int NfaceVertices();
643 
648 int NboundaryFaces();
649 
654 int NboundaryID();
655 
663 bool
664 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
665 
671 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
672 
678 {
680  int flux = -1;
681 
683  int heat_source = -1;
684 
686  int mesh_velocity_x = -1;
687 
689  int mesh_velocity_y = -1;
690 
692  int mesh_velocity_z = -1;
693 
695  int temperature = -1;
696 };
697 
703 {
704  double U_ref = 1;
705  double T_ref = 0;
706  double dT_ref = 1;
707  double P_ref = 1;
708  double L_ref = 1;
709  double A_ref = 1;
710  double V_ref = 1;
711  double rho_ref = 1;
712  double Cp_ref = 1;
713  double flux_ref = 1;
714  double source_ref = 1;
715  double t_ref = 1;
716  double s01_ref = 0;
717  double ds01_ref = 1;
718  double s02_ref = 0;
719  double ds02_ref = 1;
720  double s03_ref = 0;
721  double ds03_ref = 1;
722 };
723 
729 double (*solutionPointer(const field::NekFieldEnum & field))(int, int);
730 double (*solutionPointer(const field::NekWriteEnum & field))(int, int);
731 
736 void (*solutionWritePointer(const field::NekWriteEnum & field))(int, dfloat);
737 void (*solutionWritePointer(const field::NekFieldEnum & field))(int, dfloat);
738 
744 double get_scalar01(const int id, const int surf_offset);
745 
751 double get_scalar02(const int id, const int surf_offset);
752 
758 double get_scalar03(const int id, const int surf_offset);
759 
765 double get_usrwrk00(const int id, const int surf_offset);
766 
772 double get_usrwrk01(const int id, const int surf_offset);
773 
779 double get_usrwrk02(const int id, const int surf_offset);
780 
786 double get_temperature(const int id, const int surf_offset);
787 
793 double get_pressure(const int id, const int surf_offset);
794 
800 double get_unity(const int id, const int surf_offset);
801 
807 double get_velocity_x(const int id, const int surf_offset);
808 
814 double get_velocity_y(const int id, const int surf_offset);
815 
821 double get_velocity_z(const int id, const int surf_offset);
822 
828 double get_velocity(const int id, const int surf_offset);
829 
835 double get_velocity_x_squared(const int id, const int surf_offset);
836 
842 double get_velocity_y_squared(const int id, const int surf_offset);
843 
849 double get_velocity_z_squared(const int id, const int surf_offset);
850 
856 void set_temperature(const int id, const dfloat value);
857 
863 void set_flux(const int id, const dfloat value);
864 
870 void set_heat_source(const int id, const dfloat value);
871 
877 void set_x_displacement(const int id, const dfloat value);
878 
884 void set_y_displacement(const int id, const dfloat value);
885 
891 void set_z_displacement(const int id, const dfloat value);
892 
908 void initializeDimensionalScales(const double U,
909  const double T,
910  const double dT,
911  const double L,
912  const double rho,
913  const double Cp,
914  const double s01,
915  const double ds01,
916  const double s02,
917  const double ds02,
918  const double s03,
919  const double ds03);
920 
935 
949 
954 double referenceLength();
955 
960 double referenceTime();
961 
966 double referenceArea();
967 
972 double referenceVolume();
973 
974 // useful concept from Stack Overflow for templating MPI calls
975 template <typename T>
976 MPI_Datatype resolveType();
977 
985 template <typename T>
986 void
987 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
988 {
989  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
990  int * displacement = (int *)calloc(commSize(), sizeof(int));
991  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
992 
993  MPI_Allgatherv(input,
994  recvCounts[commRank()],
995  resolveType<T>(),
996  output,
997  (const int *)recvCounts,
998  (const int *)displacement,
999  resolveType<T>(),
1000  platform->comm.mpiComm);
1001 
1002  free(recvCounts);
1003  free(displacement);
1004 }
1005 
1006 } // end namespace nekrs
Cardinal-specific nekRS API.
Definition: NekUility.C:21
void set_heat_source(const int id, const dfloat value)
MPI_Datatype resolveType()
void setStartTime(const double &start)
int mesh_velocity_z
z-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:692
Definition: NekInterface.h:702
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:721
void storeBoundaryCoupling(const std::vector< int > &boundary_id, int &N)
void(*)(int, dfloat) solutionWritePointer(const field::NekWriteEnum &field)
Definition: NekInterface.h:736
double Pr()
double referenceVolume()
double get_scalar01(const int id, const int surf_offset)
bool hasCHT()
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:116
double P_ref
Definition: NekInterface.h:707
double get_velocity_x_squared(const int id, const int surf_offset)
double A_ref
Definition: NekInterface.h:709
int polynomialOrder()
void dimensionalizeVolume(double &integral)
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)
void set_temperature(const int id, const dfloat value)
double V_ref
Definition: NekInterface.h:710
bool isMovingMeshBoundary(const int boundary)
void set_y_displacement(const int id, const dfloat value)
double volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh)
int commRank()
int heat_source
volumetric heat source (for volumetric heating)
Definition: NekInterface.h:683
double viscosity()
bool hasUserMeshSolver()
void displacementAndCounts(const std::vector< int > &base_counts, int *counts, int *displacement, const int multiplier)
int Nelements()
double get_velocity_x(const int id, const int surf_offset)
int Nfaces()
double source_ref
Definition: NekInterface.h:714
Definition: CardinalEnums.h:91
double T_ref
Definition: NekInterface.h:705
bool isTemperatureBoundary(const int boundary)
Real nondimensionalAdditive(const field::NekFieldEnum &field)
double(*)(int, int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:729
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)
int mesh_velocity_x
x-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:686
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)
void scaleUsrwrk(const unsigned int &slot, const dfloat &value)
double get_velocity_z_squared(const int id, const int surf_offset)
bool hasHeatSourceKernel()
int temperature
temperature (for reverse-direction conjugate heat transfer coupling)
Definition: NekInterface.h:695
double L_ref
Definition: NekInterface.h:708
bool isInitialized()
double referenceLength()
Definition: CardinalEnums.h:150
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)
const std::string temperatureBoundaryType(const int boundary)
int dim()
double ds02_ref
Definition: NekInterface.h:719
void set_z_displacement(const int id, const dfloat value)
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:713
bool hasTemperatureVariable()
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:987
Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id)
int commSize()
bool isHeatFluxBoundary(const 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()
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:715
double Cp_ref
Definition: NekInterface.h:712
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:94
double getNekSetupTime()
Definition: NekInterface.h:677
double s01_ref
Definition: NekInterface.h:716
void buildOnly(int buildOnly)
double ds01_ref
Definition: NekInterface.h:717
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:718
bool hasMovingMesh()
void checkFieldValidity(const field::NekFieldEnum &field)
double heatFluxIntegral(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
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:704
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)
int flux
boundary heat flux (for conjugate heat transfer)
Definition: NekInterface.h:680
double s03_ref
Definition: NekInterface.h:720
void nondimensional(const bool n)
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:711
void set_flux(const int id, const dfloat value)
bool hasScalarVariable(int scalarId)
Definition: CardinalEnums.h:129
void set_x_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:706
double usrwrkVolumeIntegral(const unsigned int &slot, const nek_mesh::NekMeshEnum pp_mesh)
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)
int mesh_velocity_y
y-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:689
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)