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 
63 void setAbsoluteTol(double tol);
64 
69 void setRelativeTol(double tol);
70 
78 void setNekSetupTime(const double & time);
79 
84 double getNekSetupTime();
85 
90 void setStartTime(const double & start);
91 
96 bool isInitialized();
97 
107 void write_usrwrk_field_file(const int & slot, const std::string & prefix, const dfloat & time, const int & step, const bool & write_coords);
108 
115 void write_field_file(const std::string & prefix, const dfloat time, const int & step);
116 
123 void buildOnly(int buildOnly);
124 
129 int buildOnly();
130 
134 void interpolateVolumeHex3D(const double * I, double * x, int N, double * Ix, int M);
135 
140 bool hasCHT();
141 
146 bool hasMovingMesh();
147 
152 bool hasVariableDt();
153 
158 bool hasBlendingSolver();
159 
164 bool hasUserMeshSolver();
165 
170 bool endControlElapsedTime();
171 
176 bool endControlTime();
177 
182 bool endControlNumSteps();
183 
190 int scalarFieldOffset();
191 
196 int velocityFieldOffset();
197 
204 mesh_t * entireMesh();
205 
210 mesh_t * flowMesh();
211 
216 mesh_t * temperatureMesh();
217 
223 mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh);
224 
229 int commRank();
230 
235 int commSize();
236 
242 
247 bool hasTemperatureSolve();
248 
254 bool hasScalarVariable(int scalarId);
255 
260 bool hasHeatSourceKernel();
261 
266 bool scratchAvailable();
267 
272 void initializeScratch(const unsigned int & n_slots);
273 
275 void freeScratch();
276 
282 double viscosity();
283 
289 double Pr();
290 
293 
294 template <typename T>
295 void allgatherv(const std::vector<int> & base_counts,
296  const T * input,
297  T * output,
298  const int multiplier = 1);
299 
307 void displacementAndCounts(const std::vector<int> & base_counts,
308  int * counts,
309  int * displacement,
310  const int multiplier);
311 
319 void interpolationMatrix(double * I, int starting_points, int ending_points);
320 
331  double * scratch, const double * I, double * x, int N, double * Ix, int M);
332 
340 Point centroidFace(int local_elem_id, int local_face_id);
341 
347 Point centroid(int local_elem_id);
348 
355 Point gllPoint(int local_elem_id, int local_node_id);
356 
365 Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id);
366 
374 std::vector<double> usrwrkSideIntegral(const unsigned int & slot,
375  const std::vector<int> & boundary,
376  const nek_mesh::NekMeshEnum pp_mesh);
377 
384 double usrwrkVolumeIntegral(const unsigned int & slot, const nek_mesh::NekMeshEnum pp_mesh);
385 
391 void scaleUsrwrk(const unsigned int & slot, const dfloat & value);
392 
402 bool normalizeFluxBySideset(const NekBoundaryCoupling & nek_boundary_coupling,
403  const std::vector<int> & boundary,
404  const std::vector<double> & moose_integral,
405  std::vector<double> & nek_integral,
406  double & normalized_nek_integral);
407 
417 bool normalizeFlux(const NekBoundaryCoupling & nek_boundary_coupling,
418  const std::vector<int> & boundary,
419  const double moose_integral,
420  double nek_integral,
421  double & normalized_nek_integral);
422 
429 double area(const std::vector<int> & boundary_id, const nek_mesh::NekMeshEnum pp_mesh);
430 
438 double sideIntegral(const std::vector<int> & boundary_id, const field::NekFieldEnum & integrand,
439  const nek_mesh::NekMeshEnum pp_mesh);
440 
446 double volume(const nek_mesh::NekMeshEnum pp_mesh);
447 
452 void dimensionalizeVolume(double & integral);
453 
458 void dimensionalizeArea(double & integral);
459 
467  const Real & volume,
468  double & integral);
469 
476 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
477  const Real & area,
478  double & integral);
479 
487 void dimensionalizeSideIntegral(const field::NekFieldEnum & integrand,
488  const std::vector<int> & boundary_id,
489  double & integral,
490  const nek_mesh::NekMeshEnum pp_mesh);
491 
499 double volumeIntegral(const field::NekFieldEnum & integrand,
500  const double & volume,
501  const nek_mesh::NekMeshEnum pp_mesh);
502 
509 double massFlowrate(const std::vector<int> & boundary_id,
510  const nek_mesh::NekMeshEnum pp_mesh);
511 
519 double sideMassFluxWeightedIntegral(const std::vector<int> & boundary_id,
520  const field::NekFieldEnum & integrand,
521  const nek_mesh::NekMeshEnum pp_mesh);
522 
532 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
533 
540 double heatFluxIntegral(const std::vector<int> & boundary_id,
541  const nek_mesh::NekMeshEnum pp_mesh);
542 
548 void limitTemperature(const double * min_T, const double * max_T);
549 
557 void gradient(const int offset, const double * f, double * grad_f,
558  const nek_mesh::NekMeshEnum pp_mesh);
559 
568  const nek_mesh::NekMeshEnum pp_mesh,
569  const bool max);
570 
579 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
580  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
581 
586 int Nfaces();
587 
593 bool isHeatFluxBoundary(const int boundary);
594 
600 bool isMovingMeshBoundary(const int boundary);
601 
607 bool isTemperatureBoundary(const int boundary);
608 
614 const std::string temperatureBoundaryType(const int boundary);
615 
620 int polynomialOrder();
621 
626 int Nelements();
627 
632 int dim();
633 
641 int NfaceVertices();
642 
647 int NboundaryFaces();
648 
653 int NboundaryID();
654 
662 bool
663 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
664 
670 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
671 
677 {
679  int flux;
680 
683 
686 
689 
692 
695 
698 
701 
704 
707 };
708 
711 {
712  double U_ref;
713 
714  double T_ref;
715 
716  double dT_ref;
717 
718  double L_ref;
719 
720  double A_ref;
721 
722  double V_ref;
723 
724  double rho_ref;
725 
726  double Cp_ref;
727 
728  double flux_ref;
729 
730  double source_ref;
731 
733 };
734 
740 double (*solutionPointer(const field::NekFieldEnum & field))(int);
741 
746 void (*solutionPointer(const field::NekWriteEnum & field))(int, dfloat);
747 
754 double scalar01(const int id);
755 
762 double scalar02(const int id);
763 
770 double scalar03(const int id);
771 
781 double temperature(const int id);
782 
788 double pressure(const int id);
789 
795 double unity(const int id);
796 
802 double velocity_x(const int id);
803 
809 double velocity_y(const int id);
810 
816 double velocity_z(const int id);
817 
823 double velocity(const int id);
824 
830 void flux(const int id, const dfloat value);
831 
837 void heat_source(const int id, const dfloat value);
838 
844 void x_displacement(const int id, const dfloat value);
845 
851 void y_displacement(const int id, const dfloat value);
852 
858 void z_displacement(const int id, const dfloat value);
859 
869 void initializeDimensionalScales(const double U_ref,
870  const double T_ref,
871  const double dT_ref,
872  const double L_ref,
873  const double rho_ref,
874  const double Cp_ref);
875 
889 void dimensionalize(const field::NekFieldEnum & field, double & value);
890 
895 double referenceFlux();
896 
901 double referenceSource();
902 
907 double referenceLength();
908 
913 double referenceArea();
914 
919 double referenceVolume();
920 
921 // useful concept from Stack Overflow for templating MPI calls
922 template <typename T>
923 MPI_Datatype resolveType();
924 
932 template <typename T>
933 void
934 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
935 {
936  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
937  int * displacement = (int *)calloc(commSize(), sizeof(int));
938  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
939 
940  MPI_Allgatherv(input,
941  recvCounts[commRank()],
942  resolveType<T>(),
943  output,
944  (const int *)recvCounts,
945  (const int *)displacement,
946  resolveType<T>(),
947  platform->comm.mpiComm);
948 
949  free(recvCounts);
950  free(displacement);
951 }
952 
953 } // 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)
int mesh_velocity_z
z-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:691
Characteristic scales assumed in nekRS if using a non-dimensional solution.
Definition: NekInterface.h:710
double sideMassFluxWeightedIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
bool endControlNumSteps()
double referenceArea()
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:105
double A_ref
Definition: NekInterface.h:720
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:697
double V_ref
Definition: NekInterface.h:722
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:682
double viscosity()
bool nondimensional_T
Definition: NekInterface.h:732
bool hasUserMeshSolver()
void displacementAndCounts(const std::vector< int > &base_counts, int *counts, int *displacement, const int multiplier)
int Nelements()
double scalar03(const int id)
Get the scalar03 solution at given GLL index.
double pressure(const int id)
void heat_source(const int id, const dfloat value)
int Nfaces()
double source_ref
Definition: NekInterface.h:730
Definition: CardinalEnums.h:86
double T_ref
Definition: NekInterface.h:714
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:685
bool hasTemperatureSolve()
NekMeshEnum
Definition: CardinalEnums.h:45
int boundary_scalar03
boundary scalar03 (for separate domain coupling)
Definition: NekInterface.h:706
void scaleUsrwrk(const unsigned int &slot, const dfloat &value)
bool hasHeatSourceKernel()
int boundary_velocity
boundary velocity (for separate domain coupling)
Definition: NekInterface.h:694
bool normalizeFlux(const NekBoundaryCoupling &nek_boundary_coupling, const std::vector< int > &boundary, const double moose_integral, double nek_integral, double &normalized_nek_integral)
void initializeDimensionalScales(const double U_ref, const double T_ref, const double dT_ref, const double L_ref, const double rho_ref, const double Cp_ref)
double L_ref
Definition: NekInterface.h:718
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:123
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:700
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)
Get the scalar02 solution at given GLL index.
const std::string temperatureBoundaryType(const int boundary)
int dim()
double(*)(int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:740
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 flux_ref
Definition: NekInterface.h:728
bool hasTemperatureVariable()
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:934
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()
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 Cp_ref
Definition: NekInterface.h:726
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:89
double getNekSetupTime()
Definition: NekInterface.h:676
double temperature(const int id)
Get the temperature solution at given GLL index.
Definition: NekBoundaryCoupling.h:29
void buildOnly(int buildOnly)
void updateHostMeshParameters()
Update the mesh parameters on host.
void freeScratch()
Free the scratch space.
void dimensionalizeVolumeIntegral(const field::NekFieldEnum &integrand, const Real &volume, double &integral)
bool hasMovingMesh()
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)
Get the scalar01 solution at given GLL index.
double U_ref
Definition: NekInterface.h:712
double velocity_y(const int id)
void setNekSetupTime(const double &time)
int boundary_scalar02
boundary scalar02 (for separate domain coupling)
Definition: NekInterface.h:703
void setAbsoluteTol(double tol)
bool validBoundaryIDs(const std::vector< int > &boundary_id, int &first_invalid_id, int &n_boundaries)
int flux
boundary heat flux (for conjugate heat transfer)
Definition: NekInterface.h:679
double referenceSource()
void x_displacement(const int id, const dfloat value)
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:724
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:716
double usrwrkVolumeIntegral(const unsigned int &slot, const nek_mesh::NekMeshEnum pp_mesh)
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:688
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)