#!/usr/bin/env python """ Transient Laplace equation (heat/diffusion equation) with constant initial conditions given by a function In the SfePy top-level directory the following command executes the script python time_poisson_explicity_1d.py """ from __future__ import absolute_import import sys from six.moves import range sys.path.append('.') from argparse import ArgumentParser, RawDescriptionHelpFormatter import numpy as nm import matplotlib.pyplot as plt def main(): from sfepy.base.base import output from sfepy.base.conf import ProblemConf, get_standard_keywords from sfepy.discrete import (FieldVariable, Material, Integral, Function, Equation, Equations, Problem, Domain, State) # from sfepy.base.plotutils import plt from sfepy.solvers.ts_solvers import SimpleTimeSteppingSolver from sfepy.solvers.ls import ScipyDirect from sfepy.solvers.nls import Newton # required, other = get_standard_keywords() ### Use this file as the input file. conf = ProblemConf.from_file('time_poisson_explicit_1d.py') #### Create problem instance, but do not set equations. problemInstance = Problem.from_conf(conf) problemInstance.setup_default_output() # initializing simple time step solver from configurationf ile tss = SimpleTimeSteppingSolver(problemInstance.ts_conf, problem=problemInstance) tss.init_time() print ("initial problem/solver configured....") print ("") print ("problemInstance.ts_conf: " + str(problemInstance.ts_conf)) print ("problemInstance.ts.t0: " + str(problemInstance.ts.t0)) print ("problemInstance.ts.t1: " + str(problemInstance.ts.t1)) print ("problemInstance.ts.dt: " + str(problemInstance.ts.dt)) print ("") print ("tss.ts.t0: " + str(tss.ts.t0)) print ("tss.ts.t1: " + str(tss.ts.t1)) print ("tss.ts.dt: " + str(tss.ts.dt)) print ("") # Solve the problem using the time stepping solver. suffix = tss.ts.suffix genpath = "output/" ##### TYPICAL MAIN LOOP STATEMENT #### # for step, time, state in tss(): # print("step: " + str(step)) #### initialize state for problem from sfepy.solvers.ts_solvers #### def get_initial_state(problem) calls... state0 = problemInstance.create_state() problemInstance.setup_ics() state0.apply_ic() # Initialize variables with history. state0.init_history() print (state0.vec) staten1 = state0.copy(deep=True) ##### MAIN LOOP ##### totalsteps = 3 plotstep = 1 for i in range(totalsteps): ### print current step print("step: " + str(i)) #### manual plotting of every plotstep if (i%plotstep == 0): ###get materials of current problem instance matl = problemInstance.get_materials() ##### command to change flux (natural boundary condition) # matl['LoadRHS'].datas['special']['val'] = 1.0 ##### command to change conccentration (essential boundary condition) # parts = state.get_parts() # parts['c'][45] = 0.15 if (i == 0): conc = state0.get_parts()['c'] print (conc) else: conc = state.get_parts()['c'] print (conc) #### solving commands state = tss.solve_step(tss.ts, staten1) staten1 = state.copy(deep=True) problemInstance.advance(tss.ts) #### other solving commands suggested on main tutorial page # problemInstance.time_update() # state = problemInstance.solve() # print (state.vec) if __name__ == '__main__': main()