| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
/****************************************************************************/ |
| 6 |
/* */ |
| 7 |
/* File: inventor.c */ |
| 8 |
/* */ |
| 9 |
/* Purpose: visualization in IRIS Inventor format */ |
| 10 |
/* */ |
| 11 |
/* Author: Klaus Birken */ |
| 12 |
/* Rechenzentrum Uni Stuttgart */ |
| 13 |
/* Universitaet Stuttgart */ |
| 14 |
/* Allmandring 30 */ |
| 15 |
/* 70550 Stuttgart */ |
| 16 |
/* internet: [email protected] */ |
| 17 |
/* */ |
| 18 |
/* History: 95/03/28 kb begin */ |
| 19 |
/* */ |
| 20 |
/* Remarks: */ |
| 21 |
/* */ |
| 22 |
/****************************************************************************/ |
| 23 |
|
| 24 |
/****************************************************************************/ |
| 25 |
/* */ |
| 26 |
/* include files */ |
| 27 |
/* system include files */ |
| 28 |
/* application include files */ |
| 29 |
/* */ |
| 30 |
/****************************************************************************/ |
| 31 |
|
| 32 |
/* standard C library */ |
| 33 |
#include <config.h> |
| 34 |
#include <cstdio> |
| 35 |
#include <cmath> |
| 36 |
|
| 37 |
#include <dune/uggrid/parallel/ddd/dddcontext.hh> |
| 38 |
|
| 39 |
#include <dune/uggrid/parallel/ddd/dddi.h> |
| 40 |
|
| 41 |
|
| 42 |
USING_UG_NAMESPACE |
| 43 |
using namespace PPIF; |
| 44 |
|
| 45 |
START_UGDIM_NAMESPACE |
| 46 |
|
| 47 |
/****************************************************************************/ |
| 48 |
/* */ |
| 49 |
/* data structures */ |
| 50 |
/* */ |
| 51 |
/****************************************************************************/ |
| 52 |
|
| 53 |
/* graph of DDD_TYPEs, with directed edges according to references */ |
| 54 |
|
| 55 |
struct TYPE_EDGE |
| 56 |
{ |
| 57 |
DDD_TYPE reftype; /* referenced type */ |
| 58 |
int n; /* number of references */ |
| 59 |
|
| 60 |
TYPE_EDGE *next; /* linked list */ |
| 61 |
}; |
| 62 |
|
| 63 |
struct TYPE_NODE |
| 64 |
{ |
| 65 |
const TYPE_DESC *def; /* pointer to DDD_TYPE */ |
| 66 |
TYPE_EDGE *refs; /* linked list of referenced types */ |
| 67 |
}; |
| 68 |
|
| 69 |
/****************************************************************************/ |
| 70 |
/* */ |
| 71 |
/* subroutines */ |
| 72 |
/* */ |
| 73 |
/****************************************************************************/ |
| 74 |
|
| 75 |
|
| 76 |
static TYPE_EDGE *GetTypeEdge (TYPE_NODE *tn, DDD_TYPE reftype) |
| 77 |
{ |
| 78 |
TYPE_EDGE *te; |
| 79 |
|
| 80 |
for(te=tn->refs; te!=NULL && te->reftype!=reftype; te=te->next) |
| 81 |
; |
| 82 |
|
| 83 |
if (te==NULL) |
| 84 |
{ |
| 85 |
te = (TYPE_EDGE *)AllocTmp(sizeof(TYPE_EDGE)); |
| 86 |
te->reftype = reftype; |
| 87 |
te->n = 0; |
| 88 |
|
| 89 |
te->next = tn->refs; |
| 90 |
tn->refs = te; |
| 91 |
} |
| 92 |
|
| 93 |
return(te); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
static void AnalyseTypes(const DDD::DDDContext& context) |
| 98 |
{ |
| 99 |
int i; |
| 100 |
|
| 101 |
/* create graph of DDD_TYPE ref-relations */ |
| 102 |
for(i=0; i<DDD_InfoTypes(context); i++) |
| 103 |
{ |
| 104 |
const TYPE_DESC *td = &context.typeDefs()[i]; |
| 105 |
TYPE_NODE tn; |
| 106 |
int e; |
| 107 |
|
| 108 |
tn.def = td; |
| 109 |
tn.refs = NULL; |
| 110 |
|
| 111 |
for(e=0; e<td->nElements; e++) |
| 112 |
{ |
| 113 |
const ELEM_DESC *el = &(td->element[e]); |
| 114 |
|
| 115 |
if (el->type==EL_OBJPTR) |
| 116 |
{ |
| 117 |
TYPE_EDGE *te = GetTypeEdge(&tn, EDESC_REFTYPE(el)); |
| 118 |
te->n += (el->size / sizeof(void *)); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
printf("%4d: type %s (%03d) refs:\n", context.me(), td->name, i); |
| 123 |
{ |
| 124 |
TYPE_EDGE *te; |
| 125 |
for(te=tn.refs; te!=NULL; te=te->next) |
| 126 |
{ |
| 127 |
printf(" %s (%03d), n=%d\n", |
| 128 |
context.typeDefs()[te->reftype].name, te->reftype, te->n); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
/****************************************************************************/ |
| 137 |
|
| 138 |
|
| 139 |
void DDD_GraphicalAnalyser (DDD::DDDContext& context, char *filename) |
| 140 |
{ |
| 141 |
FILE *fp; |
| 142 |
|
| 143 |
fp = fopen(filename, "w"); |
| 144 |
|
| 145 |
if (context.isMaster()) |
| 146 |
{ |
| 147 |
AnalyseTypes(context); |
| 148 |
} |
| 149 |
|
| 150 |
fclose(fp); |
| 151 |
} |
| 152 |
|
| 153 |
END_UGDIM_NAMESPACE |