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 
531 double pressureSurfaceForce(const std::vector<int> & boundary_id, const Point & direction, const nek_mesh::NekMeshEnum pp_mesh);
532 
539 double heatFluxIntegral(const std::vector<int> & boundary_id,
540  const nek_mesh::NekMeshEnum pp_mesh);
541 
547 void limitTemperature(const double * min_T, const double * max_T);
548 
556 void gradient(const int offset, const double * f, double * grad_f,
557  const nek_mesh::NekMeshEnum pp_mesh);
558 
567  const nek_mesh::NekMeshEnum pp_mesh,
568  const bool max);
569 
578 double sideExtremeValue(const std::vector<int> & boundary_id, const field::NekFieldEnum & field,
579  const nek_mesh::NekMeshEnum pp_mesh, const bool max);
580 
585 int Nfaces();
586 
592 bool isHeatFluxBoundary(const int boundary);
593 
599 bool isMovingMeshBoundary(const int boundary);
600 
606 bool isTemperatureBoundary(const int boundary);
607 
613 const std::string temperatureBoundaryType(const int boundary);
614 
619 int polynomialOrder();
620 
625 int Nelements();
626 
631 int dim();
632 
640 int NfaceVertices();
641 
646 int NboundaryFaces();
647 
652 int NboundaryID();
653 
661 bool
662 validBoundaryIDs(const std::vector<int> & boundary_id, int & first_invalid_id, int & n_boundaries);
663 
669 void storeBoundaryCoupling(const std::vector<int> & boundary_id, int & N);
670 
676 {
678  int flux;
679 
682 
685 
688 
691 
694 
697 
700 
703 
706 };
707 
710 {
711  double U_ref;
712 
713  double T_ref;
714 
715  double dT_ref;
716 
717  double L_ref;
718 
719  double A_ref;
720 
721  double V_ref;
722 
723  double rho_ref;
724 
725  double Cp_ref;
726 
727  double flux_ref;
728 
729  double source_ref;
730 
732 };
733 
739 double (*solutionPointer(const field::NekFieldEnum & field))(int);
740 
745 void (*solutionPointer(const field::NekWriteEnum & field))(int, dfloat);
746 
753 double scalar01(const int id);
754 
761 double scalar02(const int id);
762 
769 double scalar03(const int id);
770 
780 double temperature(const int id);
781 
787 double pressure(const int id);
788 
794 double unity(const int id);
795 
801 double velocity_x(const int id);
802 
808 double velocity_y(const int id);
809 
815 double velocity_z(const int id);
816 
822 double velocity(const int id);
823 
829 void flux(const int id, const dfloat value);
830 
836 void heat_source(const int id, const dfloat value);
837 
843 void x_displacement(const int id, const dfloat value);
844 
850 void y_displacement(const int id, const dfloat value);
851 
857 void z_displacement(const int id, const dfloat value);
858 
868 void initializeDimensionalScales(const double U_ref,
869  const double T_ref,
870  const double dT_ref,
871  const double L_ref,
872  const double rho_ref,
873  const double Cp_ref);
874 
888 void dimensionalize(const field::NekFieldEnum & field, double & value);
889 
894 double referenceFlux();
895 
900 double referenceSource();
901 
906 double referenceLength();
907 
912 double referenceArea();
913 
918 double referenceVolume();
919 
920 // useful concept from Stack Overflow for templating MPI calls
921 template <typename T>
922 MPI_Datatype resolveType();
923 
931 template <typename T>
932 void
933 allgatherv(const std::vector<int> & base_counts, const T * input, T * output, const int multiplier)
934 {
935  int * recvCounts = (int *)calloc(commSize(), sizeof(int));
936  int * displacement = (int *)calloc(commSize(), sizeof(int));
937  displacementAndCounts(base_counts, recvCounts, displacement, multiplier);
938 
939  MPI_Allgatherv(input,
940  recvCounts[commRank()],
941  resolveType<T>(),
942  output,
943  (const int *)recvCounts,
944  (const int *)displacement,
945  resolveType<T>(),
946  platform->comm.mpiComm);
947 
948  free(recvCounts);
949  free(displacement);
950 }
951 
952 } // end namespace nekrs
nekrs::usrwrkIndices::mesh_velocity_y
int mesh_velocity_y
y-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:687
nekrs::endControlNumSteps
bool endControlNumSteps()
nekrs::solutionPointer
double(*)(int) solutionPointer(const field::NekFieldEnum &field)
Definition: NekInterface.h:739
nekrs::characteristicScales::source_ref
double source_ref
Definition: NekInterface.h:729
nekrs::commSize
int commSize()
nekrs::isHeatFluxBoundary
bool isHeatFluxBoundary(const int boundary)
nekrs::centroidFace
Point centroidFace(int local_elem_id, int local_face_id)
nekrs::viscosity
double viscosity()
nekrs::interpolationMatrix
void interpolationMatrix(double *I, int starting_points, int ending_points)
nekrs::scalar01
double scalar01(const int id)
Get the scalar01 solution at given GLL index.
nekrs::centroid
Point centroid(int local_elem_id)
nekrs::polynomialOrder
int polynomialOrder()
nekrs::resolveType
MPI_Datatype resolveType()
field::NekWriteEnum
NekWriteEnum
Enumeration of possible fields to write in nekRS.
Definition: CardinalEnums.h:104
nekrs::storeBoundaryCoupling
void storeBoundaryCoupling(const std::vector< int > &boundary_id, int &N)
NekBoundaryCoupling
Definition: NekBoundaryCoupling.h:29
nekrs::entireMesh
mesh_t * entireMesh()
nekrs::usrwrkSideIntegral
std::vector< double > usrwrkSideIntegral(const unsigned int &slot, const std::vector< int > &boundary, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::flowMesh
mesh_t * flowMesh()
nekrs::flux
void flux(const int id, const dfloat value)
nekrs::displacementAndCounts
void displacementAndCounts(const std::vector< int > &base_counts, int *counts, int *displacement, const int multiplier)
nekrs::Nelements
int Nelements()
field
Definition: CardinalEnums.h:85
nekrs::hasVariableDt
bool hasVariableDt()
nekrs::heat_source
void heat_source(const int id, const dfloat value)
nekrs::velocity
double velocity(const int id)
nekrs::hasHeatSourceKernel
bool hasHeatSourceKernel()
nekrs::characteristicScales::dT_ref
double dT_ref
Definition: NekInterface.h:715
nekrs::validBoundaryIDs
bool validBoundaryIDs(const std::vector< int > &boundary_id, int &first_invalid_id, int &n_boundaries)
NekVolumeCoupling.h
nekrs::referenceArea
double referenceArea()
nekrs::sideExtremeValue
double sideExtremeValue(const std::vector< int > &boundary_id, const field::NekFieldEnum &field, const nek_mesh::NekMeshEnum pp_mesh, const bool max)
nekrs::massFlowrate
double massFlowrate(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::usrwrkVolumeIntegral
double usrwrkVolumeIntegral(const unsigned int &slot, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::characteristicScales::nondimensional_T
bool nondimensional_T
Definition: NekInterface.h:731
nekrs::usrwrkIndices::heat_source
int heat_source
volumetric heat source (for volumetric heating)
Definition: NekInterface.h:681
nekrs::characteristicScales::Cp_ref
double Cp_ref
Definition: NekInterface.h:725
operation::max
@ max
Definition: CardinalEnums.h:122
nekrs::interpolateSurfaceFaceHex3D
void interpolateSurfaceFaceHex3D(double *scratch, const double *I, double *x, int N, double *Ix, int M)
nekrs::area
double area(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::setAbsoluteTol
void setAbsoluteTol(double tol)
nekrs::characteristicScales::T_ref
double T_ref
Definition: NekInterface.h:713
nekrs::getVgeo
dfloat * getVgeo()
nekrs::pressureSurfaceForce
double pressureSurfaceForce(const std::vector< int > &boundary_id, const Point &direction, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::initializeDimensionalScales
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)
nekrs::scalar03
double scalar03(const int id)
Get the scalar03 solution at given GLL index.
nekrs::characteristicScales::A_ref
double A_ref
Definition: NekInterface.h:719
nekrs::hasTemperatureVariable
bool hasTemperatureVariable()
nekrs::volume
double volume(const nek_mesh::NekMeshEnum pp_mesh)
nekrs::characteristicScales::U_ref
double U_ref
Definition: NekInterface.h:711
nekrs::characteristicScales
Characteristic scales assumed in nekRS if using a non-dimensional solution.
Definition: NekInterface.h:709
nekrs::dim
int dim()
nekrs::gllPointFace
Point gllPointFace(int local_elem_id, int local_face_id, int local_node_id)
nekrs::usrwrkIndices::boundary_scalar02
int boundary_scalar02
boundary scalar02 (for separate domain coupling)
Definition: NekInterface.h:702
nekrs::getMesh
mesh_t * getMesh(const nek_mesh::NekMeshEnum pp_mesh)
nekrs::y_displacement
void y_displacement(const int id, const dfloat value)
nekrs::Pr
double Pr()
nekrs::commRank
int commRank()
nekrs::setRelativeTol
void setRelativeTol(double tol)
nekrs::pressure
double pressure(const int id)
CardinalEnums.h
nekrs::updateHostMeshParameters
void updateHostMeshParameters()
Update the mesh parameters on host.
nekrs::dimensionalizeSideIntegral
void dimensionalizeSideIntegral(const field::NekFieldEnum &integrand, const Real &area, double &integral)
nekrs::allgatherv
void allgatherv(const std::vector< int > &base_counts, const T *input, T *output, const int multiplier=1)
Definition: NekInterface.h:933
nekrs::volumeExtremeValue
double volumeExtremeValue(const field::NekFieldEnum &field, const nek_mesh::NekMeshEnum pp_mesh, const bool max)
nekrs::NboundaryFaces
int NboundaryFaces()
nekrs::write_field_file
void write_field_file(const std::string &prefix, const dfloat time, const int &step)
nekrs::getSgeo
dfloat * getSgeo()
nekrs::velocity_x
double velocity_x(const int id)
nekrs::velocityFieldOffset
int velocityFieldOffset()
nekrs::limitTemperature
void limitTemperature(const double *min_T, const double *max_T)
nekrs::initializeScratch
void initializeScratch(const unsigned int &n_slots)
nekrs::characteristicScales::rho_ref
double rho_ref
Definition: NekInterface.h:723
nekrs::Nfaces
int Nfaces()
nek_mesh::NekMeshEnum
NekMeshEnum
Definition: CardinalEnums.h:44
nekrs::characteristicScales::L_ref
double L_ref
Definition: NekInterface.h:717
nekrs::referenceLength
double referenceLength()
nekrs::gllPoint
Point gllPoint(int local_elem_id, int local_node_id)
nekrs::hasMovingMesh
bool hasMovingMesh()
nekrs::copyDeformationToDevice
void copyDeformationToDevice()
Copy the deformation from host to device.
nekrs::endControlTime
bool endControlTime()
nekrs::NboundaryID
int NboundaryID()
nekrs::buildOnly
void buildOnly(int buildOnly)
nekrs::scalarFieldOffset
int scalarFieldOffset()
nekrs::dimensionalizeVolumeIntegral
void dimensionalizeVolumeIntegral(const field::NekFieldEnum &integrand, const Real &volume, double &integral)
nekrs::NfaceVertices
int NfaceVertices()
Number of vertices required to define an element face Vertices refer to the points required to place ...
nekrs::hasScalarVariable
bool hasScalarVariable(int scalarId)
nekrs::interpolateVolumeHex3D
void interpolateVolumeHex3D(const double *I, double *x, int N, double *Ix, int M)
nekrs::heatFluxIntegral
double heatFluxIntegral(const std::vector< int > &boundary_id, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::getNekSetupTime
double getNekSetupTime()
nekrs::usrwrkIndices::flux
int flux
boundary heat flux (for conjugate heat transfer)
Definition: NekInterface.h:678
nekrs::hasTemperatureSolve
bool hasTemperatureSolve()
nekrs::dimensionalize
void dimensionalize(const field::NekFieldEnum &field, double &value)
Dimensionalize a field by multiplying the nondimensional form by the reference.
nekrs::volumeIntegral
double volumeIntegral(const field::NekFieldEnum &integrand, const double &volume, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::usrwrkIndices::boundary_velocity
int boundary_velocity
boundary velocity (for separate domain coupling)
Definition: NekInterface.h:693
nekrs::unity
double unity(const int id)
nekrs::velocity_z
double velocity_z(const int id)
nekrs::hasBlendingSolver
bool hasBlendingSolver()
nekrs::sideMassFluxWeightedIntegral
double sideMassFluxWeightedIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::referenceFlux
double referenceFlux()
nekrs::usrwrkIndices
Definition: NekInterface.h:675
nekrs::temperature
double temperature(const int id)
Get the temperature solution at given GLL index.
nekrs::x_displacement
void x_displacement(const int id, const dfloat value)
nekrs::endControlElapsedTime
bool endControlElapsedTime()
nekrs::sideIntegral
double sideIntegral(const std::vector< int > &boundary_id, const field::NekFieldEnum &integrand, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::hasUserMeshSolver
bool hasUserMeshSolver()
nekrs::usrwrkIndices::boundary_scalar01
int boundary_scalar01
boundary scalar01 (for separate domain coupling)
Definition: NekInterface.h:699
nekrs::usrwrkIndices::boundary_scalar03
int boundary_scalar03
boundary scalar03 (for separate domain coupling)
Definition: NekInterface.h:705
nekrs::scratchAvailable
bool scratchAvailable()
nekrs::gradient
void gradient(const int offset, const double *f, double *grad_f, const nek_mesh::NekMeshEnum pp_mesh)
nekrs::temperatureMesh
mesh_t * temperatureMesh()
nekrs::initializeHostMeshParameters
void initializeHostMeshParameters()
Allocate memory for the host mesh parameters.
nekrs::usrwrkIndices::mesh_velocity_x
int mesh_velocity_x
x-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:684
NekBoundaryCoupling.h
nekrs::velocity_y
double velocity_y(const int id)
nekrs::setNekSetupTime
void setNekSetupTime(const double &time)
nekrs::write_usrwrk_field_file
void write_usrwrk_field_file(const int &slot, const std::string &prefix, const dfloat &time, const int &step, const bool &write_coords)
nekrs::dimensionalizeArea
void dimensionalizeArea(double &integral)
nekrs::characteristicScales::flux_ref
double flux_ref
Definition: NekInterface.h:727
nekrs::freeScratch
void freeScratch()
Free the scratch space.
nekrs::temperatureBoundaryType
const std::string temperatureBoundaryType(const int boundary)
nekrs::normalizeFlux
bool normalizeFlux(const NekBoundaryCoupling &nek_boundary_coupling, const std::vector< int > &boundary, const double moose_integral, double nek_integral, double &normalized_nek_integral)
nekrs::usrwrkIndices::boundary_temperature
int boundary_temperature
boundary temperature (for separate domain coupling)
Definition: NekInterface.h:696
nekrs
Cardinal-specific nekRS API.
Definition: NekUility.C:21
nekrs::isTemperatureBoundary
bool isTemperatureBoundary(const int boundary)
nekrs::setStartTime
void setStartTime(const double &start)
nekrs::referenceVolume
double referenceVolume()
nekrs::characteristicScales::V_ref
double V_ref
Definition: NekInterface.h:721
nekrs::hasCHT
bool hasCHT()
nekrs::isInitialized
bool isInitialized()
nekrs::isMovingMeshBoundary
bool isMovingMeshBoundary(const int boundary)
nekrs::normalizeFluxBySideset
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)
nekrs::scaleUsrwrk
void scaleUsrwrk(const unsigned int &slot, const dfloat &value)
nekrs::dimensionalizeVolume
void dimensionalizeVolume(double &integral)
field::NekFieldEnum
NekFieldEnum
Enumeration of possible fields to read from nekRS.
Definition: CardinalEnums.h:88
nekrs::usrwrkIndices::mesh_velocity_z
int mesh_velocity_z
z-velocity of moving boundary (for mesh blending solver)
Definition: NekInterface.h:690
nekrs::z_displacement
void z_displacement(const int id, const dfloat value)
nekrs::scalar02
double scalar02(const int id)
Get the scalar02 solution at given GLL index.
nekrs::referenceSource
double referenceSource()