Overview
Comment:Fix for [ 547513 ]
Re-written to eliminate need for installation.
Single C++ file (cxxsim.cc) handles the entire transformation which is
automatically compiled on invocation by "mtt sys cxxsim view".
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 7a95f8d106863fd8fe3873277f301d28de69c4cb810e78a0f32a281c22261b14
User & Date: geraint@users.sourceforge.net on 2002-12-12 16:07:13.000
Other Links: branch diff | manifest | tags
Context
2002-12-12
17:18:43
Fixed [ 647664 ] Namespace clash: LANG
Prepended MTT_ to SYS, OPTS and LANG environment variables.
check-in: 43c2af3a70 user: geraint@users.sourceforge.net tags: origin/master, trunk
16:07:13
Fix for [ 547513 ]
Re-written to eliminate need for installation.
Single C++ file (cxxsim.cc) handles the entire transformation which is
automatically compiled on invocation by "mtt sys cxxsim view".
check-in: 7a95f8d106 user: geraint@users.sourceforge.net tags: origin/master, trunk
16:00:11
Removed cruft. check-in: 441a80070a user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes
1
2
3
4
5
6

7
8
9


10
11
12



13
14
15
16
17







18
19
20
21
22
23
24


25
26
27
28


29
30
31
32

33
34
35
36
37




38
39
40
41
42



43
44
45
46



47
48
49


50

51
52
53


54


55
56
57
58
59
60
61
62

63
64

65
66
67
68

69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142


143
144

1





2



3
4



5
6
7





8
9
10
11
12
13
14


15
16
17


18
19
20
21


22
23

24


25





26
27
28
29





30
31
32
33



34
35
36
37


38
39

40
41


42
43

44
45
46
47




48

49
50

51
52



53
54










55











































56


57
58









59
60


61
62


63
64


65

-
-
-
-
-
+
-
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-



-
-
+
+


-
-
+
+
-

-
-
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+

-
-
-
+
+
+

-
-
+
+
-
+

-
-
+
+
-
+
+


-
-
-
-

-
+

-
+

-
-
-
+

-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
+

-
-
-
-
-
-
-
-
-


-
-
+

-
-
+
+
-
-
+
# -*-makefile-*-
# $Id$
# $Log$
# Revision 1.1  2000/12/28 10:12:48  peterg
# Initial revision
#

# Revision 1.1  2000/08/31 14:31:28  peterg
# Initial revision
#
# usage: mtt <sys> cxxsim view

# Revision 1.3  2000/08/31 02:56:18  geraint
# Keep mkdir quiet if $(SYS)_Simulation_Dir exists
#
# example:
# mtt copy MotorGenerator && cd MotorGenerator && mtt MotorGenerator cxxsim view

# Revision 1.2  2000/08/30 04:34:55  geraint
# *** empty log message ***
#

BIN=$(MTTPATH)/trans
# cxxsim creates a very simple C++ simulation without using Reduce
# it doesn't use MTT's normal .txt files so the resultant .cc must be edited 
# manually to alter parameter, input and logic values

# a more intelligent version would just do ese_r2cc to create <sys>_ese.cc
# this could then be embedded into MTT's normal code like <sys>_ode.cc
# maybe another day ...
INC=$(MTTPATH)/lib/cr/hh
SRC=$(MTTPATH)/trans/cc

CC=g++

INCLUDE=-I$(MTTPATH)/lib/cr/hh
OPTIMISE=-O3
INCLUDE=-I. -I${MTT_LIB}/cr/hh
OPTIMISE=-O0
WARNINGS=-Wall -ansi -pedantic

DIR=$(SYS)_Simulation_Dir
EXE=$(SYS)_cxxsim.exe

all: $(SYS)_cxxsim.$(LANG)
OBJ=$(SYS)_input.o $(SYS)_numpar.o $(SYS)_ode.o $(SYS)_init.o $(SYS)_cxxsim.o $(SYS)_switch.o

MTTFLAGS=-c -i euler -o -q

# view rule copied from gnuplot_rep.make
all: $(EXE)

$(SYS)_cxxsim.exe: $(OBJ) 
	echo Creating $(SYS)_cxxsim.exe
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) $(OBJ) -o $(SYS)_cxxsim.exe
# need it here to prevent MTT using the default route (via dae)
$(SYS)_cxxsim.view: $(SYS)_gnuplot.wish $(SYS)_cxxsim.exe
	./$(SYS)_cxxsim.exe > $(SYS)_odes.dat2
	sh $(SYS)_gnuplot.wish			|\
	mkdir -p ../$(DIR)
	cp *.cc ../$(DIR)
	cp *.hh ../$(DIR)
	cp *.o ../$(DIR)
	cp $(EXE) ../$(DIR)
		tee gnuplot_in.log		|\
		 gnuplot -geometry 400x300	\
		 > gnuplot_out.log 2> gnuplot_err.log &

$(SYS)_cxxsim.o: $(SYS)_cxxsim.cc $(SYS)_struc.hh
	echo Creating $(SYS)_cxxsim.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_cxxsim.cc
$(SYS)_cxxsim.exe: $(SYS)_cxxsim.cc
	echo Creating $(SYS)_cxxsim.exe
	$(CC) -o $@ $^ $(OPTIMISE) $(WARNINGS) $(INCLUDE)

$(SYS)_cxxsim.cc: cxxsim.txt
	echo Creating $(SYS)_cxxsim.cc
