63 ASSERT(!( problem == NULL ),
"NULL as argument of function output_convert_to_pos()\n");
64 if(
OptGetBool(
"Output",
"Write_output_file",
"no") ==
false )
66 if (ConstantDB::getInstance()->getChar(
"Sources_fname") != NULL)
84 Mesh* mesh = (
Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
88 char* filename = (
char*)ConstantDB::getInstance()->getChar(
"Sources_fname");
95 ASSERT(!( problem == NULL ),
"NULL as argument of function output_convert_to_pos_source()\n");
96 sprintf( dbl_fmt,
"%%.%dg ", ConstantDB::getInstance()->getInt(
"Out_digit"));
97 strcat(filename,
".pos");
98 out =
xfopen( filename,
"wt" );
99 xfprintf( out,
"View \"%s - sources\" {\n",
OptGetStr(
"Global",
"Description",
"No description.") );
102 switch( elm->type ) {
113 for( li = 0; li < elm->
n_nodes; li++ ) {
114 nod = elm->
node[ li ];
125 for( li = 0; li < elm->
n_nodes; li++ ) {
141 Mesh* mesh = (
Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
144 const char *bcd_names[] = {
"Dirichlet",
"Neumann",
"Newton P",
"Newton Sigma"};
148 std::string filename = IONameHandler::get_instance()->get_output_file_name(
OptGetStr(
"Input",
"Boundary",
"\\" ));
156 ASSERT(!( problem == NULL ),
"NULL as argument of function output_convert_to_pos_bcd()\n");
157 sprintf( dbl_fmt,
"%%.%dg ", ConstantDB::getInstance()->getInt(
"Out_digit"));
158 const std::string& file = filename +
".pos";
159 out =
xfopen( file,
"wt" );
160 xfprintf( out,
"View \"%s - mesh\" {\n",
OptGetStr(
"Global",
"Description",
"No description.") );
163 switch( elm->type ) {
174 for( li = 0; li < elm->
n_nodes; li++ ) {
175 nod = elm->
node[ li ];
186 for( li = 0; li < elm->
n_nodes; li++ ) {
195 for (j = 0;j < 4; j++)
199 if (bcd->type == bcd_types[ j ])
206 xfprintf( out,
"View \"%s - bcd %s\" {\n",
OptGetStr(
"Global",
"Description",
"No description."), bcd_names[j] );
209 if (bcd->type != bcd_types[ j ]){
212 switch( bcd->
side->shape ) {
243 case 2:
xfprintf( out, dbl_fmt, bcd->scalar);
break;
244 case 3:
xfprintf( out, dbl_fmt, bcd->sigma);
break;
263 Mesh* mesh = (
Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
267 char* filename = (
char*)ConstantDB::getInstance()->getChar(
"Material_fname");
275 sprintf( dbl_fmt,
"%%.%dg ", ConstantDB::getInstance()->getInt(
"Out_digit"));
277 sprintf( int_fmt,
"%d ", ConstantDB::getInstance()->getInt(
"Out_digit"));
278 strcat( filename,
".pos" );
279 out =
xfopen( filename,
"wt" );
280 xfprintf( out,
"View \"%s - materials\" {\n",
OptGetStr(
"Global",
"Description",
"No description.") );
283 switch( elm->type ) {
294 for( li = 0; li < elm->
n_nodes; li++ ) {
295 nod = elm->
node[ li ];
306 for( li = 0; li < elm->
n_nodes; li++ ) {
491 struct TElement *elements;
497 int li,time_steps,j,id,k,ci;
503 mesh = problem->mesh;
506 sprintf( dbl_fmt,
"%%.%dg ", problem->out_digit );
507 sprintf( filenameo,
"%s",problem->out_fname);
508 sprintf( filenamei,
"%s.tmp",problem->out_fname);
509 out =
xfopen( filenameo,
"wt" );
510 in =
xfopen( filenamei,
"rt" );
513 ASSERT(found,
"Can not find section: VALUES\n");
520 nodes = (
struct Node *)
xmalloc((mesh->max_nod_id + 1)*
sizeof(
struct Node));
521 elements = (
struct TElement *)
xmalloc((mesh->max_elm_id + 1)*
sizeof(
struct TElement));
524 for (li = 0; li <= mesh->max_nod_id; li++){
525 nodes[li].scalar = (
double *)
xmalloc(time_steps*
sizeof(
double));
526 for (j = 0; j < time_steps; j++)
527 nodes[li].scalar[j] = 0;
532 for (li = 0; li <= mesh->max_elm_id; li++){
533 elements[li].scalar = (
double *)
xmalloc( time_steps *
sizeof(
double));
534 elements[li].vector = (
double **)
xmalloc(3 *
sizeof(
double*));
535 for( ci = 0; ci < 3; ci++ )
536 elements[li].
vector[ci] = (
double *)
xmalloc(time_steps *
sizeof(
double));
537 for (j = 0; j < time_steps; j++)
539 elements[li].scalar[j] = 0;
540 for( ci = 0; ci < 3; ci++ )
541 elements[li].
vector[ci][j] = 0;
547 in =
xfopen( filenamei,
"rt" );
549 ASSERT(found,
"Can not find section: VALUES\n");
553 for (li = 0; li < mesh->
n_nodes; li++){
556 value = atof (
xstrtok( NULL) );
557 nodes[id].scalar[j] = value;
565 in =
xfopen( filenamei,
"rt" );
567 ASSERT(found,
"Can not find section: VALUES\n");
570 while(
skip_to(in,
"Elements")){
574 value = atof (
xstrtok( NULL) );
575 elements[id].scalar[j] = value;
576 for( ci = 0; ci < 3; ci++ ) {
577 value = atof (
xstrtok( NULL) );
578 elements[id].vector[ci][j] = value;
587 write_ascii_header(problem,out);
589 for( k = 0; k < 4; k++){
592 xfprintf( out,
"View \"%s - p\" {\n", problem->description );
595 xfprintf( out,
"View \"%s - pc\" {\n", problem->description );
598 xfprintf( out,
"View \"%s - pz\" {\n", problem->description );
601 xfprintf( out,
"View \"%s - u\" {\n", problem->description );
608 switch( ele->type ) {
619 for( li = 0; li < ele->
n_nodes; li++ ) {
620 nod = ele->
node[ li ];
632 for( li = 0; li < time_steps; li++ ) {
633 for(j = 0; j < ele->
n_nodes; j++){
636 nod = ele->
node[ j ];
637 xfprintf( out, dbl_fmt,nodes[nod->id].scalar[li]);
640 xfprintf( out, dbl_fmt,elements[ele->
id].scalar[li]);
646 if( li == time_steps - 1 && j == ele->
n_nodes - 1)
666 for( li = 0; li < time_steps; li++ ){
667 xfprintf( out, dbl_fmt, elements[ele->
id].vector[ 0 ][li] );
669 xfprintf( out, dbl_fmt, elements[ele->
id].vector[ 1 ][li] );
671 xfprintf( out, dbl_fmt, elements[ele->
id].vector[ 2 ][li] );
672 if( li == time_steps - 1)
693 static void write_transport_ascii_data(FILE *out,
struct Problem *problem,
struct Node **nodes,
struct TElement **elements,
int time_steps,
int ph)
695 int k,sbi,li,j,n_subst_;
700 double norm,vconc[3];
702 n_subst_ = problem->transport->n_subst_;
703 mesh = problem->mesh;
704 sprintf( dbl_fmt,
"%%.%dg ", problem->out_digit );
706 write_ascii_header(problem, out);
708 for( k = 0; k < 2; k++){
709 for( sbi = 0; sbi < n_subst_; sbi++ ) {
711 xfprintf( out,
"View \"Concentration in %s of %s\" {\n",
712 (k == 0) ?
"node" :
"element",problem->transport->subst_names_[ sbi ] );
716 switch( ele->type ) {
728 nod = ele->
node[ li ];
740 for( li = 0; li < time_steps; li++ ) {
744 nod = ele->
node[ j ];
745 xfprintf( out, dbl_fmt,nodes[ph][nod->id].conc[sbi][li]);
748 xfprintf( out, dbl_fmt,elements[ph][ele->
id].conc[sbi][li]);
751 if( li == time_steps - 1 && j == ele->
n_nodes - 1)
762 if((ph == 0) & (k == 1) & (problem->type == STEADY_SATURATED)){
763 xfprintf( out,
"View \"Concentration vector of %s\" {\n",
764 problem->transport->subst_names_[ sbi ] );
775 vconc[0] = ele->vector[0]/norm; vconc[1] = ele->vector[1]/norm; vconc[2] = ele->vector[2]/norm;
779 for( li = 0; li < time_steps; li++ ){
780 xfprintf( out, dbl_fmt, elements[ph][ele->
id].conc[sbi][li] * vconc[0]);
782 xfprintf( out, dbl_fmt, elements[ph][ele->
id].conc[sbi][li] * vconc[1]);
784 xfprintf( out, dbl_fmt, elements[ph][ele->
id].conc[sbi][li] * vconc[2]);
785 if( li == time_steps - 1)
802 static void write_transport_binary_data(FILE *out,
struct Problem *problem,
struct Node **nodes,
struct TElement **elements,
int time_steps,
int ph)
804 int k,sbi,i,li,j,n_subst_;
809 double norm,vconc[3],vconct[3];
811 n_subst_ = problem->transport->n_subst_;
812 mesh = problem->mesh;
815 xfprintf(out,
"%g %d %d\n", 1.4, 1,
sizeof(
double));
818 for( k = 0; k < 2; k++){
819 for( sbi = 0; sbi < n_subst_; sbi++ ) {
820 xfprintf( out,
"$View\nConcentration^in^%s^of^%s ",
821 (k == 0) ?
"node" :
"element",problem->transport->subst_names_[ sbi ] );
825 xfwrite(&one,
sizeof(
int), 1, out);
827 for(li=0;li<time_steps;li++){
828 xfwrite(&ts,
sizeof(
double), 1, out);
834 write_elm_position_to_binary_output(ele,out);
835 for( j = 0; j < time_steps; j++ )
837 xfwrite( (k==0) ? &nodes[ph][ele->
node[li]->id].conc[sbi][j] :
838 &elements[ph][ele->
id].conc[sbi][j],
sizeof(
double),1,out);
844 for( sbi = 0; sbi < n_subst_; sbi++ ) {
845 xfprintf( out,
"$View\nConcentration^vector^of^%s ",problem->transport->subst_names_[ sbi ] );
846 xfprintf(out,
"%d 0 %d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",time_steps,mesh->
n_elements());
847 xfwrite(&one,
sizeof(
int), 1, out);
849 for(li=0;li<time_steps;li++){
850 xfwrite(&ts,
sizeof(
double), 1, out);
857 vconc[0] = ele->vector[0]/norm; vconc[1] = ele->vector[1]/norm; vconc[2] = ele->vector[2]/norm;
861 for( j = 0; j < time_steps; j++ ){
862 vconct[0] = vconc[0] * elements[ph][ele->
id].conc[sbi][j];
863 vconct[1] = vconc[1] * elements[ph][ele->
id].conc[sbi][j];
864 vconct[2] = vconc[2] * elements[ph][ele->
id].conc[sbi][j];
865 xfwrite(&vconct[0],
sizeof(
double),3,out);
875 void output_transport_convert(
struct Problem *problem){
877 Mesh* mesh = problem->mesh;
879 struct TElement** elements;
882 int li,time_steps,j,id,ph;
885 int n_subst_ = problem->transport->n_subst_;
890 elements = (
struct TElement**)
xmalloc((4)*
sizeof(
struct TElement*));
894 out =
open_temp_files(problem->transport,
"%s", (problem->pos_format_id == GMSH_MSH_ASCII) ?
"wt" :
"wb" );
898 found=
skip_to(in[0],
"VALUES");
899 ASSERT(found ,
"Can not find section: VALUES\n");
904 for(ph = 0; ph < 4; ph++){
907 nodes[ph] = (
struct Node *)
xmalloc((mesh->max_nod_id + 1)*
sizeof(
struct Node));
908 elements[ph] = (
struct TElement *)
xmalloc((mesh->max_elm_id + 1)*
sizeof(
struct TElement));
914 for (li = 0; li <= mesh->max_nod_id; li++){
915 nodes[ph][li].conc = (
double **)
xmalloc(n_subst_ *
sizeof(
double*));
916 for( sbi = 0; sbi < n_subst_; sbi++ )
917 nodes[ph][li].conc[sbi] = (
double *)
xmalloc(time_steps*
sizeof(
double));
918 for( sbi = 0; sbi < n_subst_; sbi++ )
919 for (j = 0; j < time_steps; j++)
920 nodes[ph][li].conc[sbi][j] = 0;
923 for (li = 0; li <= mesh->max_elm_id; li++){
924 elements[ph][li].conc = (
double **)
xmalloc(n_subst_ *
sizeof(
double*));
925 for( sbi = 0; sbi < n_subst_; sbi++ )
926 elements[ph][li].conc[sbi] = (
double *)
xmalloc(time_steps*
sizeof(
double));
927 for( sbi = 0; sbi < n_subst_; sbi++ )
928 for (j = 0; j < time_steps; j++)
929 elements[ph][li].conc[sbi][j] = 0;
935 found=
skip_to(in[ph],
"VALUES");
936 ASSERT(found,
"Can not find section: VALUES\n");
940 while(
skip_to(in[ph],
"Nodes")){
941 for (li = 0; li < mesh->
n_nodes; li++){
944 for( sbi = 0; sbi < n_subst_; sbi++ ) {
945 value = atof (
xstrtok( NULL) );
946 nodes[ph][id].conc[sbi][j] = value;
957 found=
skip_to(in[ph],
"VALUES");
958 ASSERT(found,
"Can not find section: VALUES\n");
961 while(
skip_to(in[ph],
"Elements")){
965 for( sbi = 0; sbi < n_subst_; sbi++ ) {
966 value = atof (
xstrtok( NULL) );
967 elements[ph][id].conc[sbi][j] = value;
974 xprintf(
Msg,
"Writing transport output files... ");
975 switch(problem->pos_format_id){
977 write_transport_ascii_data(out[ph],problem,nodes,elements,time_steps,ph);
980 write_transport_binary_data(out[ph],problem,nodes,elements,time_steps,ph);