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 
66 
73 std::vector<dfloat> yPlus(const std::vector<int> & boundary_id, const unsigned int & index);
74 
80 std::vector<dfloat> viscousDrag(const std::vector<int> & boundary);
81 
86 void setAbsoluteTol(double tol);
87 
94 Real scratchUnits(const int slot);
95 
100 void nondimensional(const bool n);
101 
106 void setRelativeTol(double tol);
107 
115 void setNekSetupTime(const double & time);
116 
121 double getNekSetupTime();
122 
127 void setStartTime(const double & start);
128 
133 bool isInitialized();
134 
144 void write_usrwrk_field_file(const int & slot, const std::string & prefix, const dfloat & time, const int & step, const bool & write_coords);
145 
152 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
153 
160 void buildOnly(int buildOnly);
161 
166 int buildOnly();
167 
171 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
172 
177 bool hasCHT();
178 
183 bool hasMovingMesh();
184 
189 bool hasVariableDt();
190 
195 bool hasBlendingSolver();
196 
201 bool hasUserMeshSolver();
202 
207 bool endControlElapsedTime();
208 
213 bool endControlTime();
214 
219 bool endControlNumSteps();
220 
227 int scalarFieldOffset();
228 
233 int velocityFieldOffset();
234 
239 int fieldOffset();
240 
247 mesh_t * entireMesh();
248 
253 mesh_t * flowMesh();
254 
259 mesh_t * temperatureMesh();
260 
266 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
267 
272 int commRank();
273 
278 int commSize();
279 
285 
290 bool hasTemperatureSolve();
291 
297 bool hasScalarVariable(int scalarId);
298 
303 bool hasHeatSourceKernel();
304 
309 bool scratchAvailable();
310 
315 void initializeScratch(const unsigned int & n_slots);
316 
318 void freeScratch();
319 
325 double viscosity();
326 
332 double Pr();
333 
336 
337 template <typename T>
338 void allgatherv(const std::vector<int> & base_counts,
339  const T * input,
340  T * output,
341  const int multiplier = 1);
342 
350 void displacementAndCounts(const std::vector<int> & base_counts,
351  int * counts,
352  int * displacement,
353  const int multiplier);
354 
362 void interpolationMatrix(double * I, int starting_points, int ending_points);
363 
374  double * scratch, const double * I, double * x, int N, double * Ix, int M);
375 
383 Point centroidFace(int local_elem_id, int local_face_id);
384 
390 Point centroid(int local_elem_id);
391 
398 Point gllPoint(int local_elem_id, int local_node_id);
399 
408 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
409 
417 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
418  const std::vector<int> & boundary,
419  const nek_mesh::NekMeshEnum pp_mesh);
420 
427 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
428 
434 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
435 
442 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
443 
451 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
452  const nek_mesh::NekMeshEnum pp_mesh);
453 
459 double volume(const nek_mesh::NekMeshEnum pp_mesh);
460 
465 void dimensionalizeVolume(double & integral);
466 
471 void dimensionalizeArea(double & integral);
472 
480  const Real & volume,
481  double & integral);
482 
489 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
490  const Real & area,
491  double & integral);
492 
500 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
501  const std::vector<int> & boundary_id,
502  double & integral,
503  const nek_mesh::NekMeshEnum pp_mesh);
504 
512 double volumeIntegral(const field::NekFieldEnum & integrand,
513  const double & volume,
514  const nek_mesh::NekMeshEnum pp_mesh);
515 
522 double massFlowrate(const std::vector<int> & boundary_id,
523  const nek_mesh::NekMeshEnum pp_mesh);
524 
532 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
533  const field::NekFieldEnum & integrand,
534  const nek_mesh::NekMeshEnum pp_mesh);
535 
545 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
546 
553 double heatFluxIntegral(const std::vector<int> & boundary_id,
554  const nek_mesh::NekMeshEnum pp_mesh);
555 
561 void limitTemperature(const double * min_T, const double * max_T);
562 
571 void gradient(const int offset,
572  const int e,
573  const double * f,
574  double * grad_f,
575  const nek_mesh::NekMeshEnum pp_mesh);
576 
585  const nek_mesh::NekMeshEnum pp_mesh,
586  const bool max);
587 
596 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
597  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
598 
603 int Nfaces();
604 
610 bool isHeatFluxBoundary(const int boundary);
611 
617 bool isMovingMeshBoundary(const int boundary);
618 
624 bool isTemperatureBoundary(const int boundary);
625 
631 const std::string temperatureBoundaryType(const int boundary);
632 
637 int polynomialOrder();
638 
643 int Nelements();
644 
649 int dim();
650 
658 int NfaceVertices();
659 
664 int NboundaryFaces();
665 
670 int NboundaryID();
671 
679 bool
680 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
681 
687 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
688 
694 {
695  double U_ref = 1;
696  double T_ref = 0;
697  double dT_ref = 1;
698  double P_ref = 1;
699  double L_ref = 1;
700  double A_ref = 1;
701  double V_ref = 1;
702  double rho_ref = 1;
703  double Cp_ref = 1;
704  double flux_ref = 1;
705  double source_ref = 1;
706  double t_ref = 1;
707  double s01_ref = 0;
708  double ds01_ref = 1;
709  double s02_ref = 0;
710  double ds02_ref = 1;
711  double s03_ref = 0;
712  double ds03_ref = 1;
713 };
714 
720 double (*solutionPointer(const field::NekFieldEnum & field))(int, int);
721 double (*solutionPointer(const field::NekWriteEnum & field))(int, int);
722 
728 double get_scalar01(const int id, const int surf_offset);
729 
735 double get_scalar02(const int id, const int surf_offset);
736 
742 double get_scalar03(const int id, const int surf_offset);
743 
749 double get_usrwrk00(const int id, const int surf_offset);
750 
756 double get_usrwrk01(const int id, const int surf_offset);
757 
763 double get_usrwrk02(const int id, const int surf_offset);
764 
770 double get_temperature(const int id, const int surf_offset);
771 
777 double get_pressure(const int id, const int surf_offset);
778 
784 double get_unity(const int id, const int surf_offset);
785 
791 double get_velocity_x(const int id, const int surf_offset);
792 
798 double get_velocity_y(const int id, const int surf_offset);
799 
805 double get_velocity_z(const int id, const int surf_offset);
806 
812 double get_velocity(const int id, const int surf_offset);
813 
819 double get_velocity_x_squared(const int id, const int surf_offset);
820 
826 double get_velocity_y_squared(const int id, const int surf_offset);
827 
833 double get_velocity_z_squared(const int id, const int surf_offset);
834 
850 void initializeDimensionalScales(const double U,
851  const double T,
852  const double dT,
853  const double L,
854  const double rho,
855  const double Cp,
856  const double s01,
857  const double ds01,
858  const double s02,
859  const double ds02,
860  const double s03,
861  const double ds03);
862 
877 
891 
896 double referenceLength();
897 
902 double referenceTime();
903 
908 double referenceArea();
909 
914 double referenceVolume();
915 
916 // useful concept from Stack Overflow for templating MPI calls
917 template <typename T>
918 MPI_Datatype resolveType();
919 
927 template <typename T>
928 void
929 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
930 {
931  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
932  int * displacement = (int *)calloc(commSize(), sizeof(int));
933  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
934 
935  MPI_Allgatherv(input,
936  recvCounts[commRank()],
937  resolveType<T>(),
938  output,
939  (const int *)recvCounts,
940  (const int *)displacement,
941  resolveType<T>(),
942  platform->comm.mpiComm);
943 
944  free(recvCounts);
945  free(displacement);
946 }
947 
948 } // end namespace nekrs
Cardinal-specific nekRS API.
Definition: NekUility.C:21
MPI_Datatype resolveType()
void setStartTime(const double &start)
Definition: NekInterface.h:693
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:712
void storeBoundaryCoupling(const std::vector< int > &boundary_id, int &N)
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:117
double P_ref
Definition: NekInterface.h:698
double get_velocity_x_squared(const int id, const int surf_offset)
double A_ref
Definition: NekInterface.h:700
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)
double V_ref
Definition: NekInterface.h:701
bool isMovingMeshBoundary(const int boundary)
double volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh)
int commRank()
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:705
Definition: CardinalEnums.h:92
double T_ref
Definition: NekInterface.h:696
bool isTemperatureBoundary(const int boundary)
Real nondimensionalAdditive(const field::NekFieldEnum &field)
double(*)(int, int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:720
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()
double L_ref
Definition: NekInterface.h:699
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)
const std::string temperatureBoundaryType(const int boundary)
int dim()
double ds02_ref
Definition: NekInterface.h:710
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:704
bool hasTemperatureVariable()
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:929
Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id)
int commSize()
bool isHeatFluxBoundary(const int boundary)
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()
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:706
double Cp_ref
Definition: NekInterface.h:703
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:95
double getNekSetupTime()
double s01_ref
Definition: NekInterface.h:707
void buildOnly(int buildOnly)
double ds01_ref
Definition: NekInterface.h:708
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:709
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:695
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:711
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:702
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)
std::vector< dfloat > yPlus(const std::vector< int > &boundary_id, const unsigned int &index)
double dT_ref
Definition: NekInterface.h:697
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)
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)