17 #include "petsc_utils.h"
22 #define COMMENT_CHAR '#'
24 void parse_comment_line(
char* buff,
const int buffsize, std::map<std::string,std::string> & metadata);
33 void read_metadata(
const std::string
filename, std::map<std::string,std::string> & metadata, MPI_Comm comm);
37 template<
class T>
inline
42 int numread = 0, err = 0;
45 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
48 const size_t str_size = 5000;
49 char readbuff[str_size];
59 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
63 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
70 long int num_read_loc = 0;
72 ptr = fgets(readbuff, str_size, stream->
fd);
74 int n = sscanf(readbuff,
"%d", &nodbuff[num_read_loc]);
77 if(n == 1) num_read_loc++;
79 if(num_read_loc < num_inp_nod)
80 ptr = fgets(readbuff, str_size, stream->
fd);
88 MPI_Bcast(nodbuff.
data(), nodbuff.
size(), MPI_INT, 0, comm);
104 template<
class T>
inline
110 int numread = 0, err = 0;
113 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
126 const size_t str_size = 5000;
127 char readbuff[str_size];
132 long int num_inp_nod;
134 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
138 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
142 int nodbuff_size = 50000;
143 if(nodbuff_size > num_inp_nod) nodbuff_size = num_inp_nod;
148 while(numread < num_inp_nod) {
149 nodbuff.
assign(
size_t(nodbuff_size),
int(-1));
152 int num_read_loc = 0;
154 ptr = fgets(readbuff, str_size, stream->
fd);
156 int n = sscanf(readbuff,
"%d", &nodbuff[num_read_loc]);
158 if(n == 1) num_read_loc++;
160 if(num_read_loc < nodbuff_size)
161 ptr = fgets(readbuff, str_size, stream->
fd);
167 MPI_Bcast(nodbuff.
data(), nodbuff_size*
sizeof(
int), MPI_BYTE, 0, comm);
169 for(
int ridx = 0; ridx < nodbuff_size; ridx++) {
170 int n = nodbuff[ridx];
171 auto it = dd_map.
find(n);
173 if(n > -1 && it != dd_map.
end() && have_read.
count(n) == 0) {
200 template<
class T>
inline
205 const bool algebraic,
214 for(
size_t i = 0; i<alg_nod.
size(); i++) {
216 dd_map[dd_nbr[an]] = an;
219 for(
size_t i = 0; i<dd_nbr.
size(); i++)
220 dd_map[dd_nbr[i]] = i;
238 template<
class T>
inline
246 for(
size_t i = 0; i<dd_nbr.
size(); i++)
247 dd_map[dd_nbr[i]] = i;
253 template<
class T,
class S>
inline
260 int numread = 0, err = 0;
263 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
268 fprintf(stderr,
"%s error: dpn > 3 not supported!\n", __func__);
283 const size_t str_size = 5000;
284 char readbuff[str_size];
290 long int num_inp_nod;
292 numread = sscanf(readbuff,
"%ld", &num_inp_nod);
296 log_msg(0, 5, 0,
"%s error: Could not determine vtx data size! Aborting!\n", __func__);
300 int nodbuff_size = 50000;
301 if(nodbuff_size > num_inp_nod) nodbuff_size = num_inp_nod;
309 while(numread < num_inp_nod) {
310 nodbuff .
assign(
size_t(nodbuff_size),
int(-1));
311 doublebuff.
resize(
size_t(nodbuff_size * dpn));
314 int num_read_loc = 0;
316 ptr = fgets(readbuff, str_size, stream->
fd);
318 int n = sscanf(readbuff,
"%d %lf %lf %lf", &nodbuff[num_read_loc],
319 &doublebuff[num_read_loc*dpn+0], &doublebuff[num_read_loc*dpn+1], &doublebuff[num_read_loc*dpn+2]);
322 if(n == dpn+1) num_read_loc++;
324 if(num_read_loc < nodbuff_size)
325 ptr = fgets(readbuff, str_size, stream->
fd);
331 MPI_Bcast(nodbuff.
data(), nodbuff_size, MPI_INT, 0, comm);
332 MPI_Bcast(doublebuff.
data(), nodbuff_size*dpn, MPI_DOUBLE, 0, comm);
334 for(
int ridx = 0; ridx < nodbuff_size; ridx++) {
335 int n = nodbuff[ridx];
337 auto it = dd_map.
find(n);
338 if(n > -1 && it != dd_map.
end() && have_read.
count(n) == 0) {
340 idx[widx] = it->second;
342 for(
int j=0; j<dpn; j++)
343 dat[widx*dpn+j] = doublebuff[ridx*dpn+j];
359 template<
class T,
class S>
inline
364 const bool algebraic,
373 for(
size_t i = 0; i<alg_nod.
size(); i++) {
375 dd_map[dd_nbr[an]] = an;
379 for(
size_t i = 0; i<dd_nbr.
size(); i++)
380 dd_map[dd_nbr[i]] = i;
387 template<
class T,
class S>
inline
396 for(
size_t i = 0; i<dd_nbr.
size(); i++)
397 dd_map[dd_nbr[i]] = i;
opencarp::local_index_t mesh_int_t
opencarp::real_t SF_real
Global scalar type.
overlapping_layout< T > pl
nodal parallel layout
vector< T > & get_numbering(SF_nbr nbr_type)
Get the vector defining a certain numbering.
A vector storing arbitrary data.
size_t size() const
The current size of the vector.
void resize(size_t n)
Resize a vector.
void assign(InputIterator s, InputIterator e)
Assign a memory range.
T * data()
Pointer to the vector's start.
iterator find(const K &key)
Search for key. Return iterator.
Custom unordered_set implementation.
hm_int count(const K &key) const
void insert(InputIterator first, InputIterator last)
SF_nbr
Enumeration encoding the different supported numberings.
void parse_comment_line(char *buff, const int buffsize, std::map< std::string, std::string > &metadata)
SF_real get_volume_from_nodes(sf_mat &mass, SF::vector< mesh_int_t > &local_idx)
char * skip_comments(FILE_SPEC stream, char *readbuff, size_t buffsize, MPI_Comm comm)
SF::meshdata< mesh_int_t, mesh_real_t > sf_mesh
void read_metadata(const std::string filename, std::map< std::string, std::string > &metadata, MPI_Comm comm)
Read metadata from the header.
void read_indices_global(SF::vector< T > &idx, const std::string filename, MPI_Comm comm)
void indices_from_region_tags(SF::vector< mesh_int_t > &idx, const sf_mesh &mesh, const hashmap::unordered_set< int > &tags)
Populate vertex data with the vertices of multiple tag regions.
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
void warn_when_passing_intra_vtx(const std::string filename)
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.
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.
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
SF::abstract_matrix< SF_int, SF_real > sf_mat
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 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 f_close(FILE_SPEC &f)
Close a FILE_SPEC.