Adding new particle parameters

Miscellaneous discussion topics about Code_Saturne (development, ...)
Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Adding new particle parameters

Post by Miguel » Thu Apr 02, 2020 3:06 pm

Hello,
I shall try to make a brief summary of my consultation and the process that I am doing.
1.- I am working on Code_Saturne V 5.0.10
2.- I am developing a new fouling model for my PhD Thesis about biomass boilers.
3.- My intention is to create a new fouling model independent from the existing one linked to the coal combustion.
Although I write the code for self explanation, I attach all the subroutines files.

in file .xml
<particles_models model="thermal">
<coal_fouling status="off"/> ( Note: the former fouling model is off)
<evaporation status="off"/>
<thermal status="on"/>
<depox_fouling status="on"/> ( I have added a new one with status on)
</particles_models>

and in the boundary conditions:

<wall field_id="none" label="BC_10">
<particles choice="foulwall"/> ( Note:foulwall instead of the former "fouling")
<velocity_pressure choice="off"/>
</wall>

These new parameters are declared in cs_lagr.h :

typedef enum {

CS_LAGR_INLET = 1,
CS_LAGR_OUTLET = 2,
CS_LAGR_REBOUND = 3,
CS_LAGR_DEPO1 = 4,
CS_LAGR_DEPO2 = 5,
CS_LAGR_DEPOX = 25, (new bc type)
CS_LAGR_FOULING = 7,
CS_LAGR_JBORD1 = 8,
CS_LAGR_JBORD2 = 9,
CS_LAGR_JBORD3 = 10,
CS_LAGR_JBORD4 = 11,
CS_LAGR_JBORD5 = 12,
CS_LAGR_DEPO_DLVO = 13,
CS_LAGR_SYM = 14

} cs_lagr_bc_type_t;

...............................and:

static cs_lagr_model_t _lagr_model
= {.physical_model = 0,
.n_temperature_layers = 1,
.deposition = 0,
.dlvo = 0,
.roughness = 0,
.resuspension = 0,
.clogging = 0,
.consolidation = 0,
.precipitation = 0,
.fouling = 0,
.depox = 0, (Note: this is the new model name)
.n_stat_classes = 0,
.n_user_variables = 0};

and in cs_gui_particles.c:

else if( cs_gui_strcmp(interaction, "foulwall"))//mdt incluido un nuevo tipo
{
bdy_cond->b_zone_natures[izone] = CS_LAGR_DEPOX;
printf("L887 cs_gui La zona nº:%d es faulwall\n", izone); // for tracking
}

4.- So, the chemical ash composition will be data implemented into the xml file in DATA folder.
5.- This chemical information is placed into the particle data, between the <class> marks.

<class>
<density>1000</density>
<diameter choice="prescribed">0.0001</diameter>
<diameter_standard_deviation>1e-05</diameter_standard_deviation>
<emissivity>0.9</emissivity>
<fouling_index>1.2</fouling_index>
<frequency>1</frequency>
<mass_flow_rate>0</mass_flow_rate>
<number>2</number>
<specific_heat>1400</specific_heat>
<statistical_groups>0</statistical_groups>
<statistical_weight choice="prescribed">12</statistical_weight>
<temperature choice="prescribed">1200</temperature>
<velocity choice="fluid"/>
<ashclk>0.45</ashclk>
<ashna2o>0.18</ashna2o>
<ashsio2>0.31</ashsio2>
<ashal2o3>0.195</ashal2o3>
<ashfe2o3>0.0485</ashfe2o3>
<ashcao>0.12</ashcao>
<ashmgo>0.1</ashmgo>
</class>

6.- The new parameters added are recovered quite well by modifying the subroutine cs_gui_particles.c

_get_status(&(cs_glob_lagr_model->depox), 3, "lagrangian", "particles_models", "depox_fouling");
printf("L1083 gui_part particles_Depox model :%d\n ", cs_glob_lagr_model->depox); // for tracking

