IR_PrintVtkNS.scala 2.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//=============================================================================
//
//  This file is part of the ExaStencils code generation framework. ExaStencils
//  is free software: you can redistribute it and/or modify it under the terms
//  of the GNU General Public License as published by the Free Software
//  Foundation, either version 3 of the License, or (at your option) any later
//  version.
//
//  ExaStencils is distributed in the hope that it will be useful, but WITHOUT
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
//  more details.
//
//  You should have received a copy of the GNU General Public License along
//  with ExaStencils. If not, see <http://www.gnu.org/licenses/>.
//
//=============================================================================

19
20
21
22
23
24
25
26
27
package exastencils.applications.ns.ir

import scala.collection.mutable.ListBuffer

import exastencils.base.ir.IR_ImplicitConversion._
import exastencils.base.ir._
import exastencils.core.Duplicate
import exastencils.parallelization.api.mpi._
import exastencils.util.ir.IR_Print
28
import exastencils.visualization.ir.postprocessing.vtk.IR_PrintVtkQuads
29
30
31

/// IR_PrintVtkNS

32
case class IR_PrintVtkNS(var filename : IR_Expression, level : Int, var resolveId : Int) extends IR_PrintVtkQuads with IR_PrintVisualizationNS with IR_PrintFieldAsciiNS {
33
  override def stmtsForNodeData : ListBuffer[IR_Statement] = ListBuffer()
34

35
  def fieldnames : ListBuffer[String] = ListBuffer("vel", "p")
36

37
38
39
40
41
42
43
  override def printField(name : String, stream : IR_VariableAccess, loopBody : ListBuffer[IR_Statement], numComponents : Int = 1) : ListBuffer[IR_Statement] = ListBuffer(
    IR_ObjectInstantiation(stream, Duplicate(filename), IR_VariableAccess("std::ios::app", IR_UnknownDatatype)),
    IR_IfCondition(MPI_IsRootProc(),
      IR_Print(stream, IR_StringConstant(name), separator, numComponents, separator, numCells, separator, IR_StringConstant("double"), IR_Print.endl))) ++
    super.printField(name, stream, loopBody) :+
    IR_ExpressionStatement(IR_MemberFunctionCall(stream, "close"))

44
45
  override def stmtsForCellData : ListBuffer[IR_Statement] = {
    val stmts = ListBuffer[IR_Statement]()
46

47
    val stream = newStream
48

49
50
    stmts ++= genStmtBlock(ListBuffer[IR_Statement](
      IR_IfCondition(MPI_IsRootProc(), ListBuffer[IR_Statement](
51
        IR_ObjectInstantiation(stream, Duplicate(filename), IR_VariableAccess("std::ios::app", IR_UnknownDatatype)),
52
        IR_Print(stream, IR_StringConstant("CELL_DATA"), separator, numCells, IR_Print.endl),
53
        IR_Print(stream, IR_StringConstant("FIELD"), separator, IR_StringConstant("FieldData"), separator, numFields, IR_Print.endl),
54
        IR_MemberFunctionCall(stream, "close")))))
55

56
57
58
    // implemented in IR_PrintFieldsAsciiNS
    stmts ++= genStmtBlock(printVel())
    stmts ++= genStmtBlock(printP())
59

60
    stmts
61
62
  }
}