32 #include "petsc_utils.h" 37 #define COMMENT_CHAR '#' 39 void parse_comment_line(
char* buff,
const int buffsize, std::map<std::string,std::string> & metadata);
48 void read_metadata(
const std::string
filename, std::map<std::string,std::string> & metadata, MPI_Comm comm);
52 template<
class T>
inline 57 int numread = 0, err = 0;
60 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
63 const size_t str_size = 5000;
64 char readbuff[str_size];
67 stream =
f_open(filename.c_str(),
"r");
74 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
78 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
85 long int num_read_loc = 0;
87 ptr = fgets(readbuff, str_size, stream->
fd);
89 int n = sscanf(readbuff,
"%d", &nodbuff[num_read_loc]);
92 if(n == 1) num_read_loc++;
94 if(num_read_loc < num_inp_nod)
95 ptr = fgets(readbuff, str_size, stream->
fd);
103 MPI_Bcast(nodbuff.
data(), nodbuff.
size(), MPI_INT, 0, comm);
119 template<
class T>
inline 125 int numread = 0, err = 0;
128 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
139 stream =
f_open(filename.c_str(),
"r");
141 const size_t str_size = 5000;
142 char readbuff[str_size];
147 long int num_inp_nod;
149 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
153 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
157 int nodbuff_size = 50000;
158 if(nodbuff_size > num_inp_nod) nodbuff_size = num_inp_nod;
163 while(numread < num_inp_nod) {
164 nodbuff.
assign(
size_t(nodbuff_size),
int(-1));
167 int num_read_loc = 0;
169 ptr = fgets(readbuff, str_size, stream->
fd);
171 int n = sscanf(readbuff,
"%d", &nodbuff[num_read_loc]);
173 if(n == 1) num_read_loc++;
175 if(num_read_loc < nodbuff_size)
176 ptr = fgets(readbuff, str_size, stream->
fd);
182 MPI_Bcast(nodbuff.
data(), nodbuff_size*
sizeof(int), MPI_BYTE, 0, comm);
184 for(
int ridx = 0; ridx < nodbuff_size; ridx++) {
185 int n = nodbuff[ridx];
186 auto it = dd_map.
find(n);
188 if(n > -1 && it != dd_map.
end() && have_read.
count(n) == 0) {
215 template<
class T>
inline 220 const bool algebraic,
229 for(
size_t i = 0; i<alg_nod.
size(); i++) {
231 dd_map[dd_nbr[an]] = an;
234 for(
size_t i = 0; i<dd_nbr.
size(); i++)
235 dd_map[dd_nbr[i]] = i;
253 template<
class T>
inline 261 for(
size_t i = 0; i<dd_nbr.
size(); i++)
262 dd_map[dd_nbr[i]] = i;
268 template<
class T,
class S>
inline 275 int numread = 0, err = 0;
278 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
283 fprintf(stderr,
"%s error: dpn > 3 not supported!\n", __func__);
296 stream =
f_open(filename.c_str(),
"r");
298 const size_t str_size = 5000;
299 char readbuff[str_size];
305 long int num_inp_nod;
307 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
311 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
315 int nodbuff_size = 50000;
316 if(nodbuff_size > num_inp_nod) nodbuff_size = num_inp_nod;
324 while(numread < num_inp_nod) {
325 nodbuff .
assign(
size_t(nodbuff_size),
int(-1));
326 doublebuff.
resize(
size_t(nodbuff_size * dpn));
329 int num_read_loc = 0;
331 ptr = fgets(readbuff, str_size, stream->
fd);
333 int n = sscanf(readbuff,
"%d %lf %lf %lf", &nodbuff[num_read_loc],
334 &doublebuff[num_read_loc*dpn+0], &doublebuff[num_read_loc*dpn+1], &doublebuff[num_read_loc*dpn+2]);
337 if(n == dpn+1) num_read_loc++;
339 if(num_read_loc < nodbuff_size)
340 ptr = fgets(readbuff, str_size, stream->
fd);
346 MPI_Bcast(nodbuff.
data(), nodbuff_size, MPI_INT, 0, comm);
347 MPI_Bcast(doublebuff.
data(), nodbuff_size*dpn, MPI_DOUBLE, 0, comm);
349 for(
int ridx = 0; ridx < nodbuff_size; ridx++) {
350 int n = nodbuff[ridx];
352 auto it = dd_map.
find(n);
353 if(n > -1 && it != dd_map.
end() && have_read.
count(n) == 0) {
355 idx[widx] = it->second;
357 for(
int j=0; j<dpn; j++)
358 dat[widx*dpn+j] = doublebuff[ridx*dpn+j];
374 template<
class T,
class S>
inline 379 const bool algebraic,
388 for(
size_t i = 0; i<alg_nod.
size(); i++) {
390 dd_map[dd_nbr[an]] = an;
394 for(
size_t i = 0; i<dd_nbr.
size(); i++)
395 dd_map[dd_nbr[i]] = i;
402 template<
class T,
class S>
inline 411 for(
size_t i = 0; i<dd_nbr.
size(); i++)
412 dd_map[dd_nbr[i]] = i;
The mesh storage class. It contains both element and vertex data.
Custom unordered_set implementation.
vector< T > & get_numbering(SF_nbr nbr_type)
Get the vector defining a certain numbering.
class to store shape definitions
void read_indices(SF::vector< T > &idx, const std::string filename, const hashmap::unordered_map< mesh_int_t, mesh_int_t > &dd_map, MPI_Comm comm)
Read indices from a file.
void warn_when_passing_intra_vtx(const std::string filename)
overlapping_layout< T > pl
nodal parallel layout
void indices_from_geom_shape(SF::vector< mesh_int_t > &idx, const sf_mesh &mesh, const geom_shape shape, const bool nodal)
Populate vertex data with the vertices inside a defined box shape.
T * data()
Pointer to the vector's start.
SF_real get_volume_from_nodes(sf_mat &mass, SF::vector< mesh_int_t > &local_idx)
SF_nbr
Enumeration encoding the different supported numberings.
void indices_from_region_tag(SF::vector< mesh_int_t > &idx, const sf_mesh &mesh, const int tag)
Populate vertex data with the vertices of a given tag region.
hm_int count(const K &key) const
void read_indices_global(SF::vector< T > &idx, const std::string filename, MPI_Comm comm)
void insert(InputIterator first, InputIterator last)
char * skip_comments(FILE_SPEC stream, char *readbuff, size_t buffsize, MPI_Comm comm)
size_t size() const
The current size of the vector.
void parse_comment_line(char *buff, const int buffsize, std::map< std::string, std::string > &metadata)
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
void read_metadata(const std::string filename, std::map< std::string, std::string > &metadata, MPI_Comm comm)
Read metadata from the header.
A vector storing arbitrary data.
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
void read_indices_with_data(SF::vector< T > &idx, SF::vector< S > &dat, const std::string filename, const hashmap::unordered_map< mesh_int_t, mesh_int_t > &dd_map, const int dpn, MPI_Comm comm)
like read_indices, but with associated data for each index
void assign(InputIterator s, InputIterator e)
Assign a memory range.
iterator find(const K &key)
Search for key. Return iterator.
double SF_real
Use the general double as real type.
void resize(size_t n)
Resize a vector.
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.