$(SYS)_cxxsim.cc: $(SYS)_cr.txt $(SYS)_ese.r $(SYS)_struc.txt $(SYS)_sympar.txt cxxsim
	./cxxsim $(SYS)
	$(BIN)/cxxsim_txt2cc $(SYS) cxxsim < cxxsim.txt > $(SYS)_cxxsim.cc
	cp $@ ..

cxxsim.txt:
	echo Creating cxxsim.txt:
cxxsim: ${MTT_LIB}/rep/cxxsim.cc
	echo creating $@
	cp $(MTTPATH)/trans/cc/src/cxxsim.txt .
	echo Compiling $^
	$(CC) -o $@ $^ $(OPTIMISE) $(WARNINGS) $(INCLUDE)

# list of constitutive relationships
$(SYS)_cr.hh: $(SYS)_cr.txt
	echo Creating $(SYS)_cr.hh
	$(BIN)/cr_txt2hh $(SYS) < $(SYS)_cr.txt > $(SYS)_cr.hh

$(SYS)_cr.txt:
	mtt $(MTTFLAGS) $(SYS) cr txt
	mtt -q $(OPTS) $(SYS) cr txt

# elementary system equations, Reduce format
# elementary system equations
$(SYS)_ese.r:
	echo Creating $(SYS)_ese.r
	mtt --version
	mtt $(MTTFLAGS) $(SYS) ese r
	mtt -q $(OPTS) $(SYS) ese r

# state initialisation (MTT already has state.cc)
$(SYS)_init.o: $(SYS)_init.cc
	echo Creating $(SYS)_init.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_init.cc

$(SYS)_init.cc: $(SYS)_struc.txt
	echo Creating $(SYS)_init.cc
	$(BIN)/struc2state_txt2cc $(SYS) < $(SYS)_struc.txt > $(SYS)_init.cc

# system inputs
# system structure
$(SYS)_input.o: $(SYS)_input.cc $(SYS)_cr.hh $(SYS)_numpar.hh
	echo Creating $(SYS)_input.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_input.cc

$(SYS)_input.cc: $(SYS)_struc.txt
	echo Creating $(SYS)_input.cc
	$(BIN)/struc2input_txt2cc $(SYS) < $(SYS)_struc.txt > $(SYS)_input.cc

# system numerical parameters
$(SYS)_numpar.o: $(SYS)_numpar.cc
	echo Creating $(SYS)_numpar.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_numpar.cc

$(SYS)_numpar.cc: $(SYS)_sympar.txt
	echo Creating $(SYS)_numpar.cc
	$(BIN)/sympar2numpar_txt2cc $(SYS) < $(SYS)_sympar.txt > $(SYS)_numpar.cc

$(SYS)_numpar.hh: $(SYS)_sympar.txt
	echo Creating $(SYS)_numpar.hh
	$(BIN)/sympar2numpar_txt2hh $(SYS) < $(SYS)_sympar.txt > $(SYS)_numpar.hh

$(SYS)_numpar.txt:
	echo Creating $(SYS)_numpar.txt
	mtt $(MTTFLAGS) $(SYS) numpar txt

# ordinary differential equations
$(SYS)_ode.o: $(SYS)_ode.cc $(SYS)_cr.hh $(SYS)_numpar.hh
	echo Creating $(SYS)_ode.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_ode.cc

$(SYS)_ode.cc: $(SYS)_ode.txt
	echo Creating $(SYS)_ode.cc
	$(BIN)/ode_txt2cc $(SYS) < $(SYS)_ode.txt > $(SYS)_ode.cc

$(SYS)_ode.txt: $(SYS)_ese.r
	echo Creating $(SYS)_ode.txt
	$(BIN)/stripComments '%' < $(SYS)_ese.r | $(BIN)/resolve $(SYS) > $(SYS)_ode.txt

# system structure, sizes of state-space matrices
$(SYS)_struc.hh: $(SYS)_struc.txt
	echo Creating $(SYS)_struc.hh
	$(BIN)/struc_txt2hh $(SYS) < $(SYS)_struc.txt > $(SYS)_struc.hh

$(SYS)_struc.txt:
	echo Creating $(SYS)_struc.txt
	mtt $(MTTFLAGS) $(SYS) struc txt
	mtt -q $(OPTS) $(SYS) struc txt

# logic control
$(SYS)_switch.o: $(SYS)_switch.cc $(SYS)_struc.txt $(SYS)_sympars.txt
	echo Creating $(SYS)_switch.o
	$(CC) $(WARNINGS) $(OPTIMISE) $(INCLUDE) $(CFLAGS) -c $(SYS)_switch.cc

$(SYS)_switch.cc: $(SYS)_struc.txt
	echo Creating $(SYS)_switch.cc
	$(BIN)/struc2switch_txt2cc $(SYS) < $(SYS)_struc.txt > $(SYS)_switch.cc

# list of symbolic parameters
$(SYS)_sympar.txt:
	echo Creating $(SYS)_sympar.txt
	mtt $(MTTFLAGS) $(SYS) sympar txt
	mtt -q $(OPTS) $(SYS) sympar txt

# list of symbolic parameters and switch controls
$(SYS)_sympars.txt:
# gnuplot script
$(SYS)_gnuplot.wish:
	echo Creating $(SYS)_sympars.txt
	mtt $(MTTFLAGS) $(SYS) sympars txt
	mtt -q $(OPTS) $(SYS) gnuplot wish

MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]