Commit 06595aff authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

reload contacts

parent 6922fd28
Pipeline #4134 failed with stage
in 12 seconds
......@@ -968,7 +968,7 @@ static void _writeContactVtkSingle(ParticleProblem *p, FILE *f, int ctype, const
fprintf(f, "<DataArray Name=\"%s\" NumberOfTuples=\"%zu\" NumberOfComponents=\"1\" type=\"Float32\" format=\"ascii\">\n",cname, n);
for (size_t i = 0; i < vectorSize(p->contacts); ++i) {
if (p->contacts[i].type == ctype) {
fprintf(f, "%.2g ", p->contacts[i].dv);
fprintf(f, "%.16g ", p->contacts[i].dv);
}
}
fprintf(f, "\n</DataArray>\n");
......@@ -1341,14 +1341,111 @@ int particleProblemImportBoundaryVtk(ParticleProblem *p, const char *filename)
return 0;
}
void _importContactSingle(ParticleProblem *p, MBVtkDataArray a_idx, MBVtkDataArray a_v, ContactType type) {
int n = a_idx.number_of_tuples;
double *dv = mb_vtk_data_array_to_double(&a_v,n,1);
int * idx = mb_vtk_data_array_to_int(&a_idx,n,2);
if(n < 0 || dv == NULL || idx == NULL){
printf("contact data is incomplete in file\n");
exit(1);
}
int i = vectorSize(p->contacts);
vectorPushN(&p->contacts, n);
for (int j = 0; j < n; ++j){
p->contacts[i].o0 = idx[j*2+0];
p->contacts[i].o1 = idx[j*2+1];
p->contacts[i].dv = dv[j];
p->contacts[i].type = type;
i++;
}
free(idx);
free(dv);
mb_vtk_data_array_destroy(&a_idx);
mb_vtk_data_array_destroy(&a_v);
}
int particleProblemImportContactVtk(ParticleProblem *p, const char *filename)
{
MbXmlReader *r = mb_xml_reader_create(filename);
MbXmlElement fileelement,gridelement;
mb_xml_read_element(r,&fileelement);
mb_xml_read_element(r,&gridelement);
MbXmlElement e;
MBVtkDataArray a, pp_idx, pp_v, pd_idx, pd_v, ps_idx, ps_v;
#if DIMENSION == 3
MBVtkDataArray pt_idx, pt_v;
#endif
while(mb_xml_read_element(r,&e)!=1) {
if (!strcasecmp(e.name, "FieldData")) {
while(mb_read_vtk_data_array(r,&a)) {
if(!strcasecmp(a.name,"particle_particle")) pp_v = a;
else if(!strcasecmp(a.name,"particle_particle_idx")) pp_idx = a;
else if(!strcasecmp(a.name,"particle_disk")) pd_v = a;
else if(!strcasecmp(a.name,"particle_disk_idx")) pd_idx = a;
else if(!strcasecmp(a.name,"particle_segment")) ps_v = a;
else if(!strcasecmp(a.name,"particle_segment_idx")) ps_idx = a;
#if DIMENSION == 3
else if(!strcasecmp(a.name,"particle_triangle")) pt_v = a;
else if(!strcasecmp(a.name,"particle_triangle_idx")) pt_idx = a;
#endif
else {
printf("unexpected data array in \"%s\" : \"%s\"\n",filename, a.name);
mb_vtk_data_array_destroy(&a);
exit(1);
}
}
}
else if(!strcasecmp(e.name,"Piece")) {
int n_points, n_cells;
MbXmlElement f;
for (size_t i = 0; i<e.n_attr; ++i) {
MBVtkDataArray points={0}, connectivity={0}, offsets={0}, types={0};
while(mb_xml_read_element(r,&f)!=1) {
if (!strcasecmp(f.name,"Points")){
MBVtkDataArray a;
mb_read_vtk_data_array(r,&a);
mb_vtk_data_array_destroy(&a);
}
else {
printf("unexpected element in \"%s\" : \"%s\"\n",filename, f.name);
exit(1);
}
mb_xml_end_element(r,&f);
}
}
}
else {
printf("unexpected element in \"%s\" : \"%s\"\n",filename, e.name);
exit(1);
}
mb_xml_end_element(r,&e);
}
mb_xml_end_element(r,&gridelement);
mb_xml_end_element(r,&fileelement);
mb_xml_reader_destroy(r);
vectorClear(p->contacts);
_importContactSingle(p, pp_idx, pp_v, PARTICLE_PARTICLE);
_importContactSingle(p, pd_idx, pd_v, PARTICLE_DISK);
_importContactSingle(p, ps_idx, ps_v, PARTICLE_SEGMENT);
#if DIMENSION == 3
_importContactSingle(p, pt_idx, pt_v, PARTICLE_TRIANGLE);
#endif
return 0;
}
int particleProblemReadVtk(ParticleProblem *p, const char *dirname, int iter)
{
char *f0 = malloc(sizeof(char)*(strlen(dirname)+30));
char *f1 = malloc(sizeof(char)*(strlen(dirname)+30));
char *f2 = malloc(sizeof(char)*(strlen(dirname)+30));
sprintf(f0, "%s/particles_%05d.vtp",dirname,iter);
sprintf(f1, "%s/boundaries_%05d.vtu",dirname,iter);
sprintf(f2, "%s/contacts_%05d.vtp",dirname,iter);
particleProblemImportVtk(p,f0);
particleProblemImportBoundaryVtk(p,f1);
particleProblemImportContactVtk(p,f2);
free(f0);
free(f1);
return 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment