16 Chi::log.
Log() <<
"Initializing spatial discretization.\n";
25 const auto& sdm = *discretization_;
28 struct SpatialWeightFunction
32 virtual ~SpatialWeightFunction() =
default;
35 struct SphericalSWF :
public SpatialWeightFunction
38 {
return pt[2]*pt[2]; }
41 struct CylindricalSWF :
public SpatialWeightFunction
47 auto swf_ptr = std::make_shared<SpatialWeightFunction>();
49 swf_ptr = std::make_shared<SphericalSWF>();
51 swf_ptr = std::make_shared<CylindricalSWF>();
54 const SpatialWeightFunction& swf)
56 const auto& cell_mapping = sdm.GetCellMapping(cell);
57 const size_t cell_num_faces = cell.
faces_.size();
58 const size_t cell_num_nodes = cell_mapping.NumNodes();
59 const auto vol_qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
61 MatDbl IntV_gradshapeI_gradshapeJ(cell_num_nodes,
VecDbl(cell_num_nodes));
62 MatVec3 IntV_shapeI_gradshapeJ(cell_num_nodes,
VecVec3(cell_num_nodes));
63 MatDbl IntV_shapeI_shapeJ(cell_num_nodes,
VecDbl(cell_num_nodes));
64 VecDbl IntV_shapeI(cell_num_nodes);
66 std::vector<MatDbl> IntS_shapeI_shapeJ(cell_num_faces);
67 std::vector<MatVec3> IntS_shapeI_gradshapeJ(cell_num_faces);
68 std::vector<VecDbl> IntS_shapeI(cell_num_faces);
71 for (
unsigned int i = 0; i < cell_num_nodes; ++i)
73 for (
unsigned int j = 0; j < cell_num_nodes; ++j)
75 for (
const auto& qp : vol_qp_data.QuadraturePointIndices())
77 IntV_gradshapeI_gradshapeJ[i][j]
78 += swf(vol_qp_data.QPointXYZ(qp)) *
79 vol_qp_data.ShapeGrad(i, qp).Dot(vol_qp_data.ShapeGrad(j, qp)) *
82 IntV_shapeI_gradshapeJ[i][j]
83 += swf(vol_qp_data.QPointXYZ(qp)) *
84 vol_qp_data.ShapeValue(i, qp) *
85 vol_qp_data.ShapeGrad(j, qp) *
88 IntV_shapeI_shapeJ[i][j]
89 += swf(vol_qp_data.QPointXYZ(qp)) *
90 vol_qp_data.ShapeValue(i, qp) *
91 vol_qp_data.ShapeValue(j, qp) *
96 for (
const auto& qp : vol_qp_data.QuadraturePointIndices())
99 += swf(vol_qp_data.QPointXYZ(qp)) *
100 vol_qp_data.ShapeValue(i, qp) * vol_qp_data.JxW(qp);
105 for (
size_t f = 0; f < cell_num_faces; ++f)
107 const auto faces_qp_data = cell_mapping.MakeSurfaceQuadraturePointData(f);
108 IntS_shapeI_shapeJ[f].resize(cell_num_nodes,
VecDbl(cell_num_nodes));
109 IntS_shapeI[f].resize(cell_num_nodes);
110 IntS_shapeI_gradshapeJ[f].resize(cell_num_nodes,
VecVec3(cell_num_nodes));
112 for (
unsigned int i = 0; i < cell_num_nodes; ++i)
114 for (
unsigned int j = 0; j < cell_num_nodes; ++j)
116 for (
const auto& qp : faces_qp_data.QuadraturePointIndices())
118 IntS_shapeI_shapeJ[f][i][j]
119 += swf(faces_qp_data.QPointXYZ(qp)) *
120 faces_qp_data.ShapeValue(i, qp) *
121 faces_qp_data.ShapeValue(j, qp) *
122 faces_qp_data.JxW(qp);
123 IntS_shapeI_gradshapeJ[f][i][j]
124 += swf(faces_qp_data.QPointXYZ(qp)) *
125 faces_qp_data.ShapeValue(i, qp) *
126 faces_qp_data.ShapeGrad(j, qp) *
127 faces_qp_data.JxW(qp);
131 for (
const auto& qp : faces_qp_data.QuadraturePointIndices())
134 += swf(faces_qp_data.QPointXYZ(qp)) *
135 faces_qp_data.ShapeValue(i, qp) * faces_qp_data.JxW(qp);
142 IntV_shapeI_gradshapeJ,
147 IntS_shapeI_gradshapeJ,
151 const size_t num_local_cells = grid_ptr_->local_cells.size();
152 unit_cell_matrices_.resize(num_local_cells);
154 for (
const auto& cell : grid_ptr_->local_cells)
155 unit_cell_matrices_[cell.
local_id_] = ComputeCellUnitIntegrals(cell, *swf_ptr);
157 const auto ghost_ids = grid_ptr_->cells.GetGhostGlobalIDs();
158 for (uint64_t ghost_id : ghost_ids)
159 unit_ghost_cell_matrices_[ghost_id] =
160 ComputeCellUnitIntegrals(grid_ptr_->cells[ghost_id],*swf_ptr);
164 std::array<size_t,2> num_local_ucms = {unit_cell_matrices_.size(),
165 unit_ghost_cell_matrices_.size()};
166 std::array<size_t,2> num_globl_ucms = {0,0};
168 MPI_Allreduce(num_local_ucms.data(),
169 num_globl_ucms.data(),
178 <<
"Ghost cell unit cell-matrix ratio: "
179 << (double)num_globl_ucms[1]*100/(
double)num_globl_ucms[0]
182 <<
"Cell matrices computed. Process memory = "
183 << std::setprecision(3)
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
static double GetMemoryUsageInMB()
Get current memory usage in Megabytes.
const MPI_Comm & comm
MPI communicator.
static std::shared_ptr< PieceWiseLinearDiscontinuous > New(const chi_mesh::MeshContinuum &grid, QuadratureOrder q_order=QuadratureOrder::SECOND, CoordinateSystemType cs_type=CoordinateSystemType::CARTESIAN)
std::vector< CellFace > faces_
chi_mesh::MeshContinuumPtr grid_ptr_
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
void ComputeUnitIntegrals()
virtual void InitializeSpatialDiscretization()
std::vector< VecDbl > MatDbl
std::vector< chi_mesh::Vector3 > VecVec3
std::vector< double > VecDbl
std::vector< VecVec3 > MatVec3