if ( cs_glob_lagr_model->depox == 1) {

cs_real_t ashclk;
cs_real_t ashna2o;
cs_real_t ashal2o3;
cs_real_t ashfe2o3;
cs_real_t ashcao;
cs_real_t ashmgo;
cs_real_t ashsio2;
cs_real_t ashenc1=0.0;
cs_real_t ashenc2=0.0;

_get_double(&ashclk, 2, path2, "ashclk"); // ClK in ash mdt
_get_double(&ashna2o, 2, path2, "ashna2o"); // etc..
_get_double(&ashsio2, 2, path2, "ashsio2");
_get_double(&ashal2o3, 2, path2, "ashal2o3");
_get_double(&ashfe2o3, 2, path2, "ashfe2o3");
_get_double(&ashcao, 2, path2, "ashcao");
_get_double(&ashmgo, 2, path2, "ashmgo");

ashenc1 = 0.00835*ashsio2*100.0+0.00601*ashal2o3*100.0-0.109;
ashenc2 = 0.0415*ashsio2*100.0+0.0192*ashal2o3*100.0+0.0276*ashfe2o3*100.0+0.016*ashcao*100.0-3.92;

cs_lagr_set_zone_class_ash(iclas,
izone,
ashclk,
ashna2o,
ashal2o3,
ashfe2o3,
ashcao,
ashmgo,
ashsio2,
ashenc1,
ashenc2);


printf("\n L1100 gui_particles:\n"); // for tracking: everything is ok
printf("ashclk: %2.2f\n", ashclk);
printf("ashna2o: %2.2f\n", ashna2o);
printf("ashsio2: %2.2f\n", ashsio2);
printf("ashal2o3: %2.2f\n", ashal2o3);
printf("ashfe2o3: %2.2f\n", ashfe2o3);
printf("ashcao: %2.2f\n", ashcao);
printf("ashmgo: %2.2f\n", ashmgo);
printf("ashenc1: %2.3f\n", ashenc1);
printf("ashenc2: %2.3f\n", ashenc2);


}

7. Afterwards, I think it is necessary to pass this information to the cs_lagr_injection.c subroutine

Declaring and asigning:

double clk = userdata->ashclk;
double na2o = userdata->ashna2o;
double al2o3 = userdata->ashal2o3;
double fe2o3 = userdata->ashfe2o3;
double cao = userdata->ashcao;
double mgo = userdata->ashmgo;
double sio2 = userdata->ashsio2;
double enc1 = userdata->ashenc1;
double enc2 = userdata->ashenc2;

previously, we have built in cs_lagr.c the void function:

void
cs_lagr_set_zone_class_ash(int iclas,
int izone,
cs_real_t ashclk,
cs_real_t ashna2o,
cs_real_t ashal2o3,
cs_real_t ashfe2o3,
cs_real_t ashcao,
cs_real_t ashmgo,
cs_real_t ashsio2,
cs_real_t ashenc1,
cs_real_t ashenc2)
{
cs_lagr_zone_class_data_t *zonedata = cs_lagr_get_zone_class_data(iclas, izone);
zonedata->ashclk = ashclk;
zonedata->ashna2o = ashna2o;
zonedata->ashal2o3 = ashal2o3;
zonedata->ashfe2o3 = ashfe2o3;
zonedata->ashcao = ashcao;
zonedata->ashmgo = ashmgo;
zonedata->ashsio2 = ashsio2;
zonedata->ashenc1 = ashenc1;
zonedata->ashenc2 = ashenc2;
}

Coefficients enc1 and enc2 calculated are properly recovered in cs_lagr_injection.c

We have to include the new variables declaration in former typdef struct: " cs_lagr_zone_class_data_t" into cs_lagr.h

typedef struct {

/*! ashclk */
cs_real_t ashclk;

/*! ashna2o */
cs_real_t ashna2o;

/*! ashnsio2 */
cs_real_t ashsio2;

/*! ashal2o3 */
cs_real_t ashal2o3;

/*! ashfe2o3 */
cs_real_t ashfe2o3;

/*! ashcao */
cs_real_t ashcao;

/*! ashmgo */
cs_real_t ashmgo;

/*! enc1 calculated */
cs_real_t ashenc1;

/*! enc2 calculated */
cs_real_t ashenc2;

} cs_lagr_zone_class_data_t;

So far, so good.

8.- The problem comes when I try to work with parameters enc1 and enc2 in cs_lagr:tracking,c. Once a particle arrives at a BC zone, a model should be applied (clogging, fouling, dvlo, and my new one "depox").
For calculating the viscosity of the particle, I need to get previously enc1, enc2 and particle temperature.
Particle temperature is read easily by:

cs_real_t particle_temp = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_TEMPERATURE);

however, if I try to get in the same way enc1 by:

cs_real_t particle_enc1 = cs_lagr_particle_get_real(particle, p_am, CS_LAGR_ENC1);

it faults.
Previously, I have includded in cs_particle.h:
typedef enum {
.....................

/* depox fouling additional parameters */
CS_LAGR_ASHENC1,
CS_LAGR_ASHENC2,
...................
} cs_lagr_attribute_t;

and in cs_particle.c:

