Skip to content

Commit

Permalink
[98] Variable modifications
Browse files Browse the repository at this point in the history
Remove possibility to create variables using unicode caracters (greek
alphabet, sum, prod and sqrt).
Generated code and LaTeX view are unchanged or equivalent.

Bug: cea-hpc#98
Signed-off-by: Vincent BLAIN <[email protected]>
  • Loading branch information
vblainobeo committed Oct 4, 2022
1 parent 903a0ad commit de37f35
Show file tree
Hide file tree
Showing 210 changed files with 8,836 additions and 8,880 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ import static extension fr.cea.nabla.ir.generator.Utils.*
import static extension fr.cea.nabla.ir.generator.java.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.java.InstructionContentProvider.*

class JobContentProvider
{
static def getContent(Job it)
class JobContentProvider
{
static def getContent(Job it)
'''
«comment»
protected void «codeName»()
{
«innerContent»
}
'''
private static def dispatch CharSequence getInnerContent(Job it)
«comment»
protected void «codeName»()
{
«innerContent»
}
'''
private static def dispatch CharSequence getInnerContent(Job it)
'''
«instruction.innerContent»
'''
«instruction.innerContent»
'''
private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ import static extension fr.cea.nabla.ir.JobCallerExtensions.*
import static extension fr.cea.nabla.ir.generator.python.ExpressionContentProvider.*
import static extension fr.cea.nabla.ir.generator.python.InstructionContentProvider.*

class JobContentProvider
{
static def getContent(Job it)
class JobContentProvider
{
static def getContent(Job it)
'''
"""
Job «Utils.getCodeName(it)» called @«at» in «Utils.getCodeName(caller)» method.
In variables: «FOR v : inVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
Out variables: «FOR v : outVars.sortBy[name] SEPARATOR ', '»«v.getName»«ENDFOR»
"""
def _«Utils.getCodeName(it)»(self):
«innerContent»
'''

private static def dispatch CharSequence getInnerContent(Job it)
def _«Utils.getCodeName(it)»(self):
«innerContent»
'''

private static def dispatch CharSequence getInnerContent(Job it)
'''
«instruction.innerContent»
'''
«instruction.innerContent»
'''

private static def dispatch CharSequence getInnerContent(ExecuteTimeLoopJob it)
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fr.cea.nabla.ir.ir.TimeVariable

import static extension fr.cea.nabla.ir.IrRootExtensions.*

class ReplaceUtf8Chars extends IrTransformationStep
class ReplaceUtf8Chars extends IrTransformationStep
{
public static val UTF8Chars = #{
'\u03B1' -> 'alpha',
Expand Down Expand Up @@ -46,15 +46,15 @@ class ReplaceUtf8Chars extends IrTransformationStep
'\u03C8' -> 'psi',
'\u03C9' -> 'omega',
'\u2126' -> 'bigomega'
}
}

override getDescription()
{
"Replace UTF8 characters in function, variable and job names by ASCII characters"
}

override getDescription()
{
"Replace UTF8 characters in function, variable and job names by ASCII characters"
}

override transform(IrRoot ir, (String)=>void traceNotifier)
{
{
for (v : ir.eAllContents.filter(ArgOrVar).toIterable)
{
v.name = v.name.noUtf8
Expand All @@ -63,24 +63,24 @@ class ReplaceUtf8Chars extends IrTransformationStep
}
ir.eAllContents.filter(ReductionInstruction).forEach[x | x.result.name = x.result.name.noUtf8]
ir.eAllContents.filter(Function).forEach[x | x.name = x.name.noUtf8]
ir.jobs.forEach[x | x.name = x.name.noUtf8]
ir.jobs.forEach[x | x.name = x.name.noUtf8]
ir.mesh.connectivities.forEach[x | x.name = x.name.noUtf8]
}

}

override transform(DefaultExtensionProvider dep, (String)=>void traceNotifier)
{
dep.functions.forEach[x | x.name = x.name.noUtf8]
}

private def getNoUtf8(String name)
private def getNoUtf8(String name)
{
var n = name
for (c : UTF8Chars.entrySet)
n = n.replace(c.key, c.value)
n = n.replace(c.key, c.value)

n = n.replace('\u221A', 'sqrt')
n = n.replace('\u2211', 'sum')
n = n.replace('\u2211', 'sum')
n = n.replace('\u220f', 'prod')
return n
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void ExplicitHeatEquationModule::init()
// initialization of other attributes
m_lastDump = numeric_limits<int>::min();
m_n = 0;
m_deltat = 0.001;
m_delta_t = 0.001;
m_alpha.resize(nbCell());

// calling jobs
Expand Down Expand Up @@ -144,12 +144,12 @@ void ExplicitHeatEquationModule::computeFaceLength()

/**
* Job computeTn called @1.0 in executeTimeLoopN method.
* In variables: deltat, t_n
* In variables: delta_t, t_n
* Out variables: t_nplus1
*/
void ExplicitHeatEquationModule::computeTn()
{
m_t_nplus1 = m_t_n + m_deltat;
m_t_nplus1 = m_t_n + m_delta_t;
}

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ void ExplicitHeatEquationModule::updateU()
/**
* Job computeDeltaTn called @2.0 in simulate method.
* In variables: D, V
* Out variables: deltat
* Out variables: delta_t
*/
void ExplicitHeatEquationModule::computeDeltaTn()
{
Expand All @@ -283,8 +283,8 @@ void ExplicitHeatEquationModule::computeDeltaTn()
};
reduction0 = reducer.reduce();
}
m_deltat = reduction0 * 0.24;
m_global_deltat = m_deltat;
m_delta_t = reduction0 * 0.24;
m_global_delta_t = m_delta_t;
}

/**
Expand Down Expand Up @@ -359,13 +359,13 @@ void ExplicitHeatEquationModule::setUpTimeLoopN()

/**
* Job computeAlphaCoeff called @3.0 in simulate method.
* In variables: V, Xc, deltat, faceConductivity, faceLength
* In variables: V, Xc, delta_t, faceConductivity, faceLength
* Out variables: alpha
*/
void ExplicitHeatEquationModule::computeAlphaCoeff()
{
auto command = makeCommand(m_default_queue);
auto in_deltat = m_deltat;
auto in_delta_t = m_delta_t;
auto in_V = ax::viewIn(command, m_V);
auto in_faceLength = ax::viewIn(command, m_faceLength);
auto in_faceConductivity = ax::viewIn(command, m_faceConductivity);
Expand All @@ -374,7 +374,7 @@ void ExplicitHeatEquationModule::computeAlphaCoeff()
command << RUNCOMMAND_ENUMERATE(Cell, cCells, allCells())
{
const auto cId(cCells);
Real alphaDiag(0.0);
Real alpha_Diag(0.0);
{
const auto neighbourCellsC(m_mesh->getNeighbourCells(cId));
const Int32 nbNeighbourCellsC(neighbourCellsC.size());
Expand All @@ -384,12 +384,12 @@ void ExplicitHeatEquationModule::computeAlphaCoeff()
const auto dCells(dId);
const auto fId(m_mesh->getCommonFace(cId, dId));
const auto fFaces(fId);
const Real alphaExtraDiag(in_deltat / in_V[cCells] * (in_faceLength[fFaces] * in_faceConductivity[fFaces]) / explicitheatequationfreefuncs::norm(explicitheatequationfreefuncs::operatorSub(in_Xc[cCells], in_Xc[dCells])));
out_alpha[cCells][dCells] = alphaExtraDiag;
alphaDiag = alphaDiag + alphaExtraDiag;
const Real alpha_ExtraDiag(in_delta_t / in_V[cCells] * (in_faceLength[fFaces] * in_faceConductivity[fFaces]) / explicitheatequationfreefuncs::norm(explicitheatequationfreefuncs::operatorSub(in_Xc[cCells], in_Xc[dCells])));
out_alpha[cCells][dCells] = alpha_ExtraDiag;
alpha_Diag = alpha_Diag + alpha_ExtraDiag;
}
}
out_alpha[cCells][cCells] = 1 - alphaDiag;
out_alpha[cCells][cCells] = 1 - alpha_Diag;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ExplicitHeatEquationModule
Int32 m_n;
static constexpr Real m_u0 = 1.0;
static constexpr Real2 m_vectOne = {1.0, 1.0};
Real m_deltat;
Real m_delta_t;
Real m_t_n;
Real m_t_nplus1;
Real m_t_n0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
need-sync="true"/>

<variable
field-name="deltatj"
name="deltatj"
field-name="delta_tj"
name="delta_tj"
data-type="real"
item-kind="cell"
dim="0"
Expand Down
Loading

0 comments on commit de37f35

Please sign in to comment.