Flow123d
reaction.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @ingroup transport
27  * @brief Reactions
28  * Read input data and perform reaction computation
29  *
30  */
31 
32 #include "transport/transport.h"
33 
34 #include "system/system.hh"
35 #include "xio.h"
36 #include "mesh/mesh.h"
37 #include "reaction.h"
38 #include "materials.hh"
39 #include "elements.h"
40 
41 //=============================================================================
42 // TRANSPORT REACTION
43 /*! @brief MAIN REACTION COMPUTATION (zero order)
44  *
45  * input{Transport,elm_pos,sbi}
46  * perform reaction computation on element with elm_pos position
47  *
48  */
49 //=============================================================================
50 void oReaction::transport_reaction( double time_step,double ***conc, double ***pconc,int elm_pos, MaterialDatabase::Iter material, int sbi)
51 {
52  Mesh* mesh = (Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
53 
54  //struct Reaction *rct;
55  int i;
56  // double ***conc=transport->conc,***pconc=transport->pconc;
57 
58  // TODO: remove epos_id, find_id
59  //for(i=0;i < transport->n_reaction;i++){
60  // rct = &transport->reaction[i];
61  switch(type){
62  case 0:
63  if(substancei != sbi)
64  break;
65  if(coef[0] != -1.0){
66  conc[MOBILE][substancei][elm_pos] += coef[0] * time_step;
67  pconc[MOBILE][substancei][elm_pos] = conc[MOBILE][substancei][elm_pos];
68  // printf("%f\t%f\n",rct->coef[0],transport->time_step);
69  // getchar();
70  }
71  else{
72  conc[MOBILE][substancei][elm_pos] += 1/(material->size);
73  pconc[MOBILE][substancei][elm_pos] = conc[MOBILE][substancei][elm_pos];
74  }
75  break;
76  }
77  // }
78 }
79 //=============================================================================
80 // PARSE REACTION LINE
81 /*! @brief PARSE REACTION LINE
82  *
83  * input{Transport,reaction_number,line}
84  *
85  */
86 //=============================================================================
88 {
89  int ci,pc; // si - substance index
90  oReaction *oreact;
91  //struct Reaction *rct;
92  //rct = &transport->reaction[i];
93 
94  oreact = new oReaction();
95 
96  rct->type = atoi( xstrtok( line) );
97  if(supported_reaction_type(rct->type) == true)
99  else
100  xprintf(UsrErr,"Unsupported reaction type #%d.\n", rct->type);
101 
102  rct->sbi = atoi( xstrtok( NULL) );
103  INPUT_CHECK(!(rct->sbi > transport->n_subst_ - 1),"Unknown substance ID#%d.\n", rct->sbi);
104 
105  rct->coef = (double*)xmalloc(pc * sizeof(double));
106  for(ci = 0 ; ci < pc ; ci++)
107  rct->coef[ci] = atof( xstrtok( NULL) );
108 }
109 //=============================================================================
110 // SUPPORTED REACTION TYPE
111 /*! @brief SUPPORTED REACTION TYPE
112  *
113  * input{reaction_type}
114  *
115  */
116 //=============================================================================
118 {
119  switch (st) {
120  case 0:
121  return true;
122  }
123  return false;
124 }
125 //=============================================================================
126 // REACTION TYPE SPECIFIC COEFFICIENTS
127 /*! @brief REACTION TYPE SPECIFIC COEFFICIENTS
128  *
129  * input{reaction_type}
130  *
131  */
132 //=============================================================================
134 {
135  switch (st) {
136  case 0:
137  return 1;
138  }
139  return -1;
140 }
141 //=============================================================================
142 // READ REACTIONS LIST
143 /*! @brief READ REACTIONS LIST FROM *.MTR FILE
144  *
145  * input{Transport}
146  *
147  */
148 //=============================================================================
149 void read_reaction_list( struct Transport *transport )
150 {
151  Mesh* mesh = (Mesh*) ConstantDB::getInstance()->getObject(MESH::MAIN_INSTANCE);
152 
153  FILE* in; // input file
154  char line[ LINE_SIZE ],string[ LINE_SIZE ]; // line of data file
155  bool found;
156  int ki,r,i;
157 
158  ASSERT(!( mesh == NULL ),"NULL as argument of function read_reaction_list()\n");
159  xprintf( Msg, "Reading reactions... ")/*orig verb 2*/;
160  in = xfopen( ConstantDB::getInstance()->getChar("Material_fname"), "rt" );
161  found=skip_to( in, "$Reactions" );
162  ASSERT( found , "Can not find section: $Reactions." );
163  xfgets( line, LINE_SIZE - 2, in );
164  sscanf( line, "%s", string ); //test
165  r = 0;
166 
167  while ((strcmp(string,"$EndReactions")) != 0){
168  r++;
169  xfgets( line, LINE_SIZE - 2, in );
170  sscanf( line, "%s", string ); //test
171  }
172 
173  transport->n_reaction = r;
174  ASSERT(!( r == 0 ),"No reaction haven't defined\n");
175  transport->reaction =(struct Reaction*)xmalloc(transport->n_reaction * sizeof(struct Reaction));
176  xfclose( in );
177 
178  in = xfopen( ConstantDB::getInstance()->getChar("Material_fname"), "rt" );
179  skip_to( in, "$Reactions" );
180  for(i=0;i<transport->n_reaction;i++){
181  xfgets( line, LINE_SIZE - 2, in );
182  parse_reaction_line(transport, i ,line );
183  }
184  xfclose( in );
185 }