32 void parse_comment_line(
char* buff,
const int buffsize, std::map<std::string,std::string> & metadata)
35 if(!
has_char(buff, buffsize,
'='))
return;
41 const int wsize = 1024;
42 char lword[wsize], cword[wsize], rword[wsize];
44 int numread = sscanf(buff,
"%s %s %s", lword, cword, rword);
46 if(numread == 3 && cword[0] ==
'=') {
48 std::string key = lword, value = rword;
49 metadata[key] = value;
51 else if(numread == 1) {
54 while(ridx < wsize && lword[ridx] !=
'=') cword[widx++] = lword[ridx++];
57 std::string key = cword;
60 while(ridx < wsize && lword[ridx] !=
'\0') cword[widx++] = lword[ridx++];
63 std::string value = cword;
65 metadata[key] = value;
68 fprintf(stderr,
"%s warning: Malformed key-value pair:\n%s\n", __func__, buff);
83 MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank);
89 stream =
f_open(filename.c_str(),
"r");
90 if(stream == NULL) err++;
95 log_msg(0,5,0,
"%s error: Could not read vtx data. Aborting!", __func__);
99 const size_t str_size = 5000;
100 char readbuff[str_size];
103 char* ptr =
f_gets_par(readbuff, str_size, stream, comm);
108 ptr =
f_gets_par(readbuff, str_size, stream, comm);
113 if(
has_char(readbuff, str_size,
'#')) {
115 char iestr[128], nestr[128], nnstr[128];
116 int nread = sscanf(readbuff,
"%d # %*s %31s %d %d", &ibuff, iestr, &ne, &nn);
119 metadata[
"grid"] = iestr;
120 metadata[
"nelem"] = std::to_string(ne);
121 metadata[
"nnode"] = std::to_string(nn);
126 ptr =
f_gets_par(readbuff, str_size, stream, comm);
131 sscanf(readbuff,
"%s", grid);
133 if(strcmp(grid,
"intra") == 0) {
134 metadata[
"grid"] =
"intra";
135 }
else if(strcmp(grid,
"extra") == 0) {
136 metadata[
"grid"] =
"extra";
147 ptr =
f_gets_par(readbuff, buffsize, stream, comm);
157 std::set<mesh_int_t> idx_set;
159 for(
size_t eidx = 0; eidx < mesh.
l_numelem; eidx++) {
160 if(mesh.
tag[eidx] == tag) {
162 idx_set.insert(mesh.
con[i]);
166 idx.
assign(idx_set.begin(), idx_set.end());
176 for(
size_t i=0; i<mesh.
l_numpts; i++) {
177 p.
x = mesh.
xyz[i*3 + 0], p.
y = mesh.
xyz[i*3 + 1], p.
z = mesh.
xyz[i*3 + 2];
185 for(
size_t eidx = 0; eidx < mesh.
l_numelem; eidx++) {
186 p.
x = p.
y = p.
z = 0.0;
190 p.
x += mesh.
xyz[c*3 + 0];
191 p.
y += mesh.
xyz[c*3 + 1];
192 p.
z += mesh.
xyz[c*3 + 2];
194 p /= double(mesh.
dsp[eidx + 1] - mesh.
dsp[eidx]);
213 for(
size_t i=0; i<local_idx.
size(); i++) petsc_idx[i] = petsc_nod[local_idx[i]];
216 weights->set(petsc_idx, 1.0);
218 mass.
mult(*weights, *vols);
226 std::map<std::string,std::string> metadata;
229 if(metadata.count(
"grid")) {
230 if(metadata[
"grid"].compare(
"intra") == 0) {
231 log_msg(0,3,0,
"Warning: openCARP requires input vtx indices to be of from the input mesh, i.e. of type \"extra\".");
234 log_msg(0,3,0,
"%s warning: Could not derive grid type info from file %s", __func__, filename.c_str());
The mesh storage class. It contains both element and vertex data.
vector< T > & get_numbering(SF_nbr nbr_type)
Get the vector defining a certain numbering.
class to store shape definitions
void remove_preceding_char(char *buff, const int buffsize, const char c)
vector< T > tag
element tag
PETSc numbering of nodes.
vector< T > dsp
connectivity starting index of each element
void warn_when_passing_intra_vtx(const std::string filename)
bool has_char(char *buff, const int buffsize, const char c)
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.
vector< S > xyz
node cooridnates
SF_real get_volume_from_nodes(sf_mat &mass, SF::vector< mesh_int_t > &local_idx)
void init_vector(SF::abstract_vector< T, S > **vec)
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.
virtual void mult(const abstract_vector< T, S > &x, abstract_vector< T, S > &b) const =0
Top-level header of FEM module.
const meshdata< mesh_int_t, mesh_real_t > * mesh_ptr() const
T get_global(T in, MPI_Op OP, MPI_Comm comm=PETSC_COMM_WORLD)
Do a global reduction on a variable.
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.
size_t l_numpts
local number of points
size_t l_numelem
local number of elements
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
void assign(InputIterator s, InputIterator e)
Assign a memory range.
double SF_real
Use the general double as real type.
bool point_in_shape(const Point &p, const geom_shape &shape)
test if a point is inside a simple geometric shape
char * f_gets_par(char *s, int size, FILE_SPEC stream, MPI_Comm comm)
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.