Hi,
gas_rate and liquid_rate parameters must be of type ndarray with dimension (nqp, 1, 1) as other output values of get_coef(). Now, they are flaots. Therefore: "AttributeError: 'float' ..."
Regads
Vladimir
On 27. 05. 21 22:40, Max Maximilian wrote:
Hey all,
I'm struggled with an issue called AttributeError: 'float' object has no attribute 'ndim'.
It appears when starting at the initial condition calculation.
Is there any problems with my material setting?
#codes:
from __future__ import absolute_import from sfepy.examples.dg.example_dg_common import * from sfepy import data_dir from sfepy.base.base import output import numpy as nm from sfepy.discrete.fem import Mesh from sfepy.discrete.fem.meshio import UserMeshIO import matplotlib.pyplot as plt from sfepy.base.base import Struct
filename_mesh=None X1 = 0 XN = 2e-4 n_nod = 1001 n_el = n_nod - 1
if filename_mesh is None: filename_mesh = get_gen_1D_mesh_hook(X1, XN, n_nod)
approx_order=2 t0=0.0 t1=0.01
porosity = 0.3 # PTL porosity theta_PTL = nm.pi*30./180. # PTL contact angle KG = 4.5e-14 # Permeability, m2 R = 8.3145 # Ideal gas constant, J/mol/K T = 273.15+80 # Ambient temperature, K patm = 101325.0 # Ambient pressure s0 = 0.5 # Channel liquid saturation Mox = 0.032 # Molar mass density of oxygen, kg/mol
# Boundary pressure pc0 = 235.8e-3*(1-T/647.096)**1.256*(1-0.625*(1-T/647.096))*nm.cos(theta_PTL)*nm.sqrt(porosity/KG)*(1.417*(1-s0)-2.120*(1-s0)**2+1.263*(1-s0)**3) rho00 = (patm+pc0)/R/T*Mox
example_name = "fluid_dynamics_1D"
def post_process(out, pb, state, extend=False): # Gradient evalution rhow_grad = pb.evaluate('ev_grad.4.Omega(rho)', mode='el_avg', verbose=False) out['pressure_gradient'] = Struct(name='output_data', mode='cell', data=rhow_grad, dofs=None) return out
def get_coef(ts, coors, problem, equations=None, mode=None, **kwargs): """ Calculates the coefficient matrix and returns them. This relation results in velocities and diffusivity. """ porosity = 0.3 # PTL porosity theta_PTL = nm.pi*30./180. # PTL contact angle KG = 4.5e-14 # Permeability, m2 muG = 1.881e-5 # Gas viscosity, Pa*s muL = 3.56e-4 # Liqiud viscosity, Pa*s R = 8.3145 # Ideal gas constant, J/mol/K T = 273.15+80 # Ambient temperature, K Mox = 0.032 # Molar mass density, kg/mol rho_H2O = 996 # Water density, kg/m3 m = 3 # Relative permeabiltiy coefficient Mw = 0.018 # Molar mass density of water, kg/mol i_app = 12000. # Applied current density, A/m2 F = 96485 # Faraday constant, C/mol gas_rate = -i_app/4/F*Mox liquid_rate = i_app/2/F*Mw dpcds = nm.zeros(coors.shape[0])
if mode == 'qp': # Field and gradient values in quadrature points coordinates given by integral i # - they are the same as in `coors` argument. liquid_saturation_values = problem.evaluate('ev_volume_integrate.i.Omega(s)', mode='qp', verbose=False) liquid_saturation_values.shape = (coors.shape[0], 1, 1) liquid_saturation_dt = problem.evaluate('ev_volume_integrate.i.Omega(ds/dt)', mode='qp', verbose=False) liquid_saturation_dt.shape = (coors.shape[0], 1, 1) grad_rho_values = problem.evaluate('ev_grad.i.Omega(rho)', mode='qp', verbose=False) grad_rho_values.shape = (coors.shape[0], 1, 1) rho_values = problem.evaluate('ev_volume_integrate.i.Omega(rho)', mode='qp', verbose=False) rho_values.shape = (coors.shape[0], 1, 1) # Mass matrix of gas density: (1-s)*eps mass_dens = (1-liquid_saturation_values)*porosity # Source matrix of gas density: porosity*ds/dt source_dens = liquid_saturation_dt*porosity # Stiffness matrix of gas density: rho*KG*(1-s)^3/muG*R*T/Mox stiff_dens = rho_values*KG*(1-liquid_saturation_values)**m/muG*R*T/Mox # Mass matrix of liquid saturation: porosity*rho_H2O mass_sat = rho_H2O*porosity*nm.ones(coors.shape[0]) mass_sat.shape = (coors.shape[0], 1, 1) # Diversity matrix of liquid saturation: rho_H2O*K*s^m/muL*R*T/Mox*grad_rho div_sat = rho_H2O*KG*liquid_saturation_values**m/muL*R*T/Mox*grad_rho_values # Stiffness matrix of liquid saturation: rho_H2O*dpcds dpcds = 235.8e-3*(1-T/647.096)**1.256*(1-0.625*(1-T/647.096))*nm.cos(theta_PTL)*nm.sqrt(porosity/KG)*(-1.417+2.120*2*(1-liquid_saturation_values)-3*1.263*(1-liquid_saturation_values)**2) stiff_sat = rho_H2O*dpcds return {'mass_dens' : mass_dens, 'source_dens' : source_dens, 'stiff_dens' : stiff_dens, 'mass_sat' : mass_sat, 'div_sat' : div_sat, 'stiff_sat' : stiff_sat, 'gas_flux' : gas_rate, 'liquid_flux' : liquid_rate}
materials = { 'coef' : 'get_coef', }
fields = { 'gas_density': ('real', 'scalar', 'Omega', 2), 'liquid_saturation': ('real', 'scalar', 'Omega', 2), }
variables = { 'rho': ('unknown field', 'gas_density', 0, 1), 'v1': ('test field', 'gas_density', 'rho'), 's': ('unknown field', 'liquid_saturation', 1, 1), 'v2': ('test field', 'liquid_saturation', 's'), }
regions = { 'Omega' : 'all', 'Gamma_Left' : ('vertices in (x < 1e-8)', 'facet'), 'Gamma_Right' : ('vertices in (x > 1.99999e-4)', 'facet'), }
ebcs = { 'channel_dens' : ('Gamma_Right', {'rho.0' : rho00}), 'channel_satu' : ('Gamma_Right', {'s.0' : s0}), }
integrals = { 'i' : 2*approx_order, }
equations = { 'gas_density' : """dw_volume_dot.i.Omega(coef.mass_dens, v1, drho/dt) - dw_volume_dot.i.Omega(coef.source_dens, v1, rho) + dw_laplace.i.Omega(coef.stiff_dens, v1, rho) = dw_surface_integrate.i.Gamma_Left(coef.gas_flux, v1)""", 'liquid_saturation' : """dw_volume_dot.i.Omega(coef.mass_sat, v2, ds/dt) + dw_diffusion_r.i.Omega(coef.div_sat, v2) - dw_laplace.i.Omega(coef.stiff_sat, v2, s) = -dw_surface_integrate.i.Gamma_Left(coef.liquid_flux, v2)""", }
functions = { 'get_coef' : (get_coef,), }
ics = { 'ic' : ('Omega', {'rho.0' : rho00, 's.0' : s0}), }
solvers = { 'ls' : ('ls.scipy_direct', { }), 'newton' : ('nls.newton', { 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'problem' : 'nonlinear', }), 'tss' : ('ts.adaptive', { 't0' : t0, 't1' : t1, 'dt' : None, 'verbose' : 1, 'n_step' : 100, 'quasistatic' : True, }), }
options = { 'ts' : 'tss', 'nls' : 'newton', 'ls' : 'ls', 'save_times' : 10, 'output_dir' : 'output/' + example_name, 'output_format' : "vtk", 'post_process_hook' : 'post_process', }
SfePy mailing list -- sfepy@python.org To unsubscribe send an email to sfepy-leave@python.org https://mail.python.org/mailman3/lists/sfepy.python.org/ Member address: vlukes@kme.zcu.cz