@@ -7,7 +7,7 @@ sys.path.insert(0, adapter_root)
77from adapter import *
88
99# Get participant name from environment variable
10- # Note: In OpenFOAM and CalculiX, this is read from a command line argument (--precice-participant),
10+ # Note: In the OpenFOAM and CalculiX adapters , this is read from a command line argument (--precice-participant),
1111# but I don't know how to pass my own argument to as_run
1212participantName = os.environ["PRECICE_PARTICIPANT"]
1313
@@ -19,42 +19,34 @@ participantName = os.environ["PRECICE_PARTICIPANT"]
1919# floating point exception in Code_Aster, and therefore the .yml file cannot be read!
2020# ==========================================================================================
2121
22+ # Include adapter configuration .comm.
2223# Defines: preciceConfigFile, interfaces, participantName
2324INCLUDE(UNITE=90)
24- precice = PySolverInterface(participantName, 0, 1)
2525preciceConfigFile = settings["base-path"] + "/" + settings["precice-config-file"]
26- precice.configure(preciceConfigFile)
27-
2826participant = settings["participants"][participantName]
2927isSteadyState = ("steady-state" in settings["simulation"]) and (settings["simulation"]["steady-state"])
3028
3129# ==========================================================================================
3230# Include file in UNITE 91: Setup Aster case
3331# ==========================================================================================
3432
33+ # Include case definition.comm.
3534# Defines: MESH, MODEL, BC[], MAT[], MATS
3635INCLUDE(UNITE=91)
3736
3837# ==========================================================================================
39- # Get interface mesh
38+ # Create and initialize the adapter
4039# ==========================================================================================
4140
42- adapter = Adapter(precice, participantName, participant["interfaces"], MESH, MODEL, MAT,
41+ adapter = Adapter(preciceConfigFile,
42+ participantName,
43+ participant["interfaces"],
44+ MESH, MODEL, MAT,
4345 isNonLinear=participant["non-linear"])
4446BCs = [{'CHARGE': bc} for bc in BC]
4547LOADS = BCs + adapter.LOADS
4648
47- # ==========================================================================================
48- # Setup preCICE
49- # ==========================================================================================
50-
51- preciceDt = precice.initialize()
52-
53- if precice.isActionRequired(PyActionWriteInitialData()):
54- adapter.sendCouplingData(INIT_T, preciceDt)
55- precice.fulfilledAction(PyActionWriteInitialData())
56-
57- precice.initializeData()
49+ dt = adapter.initialize(INIT_T)
5850
5951# ==========================================================================================
6052# ==========================================================================================
@@ -64,27 +56,12 @@ precice.initializeData()
6456
6557k = 0
6658time = 0.0
67-
6859ICOND = {'CHAM_NO': INIT_T}
6960
70- while precice .isCouplingOngoing():
61+ while adapter .isCouplingOngoing():
7162
72- # ======================================================================================
73- # Write checkpoint if necessary
74- # ======================================================================================
75-
76- if precice.isActionRequired(PyActionWriteIterationCheckpoint()):
77- if time == 0:
78- ICOND = {'CHAM_NO': INIT_T}
79- else:
80- ICOND = {'EVOL_THER': PRV_TEMP}
81- precice.fulfilledAction(PyActionWriteIterationCheckpoint())
82-
83- # ======================================================================================
84- # Read and set boundary conditions
85- # ======================================================================================
86-
87- adapter.receiveCouplingData()
63+ adapter.writeCheckpoint()
64+ adapter.readCouplingData()
8865
8966 # ======================================================================================
9067 # Solve
@@ -106,7 +83,7 @@ while precice.isCouplingOngoing():
10683 EXCIT=LOADS,
10784 ETAT_INIT=_F(STATIONNAIRE='OUI'),
10885 )
109-
86+
11087 T = CREA_CHAMP(
11188 RESULTAT=TEMP,
11289 NOM_CHAM='TEMP',
@@ -118,7 +95,7 @@ while precice.isCouplingOngoing():
11895
11996 STEP = DEFI_LIST_REEL(
12097 DEBUT=time,
121- INTERVALLE=(_F(JUSQU_A=time+preciceDt , NOMBRE=1))
98+ INTERVALLE=(_F(JUSQU_A=time+dt , NOMBRE=1))
12299 )
123100
124101 if participant["non-linear"]:
@@ -139,7 +116,7 @@ while precice.isCouplingOngoing():
139116 INCREMENT=_F(LIST_INST=STEP),
140117 PARM_THETA=1.0
141118 )
142-
119+
143120 T = CREA_CHAMP(
144121 RESULTAT=TEMP,
145122 NOM_CHAM='TEMP',
@@ -148,48 +125,38 @@ while precice.isCouplingOngoing():
148125 NUME_ORDRE=1,
149126 )
150127
151- # ======================================================================================
152- # Extract and write boundary values
153- # ======================================================================================
154-
155- adapter.sendCouplingData(T, preciceDt)
128+ adapter.writeCouplingData(T)
129+ dt = adapter.advance()
130+ adapter.readCheckpoint()
156131
157- # ======================================================================================
158- # Advance
159- # ======================================================================================
160-
161- preciceDt = precice.advance(preciceDt)
162-
163- # ======================================================================================
164- # Check convergence, read checkpoint if necessary
165- # ======================================================================================
166-
167- if precice.isActionRequired(PyActionReadIterationCheckpoint()):
168- precice.fulfilledAction(PyActionReadIterationCheckpoint())
169- else:
170- if time > 0:
171- DETRUIRE(CONCEPT=_F(NOM=PRV_TEMP))
172- PRV_TEMP = COPIER(CONCEPT=TEMP)
173-
132+ if adapter.isCouplingTimestepComplete():
133+
134+ # Output if necessary
135+ k += 1
174136 if k % settings["simulation"]["output-frequency"] == 0:
175137 filename = "output-" + str(k) + ".rmed"
176138 DEFI_FICHIER(FICHIER=filename, UNITE=80)
177- IMPR_RESU(FORMAT='MED', RESU=_F(RESULTAT=TEMP));
139+ IMPR_RESU(FORMAT='MED', RESU=_F(RESULTAT=TEMP))
178140 call(["mv", filename, settings["base-path"] + "/" + participant["directory"]])
179141 DEFI_FICHIER(ACTION='LIBERER', UNITE=80)
180-
181- k = k + 1
182142
183- time = time + preciceDt
143+ # Use current solution as initial condition for the next time step
144+ if time > 0:
145+ DETRUIRE(CONCEPT=_F(NOM=TEMP_CPY))
146+ TEMP_CPY = COPIER(CONCEPT=TEMP)
147+ ICOND = {'EVOL_THER': TEMP_CPY}
148+ time = time + dt
184149
185150 # ======================================================================================
186151 # Destroy Aster objects
187152 # ======================================================================================
188-
153+
189154 DETRUIRE(CONCEPT=_F(NOM=TEMP))
190155 DETRUIRE(CONCEPT=_F(NOM=T))
191156
192157 if not isSteadyState:
193158 DETRUIRE(CONCEPT=_F(NOM=STEP))
194159
160+ adapter.finalize()
161+
195162FIN()
0 commit comments