|
[Sponsors] |
January 13, 2020, 12:34 |
access PtrList from chemistryModel
|
#1 |
Member
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 7 |
Hi all,
I created a PtrList to create multiple volScalarField in createFields.H The code looks like this: (in createFields.H) Code:
label N = 325; PtrList<volScalarField> kf(N); for(int i = 0; i < N; i++) { word kfi ("kf" + name(i)); kf.set ( i, new volScalarField ( IOobject ( kfi, runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar(kfi, dimless, 0.0) ) ); } currently my code looks like below in chemistryModel.c Code:
word kfi ("kf" + name(i)); volScalarField tkf = mesh1.lookupObject<volScalarField>(kfi); tkf[celli] = R.kf(pkf, Tkf, c2); What should I do to modify the "kfi" values globally. |
|
January 14, 2020, 06:12 |
|
#2 |
Senior Member
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15 |
Hello,
You have created local variable volScalarField. You need to use reference to original volScalarField then only it will be updated globally. Regards, -Yogesh |
|
January 14, 2020, 07:36 |
|
#3 |
Member
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 7 |
I tried like this
Code:
const volScalarField& tkf = mesh1.lookupObject<volScalarField>(kfi); tkf[celli] = R.kf(pkf, Tkf, c2); Code:
lnInclude/chemistryModel.C: In instantiation of ‘Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve(const DeltaTType&) [with DeltaTType = Foam::Field<double>; CompType = Foam::psiChemistryModel; ThermoType = Foam::constTransport<Foam::species::thermo<Foam::hConstThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >; Foam::scalar = double]’: lnInclude/chemistryModel.C:1079:43: required from ‘Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve(const scalarField&) [with CompType = Foam::psiChemistryModel; ThermoType = Foam::constTransport<Foam::species::thermo<Foam::hConstThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >; Foam::scalar = double; Foam::scalarField = Foam::Field<double>]’ chemistrySolver/chemistrySolver/makeChemistrySolvers.C:91:1: required from here lnInclude/chemistryModel.C:929:13: error: assignment of read-only location ‘(& tkf)->Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam::DimensionedField<double, Foam::volMesh>::<anonymous>.Foam::Field<double>::<anonymous>.Foam::List<double>::<anonymous>.Foam::UList<T>::operator[]<double>(celli)’ Then I tried like this Code:
volScalarField& tkf = mesh1.lookupObject<volScalarField>(kfi); Code:
lnInclude/chemistryModel.C: In instantiation of ‘Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve(const DeltaTType&) [with DeltaTType = Foam::Field<double>; CompType = Foam::psiChemistryModel; ThermoType = Foam::constTransport<Foam::species::thermo<Foam::hConstThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >; Foam::scalar = double]’: lnInclude/chemistryModel.C:1079:43: required from ‘Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve(const scalarField&) [with CompType = Foam::psiChemistryModel; ThermoType = Foam::constTransport<Foam::species::thermo<Foam::hConstThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >; Foam::scalar = double; Foam::scalarField = Foam::Field<double>]’ chemistrySolver/chemistrySolver/makeChemistrySolvers.C:91:1: required from here lnInclude/chemistryModel.C:917:62: error: invalid initialization of reference of type ‘Foam::volScalarField& {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&}’ from expression of type ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ |
|
January 14, 2020, 08:11 |
|
#4 |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14 |
lookupObjectRef
|
|
January 14, 2020, 08:26 |
|
#5 |
Member
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 7 |
I think lookupObjectRef is available only in latest versions. I use version 2.4 because the solver was previously written in this version 2.4
|
|
January 14, 2020, 09:47 |
|
#6 |
Member
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 93
Rep Power: 14 |
oh, that is too old. There might be a better solution but I think you can use const_cast. sth like this const_cast<volScalarField&>(tkf)[celli] ....
|
|
January 15, 2020, 07:17 |
|
#7 |
Member
ssa
Join Date: Sep 2018
Posts: 93
Rep Power: 7 |
Thanks Hosein. const_cast solved the problem.!!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[DesignModeler] DesignModeler Scripting: How to get Full Command Access | ANT | ANSYS Meshing & Geometry | 53 | February 16, 2020 15:13 |
Why is access to turbulence fields provided as const? | mrishi | OpenFOAM Programming & Development | 3 | January 23, 2020 12:51 |
Is there a way to access the gradient limiter in Fluent ? | CFDYourself | FLUENT | 1 | February 16, 2016 05:49 |
Temperature linearly rising after restarting a simulation | Gennaro | OpenFOAM Programming & Development | 2 | September 2, 2014 07:58 |
Newbie Question on PtrList usage | chyczewski | OpenFOAM Programming & Development | 6 | October 1, 2013 16:39 |