void
cs_lagr_particle_attr_initialize(void)
{
.................................................
attr_keys[CS_LAGR_ASHENC1][1] = ++loc_count;
attr_keys[CS_LAGR_ASHENC2][1] = ++loc_count;
.........................................................

I have followed same structure of syntax like other similar parameters for example specific heat:

attr_keys[CS_LAGR_CP][1] = ++loc_count;

It does not work with these modifications. I have made a massive search of other similar parameter (CS_LAGR_CP) along all the subroutines included in SCR folder.
I think that I have modified all what i saw.

Sure that I forgot to declare / define fuction / etc., but i can not see it.
Please, if you miss any information, let me know.
Please could you help me in this topic. I think once I solve it, only writting and post process will remain.
I enclose whole the collection of related subroutines.
Thanks in advance.

Miguel Diaz
Attachments
cs_lagr.h
(49.97 KiB) Downloaded 6 times
cs_lagr.c
(85.72 KiB) Downloaded 5 times
cs_gui_particles.c
(41.63 KiB) Downloaded 5 times

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Thu Apr 02, 2020 4:08 pm

Sorry,
I forgot to indicate that the error after compiling modified subroutines is the following:

// quote:
cs_lagr_injection.c:1218:46: error: ‘CS_LAGR_ASHENC1’ undeclared (first use in this function); did you mean ‘CS_LAGR_USER’?
cs_lagr_particle_set_real(particle, p_am, CS_LAGR_ASHENC1, userdata->ashenc1);
^~~~~~~~~~~~~~~
CS_LAGR_USER

//unquote
I think I have them declared, but I can not see maybe a "hidden" code for it.

Yvan Fournier
Posts: 2930
Joined: Mon Feb 20, 2012 3:25 pm

Re: Adding new particle parameters

Post by Yvan Fournier » Thu Apr 02, 2020 11:13 pm

Hello,

I did not see any obvious error in your description. Do you have a crash or incorrect behavior ?

You did not post your modified cs_lagr_particle.h. I assume you added the attributes there also.
Can you confirm that you modified the code in the base source tree, not just in a case's SRC, since you have modifed headers. ?

Also, did you run using a debug build ? For particle attributes, debug builds have assert() statements at every particle attribute access, so in case there is a mapping error (the most probable issue), it should be relatively easy to spot.

If you already took these precautions, then the first place where the code faults is probably the root error, and not some indirect consequence, so it would seem to confirm a mapping error. Also testing with Valgrind is even better.

Your mapping using attr_keys seems OK, but I do not remember if you need to do other steps in the following passes, so double-checking is always good.

Also, there have been quite a few cleanup operations of the code in v6.0, including for the handling of particle boundary interaction. The code is still too messy for my taste, but a bit cleaner that of v5 (so should be less bug-prone)...

Best regards,

Yvan

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Thu Apr 16, 2020 4:32 pm

Thanks Ivan for your reply,
I couldn't find the mistake, so I had to give up. Fortunately, I solved the problem by other way. I created a set of data similar to the existing "coal classes", but linked to the particle class attributes.

<depox_fouling status="on">

<ashclk coal="1">0.45</ashclk>
<ashna2o coal="1">0.18</ashna2o>
<ashsio2 coal="1">0.31</ashsio2>
<ashal2o3 coal="1">0.195</ashal2o3>
<ashfe2o3 coal="1">0.0485</ashfe2o3>
<ashcao coal="1">0.12</ashcao>
<ashmgo coal="1">0.1</ashmgo>

<ashclk coal="2">0.46</ashclk>
<ashna2o coal="2">0.12</ashna2o>
<ashsio2 coal="2">0.29</ashsio2>
<ashal2o3 coal="2">0.18</ashal2o3>
<ashfe2o3 coal="2">0.03</ashfe2o3>
<ashcao coal="2">0.10</ashcao>
<ashmgo coal="2">0.09</ashmgo>

</depox_fouling>

I could get the values correctly in cs_gui_particles.c, I could capture the former calculated enc1 and enc2 parameters of each particle class and could calculate the particle viscosity. So far, so good.

My current problem is for exporting new parameters to post process. I have tried for one extra parameter and it worked, but not with the second one. The process that I have followed has been:

1.- In cs_lagr_tracking.c:

bound_stat[ cs_glob_lagr_boundary_interactions->iviscp * n_b_faces + face_id] = viscp;

"viscp" is the name of the variable of particle viscosity.

2.- In cs_lagr.h, I included int iviscp; in the structure cs_lagr_boundary_interactions_t;
3.- In cs_lagr.c. I included .iviscp = -1, in

static cs_lagr_boundary_interactions_t _cs_glob_lagr_boundary_interactions
= {.nusbor = 0,
.npstf = 0, etc........
.iviscp = -1, (this for the new variable)
4.-In cs_lagr_options.c: Initialization:
cs_glob_lagr_boundary_interactions->iviscp = 0;
and:

irf++;
cs_glob_lagr_boundary_interactions->iviscp = irf;
_copy_boundary_varname(irf, "Part_viscosity");
cs_glob_lagr_boundary_interactions->imoybr[irf] = 1;

5.- I have realized that it is not necessary to write in xml file the corresponding name of new variable in <statistics>:

<statistics>

<boundary status="on">
<iteration_start_boundary>500</iteration_start_boundary>
<property name="Part_bndy_mass_flux"/>
<property name="Part_fouled_Xck"/>
<property name="Part_fouled_diam"/>
<property name="Part_fouled_impact_number"/>
<property name="Part_fouled_mass_flux"/>
<property name="Part_impact_angle"/>
<property name="Part_impact_number"/>
<property name="Part_impact_velocity"/>
<property name="Part_viscosity"/> <!-- the first extra variable-->
<property name="Part_kin_energy"/> <!--the second extra variable -->
<threshold_boundary>0</threshold_boundary>
</boundary>
I am not quite sure of this.

Compilation is ok with the second variable but solver is interrupted in iteration number 10. I enclose the cited files in case you need to track the error.
Is there any tutorial or work related with my consultation. Unfortunately, I have not found it.
Thank you in advance.
Miguel
Attachments
cs_lagr.c
(84.52 KiB) Downloaded 6 times
cs_lagr.h
(48.46 KiB) Downloaded 4 times
cs_lagr_tracking.c
(121.79 KiB) Downloaded 7 times

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Thu Apr 16, 2020 4:34 pm

I enclose the remaining files.
Attachments
bankitolagr01.xml
(13.94 KiB) Downloaded 7 times
cs_lagr_options.c
(97.35 KiB) Downloaded 6 times

Yvan Fournier
Posts: 2930
Joined: Mon Feb 20, 2012 3:25 pm

Re: Adding new particle parameters

Post by Yvan Fournier » Thu Apr 16, 2020 5:27 pm

Hello,

Iteration 10 is your last define iteration, so if you only defined postprocessing at the last iteration, you probably crash there.

But you did not post your log files, so I cannot confirm.

Did you run under a debugger to better analyze what is going on ?

There is a tutorial for Lagrangian coal combustion, but just for general usage, not for more advanced things like modifying the model. In general, there is some course material oriented towards debugging and general recommendations, but no specific development tutorial as the probability that the tutorial would match what a specific user needs to do is close to zero, and keeping them up to date would be almost impossible.

Best regards,

Yvan

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Thu Apr 30, 2020 5:41 pm

Hello Ivan,
In the case I add a new parameter (CS_LAGR_VISCP) to cs_lagr_attribute_t structure, which file or files in base folder must I modify?
I think that "base source tree" that you mentioned in your former reply means "base" folder belonging to src folder. Please confirm.
In SRC I have modified: cs_particle.h, cs_particle.c, cs_lagr_options.c, cs_gui_particles.c, cs_lagr_injection.c and cs_lagr_tracking for calculating this parameter.
I have also modified cs_lagr_stat.c and cs_lagr_restart for writing and postprocessing purposes.
Always appears the same compilation error: ‘CS_LAGR_VISCP’ undeclared (first use in this function);
Do you need I send the referred subroutines?
Thanks in advance
Miguel

Yvan Fournier
Posts: 2930
Joined: Mon Feb 20, 2012 3:25 pm

Re: Adding new particle parameters

Post by Yvan Fournier » Thu Apr 30, 2020 10:52 pm

Hello,

Yes, the source tree is the "src" directory of the code distribution (actually, the whole directory tree; scripts and the GUI are alos part of the code sources, though not the subject here).

Yes, it would be clearer with the routines.

As a general rule, if you are modifying .h files, unless you are simply adding new structures or values (not inserting them), never use a different version of the .h file in the installed source tree an in a case's SRC folder. So if you need to change a .h file, you need to recompile/install the whole code with the modifed version.

Best regards,

Yvan

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Fri May 01, 2020 5:24 pm

Thanks so much!
I shall keep you informed on my new trial
Thanks

Miguel
Posts: 8
Joined: Fri Sep 19, 2014 6:11 pm

Re: Adding new particle parameters

Post by Miguel » Fri May 01, 2020 5:32 pm

I shall prepare the set of modified subroutines for sending.

Post Reply